| Overall Statistics |
|
Total Trades 83 Average Win 2.53% Average Loss -1.41% Compounding Annual Return 4.032% Drawdown 12.200% Expectancy 0.293 Net Profit 19.398% Sharpe Ratio 0.558 Loss Rate 54% Win Rate 46% Profit-Loss Ratio 1.79 Alpha 0.044 Beta -0.093 Annual Standard Deviation 0.076 Annual Variance 0.006 Information Ratio 0.295 Tracking Error 0.076 Treynor Ratio -0.453 Total Fees $218.50 |
import numpy as np
from QuantConnect.Python import PythonQuandl # quandl data not CLOSE
from QuantConnect.Python import PythonData # custom data
from QuantConnect.Data import SubscriptionDataSource
from datetime import datetime, timedelta
import decimal
class FearAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetCash(100000)
self.SetStartDate(2014, 1, 1)
self.SetEndDate(2017, 10, 10)
# Add a benchmark asset to synchronize the algorithm
self.AddEquity("SPY", Resolution.Daily).Symbol
# Add VIX as our fear index.
self.AddEquity("VXX", Resolution.Daily).Symbol
# Get the 30-day EMA of the VIX:
self.ema = self.EMA("VXX", 30)
# Set warm up so we're instantly trading:
self.SetWarmUp(180)
def OnData(self, slice):
if self.LiveMode: self.Debug("Running algorithm!!")
# Make sure all the data we need is in place
if self.IsWarmingUp: return
if not slice.ContainsKey("VXX"): return
if not slice.ContainsKey("SPY"): return
if self.LiveMode: self.Debug("Warm Up Complete Deciding..")
# Make some nice plots
self.Plot("FEAR", "VXX", self.Securities["VXX"].Price)
self.Plot("FEAR", "EMA", self.ema.Current.Value)
# Decide when to invest
if self.Securities["VXX"].Price < self.ema.Current.Value:
if self.Portfolio.Invested: return
if self.LiveMode: self.Debug("Investing in SPY...")
self.SetHoldings("SPY", 1);
else:
self.Liquidate()
if self.LiveMode: self.Debug("FEAR too great, liquidating...")