Welcome to the ECOFMET Webpage!

Shortened course syllabi

What you see in this webpage is a shortened version of the course syllabi for Advanced Financial Econometrics (ECOFMET) available in Animospace.

Basic information

  1. You are enrolled in either ECOFMET V24 or V25.

  2. The prerequisite is ECOMETR.

  3. We meet for ECOFMET

    1. V24 Tuedays 1430-1600 face-to-face and Fridays 1430-1600 synchronously (unless otherwise informed)
    2. V25 Tuedays 1615-1745 face-to-face and Fridays 1615-1745 synchronously (unless otherwise informed)
  4. We have two websites: one at Animospace and one here. I maintain a course diary here.

Course description

Within the context of financial economic theory, this course combines interesting and rigorous elements of microeconometrics and time series econometrics. The microeconometrics component consists of estimation and testing frameworks used in understanding individual behavior. Topics include selected models for cross-section data (e.g. discrete choice modeling, selection models, basic GMM estimation and testing frameworks for optimization-based problems, linear panel data models for financial and economic outcomes, etc). The time series econometrics component, which is appropriately called macroeconometrics, includes methods that are quite prominent in cyclical analysis (e.g. autoregressive and moving average models) as well as other time series models (vector autoregression models and their structural variants).

Main textbooks

We will be using the following textbooks (abbreviated as SDAFE and SW in this syllabus):

Ruppert, D. & Matteson, D. S. (2015). Statistics and Data Analysis for Financial Engineering: With R Examples (2nd ed.). Springer.

Stock, J. H. & Watson, M. W. (2020). Introduction to Econometrics (4th ed.). Pearson.

Course outline

Below is a tentative course outline and we may have to adjust, depending on the circumstances.

Topics Readings
Returns SDAFE Chapter 2
Exploratory Data Analysis SDAFE Sections 4.1 to 4.5
Modeling Univariate Distributions SDAFE Chapter 5, Sections 19.1, 19.2.1, 19.2.2
Resampling SDAFE Chapter 6 and Section 19.3
Multivariate Statistical Models SDAFE Chapter 7
Time Series Models: Basics SDAFE Chapter 12, SW Chapter 15
Time Series Models: Further Topics SDAFE Chapter 13, SW Chapter 16
Regression: Advanced Topics SDAFE Chapter 11, SW Chapters 9 to 14
Cointegration SDAFE Chapter 15, SW Chapter 17
GARCH Models SDAFE Chapter 14 and Section 19.4, SW Chapter 17

References

The following references have physical copies available at the DLSU Library Reserve Section, 8th Floor of the Henry Sy Hall and most are also available for digital borrowing through the Internet Archive.

Angrist, J. D. & Pischke, J. (2015). Mastering ’Metrics: The Path from Cause to Effect. Princeton University Press. Borrow from the Internet Archive.

Wooldridge, J. W. (2010). Econometric Analysis of Cross Section and Panel Data (2nd ed.). The MIT Press.

Enders, W. (2009). Applied Econometric Time Series (3rd ed.). Wiley.

Angrist, J. D. & Pischke, J. (2008). Mostly Harmless Econometrics: An Empiricist’s Companion. Princeton University Press.

Mills, T. C. & Markellos, R. N. (2008). The Econometric Modeling of Financial Time Series (3rd ed.). Cambridge University Press.

Rachev, S. T., Mittnik, S., Fabozzi, F. J., Focardi, S. M., & Jašić, T. (2007). Financial Econometrics: From Basics to Advanced Modeling Techniques. Wiley.

Tsay, R. S. (2005). Analysis of Financial Time Series (2nd ed.). Wiley. Borrow from the Internet Archive.

Alexander, C. (2001). Market Models: A Guide to Financial Data Analysis. Borrow from the Internet Archive.

Gourieroux, C. & Jasiak, J. (2001). Financial Econometrics: Problems, Models, and Methods. Princeton University Press. Borrow from Internet Archive.

Campbell, J. Y., Lo, A. W., & MacKinlay, A. C. (1997). The Econometrics of Financial Markets. Princeton University Press. Borrow from Internet Archive.

The following references are NOT physically available at the DLSU Library but they are available for digital borrowing through the Internet Archive.

Wooldridge, J. W. (2016). Introductory Econometrics: A Modern Approach (6th ed.). CENGAGE Learning. Borrow from the Internet Archive.

Fan, J. & Yao, Q. (2015). The Elements of Financial Econometrics. Beijing Science Press. Borrow from Internet Archive.

Tsay, R. S. (2010). Analysis of Financial Time Series (3rd ed.). Wiley. Borrow from the Internet Archive.

Wang, P. (2009). Financial Econometrics. Routledge. Borrow from the Internet Archive.

Enders, W. (2004). Applied Econometric Time Series (2nd ed.). Wiley. Borrow from Internet Archive.

Wooldridge, J. W. (2002). Econometric Analysis of Cross Section and Panel Data (1st ed.). The MIT Press. Borrow from the Internet Archive.

Mills, T. C. (1999). The Econometric Modeling of Financial Time Series (2nd ed.). Cambridge University Press. Borrow from the Internet Archive.

