Skip to content

enderska/Bivariate-Copulas

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bivariate-Copulas

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.

get_transformed_series: Calculate required business transformation

Calculate month-over-month or year-over-year transformation based on argument

Description

Calculate required business transformation Calculate month-over-month or year-over-year transformation based on argument

Usage

get_transformed_series(series, trafo = NULL)

Arguments

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.

Value

Return the transformed series.

getCopfc: Wrapper function for copula forecast

Description

Wrapper function for copula forecast

Usage

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)

Arguments

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

Value

The median and 2 sigma forecast from the copula model

getMAPE: Calculate MAPE

Get the mean absolute percentage error for the prediction and the target. This is one of the metrics to benchmark our results.

Description

Calculate MAPE Get the mean absolute percentage error for the prediction and the target. This is one of the metrics to benchmark our results.

Usage

getMAPE(pred, target)

Arguments

Argument Description
pred The prediction from the model
target The actuals for the said period

Value

The MAPE between the prediction and the target

getMASE: Compute MASE

Get the mean absolute square error for the prediction and the target. One of the metrics to benchamrk our results.

Description

Compute MASE Get the mean absolute square error for the prediction and the target. One of the metrics to benchamrk our results.

Usage

getMASE(pred, target)

Arguments

Argument Description
pred The prediction from the model
target The actuals for the said period

Value

The MASE between the prediction and the target

getMaxKtau: 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

Description

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

Usage

getMaxKtau(KPI, indicators, max.lag = 18, min.lag = 5)

Arguments

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

Value

A list conating the indicator name and the lag which provide maximum dependency with the KPI

getMoM: Obtain month over month transformation

Description

Obtain month over month transformation

Usage

getMoM(column)

Arguments

Argument Description
column The vector/time series

Value

The month over month transformation of the column

getNorms: Compute L2 norm

Get the L2 norm for each row of the matrix

Description

Compute L2 norm Get the L2 norm for each row of the matrix

Usage

getNorms(diff_mat)

Arguments

Argument Description
diff_mat The matrix for which we want to calculate the norm for each row

Value

A vector containing the L2 norm for each row

getp1p2: Obtain lead time adjusted KPI and indicator

Description

Obtain lead time adjusted KPI and indicator

Usage

getp1p2(KPI, indicator, lag = 0)

Arguments

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

Value

A dataframe containing the KPI and the lead time adjusted indicator

getRMSE: Compute RMSE

Get the root mean square error for the prediction and the target. One of the metrics to benchamrk our results.

Description

Compute RMSE Get the root mean square error for the prediction and the target. One of the metrics to benchamrk our results.

Usage

getRMSE(pred, target)

Arguments

Argument Description
pred The prediction from the model
target The actuals for the said period

Value

The RMSE between the prediction and the target

getSeasonality: Extract Seasonality

Extract the seasonality from the data vector

Description

Extract Seasonality Extract the seasonality from the data vector

Usage

getSeasonality(data, s.window = 7, t.window = 12)

Arguments

Argument Description
data The vector/time series from which the seasonality is to be extracted

Value

The seasonality after extraction from data

getTrend: Extract trend

Extract the trend from the data vector

Description

Extract trend Extract the trend from the data vector

Usage

getTrend(data, s.window = 7, t.window = 12)

Arguments

Argument Description
data The vector/time series from which the trend is to be extracted

Value

The trend after extraction from data

getUseful_combs: 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

Description

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

Usage

getUseful_combs(KPI, indicators, threshold = 0.23, lags = 0:18)

Arguments

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.

Value

A list conating all the set of indicators and lead times which have kendall's tau above the said threshold

getYoY: Obtain year over year transformation

Description

Obtain year over year transformation

Usage

getYoY(column)

Arguments

Argument Description
column The vector/time series

Value

The year over year transformation of the column

l_skewT: Calculate negative log likelihood

Obtain the negative log likelihood for the vector x for a skew-t distribution

Description

Calculate negative log likelihood Obtain the negative log likelihood for the vector x for a skew-t distribution

Usage

l_skewT(x, params)

Arguments

Argument Description
x The vector for which we wish to find the negative log likelihood
params The paramters of the skew-t distribution

Value

The negative log likelihood of the vector x with respect to the skew-t distribution specified by params

multiplot: Place multiple plots together

Utility function to place multiple plots generated by ggplot on the same page

Description

Place multiple plots together Utility function to place multiple plots generated by ggplot on the same page

Usage

multiplot(..., plotlist = NULL, file, cols = 1, layout = NULL)

normalise: Normalise the time series

Normalise the time series using min-max normalisation

Description

Normalise the time series Normalise the time series using min-max normalisation

Usage

normalise(col)

Arguments

Argument Description
col The vector to be normalised

Value

Normalised vector

plotccf_kendall: 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

Description

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

Usage

plotccf_kendall(KPI, indicator, max.lag = 18, plot = FALSE)

Arguments

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

Value

The lead time for which we find the kendall's tau value to be maximum

remTrendSeasonality: Remove trend and seasonality

Remove the trend and seasonality from the data vector

Description

Remove trend and seasonality Remove the trend and seasonality from the data vector

Usage

remTrendSeasonality(data, s.window = 7, t.window = 12, seasonality = 1,
  trend = 1)

Arguments

Argument Description
data The vector/time series from which the trend and seasonality is to be removed

Value

The data after removing trend and seasonality

rev_transformation: Reverse business tranformation

Reverse the business transformation to obtain the raw forecast and time series

Description

Reverse business tranformation Reverse the business transformation to obtain the raw forecast and time series

Usage

rev_transformation(series, trafo = NULL, init_vals)

Arguments

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.

Value

The raw time series after reversing the business transformation.

revMoM: Reverse month over month transformation

Description

Reverse month over month transformation

Usage

revMoM(init_val, MoM_vals)

Arguments

Argument Description
series The transformed series
init_vals The initial values from the raw time series.

Value

The raw time series after reversing the month over month transformation.

revYoY: Reverse month over month transformation

Description

Reverse month over month transformation

Usage

revYoY(init_vals, YoY_vals)

Arguments

Argument Description
init_vals The initial values from the raw time series.
series The transformed series

Value

The raw time series after reversing the year over year transformation.

About

Multivariate data modelling and forecasting with Copulas

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors