Sunday, February 17, 2019

Dow Jones Stock Index Analysis - part 2

Introduction

In this second post, we analyse the Dow Jones weekly log returns.

Packages

The packages being used in this post series are herein listed.

suppressPackageStartupMessages(library(lubridate)) # dates manipulation
suppressPackageStartupMessages(library(fBasics)) # enhanced summary statistics
suppressPackageStartupMessages(library(lmtest)) # coefficients significance tests
suppressPackageStartupMessages(library(urca)) # unit rooit test
suppressPackageStartupMessages(library(ggplot2)) # visualization
suppressPackageStartupMessages(library(quantmod)) # getting financial data
suppressPackageStartupMessages(library(PerformanceAnalytics)) # calculating returns
suppressPackageStartupMessages(library(rugarch)) # GARCH modeling
suppressPackageStartupMessages(library(FinTS)) # ARCH test
suppressPackageStartupMessages(library(forecast)) # ARMA modeling
suppressPackageStartupMessages(library(strucchange)) # structural changes
suppressPackageStartupMessages(library(TSA)) # ARMA order identification

Getting Data

We upload the environment status as saved at the end of part 1.

load(file='DowEnvironment.RData')

Weekly Log-returns Exploratory Analysis

The weekly log returns can be computed starting from the daily ones. Let us suppose to analyse the trading week on days {t-4, t-3, t-2, t-1, t} and to know closing price at day t-5 (last day of the previous week). We define the weekly log-return as:

\[ r_{t}^{w}\ :=\ ln \frac{P_{t}}{P_{t-5}} \]

That can be rewritten as:

\[ \begin{equation} \begin{aligned} r_{t}^{w}\ = \ ln \frac{P_{t}P_{t-1} P_{t-2} P_{t-3} P_{t-4}}{P_{t-1} P_{t-2} P_{t-3} P_{t-4} P_{t-5}} = \\ =\ ln \frac{P_{t}}{P_{t-1}} + ln \frac{P_{t-1}}{P_{t-2}} + ln \frac{P_{t-2}}{P_{t-3}} + ln \frac{P_{t-3}}{P_{t-4}}\ +\ ln \frac{P_{t-4}}{P_{t-5}}\ = \\ = r_{t} + r_{t-1} + r_{t-2} + r_{t-3} + r_{t-4} \end{aligned} \end{equation} \]

Hence the weekly log return is the sum of daily log returns applied to the trading week window.

We take a look at Dow Jones weekly log-returns.

dj_weekly_ret <- apply.weekly(dj_ret, sum)
plot(dj_weekly_ret)

That plot shows sharp increses and decreases of volatility.

We transform the original time series data and index into a dataframe.

dj_weekly_ret_df <- xts_to_dataframe(dj_weekly_ret)
dim(dj_weekly_ret_df)
## [1] 627   2
head(dj_weekly_ret_df)
##   year         value
## 1 2007 -0.0061521694
## 2 2007  0.0126690596
## 3 2007  0.0007523559
## 4 2007 -0.0062677053
## 5 2007  0.0132434177
## 6 2007 -0.0057588519
tail(dj_weekly_ret_df)
##     year       value
## 622 2018  0.05028763
## 623 2018 -0.04605546
## 624 2018 -0.01189714
## 625 2018 -0.07114867
## 626 2018  0.02711928
## 627 2018  0.01142764

Basic statistics summary

