You are on page 1of 15

Question No 1:

Solution:

(a) To prepare the stock prices of Company B as a univarlate time series for smoothing
and forecasting we will use Excel.

The steps are as follows:

Step 1:

Open the "StockPriceB_Raw.csv file In Excel and select the column of Interest. In this case, we
will choose the "Closing Price" column.

Step 2:

Sort the data in ascending order by date using the "Sort" function under the "Data" tab.

Step 3:

Check for missing values and remove or interpolate them. In this case, there are no missing
values.

Step 4:

Create a time series plot of the data using the "Line" chart type under the "Charts" tab. This will
give us an idea of the overall trend and seasonality of the data.
Step 5:

If necessary, apply a transformation to stabilize the variance of the data. In this case, there is no
need for transformation.

StockPriceB_ANALYSIS
OPEN HIGH LOW CLOSE_Price VOLUME ADJ_OPEN
ADJ_HIGH ADJ_LOW ADJ_CLOSE ADJ_VOLUME EX_DIVIDEND SPLIT_RATIO
200000
150000
100000
50000
0
17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17 17
/20 /20 /20 /20 /20 /20 /20 /20 /20 /20 /20 /20 /20 /20 /20 /20 /20 /20 /20 /20 /20 /20 /20 /20 /20 /20 /20 /20 /20 /20 /20 /20
3 7 8 7 5 8 1 4 1 7 8 9 4 5 1 9 7 1 4 4 1 4 2 1 1 2 7 8 1 1 9 7
1/ 1/1 2/ 2/1 1/2 3/ 3/ 3/2 3/3 4/1 4/2 5/ 5/2 7/ 6/ 6/ 6/ 8/1 7/1 8/1 8/3 8/ 9/1 9/2 0/1 0/1 0/2 0/1 1/2 2/1 1/2 2/2
1 1 1 1 1 1 1 1

