qmim final project
TRANSCRIPT
8/3/2019 QMIM Final Project
http://slidepdf.com/reader/full/qmim-final-project 1/18
QUANTITATIVE METHODS IN INVESTMENT MANAGEMENT
Columbia University
Department of Mathematics
December 2011
Prof. Alex Greyserman
“Trend-following strategies for selected currencies”
Ana Sokoleva as4148Andres Jaime aaj2132Ezequiel Zambaglione eaz2109
Joaquin Tapia jt2670
8/3/2019 QMIM Final Project
http://slidepdf.com/reader/full/qmim-final-project 2/18
Index
Introduction
Trading Algorithm
Optimization & Backtesting
Robustness evaluation
Trading Costs
Optimal strategy portfolio
Benchmark
Backtesting vs Benchmark
Risk Management
Conclusions
Bibliography
Appendix Codes
A Trend-following strategy
B Trading strategy – Long/short/neutral
positions
C Markowitz (Benchmark)
3
3
4
5
6
6
7
8
10
13
14
15
16
17
2
8/3/2019 QMIM Final Project
http://slidepdf.com/reader/full/qmim-final-project 3/18
Introduction
Standard Moving Averages are used to identify trends in financial markets, and coupled with the
establishment of trading rules and the selection of parameters related to trend speed and trade risk
can lead an investor to obtain profits. Our project consisted in developing a Trend-Following tradingstrategy for three currencies, all against the US Dollar:
Euro (EUR),
Swiss Franc (CHF), and
Swedish Krona (SEK)
The strategy’s performance was measured against a Benchmark (BMK) comprising the four currencies
mentioned. The Benchmark was the result of the Classical Mean-Variance optimization process. The
initial allocation reflects the optimal weights of each currency in the optimal portfolio. The RiskManagement tools used were the Relative-VaR (using a 95% level of confidence) and Drawdown. The
Relative-VaR provided a risk measure easy to follow and compute, therefore if risk limits are crossed
we close the position until risk limits are within the tolerable levels.
Each currency in the portfolio includes the overnight rate earned on the investment in each currency
(Merrill Lynch indexes) and the source was Bloomberg.
Trading Algorithm
The trading rule is based on the analytic property of the smoothened time series, in which we used to
parameters:
Slope parameter (M), refers to the time window (measured in days) used to smooth the time series (f).
Then, the daily difference of the smoothed time series between time “t” and “t-1” is taken to compute
the slope of the time series.
(2)
A second smoothing step is required to estimate de curvature of the series.
(3)
This will provide an estimate of the curvature of the time series
2
8/3/2019 QMIM Final Project
http://slidepdf.com/reader/full/qmim-final-project 4/18
(4)
At time t, the trading rule proposes taking a long/short position on the underlying asset if (2) and (4)
are either both positive or both negative. In other words, we enter a long/short position when not only
the slope but also the curvature indicate a bullish or bearish trend.
Optimization and Backtesting
The parameters that we optimized were the moving averages. We calculate the Sharpe ratio of the
first 60 Moving averages for each currency, choosing the one with the highest to back-test our strategy.
The results for the best 10 Sharpe ratios are shown below:
In the case of the EUR, using out-sample data, we can see that the 18 day moving average performed
remarkably well, with a Sharpe ratio of 1.70. Also, 53.1% of the time the strategy won, while the
average daily annualized return for the strategy was 14.6%.
EUR
2008-2009 2010 to date 6 1 2 3 4 5
Rank MA in sample out sample total trades win % loss % average return
1 18 1.35 1.70 351 186 53.1% 164 46.9% 14.6%
2 15 1.31 1.64 344 186 54.23% 157 45.77% 14.40%
3 19 1.29 1.80 343 185 54.09% 157 45.91% 15.84%
4 5 1.28 -0.82 340 168 49.41% 172 50.59% -8.61%
5 4 1.22 -0.05 362 178 49.17% 184 50.83% -0.50%
6 7 1.18 -0.25 329 163 49.70% 165 50.30% -2.39%
7 13 1.07 1.02 348 183 52.59% 165 47.41% 9.34%
8 17 0.95 1.62 349 189 54.31% 159 45.69% 14.19%
9 3 0.94 -0.84 365 176 48.35% 188 51.65% -8.68%
10 16 0.92 1.24 349 187 53.74% 161 46.26% 11.03%
Regarding CHF, we achieve a Sharpe ratio of 1.21 using the 29 moving average. This strategy won 53.5%
of the time with a 11.5% of average daily annualized return.
3
EUR
2008-2009
Rank MA in sample
1 18 1.35
2 15 1.31
3 19 1.29
4 5 1.28
5 4 1.22
6 7 1.18
7 13 1.07
8 17 0.95
9 3 0.94
10 16 0.92
SEK
2008-2009
Rank MA in sample
1 60 1.73
2 45 1.50
3 58 1.37
4 47 1.05
5 59 0.95
6 57 0.90
7 56 0.83
8 55 0.75
9 52 0.58
10 46 0.53
CHF
2008-2009
Rank MA in sample
1 29 0.79
2 38 0.78
3 20 0.53
4 28 0.45
5 31 0.44
6 40 0.41
7 26 0.36
8 16 0.34
9 25 0.33
10 39 0.29
8/3/2019 QMIM Final Project
http://slidepdf.com/reader/full/qmim-final-project 5/18
CHF
2008-2009 2010 to date 6 1 2 3 4 5
Rank MA in sample out sample total trades win % loss % average return
1 29 0.79 1.21 349 185 53.5% 161 46.5% 11.5%
2 38 0.78 0.41 354 179 51.14% 171 48.86% 4.15%
3 20 0.53 2.41 348 191 55.20% 155 44.80% 24.64%
4 28 0.45 1.35 351 187 53.58% 162 46.42% 12.94%
5 31 0.44 1.77 343 183 53.98% 156 46.02% 16.15%
6 40 0.41 -0.12 343 174 51.48% 164 48.52% -1.48%
7 26 0.36 1.09 337 179 53.43% 156 46.57% 10.38%
8 16 0.34 1.25 341 177 52.52% 160 47.48% 13.75%9 25 0.33 1.27 338 176 52.38% 160 47.62% 13.80%
10 39 0.29 0.66 346 175 51.17% 167 48.83% 6.59%
Finally, the SEK was the worst performer. This was the only currency with a negative sharpe ratio of
-0.72. This strategy lost 50.8% of the times with a -9.7% average daily annualized return.
SEK
2008-2009 2010 to date 6 1 2 3 4 5
Rank MA in sample out sample total trades win % loss % average return
1 60 1.73 -0.72 373 183 49.2% 189 50.8% -9.7%
2 45 1.50 -0.04 372 183 49.33% 188 50.67% -0.56%
3 58 1.37 -0.75 374 181 48.53% 192 51.47% -10.19%4 47 1.05 -0.12 371 185 50.00% 185 50.00% -1.52%
5 59 0.95 -0.52 373 180 48.39% 192 51.61% -6.92%
6 57 0.90 -1.01 372 177 47.71% 194 52.29% -13.89%
7 56 0.83 -1.08 374 177 47.45% 196 52.55% -14.47%
8 55 0.75 -0.33 370 180 48.65% 190 51.35% -4.16%
9 52 0.58 -0.49 376 185 49.20% 191 50.80% -6.31%
10 46 0.53 0.13 362 179 49.58% 182 50.42% 1.56%
Robustness evaluation
The performance of the EUR and CHF Sharpe Ratio’s according to the best ranked moving averages for
the in-sample data shows greater stability than for the out-sample period. The following graphs show
this behavior.
Swiss Franc: Sharpe ratio's stability
in-sample versus out-sample data
-0.50
0.00
0.50
1.00
1.50
2.00
2.50
3.00
29 38 20 28 31 40 26 16 25 39
a r p e a o s u n s
Best Mo ving Averages (days)
in-sample
out-sample
Euro: Sharpe ratio's stability
in-sample versus out-sample data
-1.00
-0.50
0.00
0.50
1.00
1.50
2.00
18 15 1 9 5 4 7 13 17 3 16
a r p e a o s u n s
Best Moving Averages (days)
in-sample
out-sample
However, for the SEK the Sharpe ratios showed slightly greater stability.
4
8/3/2019 QMIM Final Project
http://slidepdf.com/reader/full/qmim-final-project 6/18
Swedish Krona: Sharpe ratio's stability
in-sample versus out-sample data
-1.50
-1.00
-0.50
0.00
0.50
1.00
1.50
2.00
60 45 58 47 59 57 56 55 52 46
a r p e a o s u n s
Best Moving Averages (days)
in-sample
out-sample
Trading Costs
All the trades are assumed to be executed using the price of the WMR fix next business day, thereforethe strategy avoids transaction costs. However, the trade-off of this execution is represented by the
loss of exact timing to execute, i.e. to start-up or stopped the strategy at any given time outside the
London Fixing.
Optimal Strategy Portfolio
With the strategy in place for these currencies, we constructed an optimal portfolio for finding the
appropriate allocation of funds among each currency-strategy. To construct the optimal portfolio for
the in-sample period, we used the annual returns of each currency considered, and then constructed
the return’s covariance matrix and solve for the optimal weights that maximize the Sharpe ratio. We
included non-negativity restrictions for the weights and its sum equal to 100%. The result of the
optimization leaded us to a portfolio of two currencies, EUR and SEK, with weights of 56.62% and
43.38%, respectively.
Strategy optimal portfolio
ReturnsStandard
Deviation
Optimal
Weights
EUR 16.79% 11.59% 56.62%SEK 21.73% 15.21% 43.38%
CHF 6.83% 12.36% 0.00%
USD 1.27% 0.00% 0.00%
Portfolio 18.93% 9.32% 100.00%
As can be seen in the table above, the risk-return profile of the Swiss Franc was dominated by the
Euro. Also, it is important to mention that the risk-free rate was in historical lows during this period.
5
8/3/2019 QMIM Final Project
http://slidepdf.com/reader/full/qmim-final-project 7/18
Benchmark
In order to compare the performance of our strategy’s portfolio we constructed a benchmark based on
the aforementioned currencies. The methodology used was the Markowitz Portfolio Selection Model,solving for the lowest portfolio variance for a given portfolio return.
2 , = ′Σ x
s.t
= ′μ
The risk-free rate used was the average rate of the US Treasury 1 month bill during the period i.e. 1.85
percent. We chose US Treasuries over Libor because during the recent financial turmoil (which covers
our analysis period) there were some doubts and skepticism about the quotations of some banks for the
determination of Libor rates. Moreover, since banks participating in Libor setting were downgraded and
thus had lower credit ratings than the US Government, we considered the later a better measure of a
risk-free rate.
The optimal portfolio (highest Sharpe Ratio) suggested showed an average return of 5.20% and a
standard deviation of 6.95% in 5.5 years of sample, with an allocation of 35% in US dollar and Swiss
Franc, 21.37% in Sweden Krona, and 8.63% in Euro.
Optimal Portfolio of selected currencies*
Figures in Percent except for the Sharpe Ratio
Sharpe
ratio**
Target
Return
Effective
Return
Standard
Deviation
of
Returns
EUR CHF SEK USD Total
0.3480 4.2% 4.4% 7.5% 35% 5% 25% 35% 100%
0.3480 4.4% 4.4% 7.5% 35% 5% 25% 35% 100%
0.3879 4.6% 4.6% 7.1% 35% 14% 16% 35% 100%
0.4393 4.8% 4.8% 6.7% 35% 25% 5% 35% 100%
0.4767 5.0% 5.0% 6.6% 28% 32% 5% 35% 100%
0.4817 5.20% 5.20% 6.95% 8.63% 35.00% 21.37% 35.00% 100.00%0.4579 5.4% 5.4% 7.8% 6% 35% 30% 29% 100%
0.4379 5.6% 5.6% 8.6% 11% 35% 33% 21% 100%
0.4212 5.8% 5.8% 9.4% 17% 35% 35% 13% 100%
0.4081 6.0% 6.0% 10.1% 25% 35% 35% 5% 100%
*Sample period: January 2006 to October 2011.
**The risk-free rate used was the 3-month T-bills rate for the corresponding period, i.e. 1.85%.
6
8/3/2019 QMIM Final Project
http://slidepdf.com/reader/full/qmim-final-project 8/18
The corresponding chart is shown below:
4.0%
4.5%
5.0%
5.5%
6.0%
6.5%
6.0% 7.0% 8.0% 9.0% 10.0% 11.0%
P o r t f o l i o ' s A n n u a l R e t u r n s
Portfolio's Standard Deviation of Annual Returns
Efficient Frontier
( 6.95% , 5.20% )
Portfolio performance versus Benchmark
In order to compare the performance of our strategy portfolio against the benchmark for the out-of-
sample period we constructed an index for each of the portfolio’s returns. The optimal strategy
portfolio in the out-of-sample period outperformed the benchmark, with a total return of 14% and 500
basis point over the Benchmark. Furthermore, the annual return of the strategy was 6.64% with a
Sharpe ratio of 0.63, against the 0.54 of the Benchmark.
0.85
0.90
0.95
1.00
1.05
1.10
1.15
1.20
1.25
1-2010 04-2010 07-2010 10-2010 01-2011 04-2011 07-2011 10-2011
BMK Index
Strategy
Optimal portfolio: Trend-Following strategy performanc
Including the risk measures that will be detailed in the following sections, the next chart display the
performance of the strategy portfolio including stop-out actions when violation of risks limits occurred
(green line).
7
8/3/2019 QMIM Final Project
http://slidepdf.com/reader/full/qmim-final-project 9/18
0.85
0.90
0.95
1.00
1.05
1.10
1.15
1.20
1.25
1-2010 04-2010 07-2010 10-2010 01-2011 04-2011 07-2011 10-2011
BMK Index
Strategy
Strategy with stop
Optimal portfolio: Trend-Following strategy performanc
Individually, the performance for the out-sample Trend-Following strategy for each currency looks as
follow:
EuroEuro: Trend-Following strategy performance
Sharpe Ratio
0.80
0.85
0.90
0.95
1.00
1.05
1.10
1.15
1.20
1.25
1.30
Jan-10 Apr-10 Jul-10 Oct-10 Jan-11 Apr-11 Jul-11 Oct-11
BMK Index TF Strategy
Swiss Franc
As can be seen, most of the time the performance of the out-sample strategy outperformed the BMK
Swiss Franc: Trend-Following strategy performance
Sharpe Ratio
0.80
0.90
1.00
1.10
1.20
1.30
1.40
1.50
Jan-10 Apr-10 Jul-10 Oct-10 Jan-11 Apr-11 Jul-11 Oct-11
BMK Index strategy
8
8/3/2019 QMIM Final Project
http://slidepdf.com/reader/full/qmim-final-project 10/18
Swedish Krona
Swedish Krona: Trend-Following strategy performance
Sharpe Ratio
0.80
0.85
0.90
0.95
1.00
1.05
1.10
1.15
1.20
1.25
Jan-10 Apr-10 Jul-10 Oct-10 Jan-11 Apr-11 Jul-11 Oct-11
BMK index TF strategy
Risk Management
Drawdowns
One of the methods used to measure portfolio risk is the maximum drawdown, which was used in our
strategy to enhance its risk assessment aspect. Maximum drawdown measures the percentage drop in
cumulative portfolio return from a previously reached high. This metric gives a good indication of the
possible losses that the strategy portfolio can experience at any given point in time. The drawdown is
calculated according to the following formula:
W(t) – Max W(P)/Max W(P),
where W(t) is a portfolio value at time t Є [0, T], and Max W(P) is the maximum between W(t) and the
value of the portfolio at time t-1.
Months to recover, on the other hand, give a good indication of how quickly a portfolio can recover
losses. It means that at some point in time, the current maximum is identified, and then, given that
the portfolio is dropping in the drawdown, it could be found out, how long it takes for it to come again
to previously reached maximum.
For instance, one could make an investment in a strategy portfolio in January, 2010. In May, 2010, the
drawdown reaches a level of minus 7%. So, if the investor took his money back in May, 2010 that would
be his approximate loss. In order to recover, he needs to wait until the level of January, 2010 will be
9
8/3/2019 QMIM Final Project
http://slidepdf.com/reader/full/qmim-final-project 11/18
reached again. So, the drawdown model also enables to approximate the average period to recover. If
the drawdown is sharp, it should take longer to recover. The key is to understand the speed and depth
of a drawdown with the time it takes to recover these losses.
In real trading strategies, risk managers usually use the following rules regarding magnitude andduration of strategy’s drawdowns:
- all positions should be closed if 20% of drawdown is reached;
- there’s a warning for the risk manager if the level of 15% drawdown is reached;
- time to get out of a drawdown shouldn’t be longer than 1 year.
As can be seen in the graph below, the largest absolute values of our strategy’s drawdowns were
reached in May, 2010 and September, 2010, which correlates with the result that we got for the
assessment of relative-VaR. At the same time, the largest absolute drawdown value in out-of-sample
period was approximately 8.7% which, according to commonly used rules, is not a signal for closing
down our positions. The time to recovery was approximately from 6 to 9 months, which is not very
good, but still also doesn’t give us the signal to close positions. So, it could be concluded that, in our
case, relative-VaR metrics is more sensitive to strategy volatility, and drawdown metrics can be used
for identifying the most significant drops of the portfolio and estimating time to recovery.
Our drawdown assessment was carried out comparing to the benchmark’s drawdowns. And it could be
seen that the benchmark is not as risky as the strategy portfolio is and has the maximum absolute valueof drawdown = 6.3%. On, the other hand, both the strategy and the benchmark have quite long, 9 or
10-months, time to recovery (for example, for the benchmark it’s from May, 2010, till February, 2011).
10
8/3/2019 QMIM Final Project
http://slidepdf.com/reader/full/qmim-final-project 12/18
Relative VaR
Another risk management tool employed was the Relative VaR of our strategy portfolio against the
benchmark. In this way, we can assess how the portfolio may underperform the benchmark in terms of
risk and set the maximum level of risk that we want to incur with our strategy.
0.20
0.40
0.60
0.80
1.00
1.20
1.40
1.60
02/10 04/10 06/10 08/10 10/10 12/10 02/11 04/11 06/11 08/11 10/11
Relative value at risk over $100 invested-1 day and 0.95 confidence-
The maximum relative VaR reached for the strategy during the out-of-sample period was 140 basis
points. This means that the strategy could under-performed the benchmark by 140 basis points in one
over twenty days.
On the other hand, the relative VaR was used to determine “when” to close a position if the strategy
hit a certain relative-VaR level. We established a maximum level of relative VaR of 80 basis points for
the strategy, i.e. every time this level was overpassed, all the positions were closed. As can be seen in
the previous graph, the position was closed nine times during the out-of-sample period.
11
8/3/2019 QMIM Final Project
http://slidepdf.com/reader/full/qmim-final-project 13/18
Portfolio BenchmarkPortfolio
with stop
Returns 6.64% 4.05% 5.25%
SD 10.40% 7.32% 9.52%
Sharpe Ratio 0.632 0.544 0.545
This tool allowed us to reduce the strategy’s portfolio volatility with the cost of reducing the annual
return as well. Hence, the Sharpe ratio was also reduced, reaching the same level as the benchmark.
This risk constrains makes the strategy more versatile in the sense that it can be used for several
investors with different risk aversion profiles. Moreover, an improvement of the strategy can be done
with an optimal risk level in order to maximize the Sharpe ratio in the sample.
Conclusions
The EUR and CHF showed an outstanding performance in the out-of-sample period using the trend
following strategy. This could be because both currencies (specially the EUR) are used as “anti-dollar”
currencies, and USD has clear trends. In the case of the SEK, the underperformance could be due to the
high correlation with commodities (Oil), which present high volatility.
The portfolio approach let us compare the performance of the portfolio strategy which outperformed
the benchmark by 500 basis points, with a Sharpe ratio of 0.64 against 0.54 of the later. Furthermore,
including the stop-out rule the strategy also outperformed the benchmark.
Regarding risk management, the relative VaR was used to determine the stop-out signal, and the
drawdowns helped us to compare riskiness of the portfolios, i.e. as already mentioned the strategy
portfolio was riskier than the benchmark, and for both the time to recovery was quite long (9 or 10-
months). An alternative risk management tool that could be considered in other exercises is to set
maximal values for Drawdowns.
12
8/3/2019 QMIM Final Project
http://slidepdf.com/reader/full/qmim-final-project 14/18
Bibliography
Kauffman, Perry. The New Commodity Trading Systems and Methods. John Wiley and Sons. 1987.
Covel, Michael. Trend Following. Pearson Education. 2009.
Pardo, Robert. Design, Testing, and Optimization of Trading Systems. Wiley. 1992.
FX timing indicators. Societe Generale Cross Asset Research. April 1, 2010.
Trend Strategies in EM FX. Diversifying the carry trade. Barclays Capital Systematic Strategies. June
3,2011.
13
8/3/2019 QMIM Final Project
http://slidepdf.com/reader/full/qmim-final-project 15/18
Appendix
a. Matlab code: Trend-following strategy
%the asset has to be ordered from newest to oldest
numMA=60;
MMA=zeros(length(x)-numMA,numMA);
for i=1:numMA %Matrix with the moving averages of the selected asset
for j=1:length(x)-i+1
average=0;
for k=j:j+i-1average=average+x(k);
end
MMA(j,i)=average/i;
end
end
fd=zeros(length(x)-1,numMA); %matrix with the first difference (MA(t)-MA(t-1))
for j=1:numMA
for i=1:length(x)-j
fd(i,j)=MMA(i,j)-MMA(i+1,j);
end
end
sizefd=size(fd);
MMA_fd=zeros(sizefd(1,1),numMA); %Matrix with the moving averages of the first difference
for i=1:numMA
for j=1:sizefd(1,1)-2*i+2
average=0;
for k=j:j+i-1
14
8/3/2019 QMIM Final Project
http://slidepdf.com/reader/full/qmim-final-project 16/18
average=average+fd(k,i);
end
MMA_fd(j,i)=average/i;
end
end
sizeMMA_fd=size(MMA_fd);
sd=zeros(sizeMMA_fd(1,1),numMA); %matrix with the second difference (MMA_fd(t)-MAA_fd(t-1))
for j=1:numMA
for i=1:sizeMMA_fd(1,1)-2*j+1
sd(i,j)=MMA_fd(i,j)-MMA_fd(i+1,j);
end
end
b. Trading strategy - Signals long/short/neutral position
days = min(731,sizeMMA_fd(1,1)-2*numMA+1); %days that we are going to use the backtest
signal=zeros(min(days,sizeMMA_fd(1,1)-2*j+1),numMA);
for j=1:numMA
back=days;
for i=1:min(days,sizeMMA_fd(1,1)-2*numMA+1)
if fd(back,j)>0 & sd(back,j)>0
signal(back,j)=1;
elseif fd(back,j)<0 & sd(back,j)<0
signal(back,j)=-1;
else
signal(back,j)=0;
end
back=days-i;
end
end
%backtest P/L; creates an index with the Yield to date
back=days;
PL=zeros(min(days,sizeMMA_fd(1,1)-2*numMA+1),numMA);
initial_investment=1;
PL(back,:)=initial_investment;
for j=1:numMA
back=days;
15
8/3/2019 QMIM Final Project
http://slidepdf.com/reader/full/qmim-final-project 17/18
8/3/2019 QMIM Final Project
http://slidepdf.com/reader/full/qmim-final-project 18/18
:=False, Transpose:=False
Sheets("Modelo MV (usd)").Select
Range("G4").Select
Selection.Copy
Sheets("Modelo MV (usd)").Select
Cells(5 + escenarios, 31).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Modelo MV (usd)").Select
Range("C4:C13").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Modelo MV (usd)").Select
Range(Cells(5 + escenarios, 32), Cells(5 + escenarios, 55)).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=True
Next escenarios
Application.ScreenUpdating = True
End Sub
17