For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
'numpy.int64' object has no attribute 'to_pydatetime' in backtrader feed
-
I am unable to fix the error - 'numpy.int64' object has no attribute 'to_pydatetime', I will be really grateful, if anyone could please help me out in this? I have already tried uninstalling pyfolio and itstalling it from git. Please see the complete code below
import os
import glob
import requests
import pandas as pd
from nsepy import *
from datetime import datetime
import backtrader as bt
import backtrader.feeds as btfeedsfrom __future__ import (absolute_import, division, print_function, unicode_literals) class TestStrategy(bt.Strategy): def log(self, txt, dt=None): ''' Logging function for 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 __name__ == '__main__': cerebro = bt.Cerebro() cerebro.addstrategy(TestStrategy) #Data feed block data_path = "/Users/kumarun/Documents/data/files" joined_files = os.path.join(data_path, "Oct-MONTHLY-Expirydata_2020.csv") joined_list = glob.glob(joined_files) df = pd.concat(map(pd.read_csv, joined_list), ignore_index=True) df.columns=['Ticker','date', 'open', 'high', 'low', 'close', 'volume','Open Interest'] filtered = df[(df['Ticker'] == 'BANKNIFTY')] #Cerebro block filtered.date = pd.to_datetime(filtered.date, format='%d-%m-%Y %H:%M:%S') feed = bt.feeds.PandasData(dataname=filtered) cerebro.adddata(feed) cerebro.broker.setcash(100000.0) print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue()) cerebro.run() print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue())'''
The data format is as below
![alt text](
image url
Thanks for the help