Overall Statistics |
Total Trades 1 Average Win 0% Average Loss 0% Compounding Annual Return 0.671% Drawdown 15.300% Expectancy 0 Net Profit 0.670% Sharpe Ratio 0.121 Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0.383 Beta -18.25 Annual Standard Deviation 0.156 Annual Variance 0.024 Information Ratio -0.007 Tracking Error 0.156 Treynor Ratio -0.001 Total Fees $1.00 |
from datetime import datetime, timedelta import numpy as np import decimal as d import dateutil ### <summary> ### Basic template algorithm simply initializes the date range and cash. This is a skeleton ### framework you can use for designing an algorithm. ### </summary> class BasicTemplateAlgorithm(QCAlgorithm): '''Basic template algorithm simply initializes the date range and cash''' 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(2017, 12, 1) # Set Start Date self.SetEndDate(2018, 12, 1) # Set End Date self.SetCash(10000) # Set Strategy Cash # Find more symbols here: http://quantconnect.com/data self.AddEquity("IWM", Resolution.Minute) # define our 30 minute trade bar consolidator. we can # access the 30 minute bar from the DataConsolidated events thirtyMinuteConsolidator = TradeBarConsolidator(timedelta(minutes=60)) # attach our event handler. The event handler is a function that will # be called each time we produce a new consolidated piece of data. thirtyMinuteConsolidator.DataConsolidated += self.ThirtyMinuteBarHandler # this call adds our 30-minute consolidator to # the manager to receive updates from the engine self.SubscriptionManager.AddConsolidator("IWM", thirtyMinuteConsolidator) # dailyConsolidator = TradeBarConsolidator(TimeSpan.FromDays(1)) # self.SubscriptionManager.AddConsolidator("IWM", dailyConsolidator) # dailyConsolidator.DataConsolidated += self.dailyBarHandler self.adx = self.ADX("IWM", 14, Resolution.Daily) # self.RegisterIndicator("IWM", self.adx, Resolution.Daily) # def dailyBarHandler(self, sender, bar): # Chart('ADX') # self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.BeforeMarketClose("IWM"), # self.update_plots) def ThirtyMinuteBarHandler(self, sender, bar): '''This is our event handler for our 30-minute trade bar defined above in Initialize(). So each time the consolidator produces a new 30-minute bar, this function will be called automatically. The sender parameter will be the instance of the IDataConsolidator that invoked the event ''' printafterdate = "2018-11-18" odate = dateutil.parser.parse(printafterdate) currentdatetime = str(self.Time) currentdate = currentdatetime[:10] ocurrentdate = dateutil.parser.parse(currentdate) if ocurrentdate > odate and self.adx.IsReady: # if self.adx.IsReady: self.Debug(str(self.Time) + ":" + str(bar) + ":" + str(self.adx.Current.Value)) # else: # self.Debug(str(self.Time) + ":" + str(bar)) # # self.Debug("Daily Bar Handler" + str(self.Time) + " " + str(bar) + str(adx)) # float_bar_close = float(bar.Close) # self.determine_vma(float_bar_close) def OnData(self, data): '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here. Arguments: data: Slice object keyed by symbol containing the stock data ''' if not self.Portfolio.Invested: self.SetHoldings("IWM", 1) def update_plots(self): if not self.adx.IsReady: return # Plots can also be created just with this one line command. self.Plot('ADX', self.adx)