Relative Data Input
-
Hi there,
I wonder is there a way to easily convert close price to relative price based on the first bar of input. Or do I need to do it manually every time?
And will database such as sqlite be supported for storing data in the future?
Thank you!
-
@Dixing-Xu said in Relative Data Input:
I wonder is there a way to easily convert close price to relative price based on the first bar of input. Or do I need to do it manually every time?
You need a
Filter
which stores the 1st price seen during action and adjusts each price with regards to it. For reference see: Docs - FiltersBut such a filter actually has been implemented (it is used for some of the proprietary tools for the Backtrader Fund (see Esfera Capital - Funds
It's a very simple filter
class PercFilter(bt.metabase.ParamsBase): params = ( ('base', 100.0), ) def __init__(self, data): self._refclose = None def __call__(self, data, *args, **kwargs): if self._refclose is None: self._refclose = data.close[0] pc = 100.0 * (data.close[0] / self._refclose - 1.0) data.close[0] = self.p.base + pc return False # no change to stream structure/length
@Dixing-Xu said in Relative Data Input:
And will database such as sqlite be supported for storing data in the future?
backtrader has no provisions for data collection/storage. Nothing prevents collecting data from the on-line sources, but how to actually store it is entirely up to the user. The sources contain a tool called
rewrite-data
which simply takes one of the inputs and outputs acsv
in the expected default format for backtrader. The same data could be written to ansqlite
database with a simple schema.