Hi all,
I'm just wondering whether its possible to use the same symboldata class for both the universe selection and the alpha when using the classical algorithm setup? I was hoping to do this so as to minimise the number of history calls as well as redundent code.
Secondly, can you make a history call within the symboldata class rather than in the OnData or Update functions for cleaner code and less resource usage?
Thank you,
Nick
Fred Painchaud
Hi Nicholas,
Short answer is: it depends. :)
Long answer is: would you mind sharing some code? Sharing objects depend on if they are mutable or not, and if they are mutable, how they are mutated, when they are mutated, how they are reused, etc.
Medium answer is: normally, the class can be reused and history calls can happen pretty much anywhere.
Fred
Nicholas Fitzgerald
I have the code available here, though currently its very broken as I'm stumbling my way through the quantconnect API.
The fundamentals are:
So you can see why I would like to re-use my symboldata class as they essentially re-use the same data.
The code is attached below, which is in the main.py file. I've commented out my symboldata class and coarse selection function so as to be able to post it.
Thanks,
Nick
Fred Painchaud
Hi Nick,
As you say, the code is not complete but now that I understand what you want to do, I would say that YES you can re-use your dictionary of SymbolData objects between Universe Selection and Alpha. Essentially, your Universe Selection will update your SymbolData objects with new universe selections and will update the indies and your Alpha will read your SymbolData objects to provide insights.
I was being careful about maybe you wanting to update your SymbolData objects at multiple places. While there is nothing bad about it, it can create unwanted behaviour if it is done without careful consideration. Here, you won't have “multiple writers” but only one so it's fine.
You're on the right path. Do come back if you need more help later.
Cheers,
Fred
Nicholas Fitzgerald
Hi Fred,
Thank you for your advice! I appreciate the time you've taken to have a look and provide some advice. I will indeed. For now, I have one further question. I'm having difficulty with my history request in the SymbolData class, could you suggest how to write this section of code as well as how to apply it to my symbols?
Sincere regards,
Nick
Fred Painchaud
Sure:
It's getting late and we're not working with compiling backtests so I'm not 100% sure it compiles but it should be close. I could have worked on a complete backtest but I believe you will learn much more by doing it yourself. Come back if you need more help.
Nicholas Fitzgerald
Hi Fred,
Thank you for providing the code. You're right and I'll work through applying it to the symbols myself.
All the best,
Nick
Nicholas Fitzgerald
Hi Fred,
I've been able to access the history request in SymbolData by passing in the algorithm parameter so I can call algorithm.History(…..). However this means I need to pass in the algorithm parameter to the coarse selection function in order to initialise the SymbolData class on my symbols. I've been pouring through the forums and documentation trying to work out how to access the algorithm parameter through the coarse selection function, but it seems it only accepts 2 arguements (self, coarse). I've attached the code below. Could you point me in the right direction so I can achieve this?
Regards,
Nick
Fred Painchaud
Sure Nick.
In CoarseSelection, self is the algo 😊.
So you'll be able to do “SymbolData(self, symbol)”. Yeah, makes a lot of “self”…
You'll need some more edits here and there in your commented out CoarseSelection method but it's heading in the right direction.
Fred
Nicholas Fitzgerald
Hi Fred,
Haha it does indeed, thank you for clearing that up.
All the best,
Nick
Nicholas Fitzgerald
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!