Using the Ratio between VXV and VIX we can calculate whether UVXY is in backwardation or contango.
Ratio = VXV/VIX
If Ratio < 0.923, then UVXY/VXX is in Contango, we should short the position
If Ratio > 0.923, then UVXY/VXX is in Backwardation, we should go long
Coming from Python, my C# skills are not up to par. I've got tested Python code (with numerous enhancements) that trades this strategy. Below is my feeble attempt to convert it to C# so that everyone can take advantage of it. I did not know how to pull the data from Quandl, so I left that part out.
I'd use VXX, but you can use UVXY for much greater profits, but drawdowns will be HIGH!
using System;
namespace QuantConnect.Algorithm
{
public class Backwardation : QCAlgorithm
{
// UVXY performs better with much higher drawdowns.
static string symbol = "VXX";
decimal ratio = 0;
// Add VXV and VIX data from Quandl or Yahoo here
// YAHOO/INDEX_VIX
// CBOE/VXV
//RollingWindow
//RollingWindow
public override void Initialize()
{
SetStartDate(2015, 2, 1);
SetEndDate(2015, 9, 9);
SetCash(100000);
AddSecurity(SecurityType.Equity, symbol, Resolution.Minute);
SetWarmup(TimeSpan.FromDays(5));
}
private DateTime last = DateTime.MinValue;
public void OnData(TradeBars data)
{
if (IsWarmingUp) return;
if (Time.Date != last.Date) {
last = Time;
// Calculate ratio of vix to vxv here
// ratio = vixdata/vxvdata;
// Once we have the ratio, we decide what to do
if (ratio < 0.923m) {
// A ratio under 0.923 indicates contango position
// sell short
if (Securities [symbol].Holdings.Quantity <= 0) {
SetHoldings(symbol, -1.5);
}
} else {
// A ratio over 0.923 indicates backwardation, go long
//buy
if (Securities [symbol].Holdings.Quantity >= 0) {
SetHoldings(symbol, 1.5);
}
}
}
}
// Quandl Datahandlers
/*
public void OnData(Quandl data) {
// Handle QUANDL DATA
}
*/
}
}
Andrew Nguyen
Michael Handschuh
AddData("CBOE/VIX", Resolution.Daily);
The string "CBOE/VIX" can be obtained from the quandl website, here's the CBOE/VIX page. When defining ratios I like to make an indicator for it so I don't have to worry about updating it. We can easily define a ratio between two security's using something like the following:// first add our data AddSecurity(SecurityType.Equity, "SPY"); AddSecurity(SecurityType.Equity, "AAPL"); // this is an indicator that will always have the most recent value of SPY close var spyClose = Identity("SPY"); // this is an indicator that will always have the most recent value of AAPL close var aaplClose = Identity("AAPL"); // here we define the ratio of SPY/AAPL using the Over method, this is a new indicator // that will have the result of SPY divided by AAPL spy_over_aapl = spyClose.Over(aaplClose);
Give the above a shot and share the algorithm back here if you run into more issues. Also, don't hesitate to ask any C# questions -- we're here to help!Michael Manus
more info here:
https://www.quantconnect.com/forum/discussion/1545/easy-volatility-investing
Andrew Nguyen
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!