davesaint86 725 posts msg #135200 - Ignore davesaint86 |
3/30/2017 11:40:39 AM
I think the strategy below is different from your Sharpe Ratio Allocation filter. Can the one below be built in SF?
For my SPY/TLT adaptive allocation strategy I tweaked the Sharpe formula a little bit. Normally the Sharpe ratio is calculated by Sharpe = rd/sd with rd=mean daily return and sd= standard deviation of daily returns. I don’t use the risk free rate, as I only use the Sharpe ratio to do a ranking. My algorithm uses the modified Sharpe formula Sharpe = rd/(sd^f) with f=volatility factor. The f factor allows me to change the importance of volatility.
If f=0, then sd^0=1 and the ranking algorithm will choose the composition with the highest performance without considering volatility.
If f=1, then I have the normal Sharpe formula.
If f>1, then I rather want to find SPY-TLT combinations with a low volatility. With high f values, the algorithm becomes a “minimum variance” or “minimum volatility” algorithm.
To get good results, the f factor should normally be higher than 1. This way you do not need to rebalance too much. In a whipsaw market, rebalancing also has the negative effect of selling low and buying high on small intermediate market corrections. This is why a system which considers only performance will not do well.
The good f factor for a system can be found by “walk forward” optimization iterations of your backtests. Normally a good value for f is about 2, but the factor changes slightly, adapting to the current market conditions.
SYMLIST(spy, tlt)
SET{perf1A, ma(3) 60 days ago}
SET{perf1b, MA(3) / perf1a}
SET{perf, perf1b - 1}
SET{var1, perf*100}
SET{rfr, ind(^irx,close)}
SET{RISKFREERETURN, rfr/100}
SET{perf63, perf - RISKFREERETURN}
SET{STD63, CSTDDEV(CLOSE,63)}
SET{VOL63a, STD63 / MA(63)}
SET{vol63, vol63a * 100}
/*CALCULATION OF SHARPE RATIO - ANNUALIZED*/
SET{SHARPE1a, perf63 / VOL63a}
set{sharpe, sharpe1a * 0.5}
set{var1a, IND(spy, var1)}
set{var1b, IND(tlt, var1)}
SET{RANK1A, COUNT(var1 is above var1a,1)}
SET{RANK1B, COUNT(var1 is above var1b,1)}
SET{RANK1C, RANK1A + RANK1B}
SET{RANK, 2 - RANK1C}
set{var2a, IND(spy, sharpe)}
set{var2b, IND(tlt, sharpe)}
SET{var3a, COUNT(var2a is above 0,1)}
SET{var3b, COUNT(var2b is above 0,1)}
SET{var4a, var2A * var3a}
SET{var4b, var2b * var3b}
set{var5a, var4a + var4b}
SET{allocation1, sharpe / var5a}
set{allocation2, allocation1 * count(sharpe above 0,1)}
set{allocation, allocation2 *100}
|