Publications by Sang-Heon Lee
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. Nelson-Siegel-Svensson model Svensson (1995) suggests an extended NS model which is typically called NSS model. Many central bank use NS...
5469 sym 10 img 1 tbl
R code snippet : Transform from long format to wide format
This post introduces a useful 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 yield curve has two dimensions : maturity and date. For this end, we can use reshape() R built-in function. Long and Wide formats What is the long and wid...
1950 sym 6 img 1 tbl
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 string. It is a starting point of pairs trading backtest to collect daily stock prices of a given stock index. Read and Concatenate Prices of Constituents of a Stock Index Pairs trading aims to select good performing pairs from a set of univer...
1500 sym 4 img 1 tbl
Arbitrage-free Nelson Siegel model with R code
Sang-Heon Lee This article explains how to estimate parameters of the Arbitrage-Free dynamic Nelson-Siegel (AFNS) model (Christensen, Diebold, and Rudebusch; 2009, Christensen, Diebold, and Rudebusch; 2011) using Kalman filter. We estimate not only parameters but also filtered latent factor estimates such as level, slope, and curvature using R co...
8405 sym 4 img 1 tbl
Dynamic Nelson-Siegel model with R code
Sang-Heon Lee This article explains how to estimate parameters of the dynamic Nelson-Siegel (DNS) model (Diebold and Li;2006, Diebold, Rudebusch, and Aruoba;2006) using Kalman filter. We estimate not only parameters but also filtered latent factor estimates such as level, slope, and curvature using R code. Dynamic Nelson-Siegel model 1. DN...
5353 sym 4 img 1 tbl
IAIS DNS Shock Generating Algorithm with R code
Sang-Heon Lee This article explains how to calculate DNS shock scenarios based on IAIS (2019). We implement DNS shock generating algorithm using R code with some modification. IAIS DNS Shock Generating Algorithm Risk-based Global Insurance Capital Standard is for the regulatory capital requirements against the unexpected loss of insurance c...
6425 sym 4 img 1 tbl
Black Lognormal model for Swaption with R code
Sang-Heon Lee This article derives the swaption pricing formula using Black model, which is a lognormal model. We present the detailed calculation example using R code. This work is a prerequisite for the calibratiion of Hull-White or LGM (Linear Gaussian Markov) model. The calibration of parameters of no-aritrage term structure model such a...
5164 sym 4 img 1 tbl
Bayesian Linear Regression with Gibbs Sampling using R code
Sang-Heon Lee This article explains how to estimate parameters of the linear regression model using the Bayesian inference. Our focus centers on user-friendly intuitive understanding of Bayesian estimation. From some radical point of view, we regard the Bayesian model as the average of multiple models generated with slightly different parameter s...
16008 sym 8 img 1 tbl
Retrieving Stock Price using R
Let’s download stock prices using getSymbols() function in quantmod R library. I hope he will come back soon. It is easy to download. The first thing is to find the ticker for the security. The second thing is to run the following R code with ticker. Tickers are easily found in search engines such as Google. 1234567891011121314151617181920...
1049 sym 4 img 1 tbl
BOK ECOS Open API using R code
BOK (Bank of Korea) administrates ECOS database for economic ststistics/market data and provides Open API for this database. ECOS API also supports several popular programming language such as R, Python. In this post, we use R programming to download data through ECOS API. This work can really help you avoid a time-consuming and tedious data co...
2184 sym 6 img 3 tbl