Lab 1: Welcome to Time Series Analysis - List out all the values.
Time Series Analysis - List out all the values.
Solution 1:
# Task 1: Run the below to import the data for this hands-on,
# The data contains All stocks in the S-P 500 index, and their historical prices for the year 2011
import pandas as pd
dataFrame = pd.read_csv('dow_jones_index.data',parse_dates=["date"], index_col="date")
dataFrame.head()
# Task 2: Run the below cell to filter the closing price related to stock 'AA'
closeTS = dataFrame[(dataFrame.stock == 'AA')].close.str.replace('$',' ').astype(float)
#print(closeTS)
# Task: 3 Using the data filtered in the above step list all the closing price from Jan to March,
# assign the resulting series to variable 'close_AA'
### Start code here
close_AA = closeTS.loc['2011-01-01': '2011-03-31']
### End code(approx 1 line)
# Task 4: Run the below cells to save your answers
from test_ts_listvalues import values
values.save_ans1(close_AA)
Lab 2: Welcome to Time Series Analysis - Resampling month wise.
Time Series - Resampling month wise.
Solution 2:
# Task 1: Run the below to import the data for this hands-on,
# The data contains All stocks in the S-P 500 index, and their historical prices for the year 2011
import pandas as pd
dataFrame = pd.read_csv('dow_jones_index.data',parse_dates=["date"], index_col="date")
dataFrame.head()
# Task 2: Run the below cell to filter the closing price related to stock 'AA'
closeTS = dataFrame[(dataFrame.stock == 'AA')].close.str.replace('$',' ').astype(float)
#print(closeTS)
# Task 3: Downsample the data filtered in the above step month wise and fill the max value of closing price for each month
# assign the resulting series to variable 'downsample'
###Start code here
downsample = closeTS.resample('M').max()
#print(downsample)
###End code(approx 1 line)
# Task 4: Run the below cells to save your answers
from test_ts_resample_month import values
values.save_ans1(downsample)
Lab 3: Welcome to Time Series Analysis - Resampling day wise and Interpolate
Time series - Resampling day wise and Interpolate
Solution 3:
# Task 1: Run the below to import the data for this hands-on,
# The data contains All stocks in the S-P 500 index, and their historical prices for the year 2011
import pandas as pd
dataFrame = pd.read_csv('dow_jones_index.data',parse_dates=["date"], index_col="date")
dataFrame.head()
# Task 2: Run the below cell to filter the closing price related to stock 'AA'
closeTS = dataFrame[(dataFrame.stock == 'AA')].close.str.replace('$',' ').astype(float)
#print(closeTS)
# Task 3: upsample the data filtered in the above step day wise and perform interpolation to forward fill the first two 'Nan' values.
# return the first 10 samples of upsampled data to variable 'upsample'
###Start code here
upsample = closeTS.resample('D' , fill_method='ffill', limit=2).head(10)
#print(upsample)
###End code(approx 1 line)
# Task 4: Run the below cells to save your answers
from test_ts_resample_month import values
values.save_ans1(upsample)
Lab 4: Time series - WMT stock
Welcome to Time Series Analysis - WMT stock
Solution 4:
# Task 1
# Run the below to import the data for this hands-on
# The data contains all stocks in the S&P 500 index, and their historical prices for the year 2011
# Dataset : http://archive.ics.uci.edu/ml/machine-learning-databases/00312/dow_jones_index.zip
import pandas as pd
dataFrame = pd.read_csv('dow_jones_index.data',parse_dates=["date"], index_col="date")
dataFrame.head()
# Task 2:
# Run the below cell to filter the opening price related to stock 'WMT'.The sample is returned to variable 'open_WMT_Ts'
open_WMT_Ts = dataFrame[(dataFrame.stock == 'WMT')].open.str.replace('$',' ').astype(float)
open_WMT_Ts.head()
# Task 3:
# from statsmodels import adfuller method
###Start code here
from statsmodels.tsa.stattools import adfuller
###End code
# Task 4:
# perform stationarity check on WMT opening price using adfuller method and return the result to variable 'tsResult'
###Start code here
tsResult = adfuller(open_WMT_Ts)
###End code
# Task 5: Run the Cell.
print('ADF Statistic: %f' % tsResult[0])
print('p-value: %f' % tsResult[1])
for key, value in tsResult[4].items():
print('\t%s: %.3f' % (key, value))
# Task 6:
# Find the value of ADF Statistic from the above test result and assign it to variable ADF_stat
ADF_stat = float(tsResult[0])
type(ADF_stat)
# Task 7:
# Run the below cells to save your answers
from test_ts_wmt import values
values.save_ans1(ADF_stat)
Lab 5: Welcome to Time Series Analysis - XOM stock
Time series - XOM stock
Solution 5: Time series - XOM stock
# Task 1
# Run the below to import the data for this hands-on
# The data contains all stocks in the S&P 500 index, and their historical prices for the year 2011
# Dataset : http://archive.ics.uci.edu/ml/machine-learning-databases/00312/dow_jones_index.zip
import pandas as pd
dataFrame = pd.read_csv('dow_jones_index.data',parse_dates=["date"], index_col="date")
dataFrame.head()
# Task 2:
# Run the below cell to filter the closing price related to stock 'XOM'. The sample is returned to variable 'close_XOM_Ts'
close_XOM_Ts = dataFrame[(dataFrame.stock == 'XOM')].close.str.replace('$',' ').astype(float)
close_XOM_Ts.head()
# Task 3:
# from statsmodels import adfuller method
###Start code here
from statsmodels.tsa.stattools import adfuller
###End code
# Task 4:
# perform stationarity check on XOM closing price using adfuller method and return the result to variable 'tsResult'
###Start code here
tsResult = adfuller(close_XOM_Ts)
###End code
# Task 5: Run the Cell.
print('ADF Statistic: %f' % tsResult[0])
print('p-value: %f' % tsResult[1])
for key, value in tsResult[4].items():
print('\t%s: %.3f' % (key, value))
# Task 6:
# Find the value of ADF Statistic from the above test result and assign it to variable ADF_stat
ADF_stat = float(tsResult[0])
type(ADF_stat)
# Task 7:
# Run the below cells to save your answers
from test_ts_wmt import values
values.save_ans1(ADF_stat)