| Overall Statistics |
|
Total Trades 9306 Average Win 0.27% Average Loss -0.24% Compounding Annual Return -32.956% Drawdown 71.200% Expectancy -0.115 Net Profit -70.228% Sharpe Ratio -1.876 Loss Rate 58% Win Rate 42% Profit-Loss Ratio 1.11 Alpha -0.374 Beta -0.015 Annual Standard Deviation 0.201 Annual Variance 0.04 Information Ratio -2.056 Tracking Error 0.26 Treynor Ratio 25.122 Total Fees $38998.94 |
#
# QuantConnect Basic Template:
# Fundamentals to using a QuantConnect algorithm.
#
# You can view the QCAlgorithm base class on Github:
# https://github.com/QuantConnect/Lean/tree/master/Algorithm
#
import numpy as np
import pandas as pd
class RunOutOfMemory(QCAlgorithm):
def Initialize(self):
'''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.'''
self.SetStartDate(2011, 01, 02) #Set Start Date
self.SetEndDate(2016, 12, 23) #Set End Date
self.SetCash(100000) #Set Strategy Cash
self.symbols = ["SPY"]
for s in self.symbols:
self.AddEquity(s,Resolution.Minute)
self.window=128
self.SetWarmup(self.window)
self.calc_len=self.window
for i in range(16):
self.Schedule.On(self.DateRules.EveryDay("SPY"),self.TimeRules.AfterMarketOpen("SPY",140+i*15),Action(self.runAndTrade))
def runAndTrade(self):
# wait for warmup
if self.IsWarmingUp:
return
for s in self.symbols:
history = self.History(s,self.calc_len,Resolution.Minute)
data=[]
index=[]
for slice in history:
data.append([np.float(slice.Open),np.float(slice.High),np.float(slice.Low),np.float(slice.Close),np.float(slice.Volume)])
index.append(slice.Time.date())
df=pd.DataFrame(data,columns=['o','h','l','p','v'],index=pd.Series(index))
if len(df)==self.calc_len:
self.Debug("Acquired "+str(len(df))+" rows of history")
r=df['p'].diff().fillna(0).values
a=np.diff(r)
m1=(r[-15:].mean()-r.mean()/r.std())
m2=(a[-15:].mean())/a.std()
#self.Debug("Finished calculations")
signal=np.sign(m1)+np.sign(m2)
self.SetHoldings(s,signal/self.Securities.Count)