| Overall Statistics |
|
Total Trades 1 Average Win 0% Average Loss 0% Compounding Annual Return 6.055% Drawdown 0.200% Expectancy 0 Net Profit 0% Sharpe Ratio 4.602 Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha -0.014 Beta 0.152 Annual Standard Deviation 0.012 Annual Variance 0 Information Ratio -7.622 Tracking Error 0.053 Treynor Ratio 0.37 Total Fees $1.00 |
import numpy as np
class BasicTemplateAlgorithm(QCAlgorithm):
def Initialize(self):
# Set the cash we'd like to use for our backtest
# This is ignored in live trading
self.SetCash(100000)
# Start and end dates for the backtest.
# These are ignored in live trading.
self.SetStartDate(2017,1,1)
self.SetEndDate(2017,1,10)
# Add securities you'd like to see
self.equities = ["SPY","QQQ"]
# Get the data from tickers
for s in self.equities:
self.Debug(str(s))
self.AddEquity(s, Resolution.Minute)
self.SMA(s, 1, Resolution.Daily)
self.SMA(s, 5, Resolution.Daily)
self.Schedule.On(self.DateRules.EveryDay("SPY"),
self.TimeRules.AfterMarketOpen("SPY", 30),
Action(self.Rebalance))
def OnData(self, slice):
pass
def Rebalance(self):
#current_price = ???
sma1 = self.SMA("SPY", 1, Resolution.Daily)
sma5 = self.SMA("SPY", 5, Resolution.Daily)
for s in self.equities:
if sma1 >= sma5:
self.SetHoldings("SPY", 0.25)
else:
self.SetHoldings("SPY", 0.00)