Last active
April 28, 2021 23:38
-
-
Save kuznetsov-m/b1ed47cf863d7536fdfcfec24bd4228c to your computer and use it in GitHub Desktop.
backtrader example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# file: requirements.txt | |
# | |
# backtrader==1.9.76.123 | |
# backtrader-plotting==1.1.0 | |
# file: dt.csv | |
# | |
# date,close,high,low,open | |
# 2017-01-03T15:00:00,115.450,115.815,115.400,115.600 | |
# 2017-01-03T16:00:00,115.370,115.670,115.135,115.450 | |
# 2017-01-03T17:00:00,115.470,115.525,115.270,115.365 | |
# 2017-01-03T18:00:00,115.235,115.495,115.235,115.475 | |
# 2017-01-03T19:00:00,115.435,115.445,115.160,115.235 | |
import pandas as pd | |
import backtrader as bt | |
import datetime | |
cerebro = bt.Cerebro() | |
cerebro.broker.setcash(100000) | |
stock_prices = pd.read_csv('dt.csv', index_col='date', parse_dates=True) | |
print(stock_prices) | |
feed = bt.feeds.PandasData(dataname=stock_prices) | |
cerebro.adddata(feed) | |
cerebro.run() | |
cerebro.plot(volume=False) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment