A simple, yet untradable (unstable), VIX Strategy using two ETFs.
It has a simple binary (all or nothing) allocation:
1. long vol (buy VXX),
2. short vol (buy XIV),
3. none.
Signal is just the standard RSI but used as a momentum (rather than a contrarian) indicator. Levels are also those standard to indicate overbought or oversold securities (i.e. 85, 70, 30, 15).
Strategy is, however, a pie in the sky... a simple daily VIX/VXV ratio signal still more stable/reliable.
Thomas Chang
I couldn't see you have used any VIX data directly. You use its derivate - futures.
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.
Alex Muci
In the above strategy, as mentioned, I used the RSI on the ETF that sell the first 3 VIX futures, aptly named 'XIV'. The signal based on hourly data, whilst trading is potentially every 2h.
I'll post the other version using the the VIX and VXV indices later. Signal and trading frequency will be daily.
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.
Petter Hansson
Nice! I like digging on the Quantopian forums for various VIX strategies and I've translated a couple I'll consider putting up here. Not all of them work all the time, but maybe one could add the signals of a bunch of them.
My one concern with VIX strategies at the moment is the ever growing popularity of shorting vol and what will happen when another 2008 like disaster arrives. I wrote a new strategy in November last year that would have returned me 150% but I haven't dared trading it (when I did, of course North Korea fired a missile over Japan so I immediately got the stoploss logic tested).
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.
Alex Muci
Petter, I share your worry: most VIX strategies on Quantopian, unfortunately, won't wistand another 2008 - they tend to sell vol when the VIX is just above 20-25 forgetting that the VIX went well over 90 during 2008... clearly just calibrated on the recent 5-7y benign environment, besides too many parameters (i.e. overfitted). True, in the last few years, simply selling vol (e.g. being long XIV) was a great strategy - but, as you rightly mentioned, the point is to avoid disaster when it strikes (and it will).
In a nutshell, we need to be mostly short vol - around 8-9 times out of 10 - whilst being out of the market (or long vol) very few times. One risk to avoid is being whipsawed (getting in and out of a position without catching the trend).
The attached code is a simplified strategy - which we may backtest all the way back to, and before, 2008 (using the index underlying the VXX, freely available from S&P DJ website) : it goes short volatility (i.e. long XIV) if the VIX curve is in contago (VIX/VXV < 0.95), and long vol (i.e. long VXX) if curve in backwardation. In addition, it can withstand whipsaw by using a median to filter 1 or 2 day spikes.
Combined with a momentum strategy, like the earlier one above (which cannot be backtested), may lead to a good strategy.
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.
Thomas Chang
Hi Alex,
1.
Thanks for the sample code, especially your code for getting the VIX datas. It's complex!
I read a post here "
" and find there is a much more simple way to get the CBOE datas. But it is in C#. I've asked if the QC has a Python version. But till now no answer.
2.
To what you discuss about the year of 2008. Yes you all are right. Most of the VIX strategies use the XIV. But the inception of XIV is Nov 29, 2010.
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.
Thomas Chang
Hi Alex,
I try to get the VIX data not from the OnData() as what you do but from a schedule function (see attached code) but fails. Maybe you have an idea? (take out the comment on line 62, 63)
Thanks!
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.
Thomas Chang
I've figured out.
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.
Lu Chen
I am very new to this technology.
So I am trying to get VIX value from Quandl. I did the following in the Initialize function. How can I get the value , (Close value) in OnData slice part ? Please help out . Thank you
self.quandlCode = "CHRIS/CBOE_VX1"
self.AddData[QuandlFuture](self.quandlCode, Resolution.Daily)
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.
Mohammed Khalfan
Greetings, interesting stuff. I'm a Quantopian migrant, and a fan of XIV strategies (I coded XIV-Shotgun, and Ballistic-XIV-VXX over on Quantopian). I'm working on porting those algos over to QC, among other things.
@Alex: Why do you call the algo in your original post a 'pie in the sky'? Is your second algo an example of a 'simple daily VIX/VXV ratio signal' ? Lastly, why do you say that combining the vix/vxv with a momentum strategy cannot be backtested?
@Peter: I see you're trading XIV-Sniper (I saw your broadcast). I've almost finished coding it too here on QC. I was live trading this on Quantopian before they shut down. For small accounts ($1k - $10k), it's a great algo.
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.
Alex Muci
Quickly - it is Saturday and I shouldn't be in front of a computer ;-)
@ Thomas
I used PythonData (for custom data) to get the data straight from the original source (i.e. CBOE).
You can probably use Quandl and get it with less code (1-2 lines vs. 10 or more of mine) - I just prefer the more general/flexible way and, besides, it is more explicit (less error prone) since the close level columns for VIX and VXV are, respectively, 'Close VIX' and just 'Close'. Go figure why,
Glad it is helpful, but it is all thanks to the great examples of @Alexandre Catarino (from QC staff).
It is true that the XIV started traded only in late 2010. But you can easily re-construct (using pandas or even Excel)
VXX and XIV back to 1990 by using their underlying indices.
For example, for the XIV:
i. go to S&PDJ website: http://us.spindices.com/indices/strategy/sp-500-vix-short-term-futures-inverse-daily-index-tr
ii. download last 10y (late 2007 to now) - if you've got Bloomberg then you can get 1-2 years more for the inverse and likely more for the one underlying the VXX.
iii. subtract the fees/TER of the ETF, if you really want (it won't make much of a difference).
@ Mohamed:
By reconstructing XIV or VXX (as mentioned above), you can now back-test strategies with at most daily trades during 2008:
1. you can definetely get a good idea regarding drawdown/returns for the second strategy I posted above (VIX strategy based on VIX/VXV ratio), BUT
2. wrt the first strategy (based on hourly data) you have to buy VX fut granular data which it makes costly, laborious and - above all - still imprecise (to the point to make it unrealiable for such small timeframe). Not worthy.
I said that the 1st (RIS-based) strategy is a pie in the sky (i.e. unreliable) because it is too dependent on the RSI period: if =6 (like the posted one or some on Quantopian's) performance is great except for the last 1-1.5y, the standard rsi period of 14 instead works marvellously well in the last couple of years but poorly in the 2012-2015 period. What's worse is that the choices in the middle (self._period = 8 to 12) are even more random and non-intuitive.
In other words, even if there is just a single parameter to optimise there is not a stable interval for the optimum - say great for =8 yet still good for 6 or 10 and so on. On top of that, I have no idea how this strategy could have performed during 2008. Trading this on its own is a too big leap of faith for me.
But I think that not all is lost: if you combine the two simple strategies above (you may want to get a longer RSI period and a shorter median) then you get a much more stable/robust strategy with Sharpe ratios of 1.8-2 and drawdown < 20%. Pretty decent for such an undiversified strategy.
If we can get 1 more unrelated strategies to combine, well... A Sharpe of 1.8-2. is achievable with a momentum (RSI) and a contango/backwardation ideas (the two strat above). We need a mean-reverting one, which is more tricky.
What I would avoid is too many parameters or convoluted strategies with no economic background. I'd rather combine two-three simple strategies and trade the net order.
Alex
PS: got a question too: does anyone know how to get the live VIX from Interactive Brokers when deploying algos via QC?
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.
Alex Muci
Forgot to say that by combining the two strategies you get a more stable performance that is much less dependent on the choice of parameters. The point is to combine enough of them to make params of the single almost irrelevant.
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.
Mohammed Khalfan
Alex, thank you for your feedback. I will try to combine the strategies, looks interesting!
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.
Thomas Chang
@Lu Chen:
If you just want to get the VIX values, you can simply use Alex's code:
vix_open = data["VIX"].Open
self.Debug("VIX_Data:%s" %ratio_d)
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.
Thomas Chang
@Alex,
I am not sure if there is a "prediction bias" in your algo, excatly to say in your VIX values.
Here I cloned your algo and remove a lot of the codes and just to get and print/Log the VIX_Open. If you run the backtest you can see the VIX_Open is excat the same as from the CBOE csv file as follow:
...
2017-10-03 00:00:00 :VIX_Open: 9.30000
2017-10-04 00:00:00 :VIX_Open: 9.53000
2017-10-05 00:00:00 :VIX_Open: 9.48000
2017-10-06 00:00:00 :VIX_Open: 9.23000
But if do the same in QuantOpian, you get the following:
...
2017-10-03 00:00:00 :VIX_Open: 9.59000
2017-10-04 00:00:00 :VIX_Open: 9.30000
2017-10-05 00:00:00 :VIX_Open: 9.53000
2017-10-06 00:00:00 :VIX_Open: 9.48000
This means, the VIX values from you algo has "prediction bias". Am I right?
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.
Alex Muci
Hi Thomas,
Clever obsevation.
I noticed that. That's why I wrote the following comment in the code:
ratio_d = data["VIX"].Open / data["VXV"].Open "# .Close will have look-ahead bias...'Basically I am assuming that I am able to get the VIX or VXV Open on that day, which is in theory a fair assumptions, and then trade a split second after that. If, instead, I used the Close in my code then it would definetely be wrong since I would be trading on information available only much later in the day -- try to change the .Open into .Close in 'ratio_d' and see the whopping difference a look-ahead bias makes!).
Quantopian - on the other end - to avoid any risk of look-ahead bias (particularly for Close), is delaying all prices by one day. Safer.
In practice, if we relay only on the CBOE .cvs file then we have to use the previous day Close in live trading (you can easily change the code to do that). This is, incidentally, the reason why I asked in the 'PS' above if anyone knew how to get the 'live' VIX from Interactive Brokers - unfortunately, it appears that live VIX prices are not possible because QC only broadcsts prices from IB and not indices too.
To be double sure just compare Quantopian using .Close (which is the previous day one) and QuantConnect same day Open. I expect the difference to be minimal.
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.
Jared Broad
Correct Thomas -- you need to adjust for the resolution of the data as the CSV's are daily and we default to minute resolution. Without specifying the width of the bars it assumes a minute/point value and the close values are available immediately vs being delayed 1 day.
self.AddData(CboeVix, "VIX", Resolution.Daily)
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.
Alex Muci
Jared Broad I have adjusted the resolution to daily as you suggested (adding 'Resolution.Daily' for both VIX and VXV in the second algo above). Backtesting is, of course, quicker now (bc OnData runs daily), but the VIX Open still do not seem to be delayed as per Thomas expectations / Quantopian. Am I missing something?
@ Thomas, do you get the new result?
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.
Thomas Chang
@Alex,
Ok, I think I figured out the delay. One has to use the following code to get the VIX except using the Resolution.Daily:
self.Securities['VIX'].Close
Could you have a try?
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.
Thomas Chang
But I notice no matter you use the .Close or .Open, the returned VIX is always the Close. This is somewhat interessting.
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.
Jared Broad
Complex questions but will try explain it --
Time is a continuous span; but time bars like this have a start and end time - denoted in LEAN by Time and EndTime respectively. BaseData is default a continuous flow of time. This means the time you're setting is the time the data will appear in LEAN.
In your case above the time is set as midnight on the date with 4 values on the data - giving you the forward looking bias. Using the current code you really you should set EndTime to be index.EndTime = data.Time.AddDays(1) -- this would reflect the fact its time +1 period; or use data timestamped according to when the data was released / made public.
Perhaps a better way would be inherit from TradeBar class which is designed to be used with periods. In this case you would set OHLC like you do here; and bar.Time = data.Time; but you must also set the bar period: bar.Period = TimeSpan.FromDays(1).
Finally another importing cause for look forward bias in backtesting is misunderstanding of timezones. Make sure your "daily" bars are in the same timezone as your algorithm. If they are UTC days you can have a 4 hour look into the future. This doesn't matter much for US market data like this but custom sources like BTC/Crypto are often internationally focused and you need to set their timezones appropriately.
@Thomas - the value of the VIX bar is whatever you set to index.Value
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.
Frank Norman
This would lead to higher performing Alpha Streams. I would add it to the arsenal.
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.
Andrew martin czeizler
Is this being included in the backtest metrics?
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.
Jack Simonson
We haven't included it yet into the backtest metrics, but it's something that we're considering as well.
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.
Tim Bohmann
I would like to see this in the backtest metrics. This would be a quick "sanity test" when backtesting.
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.
Pangyuteng
Glad to see that Quantconnect seems to be agile and willing to update methods for their algo selection. I also find it comforting that Lean is opensource, so I can check the implementation and their test cases. :)
SPY notebook SR: 0.836, PSR: 50.000% Lean SR: 0.900, PSR: 41.185% ---- SHY notebook SR: 1.237, PSR: 68.901% Lean SR: 1.224, PSR: 69.799% ---- QQQ notebook SR: 0.910, PSR: 52.476% Lean SR: 0.990, PSR: 49.063% ---- AMZN notebook SR: 1.218, PSR: 83.669% Lean SR: 1.339, PSR: 78.661% ---- GE notebook SR: -0.458, PSR: 10.897% Lean SR: -0.306, PSR: 0.159% ----For those that want to do some quick and dirty backtest or optimization/investigation in research, please do keep in mind the inevitable computation differences between LEAN and simple PSR computation in notebook. I think this is one of those little but important things most engineers/data scientists have to deal with when working among different environments. Anyways... per Alexandra's response, "rolling PSR" is computed by LEAN (I can't seem to figure out where the rolling part is though in github), while Jack's PSR is a single value derived from one stream of returns. Below shows you the difference for Sharpe Ratio (SR) and PSR for a few tickers if you buy-and-hold in the same timeframe between notebook (using annualized SR) and Lean. I would expect PSR for SPY to be a bit closer to 50% from LEAN. Avid notebook users... beware!
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.
Kamer Ali YUKSEL
I would be more than glad if someone can also share how to calculate rolling PSR.
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.
Kamer Ali YUKSEL
I also have a question, why you haven't utilized Deflated Sharpe Ratio? That seems to be an extension over PSR.
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.
Jared Broad
DSR was not deterministic, and required analysis of many backtests. PSR was chosen because it could be self contained with a single analysis.
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.
Kamer Ali YUKSEL
Hello Jared, thanks for letting me know.!I have a small objection about PSR. Since that it uses a long-only SPY benchmark, it does not make perfect sense for long-short portfolios or a long-only ETF portfolio that includes some inverse ETF(s), such as the current universe. I sometimes obtain better results in many of the metrics but the PSR is lower. To sum up, it is not a very good metric in terms of taking the market-neutrality into account (except for a long-only portfolio that does not include any Inverse ETFs - which is not valid for the current competition universe).
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.
Jared Broad
We chose not to use SPY as the benchmark but a fixed Sharpe-ratio of 1.0 to make the measurement cross-asset / cross-strategy type; so the PSR readings in LEAN's case are the probability the real algorithm returns are greater than 1.0 Sharpe ratio.
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.
Kamer Ali YUKSEL
Just to let you know, I encountered another implementation of PSR in some other source codes that I have checked. The first one below is that other implementation and the second one below is the implementation in this thread. I did not yet compare the output of those but they seemed to be different to me. I would welcome an advise on this.
std = np.sqrt(1 - (sps.skew(ret)*sharpe) + sharpe**2 * (sps.kurtosis(ret)-1)/4)
return sps.norm.cdf(sharpe * np.sqrt(len(ret)-1) / std)
std = 1 - (sps.skew(ret) * sharpe) + ((sps.kurtosis(ret)-1)/4) * sharpe
return sps.norm.cdf(sharpe / np.sqrt( std / (len(ret) - 1)))
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.
Rahul Chowdhury
Hey Kamer,
The other implementation of PSR you provided is actually the correct implementation as defined by the paper The Sharpe Ratio Efficient Fronter by Bailey D. & Prado M. (2012). That equation is the one that is defined in LEAN and is the correct one. However, we made a small mistake in copying it over in the journal post, which we've since fixed. There was a missing factor of Sharpe in the kurtosis term. With the added Sharpe factor, the two equations are the same, just differently represented. Thanks for pointing it out!
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.
Kamer Ali YUKSEL
Hello Rahul, Yeah, I also verified that later but did not want to write it here to make a conclusion :) Thnx!
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.
Apollos Hill
So i am finally rereading this thread. Sorrry. I know its kind of old now and has been added ot the Alpha criteria. I'm looking for tips on how to increase my PSR past 50 .
" the Probabilistic Sharpe Ratio is an atemporal measure of strategy performance expressed in terms of probability of skill beyond a given benchmark..." If we are using 1.0 Sharpe as a benchmark and not SPY...if my strategy is doing 250% return over a 5 year backtest, how am i only at 25-50% PSR and 0.8 sharpe? IS it suggesting that I somehow am not maximizing the profit potential of my strategy? I don't want to post a backtest here but i am in forex, trading 4 out of the 8 major pairs. I can't trade all the pairs or else i'm over exposed. I'm trading on weekly bars and holding for months using million dollar positions. I'm also in positions as much as i can be without over trading. 250% over 5 years is about 50% annual returns. Is that not worthy of a 1.0 sharpe? I doubt the assets that Ted posted above (with LEan SR thanks) could achieve these returns.
Appreciate the help on increasing my PSR so i can lease this alpha stream.
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.
Jared Broad
Hi Apollos, it means the volatility of the strategy is too high. Perhaps you can invest smaller, or risk-adjusted positions somehow? Could you invest for shorter periods to help reduce the exposure to swings of the market?
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.
Apollos Hill
Hi Jared
I tried only investing 1% per trade. I'm in the process of seeing if i can go to daily bars instead of weekly. Right now i have a nice 45degree slope up. It doesn't seem volatile to me. My Annual Variance and my Beta are 0.00. Not sure if that helps you or not. my sharpe is 0.729 so i guess PSR at 25% is saying that i have a 25% chance that my sharpe will be over 1% . So i need to improve my money making, without increasing drawdown, correct? 10% DD on a 48% total return over 5 years. (nowthat i changed to 1% positions)
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.
Rahul Chowdhury
Hey Apollos,
There is currently an issue with beta calculation for daily resolution data which produces 0 beta for all strategies. The true beta of your strategy may actually be larger. If your strategy is trading the same symbols for the same duration, changing position sizes will not dramatically change your PSR because your returns and drawdowns will scale proportionally. Instead try shortening your insight period or changing how you emit insights.
> my sharpe is 0.729 so i guess PSR at 25% is saying that i have a 25% chance that my sharpe will be over 1%
It means there's a 25% change your live-Sharpe is greater than 1.0; (in part because the backtesting Sharpe is 0.7)
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.
Ritaelyn
Hi Jared,
What's your thoughts of allowing for a sortino ratio as another means for submission? One thing I'd like to submit to alpha is about 3.60 sortino but it's under 1.0 sharpe, as sharpe unfortunately penalizes both upside and downside volatility equally.
Thanks for considering it!
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.
Hector Barrio
Hello Ritaelyn, I agree with you. Any equity trading during the COVID instability will be highly penalized by SR/PSR metrics, even if properly hedged and/or profitable. The normality assumption of the sharpe ratio can, in extreme cases, make very large positive returns in possitively skewed strategies undesirable. It is also a possibilty to have strategies that could "fish" for higher PSR by extending the test period to low volatility-low return periods (cool periods) even at equity loss.
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.
.ekz. INVESTOR
+1 to Ritaelyn point. I'd love to see Sortino Ratio. From what I've been reading, sharpe ratio (and subsequently PSR as well) is not the best perf indicator for trend following strategies.
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!