HI folks,
I am trying to access the Time property from the QCAlgorithm class in a separate class called EquitiesFundamentalSelectionModel. When I attempt to access the Time property from that class I get a type error exception.
Trying to dynamically access a method that does not exist throws a TypeError exception
I tried passing the QCAlgorithm into my SelectionModel so that I can access the time property but apparently I am doing something wrong here. Could someone see where my mistake lies?
Cheers,
Mitch
Nico Xenox
Hey Mitch Christow,
I changed self.Time with datetime.now() and deleted "self" from EquitiesFundamentalSelectionModel(self). I attached the backtest, hope it works.
Mitch Christow
HI Nico,
Thank you so much for taking a crack at this. I had done that before as well, but the date information is not populated at that point (which is why there are no purchases taking place. I was trying to refactor the code from a fellow Quantconnector. Louis had written this code, and I tried to move the Universe selection into its own class. I had ended up at point with the same code that you are shoeing, but there should be transactions. Here is the thread with the original code and my refactored code.
I don't know why the DateTime object is not propagating properly from QCAlgorithm, but I am hoping that smarter people than me can figure out what coding mistake I've made. If you look at Loius original code (cloned below) my refactored code should yield the same result. If you have any ideas what I am doing wrong I would be eternally grateful.
Cheers,
Mitch
Yuri Lopukhov
Hi, Mitch, I have fixed time bug here (it was also wrong in fine filter condition). However, this fine filter returns nothing. It seems there are no securities that match given sectors filter.
Nico Xenox
Hey Yuri Lopukhov,
nice work! If I change the filtered_fine so that it is correct:
I receive a runtime error:
So somewhere there might still be an error.
Mitch Christow
Yeah I am very perplexed about this one. It should be trivial to refactor the code from the cloned algorithm from Louis. I know that the refactoring worked once the result is the same as Louis' code. But somehow this is not working. In Louis' version, the code works since the main.py file inherits QCAlgorithm, which includes the Time component that is needed for back testing.
When one moves the three methods from main.py into their own universe selection class, then you lose access to Time. I tried passing in QCAlgorithm, which I am obviously doing wrong since that's the error that I got stuck on. In general it seems that it should be a whole lot simpler to access the methods from QCAlgorithm throughout the framework.
I really appreciate your help in trying to fix this.
Cheers,
Mitch
Mitch Christow
I have been able to clean up the refactored code to the point where the universe selection is returning the right data as part of the fine selection filters. However I am now stuck at an error which I believe is located in my alphamodel class. I am getting the error:
Trying to dynamically access a method that does not exist throws a TypeError exception. To prevent the exception, ensure each parameter type matches those required by the 'QuantConnect.Data.UniverseSelection.SecurityChanges'>) method. Please checkout the API documentation.
Which so far I have been unable to debug. Any helpful ideas would be greatly appreciated.
Yuri Lopukhov
Hi, Mitch Christow can you attach the updated code? Since its not possible to attach backtest with errors, just add self.Quit() somewhere before the error to have the backtest complete without error.
Mitch Christow
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!