ISYE 6402 Homework Spring 2024
Part 1: EXT FUNDS Gold Price Exchange
Background
In this problem, we will study fluctuations in The NEXT FUNDS Gold Price Exchange Traded Fund that is a
type of investment fund that aims to track the performance of gold prices. By investing in this fund, investors
can gain exposure to the price movements of gold without having to physically own the metal. The fund holds
physical gold as its underlying asset, and its value is based on the market price of gold. You will use the file
Fund Prices Data.csv, where monthly prices are from January 2010 to Dec 2022.
Instructions on reading the data
To read the data in R, save the file in your working directory (make sure you have changed the directory if
different from the R working directory) and read the data using the R function read.csv()
You will perform the analysis and modelling on the Close data column.
#Here are the libraries you will need:
library(mgcv)
library(TSA)
library(dynlm)
library(ggplot2)
library(reshape2)
library(greybox)
library(mlr)
library(mgcv)
library(lubridate)
library(dplyr)
library(data.table)
#Run the following code to prepare the data for analysis:
data<-read.csv("Fund Prices Data.csv")
Question 1a: Exploratory Data Analysis
Plot the Time Series and the ACF plot for the series. Comment on the stationarity of both time series based on
these plots. Which (if any) stationarity assumptions are violated for the time series?
fp <- ts(data$Close, start = 2010, freq = 12)
plot(fp,col="purple",lwd=1.5,ylab="Fund Price",main="FP Time Series Plot")
,acf(fp,lag.max=12*12,col="purple",lwd=1.5,ylab="Fund Price",main="FP ACF Plot")
, Response: 1a
From the time series plot, we cannot identify a seasonal pattern. We can see a clear trend that violates the
constant mean assumption from the plot and ACF plot.
Question 1b: Trend Estimation
Fit the following trend estimation models:
Moving average
Parametric quadratic polynomial
Local Polynomial
Splines
Overlay the fitted values derived from each trend estimation model on the corresponding data. Comment on
the effectiveness of each model to estimate the trend for the series.
time.pts = c(1:length(fp))
time.pts = c(time.pts - min(time.pts))/max(time.pts)
# Moving average
mav.fp<-ksmooth(time.pts,fp,kernel="box")
tsmav.fp<-ts(mav.fp$y,frequency=12,start=2010)
#Local Polynomial
loc.fp = loess(fp~time.pts)
fit.loc.fp = ts(fitted(loc.fp),frequency=12,start=2010)
# Splines
spl.fp<-gam(fp~s(time.pts))
fit.spl<-ts(fitted(spl.fp),frequency=12,start=2010)
#Parametric quadratic polynomial
x1 <- time.pts
x2 <- time.pts^2
para.model <- lm(fp ~ x1 + x2)
para.fit <- ts(fitted(para.model), frequency=12,start=2010)
ts.plot(fp,ylab="Fund Prices",main="Fund Prices with Trend Estimations")
lines(tsmav.fp,lwd=2,col="plum")
lines(fit.loc.fp,lwd=2,col="purple")
lines(fit.spl,lwd=2,col="green")
lines(para.fit,lwd=2,col="blue")
legend(x=2010,y=6000,legend=c("Moving Average","LOESS", "Splines", "Parametric quadratic"),
lty = 1, lwd=2, col=c("plum","purple", "green", "blue"))
Part 1: EXT FUNDS Gold Price Exchange
Background
In this problem, we will study fluctuations in The NEXT FUNDS Gold Price Exchange Traded Fund that is a
type of investment fund that aims to track the performance of gold prices. By investing in this fund, investors
can gain exposure to the price movements of gold without having to physically own the metal. The fund holds
physical gold as its underlying asset, and its value is based on the market price of gold. You will use the file
Fund Prices Data.csv, where monthly prices are from January 2010 to Dec 2022.
Instructions on reading the data
To read the data in R, save the file in your working directory (make sure you have changed the directory if
different from the R working directory) and read the data using the R function read.csv()
You will perform the analysis and modelling on the Close data column.
#Here are the libraries you will need:
library(mgcv)
library(TSA)
library(dynlm)
library(ggplot2)
library(reshape2)
library(greybox)
library(mlr)
library(mgcv)
library(lubridate)
library(dplyr)
library(data.table)
#Run the following code to prepare the data for analysis:
data<-read.csv("Fund Prices Data.csv")
Question 1a: Exploratory Data Analysis
Plot the Time Series and the ACF plot for the series. Comment on the stationarity of both time series based on
these plots. Which (if any) stationarity assumptions are violated for the time series?
fp <- ts(data$Close, start = 2010, freq = 12)
plot(fp,col="purple",lwd=1.5,ylab="Fund Price",main="FP Time Series Plot")
,acf(fp,lag.max=12*12,col="purple",lwd=1.5,ylab="Fund Price",main="FP ACF Plot")
, Response: 1a
From the time series plot, we cannot identify a seasonal pattern. We can see a clear trend that violates the
constant mean assumption from the plot and ACF plot.
Question 1b: Trend Estimation
Fit the following trend estimation models:
Moving average
Parametric quadratic polynomial
Local Polynomial
Splines
Overlay the fitted values derived from each trend estimation model on the corresponding data. Comment on
the effectiveness of each model to estimate the trend for the series.
time.pts = c(1:length(fp))
time.pts = c(time.pts - min(time.pts))/max(time.pts)
# Moving average
mav.fp<-ksmooth(time.pts,fp,kernel="box")
tsmav.fp<-ts(mav.fp$y,frequency=12,start=2010)
#Local Polynomial
loc.fp = loess(fp~time.pts)
fit.loc.fp = ts(fitted(loc.fp),frequency=12,start=2010)
# Splines
spl.fp<-gam(fp~s(time.pts))
fit.spl<-ts(fitted(spl.fp),frequency=12,start=2010)
#Parametric quadratic polynomial
x1 <- time.pts
x2 <- time.pts^2
para.model <- lm(fp ~ x1 + x2)
para.fit <- ts(fitted(para.model), frequency=12,start=2010)
ts.plot(fp,ylab="Fund Prices",main="Fund Prices with Trend Estimations")
lines(tsmav.fp,lwd=2,col="plum")
lines(fit.loc.fp,lwd=2,col="purple")
lines(fit.spl,lwd=2,col="green")
lines(para.fit,lwd=2,col="blue")
legend(x=2010,y=6000,legend=c("Moving Average","LOESS", "Splines", "Parametric quadratic"),
lty = 1, lwd=2, col=c("plum","purple", "green", "blue"))