MultiData Strategy Does not Work

Does not seem to work. I am not sure why every documentation and blog post I see is still using Yahoo and not Google when Yahoo no longer is active? Confused on that. Anyhow, when I run your code on python 3, I get this error:

Although the major problem with the latest known method with Yahoo is that data will be altered at random places. The double quotes (or empty field if two single quotes) might actually be anywhere in the file, which would mean you have to clean the file.

After the Yahoo demise the best option is to look for alternative data sources. The pandas team was looking for a solution which would involve multiple downloads of the Yahoo data to make sure that the surprises introduced by Yahoo could be corrected. This obviously would increase loading time. You may try to find if they succeeded.

Quandl's wiki data is also supported (and any other non-wiki, which has also the same CSV format from Quandl)

Again, the data I am trying to extra is from the file in the format of:

My full code for the strategy is shown below. its very odd why I am getting this error. Any idea by any chance what it could be?

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
import backtrader.feeds as btfeeds
# Create a Stratey
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): # upon __init__ being called the strategy already has a list of datas that are present in the platform. This is a standard Python list and datas can be accessed in the order they were inserted.
# Keep a reference to the "close" line in the data[0] dataseries
self.dataclose = self.datas[0].close # self.dataclose = self.datas[0].close keeps a reference to the close line. (close price)
# the first data in the list self.datas[0] is the default data for trading operations and to keep all strategy elements synchronized (its the system clock)
def next(self): # 'next' method will be called on each bar of the system clock (self.datas[0]). This is true until other things come into play like indicators, which need some bars to start producing an output.
# Simply log the closing price of the series from the reference
self.log('Close, %.2f' % self.dataclose[0])
# if the price has been falling 3 sessions in a row..... buy buy buy!
if self.dataclose[0] < self.dataclose[-1]:
# current close less than previous close
if self.dataclose[-1] < self.dataclose[-2]:
# previous close less than the previous close
# BUY, BUY, BUY!!! (with all possible default parameters)
self.log('BUY CREATE, %.2f' % self.dataclose[0])
self.buy()
if __name__ == '__main__':
# Create a cerebro entity
cerebro = bt.Cerebro()
# Add a strategy
cerebro.addstrategy(TestStrategy)
data = btfeeds.GenericCSVData(
dataname='C:\\Users\\Sam\\PycharmProjects\\Test\\.ipynb_checkpoints\\orcl-1995-2014.txt',
fromdate=datetime.datetime(2000-1-3), # these are dates available in the .txt file
todate=datetime.datetime(2000-12-29), # these are dates available in the .txt file
nullvalue=0.0, # missing values to be replaced with 0
dtformat=('%Y-%m-%d'),
datetime=0,
open=1,
high=2,
low=3,
close=4,
adj_close=5,
volume=6,
)
# 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())

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
import backtrader.feeds as btfeeds
# Create a Stratey
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): # upon __init__ being called the strategy already has a list of datas that are present in the platform. This is a standard Python list and datas can be accessed in the order they were inserted.
# Keep a reference to the "close" line in the data[0] dataseries
self.dataclose = self.datas[0].close # self.dataclose = self.datas[0].close keeps a reference to the close line. (close price)
# the first data in the list self.datas[0] is the default data for trading operations and to keep all strategy elements synchronized (its the system clock)
def next(self): # 'next' method will be called on each bar of the system clock (self.datas[0]). This is true until other things come into play like indicators, which need some bars to start producing an output.
# Simply log the closing price of the series from the reference
self.log('Close, %.2f' % self.dataclose[0])
# if the price has been falling 3 sessions in a row..... buy buy buy!
if self.dataclose[0] < self.dataclose[-1]:
# current close less than previous close
if self.dataclose[-1] < self.dataclose[-2]:
# previous close less than the previous close
# BUY, BUY, BUY!!! (with all possible default parameters)
self.log('BUY CREATE, %.2f' % self.dataclose[0])
self.buy()
if __name__ == '__main__':
# Create a cerebro entity
cerebro = bt.Cerebro()
# Add a strategy
cerebro.addstrategy(TestStrategy)
data = btfeeds.GenericCSVData(
dataname='C:\\Users\\Sam\\PycharmProjects\\Test\\.ipynb_checkpoints\\orcl-1995-2014.txt',
fromdate=datetime.datetime.strptime("2000-1-1", "%Y-%m-%d"),
todate = datetime.datetime.strptime("2000-12-31", "%Y-%m-%d"),
nullvalue=0.0, # missing values to be replaced with 0
dtformat=('%Y-%m-%d'),
datetime=0,
open=1,
high=2,
low=3,
close=4,
adj_close=5,
volume=6,
)
# 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())

The clear suggestion is to polish up your Python. At the moment you are not able to instantiate a datetime.datetime instance, even if the examples are full of such instantiations. And you are unable to read the error messages, which already show where and why things are failing.

Sooner or later (as any would) you will get a running script. But the likelihood of logic failures and the introduction of blatant bugs is very high.