Overall Statistics |
Total Trades 8 Average Win 0% Average Loss -6.82% Compounding Annual Return -98.705% Drawdown 23.000% Expectancy -1 Net Profit -23.011% Sharpe Ratio -1.742 Probabilistic Sharpe Ratio 1.991% Loss Rate 100% Win Rate 0% Profit-Loss Ratio 0 Alpha -1.332 Beta -0.376 Annual Standard Deviation 0.553 Annual Variance 0.306 Information Ratio 0.016 Tracking Error 0.968 Treynor Ratio 2.564 Total Fees $10.53 |
class VerticalNadionGearbox(QCAlgorithm): def Initialize(self): self.SetStartDate(2020, 2, 20) # Set Start Date self.SetEndDate(2020, 3, 12) self.SetCash(100000) # Set Strategy Cash symbols = [ Symbol.Create("SPY", SecurityType.Equity, Market.USA) ] self.SetUniverseSelection( ManualUniverseSelectionModel(symbols) ) self.UniverseSettings.Resolution = Resolution.Daily self.AddAlpha(MyAlphaModel()) self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel()) self.SetRiskManagement(MaximumDrawdownPercentPerSecurityCustom(0.05)) self.SetExecution(ImmediateExecutionModel()) def OnData(self, data): pass class MyAlphaModel(AlphaModel): emited = False def Update(self, algorithm, data): if not self.emited: self.emited = True return [Insight.Price("SPY", timedelta(365), InsightDirection.Up)] return [] class MaximumDrawdownPercentPerSecurityCustom(RiskManagementModel): def __init__(self, maximumDrawdownPercent = 0.01): self.maximumDrawdownPercent = -abs(maximumDrawdownPercent) self.liquidated = set() self.currentTargets = set() def ManageRisk(self, algorithm, targets): # Reset liquidated symbols on new targets algorithm.Log(targets[0].Quantity) if set(targets) != self.currentTargets: algorithm.Log("Different") self.currentTargets = set(targets) self.liquidated = set() targets = [] for kvp in algorithm.Securities: security = kvp.Value pnl = security.Holdings.UnrealizedProfitPercent if pnl < self.maximumDrawdownPercent or security.Symbol in self.liquidated: # liquidate targets.append(PortfolioTarget(security.Symbol, 0)) if algorithm.Securities[security.Symbol].Invested: self.liquidated.add(security.Symbol) #algorithm.Log(f"Liquidating {security.Symbol}") return targets