Other: Interrupted TS/ARFIMA/Spectral Analysis

Author

zoo un park

Introduction

Code
library(tidyverse)
library(ggplot2)
library(forecast)
library(astsa) 
library(xts)
library(tseries)
library(fpp2)
library(fma)
library(lubridate)
library(TSstudio)
library(quantmod)
library(tidyquant)
library(plotly)
library(imputeTS)
library(dplyr)
library(reshape2)
library(gridExtra)
library(zoo)
library(knitr)
library(kableExtra)
library(broom)

In economics, financial crises leave clear and lasting impacts across asset markets. When a crisis originates in an economy issuing a major international currency (e.g., USD, JPY, GBP, EUR), its effects tend to be larger than those of crises in smaller economies. This study focuses on how the United States economy affects the South Korean economy, using the 2008 global financial crisis—which began in the United States—as the primary case.

Although there are many factors that can trigger a financial crisis, once it begins, most financial assets typically experience sharp declines for at least one to two years, with effects that can persist for up to a decade. Among South Korean financial assets, the most severely affected during this period was the exchange rate. Historical data show that, following the U.S.-led crisis, the value of the South Korean won depreciated substantially against the U.S. dollar.

The purpose of this section is to treat the 2008 financial crisis as an exogenous shock and examine how it affected the KRW/USD spot exchange rate, as well as to consider how the exchange rate might have evolved had the crisis not occurred.

Time series plot with intervention(2008-08-01)

Code
Start_date <- as.Date("2005-01-03")
End_date   <- as.Date("2015-12-31")

kr <- read.csv("../data/fx rate/kor.csv")

kr <- kr %>%
  transmute(
    Date = as.Date(observation_date),
    krw  = DEXKOUS,
    usd  = 1 / DEXKOUS
  ) %>%
  filter(!is.na(Date)) %>%
  arrange(Date) %>%
  
  distinct(Date, .keep_all = TRUE) %>%
  filter(Date >= Start_date & Date <= End_date) %>%
  complete(Date = seq(Start_date,End_date, by = "day")) %>%
  fill(krw, usd, .direction = "down")

kr$Date <- as.Date(kr$Date)

intervention_date <- as.Date("2008-08-01")
max_y <- max(kr$krw, na.rm = TRUE)

fig <- plot_ly(
  data = kr,
  x = ~Date, y = ~krw,
  name = "KRW-USD exchange spot rate",
  type = "scatter", mode = "lines",
  hovertemplate = paste(
    "Date: %{x|%b %Y}<br>",
    "KRW-USD exchange spot rate : ₩%{y:,.2f}<extra></extra>"
  )
) %>%
  layout(
    title = "KRW-USD exchange spot rate with 2008 financial crisis",
    xaxis = list(title = "Date"),
    yaxis = list(title = "KRW-USD exchange spot rate", rangemode = "tozero"),
    shapes = list(
      list(
        type = "line",
        x0 = intervention_date, x1 = intervention_date,
        y0 = 0, y1 = max_y,
        line = list(color = "red", dash = "dash", width = 2),
        xref = "x", yref = "y"
      )
    ),
    annotations = list(
      list(
        x = intervention_date,
        y = max_y * 0.95,
        text = "2008 Financial crisis",
        showarrow = TRUE,
        arrowhead = 2,
        ax = 0, ay = -40,
        font = list(size = 12, color = "red")
      )
    ),
    legend = list(orientation = "h", x = 0, y = -0.15)
  )

fig

The time series plot shows a clear change in trend before and after the 2008 financial crisis. Prior to 2008, the KRW exchange rate was relatively stable. However, once the crisis began, the KRW/USD rate surged sharply.

Interupted Time series data preparation

Code
krw <- kr %>%
  arrange(Date) %>%                         
  filter(Date >= Start_date) %>%          
  transmute(
    Date = Date,
    Y  = krw,                              
    Xt = row_number(),                    
    Zt = if_else(Date < intervention_date,  
                 0L, 1L),
    Pt = 0L
  )

krw$Pt[krw$Date >= intervention_date] <-
  seq_len(sum(krw$Date >= intervention_date))

intervention_index <- which(krw$Date == intervention_date)


one_month_later_date  <- seq(intervention_date, by = "month", length.out = 2)[2]
one_month_index       <- which(krw$Date == one_month_later_date)

