Overall Statistics
Total Orders
26495
Average Win
0.01%
Average Loss
-0.01%
Compounding Annual Return
40.289%
Drawdown
38.400%
Expectancy
1.170
Start Equity
1000000000
End Equity
3273699379.35
Net Profit
227.370%
Sharpe Ratio
0.828
Sortino Ratio
0.814
Probabilistic Sharpe Ratio
36.252%
Loss Rate
20%
Win Rate
80%
Profit-Loss Ratio
1.71
Alpha
0.138
Beta
1.383
Annual Standard Deviation
0.343
Annual Variance
0.118
Information Ratio
0.596
Tracking Error
0.299
Treynor Ratio
0.205
Total Fees
$768643.64
Estimated Strategy Capacity
$2600000.00
Lowest Capacity Asset
TSLA UNU3P8Y3WFAD
Portfolio Turnover
1.79%
Drawdown Recovery
343
# region imports
from AlgorithmImports import *
# endregion

class TslaBollingerReversionAlgorithm(QCAlgorithm):

    def initialize(self) -> None:
        self.set_start_date(2023, 1, 1)
        self.set_cash(1_000_000_000)
        self.settings.seed_initial_prices = True
        self.settings.automatic_indicator_warm_up = True
        # Add TSLA to the algorithm.
        self._equity = self.add_equity("TSLA")
        # Add a Bollinger Band indicator for TSLA.
        self._bb = self.bb(self._equity, 20, 2, resolution=Resolution.DAILY)
        # Scan for entry/exit each morning.
        self.schedule.on(self.date_rules.every_day(self._equity), self.time_rules.at(8, 0), self._rebalance)
        # Break up entry/exit orders into many smaller orders to reduce market impact.
        # Limit order sizes to 2.5% of the current bar's volume.
        self.set_portfolio_construction(EqualWeightingPortfolioConstructionModel())
        execution_model = VolumeWeightedAveragePriceExecutionModel()
        execution_model.maximum_order_quantity_percent_volume = 0.025  
        self.set_execution(execution_model)

    def _rebalance(self) -> None:
        if not self._bb.is_ready:
            return
        # Buy when the price is below the lower band.
        price = self._equity.price
        if not self.portfolio.invested and price < self._bb.lower_band.current.value:
            self._insight = Insight.price(self._equity, timedelta(365), InsightDirection.UP)
            self.emit_insights(self._insight)
        # Exit when the price is above the upper band.
        elif self.portfolio.invested and price > self._bb.upper_band.current.value:
            self._insight.cancel(self.utc_time)