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.863
Tracking Error
0.125
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
Portfolio Turnover
0%
#region imports
from AlgorithmImports import *
#endregion

class VWAPwithSTD(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2021, 1, 1)
        self.SetEndDate(2022, 4, 12)
        self.SetCash(100_000)
        self.symbols = ["QQQ", "SPY", "AAPL", "AMZN"] # list of symbols to trade
        self.vwaps = {}
        self.stds = {}
        for symbol in self.symbols:
            equity = self.AddEquity(symbol, Resolution.Minute)
            self.vwaps[symbol] = self.VWAP(equity.Symbol, 14, Resolution.Daily)
            self.stds[symbol] = self.STD(equity.Symbol, 14, Resolution.Daily)
        self.SetWarmUp(30, Resolution.Daily)

    def OnData(self, data):
        if self.IsWarmingUp or not all(std.IsReady for std in self.stds.values()):
            return

        for symbol in self.symbols:
            price = self.Securities[symbol].Price
            vwap = self.vwaps[symbol].Current.Value
            std = self.stds[symbol].Current.Value
            ub1 = vwap + std 
            ub2 = vwap + 2*std
            lb1 = vwap - std 
            lb2 = vwap - 2*std 

            self.Plot(symbol, 'price', price)
            self.Plot(symbol, 'vwap', vwap)
            self.Plot(symbol, 'ub2', ub2)
            self.Plot(symbol, 'ub1', ub1)
            self.Plot(symbol, 'lb1', lb1)
            self.Plot(symbol, 'lb2', lb2)

            # implement trading logic for each stock here
            # e.g., if price < lb2: buy the stock
            #       if price > ub2: sell the stock
            #       otherwise, hold the stock