d.temp <- bind_rows(
  head(krw, 5),
  krw[(intervention_index - 3):(intervention_index + 3), ],
  krw[(one_month_index - 3):(one_month_index + 3), ],
  tail(krw, 5)
)

d.temp_char <- d.temp %>%
  mutate(
    Date = as.character(Date),
    Y    = round(Y, 2),
    Xt   = as.character(Xt),
    Zt   = as.character(Zt),
    Pt   = as.character(Pt)
  )

kable(d.temp_char,
      caption = "KRW-USD exchange spot rate") %>%
  kable_styling(full_width = FALSE,
                bootstrap_options = c("striped", "hover", "condensed"))
KRW-USD exchange spot rate
Date Y Xt Zt Pt
2005-01-03 1038.00 1 0 0
2005-01-04 1038.00 2 0 0
2005-01-05 1046.30 3 0 0
2005-01-06 1058.00 4 0 0
2005-01-07 1051.00 5 0 0
2008-07-29 1006.00 1304 0 0
2008-07-30 1012.30 1305 0 0
2008-07-31 1011.50 1306 0 0
2008-08-01 1015.75 1307 1 1
2008-08-02 1015.75 1308 1 2
2008-08-03 1015.75 1309 1 3
2008-08-04 1016.75 1310 1 4
2008-08-29 1089.00 1335 1 29
2008-08-30 1089.00 1336 1 30
2008-08-31 1089.00 1337 1 31
2008-09-01 1089.00 1338 1 32
2008-09-02 1134.45 1339 1 33
2008-09-03 1147.90 1340 1 34
2008-09-04 1130.30 1341 1 35
2015-12-27 1167.94 4011 1 2705
2015-12-28 1169.26 4012 1 2706
2015-12-29 1169.26 4013 1 2707
2015-12-30 1177.53 4014 1 2708
2015-12-31 1169.26 4015 1 2709

Interupted Times series model fit

Code
model <- lm(Y ~ Xt + Zt + Pt, data = krw)
summary(model)

Call:
lm(formula = Y ~ Xt + Zt + Pt, data = krw)

Residuals:
    Min      1Q  Median      3Q     Max 
-215.92  -37.51  -13.48   27.88  352.69 

Coefficients:
              Estimate Std. Error t value Pr(>|t|)    
(Intercept)  1.008e+03  3.531e+00 285.501   <2e-16 ***
Xt          -5.418e-02  4.680e-03 -11.576   <2e-16 ***
Zt           2.944e+02  4.295e+00  68.560   <2e-16 ***
Pt          -1.279e-02  4.935e-03  -2.591   0.0096 ** 
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 63.76 on 4011 degrees of freedom
Multiple R-squared:  0.6689,    Adjusted R-squared:  0.6687 
F-statistic:  2702 on 3 and 4011 DF,  p-value: < 2.2e-16

Regression model summary

Code
tab_fx <- tidy(model) %>% 
  mutate(
    Term = recode(term,
      "(Intercept)" = "Constant",
      "Xt"          = "Time",
      "Zt"          = "Financial Crisis Indicator",
      "Pt"          = "Time Since Crisis"
    ),
    stars = case_when(
      p.value < 0.001 ~ "***",
      p.value < 0.01  ~ "**",
      p.value < 0.05  ~ "*",
      TRUE            ~ ""
    ),
    `Estimate (SE)` = sprintf("%.2f%s (%.2f)", estimate, stars, std.error)
  ) %>%
  dplyr::select(Term, `Estimate (SE)`)

kable(
  tab_fx,
  caption = "Regression Summary for KRW-USD Exchange Rate (Financial Crisis)"
) %>%
  kable_styling(
    full_width = FALSE,
    bootstrap_options = c("striped", "hover", "condensed")
  )
Regression Summary for KRW-USD Exchange Rate (Financial Crisis)
Term Estimate (SE)
Constant 1008.05*** (3.53)
Time -0.05*** (0.00)
Financial Crisis Indicator 294.44*** (4.29)
Time Since Crisis -0.01** (0.00)