The following references are more recent (meaning they come from the past five years) and are mainly articles about the bigger picture related to the course:

Bollerslev, T. (2023). The story of GARCH: A personal odyssey. Journal of Econometrics, 234 Supplement: 96-100. https://doi-org.dlsu.idm.oclc.org/10.1016/j.jeconom.2023.01.015.

Blundell, R. & Bond, S. (2023). Initial conditions and Blundell-Bond estimators. Journal of Econometrics, 234 Supplement: 101-110. https://doi-org.dlsu.idm.oclc.org/10.1016/j.jeconom.2023.01.020.

Diebold, F. X. & Yilmaz, K. (2023). On the past, present, and future of the Diebold–Yilmaz approach to dynamic network connectedness. Journal of Econometrics, 234 Supplement: 115-120. https://doi-org.dlsu.idm.oclc.org/10.1016/j.jeconom.2023.01.021.

Scheuch, C., Voigt, S., & Weiss, P. (2023). Tidy Finance with R (1st ed.). Chapman and Hall/CRC. https://doi.org/10.1201/b23237.

Graham, J. R. (2022), Presidential Address: Corporate Finance and Reality. The Journal of Finance, 77: 1975-2049. https://doi.org/10.1111/jofi.13161.

The following are a subset of the references we may be using for the collaborative class project.

Creamer, J., & Warren, L. (2024). Unbanked and impoverished? Exploring banking and poverty interactions over time. Journal of Consumer Affairs, 1–32. https://doi.org/10.1111/joca.12576. Access ungated copy here.

Bekaert, G., Harvey, C. R., & Mondino, T. (2023). Emerging Equity Markets in a Globalized World. SSRN Working Paper. https://dx.doi.org/10.2139/ssrn.2344817.

Debuque-Gonzales, M. & Corpus, J. P. P. (2021) Understanding and Measuring Financial Inclusion in the Philippines. PIDS Discussion Paper DP 2021-37.

Karlan, D., Mullainathan, S., & Roth, B. N. (2019). Debt Traps? Market Vendors and Moneylender Debt in India and the Philippines. American Economic Review: Insights, 1 (1): 27-42. https://www.aeaweb.org/articles/pdf/doi/10.1257/aeri.20180030

Because of accreditation requirements, I am compelled to brush aside my modesty and refer to the following materials which may still be relevant for the current course:

Pua, A. A. Y. (2024). Econometrics. Visit online textbook draft.

Fritsch, M., Pua, A. A. Y., & Schnurbus, J. (2024). Teaching Advanced Topics in Econometrics using an Introductory Textbook: The Case of Dynamic Panel Data Methods. Working Paper.

Fritsch, M., Pua, A. A. Y., & Schnurbus, J. (2024) Seven Examples to Better Illustrate the Method of Moments for Business, Economics, and Finance Undergraduates. Working Paper.

Course requirements

There are group-based and individual-based requirements for the course. You may be asked to provide a self-evaluation and a group evaluation, as we go along. These evaluations are excellent ways to gain first-hand knowledge regarding your own and your classmates’ attitudes and behaviors.

  1. Collaborative class projects (30%): This course requirement is the core research component of the course.

  2. Individual long exams 1, 2, and 3 (each weighted 18%, 24%, 28%, respectively): These requirements are timed and scheduled in advance.

    1. The exams are conducted face to face.
    2. They are tentatively set on 2024-05-28, 2024-07-09, and 2024-07-30.
    3. These individual exams are expected to be comprehensive. This means that the second long exam may feature topics from the first long exam. In addition, the third long exam may feature topics from the first and second long exams.

Class policies

Be guided by the student handbook regarding conduct and attendance. Additional policies may be given in class, if necessary. The biggest hurdle of any student is the inability to read, comprehend, and follow instructions. Make sure to keep yourself informed.

Refer to full syllabus for exam policy, late homework policy, and other policies related to online sessions.

Collaborative efforts

Emerging market equity returns

Errata for SDAFE, 2nd edition

Google doc for maintaining an errata file here (require organization log-in credentials to view and comment)

Course diary

Suspension of classes, make-up materials

  1. Video recordings of Long Exam 01 and 02 solutions (already shared, July 12 asynchronous lecture)
  2. Video recordings of the ideas from SW Section 15.3 and testing return predictability (already shared, August 2 asynchronous lecture which replaced the suspended class on July 26)
  3. Stock and Watson 4th edition student resources
  4. Code for replicating calculations in SW Section 15.3
