christophsax / seasonalbook.content

https://christophsax.github.io/seasonalbook.content/
1 stars 0 forks source link

Add Case Study for trading days chapter #20

Closed andreranza closed 7 months ago

andreranza commented 7 months ago

Currently, using cpi_const and td1coef happens to be significant. I'll continue the search, so this is still WIP, and see whether I can find something where the effect is even more relevant. I'll make sure to comment later when I finish the search. However, @christophsax, since there's not much time this morning, you might be already happy with this to elaborate something on so I am putting this out early.

library(cbar.sa)
library(seasonal)
#> 
#> Attaching package: 'seasonal'
#> The following object is masked from 'package:cbar.sa':
#> 
#>     cpi

m0 <- seas(
  x = cpi_const,
  regression.variables = c("const", "ls2009.1"),
  arima.model = "(1 1 0)",
  regression.aictest = NULL,
  outlier = NULL,
  transform.function = "none"
)
#> Model used in SEATS is different: (0 1 1)
summary(m0)
#> 
#> Call:
#> seas(x = cpi_const, transform.function = "none", regression.aictest = NULL, 
#>     outlier = NULL, regression.variables = c("const", "ls2009.1"), 
#>     arima.model = "(1 1 0)")
#> 
#> Coefficients:
#>                   Estimate Std. Error z value Pr(>|z|)    
#> Constant            0.7068     0.1674   4.224 2.40e-05 ***
#> LS2009.1           -3.5364     0.8613  -4.106 4.02e-05 ***
#> AR-Nonseasonal-01   0.3144     0.1229   2.558   0.0105 *  
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> SEATS adj.  ARIMA: (1 1 0)  Obs.: 62  Transform: none
#> AICc:   169, BIC: 176.8  QS (no seasonality in final):0.7392  
#> Box-Ljung (no autocorr.): 11.86   Shapiro (normality): 0.9754  
#> Messages generated by X-13:
#> Notes:
#> - Model used for SEATS decomposition is different from the model
#>   estimated in the regARIMA modeling module of X-13ARIMA-SEATS.
m1 <- seas(
  x = cpi_const,
  regression.variables = c("const", "td1coef", "ls2009.1"), 
  arima.model = "(1 1 0)",
  regression.aictest = NULL,
  outlier = NULL,
  transform.function = "none"
)
#> Model used in SEATS is different: (0 1 1)
summary(m1)
#> 
#> Call:
#> seas(x = cpi_const, transform.function = "none", regression.aictest = NULL, 
#>     outlier = NULL, regression.variables = c("const", "td1coef", 
#>         "ls2009.1"), arima.model = "(1 1 0)")
#> 
#> Coefficients:
#>                   Estimate Std. Error z value Pr(>|z|)    
#> Constant            0.7050     0.1736   4.062 4.86e-05 ***
#> Weekday             0.1262     0.0436   2.896  0.00379 ** 
#> Leap Year          -0.5241     0.2943  -1.781  0.07491 .  
#> LS2009.1           -3.3119     0.7863  -4.212 2.53e-05 ***
#> AR-Nonseasonal-01   0.3927     0.1210   3.245  0.00117 ** 
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> SEATS adj.  ARIMA: (1 1 0)  Obs.: 62  Transform: none
#> AICc:   164, BIC: 175.1  QS (no seasonality in final):0.423  
#> Box-Ljung (no autocorr.): 12.95   Shapiro (normality): 0.9701  
#> Messages generated by X-13:
#> Notes:
#> - Model used for SEATS decomposition is different from the model
#>   estimated in the regARIMA modeling module of X-13ARIMA-SEATS.

Created on 2024-01-18 with reprex v2.0.2

andreranza commented 7 months ago
library(cbar.sa)
library(seasonal)
#> 
#> Attaching package: 'seasonal'
#> The following object is masked from 'package:cbar.sa':
#> 
#>     cpi

plot(budg_exp)

plot(decompose(budg_exp))

monthplot(budg_exp)


m0 <- seas(
  x = budg_exp,
  regression.variables = c("const", "ao2017.4"),
  arima.model = "(2 0 0)(0 1 0)",
  regression.aictest = NULL,
  outlier = NULL,
  transform.function = "none"
)
#> Model used in SEATS is different: (1 0 1)(0 1 0)

