Overall Statistics
Total Orders
219
Average Win
3.53%
Average Loss
-1.46%
Compounding Annual Return
12.312%
Drawdown
36.000%
Expectancy
0.442
Start Equity
100000
End Equity
178737.25
Net Profit
78.737%
Sharpe Ratio
0.359
Sortino Ratio
0.37
Probabilistic Sharpe Ratio
11.104%
Loss Rate
58%
Win Rate
42%
Profit-Loss Ratio
2.42
Alpha
0.006
Beta
0.761
Annual Standard Deviation
0.174
Annual Variance
0.03
Information Ratio
-0.088
Tracking Error
0.141
Treynor Ratio
0.082
Total Fees
$2890.36
Estimated Strategy Capacity
$1800000.00
Lowest Capacity Asset
SSO TJNNZWL5I4IT
Portfolio Turnover
11.95%
Drawdown Recovery
798
#region imports
from AlgorithmImports import *
#endregion


class EtfSmaAlphaModel(AlphaModel):

    def __init__(self, main_symbol, alt_symbol):
        self._main_symbol = main_symbol
        self._alt_symbol = alt_symbol
        self._day = -1
        self._period = timedelta(1)
    
    def update(self, algorithm, data):
        if self._day == algorithm.time.day or not algorithm.is_market_open(self._main_symbol):
            return []
            
        insights = []
        
        if self._main_symbol in data:
            if data[self._main_symbol].close > self._sma.current.value:
                insights.append(Insight.price(self._main_symbol, self._period, InsightDirection.UP))
                insights.append(Insight.price(self._alt_symbol, self._period, InsightDirection.FLAT))
            else:
                insights.append(Insight.price(self._alt_symbol, self._period, InsightDirection.UP))
                insights.append(Insight.price(self._main_symbol, self._period, InsightDirection.FLAT))
        
        if insights:
            self._day = algorithm.time.day
        return insights
        
    def on_securities_changed(self, algorithm, changed):
        if self._main_symbol in [added.symbol for added in changed.added_securities]:
            self._sma = algorithm.sma(self._main_symbol, 200, Resolution.HOUR)
        
#region imports
from AlgorithmImports import *

from alpha import EtfSmaAlphaModel
#endregion


class ParticleQuantumChamber(QCAlgorithm):

    def initialize(self):
        self.set_start_date(self.end_date - timedelta(5*365))
        self.set_cash(100_000)
      
        self._sso = Symbol.create('SSO', SecurityType.EQUITY, Market.USA)  # SSO = 2x levered SPX
        self._shy = Symbol.create('SHY', SecurityType.EQUITY, Market.USA)  # SHY = short term Treasury ETF
        
        self.set_warmup(200)
        
        self.set_benchmark('SPY')
        
        self.universe_settings.resolution = Resolution.HOUR
        self.set_alpha(EtfSmaAlphaModel(self._sso, self._shy))
        self.set_universe_selection(ManualUniverseSelectionModel([self._sso, self._shy]))
        self.set_execution(ImmediateExecutionModel())
        self.set_portfolio_construction(EqualWeightingPortfolioConstructionModel())