| Overall Statistics |
|
Total Trades 103 Average Win 3.12% Average Loss -1.61% Compounding Annual Return 1184.685% Drawdown 7.900% Expectancy 0.942 Net Profit 193.216% Sharpe Ratio 13.954 Probabilistic Sharpe Ratio 99.911% Loss Rate 34% Win Rate 66% Profit-Loss Ratio 1.93 Alpha 5.278 Beta 0.155 Annual Standard Deviation 0.381 Annual Variance 0.145 Information Ratio 12.904 Tracking Error 0.394 Treynor Ratio 34.336 Total Fees $0.00 Estimated Strategy Capacity $6000000.00 Lowest Capacity Asset ETHUSD XJ Portfolio Turnover 72.86% |
from AlgorithmImports import *
class RetrospectiveYellowGreenAlligator(QCAlgorithm):
def Initialize(self):
# INITIALIZE
self.SetStartDate(2023, 1, 18)
self.SetEndDate(2023, 6, 19)
self._cash = 100000
self.SetCash(self._cash)
self.ticker = "ETHUSD"
self.AddCrypto(self.ticker, Resolution.Daily, Market.GDAX).Symbol
# SET BENCHMARK AND PREPARE COMPARATIVE PLOT
self.reference_ticker = self.History(self.Symbol(self.ticker), 10, Resolution.Daily)['close']
self._initialValue_ticker = self.reference_ticker.iloc[0]
# SET TECHNICAL INDICATORS
self.Bolband = self.BB(self.ticker, 10, 0.45, MovingAverageType.Simple, Resolution.Daily)
self.sto = self.STO(self.ticker, 8, 5, 5, Resolution.Daily)
# Risk management
self.AddRiskManagement(TrailingStopRiskManagementModel(0.06))
self.Debug("Stop loss hit")
self.AddRiskManagement(MaximumDrawdownPercentPerSecurity(0.05))
self.Debug("Drawdown limit hit")
def OnData(self, data):
price = self.Securities[self.ticker].Close
sto_value = self.sto.Current.Value
if price > self.Bolband.UpperBand.Current.Value and sto_value > 80:
self.SetHoldings(self.ticker, -1)
self.Debug("Short position triggered")
elif price > self.Bolband.MiddleBand.Current.Value and price < self.Bolband.UpperBand.Current.Value:
self.SetHoldings(self.ticker, 0.5)
self.Debug("Mid long triggered")
elif price < self.Bolband.MiddleBand.Current.Value and price > self.Bolband.LowerBand.Current.Value and sto_value < 20:
self.SetHoldings(self.ticker, 1)
self.Debug("Long position triggered")
elif self.Portfolio[self.ticker].UnrealizedProfitPercent > 0.07:
self.Liquidate(self.ticker)
self.Debug("Take profit triggered")
else:
self.SetHoldings(self.ticker, 1)
self.Plot("Strategy Equity", str(self.ticker), self._cash * self.Securities[self.ticker].Close / self._initialValue_ticker)
self.Plot("Strategy Equity", 'Portfolio Value', self.Portfolio.TotalPortfolioValue)
self.Plot("Bollinger", 'BB Lower', self.Bolband.LowerBand.Current.Value)
self.Plot("Bollinger", 'BB Upper', self.Bolband.UpperBand.Current.Value)
self.Plot("Bollinger", 'BB Middle', self.Bolband.MiddleBand.Current.Value)
self.Plot("Bollinger", str(self.ticker), self.Securities[self.ticker].Close)
self.Plot("Stochastic", "faststoch", self.sto.FastStoch.Current.Value)
self.Plot("Stochastic", "stochk", self.sto.StochK.Current.Value)
self.Plot("Stochastic", "stochd", self.sto.StochD.Current.Value)