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
0
Tracking Error
0
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(2024, 5, 9)
        self.SetEndDate(2024, 5, 9)
        self.SetCash(100000) 
        self.AddUniverse(self.MyCoarseFilterFunction)
        self.volumeBySymbol = {}

    def MyCoarseFilterFunction(self, coarse): # and f.volume > 1000000
        filtered = [f for f in coarse if f.has_fundamental_data  and f.price > 10 and f.operation_ratios.roe.one_year > 0.1 and f.market_cap > 300000000 and f.earning_ratios.diluted_eps_growth.one_year > 0.1]
        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.price, x.volume)
        
        # sortBySMAVolume = sorted(self.volumeBySymbol.items(), key=lambda x: x[1].sma50.Current.Value, reverse=True)[:1000]
        symbols = [x[0] for x in self.volumeBySymbol.items()]
        result = []
        for symbol in symbols:
            if self.volumeBySymbol.get(symbol).vol.current.value > 1000000 and self.volumeBySymbol.get(symbol).sma50.current.value > self.volumeBySymbol.get(symbol).sma200.current.value and self.volumeBySymbol.get(symbol).rocp.current.value > 20:
                result.append(symbol.Value)
                self.Debug("Symbol : {}, rocp : {}".format(symbol.value, self.volumeBySymbol.get(symbol).rocp.current.value))
                # self.Debug("Symbol : {}, price : {}".format(symbol.value, self.volumeBySymbol.get(symbol).temp.current.value))
        self.Debug(result)
        return symbols
    
class SymbolData:
    def __init__(self,symbol,algo):
        self.algo = algo
        self.symbol = symbol
        self.sma50 = SimpleMovingAverage(50)
        self.sma200 = SimpleMovingAverage(200)
        self.rocp = RateOfChangePercent(21)
        self.vol = SimpleMovingAverage(90)
        self.temp = 0
        history = algo.History(symbol,201,Resolution.Daily)
        if not history.empty:
            for time,row in history.loc[symbol].iterrows():
                self.sma50.Update(time,row['close'])
                self.sma200.Update(time,row['close'])
                self.rocp.Update(time, row['close'])
                self.vol.Update(time, row['volume'])
                
    def Update(self,time,price, vol):
        self.sma50.Update(time, price)
        self.sma200.Update(time, price)
        self.rocp.Update(time, price)
        self.vol.Update(time, vol)