The regression model summary shows that all coefficients have very small p-values, indicating that each of them is statistically significant. This implies that the model meaningfully captures both the underlying trend in the KRW–USD spot exchange rate and the impact of the 2008 financial crisis.

  • The Time coefficient measures the pre-crisis trend in the KRW–USD exchange rate. It suggests that, for each day before the 2008 crisis, the KRW–USD spot rate decreased by approximately ₩0.05, indicating a modest appreciating trend of the Korean won against the U.S. dollar.

  • The financial crisis indicator (Zₜ) captures the immediate effect of the 2008 financial crisis. Its coefficient of about ₩294.44 implies that, at the onset of the crisis, the KRW–USD spot rate jumped upward by roughly ₩294.44, reflecting a sharp depreciation of the Korean won.

  • The time-since-crisis variable (Pₜ) represents the change in trend after the crisis. Its coefficient of about ₩−0.01 indicates that, following the crisis, the KRW–USD spot rate began to decrease by an additional ₩0.01 per day relative to the pre-crisis trend, consistent with a gradual recovery after the initial shock.

  • The constant term represents the estimated level of the KRW–USD spot rate at the start of the sample period, with a value of approximately ₩1,008.50.

Overall, the results suggest that the 2008 financial crisis had a severe and immediate impact on the KRW–USD exchange rate, causing a large one-time depreciation of the Korean won, followed by a slow but steady recovery over time.

Interupted time series plot with trend line

Code
b0 <- coef(model)[["(Intercept)"]]
b1 <- coef(model)[["Xt"]]
b2 <- coef(model)[["Zt"]]
b3 <- coef(model)[["Pt"]]

krw <- krw %>%
  mutate(
    fitted       = fitted(model),
    trend_pre    = b0 + b1 * Xt,                     
    trend_post   = b0 + b1 * Xt + b2 * Zt + b3 * Pt  
  )

y_min <- min(krw$Y, na.rm = TRUE)
y_max <- max(krw$Y, na.rm = TRUE)

fig <- plot_ly(krw, x = ~Date) %>%

  add_lines(
    y = ~Y,
    name = "Observed KRW/USD",
    mode = "lines",
    hovertemplate = paste(
      "Date: %{x|%Y-%m-%d}<br>",
      "Observed: ₩%{y:,.2f}<extra></extra>"
    )
  ) %>%
 
  add_lines(
    y = ~trend_pre,
    name = "Pre-intervention trend (extended)",
    line = list(dash = "dot"),
    hovertemplate = paste(
      "Date: %{x|%Y-%m-%d}<br>",
      "Pre trend (no crisis): ₩%{y:,.2f}<extra></extra>"
    )
  ) %>%
  add_lines(
    y = ~trend_post,
    name = "Post-intervention trend",
    line = list(dash = "solid"),
    hovertemplate = paste(
      "Date: %{x|%Y-%m-%d}<br>",
      "Post trend (with crisis): ₩%{y:,.2f}<extra></extra>"
    )
  ) %>%
  layout(
    title = "Interrupted time series for KRW-USD Exchange Rate",
    xaxis = list(title = "Date"),
    yaxis = list(title = "KRW per USD"),
    shapes = list(
      list(
        type = "line",
        x0 = intervention_date, x1 = intervention_date,
        y0 = y_min,             y1 = y_max,
        line = list(color = "red", dash = "dash", width = 2),
        xref = "x", yref = "y"
      )
    ),
    annotations = list(
      list(
        x = intervention_date,
        y = y_max,
        text = "Intervention",
        showarrow = TRUE,
        arrowhead = 2,
        ax = 0, ay = -40,
        font = list(size = 12, color = "red")
      )
    ),
    legend = list(orientation = "h", x = 0, y = -0.15)
  )

fig

This time series plot shows an interrupted time series for the KRW–USD exchange rate (KRW per USD), with the intervention marked by the red vertical line. Before the intervention (around 2005–2007), the exchange rate followed a gradually declining trend, moving from roughly 1,000 KRW per USD toward the mid-900s. This corresponds to a slow appreciation of the Korean won.

At the intervention date, the observed series exhibits a sharp upward jump, with the exchange rate spiking well above 1,500 KRW per USD. Compared with the extended pre-intervention trend (orange dotted line), this represents a large positive level shift in the exchange rate, i.e. a sudden and sizable depreciation of the won. In the post-intervention period, the exchange rate falls back from its peak but does not return to the pre-crisis path. Instead, the post-intervention trend (green line) shows a much higher average level and a flatter downward slope than the counterfactual path implied by the pre-intervention trend. While there is some gradual appreciation, the exchange rate stabilizes around 1,100 KRW per USD rather than converging toward the lower levels implied by the orange line.

