Site icon R-bloggers

Pricing of FX Forward in R and Excel

[This article was first published on K & L Fintech Modeling, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
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 and R. In particular, Excel solution uses the same linear interpolation as that of the following post.



FX Forward Pricing


FX forward is a contractual agreement between two parties to exchange a pair of currencies at a specific time in the future. Given discount factors for domestic and foreign currencies, FX forward price is easily calculated. For example, let’s take an example of the USD KRW FX forward contract as follows.


The difference between present values of two nominal amount is the price of FX forward. Of course, it can be represented by either domestic or foreign currencies.


Example Trade


As of 2021/06/30, let’s investigate the calculation process of FX forward contract of the detailed example above.



Understanding using Excel


We need the each currency’s discount factor of maturity date, which is needed to be interpolated. We use the LINEST Excel function for this purpose. This interpolation procedure is simple and useful in that we only generate regression coefficients for the corresponding maturity ranges. From Excel spreadsheet calculation, we can learn how to price a FX forward. The important thing is to calculate present values of each nominal amounts using each discount factor and get their difference under the same currency.


Here, notations used in the above Excel spreadsheet are defined in the following way.



R code


We can use R code to get the same results from Excel calculation.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#=========================================================================#
# Financial Econometrics & Derivatives, ML/DL using R, Python, Tensorflow  
# by Sang-Heon Lee 
#
# https://kiandlee.blogspot.com
#————————————————————————-#
# FX Forward Pricing
#=========================================================================#
 
graphics.off()  # clear all graphs
rm(list = ls()) # remove all files from your workspace
 
#————————————————————————–
# 1. Market Information
#————————————————————————–
    
    #——————————–
    # Zero curves as of 2021-06-30
    #——————————–
    lt.mt < list(
        spot_date = 44377,   # spot date
        
        KRWUSD.FX.Spot = 1129.945# FX Spot Rate
        
        KRW_CRS.zero = data.frame(
            
            # Excel numeric date
            date = c(44378443794438644410
                     44441444744456444747), 
            rate = c(0.00629994563073550,
                     0.00629994563073550,
                     0.00463177425055339,
                     0.00329405202619836,
                     0.00292249195639071,
                     0.00273429173667466,
                     0.00331796879551685,
                     0.00397939937284654)
        ),
        
        USD_IRS.zero  = data.frame(
            
            # Excel numeric date
            date = c(44378443864441044441,
                     44473445644465544747), 
            rate = c(0.000842844860217754,
                     0.000908701294845472,
                     0.001006361388394810,
                     0.001238311778397180,
                     0.001455778457003310,
                     0.001533135923937390,
                     0.001716219715472820,
                     0.001848263900368730)
        )
    )
    
    #——————————–
    # Interpolation of zero curve
    #——————————–
 
    # USD IRS
    v.date   < lt.mt$USD_IRS.zero$date
    v.zero   < lt.mt$USD_IRS.zero$rate
    func_linear_USD_IRS.zero < approxfun(v.date, v.zero, 
                                          method=“linear”)
    # KRW CRS
    v.date   < lt.mt$KRW_CRS.zero$date
    v.zero   < lt.mt$KRW_CRS.zero$rate
    func_linear_KRW_CRS.zero < approxfun(v.date, v.zero, 
                                          method=“linear”)
#————————————————————————–
# 2. FX Forward Trade Information
#————————————————————————–
 
    fAmt < 10000      # Foreign notional amount
    dAmt < 10948600   # Domestic notional amount
    fPosition < 1     # 1 if Foreign is a buy position, -1 if sell
    mat_date  < 44561 # maturity date of FX Forward contract
 
#————————————————————————–
# 3. FX Forward Pricing
#————————————————————————–
    
    #——————————–
    # 1) Foreign
    #——————————–
    
    # zero rate for discounting
    fzero < func_linear_USD_IRS.zero(mat_date)
    # discount factor
    fDF < exp(fzero*(mat_datelt.mt$spot_date)/365)
    # discounted foreign amount denominated in foreign currency
    pv_fAmt_in_f < fAmt*fDF
    # discounted foreign amount denominated in domestic currency
    pv_fAmt_in_d < pv_fAmt_in_f*lt.mt$KRWUSD.FX.Spot
    
    #——————————–
    # 2) Domestic
    #——————————–
    
    # zero rate for discounting
    dzero < func_linear_KRW_CRS.zero(mat_date)
    # discount factor
    dDF < exp(dzero*(mat_datelt.mt$spot_date)/365)
    # discounted domestic amount denominated in foreign currency
    pv_dAmt_in_d < dAmt*dDF
    # discounted domestic amount denominated in domestic currency
    pv_dAmt_in_f < pv_dAmt_in_d/lt.mt$KRWUSD.FX.Spot
    
    # 3) Price
    #——————————–
    price_in_f < fPosition*(pv_fAmt_in_f  pv_dAmt_in_f)
    price_in_d < fPosition*(pv_fAmt_in_d  pv_dAmt_in_d)
    
    print(paste0(“FX Forward Price ($) = “, round(price_in_f,2)))
    print(paste0(“FX Forward Price (w) = “, round(price_in_d,2)))
 
cs


Results


The following results show FX forward prices denominated in both USD dollar and KRW won. The price of this example is $318.89 or ₩360,325.24. These results are the same as those obtained using Excel.


1
2
3
4
5
6
 
>     print(paste0(“FX Forward Price ($) = “, round(price_in_f,2)))
[1“FX Forward Price ($) = 318.89”
>     print(paste0(“FX Forward Price (w) = “, round(price_in_d,2)))
[1“FX Forward Price (w) = 360325.24”
 
cs


From this post, we can calculate the price of FX forward using Excel and R. For simplicity, CRS or FX implied zero curve is assumed away in this work, we will discuss it later. \(\blacksquare\)

To leave a comment for the author, please follow the link and comment on their blog: K & L Fintech Modeling.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.