Publications by Sang-Heon Lee
gEcon : Calibration of RBC or DSGE model with IRFs
This post gives an short introduction to the gEcon R package, which provides a variety of functionalities for DSGE (Dynamic Stochastic General Equilibrium) or CGE (Computational General Equilibrium) model. It is typical that the former is solved by Matlab with Dynare, the latter by GAMS. In this post, we take a simple example of basic RBC model...
5904 sym 2 img 3 tbl
Pricing of FX Forward in R and Excel
This post explains how to price a FX forward. We assume that 1) USD is the foreign currency and KRW the domestic one, 2) USD IRS zero curve and KRW FX implied zero curve are given. Before making a R code, we use Excel spreadsheet for the clear understanding of the calculation process. In this post, we consider two solutions using Excel an...
3200 sym 6 img 2 tbl
R dataframe merge while keeping orders of row and column
This post makes a useful wrapper R function merge() for left outer join, which preserves the orders of row and column of input x data. It is not a must but useful when we prefer these fixed orders in some case. Left Outer Join which we try to do The following figure demonstrates what we are trying to do. The first is to perform left oute...
2796 sym 4 img 4 tbl
R : a combined usage of split, lapply and do.call
This post explains a combined usage of split(), lapply() and do.call() R functions, so called Split-Apply-Combine approach. These are frequently used for group based calculations such as weighted average or aggregation. It will be useful when complicated user-defined function is applied differently to each group such as currency. lapply, sp...
3094 sym 2 img 8 tbl
Basic R : Read so many CSV files
This post presents basic R code snippets to read files with given file extensions such as csv or txt. This is simple but very useful when it comes to the case where there are too many files to read manually. If we have too many (i.e. 1000 files) csv files or its variants, it is impossible to read these files one by one manually. For exam...
2073 sym 2 img 2 tbl
Bond Modified Duration in R
Bond duration is a basic building block for bond portfolio management and asset-liability management (ALM). This post explains the meaning of duration and calculation of this risk measures by using Excel and R. Instead of using another full-fledged R package, we implement it mannually for clear understanding. Bond Price Bond price with un...
5777 sym 4 img 2 tbl
Bond Convexity in Excel and R
Bond duration is the first order linear approximation and thus does not consider a non-linearity. Making up for this shortcoming of the duration, a convexity is needed to describe the non-linearity of a bond price. This post explains the meaning and calculation process of the convexity by using Excel and R. We have calculated a bond duration i...
4798 sym 4 img 2 tbl
Percent Change of Bond Price using Duration and Convexity in R
A percentage (%) change in a bond price with respect to a change in interest rate is approximated by using duration and convexity, which is based on the Talor approximation with the first and second order terms. We have calculated a bond duration and convexity in the previous posts Bond Modified Duration in Excel and R Bond Convexity ...
3790 sym 2 tbl
Machine Learning : Workflow
This post gives a brief introduction to a workflow of machine learning model and mostly used R packages before diving into the details. Given a problem to be solved, all machine learning (ML) models use the same input but different output. It is, therefore, useful to understand a common workflow of ML model. As there is no only one workflow b...
2212 sym 6 img
Price and Duration of Floating Rate Note using R
The price of a floating rate bond is always equal to the face value at the payment dates and the duration is the remaining time until the first next reset date. This post explains these arguments by using some heuristic derivations and R code. Floating rate bond or note (FRN) usually refers to an instrument whose coupon is based on a short t...
6005 sym 2 img 1 tbl