Overall Statistics
Total Orders
49
Average Win
2.56%
Average Loss
-1.08%
Compounding Annual Return
7.148%
Drawdown
8.400%
Expectancy
0.688
Net Profit
31.780%
Sharpe Ratio
0.714
Sortino Ratio
0.788
Probabilistic Sharpe Ratio
38.250%
Loss Rate
50%
Win Rate
50%
Profit-Loss Ratio
2.38
Alpha
0.003
Beta
0.491
Annual Standard Deviation
0.056
Annual Variance
0.003
Information Ratio
-0.614
Tracking Error
0.058
Treynor Ratio
0.082
Total Fees
$49.00
Estimated Strategy Capacity
$640000000.00
Lowest Capacity Asset
SPY R735QTJ8XC9X
Portfolio Turnover
2.13%
#region imports
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Globalization;
    using System.Drawing;
    using QuantConnect;
    using System.Text.RegularExpressions;
    using QuantConnect.Algorithm.Framework;
    using QuantConnect.Algorithm.Framework.Selection;
    using QuantConnect.Algorithm.Framework.Alphas;
    using QuantConnect.Algorithm.Framework.Portfolio;
    using QuantConnect.Algorithm.Framework.Execution;
    using QuantConnect.Algorithm.Framework.Risk;
    using QuantConnect.Algorithm.Selection;
    using QuantConnect.Parameters;
    using QuantConnect.Benchmarks;
    using QuantConnect.Brokerages;
    using QuantConnect.Util;
    using QuantConnect.Interfaces;
    using QuantConnect.Algorithm;
    using QuantConnect.Indicators;
    using QuantConnect.Data;
    using QuantConnect.Data.Consolidators;
    using QuantConnect.Data.Custom;
    using QuantConnect.DataSource;
    using QuantConnect.Data.Fundamental;
    using QuantConnect.Data.Market;
    using QuantConnect.Data.UniverseSelection;
    using QuantConnect.Notifications;
    using QuantConnect.Orders;
    using QuantConnect.Orders.Fees;
    using QuantConnect.Orders.Fills;
    using QuantConnect.Orders.Slippage;
    using QuantConnect.Scheduling;
    using QuantConnect.Securities;
    using QuantConnect.Securities.Equity;
    using QuantConnect.Securities.Future;
    using QuantConnect.Securities.Option;
    using QuantConnect.Securities.Forex;
    using QuantConnect.Securities.Crypto;   
    using QuantConnect.Securities.Interfaces;
    using QuantConnect.Storage;
    using QCAlgorithmFramework = QuantConnect.Algorithm.QCAlgorithm;
    using QCAlgorithmFrameworkBridge = QuantConnect.Algorithm.QCAlgorithm;
#endregion

using QuantConnect.DataSource;

namespace QuantConnect
{
    public class CBOEDataAlgorithmAlgorithm : QCAlgorithm
    {
        private Symbol _spy;
        private Symbol _vix;
        private Symbol _vxv;
        private SimpleMovingAverage _smaVIX;
        private SimpleMovingAverage _smaVXV;
        private IndicatorBase _ratio;

        public override void Initialize()
        {
            SetStartDate(2014, 1, 1);
            SetEndDate(2018, 1, 1);
            SetCash(25000);

            _spy = AddEquity("SPY", Resolution.Daily).Symbol;

            // Define the symbol and "type" of our generic data
            _vix = AddData<CBOE>("VIX", Resolution.Daily).Symbol;
            _vxv = AddData<CBOE>("VIX3M", Resolution.Daily).Symbol;
            // Set up default Indicators, these are just 'identities' of the closing price
            _smaVIX = SMA(_vix, 1);
            _smaVXV = SMA(_vxv, 1);
            // This will create a new indicator whose value is smaVXV / smaVIX
            _ratio = _smaVXV.Over(_smaVIX);

            var history = History<CBOE>(_vix, 60, Resolution.Daily);
            Debug($"We got {history.Count()} items from our history request");
        }

        public override void OnData(Slice slice)
        {
            // Wait for all indicators to fully initialize
            if (_smaVIX.IsReady && _smaVXV.IsReady && _ratio.IsReady)
            {
                if (!Portfolio.Invested && _ratio > 1)
                {
                    MarketOrder(_spy, 100);
                }
                else if (_ratio < 1)
                {
                    Liquidate();
                }
                // plot all indicators
                Plot("SMA", "VIX", _smaVIX);
                Plot("SMA", "VXV", _smaVXV);
                Plot("Ratio", "Value", _ratio.Current.Value);
            }
        }
    }
}