# Replicating SW Section 15.3 calculations
# Load dataset, download from SW website
library(readxl)
gdpgr <- read_excel("us_macro_quarterly.xlsx",
col_types = c("skip", "numeric", "skip",
"skip", "skip"))
library(xts)
# Make a date variable
gdpgr$date <- as.yearqtr(1955 + seq(0, 63*4-1)/4)
# Create xts object
gdpgr <- as.xts(gdpgr,  frequency = 4)
# Create GDP growth variable
gdpgr$Y <- 400*diff(log(gdpgr$GDPC1))
library(dyn)
# Estimate AR(1) over the specified time period
res1 <- dyn$lm(Y ~ lag(Y, 1), data=gdpgr['1962-01/2017-07'])
# Estimate AR(2) over the specified time period
res2 <- dyn$lm(Y ~ lag(Y, 1:2), data=gdpgr['1962-01/2017-07'])
# Summary tables
summary(res1)
summary(res2)
library(lmtest)
# Testing whether beta1=0
# Standard errors are based on conditional homoscedasticity
coeftest(res1)
library(sandwich)
# Standard errors are robust to conditional heteroscedasticity
coeftest(res1, vcov. = vcovHC)
# Standard errors are robust to conditional heteroscedasticity and serial correlation (autocorrelation)
# More details in SW Section 16.4
# Using defaults
coeftest(res1, vcov. = vcovHAC)
  1. Code to test whether PSEi monthly returns are predictable
# Load dataset
# Pay attention to format of original xls 
library(readxl)
PSEi <- read_excel("~/Documents/ecometf/ecofmet-V24-V25/PSEi.xls", skip = 2)
# Get a sense of the data
head(PSEi)
tail(PSEi)
PSEi[is.na(PSEi$Close),]
PSEi_clean <- PSEi[which(!is.na(PSEi$Close)),]
# Transform to xts object for use in quantmod
dates <- as.Date(PSEi_clean$Date)
prices <- PSEi_clean$Close
library(quantmod)
ts <- xts(prices, dates)
# Remove entries which will create issues with monthly return calculations
ts.monthly <- ts['1990-03/2008-06']
# log returns
ret.monthly <- monthlyReturn(ts.monthly, type="log")
# Data risk free rates
# https://www.bsp.gov.ph/Statistics/Financial%20System%20Accounts/sdir.xls
# starts from Jan 1975
# HAVE TO ADJUST THE PATH
sdir_2024_05 <- read_excel("~/Documents/ecometf/ts-data/sdir-2024-05.xls", sheet = "MONTHLY", skip = 5)
sdir_2024_05 <- sdir_2024_05[!(sdir_2024_05$...2 %in% as.character(seq(1975, 2024))), ]
sdir_2024_05 <- sdir_2024_05[3:595, c(2, seq(5, 49, by = 2), 77)]
names(sdir_2024_05) <- c("month", "tbill91", "tbill182", "tbill364", "tbillall", 
                         "timedep30_45", "timedep46_60", "timedep61_90", "timedep91_180", "timedep181_365", "timedep366_730", "timedep731", "timedep_l_1yr", "timedep_g_1yr", "timedep_l_2yr", "timedepall",
                         "sav_dep_rate", "bank_avg_lend_rate", "bank_lend_rate_high", "bank_lend_rate_low", "mnl_ref_rate_60", "mnl_ref_rate_90", "mnl_ref_rate_180", "mnl_ref_rate_all", "ibcl_rate")
sdir_2024_05 <- as.data.frame(sapply(sdir_2024_05, as.numeric))
sdir_2024_05$date <- as.yearmon(1975 + seq(0, 49*12-1+5)/12)
sdir_2024_05$month <- NULL
cleaned <- as.xts(sdir_2024_05,  frequency = 12)
tdep.monthly <- cleaned$timedep30_45
# Adjust time variable to merge correctly
time(ret.monthly) <- as.yearmon(1990 +(3:222)/12)
# Merge series
merged <- merge.xts(ret.monthly, tdep.monthly)
res <- dyn$lm(monthly.returns ~ lag(monthly.returns, 1), data = merged['1990-04/2008-07'])
library(lmtest)
coeftest(res, vcov. = vcov)
library(sandwich)
coeftest(res, vcov. = vcovHC)
coeftest(res, vcov. = vcovHAC)
# Compute excess returns
merged$excess.ret <- merged$monthly.returns-log(1+merged$timedep30_45/(12*100))
# testing predictability of monthly excess returns
res <- dyn$lm(excess.ret ~ lag(excess.ret, 1), data = merged['1990-04/2008-07'])
library(lmtest)
coeftest(res, vcov. = vcov)
library(sandwich)
coeftest(res, vcov. = vcovHC)
coeftest(res, vcov. = vcovHAC)
res <- dyn$lm(excess.ret ~ lag(excess.ret, 1:2), data = merged['1990-04/2008-07'])
library(car)
linearHypothesis(res, 
                      c("lag(excess.ret, 1:2)1", "lag(excess.ret, 1:2)2"), 
                      rhs = 0, 
                      test = "Chisq", 
                      vcov. = vcov)
library(sandwich)
linearHypothesis(res, 
                      c("lag(excess.ret, 1:2)1", "lag(excess.ret, 1:2)2"), 
                      rhs = 0, 
                      test = "Chisq", 
                      vcov. = vcovHC)
linearHypothesis(res, 
                      c("lag(excess.ret, 1:2)1", "lag(excess.ret, 1:2)2"), 
                      rhs = 0, 
                      test = "Chisq", 
                      vcov. = vcovHAC)

