# Articles by sang-heon lee

### Black-Derman-Toy Interest Rate model using R

October 9, 2021 |

This post implements Black-Derman-Toy (BDT) interest rate tree using R. This implementation is based on the previous post for BDT model. R Implementation of BDT Interest Rate Tree We implement BDT tree according to the content of the previous p... ### Using Java functions from JAR file in R using rJava

October 1, 2021 |

This post explains how to call Java functions from jar file in R. This is useful especially when derivatives pricing or risk calculation engine already have been developed well in the form of Java in your company. It is more efficient to use time-te... ### A Simple Two-Stage Stochastic Linear Programming using R

September 30, 2021 |

This post explains a two-stage stochastic linear programming (SLP) in a simplified manner and implements this model using R. This exercise is for the clear understanding of SLP model and will be a solid basis for the advanced topics such as multi-st... ### A Simple ALM Cash Flow Matching using Excel and R

September 26, 2021 |

This post implements a simple asset-liability cash flow matching using Excel and R. This example is a linear programming (LP) model but will serve as a foundation for the advanced ALM modeling techniques such as two-stage or multi-stage stochastic l... ### Numerical Calculation of FRN Duration in R

September 21, 2021 |

The duration of a floating rate note (FRN) is the remaining time until the first next payment date. Using this fact, a duration of FRN has not been calculated explicitly but has been understood conceptually. Instead of this reasoning, this post trie... ### Price and Duration of Floating Rate Note using R

September 20, 2021 |

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. F... ### Machine Learning : Workflow

September 19, 2021 |

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, ... ### Percent Change of Bond Price using Duration and Convexity in R

September 14, 2021 |

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 duratio... [Read more...]

### Bond Convexity in Excel and R

September 11, 2021 |

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 c... ### Bond Modified Duration in R

September 3, 2021 |

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 ... ### Basic R : Read so many CSV files

September 2, 2021 |

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 file... ### R : a combined usage of split, lapply and do.call

August 29, 2021 |

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 compl... ### R dataframe merge while keeping orders of row and column

August 15, 2021 |

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... ### Pricing of FX Forward in R and Excel

August 8, 2021 |

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 under... ### gEcon : Calibration of RBC or DSGE model with IRFs

August 2, 2021 |

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 ... ### RDCOMClient : A Simple Libor IRS Pricing with OIS Discounting

July 31, 2021 |

This post shows a simple example which uses the RDCOMClient R package. As an example, A Libor IRS pricing with OIS discounting is presented with the help of a VBA macro code from Mikael Katajamäki's source with proper citation (this should be always... ### RDCOMClient : read and write Excel, and call VBA macro in R

July 29, 2021 |

This post gives an short introduction to the RDCOMClient R package, which provides a variety of functionalities. Our focus is on reading from and writing to Excel, and call VBA macro function in R. Introduction Using RDCOMClient R package,... ### Delta Sensitivity of Interest Rate Swap

July 23, 2021 |

This post explains how to calculate delta sensitivities or delta vector of interest rate swap, especially delta. delta can be calculated by either 1) zero delta or 2) market delta. To the best of our knowledge, FRTB can use these two methods but SIM... ### Interest Rate Swap Pricing using R code

July 10, 2021 |

This post explains how to price an interest rate swap (IRS) using R code and Excel's illustrations. We use swap rates, zero curve data from Bloomberg. We consider 5-Year Libor 3M IRS without OIS discounting as an pre-crisis IRS example. Libor ...  