Derivatives Learned Using Python-(1) Calculation of Forward Exchange Rate-

I'm in a financial IT company and I'm dealing with derivatives, but I've learned a lot about the theory of derivatives, so I will write down the explanation and the program in Python for review and creation of educational materials. By the way, we will do it based on publicly available information such as books. Therefore, it has nothing to do with work know-how.

Derivative series to learn using Python

First: Calculation of forward exchange rate- 2nd: Draw a yield curve (JPYLibor curve)

How to calculate the forward exchange rate

Forward exchange is the exchange rate of exchange at a certain point in the future.

The forward exchange rate (FwdFX) can be calculated from the current exchange rate, the spot exchange rate (SpotFX), and the interest rates of both currencies.

For example, when calculating the conversion rate between dollars and yen

FwdFX(USD/JPY) = SpotFX(USD/JPY) × DF(USD) / DF(JPY)

Can be calculated with.

Although it is called interest rate, interest rate does not come out, and instead, something called DF is coming out, DF is a discount factor, It's like a hook used to discount the value at a certain point in the future by the current value. The future 1 million yen and the current 1 million yen have interest rates, so they are not equal in value. So how much is the future value of 1 million yen? At times, the value can be calculated with a DF that costs 1 million yen. And DF can be calculated from the interest rate. The story around DF is different, so I won't talk about it anymore. I will proceed on the premise that I know it.

Commentary

Let the current exchange rate be S (1 dollar S yen), the period be T (year), the yen spot interest rate on a continuous compound interest basis for T years be Ry, and the dollar spot interest rate be Rd.

(1) If you convert the yen fund S yen you have at the moment into dollars and operate it for T years

S \times \frac{1}{S} \times e^{RdT} = e^{RdT}(Dollar) 

Will be.

(2) When operating in yen for T years

S \times e^{RyT}(Circle)

Will be.

Here, let X (X yen per dollar) be the exchange rate after T years.

Since the same result (*) is obtained between operating yen by converting it to dollar (1) and operating it by yen and converting it to dollar (2).

S \times e^{RyT} \times \frac{1}{X} = e^{RdT}

Is established.

Therefore, the forward exchange rate X is

\begin{align}
X &= S \times e^{-RdT} \times \frac{1}{e^{-RyT}} \\
&= S \times \frac{Dfd}{Dfy}
\end{align}

It is calculated by the spot exchange rate x DF (dollar) / DF (yen).

Sample code

# -*- coding: utf-8 -*-


import numpy as np

#Various data
SFX= 120 #Spot exchange rate
ry = 0.01 #Yen spot interest rate
rd = 0.05 #Dollar spot interest rate
T = 1 #period

#One year continuous compound interest rate(R)The spot interest rate(r)Calculate from.
"""
e^RT = (1+r)^T
RT = ln(1+r)
R = ln(1+r) / T
"""
Ry = np.log(1 + ry) / T
Rd = np.log(1 + rd) / T

#The discant factor is e^Because it is calculated by RT
DFy = np.exp(-Ry * T)
DFd = np.exp(-Rd * T)

#Forward exchange rate is spot exchange rate x DF(Dollar) / DF(Circle)Because it is calculated by
FFX = SFX * DFd / DFy
print(FFX)

Recommended Posts

Derivatives Learned Using Python-(1) Calculation of Forward Exchange Rate-
1. Statistics learned with Python 1-3. Calculation of various statistics (statistics)
1. Statistics learned with Python 1-2. Calculation of various statistics (Numpy)
Calculation of match rate of character string breaks [python]
Age calculation using python
Derivatives learned using Python-(2) Draw a yield curve (JPYLibor curve)-
python: Basics of using scikit-learn ①
# 1 [python3] Simple calculation using variables
Calculation of satellite orbit LST using python (true sun, average sun)
Image capture of firefox using python
Calculation of normal vector using convolution
Removal of haze using Python detailEnhanceFilter
Implementation of desktop notifications using Python
[Python] Calculation of Kappa (k) coefficient
Examination of exchange rate forecasting method using deep learning and wavelet transform
Python: Basics of image recognition using CNN
[Python] Extension using inheritance of matplotlib (NavigationToolbar2TK)
Automatic collection of stock prices using python
About building GUI using TKinter of Python
(Bad) practice of using this in Python
Algorithm learned with Python 8th: Evaluation of algorithm
Python: Application of image recognition using CNN
[Python] Calculation of image similarity (Dice coefficient)
Calculation of forward average (Piyolog sleep time)
Study on Tokyo Rent Using Python (3-1 of 3)
Meaning of using DI framework in Python
Web application production course learned with Flask of Python Part 2 Chapter 1 ~ JSON exchange ~
Time variation analysis of black holes using python
Chord recognition using chromagram of python library librosa
Algorithm learned with Python 13th: Tower of Hanoi
Introduction of Python Imaging Library (PIL) using HomeBrew
Character encoding when using csv module of python 2.7.3
Try using the collections module (ChainMap) of python3
Anonymous upload of images using Imgur API (using Python)
Find the geometric mean of n! Using Python
Python introductory study-output of sales data using tuples-
Calculation of support vector machine (SVM) (using cvxopt)
Summary of Excel operations using OpenPyXL in Python
"Principle of dependency reversal" learned slowly with Python