| 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 -3.407 Tracking Error 0.093 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset |
# 1. Weekly volume is larger than previous week volume * 1.3
# 2. Weekly close > previous week close
# 3. Weekly close > open
# 4. Market cap >= 2B
# 5. Weekly volume is larger than or equal to the previous 10 weeks (not including current week) simple average volume
# 6. Weekly close is higher than the previous 14 weeks (not including current week) average true range (ATR)
''' What is the parameter for ATR? '''
''' When you mean weekly, do you mean the: average, sum, or single value? '''
import datetime
class MeasuredGreenManatee(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2021, 6, 15)
self.SetEndDate(2021, 7, 1)
self.SetCash(100000)
self.AddUniverse(self.Coarse, self.Fine)
self.finalPassWeeks1 = 10
self.finalPassWeeks2 = 14+1 #plus one for current week
self.diff = self.finalPassWeeks2 - self.finalPassWeeks1 - 1
self.lastDate = datetime.datetime.min
def OnData(self, data):
pass
def OnSecuritiesChanged(self, changes):
for added in changes.AddedSecurities:
pass
for removed in changes.RemovedSecurities:
pass
def Coarse(self, coarse):
delta = self.Time - self.lastDate
if delta.days < 7:
return Universe.Unchanged
self.lastDate = self.Time
self.Debug(self.Time)
allCoarse = [x.Symbol for x in coarse if x.Price > 0 and x.Volume > 0 and x.HasFundamentalData] # Will not trade ETFs if HasFundamentalData
return allCoarse
def Fine(self, fine):
allFine = [x.Symbol for x in fine if x.MarketCap >= 2e9]
history = self.History(allFine, 10, Resolution.Daily)
firstPass = []
for symbol in allFine:
if self.FirstPass(symbol, history):
firstPass.append(symbol)
self.Debug(f"Length of first pass filter {len(firstPass)}")
history = self.History(firstPass, 5*self.finalPassWeeks2, Resolution.Daily)
finalPass = []
for symbol in firstPass:
if self.FinalPass(symbol, history):
finalPass.append(symbol)
tickers = [x.Value for x in finalPass]
self.Debug(f"Length of final pass filter {len(finalPass)}")
self.Debug(tickers)
return finalPass
def FirstPass(self, symbol, history):
if len(history.loc[symbol].index) < 10: return False
currentWeeklyVolume = sum(history.loc[symbol].iloc[5:10].volume)
currentWeeklyClose = (history.loc[symbol].iloc[5:10].close).mean()
currentOpen = history.loc[symbol].iloc[0].open
previousWeeklyVolume = sum(history.loc[symbol].iloc[0:5].volume)
previousWeeklyClose = history.loc[symbol].iloc[5].close
if currentWeeklyVolume > previousWeeklyVolume*1.3 and currentWeeklyClose > previousWeeklyClose and currentWeeklyClose > currentOpen:
return True
return False
def FinalPass(self, symbol, history):
if len(history.loc[symbol].index) < 5*self.finalPassWeeks2: return False
currentWeeklyVolume = (history.loc[symbol].iloc[-5:-1].volume).mean()
previousWeeklyVolume = (history.loc[symbol].iloc[self.diff*5:-5].volume).mean()
if not currentWeeklyVolume >= previousWeeklyVolume:
return False
currentAtr = AverageTrueRange(5, MovingAverageType.Simple)
for tuple in history.loc[symbol].iloc[-5:-1].itertuples():
currentAtr.Update(TradeBar(tuple.Index, symbol, tuple.open, tuple.high, tuple.low, tuple.close, tuple.volume))
previousAtr = AverageTrueRange(self.finalPassWeeks2, MovingAverageType.Simple)
for tuple in history.loc[symbol].iloc[:-5].itertuples():
previousAtr.Update(TradeBar(tuple.Index, symbol, tuple.open, tuple.high, tuple.low, tuple.close, tuple.volume))
if currentAtr.Current.Value > previousAtr.Current.Value:
return True
return False