Backtrader Community

    • 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/

    Quickstart Guide Error

    General Code/Help
    1
    1
    77
    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.
    • R
      Ryan_t9 last edited by

      I keep on getting strange error messages after the 3rd quickstart guide, each one differing but the first one is listed below, any idea to fix?
      Starting Portfolio Value: 100000.00
      Traceback (most recent call last):
      File "c:\Users\ryanz\OneDrive\Desktop\Python Code\AlgoTrading\2nd Program.py", line 61, in <module>
      cerebro.run()
      File "C:\Users\ryanz\AppData\Local\Programs\Python\Python310\lib\site-packages\backtrader\cerebro.py", line 1127, in run
      runstrat = self.runstrategies(iterstrat)
      File "C:\Users\ryanz\AppData\Local\Programs\Python\Python310\lib\site-packages\backtrader\cerebro.py", line 1210, in runstrategies
      data._start()
      File "C:\Users\ryanz\AppData\Local\Programs\Python\Python310\lib\site-packages\backtrader\feed.py", line 203, in _start
      self.start()
      File "C:\Users\ryanz\AppData\Local\Programs\Python\Python310\lib\site-packages\backtrader\feeds\yahoo.py", line 94, in start
      super(YahooFinanceCSVData, self).start()
      File "C:\Users\ryanz\AppData\Local\Programs\Python\Python310\lib\site-packages\backtrader\feed.py", line 674, in start
      self.f = io.open(self.p.dataname, 'r')
      FileNotFoundError: [Errno 2] No such file or directory: 'c:\Users\ryanz\OneDrive\Desktop\Python Code\AlgoTrading\../../datas/orcl-1995-2014.txt'

      from future import (absolute_import, division, print_function,
      unicode_literals)

      import datetime # For datetime objects
      import os.path # To manage paths
      import sys # To find out the script name (in argv[0])

      Import the backtrader platform

      import backtrader as bt

      if name == 'main':
      # Create a cerebro entity
      cerebro = bt.Cerebro()

      # Datas are in a subfolder of the samples. Need to find where the script is
      # because it could have been called from anywhere
      modpath = os.path.dirname(os.path.abspath(sys.argv[0]))
      datapath = os.path.join(modpath, '../../datas/orcl-1995-2014.txt')
      
      # Create a Data Feed
      data = bt.feeds.YahooFinanceCSVData(
          dataname=datapath,
          # Do not pass values before this date
          fromdate=datetime.datetime(2000, 1, 1),
          # Do not pass values after this date
          todate=datetime.datetime(2000, 12, 31),
          reverse=False)
      
      # Add the Data Feed to Cerebro
      cerebro.adddata(data)
      
      # Set our desired cash start
      cerebro.broker.setcash(100000.0)
      
      # Print out the starting conditions
      print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue())
      
      # Run over everything
      cerebro.run()
      
      # Print out the final result
      print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue())
      
      1 Reply Last reply Reply Quote 0
      • 1 / 1
      • First post
        Last post
      Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors