示例#1
0
df = pd.read_csv('../../data/project_1/eod-quotemedia.csv',
                 parse_dates=['date'],
                 index_col=False)

close = df.reset_index().pivot(index='date',
                               columns='ticker',
                               values='adj_close')

print('Loaded Data')

# ### View Data
# Run the cell below to see what the data looks like for `close`.

# In[4]:

project_helper.print_dataframe(close)

# ### Stock Example
# Let's see what a single stock looks like from the closing prices. For this example and future display examples in this project, we'll use Apple's stock (AAPL). If we tried to graph all the stocks, it would be too much information.

# In[5]:

apple_ticker = 'AAPL'
project_helper.plot_stock(close[apple_ticker], '{} Stock'.format(apple_ticker))

# ## Resample Adjusted Prices
#
# The trading signal you'll develop in this project does not need to be based on daily prices, for instance, you can use month-end prices to perform trading once a month. To do this, you must first resample the daily adjusted closing prices into monthly buckets, and select the last observation of each month.
#
# Implement the `resample_prices` to resample `close_prices` at the sampling frequency of `freq`.
data = web.DataReader(tickers,
                      data_source='yahoo',
                      start=start_date,
                      end=end_date)['Adj Close']

print('Loaded Data')

#print(data['aapl'])
plt.plot(data['aapl'])

# ### View Data
# Run the cell below to see what the data looks like for `close`.

# In[5]:

project_helper.print_dataframe(data)

# ### Stock Example
# Let's see what a single stock looks like from the closing prices. For this example and future display examples in this project, we'll use Apple's stock (AAPL). If we tried to graph all the stocks, it would be too much information.

# In[6]:

apple_ticker = 'aapl'
project_helper.plot_stock(data[apple_ticker], '{} Stock'.format(apple_ticker))

# ## Resample Adjusted Prices
#
# The trading signal you'll develop in this project does not need to be based on daily prices, for instance, you can use month-end prices to perform trading once a month. To do this, you must first resample the daily adjusted closing prices into monthly buckets, and select the last observation of each month.
#
# Implement the `resample_prices` to resample `close_prices` at the sampling frequency of `freq`.