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
-45.015
Tracking Error
0.025
Treynor Ratio
0
Total Fees
$0.00
class TachyonParticleCoil(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2019, 10, 23)  # Set Start Date
        self.SetEndDate(2019, 10, 25)  # Set Start Date
        self.SetCash(100000)  # Set Strategy Cash
        self.AddEquity("SPY", Resolution.Minute)
        self.volume_per_level = {}


    def OnData(self, data):
        if not data.ContainsKey("SPY"):
            return
        
        # Get price range of candle
        low = round(data['SPY'].Low, 2)
        high = round(data['SPY'].High, 2)
        price_range = high - low
        
        # Get volume per penny level throughout candle
        vol_per_level =  price_range / data['SPY'].Volume
        
        # Update dictionary that saves volume at each level
        for i in range(int(price_range * 100)):
            key = f"{i/100 + low}"
            if key not in self.volume_per_level.keys():
                self.volume_per_level[key] = vol_per_level
            else:
                self.volume_per_level[key] += vol_per_level
    
    def OnEndOfDay(self):
        # Set target volume - 70% of daily volume
        target_vol = sum(self.volume_per_level.values()) * 0.7
        
        # Get the price level that had the largest volume
        max_vol_price = max(self.volume_per_level, key=self.volume_per_level.get)
        
        # Setup a window to capture the POC, centered at the most liquid level
        curr_max_price = float(max_vol_price)
        curr_min_price = float(max_vol_price)
        curr_vol = self.volume_per_level[max_vol_price]
        
        # Grow window bounds until we have 70% of the day's volume captured
        while curr_vol < target_vol:
            # Price one level up
            price_up = str(round(curr_max_price + 0.01, 2))
            price_up_vol = 0
            
            # Price one level down
            price_down = str(round(curr_min_price - 0.01, 2))
            price_down_vol = 0

            # Get associated volume at new potential levels
            if price_up in self.volume_per_level.keys():
                price_up_vol = self.volume_per_level[price_up]
            if price_down in self.volume_per_level.keys():
                price_down_vol = self.volume_per_level[price_down]
       
            # Grow window in the direction of more volume
            if price_up_vol > price_down_vol:
                curr_max_price = round(float(price_up), 2)
                curr_vol += self.volume_per_level[price_up]
            else:
                curr_min_price = round(float(price_down), 2)
                curr_vol += self.volume_per_level[price_down]
            
        self.Log(f"Max: {curr_max_price}")
        self.Log(f"Min: {curr_min_price}")
        self.volume_per_level.clear()