Overall Statistics
Total Orders
0
Average Win
0%
Average Loss
0%
Compounding Annual Return
0%
Drawdown
0%
Expectancy
0
Start Equity
100000
End Equity
100000
Net Profit
0%
Sharpe Ratio
0
Sortino 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
-6.143
Tracking Error
0.037
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
Portfolio Turnover
0%
# region imports
from AlgorithmImports import *
# endregion
class SquareBrownJellyfish(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2021, 2, 11)
        self.SetEndDate(2021, 2, 16)
        self.SetCash(100000) 
        self.AddUniverse(self.MyCoarseFilterFunction)
        self.volumeBySymbol = {}

    def MyCoarseFilterFunction(self, coarse):
        filtered = [ x for x in coarse if x.price > 20 and x.volume > 1000000 ]
        for x in filtered:
            if x.Symbol not in self.volumeBySymbol:
                self.volumeBySymbol[x.Symbol] = SymbolData(x.Symbol, self)
            self.volumeBySymbol[x.Symbol].Update(x.EndTime, x.Volume)
        
        sortBySMAVolume = sorted(self.volumeBySymbol.items(), key=lambda x: x[1].sma.Current.Value, reverse=True)[:50]
        symbols = [x[0] for x in sortBySMAVolume]
        for symbol in symbols:
            self.debug(symbol)
        return symbols
    
class SymbolData:
    def __init__(self,symbol,algo):
        self.algo = algo
        self.symbol = symbol
        self.sma = SimpleMovingAverage(30)
        # self.high = self.MAX(symbol, 253, Resolution.Daily, Field.High)
        # self.low = self.MIN(symbol, 253, Resolution.Daily, Field.Low)
        history = algo.History(symbol,30,Resolution.Daily)
        if not history.empty:
            for time,row in history.loc[symbol].iterrows():
                self.sma.Update(time,row['volume'])
    def Update(self,time,vol):
        self.sma.Update(time,vol)