(dj_stats <- dataframe_basicstats(dj_weekly_ret_df))
##                  2007      2008      2009      2010      2011      2012
## nobs        52.000000 52.000000 53.000000 52.000000 52.000000 52.000000
## NAs          0.000000  0.000000  0.000000  0.000000  0.000000  0.000000
## Minimum     -0.043199 -0.200298 -0.063736 -0.058755 -0.066235 -0.035829
## Maximum      0.030143  0.106977  0.086263  0.051463  0.067788  0.035316
## 1. Quartile -0.009638 -0.031765 -0.015911 -0.007761 -0.015485 -0.010096
## 3. Quartile  0.014808  0.012682  0.022115  0.016971  0.014309  0.011887
## Mean         0.001327 -0.008669  0.003823  0.002011  0.001035  0.001102
## Median       0.004244 -0.006811  0.004633  0.004529  0.001757  0.001166
## Sum          0.069016 -0.450811  0.202605  0.104565  0.053810  0.057303
## SE Mean      0.002613  0.006164  0.004454  0.003031  0.003836  0.002133
## LCL Mean    -0.003919 -0.021043 -0.005115 -0.004074 -0.006666 -0.003181
## UCL Mean     0.006573  0.003704  0.012760  0.008096  0.008736  0.005384
## Variance     0.000355  0.001975  0.001051  0.000478  0.000765  0.000237
## Stdev        0.018843  0.044446  0.032424  0.021856  0.027662  0.015382
## Skewness    -0.680573 -0.985740  0.121331 -0.601407 -0.076579 -0.027302
## Kurtosis    -0.085887  5.446623 -0.033398  0.357708  0.052429 -0.461228
##                  2013      2014      2015      2016      2017      2018
## nobs        52.000000 52.000000 53.000000 52.000000 52.000000 53.000000
## NAs          0.000000  0.000000  0.000000  0.000000  0.000000  0.000000
## Minimum     -0.022556 -0.038482 -0.059991 -0.063897 -0.015317 -0.071149
## Maximum      0.037702  0.034224  0.037693  0.052243  0.028192  0.050288
## 1. Quartile -0.001738 -0.006378 -0.012141 -0.007746 -0.002251 -0.011897
## 3. Quartile  0.011432  0.010244  0.009620  0.012791  0.009891  0.019857
## Mean         0.004651  0.001756 -0.000669  0.002421  0.004304 -0.001093
## Median       0.006360  0.003961  0.000954  0.001947  0.004080  0.001546
## Sum          0.241874  0.091300 -0.035444  0.125884  0.223790 -0.057950
## SE Mean      0.001828  0.002151  0.002609  0.002436  0.001232  0.003592
## LCL Mean     0.000981 -0.002563 -0.005904 -0.002470  0.001830 -0.008302
## UCL Mean     0.008322  0.006075  0.004567  0.007312  0.006778  0.006115
## Variance     0.000174  0.000241  0.000361  0.000309  0.000079  0.000684
## Stdev        0.013185  0.015514  0.018995  0.017568  0.008886  0.026154
## Skewness    -0.035175 -0.534403 -0.494963 -0.467158  0.266281 -0.658951
## Kurtosis    -0.200282  0.282354  0.665460  2.908942 -0.124341 -0.000870

Mean

Years when Dow Jones weekly log-returns has positive mean are:

filter_dj_stats(dj_stats, "Mean", 0)
## [1] "2007" "2009" "2010" "2011" "2012" "2013" "2014" "2016" "2017"

All mean values in ascending order.

dj_stats["Mean",order(dj_stats["Mean",,])]
##           2008      2018      2015     2011     2012     2007     2014
## Mean -0.008669 -0.001093 -0.000669 0.001035 0.001102 0.001327 0.001756
##          2010     2016     2009     2017     2013
## Mean 0.002011 0.002421 0.003823 0.004304 0.004651

Median

Years when Dow Jones weekly log-returns has positive median are:

filter_dj_stats(dj_stats, "Median", 0)
##  [1] "2007" "2009" "2010" "2011" "2012" "2013" "2014" "2015" "2016" "2017"
## [11] "2018"

All median values in ascending order.

dj_stats["Median",order(dj_stats["Median",,])]
##             2008     2015     2012     2018     2011     2016     2014
## Median -0.006811 0.000954 0.001166 0.001546 0.001757 0.001947 0.003961
##           2017     2007     2010     2009    2013
## Median 0.00408 0.004244 0.004529 0.004633 0.00636

Skewness