Lecture 15, 2024-07-19, online

  1. What happens to the sample mean outside of the IID case?
  2. Motivation for considering AR(1) models
  3. Best prediction and forecasting
  4. Notes for V24, notes for V25

Lecture 14, 2024-07-16, face-to-face

  1. Recap of the big picture for what makes the analysis of time series very different
  2. Understanding the concept of stationarity (SW Key Concept 15.3) and how dependence is completely different from stationarity
  3. Visualizations to understand stationarity and why it may be difficult to distinguish stationary and nonstationary time series when you only have one sample
### Process 1: IID N(1,4)
n <- 50
xt <- ts(rnorm(n, 1, 2))
plot(xt, ylim=c(-5,7))
# run after the first part
par(new=TRUE)
xt <- ts(rnorm(n, 1, 2))
plot(xt, ylim=c(-5,7))
### Process 2: MA(1) 
n <- 50
theta <- 0.5
zt <- ts(rnorm(n))
xt <- zt+theta*lag(zt,-1)
plot(xt, ylim=c(-3,3))
# run after the first part
par(new=TRUE)
zt <- ts(rnorm(n))
xt <- zt+theta*lag(zt,-1)
plot(xt, ylim=c(-3,3))
### Process 3: AR(1) 
xt <- arima.sim(n = 50, list(order=c(1,0,0), ar = 0.98), innov = rnorm(50))
plot(xt, ylim=c(-10,10))
# run after first part
xt <- arima.sim(n = 50, list(order=c(1,0,0), ar = 0.98), innov = rnorm(50))
plot(xt, ylim=c(-10,10))
### Process 4: Random walk 
n <- 50
xt <- ts(cumsum(rnorm(n)))
plot(xt, ylim=c(-10, 10))
# run after running the first part
par(new=TRUE)
xt <- ts(cumsum(rnorm(n)))
plot(xt, ylim=c(-10, 10))

Long exam 02, 2024-07-09

Lecture 13, 2024-07-05, online

  1. Continuing slides for time series: Recapping major ideas
  2. Why is the case where \(\beta_1^*=1\) and \(\beta_1^*<1\) for the AR(1) model \(Y_t=\beta_0^*+\beta_1^*Y_{t-1}+u_t\) is very different? Why does it matter for practice?
  3. Thinking about how to determine if returns are predictable
  4. Notes for V24, Notes for V25

Lecture 12, 2024-06-14, online

  1. How to use Chapters 2, 4, and 5 to assess market risk: Sections 19.1 to 19.2, Slides as of 2024-06-13
  2. Move on to effect of using time series data when running linear regressions: Slides as of 2024-06-11

Lecture 11, 2024-06-11, face-to-face

  1. Wrap up Chapter 5
  2. Code in book versus code shared in this website
  3. Discussed other use cases for maximum likelihood
  4. Introduced the method of moments

Lecture 10, 2024-06-07, online

  1. Discussed location-scale transformations of \(t_{\nu}\) and the GED, incorporating asymmetries for symmetric distributions

  2. Maximum likelihood as an algorithm: obtaining estimates (Section 5.9), standard errors (Section 5.10), confidence intervals (Section 5.10), choosing models (Section 5.12), testing (Section 5.11)

  3. Rough theoretical ideas as to why we expect MLE to work: quadraticity of the log-likelihood is the crucial reason, code below demonstrates for a simple example

# Draw random numbers from N(1, 4)
n <- 5
mu <- 1
sigma.sq <- 4 # change this to 1/4 and 40 if you want to look at the curvature of the log-likelihood
y <- rnorm(n, mu, sqrt(sigma.sq))
# Set up MINUS the log-likelihood (reused code from example)
# BUT sigma.sq is known, rather than a parameter to be estimated
mlnl <- function(par)
{
  sum(-dnorm(y, mean = par, sd = sqrt(sigma.sq), log = TRUE))
}
# New part where I want a plot of the log-likelihood for mu
# Place a grid of values for mu, adjust length.out if you wish
mu.val <- seq(-10, 10, length.out = 1000)
# Compute the log-likelihood at every value in mu.val
# The MINUS sign is to enable me to display the log-likelihood rather than the negative of the log-likelihood
log.like <- -sapply(mu.val, mlnl)
# Create a plot: vertical axis are the log-likelihood values, horizontal axis are the values of mu
# type = "l" is to connect the dots, try removing it
# fix the vertical axis for a nicer effect
plot(mu.val, log.like, type = "l", ylim = c(-200, 0))
# Draw a vertical line at the MLE for mu
# Make sure the line is colored blue-ish and dotted
abline(v = nlm(mlnl, 0)$estimate, col = "#0072B2", lty = "dotted")
# Draw a vertical line at mu, hence v = mu
# Make sure the line is colored orange-ish and is dotted
abline(v = mu, col = "#D55E00", lty = "dotted")
# Draw a curve representing the expected log-likelihood
curve(-n/2*log(2*pi)-n/2*log(sigma.sq)-n/2-n/(2*sigma.sq)*(1-x)^2, add = TRUE, col = "#CC79A7", lty = "dashed", lwd = 3)
  1. Application to daily returns for the PSEi

  2. Code to fit \(t_{\nu}^{\mathrm{std}}(\mu,\sigma^2)\), GED with parameters \(\mu\), \(\sigma^2\), \(\nu\), skewed \(t_{\nu}^{\mathrm{std}}(\mu,\sigma^2)\) with additional parameter \(\xi\): report estimates, standard errors, minimized negative log-likelihoods, AIC, BIC, check fit with Q-Q plot

