| Overall Statistics |
|
Total Trades 2531 Average Win 0% Average Loss 0% Compounding Annual Return 89.854% Drawdown 80.400% Expectancy 0 Net Profit 116021.620% Sharpe Ratio 1.676 Probabilistic Sharpe Ratio 64.717% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 1.231 Beta -0.3 Annual Standard Deviation 0.712 Annual Variance 0.507 Information Ratio 1.443 Tracking Error 0.739 Treynor Ratio -3.981 Total Fees $2610.05 |
class BuyAndHold(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2010, 1, 1)
self.SetEndDate(2020, 12, 31)
self.SetCash(100000) # Set Strategy Cash
self.leveragedETFSymbol = "SOXL"
self.minutesBeforeMarketClose = 10
self.counter = 0
self.investmentInterval = 14
#1. Update the AddEquity command to request TQQQ data
self.leveragedETF = self.AddEquity(self.leveragedETFSymbol, Resolution.Daily)
self.leveragedETF.SetDataNormalizationMode(DataNormalizationMode.Raw)
self.Schedule.On(self.DateRules.EveryDay(self.leveragedETFSymbol), self.TimeRules.BeforeMarketClose(self.leveragedETFSymbol, self.minutesBeforeMarketClose), self.dollarCostAverage)
def OnData(self, data):
'''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.
Arguments:
data: Slice object keyed by symbol containing the stock data
'''
#This conditional will only purchase one single share
if not self.Portfolio.Invested:
#2. Place an order for 100 shares of TQQQ and print the average fill price
self.SetHoldings(self.leveragedETFSymbol, 1)
#3. Display the Quantity of TQQQ Shares You Own
#self.SetHoldings([PortfolioTarget("SOXL", 0.6), PortfolioTarget("TQQQ", 0.2)])
#self.Debug("Time: " + str(self.UtcTime) + ", Buying Power: " + str(self.Portfolio.GetBuyingPower) + ", SOXL Shares: " + str(self.Portfolio["SOXL"].Quantity) + ", TQQQ Shares: " + str(self.Portfolio["TQQQ"].Quantity) + "Cash: " + str(self.Portfolio.Cash) )
#4. Debug the AveragePrice of TQQQ
#self.Debug("Time: " + str(self.Time) + ", Average Share Price: " + str(self.Portfolio["TQQQ"].AveragePrice) + ", " + str(self.Portfolio["TQQQ"].Price))
def dollarCostAverage(self):
self.counter += 1
if self.counter % self.investmentInterval:
investment = 1666
self.Portfolio.SetCash(self.Portfolio.Cash + investment);
self.SetHoldings(self.leveragedETFSymbol, 1)
self.Debug("Cash: " + str(self.Portfolio.Cash))
self.SetHoldings(self.leveragedETFSymbol, 1)