Hi everyone,
I have solely used python in the past for running backtests. With recent backtesting taking a very long time, I am interested in transitioning to c# to improve speed. First, is this assumption that C# will run faster than python in backtests correct (by this I mean the backtest simulation, not the jupyter notebook research file)?
Also, when I click ‘Create a New Algorithm’ to begin a project in c#, I see that a python file (main.py) and research file (research.ipynb) are created. How can I code in the c# environment instead of python (I tried changing main.py to main.cs to no avail)? I see that when I access the research file I am able to change from python to c# but it is not clear how to do so with the main file.
If c# is only available in the jupyter notebook, how do you port c# code from the jupyter notebook to the main file? What would be the advantage of using c# in the research file if it is not usable in main?
If anyone could give direction, that would be very helpful!
Thanks
Arthur Asenheimer
If you want to create a C# project, you have to change you preferred language first. See here for further instructions.
Regarding speed, in general, C# is faster than Python of course. But it strongly depends on your algorithm whether and how much you can speed up your algorithm by switching to C#. As you can see here, the speed difference isn't very large for a “do-nothing” algorithm, but it can increase quickly if you have a lot of heavy computations in your algorithm.
Before switching to C# (in particular if you're not an experienced C# programmer), you should consider optimizing the design of your algorithm (use of optimal data structures, caching and avoiding unnecessary computations etc). In most cases you can get a reasonable backtest speed if you pay attention to these aspects. That, at least, is what I found in my experience.
Justin E
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!