Backtrader Community

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. Garen62
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
    • Profile
    • Following 0
    • Followers 0
    • Topics 3
    • Posts 6
    • Best 1
    • Controversial 0
    • Groups 0

    Garen62

    @Garen62

    1
    Reputation
    79
    Profile views
    6
    Posts
    0
    Followers
    0
    Following
    Joined Last Online
    Location Paris Age 29

    Garen62 Unfollow Follow

    Best posts made by Garen62

    • RE: Cannot create a DataFeed for my CSV File

      Thank you ! The problem was half solved with your solution, it gave me 23:59:00 at each line instead of the real time, the solution was to add a :
      timeframe=bt.TimeFrame.Minutes in the GenericCSVData parameters

      Thanks again !

      posted in General Code/Help
      Garen62
      Garen62

    Latest posts made by Garen62

    • How does Backtrader manage order execution ?

      Hi, when an order is initiated in the backtest, does backtrader use the next data lines OHLCV to know if the order could have passed ? How does it know ?

      posted in General Code/Help
      Garen62
      Garen62
    • RE: Cannot create a DataFeed for my CSV File

      Thank you ! The problem was half solved with your solution, it gave me 23:59:00 at each line instead of the real time, the solution was to add a :
      timeframe=bt.TimeFrame.Minutes in the GenericCSVData parameters

      Thanks again !

      posted in General Code/Help
      Garen62
      Garen62
    • RE: Cannot create a DataFeed for my CSV File

      Update : The problem with the comma was an Excel thing, when I copy pasted it on an Text Editor there were commas at each line.

      After that, I got an IndexError: array assignment index out of range, which was solved by adding more data, thanks to this thread : https://community.backtrader.com/topic/407/indexerror-array-assignment-index-out-of-range/3

      My last problem is that I don't know how to show Hours-Minutes-Seconds when I launch the script, my log function is :

      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))
      

      Backtrader shows me :
      2019-06-30, Close, 295.65
      2019-06-30, Close, 295.65
      2019-06-30, Close, 295.85
      But how can I have H-M-S too in the log function ?

      posted in General Code/Help
      Garen62
      Garen62
    • RE: Cannot create a DataFeed for my CSV File

      @backtrader Yes that is the problem, I don't understand why the quote is here. I just followed the documentation of GenericCSVData, do you have an idea about why ?

      posted in General Code/Help
      Garen62
      Garen62
    • Cannot create a DataFeed for my CSV File

      Hi, I have a problem creating my own DataFeed

      I used GenericCSVData to use my CSV file on Backtrader, but I get this error :

      ValueError: time data '"2019-06-30T15-10-00' does not match format '%Y-%m-%dT%H-%M-%S'

      Which doesn't make sense because it seems to be right.
      I succeeded to make it working with a CSV years-months-day only, but not with hours-minutes-seconds, I don't understand why ? I think the problem might be this " which is near the 2019 in the error message, but I don't know how to erase it.

      Here is the code :

      modpath = os.path.dirname(os.path.abspath(sys.argv[0]))
      datapath = os.path.join(modpath, 'backtrader/datas/yhoo.csv')
      # Create a Data Feed
      data = btfeed.GenericCSVData(
      dataname=datapath,
      
      nullvalue=0.0,
      
      dtformat=('%Y-%m-%d'),
      tmformat=('%H-%M-%S'),
      
      datetime=0,
      time=1,
      open=2,
      high=3,
      low=4,
      close=5,
      volume=6,
      openinterest=-1
      

      )

      Here is my CSV : alt text https://ibb.co/sF47WV4

      And here is the full error I get :

      Starting Portfolio Value: 10000.00
      Traceback (most recent call last):
      File "G22.py", line 151, in <module>
      cerebro.run()
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/backtrader-1.9.70.122-py3.7.egg/backtrader/cerebro.py", line 1127, in run
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/backtrader-1.9.70.122-py3.7.egg/backtrader/cerebro.py", line 1212, in runstrategies
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/backtrader-1.9.70.122-py3.7.egg/backtrader/feed.py", line 688, in preload
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/backtrader-1.9.70.122-py3.7.egg/backtrader/feed.py", line 479, in load
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/backtrader-1.9.70.122-py3.7.egg/backtrader/feed.py", line 710, in _load
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/backtrader-1.9.70.122-py3.7.egg/backtrader/feeds/csvgeneric.py", line 114, in _loadline
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/_strptime.py", line 577, in _strptime_datetime
      tt, fraction, gmtoff_fraction = _strptime(data_string, format)
      File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/_strptime.py", line 359, in _strptime
      (data_string, format))
      ValueError: time data '"2019-06-30T15-10-00' does not match format '%Y-%m-%dT%H-%M-%S'

      posted in General Code/Help
      Garen62
      Garen62
    • Erase it please

      I failed this thread, I cannot erase it myself sorry

      posted in General Code/Help
      Garen62
      Garen62