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 |
from clr import AddReference AddReference("System") AddReference("QuantConnect.Algorithm") AddReference("QuantConnect.Common") from System import * from QuantConnect import * from QuantConnect.Algorithm import * from QuantConnect.Data import SubscriptionDataSource from QuantConnect.Python import PythonData from datetime import date, timedelta, datetime from System.Collections.Generic import List from QuantConnect.Algorithm import QCAlgorithm from QuantConnect.Data.UniverseSelection import * import decimal as d import numpy as np import math import json ### <summary> ### In this algortihm we show how you can easily use the universe selection feature to fetch symbols ### to be traded using the BaseData custom data system in combination with the AddUniverse{T} method. ### AddUniverse{T} requires a function that will return the symbols to be traded. ### </summary> ### <meta name="tag" content="using data" /> ### <meta name="tag" content="universes" /> ### <meta name="tag" content="custom universes" /> class DropboxBaseDataUniverseSelectionAlgorithm(QCAlgorithm): def Initialize(self): self.UniverseSettings.Resolution = Resolution.Minute; self.SetStartDate(2017,2,1) self.SetEndDate(2017,2,27) self.AddUniverse(StockDataSource, "my-stock-data-source", self.stockDataSource) self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.At(15, 44), self.liquidateOnClose) def stockDataSource(self, data): list = [] for item in data: if self.Time.date() == item.Time.date(): for symbol in item["Symbols"]: list.append(symbol) return list def OnData(self, slice): if slice.Bars.Count == 0: return if self._changes == None: return for tradeBar in slice.Bars.Values: self.SetHoldings(tradeBar.Symbol, .05) # reset changes self._changes = None def OnSecuritiesChanged(self, changes): self.Log("OnSecuritiesChanged: self.Time.date(): {}".format(self.Time.date())) self._changes = changes def liquidateOnClose(self): self.Liquidate() class StockDataSource(PythonData): def GetSource(self, config, date, isLiveMode): if isLiveMode: url = "https://www.dropbox.com/s/307kb876cnc0grv/universe-test-live.csv?dl=1" else: url = "https://www.dropbox.com/s/307kb876cnc0grv/universe-test-backtest.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 stocks = StockDataSource() stocks.Symbol = config.Symbol csv = line.split(',') if isLiveMode: stocks.Time = date stocks["Symbols"] = csv else: stocks.Time = datetime.strptime(csv[0], "%Y-%m-%d") stocks["Symbols"] = csv[1:] return stocks