| 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 System import *
from QuantConnect import *
from QuantConnect.Algorithm import QCAlgorithm
from QuantConnect.Data.UniverseSelection import *
import base64
### <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 DropboxUniverseSelectionAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2013,1,1)
self.SetEndDate(2013,12,31)
self.backtestSymbolsPerDay = {}
self.current_universe = []
self.Log(self.current_universe)
self.UniverseSettings.Resolution = Resolution.Daily
self.AddUniverse("my-dropbox-universe", self.selector)
def selector(self, date):
if len(self.backtestSymbolsPerDay) == 0:
str = self.Download("https://www.dropbox.com/s/ua6ff99r75hby2j/poc.csv?dl=0")#, headers)
self.Log(str)
for line in str.splitlines():
data = line.split(';')
self.backtestSymbolsPerDay[data[0]] = data[1:]
index = date.strftime("%Y%m%d")
self.current_universe = self.backtestSymbolsPerDay.get(index, self.current_universe)
return self.current_universe
def OnData(self, slice):
if slice.Bars.Count == 0: return
if self.changes is None: return
# start fresh
self.Liquidate()
percentage = 1 / slice.Bars.Count
for tradeBar in slice.Bars.Values:
self.SetHoldings(tradeBar.Symbol, percentage)
# reset changes
self.changes = None
self.Log(self.current_universe)
def OnSecuritiesChanged(self, changes):
self.changes = changes