| Overall Statistics |
|
Total Orders 294 Average Win 0% Average Loss 0% Compounding Annual Return 4.847% Drawdown 25.700% Expectancy 0 Start Equity 1000000 End Equity 3184531.00 Net Profit 218.453% Sharpe Ratio 0.205 Sortino Ratio 0.188 Probabilistic Sharpe Ratio 0.200% Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0.002 Beta 0.279 Annual Standard Deviation 0.069 Annual Variance 0.005 Information Ratio -0.225 Tracking Error 0.126 Treynor Ratio 0.05 Total Fees $294.00 Estimated Strategy Capacity $370000000.00 Lowest Capacity Asset QQQ RIWIV7K5Z9LX Portfolio Turnover 0.00% |
from AlgorithmImports import *
class MonthlyInvestmentAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2000, 1, 1) # Set Start Date
#self.SetEndDate(2023, 1, 1) # Set End Date
self.SetCash(1000000) # Set Strategy Cash
self.symbol = self.AddEquity("qqq", Resolution.Daily).Symbol
# Schedule the monthly investment
self.Schedule.On(self.DateRules.MonthStart(self.symbol),
self.TimeRules.AfterMarketOpen(self.symbol),
self.InvestMonthly)
# Initialize variables to track total investment
self.total_investment = 0
self.monthly_investment = 1000
def InvestMonthly(self):
# Calculate the number of shares to buy
quantity = self.monthly_investment / self.Securities[self.symbol].Price
self.MarketOrder(self.symbol, quantity)
# Increment the total investment amount
self.total_investment += self.monthly_investment
# print out time of investment and amount invested
#self.Debug(f"{self.Time}: Total Amount Invested: {self.total_investment}")
holdings_value = self.Portfolio[self.symbol].Quantity * self.Securities[self.symbol].Price
# print out total investment and final value of holdings, exclude the cash
self.Debug(f"{self.Time}: Total Value of Holdings: {holdings_value}")
# draw a line on the chart to indicate the investment
self.Plot("Investment", "Investment", holdings_value)
def OnEndOfAlgorithm(self):
self.Log(f"Total Amount Invested: {self.total_investment}")
holdings_value = self.Portfolio[self.symbol].Quantity * self.Securities[self.symbol].Price
# print out total investment and final value of holdings, exclude the cash
self.Log(f"Final Value of Holdings: {holdings_value}")