| Overall Statistics |
|
Total Trades 9098 Average Win 0.01% Average Loss -0.01% Compounding Annual Return 1.033% Drawdown 14.600% Expectancy 1.064 Net Profit 29.247% Sharpe Ratio 0.239 Probabilistic Sharpe Ratio 0.000% Loss Rate 42% Win Rate 58% Profit-Loss Ratio 2.56 Alpha -0.001 Beta 0.125 Annual Standard Deviation 0.032 Annual Variance 0.001 Information Ratio -0.411 Tracking Error 0.144 Treynor Ratio 0.061 Total Fees $9098.00 Estimated Strategy Capacity $72000000.00 Lowest Capacity Asset SPY R735QTJ8XC9X |
# region imports
from AlgorithmImports import *
# endregion
class SimpleMovingAverageAlgorithm(QCAlgorithm):
def Initialize(self):
# Set the cash we'd like to use for our backtest
self.SetCash(100000)
# Set the symbol we'd like to use for our backtest
self.symbol = self.AddEquity("SPY").Symbol
# Set the time frame for our simple moving average
self.time_frame = 30
# Set our simple moving average
self.sma = self.SMA(self.symbol, self.time_frame)
# Schedule an event to be fired every day at 4:00 PM
self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.At(16, 0), self.Trade)
def Trade(self):
# If we don't have data for our simple moving average, do nothing
if not self.sma.IsReady:
return
# Get the current price of the security
current_price = self.Securities[self.symbol].Price
# If the current price is greater than our simple moving average, buy
if current_price > self.sma.Current.Value:
self.Log("Purchasing {0}".format(self.symbol.Value))
self.Order(self.symbol, 1)
# If the current price is less than our simple moving average, sell
elif current_price < self.sma.Current.Value:
self.Log("Selling {0}".format(self.symbol.Value))
self.Order(self.symbol, -1)