summary(m0)
#> 
#> Call:
#> seas(x = budg_exp, transform.function = "none", regression.aictest = NULL, 
#>     outlier = NULL, regression.variables = c("const", "ao2017.4"), 
#>     arima.model = "(2 0 0)(0 1 0)")
#> 
#> Coefficients:
#>                     Estimate Std. Error z value Pr(>|z|)    
#> Constant            387.7303   132.6318   2.923  0.00346 ** 
#> AO2017.4          -2167.5414   471.7620  -4.595 4.34e-06 ***
#> AR-Nonseasonal-01     0.1612     0.1291   1.248  0.21192    
#> AR-Nonseasonal-02     0.1691     0.1301   1.300  0.19373    
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> SEATS adj.  ARIMA: (2 0 0)(0 1 0)  Obs.: 62  Transform: none
#> AICc: 933.3, BIC: 942.4  QS (no seasonality in final):    0  
#> Box-Ljung (no autocorr.): 26.16   Shapiro (normality): 0.9913  
#> Messages generated by X-13:
#> Notes:
#> - Model used for SEATS decomposition is different from the model
#>   estimated in the regARIMA modeling module of X-13ARIMA-SEATS.

m1 <- seas(
  x = budg_exp,
  regression.variables = c("const", "td", "ao2017.4"),
  arima.model = "(2 0 0)(0 1 0)",
  regression.aictest = NULL,
  outlier = NULL,
  transform.function = "none"
)

summary(m1)
#> 
#> Call:
#> seas(x = budg_exp, transform.function = "none", regression.aictest = NULL, 
#>     outlier = NULL, regression.variables = c("const", "td", "ao2017.4"), 
#>     arima.model = "(2 0 0)(0 1 0)")
#> 
#> Coefficients:
#>                     Estimate Std. Error z value Pr(>|z|)    
#> Constant            350.3435   149.1736   2.349  0.01885 *  
#> Mon                -250.0954   124.1819  -2.014  0.04402 *  
#> Tue                 -21.8921   149.7580  -0.146  0.88378    
#> Wed                -312.1866   123.9575  -2.518  0.01179 *  
#> Thu                -258.8729   120.8140  -2.143  0.03213 *  
#> Fri                 337.1366   123.3984   2.732  0.00629 ** 
#> Sat                 207.2222   140.6061   1.474  0.14054    
#> Leap Year          -601.6833   195.6765  -3.075  0.00211 ** 
#> AO2017.4          -2519.8592   442.7452  -5.691 1.26e-08 ***
#> AR-Nonseasonal-01     0.2886     0.1271   2.270  0.02322 *  
#> AR-Nonseasonal-02     0.2529     0.1276   1.982  0.04745 *  
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> SEATS adj.  ARIMA: (2 0 0)(0 1 0)  Obs.: 62  Transform: none
#> AICc: 924.6, BIC: 942.4  QS (no seasonality in final):    0  
#> Box-Ljung (no autocorr.): 13.98   Shapiro (normality): 0.983

m2 <- seas(
  x = budg_exp,
  regression.variables = c("const", "td1coef", "ao2017.4"),
  arima.model = "(2 0 0)(0 1 0)",
  regression.aictest = NULL,
  outlier = NULL,
  transform.function = "none"
)
summary(m2)
#> 
#> Call:
#> seas(x = budg_exp, transform.function = "none", regression.aictest = NULL, 
#>     outlier = NULL, regression.variables = c("const", "td1coef", 
#>         "ao2017.4"), arima.model = "(2 0 0)(0 1 0)")
#> 
#> Coefficients:
#>                     Estimate Std. Error z value Pr(>|z|)    
#> Constant            367.7669   140.4775   2.618  0.00885 ** 
#> Weekday             -63.0671    46.7028  -1.350  0.17689    
#> Leap Year          -700.6442   228.7871  -3.062  0.00220 ** 
#> AO2017.4          -2252.1083   430.7000  -5.229  1.7e-07 ***
#> AR-Nonseasonal-01     0.2288     0.1290   1.773  0.07627 .  
#> AR-Nonseasonal-02     0.1973     0.1305   1.512  0.13061    
#> ---
#> Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> 
#> SEATS adj.  ARIMA: (2 0 0)(0 1 0)  Obs.: 62  Transform: none
#> AICc: 927.7, BIC: 939.9  QS (no seasonality in final):    0  
#> Box-Ljung (no autocorr.):  16.3   Shapiro (normality): 0.9698

Created on 2024-01-18 with reprex v2.0.2

christophsax commented 7 months ago

Merging this