# Load dataset
# Pay attention to format of original xls 
library(readxl)
PSEi <- read_excel("PSEi.xls", skip = 2)
# Get a sense of the data
head(PSEi)
tail(PSEi)
PSEi[is.na(PSEi$Close),]
PSEi_clean <- PSEi[which(!is.na(PSEi$Close)),]
# Transform to xts object for use in quantmod
dates <- as.Date(PSEi_clean$Date)
prices <- PSEi_clean$Close
library(quantmod)
ts <- xts(prices, dates)
ret.daily <- dailyReturn(ts, type="log", leading = FALSE)
# Adapted from Ruppert and Matteson
# Estimating parameters of t-distribution
# starting values
start <- c(mean(ret.daily$daily.returns), sd(ret.daily$daily.returns), 4)
# package for standardized t-distribution
library(fGarch)
# negative log-likelihood 
loglik <- function(theta)
{
  -sum(dstd(ret.daily$daily.returns, mean = theta[1], sd = theta[2], nu = theta[3], log = TRUE))
}
mle <- optim(start, loglik, hessian = TRUE)
# parameter estimates
mle$par
# minimized value of negative log-likelihood
mle$value
# Inverse of Fisher information
invFishInfo <- solve(mle$hessian)
# standard errors
sqrt(diag(invFishInfo))
# AIC
aic_t <- 2*mle$value+2*length(mle$par)
# BIC
bic_t <- 2*mle$value+log(length(ret.daily$daily.returns))*length(mle$par)
c(aic_t, bic_t)
# qq plots from scratch based on Ruppert and Matteson
n = length(ret.daily$daily.returns)
grid = (1:n)/(n+1)
# as.numeric here is important, without it will produce no plot
qqplot(sort(as.numeric(ret.daily$daily.returns)), 
       qstd(grid,mean=mle$par[1], sd=mle$par[2], nu=mle$par[3]),
       xlab="Data",ylab="t-quantiles",
       main="(a) t model")
# reference line
abline(0,1,col="red",lwd=2)
# an alternative possibility using qqPlot which may be easier
car::qqPlot(sort(as.numeric(ret.daily$daily.returns)), distribution = "std", mean=mle$par[1], sd=mle$par[2], nu=mle$par[3])
# Repeat for standardized generalized error distribution
library(fGarch)
loglik <- function(theta)
{
  -sum(dged(ret.daily$daily.returns, mean = theta[1], sd = theta[2], nu = theta[3], log = TRUE))
}
start <- c(mean(ret.daily$daily.returns), sd(ret.daily$daily.returns), 2)
mle <- optim(start, loglik, hessian = TRUE)
mle$par
mle$value
invFishInfo <- solve(mle$hessian)
sqrt(diag(invFishInfo))
aic_ged <- 2*mle$value+2*length(mle$par)
bic_ged <- 2*mle$value+log(length(ret.daily$daily.returns))*length(mle$par)
c(aic_ged, bic_ged)
car::qqPlot(sort(as.numeric(ret.daily$daily.returns)), distribution = "ged", mean=mle$par[1], sd=mle$par[2], nu=mle$par[3])
# Repeat for skewed standardized t-distribution
library(fGarch)
loglik <- function(theta)
{
  -sum(dsstd(ret.daily$daily.returns, mean = theta[1], sd = theta[2], nu = theta[3], xi = theta[4], log = TRUE))
}
start <- c(mean(ret.daily$daily.returns), sd(ret.daily$daily.returns), 4, 2)
mle <- optim(start, loglik, hessian = TRUE)
mle$par
mle$value
invFishInfo <- solve(mle$hessian)
sqrt(diag(invFishInfo))
aic_st <- 2*mle$value+2*length(mle$par)
bic_st <- 2*mle$value+log(length(ret.daily$daily.returns))*length(mle$par)
c(aic_st, bic_st)
car::qqPlot(sort(as.numeric(ret.daily$daily.returns)), distribution = "sstd", mean=mle$par[1], sd=mle$par[2], nu=mle$par[3], xi=mle$par[4])
  1. Code to conduct a likelihood ratio test of the null \(\xi=1\) (meaningful in our context as a way to determine whether the data provides evidence to support the hypothesis of symmetry for the distribution of daily returns)
