| Overall Statistics |
|
Total Orders 3340 Average Win 20.07% Average Loss 0% Compounding Annual Return 25.018% Drawdown 58.000% Expectancy 0 Start Equity 50000 End Equity 879757.51 Net Profit 1659.515% Sharpe Ratio 0.711 Sortino Ratio 0.716 Probabilistic Sharpe Ratio 11.187% Loss Rate 0% Win Rate 100% Profit-Loss Ratio 0 Alpha 0.022 Beta 1.925 Annual Standard Deviation 0.266 Annual Variance 0.071 Information Ratio 0.785 Tracking Error 0.13 Treynor Ratio 0.098 Total Fees $56.47 Estimated Strategy Capacity $10000000.00 Lowest Capacity Asset IVV RUTTRZ1RC7L1 Portfolio Turnover 0.16% |
#region imports
from AlgorithmImports import *
#endregion
class RetrospectiveYellowGreenAlligator(QCAlgorithm):
def Initialize(self):
# INITIALIZE
self.SetStartDate(2012, 6, 1)
self.SetEndDate(2025, 4, 1)
self._cash=50000
self.SetCash(self._cash)
self.ticker = "IVV"
self.spy = self.AddEquity("SPY", Resolution.Daily).Symbol
self._ticker = self.AddEquity(self.ticker, Resolution.Daily).Symbol
self._numDays = 20
# SET BENCHMARK AND PREPARE COMPARATIVE PLOT
self.reference = self.History(self.spy, 10, Resolution.Daily)['close']
self._initialValue = self.reference.iloc[0]
self.reference_ticker = self.History(self.Symbol(self.spy), 10, Resolution.Daily)['close']
self._initialValue_ticker = self.reference_ticker.iloc[0]
self._std = self.STD(self._ticker, self._numDays, Resolution.Daily)
self.Log(f" Directory : {dir(self._std)}")
def OnData(self, data):
self._close = self.Securities[self.ticker].Close
self.stopPrice = self._close * (1 + 0.05 * self._std.Current.Value/self._numDays)
self.limitPrice = self._close * (1 - 0.10 * self._std.Current.Value/self._numDays)
self.stopLimitTicket = self.StopLimitOrder(self.ticker, 100, self.stopPrice, self.limitPrice)
if self.Securities[self.ticker].Price < self._close * (1 - 0.5*self._std.Current.Value/self._numDays):
self.Liquidate()
#self.SetHoldings(self.ticker, -1)
self.Plot("Strategy Equity", "SPY", self._cash*self.Securities["SPY"].Close/self._initialValue)
#self.Plot("Strategy Equity", str(self.ticker), self._cash*self.Securities[self.ticker].Close/self._initialValue_ticker)
self.Plot("Limits", "Stop", self.stopPrice)
self.Plot("Limits", "Limit", self.limitPrice)
self.Plot("Limits", str(self.ticker), self.Securities[self.ticker].Close)