forked from domokane/FinancePy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestFinFXForward.py
88 lines (67 loc) · 3.04 KB
/
TestFinFXForward.py
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
###############################################################################
# Copyright (C) 2018, 2019, 2020 Dominic O'Kane
###############################################################################
import sys
sys.path.append("..")
from financepy.products.fx.FinFXForward import FinFXForward
from financepy.finutils.FinDayCount import FinDayCountTypes
from financepy.finutils.FinCalendar import FinCalendarTypes
from financepy.products.funding.FinIborSingleCurve import FinIborSingleCurve
from financepy.products.funding.FinIborDeposit import FinIborDeposit
from financepy.finutils.FinDate import FinDate
from FinTestCases import FinTestCases, globalTestCaseMode
testCases = FinTestCases(__file__, globalTestCaseMode)
##########################################################################
def test_FinFXForward():
# https://stackoverflow.com/questions/48778712
# /fx-vanilla-call-price-in-quantlib-doesnt-match-bloomberg
valuationDate = FinDate(13, 2, 2018)
expiryDate = valuationDate.addMonths(12)
# Forward is on EURUSD which is expressed as number of USD per EUR
# ccy1 = EUR and ccy2 = USD
forName = "EUR"
domName = "USD"
currencyPair = forName + domName # Always ccy1ccy2
spotFXRate = 1.300 # USD per EUR
strikeFXRate = 1.365 # USD per EUR
ccy1InterestRate = 0.02 # USD Rates
ccy2InterestRate = 0.05 # EUR rates
###########################################################################
spotDays = 0
settlementDate = valuationDate.addWeekDays(spotDays)
maturityDate = settlementDate.addMonths(12)
notional = 100.0
calendarType = FinCalendarTypes.TARGET
depos = []
fras = []
swaps = []
depositRate = ccy1InterestRate
depo = FinIborDeposit(settlementDate, maturityDate, depositRate,
FinDayCountTypes.ACT_360, notional, calendarType)
depos.append(depo)
forDiscountCurve = FinIborSingleCurve(valuationDate, depos, fras, swaps)
depos = []
fras = []
swaps = []
depositRate = ccy2InterestRate
depo = FinIborDeposit(settlementDate, maturityDate, depositRate,
FinDayCountTypes.ACT_360, notional, calendarType)
depos.append(depo)
domDiscountCurve = FinIborSingleCurve(valuationDate, depos, fras, swaps)
notional = 100.0
notionalCurrency = forName
fxForward = FinFXForward(expiryDate,
strikeFXRate,
currencyPair,
notional,
notionalCurrency)
testCases.header("SPOT FX", "FX FWD", "VALUE_BS")
fwdValue = fxForward.value(valuationDate, spotFXRate,
domDiscountCurve, forDiscountCurve)
fwdFXRate = fxForward.forward(valuationDate, spotFXRate,
domDiscountCurve,
forDiscountCurve)
testCases.print(spotFXRate, fwdFXRate, fwdValue)
###############################################################################
test_FinFXForward()
testCases.compareTestCases()