This is an R HTML document. When you click the Knit HTML button a web page will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

# Load necessary libraries
library(tseries)
## Registered S3 method overwritten by 'quantmod':
##   method            from
##   as.zoo.data.frame zoo
library(nlts)
## Loading required package: locfit
## locfit 1.5-9.7      2023-01-02
## Loading required package: acepack
library(POT)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(lubridate)
## 
## Attaching package: 'lubridate'
## The following objects are masked from 'package:base':
## 
##     date, intersect, setdiff, union
library(forecast)
library(rugarch)
## Loading required package: parallel
## 
## Attaching package: 'rugarch'
## The following object is masked from 'package:stats':
## 
##     sigma
library(ggplot2)
library(stats4)
library(lmtest)
## Loading required package: zoo
## 
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
## 
##     as.Date, as.Date.numeric
library(FinTS)
## 
## Attaching package: 'FinTS'
## The following object is masked from 'package:forecast':
## 
##     Acf
library(moments)  # Load the moments package

# Load data
url <- "https://fred.stlouisfed.org/graph/fredgraph.csv?bgcolor=%23e1e9f0&chart_type=line&drp=0&fo=open%20sans&graph_bgcolor=%23ffffff&height=450&mode=fred&recession_bars=on&txtcolor=%23444444&ts=12&tts=12&width=1168&nt=0&thu=0&trc=0&show_legend=yes&show_axis_titles=yes&show_tooltip=yes&id=DEXUSEU&scale=left&cosd=1997-01-01&coed=2023-04-24&line_color=%234572a7&link_values=false&line_style=solid&mark_type=none&mw=3&lw=2&ost=-99999&oet=99999&mma=0&fml=a&fq=Daily&fam=avg&fgst=lin&fgsnd=2020-02-01&line_index=1&transformation=lin&vintage_date=2021-09-08&revision_date=2021-09-08&nd=1997-01-01"
data <- read.csv(url, stringsAsFactors = FALSE)
colnames(data) <- c("DATE", "EXCHANGE_RATE")

# Convert the 'EXCHANGE_RATE' column to a numeric data type and take the log of the data
data$EXCHANGE_RATE <- as.numeric(data$EXCHANGE_RATE)
## Warning: NAs introduced by coercion
data$log_returns <- c(NA, diff(log(data$EXCHANGE_RATE)))

# Filter data to include only Wednesdays
data$DATE <- as.Date(data$DATE)
wednesday_data <- data[weekdays(data$DATE) == "Wednesday",]

# Drop missing values
wednesday_data <- na.omit(wednesday_data)

# Standardize the data
wednesday_data$std_returns <- wednesday_data$log_returns / sd(wednesday_data$log_returns)



# (1) Probabilistic Features of the Exchange Rate Data

# (2) Standardized Series Plots
ggplot(wednesday_data, aes(x=DATE, y=std_returns)) +
  geom_line() +
  ylab("Standardized Log Returns") +
  ggtitle("Standardized Series Plots")
plot of chunk unnamed-chunk-1
# (1) Probabilistic Features of the Exchange Rate Data

# Autocorrelation function (ACF) and partial autocorrelation function (PACF) plots
par(mfrow=c(2,1))
acf(wednesday_data$log_returns, main="ACF of Log Returns")
pacf(wednesday_data$log_returns, main="PACF of Log Returns")
plot of chunk unnamed-chunk-1
# Scatter plot matrix
pairs(wednesday_data[,c("log_returns","EXCHANGE_RATE")])
plot of chunk unnamed-chunk-1
# Bivariate density estimate
ggplot(wednesday_data, aes(x=log_returns, y=EXCHANGE_RATE)) +
  geom_density_2d() +
  ggtitle("Bivariate Density Estimate")
plot of chunk unnamed-chunk-1
# (2) Standardized Series Plots
ggplot(wednesday_data, aes(x=DATE, y=std_returns)) +
  geom_line() +
  ylab("Standardized Log Returns") +
  ggtitle("Standardized Series Plots")
plot of chunk unnamed-chunk-1
# (3) Table I: Sample Statistics
stats_table <- data.frame(
  Mean = mean(wednesday_data$log_returns),
  Std.Dev = sd(wednesday_data$log_returns),
  Skewness = skewness(wednesday_data$log_returns),
  Kurtosis = kurtosis(wednesday_data$log_returns)
)
rownames(stats_table) <- "Log Returns"
print(stats_table)
##                      Mean     Std.Dev  Skewness Kurtosis
## Log Returns -1.048127e-05 0.005645591 0.3197191 6.043201
# (1) Probabilistic Features of the Exchange Rate Data

# Autocorrelation function (ACF) and partial autocorrelation function (PACF) plots
# These plots help to show that the series are stationary
par(mfrow=c(2,1))
acf(wednesday_data$log_returns, main="ACF of Log Returns")
pacf(wednesday_data$log_returns, main="PACF of Log Returns")
plot of chunk unnamed-chunk-1
# Scatter plot matrix
# This plot helps to show that the series exhibit non-linear temporal dependence
pairs(wednesday_data[,c("log_returns","EXCHANGE_RATE")])
plot of chunk unnamed-chunk-1
# Bivariate density estimate
# This plot helps to show that the series exhibit non-linear temporal dependence
ggplot(wednesday_data, aes(x=log_returns, y=EXCHANGE_RATE)) +
  geom_density_2d() +
  ggtitle("Bivariate Density Estimate")
plot of chunk unnamed-chunk-1
# (2) Standardized Series Plots
# This plot shows the standardized time series graph of the log returns
ggplot(wednesday_data, aes(x=DATE, y=std_returns)) +
  geom_line() +
  ylab("Standardized Log Returns") +
  ggtitle("Standardized Series Plots")
plot of chunk unnamed-chunk-1
# (3) Table I: Sample Statistics
# This table shows the sample mean, standard deviation, skewness, and kurtosis coefficients of the series
stats_table <- data.frame(
  Mean = mean(wednesday_data$log_returns),
  Std.Dev = sd(wednesday_data$log_returns),
  Skewness = skewness(wednesday_data$log_returns),
  Kurtosis = kurtosis(wednesday_data$log_returns)
)
rownames(stats_table) <- "Log Returns"
print(stats_table)
##                      Mean     Std.Dev  Skewness Kurtosis
## Log Returns -1.048127e-05 0.005645591 0.3197191 6.043201
# (4) Bivariate Density Estimates
## Scatter plot matrix
# This plot shows the joint distribution of two variables
pairs(wednesday_data[,c("log_returns", "std_returns")])
plot of chunk unnamed-chunk-1
## 3D surface plot (optional)
library(plotly)  # Install and load the plotly package
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
fig <- plot_ly(wednesday_data, x = ~log_returns, y = ~std_returns, z = ~EXCHANGE_RATE, type = "scatter3d", mode = "markers", marker = list(size = 3))
fig
## Error in loadNamespace(name): there is no package called 'webshot'
# (5) Histogram and normal probability plot
# These plots help to show that the series are leptokurtic
par(mfrow=c(1,2))
hist(wednesday_data$log_returns, main="Histogram of Log Returns", xlab="Log Returns", freq=FALSE)
qqnorm(wednesday_data$log_returns, main="Normal Probability Plot")
qqline(wednesday_data$log_returns)
plot of chunk unnamed-chunk-1

You can also embed plots, for example:

plot(cars)
plot of chunk unnamed-chunk-2