Académique Documents
Professionnel Documents
Culture Documents
Introduction
In terms of currencies, the most actively traded currency
1.1
different currencies.
HE
EUR/USD
28%
28%
USD/JPY
GBP/USD
3.10%
AUD/USD
2.53%
3.25%
USD/CAD
Citi
16.04%
4.38%
Deutsche Bank
Barclays Capital
5.55%
UBS
HSBC
USD/CHF
3%
EUR/JPY
3%
14%
4%
EUR/GBP
Other
5%
6%
9%
JPMorgan
7.12%
15.67%
10.88%
10.91%
Goldman Sachs
The forex market assists international trade and investFigure 1: Major participants in the forex market, data source:
Meakin 2 .
Email: chenxu@stanford.edu
1.2
Data
price, ask size, bid price, bid size, tier, as well as time stamp.
The time interval between two consecutive quotes is not
uniform, but roughly differs by 300 milliseconds. For some
time stamp, several different quotes exist, considering the
tiny differences they have, only the first one is accounted. 0
values exist for some date (very few occasions), which gets
replaced by the interpolated value of the previous and next
entry.
22:00
20:00
18:00
16:00
14:00
12:00
10:00
08:00
06:00
04:00
02:00
Bid
Ask
00:00
Price (EUR/USD)
Time
1.3
Methodology
With various technical analysis available for the forex
its sheer size. There are always buyers and sellers active in the marketplace;
- Leverage: only a small margin is needed to purchase a
contract with much higher value, i.e. one can use this
leverage to enhance profit and loss margins;
1.3.1
set. That is, starting from the opening of the market, one
does trading every 5 minutes (The every-5-minute trading
Prediction features
Prediction label
Place order
t-5min
t-10 min
Fill order
t+5min
Time
With this setup, the prediction is one step ahead, i.e., the pre-
formula:
diction is made for the bid price of next trading node (with
MAPE =
n A F
100% X
k
i
n k=1 A i
(1)
clude bid price, bid size, ask price, ask size and tier. The
1.5
parison to SVM).
Backtesting was performed on the data introduced in
1.0
1.4
Trading Strategy
0.5
Percentage
Section 1.2.
ing: cash and risky asset (shares), with a initial cash amount
of $10000 and risky asset of 0 share. Three strategies were
0
50
100
150
200
Trading nodes
1.4.1
Figure 5: The MAPE of all the prices within 10s of the trading
Strategy A
than the current bid price, then all the cash is used
paid);
1.3.2
P1 = P1, P2 = P2
Algorithm of Strategy A:
Require: B c , B p , A c , P 1,2
P1 = P1 + P2 Bc
if B p >= B c then
P 2 = P 1 /A c + 10000, P 1 = 10000 A c
P 2 = P 2 + P 1 /A c
P1 = 0
P 1 = (P 2 + 10000) B c , P 2 = 10000
else
end if
P 1 = P 1 + (P 2 + 10000) B c
P 2 = 10000
end if
where B p is the predicted future bid price, B c the current bid
1.4.3
Modified Strategy B
Strategy B only uses training error to measure the accuracy of the prediction, which is certainly not enough. However, with an online learning mechanism the past test error
1.4.2
Strategy B
two aspects:
Require: B c , B p , A c , P 1,2 , Tr ai n , R
if Tr ai n > 104 || R < 0 then
and ask prices, then all cash is spent to long the risky
asset;
P 2 = P 2 + P 1 /A c , P 1 = 0
price, but smaller than the ask price, we again hold the
positions;
P1 = P1, P2 = P2
price but still larger than the ask price, then all the
P1 = P1 + P2 Bc
holding shares get sold, all the cash will be used to pur-
P 2 = P 1 /A c + 10000, P 1 = 10000 A c
end if
bid and ask prices, we simply sell all the holding shares
and short another 10000 shares.
Backtesting Performances
2.1
Learning Performances
To calibrate the accuracy of the error, the absolute errors
P 2 = P 2 + P 1 /A c , P 1 = 0
For each day and each trade, the deviation of the predicted
bid price from the actual bid price is calculated, and then the
4
errors were averaged over all the trades within a day (which
Daily mean absolute error
SVM
GLM
average SVM
average GLM
(2)
8
MAE =
Error (*1e4)
predicted value.
50
SVM
GLM
10
15
20
25
30
40
Trading dates
30
20
10
Error (*1e4)
Strat.B, SVM
Strat.B, GLM
60
80
100
120
140
Trading nodes
40
Percentage
20
10
15
20
25
30
Trading dates
GLM.
The difference in the accuracy of the predictions will certainly affect the performance of the strategy as well. The cumulative returns using Strategy B with -SVM and GLM are
shown in Figure 8.
whole month.
sometimes vary only in the 4th digit), but the effect persists
days, but also suffers larger loss when the strategy fails to
catch the trend of the market. On the other hand, while be-
return.
Mod. Strat. B
Strategy B
Strategy A
nel), for 250 data points. With the growth of the number
Percentage (%)
2.2
10
15
20
25
30
Daily return
2.0
1.5
1.0
0.5
0.0
Percentage (%)
ing). The Sharpe ratios calculated for the month are 0.2778,
0.5
1.0
1.5
Mod. Strat. B
Strategy B
Strategy A
tively.
10
15
20
25
30
Trading dates
pretty high, rendering the -SVM very feasible for the pre-
worked well.
Paper Trading
To further test the robustness of the algorithm, the algorithm is deployed in the Quantopian platform, where algo-
3.1
limited support. In the platform, the trade can be made ei5. The features used include volume, open price, close
price, high price (of the day), low price, and current
As for the strategy, since the bid and ask prices, as well
Due to such limitations, the algorithm and strategy backtested on this platform is slightly different from those of the
3.3
3.2
Backtesting Performances
The backtesting was performed with data from January
400
300
200
1. For daily trading, the data from the past 15 days were
500
600
Jan 14
May 14
Sep 13
Jan 13
May 13
Sep 12
Jan 12
May 12
Sep 11
Jan 11
May 11
Sep 10
Jan 10
May 10
Sep 09
Jan 09
May 09
100
Trading dates
Figure 11: Open prices for NASDAQ: AAPL on all trading dates,
from January 01, 2010 to May 30, 2014.
Figure 12: Performance panel for the backtesting of the algorithm. The trade was made daily, from January 01, 2010 to May 30, 2014, on
NASDAQ: AAPL. Figure acquired from Quantopian.com.
300
Sharpe Ratio
200
100
Percentage (%)
2010
2011
2012
Trading dates
2013
2014
2010
2011
2012
2013
2014
Trading dates
Figure 13: Left: Monthly return of the algorithm, backtested with the daily data, on NASDAQ: AAPL. The red dashed line
indicates the average level of the return, which is 18.13%. Right: Monthly Sharpe ratio of the algorithm, backtested with the
daily data on NASDAQ: AAPL. The red dashed line indicates the average level of the Sharpe ratio, which is 0.6271.
3.3.1
3.3.2
traday data and 62% for daily data. The low accuracy may be
Figure 14: Performance panel for the backtesting of the algorithm. The trade was made in minutes, from January 01, 2010 to May 30,
2014, on NASDAQ: AAPL. Figure acquired from Quantopian.com.
1000
500
Sharpe Ratio
500
Percentage (%)
1000
2010
2011
2012
Trading dates
2013
2014
2010
2011
2012
2013
2014
Trading dates
Figure 15: Left: Monthly return of the algorithm, backtested with the intraday data, on NASDAQ: AAPL. The red dashed line
indicates the average level of the return, which is 17.62%. Right: Monthly Sharpe ratio of the algorithm, backtested with the
intraday data on NASDAQ: AAPL. The red dashed line indicates the average level of the Sharpe ratio, which is 0.6803.
10
loss. If, on the other hand, the predictions can be more accu-
to detect.
Figure 12, the shapes of the curves look very alike. This is
due to the nature of the strategy, which really has a delay effect.
4
Present value, SVM model
Execution Discussion
Stock Price, AAPL
Forex Trading
700
4.1
8000
6000
USD
USD
4000
2000
400
training speed of SV M depends on the size of the training data. To reach a good accuracy, at least 200 or more
SVM model
Labeled
Trading dates
Nov 13
Jul 13
Sep 13
May 13
Jan 13
Mar 13
Nov 12
Jul 12
Sep 12
May 12
Jan 12
Mar 12
Nov 11
Jul 11
Sep 11
May 11
Jan 11
Mar 11
Nov 13
Jul 13
Sep 13
May 13
Jan 13
Mar 13
Nov 12
Jul 12
Sep 12
May 12
Jan 12
Mar 12
Nov 11
Jul 11
Sep 11
May 11
Jan 11
Mar 11
around 5 seconds. If taking the prediction making and strategy executing time as 2 seconds, the total time will be at least
7 seconds, which makes such strategy not very suitable for
Trading dates
the daily data of NASDAQ: AAPL. The red dashed line indi-
C++.
The real problem is to place the order, as the order might
not get placed at the desired time and price. Since how and
11
4.2
Equity Trading
In addition, a similar algorithm was backtested in the paper trading platform Quantopian, with the historical data of
The equity trading is generally similar to the forex trading, except that commission is required for each trade, so
that the predictions must be more accurate, otherwise a
working strategy in forex market might end up profitless.
NASDAQ: AAPL, from January 2010 to May 30, 2014. High returns were achieved both for daily and intraday trading. Our
work thus provides a good reference for trading algorithms
using machine learning techniques.
Trading in stocks requires more features (P/E ratio, 10day volume, risk premium, Williams.R%, etc.), as well as data
points.
It is very different whether one is trading in minutes or
days. For daily trading, it is helpful to incorporate the influences of the news into the algorithm, so that the algorithm
gets more sensitive to turning points. For intraday trading,
the accuracy becomes very important, since within a day,
the prices may fluctuate while not changing much, and bad
predictions can cause large loss.
The big challenge is still placing and filling of orders. For
Acknowledgement
We thank Dr. Lisa Borland for teaching this great course
where we learned a lot. And thank you for bringing the guest
lecturers into the classes, we enjoyed the lectures very much.
We thank Dr. Lisa Borland and Mr. Enzo Busseti for the
many intelligent instructions and suggestions they provided
us. It has been really a very enjoyable quarter, each meeting
with you has been very fruitful. We really appreciate your
help and we are planning to continue the research.
daily trading, one can always place an order before the close
of the market, which requires one paying a commission of
0.3% for NYSE; for intraday trading, a strategy of setting trading frequency may work as well.
To hedge the risk, options on the asset can be longed or
shorted accordingly, with different positions in the asset.
References
[1] Levinson, M. Guide to financial markets; Bloomberg
Press, 2009.
[2] Meakin, L. Deutsche Bank currency crown lost to Citigroup on low volatility; 2014.
Summary
[3] Monetary&Economic, D. Foreign exchange turnover in
To summarize, an algorithm on forex trading was devel-
oped. The prediction accuracy for the bid price is high for
-support vector machine model. Three different strategies
originated from intuitive thoughts were tested, whose performances were evaluated. Using the data of USD/EUR in
March, 2014, a high monthly return of 10% was achieved.
12