Overall Statistics
Total Trades
49
Average Win
0.04%
Average Loss
-0.01%
Compounding Annual Return
1.638%
Drawdown
0.100%
Expectancy
1.588
Net Profit
0.379%
Sharpe Ratio
2.952
Probabilistic Sharpe Ratio
87.444%
Loss Rate
42%
Win Rate
58%
Profit-Loss Ratio
3.44
Alpha
0.013
Beta
0.002
Annual Standard Deviation
0.005
Annual Variance
0
Information Ratio
-4.288
Tracking Error
0.099
Treynor Ratio
7.66
Total Fees
$49.00
OrderTypeKeys = [
    'Market', 'Limit', 'StopMarket', 'StopLimit', 'MarketOnOpen',
    'MarketOnClose', 'OptionExercise',
]

OrderTypeCodes = dict(zip(range(len(OrderTypeKeys)), OrderTypeKeys))
class DynamicHorizontalChamber(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2019, 1, 7)
        self.SetEndDate(2019, 4, 1)
        self.SetCash(100000)
        self.UniverseSettings.Resolution = Resolution.Daily
        self.AddUniverse(self.SelectionFunction) 
        self.averages = { }
        
    def SelectionFunction(self, universe):  
        selected = []
        universe = sorted(universe, key=lambda c: c.DollarVolume, reverse=True)  
        universe = [c for c in universe if c.Price > 100][:100]

        for coarse in universe:  
            symbol = coarse.Symbol
            
            if symbol not in self.averages:
                
                history = self.History(symbol, 200, Resolution.Daily)
                
                self.averages[symbol] = Selection(history) 

            self.averages[symbol].update(self.Time, coarse.AdjustedPrice)
            
            if  self.averages[symbol].is_ready() and self.averages[symbol].stt.Current.Value < 2:
                selected.append(symbol)
                
        return selected[:100]

    def OnSecuritiesChanged(self, changes):
        self.Log(f"OnSecuritiesChanged({self.Time}):: {changes}")
        
        for security in changes.RemovedSecurities:
            if security.Invested:
                self.Liquidate(security.Symbol)
        
        for security in changes.AddedSecurities:            
            self.SetHoldings(security.Symbol, 0.10)
            
class Selection():
    def __init__(self,history):
            
        self.stt = StandardDeviation(200)
        for bar in history.itertuples():
            self.stt.Update(bar.Index[1],bar.close)
            

    def is_ready(self):
        return self.stt.IsReady
    
    def update(self, time, price):
        self.stt.Update(time,price)