| Overall Statistics |
|
Total Trades 226 Average Win 8.33% Average Loss -1.28% Compounding Annual Return 180.161% Drawdown 33.700% Expectancy 2.628 Net Profit 2320.468% Sharpe Ratio 2.919 Probabilistic Sharpe Ratio 97.494% Loss Rate 52% Win Rate 48% Profit-Loss Ratio 6.52 Alpha 1.163 Beta 0.42 Annual Standard Deviation 0.419 Annual Variance 0.175 Information Ratio 2.542 Tracking Error 0.425 Treynor Ratio 2.908 Total Fees $4668.75 Estimated Strategy Capacity $220000000.00 Lowest Capacity Asset TSLA UNU3P8Y3WFAD |
from datetime import timedelta
class MOMAlphaModel(AlphaModel):
def __init__(self):
self.mom = []
def OnSecuritiesChanged(self, algorithm, changes):
for security in changes.AddedSecurities:
symbol = security.Symbol
self.mom.append({"symbol":symbol, "indicator":algorithm.MOM(symbol, 14, Resolution.Daily)})
def Update(self, algorithm, data):
ordered = sorted(self.mom, key=lambda kv: kv["indicator"].Current.Value, reverse=True)
return Insight.Group([Insight.Price(ordered[0]['symbol'], timedelta(1), InsightDirection.Up), Insight.Price(ordered[1]['symbol'], timedelta(1), InsightDirection.Flat) ])
class FrameworkAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2018, 10, 1)
# self.SetEndDate(2020, 12, 1)
self.SetCash(100000)
symbols = [Symbol.Create("TSLA", SecurityType.Equity, Market.USA), Symbol.Create("BND", SecurityType.Equity, Market.USA)]
self.UniverseSettings.Resolution = Resolution.Daily
self.SetUniverseSelection(ManualUniverseSelectionModel(symbols))
self.SetAlpha(MOMAlphaModel())
self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel())
self.SetRiskManagement(MaximumDrawdownPercentPerSecurity(0.02))
#1. Set the Execution Model to an Immediate Execution Model
self.SetExecution(ImmediateExecutionModel())