Line chart
L IN E C H A R T OF ST OC K _P R IC E
1/ 3/2017 EOD daily 1/4/2017 EOD daily 1/ 5/2017 EOD daily 1/9/2017 EOD daily
1/ 6/2017 EOD daily 1/10/2017 EOD daily 1/ 12/2017 EOD daily 1/11/2017 EOD daily
1/ 17/2017 EOD daily 1/13/2017 EOD daily 1/ 18/2017 EOD daily 1/19/2017 EOD daily
1/ 20/2017 EOD daily 1/23/2017 EOD daily 2/ 6/2017 EOD daily 2/7/2017 EOD daily
2/ 8/2017 EOD daily 1/24/2017 EOD daily 2/ 9/2017 EOD daily 1/31/2017 EOD daily
2/ 2/2017 EOD daily 1/30/2017 EOD daily 2/ 10/2017 EOD daily 2/1/2017 EOD daily
2/ 17/2017 EOD daily 2/13/2017 EOD daily 1/ 27/2017 EOD daily 1/26/2017 EOD daily
2/ 3/2017 EOD daily 2/14/2017 EOD daily 2/ 16/2017 EOD daily 2/15/2017 EOD daily
1/ 25/2017 EOD daily 2/21/2017 EOD daily 2/ 24/2017 EOD daily 2/27/2017 EOD daily
3/ 6/2017 EOD daily 2/22/2017 EOD daily 3/ 2/2017 EOD daily 2/28/2017 EOD daily
3/ 8/2017 EOD daily 3/7/2017 EOD daily 2/ 23/2017 EOD daily 3/10/2017 EOD daily
3/ 9/2017 EOD daily 3/14/2017 EOD daily 3/ 13/2017 EOD daily 3/3/2017 EOD daily
3/ 1/2017 EOD daily 3/15/2017 EOD daily 3/ 16/2017 EOD daily 3/17/2017 EOD daily
3/ 22/2017 EOD daily 3/20/2017 EOD daily 3/ 21/2017 EOD daily 3/23/2017 EOD daily
3/ 24/2017 EOD daily 3/27/2017 EOD daily 3/ 30/2017 EOD daily 3/28/2017 EOD daily
3/ 29/2017 EOD daily 4/5/2017 EOD daily 4/ 4/2017 EOD daily 4/3/2017 EOD daily
3/ 31/2017 EOD daily 4/6/2017 EOD daily 4/ 21/2017 EOD daily 4/19/2017 EOD daily
4/ 7/2017 EOD daily 4/20/2017 EOD daily 4/ 18/2017 EOD daily 4/10/2017 EOD daily
4/ 17/2017 EOD daily 4/11/2017 EOD daily 4/ 13/2017 EOD daily 4/12/2017 EOD daily
4/ 24/2017 EOD daily 4/26/2017 EOD daily 4/ 25/2017 EOD daily 4/27/2017 EOD daily
4/ 28/2017 EOD daily 5/1/2017 EOD daily 5/ 2/2017 EOD daily 5/3/2017 EOD daily
5/ 4/2017 EOD daily 5/11/2017 EOD daily 5/ 12/2017 EOD daily 5/10/2017 EOD daily
5/ 9/2017 EOD daily 5/8/2017 EOD daily 5/ 18/2017 EOD daily 5/5/2017 EOD daily
5/ 15/2017 EOD daily 5/17/2017 EOD daily 5/ 19/2017 EOD daily 5/16/2017 EOD daily
5/ 24/2017 EOD daily 5/23/2017 EOD daily 5/ 22/2017 EOD daily 5/26/2017 EOD daily
5/ 25/2017 EOD daily 6/30/2017 EOD daily 6/ 29/2017 EOD daily 6/15/2017 EOD daily
7/ 5/2017 EOD daily 7/6/2017 EOD daily 7/ 3/2017 EOD daily 6/16/2017 EOD daily
5/ 30/2017 EOD daily 6/12/2017 EOD daily 5/ 31/2017 EOD daily 6/26/2017 EOD daily
6/ 1/2017 EOD daily 6/13/2017 EOD daily 7/ 7/2017 EOD daily 6/23/2017 EOD daily
7/ 10/2017 EOD daily 6/21/2017 EOD daily 6/ 14/2017 EOD daily 6/22/2017 EOD daily
6/ 9/2017 EOD daily 6/28/2017 EOD daily 6/ 27/2017 EOD daily 6/19/2017 EOD daily
6/ 20/2017 EOD daily 8/10/2017 EOD daily 7/ 11/2017 EOD daily 6/8/2017 EOD daily
6/ 7/2017 EOD daily 6/6/2017 EOD daily 6/ 2/2017 EOD daily 7/12/2017 EOD daily
6/ 5/2017 EOD daily 7/24/2017 EOD daily 7/ 25/2017 EOD daily 7/21/2017 EOD daily
8/ 11/2017 EOD daily 7/13/2017 EOD daily 7/ 27/2017 EOD daily 7/26/2017 EOD daily
8/ 17/2017 EOD daily 7/17/2017 EOD daily 7/ 31/2017 EOD daily 7/28/2017 EOD daily
7/ 14/2017 EOD daily 7/18/2017 EOD daily 7/ 20/2017 EOD daily 7/19/2017 EOD daily
8/ 21/2017 EOD daily 8/18/2017 EOD daily 8/ 16/2017 EOD daily 8/15/2017 EOD daily
8/ 14/2017 EOD daily 8/29/2017 EOD daily 8/ 9/2017 EOD daily 8/30/2017 EOD daily
8/ 1/2017 EOD daily 8/23/2017 EOD daily 8/ 24/2017 EOD daily 8/22/2017 EOD daily
8/ 31/2017 EOD daily 8/25/2017 EOD daily 8/ 3/2017 EOD daily 8/2/2017 EOD daily
9/ 5/2017 EOD daily 8/7/2017 EOD daily 8/ 8/2017 EOD daily 8/28/2017 EOD daily
8/ 4/2017 EOD daily 9/1/2017 EOD daily 9/ 6/2017 EOD daily 9/7/2017 EOD daily
9/ 8/2017 EOD daily 9/14/2017 EOD daily 9/ 13/2017 EOD daily 9/15/2017 EOD daily
9/ 12/2017 EOD daily 9/11/2017 EOD daily 9/ 18/2017 EOD daily 9/27/2017 EOD daily
9/ 28/2017 EOD daily 9/19/2017 EOD daily 9/ 26/2017 EOD daily 9/20/2017 EOD daily
9/ 21/2017 EOD daily 9/25/2017 EOD daily 9/ 22/2017 EOD daily 10/ 6/2017 EOD daily
10/2/2017 EOD daily 10/10/2017 EOD daily 10/9/2017 EOD daily 9/29/2017 EOD daily
10/11/2017 EOD daily 10/25/2017 EOD daily 10/26/2017 EOD daily 10/ 3/2017 EOD daily
10/23/2017 EOD daily 10/5/2017 EOD daily 10/4/2017 EOD daily 11/ 13/ 2017 EOD daily
10/12/2017 EOD daily 11/14/2017 EOD daily 10/24/2017 EOD daily 10/ 20/ 2017 EOD daily
11/10/2017 EOD daily 10/19/2017 EOD daily 10/16/2017 EOD daily 11/ 9/2017 EOD daily
10/27/2017 EOD daily 10/17/2017 EOD daily 10/13/2017 EOD daily 10/ 30/ 2017 EOD daily
11/15/2017 EOD daily 10/31/2017 EOD daily 11/7/2017 EOD daily 11/ 8/2017 EOD daily
10/18/2017 EOD daily 11/16/2017 EOD daily 11/2/2017 EOD daily 11/ 17/ 2017 EOD daily
11/6/2017 EOD daily 11/3/2017 EOD daily 11/20/2017 EOD daily 11/ 1/2017 EOD daily
11/21/2017 EOD daily 11/22/2017 EOD daily 12/28/2017 EOD daily 12/ 6/2017 EOD daily
12/7/2017 EOD daily 12/29/2017 EOD daily 12/8/2017 EOD daily 11/ 24/ 2017 EOD daily
12/11/2017 EOD daily 12/14/2017 EOD daily 12/12/2017 EOD daily 12/ 5/2017 EOD daily
11/27/2017 EOD daily 12/13/2017 EOD daily 12/4/2017 EOD daily 11/ 28/ 2017 EOD daily
11/29/2017 EOD daily 12/15/2017 EOD daily 11/30/2017 EOD daily 12/ 1/2017 EOD daily
12/18/2017 EOD daily 12/20/2017 EOD daily 12/19/2017 EOD daily 12/ 26/ 2017 EOD daily
12/27/2017 EOD daily 12/22/2017 EOD daily 12/21/2017 EOD daily

