| Overall Statistics |
|
Total Trades 6 Average Win 0% Average Loss -0.01% Compounding Annual Return -1.507% Drawdown 0.000% Expectancy -1 Net Profit -0.019% Sharpe Ratio -7.099 Loss Rate 100% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta -0.886 Annual Standard Deviation 0.001 Annual Variance 0 Information Ratio -13.677 Tracking Error 0.002 Treynor Ratio 0.011 Total Fees $19.41 |
from QuantConnect.Python import PythonData
from datetime import date, timedelta, datetime
import decimal as d
class ScheduledEventsAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2017,1,1)
self.SetEndDate(2017,1,5)
self.SetCash(100000)
spy = self.AddEquity("SPY").Symbol
self.symbols = list()
self.UniverseSettings.Resolution = Resolution.Daily;
self.AddUniverse(StockDataSource, "my-stock-data-source", self.stockDataSource)
self.Schedule.On(self.DateRules.EveryDay(spy), self.TimeRules.AfterMarketOpen(spy, 10), self.OpenPositions)
self.Schedule.On(self.DateRules.EveryDay(spy), self.TimeRules.BeforeMarketClose(spy, 10), self.LiquidatePositions)
def stockDataSource(self, data):
self.symbols = [x.Symbol for x in data]
return self.symbols
def OpenPositions(self):
length = len(self.symbols)
if length == 0 or self.Portfolio.Invested:
return
for symbol in self.symbols:
self.SetHoldings(symbol, 1.0 / length)
def LiquidatePositions(self):
if self.Portfolio.Invested:
self.Liquidate()
class StockDataSource(PythonData):
def GetSource(self, config, date, isLiveMode):
url = "https://www.dropbox.com/s/2az14r5xbx4w5j6/daily-stock-picker-live.csv?dl=1" if isLiveMode else \
"https://www.dropbox.com/s/e17vdejcjrb6hpj/stock_test.csv?dl=1"
return SubscriptionDataSource(url, SubscriptionTransportMedium.RemoteFile)
def Reader(self, config, line, date, isLiveMode):
if not (line.strip() and line[0].isdigit()): return None
csv = line.split(',')
stocks = StockDataSource()
stocks.Time = datetime.now()
if not isLiveMode:
stocks.Time = datetime.strptime(csv[0], "%Y%m%d")
stocks.Symbol = Symbol.Create(csv[1], SecurityType.Equity, Market.USA)
stocks.Value = d.Decimal(csv[2])
else:
raise Exception('Live not implemented')
stocks.EndTime = stocks.Time + timedelta(1)
return stocks