Overall Statistics |
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio 0 Tracking Error 0 Treynor Ratio 0 Total Fees $0.00 |
import math import numpy as np import pandas as pd import statistics from datetime import datetime, timedelta class BasicTemplateAlgorithm(QCAlgorithm): def Initialize(self): self.SetCash(100000) self.SetStartDate(2015, 8, 1) self.SetEndDate(2015, 9, 30) # Add securities and get the data self.equities = ["SPY","IWM"] self.roc = [] self.stdev = [] for s in self.equities: self.AddEquity(s, Resolution.Minute) self.roc.append(self.ROCP(s, 1, Resolution.Daily)) self.stdev.append(self.STD(s, 20, Resolution.Daily)) # Schedule trades at 10am self.Schedule.On(self.DateRules.EveryDay("SPY"), self.TimeRules.AfterMarketOpen("SPY", 5), Action(self.Rebalance)) # Days to warm up the indicators self.SetWarmup(timedelta(20)) def OnData(self, slice): pass def Rebalance(self): for i in range(len(self.equities)): # position sizing variables history = self.History("SPY", 21, Resolution.Daily) #close = history['close'] # close is a list containing the 21 days closing price #roc = [(close[i]-close[i-1])/close[i] for i in range(1,len(a))] self.Log("{0} {1} stdev: {2} ".format(str(self.Time), self.equities[i], str(history))) ## error message "unindexable object" when I remove # from close = and from roc #roc = round(self.roc[i].Current.Value, 4) #annl_stdev = np.log(roc[i]).std() * (252 ** 0.5) ## different attempts at annL_stdev give errors wrt float, decimal, etc ## issue appears to be floats not being indexable, but I don't know how to fix