Overall Statistics
Total Trades
173
Average Win
0%
Average Loss
0.00%
Compounding Annual Return
-95.583%
Drawdown
2.200%
Expectancy
-1
Net Profit
-1.695%
Sharpe Ratio
-4.705
Probabilistic Sharpe Ratio
0%
Loss Rate
100%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.225
Beta
1.434
Annual Standard Deviation
0.187
Annual Variance
0.035
Information Ratio
-1.932
Tracking Error
0.057
Treynor Ratio
-0.612
Total Fees
$175.61
Estimated Strategy Capacity
$100000000.00
Lowest Capacity Asset
IWM RV0PWMLXVHPH
class CustomIndicatorAlgorithm(QCAlgorithm):
    
    def Initialize(self):
        self.SetStartDate(2013,10,7)
        self.SetEndDate(2013,10,8)
        self.AddEquity("SPY", Resolution.Second)
        self.AddUniverse(self.MyCoarseFilterFunction)

        self.SymbolData = {}
        
    def OnData(self, data):
        for SymbolData in self.SymbolData.values():
            if not data.ContainsKey(SymbolData.symbol) or not SymbolData.isready(): continue
            self.SetHoldings(SymbolData.symbol, 0.1)
            self.Log(f'last value of {SymbolData.symbol} : {[str(key) + " " + str(window[0]) for key, window in SymbolData.smaWindow.items()]}')
            
    def OnSecuritiesChanged(self, changes):
        for change in changes.AddedSecurities:
            self.SymbolData[change.Symbol] = SymbolData(change.Symbol, self.SMA)
            sma = self.SymbolData[change.Symbol].sma
            history = self.History([change.Symbol], 10, Resolution.Daily)
            for window in sma.values():
                for time, row in history.loc[change.Symbol].iterrows():
                    window.Update(time, row["close"])
        
        for change in changes.RemovedSecurities:
            if change.Symbol in self.SymbolData:
                del self.SymbolData[change.Symbol]
                
    def MyCoarseFilterFunction(self, coarse):
         sortedByDollarVolume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True)
         filtered = [ x.Symbol for x in sortedByDollarVolume 
                      if x.Price > 10 and x.DollarVolume > 10000000 ]
         return filtered[:5]
     
class SymbolData:
    
    def __init__(self, symbol, method):
        self.symbol = symbol
        self.sma = {}
        self.smaWindow = {}
        
        self.sma['5'] = method(symbol, 5, Resolution.Daily)
        self.smaWindow['5'] = RollingWindow[IndicatorDataPoint](2)   
        self.sma['5'].Updated += self.smaWindow_5_Update
        self.sma['10'] = method(symbol, 10, Resolution.Daily)
        self.smaWindow['10'] = RollingWindow[IndicatorDataPoint](2)   
        self.sma['10'].Updated += self.smaWindow_10_Update
        
    def smaWindow_5_Update(self, sender, updated):
        '''Event holder to update the fast SMA Rolling Window values'''
        self.smaWindow['5'].Add(updated)
    
    def smaWindow_10_Update(self, sender, updated):
        '''Event holder to update the fast SMA Rolling Window values'''
        self.smaWindow['10'].Add(updated)
        
    def isready(self):
        return all([window.IsReady for window in self.smaWindow.values()]) and all([sma.IsReady for sma in self.sma.values()])