| Overall Statistics |
|
Total Trades 8 Average Win 11.09% Average Loss -12.00% Compounding Annual Return 20.566% Drawdown 18.900% Expectancy 0.443 Net Profit 20.628% Sharpe Ratio 0.924 Sortino Ratio 0.725 Probabilistic Sharpe Ratio 45.294% Loss Rate 25% Win Rate 75% Profit-Loss Ratio 0.92 Alpha 0.093 Beta 0.331 Annual Standard Deviation 0.158 Annual Variance 0.025 Information Ratio -0.067 Tracking Error 0.226 Treynor Ratio 0.442 Total Fees $12.59 Estimated Strategy Capacity $700000000.00 Lowest Capacity Asset SPY R735QTJ8XC9X Portfolio Turnover 2.18% |
from AlgorithmImports import *
class BootCampTask(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 1, 1)
self.SetEndDate(2021, 1, 1)
self.SetCash(100000)
spy = self.AddEquity("SPY", Resolution.Daily)
spy.SetDataNormalizationMode(DataNormalizationMode.Raw)
self.spy = spy.Symbol
self.SetBenchmark("SPY")
self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Margin)
self.entryPrice = 0
self.period = timedelta(31)
self.nextEntryTIme = self.Time
def OnData(self, data):
if not self.spy in data:
return
# TradeBars
# QuoteBars
#price = data.Bars[self.spy].Close
price = data[self.spy].Close
#price = self.Securities[self.spy].Close
if not self.Portfolio.Invested:
if self.nextEntryTIme <= self.Time:
self.SetHoldings(self.spy, 1)
# self.MarketOrder(self.spy, int(self.Portfolio.Cash / price))
self.Log("Buy SPY @" + str(price))
self.entryPrice = price
elif self.entryPrice *1.1 < price or self.entryPrice *.9 >price:
self.Liquidate()
self.Log("Sell SPY @" + str(price))
self.nextEntryTIme = self.Time + self.period