Professional Documents
Culture Documents
Algorithmic Trading With MATLAB®: Martin Demel, Application Engineer
Algorithmic Trading With MATLAB®: Martin Demel, Application Engineer
Increasing complexity
– More data
– More complicated models
Increasing computational speed
– Push to higher frequency
Long deployment cycle
– (Re)coding is costly and error-prone
2
Challenges through the organization
Regulators
Management
Financial
Engineer
Clients
Traders
Quant Group
Partners
Other groups
3
Customers using MATLAB
4
Algorithmic trading workflow
Testing &
Databases Applications
Optimization
Strategy
Development
Datafeeds Production
Automate
5
Algorithmic trading workflow
Report Generator
Spreadsheet Link EX Fixed Income Financial Derivatives Econometrics Builder EX
MATLAB Compiler
MATLAB
6
Agenda
7
The problem at hand: Identifying profitable
trading strategies
Commodities analyst
Developing a trading strategy
– Multiple trading rules
– High frequency
Management requirements:
– Tested on historical data
– Uses sophisticated analytics to
identify optimal trading rule
combination
– Integrates with existing data and
execution APIs
8
Trading decision engine
Implementation
Live Data Decision Engine Execution
Real-Time Feeds Models Broker API
Event-Based Trading Rules Order Routing
9
Requirements for the trading engine
Sophisticated analytics
– Custom rules & indicators
– Non-traditional techniques
Scalable speed
– Higher frequency data
– More trading rules
Quick to develop and deploy
– Try different strategies
– Embed in trading engine
10
Task 1: Develop a back testing environment
Implementation
Live Data Decision Engine Execution
Real-Time Feeds Models Broker API
Event-Based Trading Rules Order Routing
11
Key tasks
Key tasks
Import data from files 0.8
Max Sharpe Ratio 0.758 for Lead 17 and Lag 120
0.6 0.6
0.2 0.4
0.2
-0.4
-0.6
0
-0.8
Solutions 0
20
-0.2
60 -0.4
80
0 20
pre-built functions
Powerful graphics
environment
12
Task 2: Expand the scale of the engine
Implementation
Live Data Decision Engine Execution
Real-Time Feeds Models Broker API
Event-Based Trading Rules Order Routing
14
Key tasks
Key tasks
Importing data from
databases
Increase computational speed
Solutions
MATLAB data tools: Database
Toolbox
High-performance computing:
Parallel Computing Toolbox,
MATLAB Distributed
Computing Server
15
Task 3: Rule selection engine
Implementation
Live Data Decision Engine Execution
Real-Time Feeds Models Broker API
Event-Based Trading Rules Order Routing
17
Key tasks
Key tasks
Increase number of rules
Incorporate advanced
analytics to select best
combination
18
Working with multiple strategies
Should I trade?
Signal 1 AND
OR Signal 2 AND
OR Signal 3
Yes Yes No
Dempster et. al., Computational learning techniques for intraday fx trading using popular technical indicators,
IEEE Transactions on Neural Networks (2001). 19
Working with multiple strategies
1 0 0 1 0 1 1 1 1 1
Signal 1
Signal 2
Signal 3 Signals
AND OR
Active?
20
Building Custom Evolution Algorithms
Selection
– Retain the best performing bit strings from one generation to
the next. Favor these for reproduction
Crossover
– parent1 = [ 1 0 1 0 0 1 1 0 0 0 ]
– parent2 = [ 1 0 0 1 0 0 1 0 1 0 ]
– child = [1 0 0 0 0 1 1 0 1 0]
Mutation
– parent = [1 0 1 0 0 1 1 0 0 0]
– child = [0 1 0 1 0 1 0 0 0 1]
21
Key tasks
Key tasks
Increase number of rules
Incorporate advanced
analytics to select best
combination
Evolutionary Learning Results, Sharpe Ratio = 2.38
150
Price (USD)
100
Solutions 50
High-level programming 0
1000 2000 3000 4000 5000 6000 7000 8000 9000 10000
Optimization, …
Price (USD)
150
Position
100 Cumulative Return
50
0
1000 2000 3000 4000 5000 6000 7000 8000 9000 10000
Serial time number
22
Review: Requirements for the trading engine
Sophisticated analytics
– Custom rules & indicators
– Non-traditional techniques
Scalable speed
– Higher frequency data
– More trading rules
Quick to develop and deploy
– Try different strategies
– Embed in trading engine
23
MATLAB’s solutions
Sophisticated analytics
– Advanced graphics environment
– Toolboxes give access to hundreds
of new techniques
– Flexible and customizable
Scalable speed
– Parallel computing solution
Quick to develop and deploy
– High-level programming
– Automated deployment … after the break
24
Agenda
25
Pairs Trading in Brief
long-term behavior 80
Price (USD)
spread apart 76
prices revert 70
26
Key tasks / challenges
Key tasks
Identify cointegrating Pairs indicator: rebalance every 60 minutes with previous 420 minutes' prices.
relationships 3 Indicator
LCO: Over bought
2
Test the strategy
LCO: Over sold
Indicator
-1
Solution -2
Econometrics Toolbox -3
-4
– New in R2011a: Engle- -5
Granger and Johansen -6
frameworks 2450 2500 2550 2600 2650 2700 2750 2800 2850
Implementation
Live Data Decision Engine Execution
Real-Time Feeds Models Broker API
Event-Based Trading Rules Order Routing
28
Key Tasks
Key tasks
Read live market data from data feed
Connect to trading “engine”
Solutions
Datafeed Toolbox
Many external APIs
– .NET, Java, C/C++, etc.
– 3rd party APIs
29
Deploying Applications with MATLAB
30
MATLAB’s solutions
Sophisticated analytics
– Advanced graphics environment
– Toolboxes give access to hundreds
of new techniques
Scalable speed
– Parallel computing solution
Quick to develop and deploy
– High-level programming
– Automated deployment
31
Support and Community
32
Consulting Services
Accelerating return on investment
A global team of experts supporting every stage of tool and process integration
Continuous Improvement
Process and Technology
Standardization
Full Application
Deployment
Process Assessment
Component
Deployment
Advisory Services
Jumpstart
Migration Planning
33
Training Services
Exploit the full potential of MathWorks products
34
MATLAB Central
36
Book Program
37
Technical Support
Resources
Over 100 support engineers
– All with MS degrees (EE, ME, CS)
– Local support in North America,
Europe, and Asia
Comprehensive, product-specific Web
support resources
38