I'm trying to build an Algotrader but keep getting the above error (please see subject header). I've tried various workarounds, having researched the issue on Stack Overflow, but I've not been able to resolve the issue. Any help would be much appreciated. I've pasted my code below:
import pandas as pd
import matplotlib.pyplot as plt
import quandl
# The quandl module allows us to obtain the stock data we require without downloading the corresponding CSV files.
aapl = quandl.get('WIKI/AAPL', start_date='2012-10-01', end_date='2014-01-01')
# We can now use .head, .tail methods to seize first and last five elements of the data. Using such methods will allow
# you to see that the data is stepped on a monthly basis atm.
data_frame = pd.read_csv('WIKI-FB.csv')
# Once you've created the data-frame object, you can extrapolate data from various segmented timelines using slicing.
# data_frame.index will give you the start, range and step of the relevant data set.
# At the moment, the index for the dataframe is measured in integers whereas we need to convert it into date-based
# values, thus allowing chronological plotting of the data. parse_dates below enables the conversion. Notice we then sort.
df_with_date_index = pd.read_csv('WIKI-FB.csv', index_col= 'Date', parse_dates= True)
df_with_date_index = df_with_date_index.sort_index()
df_with_date_index_1 = data_frame.set_index('Date').sort_index()
df_with_date_index_1.index = pd.to_datetime(df_with_date_index_1.index)
# Once we've created an indexable set of x-y values from the segment of data, we can use the plot method to display
# in our GUI, as in the commented-out code just below.
df_with_date_index_1['Adj. Close'].plot()
#plt.show()
# We now want to create code to operate with multiple stocks. First we specify a range of dates using pandas datetime
# index and assign them to a new empty dataframe. We can then apply this dataframe to any number of given stocks.
date_range = pd.date_range('2014-01-03', '2014-04-01')
date_range
df_multi_stock = pd.DataFrame(index=date_range)
df_fb = pd.read_csv('WIKI-FB.csv', index_col='Date', parse_dates=True, usecols= ['Date', 'Adj. Close'])
# Now we combine our two sets of data. We use the how parameter below to tell our program to ignore non-numeric values.
# Inner join is the most common type of join you’ll be working with. It returns a dataframe with only those rows that have
# common characteristics.
df_multi_stock = df_multi_stock.join(df_fb)
#df_multi_stock.head()
df_multi_stock = pd.DataFrame(index=date_range)
# The addition of the how='inner' method results in the exclusion of non-trading days, which would otherwise produce
# sequences of null values.
df_multi_stock = df_multi_stock.join(df_fb, how='inner')
df_multi_stock = df_multi_stock.rename(columns={'Adj.Close':'FB'})
# plt.show()
# Now we repeat the above steps for our AAPL stocks.
df_aapl = pd.read_csv('WIKI-AAPL.csv', index_col='Date', parse_dates=True, usecols= ['Date', 'Adj. Close'])
df_multi_stock = df_multi_stock.rename(columns={'Adj.Close':'AAPL'})
df_multi_stock = df_multi_stock.join(df_aapl, how='inner')
df_multi_stock[['FB', 'AAPL']].plot()
plt.show()