Multivariate data modelling and forecasting with Copulas
Statistical modelling of the dependence structure between pairs of univariate time series using the concept of copulas. Copulas are functions that describe the dependence between two or more random variables. Three data sets are selected to illustrate the methodology, aiming to capture correlation beyond the usual linear form, such as tail and asymmetric dependence. As a back testing procedure, Monte Carlo simulations are performed to forecast conditional moments of financial Key Performance Indicators. Results are compared to linear time series models.
Calculate month-over-month or year-over-year transformation based on argument
Calculate required business transformation Calculate month-over-month or year-over-year transformation based on argument
get_transformed_series(series, trafo = NULL)
| Argument | Description |
|---|---|
series |
The time series which needs to be transformed |
trafo |
A string which should be one of c(NULL, 'mom','yoy') to specify which transformation. |
Return the transformed series.
Wrapper function for copula forecast
getCopfc(KPI, indicator_set, indicator_name = NULL, min.lag = 5,max.lag = 18, lag = NULL, kpi_trafo = NULL, ind_trafo = NULL,KPI_outlier_corr = FALSE, indicator_outlier_corr = FALSE, offset = TRUE,dates = NULL)
| Argument | Description |
|---|---|
KPI |
The time series which needs to be predicted |
indicator_set |
The set of indicators which are looked through for finding an exogeneous time series |
indicator_name |
The indicator which is used to forecast the KPI . If it is NULL , then maximum kendall's tau is used to automatically pick the exogeneous time series |
min.lag |
The minimum lead time which is looked at while picking the exogeneous time series |
max.lag |
The maximum lwead time which is looked at while picking the exogeneous time series |
kpi_trafo |
The transformation which is applied to the KPI before forecasting |
ind_trafo |
The transformation which is applied to the indicator before forecasting |
KPI_outlier_corr |
Boolean to indicate whether to perform outlier correction on the KPI |
indicator_outlier_corr |
Boolean to indicate whether to perform outlier correction on the indicator |
offset |
Indicates whether the copula forecast should be offset or not. The offset is determined by the |
dates |
Deprecated |
The median and 2 sigma forecast from the copula model
Get the mean absolute percentage error for the prediction and the target. This is one of the metrics to benchmark our results.
Calculate MAPE Get the mean absolute percentage error for the prediction and the target. This is one of the metrics to benchmark our results.
getMAPE(pred, target)
| Argument | Description |
|---|---|
pred |
The prediction from the model |
target |
The actuals for the said period |
The MAPE between the prediction and the target
Get the mean absolute square error for the prediction and the target. One of the metrics to benchamrk our results.
Compute MASE Get the mean absolute square error for the prediction and the target. One of the metrics to benchamrk our results.
getMASE(pred, target)
| Argument | Description |
|---|---|
pred |
The prediction from the model |
target |
The actuals for the said period |
The MASE between the prediction and the target
Gets the indicator and lead time from a set of indicators which ahs the maximum kendall's tau with repsect to the said KPI
Find best indicator and lead time Gets the indicator and lead time from a set of indicators which ahs the maximum kendall's tau with repsect to the said KPI
getMaxKtau(KPI, indicators, max.lag = 18, min.lag = 5)
| Argument | Description |
|---|---|
KPI |
The KPi for which we wish to find an exogeneous time series and appropriate lead time |
indicators |
The set of indicators which we look at to find the best exogeneous time series variable |
max.lag |
The maximum lag which is considered while finding an exogeneous time series |
min.lag |
The minimum lag which is considered while finding an exogeneous time series |
A list conating the indicator name and the lag which provide maximum dependency with the KPI
Obtain month over month transformation
getMoM(column)
| Argument | Description |
|---|---|
column |
The vector/time series |
The month over month transformation of the column
Get the L2 norm for each row of the matrix
Compute L2 norm
Get the L2 norm for each row of the matrix
getNorms(diff_mat)
| Argument | Description |
|---|---|
diff_mat |
The matrix for which we want to calculate the norm for each row |
A vector containing the L2 norm for each row
Obtain lead time adjusted KPI and indicator
getp1p2(KPI, indicator, lag = 0)
| Argument | Description |
|---|---|
KPI |
The time series which we wish to predict |
indicator |
The exogeneous time series which we use to predict the KPI |
lag |
The lead time between the KPI and the indicator |
A dataframe containing the KPI and the lead time adjusted indicator
Get the root mean square error for the prediction and the target. One of the metrics to benchamrk our results.
Compute RMSE Get the root mean square error for the prediction and the target. One of the metrics to benchamrk our results.
getRMSE(pred, target)
| Argument | Description |
|---|---|
pred |
The prediction from the model |
target |
The actuals for the said period |
The RMSE between the prediction and the target
Extract the seasonality from the data vector
Extract Seasonality
Extract the seasonality from the data vector
getSeasonality(data, s.window = 7, t.window = 12)
| Argument | Description |
|---|---|
data |
The vector/time series from which the seasonality is to be extracted |
The seasonality after extraction from data
Extract the trend from the data vector
Extract trend
Extract the trend from the data vector
getTrend(data, s.window = 7, t.window = 12)
| Argument | Description |
|---|---|
data |
The vector/time series from which the trend is to be extracted |
The trend after extraction from data
Obtain the list of combinations of KPI and indicator which have Kenadll's tau above a certain threshold. This is used to obtain KPI and indicator time series pairs
Find useful indicators for a KPI Obtain the list of combinations of KPI and indicator which have Kenadll's tau above a certain threshold. This is used to obtain KPI and indicator time series pairs
getUseful_combs(KPI, indicators, threshold = 0.23, lags = 0:18)
| Argument | Description |
|---|---|
KPI |
The time series which we want to find lead time indicators for |
indicators |
The set of indicators which we need to look at |
threshold |
The threshold for kendall's tau above which we consider an indicator useful in modelling the KPI |
lags |
The set of lead times we look at. |
A list conating all the set of indicators and lead times which have kendall's tau above the said threshold
Obtain year over year transformation
getYoY(column)
| Argument | Description |
|---|---|
column |
The vector/time series |
The year over year transformation of the column
Obtain the negative log likelihood for the vector x for a skew-t distribution
Calculate negative log likelihood
Obtain the negative log likelihood for the vector x for a skew-t distribution
l_skewT(x, params)
| Argument | Description |
|---|---|
x |
The vector for which we wish to find the negative log likelihood |
params |
The paramters of the skew-t distribution |
The negative log likelihood of the vector x with respect to the skew-t distribution specified by params
Utility function to place multiple plots generated by ggplot on the same page
Place multiple plots together
Utility function to place multiple plots generated by ggplot on the same page
multiplot(..., plotlist = NULL, file, cols = 1, layout = NULL)
Normalise the time series using min-max normalisation
Normalise the time series Normalise the time series using min-max normalisation
normalise(col)
| Argument | Description |
|---|---|
col |
The vector to be normalised |
Normalised vector
Plot the variation of kendall's tau with varying lead times. Useful to identify optimal lead time between KPI and indicator
Calculate optimal lead time Plot the variation of kendall's tau with varying lead times. Useful to identify optimal lead time between KPI and indicator
plotccf_kendall(KPI, indicator, max.lag = 18, plot = FALSE)
| Argument | Description |
|---|---|
KPI |
A vector which we wish to find the optimal lead time |
indicator |
The exogeneous time series vector |
max.lag |
The maximum lead time which we look at while finding the optimal lead time |
plot |
A boolean option which we use to indicate whether plot should be generated or not |
The lead time for which we find the kendall's tau value to be maximum
Remove the trend and seasonality from the data vector
Remove trend and seasonality
Remove the trend and seasonality from the data vector
remTrendSeasonality(data, s.window = 7, t.window = 12, seasonality = 1,trend = 1)
| Argument | Description |
|---|---|
data |
The vector/time series from which the trend and seasonality is to be removed |
The data after removing trend and seasonality
Reverse the business transformation to obtain the raw forecast and time series
Reverse business tranformation Reverse the business transformation to obtain the raw forecast and time series
rev_transformation(series, trafo = NULL, init_vals)
| Argument | Description |
|---|---|
series |
The transformed series |
trafo |
A string which should be one of c(NULL, 'mom','yoy') to specify which transformation to reverse |
init_vals |
The initial values from the raw time series. |
The raw time series after reversing the business transformation.
Reverse month over month transformation
revMoM(init_val, MoM_vals)
| Argument | Description |
|---|---|
series |
The transformed series |
init_vals |
The initial values from the raw time series. |
The raw time series after reversing the month over month transformation.
Reverse month over month transformation
revYoY(init_vals, YoY_vals)
| Argument | Description |
|---|---|
init_vals |
The initial values from the raw time series. |
series |
The transformed series |
The raw time series after reversing the year over year transformation.