| Overall Statistics |
|
Total Orders 81 Average Win 1.99% Average Loss -98.63% Compounding Annual Return 28.381% Drawdown 77.200% Expectancy -0.629 Net Profit 1116.162% Sharpe Ratio 0.68 Sortino Ratio 0.731 Probabilistic Sharpe Ratio 8.502% Loss Rate 64% Win Rate 36% Profit-Loss Ratio 0.02 Alpha 0.104 Beta 2.174 Annual Standard Deviation 0.393 Annual Variance 0.155 Information Ratio 0.664 Tracking Error 0.289 Treynor Ratio 0.123 Total Fees $25.66 Estimated Strategy Capacity $13000000.00 Lowest Capacity Asset AVGO UEW4IOBWVPT1 Portfolio Turnover 0.18% |
from AlgorithmImports import *
class GrowthStocksAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2014, 1, 1) # Set Start Date
self.SetEndDate(2024, 1, 1) # Set End Date
self.SetCash(10000) # Set Strategy Cash
self.UniverseSettings.Resolution = Resolution.Daily
self.AddUniverse(self.CoarseSelectionFunction, self.FineSelectionFunction)
self.Schedule.On(self.DateRules.MonthStart(), self.TimeRules.At(10, 0), self.RebalancePortfolio)
self.trailingStopLossPercent = 0.7 # 15% trailing stop
self.highWaterMarks = dict() # Dictionary to store high water marks for symbols
self.changes = [] # To track added securities
def CoarseSelectionFunction(self, coarse):
filtered_coarse = [x for x in coarse if x.DollarVolume > 1e6 and x.Price > 5]
sorted_by_liquidity = sorted(filtered_coarse, key=lambda x: x.DollarVolume, reverse=True)
selected_symbols = [x.Symbol for x in sorted_by_liquidity if x.Price * x.DollarVolume / x.Price > 2e9]
return selected_symbols[:100]
def FineSelectionFunction(self, fine):
filtered_fine = [x for x in fine if x.OperationRatios.RevenueGrowth.OneYear > 0.0
and x.OperationRatios.NetIncomeGrowth.OneYear > 0.0
and x.EarningReports.BasicEPS.TwelveMonths > 0
and (x.ValuationRatios.PEGRatio > 0 and x.ValuationRatios.PEGRatio < 1.5)
and x.FinancialStatements.BalanceSheet.TotalEquity.Value > 0]
sorted_by_growth = sorted(filtered_fine, key=lambda x: x.OperationRatios.RevenueGrowth.OneYear, reverse=True)
return [x.Symbol for x in sorted_by_growth[:10]]
def RebalancePortfolio(self):
if self.changes is None or len(self.changes) == 0:
return
weight_per_security = 1.0 / len(self.changes)
for symbol in self.changes:
if not self.Securities[symbol].Invested:
self.SetHoldings(symbol, weight_per_security)
self.highWaterMarks[symbol] = self.Securities[symbol].Price
self.changes = [] # Reset the changes after rebalancing
def OnSecuritiesChanged(self, changes):
self.changes = [x.Symbol for x in changes.AddedSecurities]
def OnData(self, data):
symbolsToLiquidate = []
for symbol, highWaterMark in self.highWaterMarks.items():
# Check if the symbol has data before accessing its Close price
if symbol in data and data[symbol] is not None:
currentPrice = data[symbol].Close
if currentPrice > highWaterMark:
self.highWaterMarks[symbol] = currentPrice
trailingStopPrice = highWaterMark * (1 - self.trailingStopLossPercent)
if currentPrice < trailingStopPrice:
symbolsToLiquidate.append(symbol)
for symbol in symbolsToLiquidate:
self.Liquidate(symbol)
del self.highWaterMarks[symbol]