This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Shifting the Time Series | |
ts.shift(2) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pandas import read_csv | |
from matplotlib import pyplot | |
from statsmodels.graphics.tsaplots import plot_acf | |
series = read_csv ('Series dj$Index’.csv', header=0, index_col=0) | |
plot_acf(series, lags=20) | |
pyplot.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pandas import read_csv | |
from matplotlib import pyplot | |
from statsmodels.graphics.tsaplots import plot_pacf | |
series = read_csv ('Series dj$Index’.csv', header=0, index_col=0) | |
plot_pacf(series, lags=20) | |
pyplot.show() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Populates the time period number in stock under head t | |
stock['t'] = range (1,len(stock)+1) | |
#Computes t squared, tXD(t) and n | |
stock['sqr t']=stock['t']**2 | |
stock['tXD']=stock['t']*stock['Adj Close'] | |
n=len(stock) | |
#Computes slope and intercept | |
slope = (n*stock['tXD'].sum() - stock['t'].sum()*stock['Adj Close'].sum())/(n*stock['sqr t'].sum() - (stock['t'].sum())**2) | |
intercept = (stock['Adj Close'].sum()*stock['sqr t'].sum() - stock['t'].sum()*stock['tXD'].sum())/(n*stock['sqr t'].sum() - (stock['t'].sum())**2) | |
print ('The slope of the linear trend (b) is: ', slope) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Computes the forecasted values | |
stock['forecast'] = intercept + slope*stock['t'] | |
#Computes the error | |
stock['error'] = stock['Adj Close'] - stock['forecast'] | |
mean_error=stock['error'].mean() | |
print ('The mean error is: ', mean_error) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import pandas_datareader as web | |
import matplotlib.pyplot as plt | |
import numpy as np |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stock = web.DataReader('MRF.BO','yahoo', start = "01-01-2012", end="06-01-2012") | |
stock = stock.dropna(how=’any’) | |
We can check the data using the head() function. | |
stock.head() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stock[‘Adj Close’].plot(grid = True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stock['ret'] = stock['Adj Close'].pct_change() | |
stock['ret'].plot(grid=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
stock['20d'] = stock['Adj Close'].rolling(window=20, center=False).mean() | |
stock['20d'].plot(grid=True) |
OlderNewer