1 General directions for this Workshop

You will work in RStudio. Create an R Notebook document (File -> New File -> R Notebook), where you have to write whatever is asked in this workshop.

At the beginning of the R Notebook write Workshop 7 - Financial Econometrics II and your name (as we did in previous workshop).

You have to replicate all the steps explained in this workshop, and ALSO you have to do whatever is asked. Any QUESTION or any STEP you need to do will be written in CAPITAL LETTERS. For ANY QUESTION, you have to RESPOND IN CAPITAL LETTERS right after the question. It is STRONGLY RECOMMENDED that you write your OWN NOTES as if this were your notebook. Your own workshop/notebook will be very helpful for your further study.

You have to keep saving your .Rmd file, and ONLY SUBMIT the .html version of your .Rmd file. Pay attention in class to know how to generate an html file from your .Rmd.

2 Spurious regression

When we want to examine the relationship between two non-stationary variables by running a regression model, we have the risk to end up with a non-valid - spuious - regression. Before we understand why a regression model can be spurious, we start with and example using 2 real-world variables.

Install the wbstats package using RStudio. This package was written by the World Bank, and it has functions to download data of all countries around the world. The function wb downloads hundreds of time-series variables that the World Bank tracks for all countries. If you want to know more about this package, you can check its documentation in the cran web site (https://cran.r-project.org/web/packages/wbstats/wbstats.pdf)

We will download the infant mortality rate and the exports for Mexico. It is supposed that these variables have nothing in common, so we would not expect a significant relationship.

library(wbstats)
## Warning: package 'wbstats' was built under R version 4.1.3
# Mexico - Infant mortality
infantm<-wb_data(indicator = c("SP.DYN.IMRT.IN"), 
      country="MEX", start_date = 1980, end_date = 2020)
# Mexico - Export value
exports<-wb_data(indicator = c("TX.VAL.MRCH.XD.WD"), 
      country="MEX", start_date = 1980, end_date = 2020)

The wb function brings a data frame with the requested data. We can plot the data to have an idea of these 2 variables:

plot.ts(infantm$SP.DYN.IMRT.IN)

plot.ts(exports$TX.VAL.MRCH.XD.WD)

Now run a regression using these series. Report the result of the regression. Did you find significant relationship? is your result what you expected?

m1 <- lm(exports$TX.VAL.MRCH.XD.WD ~ infantm$SP.DYN.IMRT.IN)
summary(m1)
## 
## Call:
## lm(formula = exports$TX.VAL.MRCH.XD.WD ~ infantm$SP.DYN.IMRT.IN)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -49.842 -41.039  -4.786  39.072  73.624 
## 
## Coefficients:
##                        Estimate Std. Error t value Pr(>|t|)    
## (Intercept)            280.3572    15.5425   18.04  < 2e-16 ***
## infantm$SP.DYN.IMRT.IN  -6.3166     0.5205  -12.13 8.14e-15 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 41.48 on 39 degrees of freedom
## Multiple R-squared:  0.7906, Adjusted R-squared:  0.7852 
## F-statistic: 147.3 on 1 and 39 DF,  p-value: 8.139e-15

Research about spurious regression, and explain in which cases you can end up with a spurious regression

Are the series cointegrated? Is the regression spurious or valid? Run the corresponding test

library(tseries)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
adf.test(m1$residuals, k = 0)
## 
##  Augmented Dickey-Fuller Test
## 
## data:  m1$residuals
## Dickey-Fuller = -2.1794, Lag order = 0, p-value = 0.503
## alternative hypothesis: stationary

3 Cointegration between Financial series

Using daily data of Mexico IPCyC market index and the S&P 500, examine whether two series are cointegrated. Generate an index for each instrument. To do these indexes, create a variable that represents how 1.00 peso or 1.00 dollar invested in each instrument would be changing over time.

  1. From Jan 1, 2015 to Oct 2, 2017.

  2. From Oct 3, 2017 to Feb 28, 2018

For both cases, run a cointegration test and INTERPRET your results.

4 Holding return of a portfolio of 2 stocks

Once we have an idea about cointegration, we will review how to form a portfolio of 2 assets and calculate its holding return over time. The holding period return of an asset from day 1 to day N (HPR) can be calculated with any of the following ways:

  1. HPR = (Price of the stock at day N / Price of the stock at day 1) - 1

  2. HPR = exp ( Sum of all continuous compounded returns from day 1 to day N) - 1

The expected return of a portfolio of 2 assets is estimated as a weighted average of the expected stock returns:

\(E[R_{p}]=w_{1}*E[R_{1}]+w_{2}*E(R_{2})\)

The holding return of a portfolio of 2 assets for a specific period of time is estimated as a weighted average of the holding returns of the assets:

\(HPR_{p}=w_{1}*HPR_{1}+w_{2}*HPR_{2}\)

Download daily prices from CEMEX and ALFA from Jan 1, 2015 to Dec 31, 2017.

Calculate their holding period returns of both stocks

Create a portfolio 1 assigning 30% to CEMEX and 70% for ALFA and calculate the HPR of the portfolio

Create a portfolio 2 assigning -100% to CEMEX and +200% to ALFA and calcuate the HPR of this portfolio

What does a negative sign mean a portfolio? Briefly explain with the previous example.

5 CHALLENGE: Statistical arbitrage

Using the CEMEX and the ALFAA daily price series from Jan 1, 2015 to Dec 31, 2017, examine whether these two series are cointegrated. Assume you are in December 31, 2017. If the series are cointegrated that means that the residual of the regression between these series is a stationary series. Then, if this is the case, what can you do to take advantage in financial trading? If you were to invest from Jan 1, 2018 to Feb 28, 2018 in a portfolio of these stocks, which weights would you assign? Calculate the HPR of your portfolio from Jan 1st to Feb 28, 2018.

This is called statistical arbitrage, and some technical analysts use this technique to find arbitrage opportunities (be careful, this is not a safe strategy to follow)

6 Quiz 7 and W7 submission

Go to Canvas and respond Quiz 7. You will have 3 attempts. Questions in this Quiz are related to concepts of the readings related to this Workshop.

The grade of this Workshop will be the following:

  • Complete (100%): If you submit an ORIGINAL and COMPLETE HTML file with all the activities, with your notes, and with your OWN RESPONSES to questions
  • Incomplete (75%): If you submit an ORIGINAL HTML file with ALL the activities but you did NOT RESPOND to the questions and/or you did not do all activities and respond to some of the questions.
  • Very Incomplete (10%-70%): If you complete from 10% to 75% of the workshop or you completed more but parts of your work is a copy-paste from other workshops.
  • Not submitted (0%)

Remember that you have to submit your .html file through Canvas BEFORE NEXT CLASS.