predicted and counterfactual trend plot

Code
krw$Y_hat <- predict(model, newdata = krw)

datanew <- data.frame(
  Xt = krw$Xt,
  Zt = 0,
  Pt = 0
)
krw$Y_counterfactual <- predict(model, newdata = datanew)

intervention_index <- which(krw$Date == intervention_date)
y_min <- min(krw$Y, krw$Y_hat, krw$Y_counterfactual, na.rm = TRUE)
y_max <- max(krw$Y, krw$Y_hat, krw$Y_counterfactual, na.rm = TRUE)


library(plotly)

fig <- plot_ly()

fig <- fig %>%
  add_markers(
    data = krw,
    x = ~Date, y = ~Y,
    name = "Observed KRW/USD",
    marker = list(color = "gray", opacity = 0.5),
    hovertemplate = paste(
      "Date: %{x|%Y-%m-%d}<br>",
      "Observed: ₩%{y:,.2f}<extra></extra>"
    )
  )

fig <- fig %>%
  add_lines(
    x = krw$Date[1:(intervention_index - 1)],
    y = krw$Y_hat[1:(intervention_index - 1)],
    name = "Predicted (Pre-intervention)",
    line = list(color = "purple"),
    hovertemplate = paste(
      "Date: %{x|%Y-%m-%d}<br>",
      "Predicted (pre): ₩%{y:,.2f}<extra></extra>"
    )
  )

fig <- fig %>%
  add_lines(
    x = krw$Date[intervention_index:nrow(krw)],
    y = krw$Y_hat[intervention_index:nrow(krw)],
    name = "Predicted (Post-intervention)",
    line = list(color = "skyblue", dash = "solid"),
    hovertemplate = paste(
      "Date: %{x|%Y-%m-%d}<br>",
      "Predicted (post): ₩%{y:,.2f}<extra></extra>"
    )
  )

fig <- fig %>%
  add_lines(
    x = krw$Date[intervention_index:nrow(krw)],
    y = krw$Y_counterfactual[intervention_index:nrow(krw)],
    name = "Counterfactual (No crisis)",
    line = list(color = "orange", dash = "dash"),
    hovertemplate = paste(
      "Date: %{x|%Y-%m-%d}<br>",
      "Counterfactual: ₩%{y:,.2f}<extra></extra>"
    )
  )

fig <- fig %>%
  layout(
    title = "KRW-USD Exchange Rate: Predicted vs. Counterfactual(2008 financial crisis)",
    xaxis = list(title = "Date"),
    yaxis = list(title = "KRW per USD"),
    legend = list(x = 0.01, y = 0.99),
    shapes = list(
      list(
        type = "line",
        x0 = intervention_date, x1 = intervention_date,
        y0 = y_min, y1 = y_max,
        line = list(color = "firebrick", dash = "dot"),
        xref = "x", yref = "y"
      )
    ),
    annotations = list(
      list(
        x = intervention_date,
        y = y_max,
        text = "Intervention",
        showarrow = TRUE,
        arrowhead = 2,
        ax = 0, ay = -40,
        font = list(size = 12, color = "firebrick")
      )
    )
  )

fig

This plot compares the observed KRW–USD exchange rate with the fitted paths from an interrupted time-series model and a counterfactual “no-crisis” scenario around the 2008 financial crisis. The pre-crisis fitted trend (purple) slopes gently downward, implying a gradual appreciation of the won, while the counterfactual extension of this trend (orange dashed) suggests the exchange rate would have continued to fall toward levels below 900 KRW per USD. In contrast, the post-crisis predicted path (blue) starts from a much higher level of around 1,200–1,250 KRW per USD and declines only slowly, closely tracking the actual data. This indicates that the 2008 crisis caused both a sharp immediate depreciation of the won (a large upward level shift) and a persistent change in the underlying trend, leaving the KRW–USD rate on a higher, more weak-won trajectory than would have been expected in the absence of the crisis.

delayed effect

Code
library(dplyr)
library(plotly)


krw$Y_hat <- predict(model, newdata = krw)

datanew <- data.frame(
  Xt = krw$Xt,
  Zt = 0,
  Pt = 0
)
krw$Y_counterfactual <- predict(model, newdata = datanew)


intervention_index <- which(krw$Date == intervention_date)


