Skip to content

Instantly share code, notes, and snippets.

@iSevenDays
Created February 14, 2021 12:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iSevenDays/378a75e392a92a602cc80ffe8df6ddd7 to your computer and use it in GitHub Desktop.
Save iSevenDays/378a75e392a92a602cc80ffe8df6ddd7 to your computer and use it in GitHub Desktop.
get_feed_for_csv_path.py
import backtrader as bt
from backtrader.feeds import GenericCSVData
class GenericCSV_Signal(GenericCSVData):
# Add a 'pe' line to the inherited ones from the base class
lines = ('autoencoder_signal',)
# auto encoder signal in GenericCSVData has index 8 ...
# add the parameter to the parameters inherited from the base class
params = (('autoencoder_signal', 8),)
def get_feed_for_csv_path(path, fromdate, todate, has_signal=False):
config = dict(dataname=path,
fromdate=fromdate,
todate=todate,
nullvalue=0.0,
dtformat='%Y-%m-%d',
datetime=0,
high=2,
low=3,
open=1,
close=4,
volume=5,
openinterest=-1)
return bt.feeds.GenericCSVData(**config) if not has_signal else GenericCSV_Signal(**config)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment