I'm currently working to optimize a function from the research environment to start with; which I am making progress with magic commands or numba decorators; though I think I need to stick to cython. With the final deployment the goal I want something to work in the backtest environment, though I see no examples of this anywhere yet. Are there any examples of cython for our workflow here? All my reading is pointing to the need to compile code and see no means of doing this currently. I may swing back to numba, but I think it may not be sufficient in my case.
Aaron Janeiro Stone
While Cython can be used in a QuantBook by means of using magic/decorators (for usage, see https://ipython-books.github.io/55-accelerating-python-code-with-cython/ ), it seems impossible to reference a compiled binary from a strategy. Thus, importing into a .py doesn't seem possible. If speed is of the utmost importance, you can consider writing the strategy in C# which can bring similar improvements.
Aaron Janeiro Stone
Just following up with some additional findings…
As per http://docs.cython.org/en/latest/src/tutorial/pure.html, we can use decorators within .py to get some .pyx functionality. See the attached backtest for an example! Note that this does not seem to compile, however (this can be verified by introducing a cython.compiled switch).
DanRock
Thank you for the response. I've been playing around with that today, running a check for whether it compiled seems to show its not. Started adapting it to numba to play with it, but now I ran out of logging quota for the day. Will mess with it tomorrow again with it at daily…oops. I suppose I may have to dig deep for my old cpp skills and try to adapt to c# after all. Would be nice if these libraries are available to have them working smoothly for trading as that is where it matters most.
Appreciate the thoughts!
Louis Szeto
Hi DanRock and Aaron
Thank you for the answer Aaron! We'd like to give an example for numba jit compiler using decorator for improving the speed. Please check the attached backtest.
Best
Louis Szeto
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.
DanRock
Thank you for the example Luis!!!
I assume since this is for Numba, Cython is off the tables for now in the trading side. I will do my best to work toward Numba, but would be nice to have Cython as well. But this will be extremely helpful none the less.
DanRock
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!