nautechsystems / nautilus_trader

A high-performance algorithmic trading platform and event-driven backtester
https://nautilustrader.io
GNU Lesser General Public License v3.0
1.71k stars 402 forks source link

Add from_raw_arrays_to_list method for Bar #1623

Closed rsmb7z closed 2 months ago

rsmb7z commented 2 months ago

Pull Request

Add from_raw_arrays_to_list method for Bar.

Type of change

cjdsellers commented 2 months ago

I suppose this offers some advantages when called from Python to avoid a for loop?

Otherwise I'd imagine performance would be fairly close just calling from_raw_c in a loop from Cython?

cjdsellers commented 2 months ago

Might be good to add one test too?

rsmb7z commented 2 months ago

I suppose this offers some advantages when called from Python to avoid a for loop?

Otherwise I'd imagine performance would be fairly close just calling from_raw_c in a loop from Cython?

Yes correct, by having loop in Cython and passing the Numpy view is much faster straight from Python. I did some experiment with Wranglers and could be moved to Python offering same performance as currently in Cython. I think OrderBook is pending and then we could remove Cython for Wranglers.

Also having single method, we avoid checking InstrumentId/BarType and reuse the objects on every item where we know its same which also adds up some performance increase and the reason of not calling from_raw_c within Cython.