| 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 Probabilistic 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 2.337 Tracking Error 0.206 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset |
class VirtualBrownGull(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2022, 2, 7) # Set Start Date
self.SetEndDate(2022, 2, 21)
self.SetCash(100_000)
self.UniverseSettings.Resolution = Resolution.Daily
self.AddUniverse(self.CoarseSelectionFunction)
#self.selected = None
#smavolumemin = 1000000
#self.smavolumemin = smavolumemin
self.averages = {}
def CoarseSelectionFunction(self, coarse): # was originally self, universe
selected = []
sortedbyPrice = sorted(coarse, key=lambda c: c.Price, reverse=False)
filteredbyPrice = [c for c in sortedbyPrice if c.Price > 2 and c.Price < 30 and c.DollarVolume > 0][:50] #need to put dollarvolume condition in to avoid symbols with nil volume ruining algo
self.Log(f"Number of assets: {len(filteredbyPrice)}")
for c in filteredbyPrice:
symbol = c.Symbol
if symbol not in self.averages:
history = self.History(symbol, 30, Resolution.Daily)
self.averages[symbol] = SelectionData(history)
self.averages[symbol].update(self.Time, c.Volume)
if self.averages[symbol].is_ready():
if self.averages[symbol].thirtysma.Current.Value > 1_000_000:
selected.append(symbol)
return selected[:10]
self.Log(f"Number of assets: {len(selected)}")
def OnSecuritiesChanged(self, changes):
for added in changes.AddedSecurities:
self.Log(f"Added {added.Symbol}")
for removed in changes.RemovedSecurities:
self.Log(f"Removed {removed.Symbol}")
#self.Log(selected(symbol).thirtysma.Current.Value)
# return
class SelectionData(): # this changes
def __init__(self, history):
self.thirtysma = SimpleMovingAverage(30)
for bar in history.itertuples():
self.thirtysma.Update(bar.Index[1], bar.volume)
def is_ready(self):
return self.thirtysma.IsReady
def update(self, time, volume):
#self.volume = volume
self.thirtysma.Update(time, volume)