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.162
Tracking Error
0.087
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
class HipsterOrangeMonkey(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2021, 6, 1)  # Set Start Date
        self.SetEndDate(2021, 8, 15)
        self.SetCash(100000)  # Set Strategy Cash
        
        self.AddEquity("SPY", Resolution.Daily)
        self.AddEquity("AHPI", Resolution.Daily)
        #create symbol objects that get passed through universe selection model
        self.symbols = [Symbol.Create("SPY", SecurityType.Equity, Market.USA), Symbol.Create("AHPI", SecurityType.Equity, Market.USA)]
        
        #set resolution for your universe
        self.UniverseSettings.Resolution = Resolution.Daily
        
        #Set the universe and pass in a Manual Universe Selection Model, initialize with symbols list
        self.AddUniverseSelection(ManualUniverseSelectionModel(self.symbols))
        self.SetWarmUp(50)
        self.selected = []
    def ManualUniverseSelectionModel(self, coarse):
        selected = []
        for c in self.symbols:
            if c.Symbol not in self.stateData:
                self.stateData[c.Symbol] = SelectionData(c.Symbol, 20)
            avg = self.stateData[c.Symbol]
            avg.update(c.EndTime, c.AdjustedPrice, c.DollarVolume)
            self.Debug(str(self.symbols))
        # filter the values of selectionData(sd) above SMA
        values = [sd for sd in self.stateData.values() if sd.volume > sd.sma.Current.Value and sd.volume_ratio > 2]
        for sd.symbol in values:
            self.selected.append(security.Symbol)
            self.Debug(str(selected))
                
            
        # sort sd by the largest % jump in volume.
        values.sort(key=lambda sd: sd.volume_ratio, reverse=True)

        # return the symbol objects
        return [ sd.symbol for sd in values ]
        
    def OnData(self, data):
        '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
            Arguments:
                data: Slice object keyed by symbol containing the stock data
        '''
    
        for security in self.selected:
            self.SetHoldings(security.Symbol, 0.5)
        self.Debug(self.symbols)
class SelectionData():
    def __init__(self, symbol, period):
        self.symbol = symbol
        self.volume = 0 
        self.volume_ratio = 0
        self.sma = SimpleMovingAverage(20)
        
    def is_ready(self):
        return self.sma.IsReady
        
    def update(self, time, price, volume):
        self.volume = volume
            
        if self.sma.Update(time, volume):
                # get ratio of this volume bar vs previous 20 before it.
            self.volume_ratio = volume / self.sma.Current.Value