Showing posts with label Rcode. Show all posts
Showing posts with label Rcode. Show all posts

R : VAR Impulse Response Function

This post draws the orthogonal impulse response functions from an estimated VAR model with 1 standard deviation or 1 unit shock. vars R package does not provide 1 unit shock so I implemented it using the Cholesky decomposition.

R code: Understanding Dynamic Conditional Correlation (DCC) model

This post explains the structure of DCC (dynamic conditional correlation) model of Engle (2002) and then, uses rmgarch R package for estimating DCC model. This R package also provides various extended versions of DCC model.

R code: Estimation and Forecasting of GARCH Volatility model

This post uses rugarch R package for estimating GARCH model to obtain conditional volatility estimates. This R package also provides various extended versions of GARCH model such as EGARCH, GJR-GARCH, to name a few.

R code: Range-Based Volatility Estimator

This post uses TTR R package to calculate various range-based volatility estimators such as Parkinson (1980), Garman and Klass (1989) and so on.

R code : Extract data from an image file using digitize R package

This post shows how to extract data from an image file using digitize R package. By clicking relevant data points on image, the corresponding data points are read. To improve an applicability of this scanned data to impose the equidistance between adjacent data points, I apply a numerical rounding and then an interpolation.

R code : Creating lagged Xs and y for supervised learning

This post shows a simple R code to create various lagged time series and concatenate them with the original time series. This can be used frequently when preprocessing time series data for machine/deep learning models.

R code : Back Transform from Caret's preProcess()

This post gives a small R code for the back transformation of the caret's preProcess() function, which is not implemented in caret R package yet.

R code : setting x-axis as the selected dates

This post shows a simple R code to set x-axis as some selected dates rather than using 1, 2, 3, ... on x-axis.

Diebold-Yilmaz Spillover Index using R package

This post explains how to use Spillover R package to calculate Diebold-Yilmaz spillover index. It measures a return or volatility spillover across asset classes and also a time series of rolling spillover index for taking time-varying spillovers into account.

Understanding the Haar wavelet

This post gives an brief introduction to the discrete wavelet transform (DWT) and illustrates an example of the Haar wavelet.

Paste R plot images into MS Word

This post explains how to paste R plot images into MS Word with some additional information such as title, description, and data table. This can be done by using the officer R package.

Hurst Exponent using R code

This post explains how to estimate the Hurst exponent which indicates characteristics of a time series : mean-reversion, random walk, and trending with long memory using S&P 500 index returns.

R code snippet : Read and Concatenate Prices of Constituents of a Stock Index

This post shows how to read all prices of constituents of a stock index given all symbols as a string. It is a prerequisite of the pairs trading backtest.

R code snippet : Transform from long format to wide format

This post introduces a simple R code snippet for transforming the long format data to the wide format. We occasionally encounter the long format data such as yield curve data since it has two dimensions : maturity and time. For this end, we can use reshape() R built-in function.

Nelson-Siegel-Svensson Yield Curve model using R code

This post introduces Nelson-Siegel-Svensson (NSS) yield curve model which is an extension of Nelson-Siegel (NS) model with an additional curvature factor. It aims to fit longer term maturities well.

Loan Amortization Schedule using R code

This post explains and implements major three types of loan amortization or repayment schedule using R code: 1) bullet or balloon payment, 2) equal total payment, and 3) equal principal payment.

Understanding PCA 3 Factors of the Yield Curve using R code

This post explains how to decompose a movement of bond yields into 3 factors (level, slope, curvature) which is the work of Litterman and Scheinkman (1991). Using R functions for the principal component analysis and eigen decomposition, we can understand the contributions of these factors.