For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
Trouble with the Quickstart code
-
Here is the code I copy and paste from the Quickstart page.
The problem seems to be at this line
datapath = os.path.join(modpath, '../../datas/orcl-1995-2014.txt')
where the code have problem locating the orcl-1995-2014.txt file... Where shall I place the file so that the code can find it?? Thx in advance
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())
Below is the IPython console output...
runfile('C:/Users/Administrator/Desktop/Trading Project/TestRun.py', wdir='C:/Users/Administrator/Desktop/Trading Project') Starting Portfolio Value: 100000.00 Traceback (most recent call last): File "<ipython-input-15-e54c45e4ce34>", line 1, in <module> runfile('C:/Users/Administrator/Desktop/Trading Project/TestRun.py', wdir='C:/Users/Administrator/Desktop/Trading Project') File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile execfile(filename, namespace) File "C:\ProgramData\Anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile exec(compile(f.read(), filename, 'exec'), namespace) File "C:/Users/Administrator/Desktop/Trading Project/TestRun.py", line 39, in <module> cerebro.run() File "C:\ProgramData\Anaconda3\lib\site-packages\backtrader\cerebro.py", line 1127, in run runstrat = self.runstrategies(iterstrat) File "C:\ProgramData\Anaconda3\lib\site-packages\backtrader\cerebro.py", line 1210, in runstrategies data._start() File "C:\ProgramData\Anaconda3\lib\site-packages\backtrader\feed.py", line 203, in _start self.start() File "C:\ProgramData\Anaconda3\lib\site-packages\backtrader\feeds\yahoo.py", line 90, in start super(YahooFinanceCSVData, self).start() File "C:\ProgramData\Anaconda3\lib\site-packages\backtrader\feed.py", line 671, in start self.f = io.open(self.p.dataname, 'r') FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Administrator\\Desktop\\Trading Project\\../../datas/orcl-1995-2014.txt'
-
@benjamin-chow said in Trouble with the Quickstart code:
Where shall I place the file so that the code can find it??
@benjamin-chow said in Trouble with the Quickstart code:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Administrator\\Desktop\\Trading Project\\../../datas/orcl-1995-2014.txt'