Back

Debug a method in Custom Class is not shown when I try step by step debugging

So I have created this custom class and relevant code like this - 

Search for "rsiSelectionData.update(sec.EndTime, sec.AdjustedPrice, sec.DollarVolume)".

 

While debugging, the debugger goes to this line, but nest step it goes to next line

"validBuyValues =  filter(lambda x : x.isBuyZone, self.stateData.values())"

Not sure why the debugger does not go into the custom update method?

I get the debt statements though. Any ideas? thank you

 

from Alphas.RsiAlphaModel import RsiAlphaModel
from Execution.ImmediateExecutionModel import ImmediateExecutionModel
from System import *
from System.Collections.Generic import List
from QuantConnect import *
from QuantConnect.Algorithm import QCAlgorithm
from QuantConnect.Data.UniverseSelection import *

'''
Simple testing strategy so that find all stocks for which the RSI is more than 20
Buy. - if RSI of today is more than 25, but yesterday was less than 25
Liquidate - if RSI of open positions goes above 75

SELL - if RSI today is less than 75 but yesterday was more than 75
Liquidate - if RSI of open positions goes below 25
'''
class ResistanceVentralThrustAssembly(QCAlgorithm):

def Initialize(self):
self.SetStartDate(2019, 11, 20) # Set Start Date
self.SetEndDate(2019, 11, 21)
self.SetCash(10000) # Set Strategy Cash

# Strategy is for Daily data
self.UniverseSettings.Resolution = Resolution.Daily

#self.AddUniverse(self.MyCoarseFilterFunction, self.FineSelectionFunction)
self.AddUniverse(self.MyCoarseFilterFunction)
self.SetWarmUp(timedelta(20))

self.AddAlpha(RsiAlphaModel(60, Resolution.Daily))

self.SetExecution(ImmediateExecutionModel())

self.SetPortfolioConstruction(InsightWeightingPortfolioConstructionModel())

self.SetRiskManagement(TrailingStopRiskManagementModel(0.03))

self.__numberOfSymbols = 10
self.stateData = {}

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
'''

# if not self.Portfolio.Invested:
# self.SetHoldings("SPY", 1)
pass

def MyCoarseFilterFunction(self, coarse):

# Get all symbols by dollar volume
sortedByDollarVolume = sorted(coarse, key=lambda x: x.DollarVolume, reverse=True)
filtered = [x for x in sortedByDollarVolume
if x.Price > 10 ][:5]

for sec in filtered:

if sec.Symbol not in self.stateData:
self.stateData[sec.Symbol] = SelectionData(self, sec.Symbol, 14)

rsiSelectionData = self.stateData[sec.Symbol]
rsiSelectionData.update(sec.EndTime, sec.AdjustedPrice, sec.DollarVolume)

validBuyValues = filter(lambda x : x.isBuyZone, self.stateData.values())

return [x.Symbol for x in filtered[:1] ]

class SelectionData(object):
def __init__(self, algo, symbol, period):
self.symbol = symbol
self.rsi = ExponentialMovingAverage(period)
self.isBuyZone = False
self.volume = 0
self.algo = algo

def update(self, time, price, volume):
self.algo.Debug('test')
self.volume = volume
self.rsi.Update(time, price)
self.algo.Debug('rsi----')
self.algo.Debug(self.rsi)

 

Update Backtest







0

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.


HOw can I close a discussion if I do not ned any more?

0

Hey Ray! Mind posting the solution you discovered for others to learn? 

0

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.


I exacfly did not find a solution, but I worked my way around the step by step debug by multiple ways

  1. Added sefl.Debug to get some values
  2. tagging my trades with values I want to check and scenario under which the trade started like my RSI value etc etc
  3. I started adding brak points on exact function I want to debug and once the code reaches the function , I add as many watch variables I want.

So I can get the results I need

There should be a way to accept my comment as answer otherwise it troubles my OCD brain that this thing is still open

1

Update Backtest





0

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.


Loading...

This discussion is closed