Hi All,
I am trying to run some debugging using VSCode, I have tried reinstalling leanCLI, pylance etc but can not get passed this hurdle. From my understanding it is not importing correctly the subclass QCAlgorithm correctly. This is across all projects and not not isolated. Please see the screenshot attached, any help on solving this would be great. Just to test and make sure it was not my own code being the issue for the example below I am using one of the templates provided and still having issues.
Thanks
# region imports
from QuantConnect.Algorithm import QCAlgorithm
from AlgorithmImports import *
import pdb
pdb.set_trace()
from alpha import VIXAlphaModel
# endregion
class VIXPredictsStockIndexReturns(QCAlgorithm):
undesired_symbols_from_previous_deployment = []
checked_symbols_from_previous_deployment = False
previous_direction_by_symbol = {}
week = -1
def Initialize(self):
self.SetStartDate(2022, 7, 1)
self.SetEndDate(2023, 7, 1)
self.SetCash(1_000_000)
self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Margin)
self.Settings.MinimumOrderMarginPortfolioPercentage = 0
self.UniverseSettings.DataNormalizationMode = DataNormalizationMode.Raw
self.AddUniverseSelection(ManualUniverseSelectionModel([Symbol.Create("OEF", SecurityType.Equity, Market.USA)]))
lookback_days = self.GetParameter("lookback_days", 504)
self.AddAlpha(VIXAlphaModel(
self,
lookback_days,
self.GetParameter("long_percentile", 90),
self.GetParameter("short_percentile", 10)
))
self.Settings.RebalancePortfolioOnInsightChanges = False
self.Settings.RebalancePortfolioOnSecurityChanges = False
self.SetPortfolioConstruction(EqualWeightingPortfolioConstructionModel(self.rebalance_func))
self.AddRiskManagement(NullRiskManagementModel())
self.SetExecution(ImmediateExecutionModel())
self.SetWarmUp(timedelta(lookback_days*2))
def rebalance_func(self, time):
# Rebalance when all of the following are true:
# - Not warming up
# - There is QuoteBar data in the current slice
# - It's a new week or the insight direction has changed
direction_by_symbol = {insight.Symbol: insight.Direction for insight in self.Insights}
if not self.IsWarmingUp and self.CurrentSlice.QuoteBars.Count > 0 \
and (direction_by_symbol != self.previous_direction_by_symbol or self.Time.date().isocalendar()[1] != self.week):
self.week = self.Time.date().isocalendar()[1]
self.previous_direction_by_symbol = direction_by_symbol
return time
return None
def OnData(self, data):
# Exit positions that aren't backed by existing insights.
# If you don't want this behavior, delete this method definition.
if not self.IsWarmingUp and not self.checked_symbols_from_previous_deployment:
for security_holding in self.Portfolio.Values:
if not security_holding.Invested:
continue
symbol = security_holding.Symbol
if not self.Insights.HasActiveInsights(symbol, self.UtcTime):
self.undesired_symbols_from_previous_deployment.append(symbol)
self.checked_symbols_from_previous_deployment = True
for symbol in self.undesired_symbols_from_previous_deployment[:]:
if self.IsMarketOpen(symbol):
self.Liquidate(symbol, tag="Holding from previous deployment that's no longer desired")
self.undesired_symbols_from_previous_deployment.remove(symbol)
Mia Alissi
From the information provided in the extracts, it seems like you're having trouble with debugging in VS Code. Here are some steps you can follow to debug Python code in VS Code:
lean backtest "<projectName>" --debug ptvsd
, and then wait until the CLI tells you to attach to the debugger.If you're still having trouble, it might be due to some issues with your Python environment or the way your project is set up. Make sure you have the correct Python version installed and that your project dependencies are correctly set up.
If the problem persists, you might want to check the QuantConnect forum for similar issues or post your question there to get help from the community.
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Nicholas Pearce
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!