| Overall Statistics |
|
Total Orders 1 Average Win 0% Average Loss 0% Compounding Annual Return 20.319% Drawdown 29.600% Expectancy 0 Start Equity 100000 End Equity 174181.15 Net Profit 74.181% Sharpe Ratio 0.606 Sortino Ratio 0.718 Probabilistic Sharpe Ratio 19.329% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0.101 Beta 1.139 Annual Standard Deviation 0.29 Annual Variance 0.084 Information Ratio 0.644 Tracking Error 0.171 Treynor Ratio 0.154 Total Fees $6.54 Estimated Strategy Capacity $630000000.00 Lowest Capacity Asset AAPL R735QTJ8XC9X Portfolio Turnover 0.09% |
# code to combine indicators and backtest the performance
# region imports
from AlgorithmImports import *
# endregion
class Indicators(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 1, 1) # Set Start Date
self.SetEndDate(2023, 1, 1) # Set Start Date
self.SetCash(100000) # Set Strategy Cash
self.spy = self.AddEquity("AAPL", Resolution.Daily).Symbol #set data for SPY
self.sma = self.SMA(self.spy, 30, Resolution.Daily) #set data for SMA
closing_price = self.History(self.spy, 30, Resolution.Daily)["close"] #take historic prices for SMA
for time, price in closing_price.loc[self.spy].items():
self.sma.Update(time,price) #update first 30 values of SMA to historic prices
def OnData(self, data: Slice):
if not self.sma.IsReady: # to check if SMA is ready or not as it is a average indicator
return
#Another indicator to check for high and low of 60 Daily
hist = self.History(self.spy, timedelta(252), Resolution.Daily)
low = min(hist["low"])
high = min(hist["high"])
#combining both trading logics - SMA + High/Low
price = self.Securities[self.spy].Price
if price >= 1.05*high and self.sma.Current.Value > price:
if not self.Portfolio[self.spy].IsLong:
self.SetHoldings(self.spy,1)
if price <= 0.95*low and self.sma.Current.Value < price:
if not self.Portfolio[self.spy].IsShort:
self.SetHoldings(self.spy,-1)
self.Plot("Benchmark", "60m-High", high)
self.Plot("Benchmark", "60m-Low", low)
self.Plot("Benchmark", "60m-High", self.sma.Current.Value)