Step 6:

Spilt the data into a training set and a test set. We will use the first 48 months (November 2017
to October 2021) as the training set and the last 12 months (November 2021 to October 2022) as
the test set.

Step 7:

Save the training and test sets as separate Excel files.

Mean and SD in excel


(b) To examine the prepared time series of Company B, we will perform the following

Task Solution

Step 1:

Import the training set into SAS using the following code:

Proc import datafile="path_to_file/training_set.xlsx"

Out-stockpriceb_train dbms=xlsx

Replace;

Sheet "Sheet1";

Run;

Step 2:

Check the descriptive statistics of the time series using the following SAS code:

Proc univariate data-stockpriceb_train;


Var closing price:

run:

Step 3:

Plot the time series decomposition using the following SAS code:

Proc timeseries data=stockpriceb_train out = decomp;

var closing price;

id date interval-month;

run;

Data exploration

(i) Descriptive statistics such as mean, varlance, autocorrelation, etc. We can use SAS to
compute the descriptive statistics of the time series. The mean, variance, and
autocorrelation of the closing prices are shown below:

Proc univariate data-stockpriceb_train;

Var closing price;

Autocorr ;

Run:

(ii) Graphical exploration (eg, line plots, histograms, etc.)

We can use SAS to create line plots and histograms of the closing prices. The line plot shows the
overall trend and seasonality of the data, while the histogram shows the distribution of the data.

Proc sgplot data-stockpriceb_train,

Series x-date y=closing price;


Run:

Proc sgplot data stockpriceb_train

Histogram closing price/nbins-20;

Run:

(iii) Time series decomposition plots

We can use SAS to decompose the time series into its trend, seasonal, and regular components.
The decomposition plot shows the magnitude and direction of each component.

Proc timeseries data stockpriceb train out-decomp

Var closing price, id date interval-mont:

Proc saplot data-decomp

Series x date y trend/lineattrs = (color blue);

Series x=date y seasonal/ lincattrs= (color=red);

Series x-date y irregular lineattrs = (color=green);

Run;

Question no 2:

Ans:
In the first part (a) of the question, described the steps to prepare the monthly stock prices of
Company B from November 2017 to October 2022 as a univariate time series for smoothing and
forecasting in Excel.

The steps included selecting the column of interest, sorting the data in ascending order by date,
checking for missing values and removing or interpolating them, creating a time series plot of the
data, splitting the data into a training set and a test set, saving the training and test sets as
separate Excel files, and importing the training set into SAS. The steps were presented in a
concise manner and illustrated with relevant screenshots.

In the second part (b) of the question, I described the data exploration tasks that can be
performed on the prepared time series using SAS.

The tasks included computing descriptive statistics such as mean, variance, and autocorrelation,
creating line plots and histograms to explore the overall trend and distribution of the data, and
decomposing the time series into its trend, seasonal, and Irregular components to better
understand the underlying patterns.

For each task, I provided the relevant SAS code and illustrated the output with in-text
screenshots. The SAS code was not included in the word count limit.

SAS Analysis
Output:
Return serious
HMM return

Output
Parameters
VaR forcast
Output:

You might also like