Overall Statistics
Total Trades
22533
Average Win
0.43%
Average Loss
-0.10%
Compounding Annual Return
-0.829%
Drawdown
33.800%
Expectancy
0.006
Net Profit
-4.079%
Sharpe Ratio
-0.043
Sortino Ratio
-0.051
Probabilistic Sharpe Ratio
0.594%
Loss Rate
82%
Win Rate
18%
Profit-Loss Ratio
4.53
Alpha
-0.012
Beta
0.048
Annual Standard Deviation
0.191
Annual Variance
0.036
Information Ratio
-0.325
Tracking Error
0.254
Treynor Ratio
-0.17
Total Fees
$0.00
Estimated Strategy Capacity
$6800000.00
Lowest Capacity Asset
QQQ RIWIV7K5Z9LX
Portfolio Turnover
2310.00%
# region imports
from AlgorithmImports import *
from QuantConnect.Data import Slice
# endregion

class VwapTrend(QCAlgorithm):
    def Initialize(self):
        self.SetStartDate(2018, 11, 10)
        self.SetEndDate(2023, 11, 11)
        self.SetCash(25000)
        self.Settings.MinimumOrderMarginPortfolioPercentage = 0.01
        self.SetWarmUp(390)
 
        self.asset = self.AddEquity("QQQ", Resolution.Minute)
        self.asset.SetDataNormalizationMode(DataNormalizationMode.Raw)
        self.asset.vwap = self.VWAP(self.asset.Symbol) 
        self.asset.SetFeeModel(ConstantFeeModel(0))

        # Flat before market close
        self.Schedule.On(self.DateRules.EveryDay(self.asset.Symbol), self.TimeRules.BeforeMarketClose(self.asset.Symbol, 1), self.Liquidate)

    def OnData(self, slice: Slice) -> None:
        if not self.asset.vwap.IsReady:
            return

        diff = self.asset.Close - self.asset.vwap.Current.Value
        minimum = 0
        if diff > minimum and self.asset.Holdings.Quantity <= 0:
            self.SetHoldings(self.asset.Symbol, 1)

        if diff < -1 * minimum and self.asset.Holdings.Quantity >= 0:
            self.SetHoldings(self.asset.Symbol, -1)