Years when Dow Jones weekly log-returns has positive skewness are:

filter_dj_stats(dj_stats, "Skewness", 0)
## [1] "2009" "2017"

All skewness values in ascending order.

dj_stats["Skewness",order(dj_stats["Skewness",,])]
##              2008      2007      2018      2010      2014      2015
## Skewness -0.98574 -0.680573 -0.658951 -0.601407 -0.534403 -0.494963
##               2016      2011      2013      2012     2009     2017
## Skewness -0.467158 -0.076579 -0.035175 -0.027302 0.121331 0.266281

Excess Kurtosis

Years when Dow Jones weekly log-returns has positive excess kurtosis are:

filter_dj_stats(dj_stats, "Kurtosis", 0)
## [1] "2008" "2010" "2011" "2014" "2015" "2016"

All excess kurtosis values in ascending order.

dj_stats["Kurtosis",order(dj_stats["Kurtosis",,])]
##               2012      2013      2017      2007      2009     2018
## Kurtosis -0.461228 -0.200282 -0.124341 -0.085887 -0.033398 -0.00087
##              2011     2014     2010    2015     2016     2008
## Kurtosis 0.052429 0.282354 0.357708 0.66546 2.908942 5.446623

Year 2008 has also highest weekly kurtosis. However in this scenario, 2017 has negative kurtosis and year 2016 has the second highest kurtosis.

Boxplots

dataframe_boxplot(dj_weekly_ret_df, "DJIA weekly log-returns box plots 2007-2018")

Density plots

dataframe_densityplot(dj_weekly_ret_df, "DJIA weekly log-returns density plots 2007-2018")

Shapiro Tests

dataframe_shapirotest(dj_weekly_ret_df)
##            result
## 2007 0.0140590311
## 2008 0.0001397267
## 2009 0.8701335006
## 2010 0.0927104389
## 2011 0.8650874270
## 2012 0.9934600084
## 2013 0.4849043121
## 2014 0.1123139646
## 2015 0.3141519756
## 2016 0.0115380989
## 2017 0.9465281164
## 2018 0.0475141869

The null hypothesis of normality is rejected for years 2007, 2008, 2016.

QQ plots

dataframe_qqplot(dj_weekly_ret_df, "DJIA weekly log-returns QQ plots 2007-2018")

Strong departure from normality is particularly visible on year 2008.

Saving the current enviroment for further analysis.

save.image(file='DowEnvironment.RData')

References

[1] Dow Jones Industrial Average [https://en.wikipedia.org/wiki/Dow_Jones_Industrial_Average]

[2] Skewness [https://en.wikipedia.org/wiki/Skewness]

[3] Kurtosis [https://en.wikipedia.org/wiki/Kurtosis]

[4] An introduction to analysis of financial data with R, Wiley, Ruey S. Tsay [https://www.wiley.com/en-us/An+Introduction+to+Analysis+of+Financial+Data+with+R-p-9780470890813]

[5] Time series analysis and its applications, Springer ed., R.H. Shumway, D.S. Stoffer [https://www.springer.com/gp/book/9783319524511]

[6] Applied Econometric Time Series, Wiley, W. Enders, 4th ed. [https://www.wiley.com/en-us/Applied+Econometric+Time+Series%2C+4th+Edition-p-9781118808566]

[7] Forecasting - Principle and Practice, Texts, R.J. Hyndman [https://otexts.org/fpp2/]

[8] Options, Futures and other Derivatives, Pearson ed., J.C. Hull[https://www.pearson.com/us/higher-education/product/Hull-Options-Futures-and-Other-Derivatives-9th-Edition/9780133456318.html]

[9] An introduction to rugarch package [https://cran.r-project.org/web/packages/rugarch/vignettes/Introduction_to_the_rugarch_package.pdf]

Disclaimer

Any securities or databases referred in this post are solely for illustration purposes, and under no regard should the findings presented here be interpreted as investment advice or a promotion of any particular security or source.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.