Overall Statistics
Total Trades
1
Average Win
0%
Average Loss
0%
Compounding Annual Return
94.842%
Drawdown
36.400%
Expectancy
0
Net Profit
0%
Sharpe Ratio
1.155
Loss Rate
0%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.641
Beta
-0.584
Annual Standard Deviation
0.521
Annual Variance
0.271
Information Ratio
0.977
Tracking Error
0.546
Treynor Ratio
-1.029
Total Fees
$4.84
namespace QuantConnect 
{   
    /*
    *   QuantConnect University: Futures Example
    *
    *   QuantConnect allows importing generic data sources! This example demonstrates importing a futures
    *   data from the popular open data source Quandl.
    *
    *   QuantConnect has a special deal with Quandl giving you access to Stevens Continuous Futurs (SCF) for free. 
    *   If you'd like to download SCF for local backtesting, you can download it through Quandl.com.
    */
    public class VolatilityETN : QCAlgorithm
    {
        string xiv = "XIV";
        string tvix = "TVIX";
        decimal IVTS = new decimal();
        string VIX = "YAHOO/INDEX_VIX";
        string VXV = "CBOEFE/INDEX_VXV";
        
        DateTime sampledToday = DateTime.Now;
        
        //Initialize the data and resolution you require for your strategy:
        public override void Initialize()
        {
            SetStartDate(2016, 1, 1);         
            SetEndDate(DateTime.Now.Date.AddDays(-1));
            SetCash(25000);
            AddSecurity(SecurityType.Equity, xiv, Resolution.Minute);
            AddSecurity(SecurityType.Equity, tvix, Resolution.Minute);
            
            AddData<Quandl>(VXV, Resolution.Daily);
            AddData<Quandl>(VIX, Resolution.Daily);
        }

        /// <summary>
        /// Event - v3.0 DATA EVENT HANDLER: Basic template for user to override for receiving all subscription data in a single event
        /// </summary>
        /// <code>
        /// TradeBars bars = slice.Bars;
        /// Ticks ticks = slice.Ticks;
        /// TradeBar spy = slice["SPY"];
        /// List<Tick> aaplTicks = slice["AAPL"]
        /// Quandl oil = slice["OIL"]
        /// dynamic anySymbol = slice[symbol];
        /// DataDictionary<Quandl> allQuandlData = slice.Get<Quand>
        /// Quandl oil = slice.Get<Quandl>("OIL")
        /// </code>
        /// <param name="slice">The current slice of data keyed by symbol string</param>
        public void OnData(Slice data) 
        {   
            // gets all Quandl data from our 'Slice' object
            var quandls = data.Get<Quandl>();
            
            if (!quandls.ContainsKey(VIX) || !quandls.ContainsKey(VXV)) return;
         
            // add logic to have orders placed once / day
            
            // IVTS = VIX / VXV
            IVTS = quandls[VXV].Value / quandls[VIX].Value;
            
            if (IVTS < 0.923m) 
            {
				Liquidate(xiv);
				SetHoldings(xiv, -1);
			} else 
			{
            	Liquidate(xiv);
				SetHoldings(xiv, 1);
			}
        }
    }
}