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
0
Tracking Error
0
Treynor Ratio
0
Total Fees
$0.00
import statistics
import pandas as pd
import numpy as np

class TachyonMultidimensionalChamber(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 12, 17)  # Set Start Date
        self.SetEndDate(2020, 12, 17)  # Set End Date
        self.SetCash(400000)  # Set Strategy Cash
        self.AddUniverse(self.CoarseSelectionFunction)
        
        self.SetSecurityInitializer(self.SecurityInitializer)
        
        self.UniverseSettings.ExtendedMarketHours = True
        self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Margin)
        self.UniverseSettings.Leverage = 4
        #self.UniverseSettings.Resolution = Resolution.Hour #can comment/change this out
        self.SetWarmUp(5)


        ###variables to keep track of
        self.sd = {} #all symbol data
        

    def SecurityInitializer(self, security):
        security.SetLeverage(4)
    
    
    def CoarseSelectionFunction(self, universe):  
        selected = []
        for coarse in universe:  
            if coarse.Volume > 20000000 and coarse.Value > 10 and coarse.HasFundamentalData:
                symbol = coarse.Symbol
                selected.append(symbol)
        return selected #list of objects of type Symbol
    
    
    def OnSecuritiesChanged(self, changed):
        for security in changed.AddedSecurities:
            symbol = security.Symbol
            if symbol not in self.sd:
                self.sd[symbol] = SymbolData(self, symbol)
        for security in changed.RemovedSecurities:
            symbol = security.Symbol
            self.sd.pop(symbol, None)

    
            

        
class SymbolData:
    def __init__(self, algorithm, symbol):
        self.vwap = algorithm.VWAP(symbol, 2000, Resolution.Minute)
        self.ema = algorithm.EMA(symbol, 9, Resolution.Minute)

        prehist = algorithm.History(symbol, 10, Resolution.Minute)
        
        if not prehist.empty:
            hist = prehist.loc[symbol]
            
            if 'volume' not in prehist.columns:
                algorithm.Log(f"No volume: {symbol}\n{prehist.to_string()}")
                return
            
            for idx, bar in hist.iterrows():
                
                tradeBar = TradeBar(idx, symbol, bar.open, bar.high, bar.low, bar.close, bar.volume, timedelta(minutes=1))
                self.vwap.Update(tradeBar)
                self.ema.Update(idx, bar.close)