GenericCSVData not feeding data?
-
Hello, I am just working on the Quickstart tutorial, except I am trying to use the GenericCSVData to parse per minute data:
Here is a sample of the csv file:
3/12/2018 16:00:00,97.025,97.07,96.76,96.77,2661032,1
3/12/2018 15:59:00,96.9871,97.03,96.98,97.03,141136,2
3/12/2018 15:58:00,96.95,96.99,96.93,96.99,132356,3
3/12/2018 15:57:00,96.93,96.95,96.9,96.94,111733,4
3/12/2018 15:56:00,96.91,96.98,96.9,96.93,132513,5
3/12/2018 15:55:00,96.99,96.99,96.89,96.91,128721,6
3/12/2018 15:54:00,96.9844,97.01,96.965,96.99,93297,7
3/12/2018 15:53:00,97.01,97.025,96.975,96.9881,62685,8
3/12/2018 15:52:00,97.01,97.04,96.98,97.005,106785,9
3/12/2018 15:51:00,97.08,97.11,97.01,97.02,168636,10
3/12/2018 15:50:00,97.18,97.21,96.95,97.08,145091,11My code to read the data is as follows:
data = bt.feeds.GenericCSVData(
dataname = 'intraday_1min_MSFT_1.csv',
openinterest = -1,
fromdate=datetime.datetime(2018, 2, 27),
todate=datetime.datetime(2018, 3, 12),
dtformat=('%m/%d/%Y %H:%M:%S'),
headers = False,
timeframe = bt.TimeFrame.Minutes,
)It simply outputs:
Starting Portfolio Value: 1000000.00
Final Portfolio Value: 1000000.00It doesn't show any portfolio actions(buying/selling)
This is my strategy code(which I just copied from quickstart)
class TestStrategy(bt.Strategy):
def log(self, txt, dt=None): ''' Logging function fot this strategy''' dt = dt or self.datas[0].datetime.date(0) print('%s, %s' % (dt.isoformat(), txt)) def __init__(self): # Keep a reference to the "close" line in the data[0] dataseries self.dataclose = self.datas[0].close def next(self): # Simply log the closing price of the series from the reference self.log('Close, %.2f' % self.dataclose[0]) if self.dataclose[0] < self.dataclose[-1]: # current close less than previous close if self.dataclose[-1] < self.dataclose[-2]: # previous close less than the previous close # BUY, BUY, BUY!!! (with all possible default parameters) self.log('BUY CREATE, %.2f' % self.dataclose[0]) self.buy()
I noticed something interesting, when I commented out the fromdate and todate lines in the GenericCSVData, it does output trades, but does so in backwards date order.
-
@brian-lin said in GenericCSVData not feeding data?:
3/12/2018 16:00:00,97.025,97.07,96.76,96.77,2661032,1
3/12/2018 15:59:00,96.9871,97.03,96.98,97.03,141136,2
3/12/2018 15:58:00,96.95,96.99,96.93,96.99,132356,3@brian-lin said in GenericCSVData not feeding data?:
I noticed something interesting, when I commented out the fromdate and todate lines in the GenericCSVData, it does output trades, but does so in backwards date order.
Isn't the data in backwards order?
-
Should the data be fed in from oldest to newest? I wasn't sure about that.
I did try and feed it in in reversed order, and it printed in proper order, however I still got a strange result.
My strategy code is the same as you can see. It only creates buy orders, and not sells. However at the end of my code execution I end up with more money in my account than I started with
Eg:
I started with 1,000,000
.
.
.
2018-03-12, Close, 97.00
2018-03-12, BUY CREATE, 97.00
2018-03-12, Close, 96.99
2018-03-12, BUY CREATE, 96.99
2018-03-12, Close, 96.99
2018-03-12, Close, 96.91
2018-03-12, Close, 96.93
2018-03-12, Close, 96.94
2018-03-12, Close, 96.99
2018-03-12, Close, 97.03
2018-03-12, Close, 96.77
Final Portfolio Value: 1002221.66
Final Portfolio Value: 1002221.66 -
@brian-lin said in GenericCSVData not feeding data?:
Should the data be fed in from oldest to newest? I wasn't sure about that.
If you want to trade forward, it seems pretty obvious you should be feeding the data forwards. If data were coming from a socket, with a bar each 10 seconds, how should the platform know which data goes first and which second?
@brian-lin said in GenericCSVData not feeding data?:
My strategy code is the same as you can see. It only creates buy orders, and not sells. However at the end of my code execution I end up with more money in my account than I started with
You have a greater value. It isn't cash.
Let me suggest that you get used with the basics of trading and basics like portfolio value, before you go any further.
-
You have a greater value. It isn't cash.
I missed that totally. Thanks for the help.