Hello QR Community,
I like to explicity name parameters in Python because I find the code a lot easier to read.
But I also notice different behavior. For example:
slices = self.History(
symbols = symbols,
periods = 365,
resolution = Resolution.Daily)
history = self.History(symbols, 365, Resolution.Daily)
gives two different results.
Looking at the codebase, I noticed two different call signatures:
public IEnumerable<Slice> History(IEnumerable<Symbol> symbols, int periods, Resolution? resolution = null)
public IEnumerable<DataDictionary<T>> History<T>(IEnumerable<Symbol> symbols, int periods, Resolution? resolution = null)
The only difference is
History<T>
Can someone explain to me what that is and what the underlying issue is?
Thank you!
Fred Painchaud
Hi Jonathan,
I will assume you already understand the object-oriented concepts I will be using.
Those two methods are overloaded; same names, different signatures. Moreover, the first one is not generic, the second one is. The first one returns a sequence of Slice objects. The second one returns a sequence of generic DataDictionary objects (most likely in the form of pandas DF). So, the difference in behavior lies in what format/structure they return.
Now, what you underline is new to me, which is that the method chosen to be called if you use named params or not varies. In terms of ways of overloading methods, C# is much richer than Python, there are many more ways in C#. I thus believe that this effect of different method selection is due to Python.NET, which is the technology used by LEAN to let Python code use C# code and vice versa. For some reason in how Python.NET handles calls, when you use named params, Python.NET selects the first method above and when you don't, it selects the second one. Well, according to your variables' names “slices” and “history”, so my analysis assumes you are telling the truth 😊 about the different behavior you are observing. 😊
Based on that, I would personally consider this a bug in Python.NET. However, if I am right, LEAN devs can't do much about it except maybe flag it themselves to the Python.NET project, which is totally independent from LEAN. Then, Python.NET devs would need to fix it, and then again, LEAN devs would need to upgrade their version of Python.NET they use, which in itself, is a big task because doing that can break other things so you need to perform regression testing and correct the issues that may pop up while using the new version. It can also have an impact on the behavior of algos already written and even running live…
Fred
Jonathan Ng
Perhaps related to this:
Fred Painchaud
Oh yes. It is not the same bug or at least, the test cases are not spotting the exact same bug BUT yes, that bug is certainly linked to the difficulty of coding a method dispatch algorithm correctly, and your bug is also about the same thing. At the end:
https://github.com/pythonnet/pythonnet/issues/1099#issuecomment-926146003
it says it is fixed in 3.0, but LEAN does not use 3.0 but a previous version. We don't know if all bugs related to method dispatch are fixed in 3.0 or only that one (related to Enums, int and float). Eventually, LEAN will most likely update Python and Python.NET. This is going to be a big step/work, however. On the other hand, unfortunately, the more they need to wait (because they have more pressing work to do), the more the upgrade might be painful…
It's the kind of dilemma that brings devs into foetal position from the stress… 😊
Fred
Jonathan Ng
Thank you, Fred Painchaud ! Very informative!
Jonathan Ng
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!