Skip to contents

This function computes the rolling window AMIM for a given data.table

Usage

AMIM.roll(
  data.table,
  identity.col,
  Date.col,
  rollWindow,
  return.col,
  min.obs,
  max.lag
)

Arguments

data.table

data.table with the data

identity.col

column name of the identity intrument for example the stock ticker

Date.col

column name of the date column with format "YYYY-mm-dd" (for example "2019-12-01")

rollWindow

number of days to compute the AMIM

return.col

column name of the return column

min.obs

minimum number of observations to compute the AMIM

max.lag

maximum number of lags to compute the MIM and then AMIM. The algorithm will select the number of lags that minimize the AIC but the maximum number of lags is limited by this parameter. In case the AIC is zero for the zero lag then the algorithm will estimate an AR(1) model. This is to avoid zero in the MIM and AMIM.

Value

data.table with the MIM, AMIM and the number of lags used to compute the MIM, AMIM, confidence interval (CI), and the number of lags (N).

Examples

library(AMIM)
library(data.table)
data <- AMIM::exampledata # load the example data
AMIM <- AMIM.roll(
  data.table = data, identity.col = "ticker", rollWindow = 60,
  Date.col = "Date", return.col = "RET", min.obs = 30, max.lag = 10
)
#> 
  |                                                                            
  |                                                                      |   0%
  |                                                                            
  |===                                                                   |   4%
  |                                                                            
  |======                                                                |   8%
  |                                                                            
  |=========                                                             |  12%
  |                                                                            
  |============                                                          |  17%
  |                                                                            
  |===============                                                       |  21%
  |                                                                            
  |==================                                                    |  25%
  |                                                                            
  |====================                                                  |  29%
  |                                                                            
  |=======================                                               |  33%
  |                                                                            
  |==========================                                            |  38%
  |                                                                            
  |=============================                                         |  42%
  |                                                                            
  |================================                                      |  46%
  |                                                                            
  |===================================                                   |  50%
  |                                                                            
  |======================================                                |  54%
  |                                                                            
  |=========================================                             |  58%
  |                                                                            
  |============================================                          |  62%
  |                                                                            
  |===============================================                       |  67%
  |                                                                            
  |==================================================                    |  71%
  |                                                                            
  |====================================================                  |  75%
  |                                                                            
  |=======================================================               |  79%
  |                                                                            
  |==========================================================            |  83%
  |                                                                            
  |=============================================================         |  88%
  |                                                                            
  |================================================================      |  92%
  |                                                                            
  |===================================================================   |  96%
  |                                                                            
  |======================================================================| 100%

AMIM[, .SD[(.N - 5):(.N), ], by = ticker] # Last 5 rows of each instrument
#>     ticker  N       Date       MIM        CI        AMIM
#>  1:      A  2 2021-07-06 0.7044131 0.7604725 -0.23404162
#>  2:      A  2 2021-07-07 0.7044131 0.7604725 -0.23404162
#>  3:      A  3 2021-07-08 0.8058670 0.8110500 -0.02743054
#>  4:      A  3 2021-07-09 0.8017444 0.8110500 -0.04924920
#>  5:      A  3 2021-07-10 0.8017444 0.8110500 -0.04924920
#>  6:      A  3 2021-07-11 0.8017444 0.8110500 -0.04924920
#>  7:      B NA 2021-07-06        NA        NA          NA
#>  8:      B NA 2021-07-07        NA        NA          NA
#>  9:      B NA 2021-07-08        NA        NA          NA
#> 10:      B NA 2021-07-09        NA        NA          NA
#> 11:      B NA 2021-07-10        NA        NA          NA
#> 12:      B NA 2021-07-11        NA        NA          NA