# Estimate the model without imposing the null (unrestricted/unconstrained model)
library(fGarch)
loglik <- function(theta)
{
  -sum(dsstd(ret.daily$daily.returns, mean = theta[1], sd = theta[2], nu = theta[3], xi = theta[4], log = TRUE))
}
start <- c(mean(ret.daily$daily.returns), sd(ret.daily$daily.returns), 4, 2)
# Remove hessian=TRUE to save computational time
mle <- optim(start, loglik)
nllu <- mle$value ## Negative log-likelihood at the optimum found
# Estimate the model imposing the null (restricted/constrained model)
library(fGarch)
loglik <- function(theta)
{
  -sum(dsstd(ret.daily$daily.returns, mean = theta[1], sd = theta[2], nu = theta[3], xi = 1, log = TRUE))
}
# Change starting point to reflect that onyl 3 parameters are estimated
start <- c(mean(ret.daily$daily.returns), sd(ret.daily$daily.returns), 4)
# Remove hessian=TRUE to save computational time
mle <- optim(start, loglik)
nllc <- mle$value ## Negative log-likelihood at the optimum found
# likelihood ratio LR test statistic
test.statistic <- 2*(-nllu-(-nllc)) 
# significance level 0.05
# critical value from chi-squared with 1 df, because we have 1 restriction
critical <- qchisq(0.95, df = 1)
# decision
test.statistic > critical # if TRUE reject null, if FALSE fail to reject null
# report p-value
p.val <- pchisq(test.statistic, df = 1, lower.tail = FALSE)
p.val
  1. Students should work on the examples found in Section 5.14.

  2. Reading assignment for next meeting: Sections 19.1 to 19.2, Chapter 12

  3. Labs and practice exercises: Lab 5.19.2 Problems 6 and 7, Lab 5.19.3, Exercises 11 to 13

  4. Notes for V24, notes for V25

Long exam 01, 2024-06-04, face-to-face

What to bring for ECOMATH exam:

  1. Pens and extra pens
  2. Non-programmable scientific calculator
  3. University ID with picture

Coverage:

  1. Chapters 2, 4 (specifically Sections 4.1 to 4.4), and 5 (specifically Sections 5.1, 5.2, 5.4.2, 5.5 (only \(t_{\nu}\), discrete mixtures), 5.6 (only what GEDs are), 5.9)
  2. Updated practice exercises for Chapter 5 are Exercises 2, 7, 8, 9. The style of questioning found in Labs 5.19.2 and 5.19.3 and Exercises 11 and 12 may be relevant.
  3. Review how to calculate expected values and variances (along with using their properties) even just for the discrete case.
  4. And whatever we have done in class until May 31.

Lecture 9, 2024-05-31, online

  1. Maximum likelihood estimation as an algorithm: MLE by hand and using R
  2. Why could we not use the \(t_{\nu}\) distribution right away as a model for returns data?
  3. Code used in class
# Generate simulated data from N(1, 4)
# 1 = popn mean
# 4 = popn variance
n <- 5
mu <- 1
sigma.sq <- 4
# Artificial data
y <- rnorm(n, mu, sqrt(sigma.sq))
# Only get to see and use y from here on
# Use fitdistr
library(MASS)
fitdistr(y, "normal")
     mean         sd    
  2.3566398   1.5829661 
 (0.7079240) (0.5005778)
# Use nlm()
# Set up MINUS the log-likelihood
mlnl <- function(par)
{
  sum(-dnorm(y, mean = par[1], sd = sqrt(par[2]), log = TRUE))
}
# nlm() is one of the numerical optimization routines available in R
# Print out things completely
# Try changing the starting points for yourself
output <- nlm(mlnl, c(1,4), hessian = TRUE, print.level = 2)
iteration = 0
Step:
[1] 0 0
Parameter:
[1] 1 4
Function Value
[1] 10.77684
Gradient:
[1] -1.69579908 -0.05410171

iteration = 1
Step:
[1] 1.69579908 0.05410171
Parameter:
[1] 2.695799 4.054102
Function Value
[1] 9.710163
Gradient:
[1] 0.4182932 0.2180144

iteration = 2
Step:
[1] -0.3229366 -0.1411842
Parameter:
[1] 2.372863 3.912918
Function Value
[1] 9.606537
Gradient:
[1] 0.02073124 0.22971721

iteration = 3
Step:
[1] -0.1067777 -0.2839884
Parameter:
[1] 2.266085 3.628929
Function Value
[1] 9.54894
Gradient:
[1] -0.1247667  0.2116594

iteration = 4
Step:
[1] -0.1628645 -1.2786754
Parameter:
[1] 2.103220 2.350254
Function Value
[1] 9.464752
Gradient:
[1] -0.53912994 -0.09945711

iteration = 5
Step:
[1] 0.1995725 0.4251879
Parameter:
[1] 2.302793 2.775442
Function Value
[1] 9.406431
Gradient:
[1] -0.09700411  0.08657624

iteration = 6
Step:
[1]  0.06161348 -0.24024040
Parameter:
[1] 2.364406 2.535201
Function Value
[1] 9.391424
Gradient:
[1] 0.01531961 0.01142023

iteration = 7
Step:
[1] -0.005896888 -0.032759406
Parameter:
[1] 2.358509 2.502442
Function Value
[1] 9.3912
Gradient:
[1]  0.003737883 -0.001334322

