| Overall Statistics |
|
Total Trades 57 Average Win 3.08% Average Loss -1.87% Compounding Annual Return 6.695% Drawdown 9.400% Expectancy 0.226 Net Profit 13.858% Sharpe Ratio 0.375 Probabilistic Sharpe Ratio 15.049% Loss Rate 54% Win Rate 46% Profit-Loss Ratio 1.64 Alpha 0.074 Beta -0.127 Annual Standard Deviation 0.137 Annual Variance 0.019 Information Ratio -0.466 Tracking Error 0.273 Treynor Ratio -0.402 Total Fees $88.95 Estimated Strategy Capacity $1000000000.00 Lowest Capacity Asset SPY R735QTJ8XC9X Portfolio Turnover 7.78% |
# region imports
from AlgorithmImports import *
# endregion
class MeasuredGreenSheep(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 1, 1)
self.SetEndDate(2022,1,1)
self.SetCash(100000)
self.spy=self.AddEquity('SPY', Resolution.Daily).Symbol
#include incidcator
self.sma=self.SMA(self.spy,30,Resolution.Daily)
closing_prices = self.History(self.spy,30,Resolution.Daily)['close']
for time, price in closing_prices.loc[self.spy].items():
self.sma.Update(time, price)
def OnData(self, data: Slice):
if not self.sma.IsReady:
return
hist = self.History(self.spy, timedelta(365),Resolution.Daily)
low = min(hist['low'])
high = max(hist['high'])
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)
elif price * 0.95 <= low and self.sma.Current.Value > price:
if not self.Portfolio[self.spy].IsShort:
self.SetHoldings(self.spy,-1)
else:
self.Liquidate()
self.Plot("Benchmark","52w-High",high)
self.Plot("Benchmark","52w-Low",low)
self.Plot("Benchmark","SMA",self.sma.Current.Value)
pass