Issues getting raw values from downloaded file.
rwestbrookjr last edited by
I have downloaded from Yahoo Finance the data available for Symbol M for Macy's. I have set up the data feed to use YahooFinanceCSVData:
# Create a Data Feed data = bt.feeds.YahooFinanceCSVData( dataname=datapath, # Do not pass values before this date fromdate=datetime.datetime(1992,2,1), # Do not pass values after this date todate=datetime.datetime(1992,2,20), reverse=False )
and have added it to cerbero:
Because the strategy I am trying to implement is based off of Heikin Ashi candles, I need to be able to access the raw values for HLOC to do my calculations both on current and previous candles. I am trying to do this by storing the current candle into a list by first grabbing the values in the init function:
def __init__(self): # Keep a reference to the "close" line in the data dataseries # self.datadate = self.datas.datetime.date(0) self.dataclose = self.datas.close self.dataopen = self.datas.open self.datahigh = self.datas.high self.datalow = self.datas.low print('''Open: %s High: %s Low: %s Close: %s''' % (self.dataopen, self.datahigh, self.datalow, self.dataclose))
then putting them into a list in the next function so that I can access them.
The problem I am having is I am not getting the actual values from the csv file.
The print method above is giving me this before I get to the next function:
Open: <backtrader.linebuffer.LineBuffer object at 0x0000000004B59D08> High: <backtrader.linebuffer.LineBuffer object at 0x0000000004B59B88> Low: <backtrader.linebuffer.LineBuffer object at 0x0000000004B59A08> Close: <backtrader.linebuffer.LineBuffer object at 0x0000000004B59808>
I would have hoped to see the raw values here and not the buffers, however in the next function, I do a print to see what some of these values are:
def next(self): # Simply log the closing price of the series from the reference self.log('Open: %.2f Close: %.2f' % (self.dataopen, self.dataclose))
and this is the result:
1992-02-05, Open: 5.44 Close: 5.14 1992-02-06, Open: 5.14 Close: 5.03 1992-02-07, Open: 5.03 Close: 4.66
If I look in the csv file, I see that these values do not match the actual data. The close price matches the ADJ CLOSE, but not the actual close, and I cannot for the life of me understand what the open is matching up to.
Date , Open , High , Low , Close , Adj Close, Volume 1992-02-05, 9.125000 , 9.125000 , 8.250000 , 8.625000 , 5.140320 , 11325800 1992-02-06, 8.625000 , 8.625000 , 8.375000 , 8.437500 , 5.028574 , 5696400 1992-02-07, 8.437500 , 8.437500 , 7.812500 , 7.812500 , 4.656087 , 1698000
Can someone please advise what it is I am doing wrong? I Initially thought it may be due to developing on Python 3.7, so I did downgrade to 2.7, but the issue still remains. I have read through the documentation, but unfortunately there must be something I am missing.
ab_trader last edited by
Can someone please advise what it is I am doing wrong?
Not reading the documentation.
This is from Docs - Refs - YahooFinanceCSVData
adjclose (default: True)
Whether to use the dividend/split adjusted close and adjust all values according to it.
rwestbrookjr last edited by
Thank you so much. This 100% resolved the issue. I had read the docs, however I did not go all the way down to the general reference section. Thank you for your time @ab_trader !!