iteration = 8
Step:
[1] -0.001970372  0.003488168
Parameter:
[1] 2.356539 2.505930
Function Value
[1] 9.391195
Gradient:
[1] -1.987399e-04  5.944937e-05

iteration = 9
Parameter:
[1] 2.356639 2.505782
Function Value
[1] 9.391195
Gradient:
[1] 3.693459e-08 3.906057e-07

Relative gradient close to zero.
Current iterate is probably solution.
output
$minimum
[1] 9.391195

$estimate
[1] 2.356639 2.505782

$gradient
[1] 3.693459e-08 3.906057e-07

$hessian
              [,1]          [,2]
[1,]  1.995385e+00 -9.292058e-05
[2,] -9.292058e-05  3.979971e-01

$code
[1] 1

$iterations
[1] 9
# Use optim()
# Try changing the starting points for yourself
output.optim <- optim(c(1,4), mlnl, hessian=TRUE)
  1. Try to modify the code above to directly estimate the population standard deviation rather than the population variance so that the results of nlm(), optim(), and MASS::fitdistr() will match.

  2. Notes for V24, notes for V25

Lecture 8, 2024-05-28, face-to-face

  1. Move on to Chapter 5

  2. Reading assignment for Chapter 5: Focus on Sections 5.1 to 5.6, 5.9 to 5.12, 5.14 (skip Example 5.16), 5.16 (return also to Section 4.5 on boxplots)

  3. Labs for Chapter 5: Focus on 5.19.2 (skip Problems 8 and 9), 5.19.3

  4. Exercises for Chapter 5: 2, 4a, 4b, 5a, 5b, 5c, 7 to 13

Lecture 7, 2024-05-24, online

  1. Wrap up Chapter 4

  2. Code used in class, shown below is for monthly returns. Adjust accordingly for daily returns.

# Load dataset
# Pay attention to format of original xls 
library(readxl)
PSEi <- read_excel("PSEi.xls", skip = 2)
# Get a sense of the data
head(PSEi)
tail(PSEi)
PSEi[is.na(PSEi$Close),]
PSEi_clean <- PSEi[which(!is.na(PSEi$Close)),]
# Transform to xts object for use in quantmod
dates <- as.Date(PSEi_clean$Date)
prices <- PSEi_clean$Close
library(quantmod)
ts <- xts(prices, dates)
# Remove entries which will create issues with monthly return calculations
ts.monthly <- ts['1990-03/2008-06']
ret.monthly <- monthlyReturn(ts.monthly, type="log")
# Density estimate for monthly returns
plot(density(ret.monthly$monthly.returns))
grid <- seq(-.4, 0.4, length=1000)
# Parametric fit using normal distribution
lines(grid, dnorm(grid, mean=mean(ret.monthly$monthly.returns), sd=sd(ret.monthly$monthly.returns)), col = "red", lty = 2)
# Use a robust estimator of spread
lines(grid, dnorm(grid, mean=mean(ret.monthly$monthly.returns), sd=mad(ret.monthly$monthly.returns)), col = "blue", lty = 3)
# Q-Q plot with normal as reference distribution (all default options)
# as.numeric shows up here to convert the xts object into an which qqnorm could understand
# try removing as.numeric() to see what happens
qqnorm(as.numeric(ret.monthly$monthly.returns), datax = TRUE)
qqline(as.numeric(ret.monthly$monthly.returns), datax = TRUE)
# Q-Q plot with t as reference distribution
# Require df as input
# sorting was adopted from the book (but does not seem to be necessary)
s_monthlyRet <- sort(as.numeric(ret.monthly$monthly.returns))
n <- length(s_monthlyRet)
# Grid to represent the cumulative probabilities (or how many percent full of water is the vase)
grid <- (1:n)/(n+1)
df = 4 # feel free to change this, needed for next line
# Compare with t with df=df as reference distribution
# qt() gives quantiles of the t distribution require df as input
qqplot(s_monthlyRet, qt(grid,df=df), xlab="monthly returns", ylab=paste("Quantiles of t-distribution with df=", df))
# Make own reference line 
lmfit <- lm(qt(c(.25,.75),df = df) ~ quantile(s_monthlyRet,c(.25,.75)))
abline(lmfit)
# Alternative from car package with confidence bands
# But does not conform with convention in Ruppert and Matteson
# specifically for datax = TRUE
library(car)
# compare with normal as reference distribution
qqPlot(s_monthlyRet, dist="norm", ylab = "monthly returns")
# compare with t distribution, adjust df accordingly
df = 4
qqPlot(s_monthlyRet, dist="t", df=df, ylab = "monthly returns")
  1. Previewed Sections 5.1 to 5.3, and a bit of maximum likelihood

  2. Labs for Chapter 4: All are included but there is code for Problem 6 which require some knowledge of Chapter 5.

  3. Exercises for Chapter 4: 1a to 1d, 2, 3, 4, 5, 6

Lecture 6, 2024-05-21, face-to-face

  1. Recapped connections among Chapters 2, 4, and 5
  2. Focused on the following population objects: cdf, population quantile
  3. Focused on the following sample objects: empirical cdf, sample quantiles, order statistics
  4. Water-filling analogy for normal probability plots (resulting patterns of plots for distributions which differ from the normal)

