Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    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

    General Code/Help
    1
    1
    91
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • mmed pod
      mmed pod last edited by

      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 btfeeds

      from __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](1deaab05-badc-41b9-9383-b35432aeea99-image.png image url

      Thanks for the help

      1 Reply Last reply Reply Quote 0
      • 1 / 1
      • First post
        Last post
      Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors