Offering a faster alternative to calling Self.History(). In my tests, I've seen up to 10x speed gains; you may or may not see the same, depending on your use case. Eg: expect different different performance gains if you are fetching a single history bar for one asset, versus thousands of bars for hundreds of assets.

I'm calling it an Identity History indicator. It's not really an "indicator" per se, but leverages the indicator architecture, extending from the PythonIndicator base class. It has “Identity” functionality in that it doesn't perform any calculations – it just gives you back the price information, just like the QC Identity indicator. The difference is it gives you historical information, not just the most recent.

Hope this helps someone.

 

How to Use it:

Create an instance of the indicator, then warm it up using self.WarmUpIndicator() with your desired resolution. Once it's ready you can access the 'History' property of the indicator, which contains a list of the history bars.  An example is in the attached backtest.

Why it works:

Calling Self.WarmupIndicator() is faster than Self History() because the history request and the indicator update are done on the "C# side" instead of on the Python side, and the history requests don't need to be converted to pandas and then back to TradeBar.

https://www.quantconnect.com/terminal/processCache?request=embedded_backtest_72ebd6a78551b8ad251a6c1f827cb398.html

 

Notes:

  • You can only fetch historical data from some point in history up till present. With Self.History you can get fetch historical data between to arbitrary dates.
  • There are even further performance improvements to be made, like using a list instead of a dequeue (thanks Fred Painchaud  ) – I may get around to sharing an updated version soon.

 

Thanks to Fred Painchaud and Alexandre Catarino for validating / bouncing ideas around this effort.