Back

Fastest way to execute a C# algorithm

Hi everyone,

My experience with research notebooks has been great, but I always get limited by speed at some point due to the python experience and the complexity of my alpha idea. Using a complex lamba function and "apply"ing it to a dataframe is straightforward enough to make, but has some drawdowns:

1) Slow. Because it will be done in python and not C
2) Non-transferable. Ok, it technically is transferable... if you plan to use the History API every cycle to generate an entire dataframe then apply it to that. But.... see 1)

So to kill two birds with one stone, I want to find a way to work on my alpha in C#, and then analyze the results in a notebook. Ideally I want to do all the work from within a notebook but that's not as simple as it sounds.


Right now, to achieve what I want, I can:

1) Build my Alpha in C#
2) Execute the backtest, saving the trading results to file
3) Open an analyze the results in a notebook for pretty printing.

This is a slow cycle really, but it will do for now.

What I would like to achieve is:
1) Build my alpha in a C# notebook and see the results instantly in a nice chart.
In a similar way to how zipline can be run really.

 

To get to this point, first I need notebooks to use C#, which is kinda here!
 

https://devblogs.microsoft.com/dotnet/net-core-with-juypter-notebooks-is-here-preview-1/

But this only works for dot net core 3.0
The other part of my problem is, I don't know how to execute a strategy and get back the results from a simple function call. Something like this
var Results = Lean.Run(MyAlpha)

Is what I'm looking to achieve. Where Results will contain a bunch of performance results along with actual trades/times etc.

Are there some tests that I could look at which would be close to what I want to achieve? I am pretty lost in all the code to be honest. The standard way to run an algorithm pulls config values from file, then runs the algo as a job in a separate thread. I want to avoid all of that and just execute my algo as cleanly as possible. From the test examples, there are many mock setups and I'm not sure what handlers etc are neccessary etc.

If anyone could give me a bit of direction here it would be much appreciated.

Thanks
 

Update Backtest







0

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.


Ok, maybe my code would be more like: 

var Results = Lean.Run<MyAlgorithm>();

 

0

We have C# notebook support in the research environment at the moment if you create a C# project it'll assign a C# notebook :)

We do plan to allow quickly backtesting alphas in the research environment which is why we integrated them so you could access your classes there. Having LEAN run the full backtest will be just as slow though as it's still running the event-based research. Is that what you'd expect?

0

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 be honest for some reason I thought that the C# notebooks had been removed - no idea why I missed that. So I'm happy C# works in notebooks - after checking it out though it doesn't seem to be the newer dot net core 3 version, which would allow for some nice charting tools etc. This really would be a fantastic upgrade to QC.

https://www.hanselman.com/blog/AnnouncingNETJupyterNotebooks.aspx

 

 

Basically, what I am trying to do is speed up the research cycle and ensure integrity when moving from research to forward testing/live later.

It would be 4 sections in a c# notebook

1) Algo code

2) Alpha (other module whatever) code

3) Backtest execution and output code

4) large custom analysis section similar to tearsheets


We almost have this right now just with the lab, but we don't have the option for custom anaylsis without exporting the returns and pasting them into a notebook etc etc. I want to streamline that part really.  Hope that makes sense :-)

 

 

0

Sorry, to answer your question - yes it would be fast enough.

0

Update Backtest





0

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.


Loading...

This discussion is closed