| Overall Statistics |
|
Total Orders 7 Average Win 3.39% Average Loss -0.48% Compounding Annual Return 13.493% Drawdown 2.900% Expectancy 4.363 Start Equity 2000000 End Equity 2108706.1 Net Profit 5.435% Sharpe Ratio 0.472 Sortino Ratio 0.739 Probabilistic Sharpe Ratio 51.986% Loss Rate 33% Win Rate 67% Profit-Loss Ratio 7.05 Alpha -0.055 Beta 0.52 Annual Standard Deviation 0.086 Annual Variance 0.007 Information Ratio -1.707 Tracking Error 0.084 Treynor Ratio 0.078 Total Fees $212.20 Estimated Strategy Capacity $570000000.00 Lowest Capacity Asset AMZN R735QTJ8XC9X Portfolio Turnover 2.31% |
from AlgorithmImports import *
class MomentumTradingAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2023, 12, 20)
self.SetEndDate(2024, 5, 20)
self.SetCash(2_000_000)
self.symbol = self.AddEquity("AMZN", Resolution.Daily).Symbol
self.sma = self.SMA(self.symbol, 20, Resolution.Daily)
self.weight = 0.50 # 50% of portfolio
def OnData(self, data):
if not self.sma.IsReady or self.symbol not in data: ## we don’t have enough data (20 days), exit early
return
price = data[self.symbol].Close
sma_value = self.sma.Current.Value
if price > sma_value and not self.Portfolio[self.symbol].Invested:
self.SetHoldings(self.symbol, self.weight) # enter long (50% allocation)
elif price <= sma_value and self.Portfolio[self.symbol].Invested:
self.Liquidate(self.symbol) # If we ARE currently holding AMZN, sell everything