Overall Statistics
Total Trades
116
Average Win
0.00%
Average Loss
0.00%
Compounding Annual Return
-0.213%
Drawdown
0.100%
Expectancy
-0.872
Net Profit
-0.106%
Sharpe Ratio
-5.618
Probabilistic Sharpe Ratio
0%
Loss Rate
90%
Win Rate
10%
Profit-Loss Ratio
0.23
Alpha
-0.002
Beta
0.001
Annual Standard Deviation
0
Annual Variance
0
Information Ratio
-2.571
Tracking Error
0.134
Treynor Ratio
-2.406
Total Fees
$116.00
Estimated Strategy Capacity
$110000000.00
Lowest Capacity Asset
AAPL R735QTJ8XC9X
class EnergeticLightBrownDuck(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 12, 6)
        self.SetCash(100000) 
        self.spy = self.AddEquity("SPY", Resolution.Hour)
        self.deviations = 2
        self.apl = self.AddEquity("AAPL",Resolution.Hour)
        self.Data_symbol = {}
        self.Data_symbol[self.spy.Symbol] = SymbolData(self,self.spy,60,Resolution.Hour)
        self.Data_symbol[self.apl.Symbol] = SymbolData(self,self.apl,60,Resolution.Hour)
        self.assets = [self.spy.Symbol,self.apl.Symbol]
      
        
        
    def PriceIsFavorable(self, data, unorderedQuantity):
        '''Determines if the current price is more than the configured
       number of standard deviations away from the mean in the favorable direction.'''
        sma = data.SMA.Current.Value
        deviations = self.deviations * data.STD.Current.Value
        if unorderedQuantity > 0:
            return data.Security.BidPrice < sma - deviations
        else:
            return data.Security.AskPrice > sma + deviations
    def OnData(self, data):

        for ticker in self.assets:
            if ticker not in data.Bars:continue
            Data = self.Data_symbol.get(ticker,None)
            if Data == None:continue
            if self.Portfolio[ticker].Invested:
                self.Liquidate(ticker)
                continue
            if Data.STD.IsReady and self.PriceIsFavorable(Data,1):
                self.MarketOrder(ticker,1)
                self.Debug('Executed')
            
class SymbolData:
    def __init__(self, algorithm, security, period, resolution):
        symbol = security.Symbol
        self.Security = security
        self.SMA = algorithm.SMA(security.Symbol, period,resolution)
        self.STD = algorithm.STD(security.Symbol, period,resolution)
        history = algorithm.History(symbol, period, resolution)
        
        if history.empty or 'close' not in history.columns:
           return
        
        history = history.close.unstack(0).squeeze()
        for time, value in history.iteritems():
                self.SMA.Update(time, value)
                self.STD.Update(time, value)