Use the link below to go the original post
Click here to see the full blog post
It's a bit confusing as it misses killer backtester features that zipline doesn't have and points out to something not very important from my point of view. I can give you more details if you want, but probably not in this topic.
It would really be interesting to learn about those "killer" features.
With regards to
live implementation (to keep it separate). The platform makes no distinction between data feeds and also no distinction between brokers.
You obviously need to load a different data feed when connecting to Interactive Brokers and plug-in the Interactive Brokers broke entity, to let the system know to stop using the broker simulation.
But the logic in the strategy doesn't know that you are getting data from different feeds and talking to a different broker.
But even with all that in mind you have to develop your logic taking into account that you will be connecting to a live feed. Example:
cheat-on-closemode to buy the
closeprice of daily bars in the simulation
.but how do I test that strategy over an entire stock universe, or even just the top 200 stocks
This is unclear. Do you have a strategy which looks at the entire stock universe and cherry picks or do you want to try the same approach on the entire stock universe and then select the stocks that happen to be better suited for the strategy?
Entire stock universe altogether
cerebro.adddatauntil you exhaust the universe and then
cerebro.run. The strategy will of course be fairly complex in that you'll be looking at a huge number of assets and juggling them.
One at a time
adddataonce, add a strategy and then
In both cases the analysis is about plugging in
TimeReturn, logarithmic returns,
TradeAnalyzer and you can plug your own.
The general analyzer documentation and reference
Several samples and blog posts use analyzer:
You can see also the following samples in the sources:
which also use performance measuring analyzers.
There are some tens of samples plotting candlesticks and/or bars.
Check here for the option
style when plotting: Docs - Plotting
You can extend a data feed to have extra data Docs - Extending a Data Feed which can be the
P/E ratio like in that case or anything you like.
To Plot the events the best options would be:
Indicator that only delivers a point when an economic event happens. Assign the
high or the
low and plot and arrow/triangle or other marker
The same but with an
Observer. In this blog post, the triangles of the
BuySell observer are changed to arrows Blog - Arrows for the BuySell Observer
Your best option is to check the source for the
BuySell observer or the
Trades observer and plot the economic events instead of the operations/trades.
I was just taking a look to see about adding InfluxDB as a data feed source. I see a lot of code specific to CSV data sources in the backtrader/feeds.py. @backtrader any thought toward providing the basic structure to add JSON as a data feed format?
The thing is that CSV based formats share all a common structure and that's why a base class can provide a lot of functionality to (super)simplify what each CSV data feed has to do (to the point that the GenericCSVData could actually handle all the cases with the proper configuration)
Supporting a JSON based data feed doesn't pose any real problem. But for sure each JSON format will be different. In one the prices will be in a list with dict items, in another lists will be embedded in lists with prices being identified by position.
Any sample format?