Skip to content

Commit 0cfcc73

Browse files
committed
modified BPV calculation
1 parent 9275b93 commit 0cfcc73

File tree

2 files changed

+132
-53
lines changed

2 files changed

+132
-53
lines changed

financepy/products/rates/ibor_swap.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,8 @@ def payer_side_BPV(self, value_dt, discount_curve,payment_periods: float,):
481481
times one basis point (0.0001)
482482
"""
483483
bp=0.0001
484-
return self.payer_side_modified_duration(value_dt, discount_curve,payment_periods)*self.fixed_leg.notional*bp
484+
modi_dur = self.payer_side_modified_duration(value_dt, discount_curve,payment_periods)
485+
return modi_dur*self.fixed_leg.notional*bp
485486

486487
###########################################################################
487488

notebooks/products/rates/FINIBORSWAP_ReplicationgBONDMATHDurationExample3M.ipynb

Lines changed: 130 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,26 @@
66
"metadata": {
77
"collapsed": true,
88
"ExecuteTime": {
9-
"end_time": "2025-05-23T02:31:22.631355Z",
10-
"start_time": "2025-05-23T02:31:22.625849Z"
9+
"end_time": "2025-05-23T02:54:25.031837Z",
10+
"start_time": "2025-05-23T02:54:25.027815Z"
1111
}
1212
},
1313
"source": [
1414
"from financepy.utils import *\n",
1515
"from financepy.products.rates import *\n",
1616
"from financepy.market.curves import *\n",
17-
"import datetime as dt"
17+
"import datetime as dt\n",
18+
"\n",
19+
"from notebooks.products.rates.FINIBORSWAP_ReplicationgBONDMATHDurationExample import payment_periods"
1820
],
1921
"outputs": [],
20-
"execution_count": 2
22+
"execution_count": 34
2123
},
2224
{
2325
"metadata": {
2426
"ExecuteTime": {
25-
"end_time": "2025-05-23T02:31:22.679560Z",
26-
"start_time": "2025-05-23T02:31:22.657680Z"
27+
"end_time": "2025-05-23T02:54:25.043454Z",
28+
"start_time": "2025-05-23T02:54:25.039940Z"
2729
}
2830
},
2931
"cell_type": "code",
@@ -63,13 +65,13 @@
6365
],
6466
"id": "1ebf43316efee835",
6567
"outputs": [],
66-
"execution_count": 3
68+
"execution_count": 35
6769
},
6870
{
6971
"metadata": {
7072
"ExecuteTime": {
71-
"end_time": "2025-05-23T02:31:22.694667Z",
72-
"start_time": "2025-05-23T02:31:22.687165Z"
73+
"end_time": "2025-05-23T02:54:25.056980Z",
74+
"start_time": "2025-05-23T02:54:25.052895Z"
7375
}
7476
},
7577
"cell_type": "code",
@@ -89,18 +91,18 @@
8991
"31-MAR-2024"
9092
]
9193
},
92-
"execution_count": 4,
94+
"execution_count": 36,
9395
"metadata": {},
9496
"output_type": "execute_result"
9597
}
9698
],
97-
"execution_count": 4
99+
"execution_count": 36
98100
},
99101
{
100102
"metadata": {
101103
"ExecuteTime": {
102-
"end_time": "2025-05-23T02:31:22.727011Z",
103-
"start_time": "2025-05-23T02:31:22.719602Z"
104+
"end_time": "2025-05-23T02:54:25.078736Z",
105+
"start_time": "2025-05-23T02:54:25.073700Z"
104106
}
105107
},
106108
"cell_type": "code",
@@ -123,13 +125,13 @@
123125
],
124126
"id": "290b7a06932da41d",
125127
"outputs": [],
126-
"execution_count": 5
128+
"execution_count": 37
127129
},
128130
{
129131
"metadata": {
130132
"ExecuteTime": {
131-
"end_time": "2025-05-23T02:31:22.746919Z",
132-
"start_time": "2025-05-23T02:31:22.739589Z"
133+
"end_time": "2025-05-23T02:54:25.092695Z",
134+
"start_time": "2025-05-23T02:54:25.087190Z"
133135
}
134136
},
135137
"cell_type": "code",
@@ -142,18 +144,18 @@
142144
"0.030065619962567392"
143145
]
144146
},
145-
"execution_count": 6,
147+
"execution_count": 38,
146148
"metadata": {},
147149
"output_type": "execute_result"
148150
}
149151
],
150-
"execution_count": 6
152+
"execution_count": 38
151153
},
152154
{
153155
"metadata": {
154156
"ExecuteTime": {
155-
"end_time": "2025-05-23T02:31:22.765913Z",
156-
"start_time": "2025-05-23T02:31:22.759349Z"
157+
"end_time": "2025-05-23T02:54:25.120452Z",
158+
"start_time": "2025-05-23T02:54:25.116135Z"
157159
}
158160
},
159161
"cell_type": "code",
@@ -166,18 +168,18 @@
166168
"-404094.769553849"
167169
]
168170
},
169-
"execution_count": 7,
171+
"execution_count": 39,
170172
"metadata": {},
171173
"output_type": "execute_result"
172174
}
173175
],
174-
"execution_count": 7
176+
"execution_count": 39
175177
},
176178
{
177179
"metadata": {
178180
"ExecuteTime": {
179-
"end_time": "2025-05-23T02:31:22.784960Z",
180-
"start_time": "2025-05-23T02:31:22.779808Z"
181+
"end_time": "2025-05-23T02:54:25.148481Z",
182+
"start_time": "2025-05-23T02:54:25.143313Z"
181183
}
182184
},
183185
"cell_type": "code",
@@ -190,18 +192,18 @@
190192
"-6.794198629548404"
191193
]
192194
},
193-
"execution_count": 8,
195+
"execution_count": 40,
194196
"metadata": {},
195197
"output_type": "execute_result"
196198
}
197199
],
198-
"execution_count": 8
200+
"execution_count": 40
199201
},
200202
{
201203
"metadata": {
202204
"ExecuteTime": {
203-
"end_time": "2025-05-23T02:31:22.817161Z",
204-
"start_time": "2025-05-23T02:31:22.812093Z"
205+
"end_time": "2025-05-23T02:54:25.169741Z",
206+
"start_time": "2025-05-23T02:54:25.164469Z"
205207
}
206208
},
207209
"cell_type": "code",
@@ -214,18 +216,18 @@
214216
"6.794198629548404"
215217
]
216218
},
217-
"execution_count": 9,
219+
"execution_count": 41,
218220
"metadata": {},
219221
"output_type": "execute_result"
220222
}
221223
],
222-
"execution_count": 9
224+
"execution_count": 41
223225
},
224226
{
225227
"metadata": {
226228
"ExecuteTime": {
227-
"end_time": "2025-05-23T02:31:22.858301Z",
228-
"start_time": "2025-05-23T02:31:22.853154Z"
229+
"end_time": "2025-05-23T02:54:25.199176Z",
230+
"start_time": "2025-05-23T02:54:25.193898Z"
229231
}
230232
},
231233
"cell_type": "code",
@@ -238,18 +240,18 @@
238240
"-6.743511664816526"
239241
]
240242
},
241-
"execution_count": 10,
243+
"execution_count": 42,
242244
"metadata": {},
243245
"output_type": "execute_result"
244246
}
245247
],
246-
"execution_count": 10
248+
"execution_count": 42
247249
},
248250
{
249251
"metadata": {
250252
"ExecuteTime": {
251-
"end_time": "2025-05-23T02:31:22.894478Z",
252-
"start_time": "2025-05-23T02:31:22.889858Z"
253+
"end_time": "2025-05-23T02:54:25.228763Z",
254+
"start_time": "2025-05-23T02:54:25.224367Z"
253255
}
254256
},
255257
"cell_type": "code",
@@ -262,18 +264,18 @@
262264
"6.743511664816526"
263265
]
264266
},
265-
"execution_count": 11,
267+
"execution_count": 43,
266268
"metadata": {},
267269
"output_type": "execute_result"
268270
}
269271
],
270-
"execution_count": 11
272+
"execution_count": 43
271273
},
272274
{
273275
"metadata": {
274276
"ExecuteTime": {
275-
"end_time": "2025-05-23T02:31:22.942622Z",
276-
"start_time": "2025-05-23T02:31:22.937046Z"
277+
"end_time": "2025-05-23T02:54:25.264697Z",
278+
"start_time": "2025-05-23T02:54:25.260233Z"
277279
}
278280
},
279281
"cell_type": "code",
@@ -323,13 +325,13 @@
323325
]
324326
}
325327
],
326-
"execution_count": 12
328+
"execution_count": 44
327329
},
328330
{
329331
"metadata": {
330332
"ExecuteTime": {
331-
"end_time": "2025-05-23T02:31:22.977499Z",
332-
"start_time": "2025-05-23T02:31:22.971711Z"
333+
"end_time": "2025-05-23T02:54:25.286790Z",
334+
"start_time": "2025-05-23T02:54:25.282897Z"
333335
}
334336
},
335337
"cell_type": "code",
@@ -361,13 +363,13 @@
361363
]
362364
}
363365
],
364-
"execution_count": 13
366+
"execution_count": 45
365367
},
366368
{
367369
"metadata": {
368370
"ExecuteTime": {
369-
"end_time": "2025-05-23T02:31:23.015658Z",
370-
"start_time": "2025-05-23T02:31:23.010172Z"
371+
"end_time": "2025-05-23T02:54:25.315781Z",
372+
"start_time": "2025-05-23T02:54:25.311063Z"
371373
}
372374
},
373375
"cell_type": "code",
@@ -399,17 +401,21 @@
399401
]
400402
}
401403
],
402-
"execution_count": 14
404+
"execution_count": 46
403405
},
404406
{
405407
"metadata": {
406408
"ExecuteTime": {
407-
"end_time": "2025-05-23T02:31:23.043840Z",
408-
"start_time": "2025-05-23T02:31:23.039172Z"
409+
"end_time": "2025-05-23T02:54:25.345988Z",
410+
"start_time": "2025-05-23T02:54:25.341966Z"
409411
}
410412
},
411413
"cell_type": "code",
412-
"source": "swap.payer_side_profits(value_dt, zero_curve,8,-0.004)",
414+
"source": [
415+
"payment_periods=8\n",
416+
"swap_rate_changes=-0.004\n",
417+
"swap.payer_side_profits(value_dt, zero_curve,payment_periods,swap_rate_changes)"
418+
],
413419
"id": "5ef5f29ad5dfad00",
414420
"outputs": [
415421
{
@@ -418,12 +424,84 @@
418424
"-404610.6998889916"
419425
]
420426
},
421-
"execution_count": 15,
427+
"execution_count": 47,
428+
"metadata": {},
429+
"output_type": "execute_result"
430+
}
431+
],
432+
"execution_count": 47
433+
},
434+
{
435+
"metadata": {
436+
"ExecuteTime": {
437+
"end_time": "2025-05-23T02:54:25.433818Z",
438+
"start_time": "2025-05-23T02:54:25.427828Z"
439+
}
440+
},
441+
"cell_type": "code",
442+
"source": "swap.receiver_side_profits(value_dt, zero_curve,payment_periods,swap_rate_changes)",
443+
"id": "11109a6f2da7b7dc",
444+
"outputs": [
445+
{
446+
"data": {
447+
"text/plain": [
448+
"404610.6998889916"
449+
]
450+
},
451+
"execution_count": 48,
452+
"metadata": {},
453+
"output_type": "execute_result"
454+
}
455+
],
456+
"execution_count": 48
457+
},
458+
{
459+
"metadata": {
460+
"ExecuteTime": {
461+
"end_time": "2025-05-23T02:54:25.518531Z",
462+
"start_time": "2025-05-23T02:54:25.513863Z"
463+
}
464+
},
465+
"cell_type": "code",
466+
"source": "swap.payer_side_BPV(value_dt, zero_curve,payment_periods)",
467+
"id": "a4c532a9a90b445c",
468+
"outputs": [
469+
{
470+
"data": {
471+
"text/plain": [
472+
"-40461.06998889916"
473+
]
474+
},
475+
"execution_count": 49,
476+
"metadata": {},
477+
"output_type": "execute_result"
478+
}
479+
],
480+
"execution_count": 49
481+
},
482+
{
483+
"metadata": {
484+
"ExecuteTime": {
485+
"end_time": "2025-05-23T02:54:25.578843Z",
486+
"start_time": "2025-05-23T02:54:25.574712Z"
487+
}
488+
},
489+
"cell_type": "code",
490+
"source": "swap.receiver_side_BPV(value_dt, zero_curve,payment_periods)",
491+
"id": "8f8630e90883e3b5",
492+
"outputs": [
493+
{
494+
"data": {
495+
"text/plain": [
496+
"40461.06998889916"
497+
]
498+
},
499+
"execution_count": 50,
422500
"metadata": {},
423501
"output_type": "execute_result"
424502
}
425503
],
426-
"execution_count": 15
504+
"execution_count": 50
427505
}
428506
],
429507
"metadata": {

0 commit comments

Comments
 (0)