Professional Documents
Culture Documents
1. Overview
Exisng FX trading portals are widely available on the web today that allow individual to place orders online. A
number of portals support automac execuon of trades bases on user‐defined strategies. To implement an
automac trading strategy, beginners o"en resort to common knowledge that he acquired from others.
Experienced traders usually have to go through many trials and errors in order to have a defined set of strategies
that he thinks that give posive results most of the me. The processes is long, costly and even the experienced
traders seem not to have an accountable way to test his strategies empirically on large amount of data.
During the last several year we also observe the explosion of interest in machine learning, specifically in neural
networks in financial industry where there are needs of forecasng, classificaon and management large amount of
data. Neural networks learn by examples and shield user from possible complexies in explicitly modelling
knowledge. The user of a neural network collates representave data and then starts the algorithm of training, then
as new data coming, the networks can give the classificaon based on what it has learned in the part.
We proposed a system to help tesng trading strategies and automac execuon of orders and have achieved all
the implementaon goals. Specifically:
2. Hypothesis
Exisng machine learning techniques applied in Forex trading predict the future prices of the rate. Using neural
network, those algorithms will try to find a curve that fit the historical prices from which future prices is
extrapolated. Although this is ulmately preferable we believe it can only predict the very near future. Given FX
market is an extremely volale market with 99% of the trades are speculave, we believe that predicng price is
unreliable. On the other hand, even the market is speculave, there are common pracces among traders. As one
trader learn from the other, they act similarly to market signals, in other words they start with some basic
strategies. Personal preferences, risk taking a9tude, capital availability and experience then segregated these
traders into different subsets. The process itself is a human‐learning process where each trader learn by examples
and fine‐tune their strategy overme. Given FX trading a zero‐sum game, traders who improve their techniques
faster are more o"en the winners. The inferiority of beginners’ strategies will most of the me results in losing
1 of 8 9/9/2009 5:44 PM
file:///C:/Users/gms/MyDocuments/ClassCoursework/Fall2009/FT_CO...
money.
Given winning and losing strategies exist in the market . We therefore postulate that it is preferable to predicng
strategy outcomes rather than price. In other words, it might be more reliable by not predicng the price but the
success and failure of a trade based on pa1erns of technical indicators.
It is important to note that by existence of winning strategies we do not mean a winning strategy will be winning
forever, market efficiency will sooner or later void its effecveness. Sll, being able to quickly spot a strategy that is
currently effecve might give us posive returns.
Our system supports connuous, reinforcement learning model that changes over me. So the trading strategy that
we give it inially will change as well.
3. System design
Historical data are saved in standard form of mestamp, open, high, low, close & volume values. From these values,
we can calculate technical indicator values. We use following 15 indicators (including price values):
1.open
2.high
3.low
4.close
5.upper_bollinger
6.lower_bollinger
7.Relative Strength Index (RSI)
8.CCI
9.Parabolic SAR
10.Stochastic
11.Moving average 10 (MA10)
12.Movng average 20 (MA20)
13.MACD Signal line
14.MACD histogram
15.ADX
2 of 8 9/9/2009 5:44 PM
file:///C:/Users/gms/MyDocuments/ClassCoursework/Fall2009/FT_CO...
From these indicators, trading strategies are made. A strategy is a set of condions applied to an indicator or a
combinaon of several indicators. When all the condion are sasfied, the strategy is said to be sasfied. The more
condions a strategy has, its success rate increases; however the less frequently all the condions are sasfied
results in it become less frequently executed. Our strategies has about 7,8 condions each. A strategy also has some
condions to exit the trade, called exit condions.
A"er each condions is calculated into true, false or real value, these values will be used as features vector for
machine learning model for training. In this phase, at every price instances, we entered the trade. The exit strategy
will determine me to exit the trade. At that me we can calculate the profit (or loss) of the trade. Profitable trade is
assigned label 1, loss is assigned label 0 to be used by learning model.
The support vector machine then take the feature and label vectors as input to train its internal model. By entering
at any price instances earlier, we accounted for all indicator pa1erns. That is how the perfect pa1ern is detected by
the machine, not by inial assumpon of the trader in his strategy that all condions must be sasfied.
Figure 2. illustrates the process of tesng data. Similar to training, we obtain feature and label vectors. This me
label vectors is not given as input to the model but is compared with its classificaon results.
‐ Number of trades (absolute value and percentage): each trade is associated with a spread: commission that is
paid to the dealer. More trades will therefore decrease profit. Not enough trade, however also result in too much
opportunity cost.
‐ Profit: we keep tracks of profit at every instances of trading life and total profit.
‐ Capital required: we keep track of capital required at every instances. This is pivotal in maintaining a trading
account for several reasons:
Every me a trade is entered, an amount of money equal to the price of one trade (called margin required)
is locked in the system. User’s account is le" with that less of money to enter other trades. User has to wait unl the
3 of 8 9/9/2009 5:44 PM
file:///C:/Users/gms/MyDocuments/ClassCoursework/Fall2009/FT_CO...
trade exits to release that money. Profit will be added up and loss deducted from.
This locked in process mean we cannot place too many trades at a me. As margin varies together with
profit and loss of the trade. Leaving too li1le money le" can result in dealer automacally execute our trade to
prevent negave cash flow for them (this happen when the loss is equal to buy price + money le", which make our
balance go to 0, dealer will not let it go below 0).
Thirdly, too much capital required to maintain a profitable trading will prove the strategy less effecve.
b. Automatic trading
A"er training and tesng, the most effecve strategy is used for automac trading.
A trading pla3orm is used to provide real me data and ge9ng orders from our system. MetaTrader pla3orm and
its programming language MLQ4 are excellent tools. The process start with MetaTrader output data to a file read
later by our Matlab roune. Our system run the data just as it process tesng data, but this me only produce 1
suggeson. The trade suggeson is then wri1en to another file. MetaTrader read this file and follow the instrucon
to either enter a Long (Buy) posion, Short (Sell) posion or do nothing.
We write code to instruct MetaTrader to read, write data, enter and exit orders. Exit strategies are implemented by
MLQ4 to be executed by MetaTrader. For 2 reasons:
‐ Exit is crical, execung it directly from MetaTrader will result in less delay which can make a different
between a profit or losing trade.
c. System in action
4 of 8 9/9/2009 5:44 PM
file:///C:/Users/gms/MyDocuments/ClassCoursework/Fall2009/FT_CO...
Matlab machine learning component run alongside with MetaTrader trading pla3orm. Please see our User Manual
on how to use the system.
4. Components details
We list the files by one author each. The larger the file name, the more important it is.
I. MetaTrader
Trade Monitor.mq4
Author: Linh Vu
Descripon: extract real me price from MetaTrader pla3orm, write to file that is read by Matlab process. Reading
trade command and place the trade if suggested.
Input: trade command file (<MetaTrader>/experts/Order.txt)
Output: data file (<MetaTrader>/experts/data.txt)
II. Matlab
Indicator Evaluation
indicatorBuilders.m
Author: Linh Vu
Descripon: calculate 15 indicators from data series
Input: data series in date, me, open, high, low, close, volume form
Output: 15 series
Libraries used: Technical Analysis Library (ta_lib)
Trade Evaluation
spotFX.m
Author: Linh Vu
5 of 8 9/9/2009 5:44 PM
file:///C:/Users/gms/MyDocuments/ClassCoursework/Fall2009/FT_CO...
Descripon: evaluate a strategy on all data instances, ge9ng success/failure value for each. Output will be used by
machine learning process.
Input: data series from indicator builders
Output: files contains training and tesng feature vectors and labels.
Strategies
All strategy files input and output are of the same format.
trend.m
Author: Linh Vu
Descripon: detect if a data series is trending UP or DOWN at t.
Input: single data series
Output: 1: there’s such a trend, 0: there’s no such trend
hasLine.m
Author: Linh Vu
Descripon: detect if a data series has a support or resistance line at me t.
Input: single data series
Output: 1: there’s such a line, 0: there’s no line
beyond.m
Author: Linh Vu
Descripon: detect if a data value exceed a target value at me t. A 5% margin is used in contrast to absolute
comparison.
Input: single data series
Output: 1 if true, 0 if false
within.m
Author: Linh Vu
Descripon: detect if a data value in within a target value at me t. A 5% margin is used in contrast to absolute
equality.
Input: single data series
Output: 1 if true, 0 if false
evalLast.m
Author: Linh Vu
Descripon: evaluate the most recent data to get its feature vector. It uses indicatorBuilders and evaluate the
strategy to get the condion values.
Input: price data
Output: feature vector
machine learning
classifyLast
Author: Naiteek & Linh Vu
Descripon: calling evalLast to get feature vector, feed it to model and write to file so that MetaTrader can read.
Input: price data
Output: file containing order (1: Enter, ‐1: do nothing)
6 of 8 9/9/2009 5:44 PM
file:///C:/Users/gms/MyDocuments/ClassCoursework/Fall2009/FT_CO...
run_svm
Author: Naiteek
evalStrategy
Author: Naiteek
Descripon: perform strategy evaluaon on accuracy, capital needed, number of trades, profit.
Input: learned model, tesng data.
Output: evaluaon results
Automated trading
Communicaon.m, Communicaon.fig
Author: Linh Vu
Descripon: Matlab Graphic User Interface that communicang with MetaTrader process to get data and instruct
machine learning model to issue next command.
Documentaon
Linh Vu
Presentaon
7 of 8 9/9/2009 5:44 PM
file:///C:/Users/gms/MyDocuments/ClassCoursework/Fall2009/FT_CO...
5. Future works
FX market is a fast changing environment where traders have to watch the price closely. Our system proposed an
me‐saving way so that trader can be advised on trades when the condion is preferable instead of having to be at
the trade terminal all the me. The system also allow trader to test new strategies on new data to find whether they
are sll effecve. With quanfiable measurements on performance of strategies, traders have precise knowledge
on the effecveness instead of usually vague percepon and experience. Knowing exactly how and when a strategy
is sll effecve he can later instruct the system to learn again adapng itself to new situaons. Our work is a
framework where more complicated strategies can be defined and tested.
8 of 8 9/9/2009 5:44 PM