(credit attribution: https://cssanalytics.wordpress.com/2017/11/15/adaptive-volatility/)
Aim: Get a better position sizing than [target_vol / realized_vol_{t-1}], using a more 'adaptive' volatility that varies its lookback period according to market conditions.
The simplest method is to use the R-squared of the regression of prices vs time:
1. high R-squared indicates a trending market -> use short lookback periods
2. low R-squared instead implies a mean-reverting market -> lengthen lookback periods.
Such a R_squared value is translated into the alpha of an EMA using an exponential function (see code).
Hence the (theorical) daily exposure is:
target_vol / sqrt( EMA_{t-1}(squared rturns, alpha_t) * 252)
To limit excessive trading, rebalacing happens only if theoretical exposure above a certain threshold (say 5%).
Concept here shown for a simple static portfolio of two ETFs: SPY and TLT.
A more interesting use of this position sizing scheme is when using algorithms with long periodical rebalacings, say monthly or quarterly.
Valery T
I added gold GLD and results are worse:
Alex Muci
2019 YtD (Jan to Aug included) Sharpe of 4.1 !
Spacetime
Hi Alex, thanks for sharing this model. I keep receiving key error. I have spent countless hours trying to fix this key issue, but not having any breakthrough. I have tried to check daily_rtrn and prices if key exists, but stilll no luck. Will you care to shed some light on this?
Thank You!
Runtime Error: In Scheduled Event 'SPY: EveryDay: SPY: -90 min after MarketOpen', Trying to retrieve an element from a collection using a key that does not exist in that collection throws a KeyError exception. To prevent the exception, ensure that the SPY key exist in the collection and/or that collection is not empty. at rebalance in main.py:line 144 at pos_sizing in main.py:line 194 :: vol = daily_rtrn[tkr.Value].ewm(alpha=alpha_).std() # alpha = 2/(span+1) = 1-exp(log(0.5)/halflife) KeyError : 'SPY'
Alexandre Catarino
Hi spacetime (and Alex Muci )
We advise using Symbol object as key/index whenever possible and in Alex' algorithms, he is using the ticker (Symbol.Value) instead. Please find the attached backtest with some changes that address the runtime error.
Spacetime
Hi Alex (Alexandre), Thank you very much for fixing the model and providing an explanation. I will keep your advice in mind for future.
Alex Muci
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!