| Overall Statistics |
|
Total Orders 302 Average Win 6.05% Average Loss -2.98% Compounding Annual Return 16.242% Drawdown 40.300% Expectancy 0.247 Start Equity 5000 End Equity 10618.78 Net Profit 112.376% Sharpe Ratio 0.443 Sortino Ratio 0.371 Probabilistic Sharpe Ratio 8.443% Loss Rate 59% Win Rate 41% Profit-Loss Ratio 2.03 Alpha 0.102 Beta 0.379 Annual Standard Deviation 0.305 Annual Variance 0.093 Information Ratio 0.15 Tracking Error 0.317 Treynor Ratio 0.356 Total Fees $302.00 Estimated Strategy Capacity $1700000000.00 Lowest Capacity Asset TSLA UNU3P8Y3WFAD Portfolio Turnover 13.84% |
from AlgorithmImports import *
class HSMAlphaStreamModel(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 1, 1)
self.SetEndDate(2024, 12, 31)
self.SetCash(5000)
# Add Tesla stock
self.symbol = self.AddEquity("TSLA", Resolution.Daily).Symbol
# Use AlphaStreams-compatible brokerage
self.SetBrokerageModel(BrokerageName.AlphaStreams)
# Framework modules
self.SetAlpha(HSMAlphaModel(self.symbol))
self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel())
self.SetExecution(ImmediateExecutionModel())
self.SetRiskManagement(TrailingStopRiskManagementModel(0.015)) # Optional: 1.5% trailing stop
class HSMAlphaModel(AlphaModel):
def __init__(self, symbol):
self.symbol = symbol
self.name = "HSMAlphaModel"
self.lastInsightTime = None
self.rsi = None
self.macd = None
self.adx = None
self.atr = None
def Update(self, algorithm, data):
insights = []
# Initialize indicators only once
if self.rsi is None:
self.rsi = algorithm.RSI(self.symbol, 14, MovingAverageType.Wilders, Resolution.Daily)
self.macd = algorithm.MACD(self.symbol, 12, 26, 9, MovingAverageType.Exponential, Resolution.Daily)
self.adx = algorithm.ADX(self.symbol, 14, Resolution.Daily)
self.atr = algorithm.ATR(self.symbol, 14, MovingAverageType.Wilders, Resolution.Daily)
return []
# Wait until indicators are ready
if not (self.rsi.IsReady and self.macd.IsReady and self.adx.IsReady and self.atr.IsReady):
return []
# Prevent emitting multiple insights per day
if self.lastInsightTime is not None and self.lastInsightTime.date() == algorithm.Time.date():
return []
# Signal logic
if (
self.rsi.Current.Value > 45
and self.macd.Current.Value > self.macd.Signal.Current.Value
and self.adx.Current.Value > 15
):
insight = Insight.Price(
self.symbol,
timedelta(days=5),
InsightDirection.Up,
magnitude=0.03, # Higher magnitude for TSLA
confidence=0.8 # Increased confidence for TSLA's volatility
)
insights.append(insight)
algorithm.Debug(f" TSLA Insight Emitted: {insight}")
self.lastInsightTime = algorithm.Time
return insights