Back

VXV-VIX Contango Ratio Strategy

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 vixdata = new RollingWindow(1);
//RollingWindow vxvdata = new RollingWindow(1);

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
}
*/

}
}
Update Backtest








Another option is liquidate when ratio over (0.923) and go short when ratio under (0.923).
0

Hey Andrew, thanks for sharing! You can attach a backtest using the 'Select Project' and 'Attach Backtest Result' drop downs. You'll need to specify both, a project and a backtest for it to attach.

Also, have a peek at this thread for some things to think about when using Quandl data in a live algorithm.

You can add data from Quandl pretty easily, clone the QCU How Do I Import Quandl Data? algorithm. You can access the QCU (QuantConnect University) on the left hand side in the terminal.

The short story is you can add Quandl data using the following: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!
0

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 - did you have a chance to tweak the code? I would love to see a backtest! I am newer to C# myself
0


Update Backtest





0

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.


Loading...

This discussion is closed