Matlab Real-Time Trading Presentation
Matlab Real-Time Trading Presentation
Yair Altman
Undocumented Matlab.com [email protected]
Yair Altman
UndocumentedMatlab.com
Common solutions:
o Use Excel with trading-platform plugin o Use limited internal programmability (MT4, TS) o Develop custom C++/Java applications
Yair Altman
UndocumentedMatlab.com
Tried-and-tested
o Prevents risk of losses due to computational bugs o Most functions have editable source code no secrets o Reduces total cost of ownership (develop/test/maintain)
Excellent at exactly the task taking most time/cost to develop: the algo strategy/model
o All other components are usually far easier to develop
mathworks.com/discovery/algorithmic-trading.html
Yair Altman UndocumentedMatlab.com 3
However
MATLAB could not until recently complete the trading loop
Send automated trade orders to broker Modify/cancel open orders Track trade executions Receive portfolio/account info
UndocumentedMatlab.com 4
Yair Altman
Solutions
MATLAB 8.1 (R2013a): new Trading Toolbox
o Windows only o Bloomberg EMSX o Trading Technologies X_TRADER o R2013b: Added CQG + IB interfaces o mathworks.com/products/trading
Yair Altman
UndocumentedMatlab.com
Deployment server
Compiled code (MCC, Linux); Java, or .NET MATLAB Production Server client; .C or HDL (FPGA) via MATLAB Code Generator
Todays demo
Trade orders
Yair Altman
UndocumentedMatlab.com
Live demo
Yair Altman
UndocumentedMatlab.com
IB-MATLAB
Connects MATLAB to IB
o o o o o o o o Receive account data (portfolio, cash, limits) Receive market data feed (historic, snapshot, streaming quotes) Send trade orders to market Modify/cancel open orders Track executions (MATLAB callback functions) Synchronous + asynchronous modes Fully supports IBs API 5-10 mS latency for IB events
Works on all MATLAB platforms, Java-based API Hundreds of installations, trades $100M/day
Yair Altman UndocumentedMatlab.com 11
'AMZN' 'AMZN' 'NASDAQ' 'STK' 'USD' '0' '' 0 9200 1715800 186.5 169.03183335 [1x1 struct]
UndocumentedMatlab.com 12
22209874 '02-Dec-2010 00:47:23' '02-Dec-2010 00:47:23' 734474.032914491 'GOOG' 563.68 564.47 562.82 555.71 562.4 571.57 -1 36891 0.01 3 3 0 [1x1 struct]
UndocumentedMatlab.com 13
>> data.dateTime ans = '20110225 16:30:00' '20110225 17:00:00' '20110225 18:00:00' '20110225 19:00:00' '20110225 20:00:00' '20110225 21:00:00' '20110225 22:00:00'
Yair Altman UndocumentedMatlab.com 14
Yair Altman
UndocumentedMatlab.com
15
Yair Altman
UndocumentedMatlab.com
16
% Start an endless timer at the specified frequency that will % run the specified callbackFunc upon each invocation function hTimer = tradeSymbol(symbolName, period, callbackFunc)
% Create the timer object hTimer = timer('ExecutionMode','fixedRate', ... 'Period',period, ... 'TimerFcn',{callbackFunc,symbolName}); % Start the timer start(hTimer); end % tradeSymbol
UndocumentedMatlab.com 18
Yair Altman
end
Yair Altman UndocumentedMatlab.com 19
Yair Altman
www.UndocumentedMatlab.com
21
Yair Altman
www.UndocumentedMatlab.com
22
Backtesting in MATLAB
tadeveloper.com
Yair Altman
UndocumentedMatlab.com
23
Conclusion
Technology is no longer a barrier to developing a relatively low-cost algorithmic trading engine We no longer need to handle connectivity plumbing We no longer need to prototype in MATLAB, deploy in C
o MATLAB can handle entire investment management lifecycle o Simpler development, reduced cost & time-to-market
Resources
mathworks.com/products/trading
undocumentedmatlab.com/ib-matlab
interactivebrokers.com/en/software/ibapi.php
Yair Altman
UndocumentedMatlab.com
25