Lecture 5, 2024-05-17, face-to-face ONLINE

  1. Continue working on Chapter 4

    1. Why bother estimating a density?
    2. Why a histogram would be useful visualization even in the time series case? Can we use it all the time?
    3. Introduce density estimation: You have already been doing it with histograms.
    4. Some details about density estimation: meaning of the formula, kernel function, bandwidth choice
    5. A preview of how to choose the bandwidth (at least when thinking about the histogram as a density estimator)
    6. Bart Simpson density: Check page 2 of these notes. If interested, you can look into the theoretical details of density estimation.
  2. Some real data examples

# Load dataset (make sure working directory has the file)
# Pay attention to format of original xls 
# Pay attention to the packages
library(readxl)
PSEi <- read_excel("PSEi.xls", skip = 2)
# Get a sense of the data
head(PSEi)
tail(PSEi)
PSEi[is.na(PSEi$Close),]
PSEi_clean <- PSEi[which(!is.na(PSEi$Close)),]
# Transform to xts object for use in quantmod
dates <- as.Date(PSEi_clean$Date)
closing <- PSEi_clean$Close
library(quantmod)
ts <- xts(closing, dates)
# Remove entries which will create issues with monthly return calculations
ts.monthly <- ts['1990-03/2008-06']
ret.monthly <- monthlyReturn(ts.monthly, type="log")
ret.daily <- dailyReturn(ts, type="log", leading = FALSE)
# Using histogram as a density estimator
hist(ret.daily$daily.returns, freq = FALSE)
# Using density() with Gaussian kernel and automatic bandwidth
plot(density(ret.daily$daily.returns))
  1. Notes for V24, notes for V25

  2. Reading assignment for next meeting: Chapter 4 (skip Sections 4.3.3, 4.6 to 4.8), Sections 5.1 to 5.5

  3. Practice exercises: Codes used to generate figures in the book, Chapter 4 Lab Problems 1, 2, 9, 10

Lecture 4, 2024-05-14, face-to-face ONLINE

  1. Work on lognormal distributions and Exercise 8

  2. Discuss the purpose of Chapter 4. Connect to idea of stationarity in Chapter 12.

  3. Reading assignment for next meeting: Chapter 4 (skip Sections 4.3.3, 4.6 to 4.8)

  4. Notes for V24, notes for V25

Lecture 3, 2024-05-10, online

  1. Wrap up Chapter 2

    • R Lab: Section 2.4.3 and related implementation for Exercise 1
    • Exercises in class: 1, 7c, 7d
    • Practice exercises: 2, 3, 4, 5, 6, 7a, 7b
    • For a challenge, try Exercises 9a, 9c, 10, 11 and R Lab Section 2.4.2
    • Advice: When doing the labs and exercises, ask why these were made part of the book.
  2. Code used in class (with slight changes compared to the live demo): Thanks to Carlos Conda for pointing out what could be wrong with my initial live attempt!

# Calculating normal probabilities using R (to the left, see help for others)
pnorm(log(0.99), mean = 0.001, sd = 0.015)
# Modified code from Ruppert and Matteson 
# Changed = to <- 
# How to answer Exercise 1 with a computer alone
set.seed(2012) # Comment out if needed
n <- 1 # Number of holding periods
nsim <- 1e4 # Number of replications
indicator <- numeric(nsim) # Storage
for (i in 1:nsim) 
{
  logr <- rnorm(n,0.001,0.015) # Simulated data on daily log returns, fixed a gross mistake here
  wealth <- c(1000,1000*exp(cumsum(logr))) # initial wealth, plus path of wealth
  indicator[i] <- (wealth[(n+1)] <= 990) # check final wealth whether it is below threshold
}
mean(indicator) # estimate of the exact probability that final wealth is below 990 dollars
  1. Reading assignment for next meeting: Chapter 4 (skip Sections 4.3.3, 4.6 to 4.8)

  2. Notes for V24, notes for V25

Lecture 2, 2024-05-07, face-to-face ONLINE

  1. Continue Chapter 2

    1. Returns in various guises
    2. Why bother with log returns? When are they most appropriate?
    3. What is the point of computing \(k\)-period log-returns? Why obtain its distribution?
    4. Connection to random walks
  2. Reading assignment for next meeting: Chapter 2, Chapter 4 (skip Sections 4.6 to 4.8)

  3. Notes for V24, notes for V25

Lecture 1, 2024-05-03, online

  1. Course administration:

    • Deadline for dropping course: May 8 with 90% refund, May 15 with 50% refund, May 29 with no refund
    • Deadline for withdrawal from course: May 30 to June 29 with no refund
  2. Advice:

    1. Forget what you know about study habits.
    2. How to write an email
  3. Broad sense of what financial econometrics looks like about 10 years ago

    1. Op-ed at the Business Times
    2. Interview with Eric Ghysels
  4. Why study returns? How to compute returns? Why have a model for the distribution of returns?

  5. Reading assignment for next meeting: Chapter 2

  6. Notes for V24, notes for V25