delayed_index <- intervention_index +180
delayed_index <- min(delayed_index, nrow(krw))   
delayed_effect_date <- krw$Date[delayed_index]


y_min <- min(krw$Y, krw$Y_hat, krw$Y_counterfactual, na.rm = TRUE)
y_max <- max(krw$Y, krw$Y_hat, krw$Y_counterfactual, na.rm = TRUE)


fig <- plot_ly()

fig <- fig %>%
  add_markers(
    data = krw,
    x = ~Date, y = ~Y,
    name = "Observed KRW/USD",
    marker = list(color = "gray", opacity = 0.5),
    hovertemplate = paste(
      "Date: %{x|%Y-%m-%d}<br>",
      "Observed: ₩%{y:,.2f}<extra></extra>"
    )
  )

fig <- fig %>%
  add_lines(
    x = krw$Date[1:(intervention_index - 1)],
    y = krw$Y_hat[1:(intervention_index - 1)],
    name = "Predicted (Pre-crisis)",
    line = list(color = "dodgerblue"),
    hovertemplate = paste(
      "Date: %{x|%Y-%m-%d}<br>",
      "Predicted (pre): ₩%{y:,.2f}<extra></extra>"
    )
  )

fig <- fig %>%
  add_lines(
    x = krw$Date[intervention_index:nrow(krw)],
    y = krw$Y_hat[intervention_index:nrow(krw)],
    name = "Predicted (Post-crisis)",
    line = list(color = "dodgerblue", dash = "solid"),
    hovertemplate = paste(
      "Date: %{x|%Y-%m-%d}<br>",
      "Predicted (post): ₩%{y:,.2f}<extra></extra>"
    )
  )

fig <- fig %>%
  add_lines(
    x = krw$Date[intervention_index:nrow(krw)],
    y = krw$Y_counterfactual[intervention_index:nrow(krw)],
    name = "Counterfactual (No crisis)",
    line = list(color = "darkorange", dash = "dash"),
    hovertemplate = paste(
      "Date: %{x|%Y-%m-%d}<br>",
      "Counterfactual: ₩%{y:,.2f}<extra></extra>"
    )
  )

fig <- fig %>%
  layout(
    title = "KRW-USD Exchange Rate: Predicted vs Counterfactual (Delayed Effects)",
    xaxis = list(title = "Date"),
    yaxis = list(title = "KRW per USD"),
    legend = list(x = 0.01, y = 0.99),
    shapes = list(
      list(
        type = "line",
        x0 = intervention_date, x1 = intervention_date,
        y0 = y_min, y1 = y_max,
        line = list(color = "red", dash = "dot"),
        xref = "x", yref = "y"
      ),
      list(
        type = "line",
        x0 = delayed_effect_date, x1 = delayed_effect_date,
        y0 = y_min, y1 = y_max,
        line = list(color = "green", dash = "dot"),
        xref = "x", yref = "y"
      )
    ),
    annotations = list(

      list(
        x = intervention_date,
        y = y_max * 1.02,               
        text = "Financial Crisis",
        showarrow = TRUE,
        arrowhead = 2,
        arrowsize = 1,                  
        arrowwidth = 1.5,               
        ax = -20, ay = -40,                
        font = list(size = 11, color = "red")
      ),
      list(
        x = delayed_effect_date,
        y = y_max * 0.99,               
        text = "Delayed Effect",
        showarrow = TRUE,
        arrowhead = 2,
        arrowsize = 1,
        arrowwidth = 1.5,
        ax = 20, ay = -30,
        font = list(size = 11, color = "purple")
      )
    )
  )

fig

This plot shows how the delayed effect changes the interpretation of the 2008 financial crisis on the KRW–USD exchange rate. The pre-crisis prediction (blue line) continues the gently declining trend of the won’s appreciation up to the crisis date (red dashed line), and its counterfactual extension (orange dashed line) shows that, in the absence of a crisis, the exchange rate would likely have kept falling toward the mid-800 KRW range by the mid-2010s. In reality, however, the observed series (grey dots) rises sharply only after the crisis date, with the largest depreciation occurring around the “delayed effect” date (green dashed line). The post-crisis prediction that incorporates this delayed effect tracks this pattern by shifting the level of the exchange rate upward. This suggests that the financial crisis did not instantaneously change the exchange-rate regime, but instead led, with some delay, to a persistent move to a weaker-won trajectory relative to the no-crisis counterfactual.