developing professional-quality applications with matlab

23
Developing professional-quality applications with MATLAB Yair Altman Undocumented Matlab.com [email protected] © Yair Altman UndocumentedMatlab.com 1

Upload: others

Post on 16-Oct-2021

6 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Developing professional-quality applications with MATLAB

Developing professional-quality applications with MATLAB

Yair Altman

Undocumented Matlab.com

[email protected]

© Yair Altman UndocumentedMatlab.com 1

Page 2: Developing professional-quality applications with MATLAB

Common challenges

© Yair Altman UndocumentedMatlab.com 2

RAD

Functionality

Robustness

Usability

Performance

Page 3: Developing professional-quality applications with MATLAB

General trading application design

© Yair Altman UndocumentedMatlab.com 3

Page 4: Developing professional-quality applications with MATLAB

Pairformax process flow

© Yair Altman UndocumentedMatlab.com 4

1. Scan for applicable stocks

2. Download historical data

3. Correlate – find well-correlated pairs

4. Backtest various user-defined strategies

5. Select pairs/strategies to trade

6. Trade the selected pairs/strategies

Page 5: Developing professional-quality applications with MATLAB

Pairformax main components

© Yair Altman UndocumentedMatlab.com 5

Nasdaq

Page 6: Developing professional-quality applications with MATLAB

Data challenges

© Yair Altman UndocumentedMatlab.com 6

• Huge amounts of data o 3K stocks (^2) * 6 data items / bar *

8 bytes (double) / bar * 4K 30-min bars / year * 5 years

o Multiple backtesting strategies

o Impractical to process everything in sequence

• Data quality o gaps, inaccuracies, misaligned data

• Time constraint o Real-time scanning during auto-trading & research

o Interactive backtesting design cycles

Page 7: Developing professional-quality applications with MATLAB

Improving run-time performance

© Yair Altman UndocumentedMatlab.com 7

• Data reduction o Several processing steps o Tighter config constraints

• Wherever possible: o Cache data o Vectorize processing o Employ early bail-outs

• Hardware: add RAM, use SSD

• Separate machines for backtest R&D, auto-trading

• Parallel processing o Use Parallel Processing Toolbox o parpool(feature('numcores'))

o Reduce broadcast data to minimum o Especially important for tasks having I/O waits

Page 8: Developing professional-quality applications with MATLAB

GUI challenges

© Yair Altman UndocumentedMatlab.com 8

• Display large amounts of results data

• Interactivity / reactivity

• Usability

Page 9: Developing professional-quality applications with MATLAB

Displaying large amounts of data

© Yair Altman UndocumentedMatlab.com 9

• General concepts o Focus user attention on important data (summary, anomalies) o Hide less-important data by default o Combination of tables (quantitative) & charts (qualitative) o Enable data zoom-in (detachable chart, axes zoom, table click)

• Sorting, filtering & searching in data tables o Extremely important o Pre-sort data tables by descending value (best at top)

• Provide an integrated search-box

• Use tabs, flex-box panels (uiextras on FEX)

• Summarize data in separate tabs, sub-tables

Page 10: Developing professional-quality applications with MATLAB

Improving usability

© Yair Altman UndocumentedMatlab.com 10

• User should be able to configure GUI as much as possible • Remember user preferences (setpref/getpref)

• Automatically reload last-used data • Intuitive flow (leftright, topbottom) • Disable or hide figure/panel/controls during processing:

o enableDisableFig (FEX) o Ensure you restore in all exit conditions, including early bail-outs/exceptions

• Avoid data overload – hide non-critical data o Use tooltips, tabs, closed/hidden panels etc. o Remove unnecessary scrollbars, panel/table borders, unused controls

• Use appropriate Java controls o date/folder selector, spinner, tree, search box, password field

• Use colors/fonts consistently o Deviate to emphasize, e.g. backtesting summary sub-table headers (HTML)

Page 11: Developing professional-quality applications with MATLAB

Caveat emptor…

© Yair Altman UndocumentedMatlab.com 11

• Improved GUI functionality requires Java controls

• Using Java controls in MATLAB is: o Free & super-easy, but: o Undocumented o Unsupported o May break in some future MATLAB release

• Use such features if you: o Accept the risk that MathWorks will not fix bugs o Are willing to code without MathWorks’ official support o Need professional GUIs today o Don’t care about future compatibility (e.g., compiling an exe) or: o Accept the risk that re-coding may be required in the future

Page 12: Developing professional-quality applications with MATLAB

Improving GUI performance

© Yair Altman UndocumentedMatlab.com 12

• Use uitable('v0') or JTable, not standard uitable

• Use drawnow sparingly o Not too often, to avoid flicker/slowdowns

o Not too seldom, to let the user see ongoing progress

• Improve the perceived performance o Intuitive flow

o Postpone non-visible updates to end of processing

o Ongoing feedback (console, progress bars, GUI update)

Page 13: Developing professional-quality applications with MATLAB

Pairformax screenshots + live demo

© Yair Altman UndocumentedMatlab.com 13

Page 14: Developing professional-quality applications with MATLAB

Pairformax screenshots + live demo

© Yair Altman UndocumentedMatlab.com 14

Page 15: Developing professional-quality applications with MATLAB

Pairformax screenshots + live demo

© Yair Altman UndocumentedMatlab.com 15

Page 16: Developing professional-quality applications with MATLAB

Pairformax screenshots + live demo

© Yair Altman UndocumentedMatlab.com 16

Page 17: Developing professional-quality applications with MATLAB

Pairformax screenshots + live demo

© Yair Altman UndocumentedMatlab.com 17

Page 18: Developing professional-quality applications with MATLAB

Pairformax screenshots + live demo

© Yair Altman UndocumentedMatlab.com 18

Page 19: Developing professional-quality applications with MATLAB

Pairformax screenshots + live demo

© Yair Altman UndocumentedMatlab.com 19

Page 20: Developing professional-quality applications with MATLAB

Pairformax screenshots + live demo

© Yair Altman UndocumentedMatlab.com 20

Realized

P&L

Total P&L

Unrealized

P&L

Page 21: Developing professional-quality applications with MATLAB

Products & services used

© Yair Altman UndocumentedMatlab.com 21

• MathWorks o MATLAB o Datafeed Toolbox o Parallel Computing Toolbox o Optional: Financial, Database, Optimization, Compiler Toolboxes

• 3rd-party (MATLAB) o IB-Matlab Toolbox o Spatial Econometrics Toolbox o GUI Layout Toolbox

• 3rd-party (other) o Interactive Brokers o DTN IQ-Feed o Nasdaq.com, FinViz.com

Page 22: Developing professional-quality applications with MATLAB

Conclusions

• MATLAB is not inherently ‘slow’

• MATLAB GUI is not inherently ‘simplistic’

• MATLAB can be used to create professional-quality user-facing applications, while enjoying MATLAB’s benefits (RAD, functionality, reliability)

• As with everything in life, there are tradeoffs: o For better performance, invest extra code development time

o For better appearance, invest extra design time

o For better usability, use unsupported Java controls

© Yair Altman UndocumentedMatlab.com 22