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
clr.AddReference('QuantConnect.Research')
from QuantConnect.Research import QuantBook
import statistics
import pandas as pd
import numpy as np
import math

class TachyonMultidimensionalChamber(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2021, 1, 14)  # Set Start Date
        self.SetEndDate(2021, 1, 14)  # 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.Minute #can comment/change this out
        
        ###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.Symbol.Value == "AAPL": 
                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)

    ########### 
    # on data #
    ###########
    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 s in self.sd:
            if data.ContainsKey(s) and data.Bars.ContainsKey(s) and self.Time.hour < 16:
                minute = data.Bars
                
                if self.Time.hour == 9:
                    self.Debug(str(minute[s].Open) + "\t" + str(minute[s].High) + "\t" + str(minute[s].Low) + "\t" + str(minute[s].Close) + "\t" + str(minute[s].Volume))
                return 


        
class SymbolData:
    def __init__(self, algorithm, symbol):
        self.vwap = algorithm.VWAP(symbol, 2000, Resolution.Minute) #60*24 = 1440 minutes in a day
        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}")
                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)