|
6 | 6 | "metadata": { |
7 | 7 | "collapsed": true, |
8 | 8 | "ExecuteTime": { |
9 | | - "end_time": "2025-05-23T02:25:34.603675Z", |
10 | | - "start_time": "2025-05-23T02:25:34.599467Z" |
| 9 | + "end_time": "2025-05-23T02:31:22.631355Z", |
| 10 | + "start_time": "2025-05-23T02:31:22.625849Z" |
11 | 11 | } |
12 | 12 | }, |
13 | 13 | "source": [ |
|
17 | 17 | "import datetime as dt" |
18 | 18 | ], |
19 | 19 | "outputs": [], |
20 | | - "execution_count": 16 |
| 20 | + "execution_count": 2 |
21 | 21 | }, |
22 | 22 | { |
23 | 23 | "metadata": { |
24 | 24 | "ExecuteTime": { |
25 | | - "end_time": "2025-05-23T02:25:34.630084Z", |
26 | | - "start_time": "2025-05-23T02:25:34.621619Z" |
| 25 | + "end_time": "2025-05-23T02:31:22.679560Z", |
| 26 | + "start_time": "2025-05-23T02:31:22.657680Z" |
27 | 27 | } |
28 | 28 | }, |
29 | 29 | "cell_type": "code", |
|
63 | 63 | ], |
64 | 64 | "id": "1ebf43316efee835", |
65 | 65 | "outputs": [], |
66 | | - "execution_count": 17 |
| 66 | + "execution_count": 3 |
67 | 67 | }, |
68 | 68 | { |
69 | 69 | "metadata": { |
70 | 70 | "ExecuteTime": { |
71 | | - "end_time": "2025-05-23T02:25:34.640874Z", |
72 | | - "start_time": "2025-05-23T02:25:34.636086Z" |
| 71 | + "end_time": "2025-05-23T02:31:22.694667Z", |
| 72 | + "start_time": "2025-05-23T02:31:22.687165Z" |
73 | 73 | } |
74 | 74 | }, |
75 | 75 | "cell_type": "code", |
|
89 | 89 | "31-MAR-2024" |
90 | 90 | ] |
91 | 91 | }, |
92 | | - "execution_count": 18, |
| 92 | + "execution_count": 4, |
93 | 93 | "metadata": {}, |
94 | 94 | "output_type": "execute_result" |
95 | 95 | } |
96 | 96 | ], |
97 | | - "execution_count": 18 |
| 97 | + "execution_count": 4 |
98 | 98 | }, |
99 | 99 | { |
100 | 100 | "metadata": { |
101 | 101 | "ExecuteTime": { |
102 | | - "end_time": "2025-05-23T02:25:34.675868Z", |
103 | | - "start_time": "2025-05-23T02:25:34.663679Z" |
| 102 | + "end_time": "2025-05-23T02:31:22.727011Z", |
| 103 | + "start_time": "2025-05-23T02:31:22.719602Z" |
104 | 104 | } |
105 | 105 | }, |
106 | 106 | "cell_type": "code", |
|
123 | 123 | ], |
124 | 124 | "id": "290b7a06932da41d", |
125 | 125 | "outputs": [], |
126 | | - "execution_count": 19 |
| 126 | + "execution_count": 5 |
127 | 127 | }, |
128 | 128 | { |
129 | 129 | "metadata": { |
130 | 130 | "ExecuteTime": { |
131 | | - "end_time": "2025-05-23T02:25:34.693421Z", |
132 | | - "start_time": "2025-05-23T02:25:34.686347Z" |
| 131 | + "end_time": "2025-05-23T02:31:22.746919Z", |
| 132 | + "start_time": "2025-05-23T02:31:22.739589Z" |
133 | 133 | } |
134 | 134 | }, |
135 | 135 | "cell_type": "code", |
|
142 | 142 | "0.030065619962567392" |
143 | 143 | ] |
144 | 144 | }, |
145 | | - "execution_count": 20, |
| 145 | + "execution_count": 6, |
146 | 146 | "metadata": {}, |
147 | 147 | "output_type": "execute_result" |
148 | 148 | } |
149 | 149 | ], |
150 | | - "execution_count": 20 |
| 150 | + "execution_count": 6 |
151 | 151 | }, |
152 | 152 | { |
153 | 153 | "metadata": { |
154 | 154 | "ExecuteTime": { |
155 | | - "end_time": "2025-05-23T02:25:34.722494Z", |
156 | | - "start_time": "2025-05-23T02:25:34.715862Z" |
157 | | - } |
158 | | - }, |
159 | | - "cell_type": "code", |
160 | | - "source": [ |
161 | | - "# def payer_side_macaulay_duration(value_dt, discount_curve):\n", |
162 | | - "# \"\"\"Calculation of the Payer's Macaulay Duration in an Interest Rate Swap\n", |
163 | | - "# Based on Bond Math: The Theory Behind the Formulas, Second Edition by\n", |
164 | | - "# Donald J. Smith\n", |
165 | | - "# \"\"\"\n", |
166 | | - "# # Number of fixed leg payments\n", |
167 | | - "# payment_period = len(swap.fixed_leg.payments)\n", |
168 | | - "#\n", |
169 | | - "# # Get coupon frequency\n", |
170 | | - "# coupon_frequency = self.fixed_leg.freq_type.value\n", |
171 | | - "#\n", |
172 | | - "# # Get swap rate\n", |
173 | | - "# swap_rate_val = self.swap_rate(value_dt, discount_curve)\n", |
174 | | - "#\n", |
175 | | - "# y = swap_rate_val / coupon_frequency\n", |
176 | | - "# N = payment_period\n", |
177 | | - "# c = swap_rate_val / coupon_frequency\n", |
178 | | - "# md1 = (1 + y) / y\n", |
179 | | - "# md2 = 1 + y + (N * (c - y))\n", |
180 | | - "# md3 = c * ((1 + y) ** N - 1) + y\n", |
181 | | - "# mac_duration = 1 - (md1 - md2 / md3)\n", |
182 | | - "# return mac_duration\n", |
183 | | - "\n", |
184 | | - "\n", |
185 | | - "payment_period = len(swap.fixed_leg.payments) + 1\n", |
186 | | - "coupon_frequency = swap.fixed_leg.freq_type.value\n", |
187 | | - "swap_rate_val = swap.swap_rate(value_dt, zero_curve)\n", |
188 | | - "y = swap_rate_val / coupon_frequency\n", |
189 | | - "N = payment_period\n", |
190 | | - "c = swap_rate_val / coupon_frequency\n", |
191 | | - "md1 = (1 + y) / y\n", |
192 | | - "md2 = 1 + y + (N * (c - y))\n", |
193 | | - "md3 = c * ((1 + y) ** N - 1) + y\n", |
194 | | - "mac_duration = 1 - (md1 - md2 / md3)\n", |
195 | | - "\n", |
196 | | - "delta_mv=-(-mac_duration/4*notional*(-0.004))" |
197 | | - ], |
198 | | - "id": "65a401442f9bf084", |
199 | | - "outputs": [], |
200 | | - "execution_count": 21 |
201 | | - }, |
202 | | - { |
203 | | - "metadata": { |
204 | | - "ExecuteTime": { |
205 | | - "end_time": "2025-05-23T02:25:34.740382Z", |
206 | | - "start_time": "2025-05-23T02:25:34.734050Z" |
| 155 | + "end_time": "2025-05-23T02:31:22.765913Z", |
| 156 | + "start_time": "2025-05-23T02:31:22.759349Z" |
207 | 157 | } |
208 | 158 | }, |
209 | 159 | "cell_type": "code", |
|
216 | 166 | "-404094.769553849" |
217 | 167 | ] |
218 | 168 | }, |
219 | | - "execution_count": 22, |
| 169 | + "execution_count": 7, |
220 | 170 | "metadata": {}, |
221 | 171 | "output_type": "execute_result" |
222 | 172 | } |
223 | 173 | ], |
224 | | - "execution_count": 22 |
| 174 | + "execution_count": 7 |
225 | 175 | }, |
226 | 176 | { |
227 | 177 | "metadata": { |
228 | 178 | "ExecuteTime": { |
229 | | - "end_time": "2025-05-23T02:25:34.769581Z", |
230 | | - "start_time": "2025-05-23T02:25:34.763504Z" |
| 179 | + "end_time": "2025-05-23T02:31:22.784960Z", |
| 180 | + "start_time": "2025-05-23T02:31:22.779808Z" |
231 | 181 | } |
232 | 182 | }, |
233 | 183 | "cell_type": "code", |
|
240 | 190 | "-6.794198629548404" |
241 | 191 | ] |
242 | 192 | }, |
243 | | - "execution_count": 23, |
| 193 | + "execution_count": 8, |
244 | 194 | "metadata": {}, |
245 | 195 | "output_type": "execute_result" |
246 | 196 | } |
247 | 197 | ], |
248 | | - "execution_count": 23 |
| 198 | + "execution_count": 8 |
249 | 199 | }, |
250 | 200 | { |
251 | 201 | "metadata": { |
252 | 202 | "ExecuteTime": { |
253 | | - "end_time": "2025-05-23T02:25:34.803424Z", |
254 | | - "start_time": "2025-05-23T02:25:34.798626Z" |
| 203 | + "end_time": "2025-05-23T02:31:22.817161Z", |
| 204 | + "start_time": "2025-05-23T02:31:22.812093Z" |
255 | 205 | } |
256 | 206 | }, |
257 | 207 | "cell_type": "code", |
|
264 | 214 | "6.794198629548404" |
265 | 215 | ] |
266 | 216 | }, |
267 | | - "execution_count": 24, |
| 217 | + "execution_count": 9, |
268 | 218 | "metadata": {}, |
269 | 219 | "output_type": "execute_result" |
270 | 220 | } |
271 | 221 | ], |
272 | | - "execution_count": 24 |
| 222 | + "execution_count": 9 |
273 | 223 | }, |
274 | 224 | { |
275 | 225 | "metadata": { |
276 | 226 | "ExecuteTime": { |
277 | | - "end_time": "2025-05-23T02:25:34.836332Z", |
278 | | - "start_time": "2025-05-23T02:25:34.831799Z" |
| 227 | + "end_time": "2025-05-23T02:31:22.858301Z", |
| 228 | + "start_time": "2025-05-23T02:31:22.853154Z" |
279 | 229 | } |
280 | 230 | }, |
281 | 231 | "cell_type": "code", |
|
288 | 238 | "-6.743511664816526" |
289 | 239 | ] |
290 | 240 | }, |
291 | | - "execution_count": 25, |
| 241 | + "execution_count": 10, |
292 | 242 | "metadata": {}, |
293 | 243 | "output_type": "execute_result" |
294 | 244 | } |
295 | 245 | ], |
296 | | - "execution_count": 25 |
| 246 | + "execution_count": 10 |
297 | 247 | }, |
298 | 248 | { |
299 | 249 | "metadata": { |
300 | 250 | "ExecuteTime": { |
301 | | - "end_time": "2025-05-23T02:25:34.864470Z", |
302 | | - "start_time": "2025-05-23T02:25:34.860289Z" |
| 251 | + "end_time": "2025-05-23T02:31:22.894478Z", |
| 252 | + "start_time": "2025-05-23T02:31:22.889858Z" |
303 | 253 | } |
304 | 254 | }, |
305 | 255 | "cell_type": "code", |
|
312 | 262 | "6.743511664816526" |
313 | 263 | ] |
314 | 264 | }, |
315 | | - "execution_count": 26, |
| 265 | + "execution_count": 11, |
316 | 266 | "metadata": {}, |
317 | 267 | "output_type": "execute_result" |
318 | 268 | } |
319 | 269 | ], |
320 | | - "execution_count": 26 |
| 270 | + "execution_count": 11 |
321 | 271 | }, |
322 | 272 | { |
323 | 273 | "metadata": { |
324 | 274 | "ExecuteTime": { |
325 | | - "end_time": "2025-05-23T02:25:34.895364Z", |
326 | | - "start_time": "2025-05-23T02:25:34.888381Z" |
| 275 | + "end_time": "2025-05-23T02:31:22.942622Z", |
| 276 | + "start_time": "2025-05-23T02:31:22.937046Z" |
327 | 277 | } |
328 | 278 | }, |
329 | 279 | "cell_type": "code", |
|
373 | 323 | ] |
374 | 324 | } |
375 | 325 | ], |
376 | | - "execution_count": 27 |
| 326 | + "execution_count": 12 |
377 | 327 | }, |
378 | 328 | { |
379 | 329 | "metadata": { |
380 | 330 | "ExecuteTime": { |
381 | | - "end_time": "2025-05-23T02:25:34.923991Z", |
382 | | - "start_time": "2025-05-23T02:25:34.918594Z" |
| 331 | + "end_time": "2025-05-23T02:31:22.977499Z", |
| 332 | + "start_time": "2025-05-23T02:31:22.971711Z" |
383 | 333 | } |
384 | 334 | }, |
385 | 335 | "cell_type": "code", |
|
411 | 361 | ] |
412 | 362 | } |
413 | 363 | ], |
414 | | - "execution_count": 28 |
| 364 | + "execution_count": 13 |
415 | 365 | }, |
416 | 366 | { |
417 | 367 | "metadata": { |
418 | 368 | "ExecuteTime": { |
419 | | - "end_time": "2025-05-23T02:25:35.017712Z", |
420 | | - "start_time": "2025-05-23T02:25:35.013394Z" |
| 369 | + "end_time": "2025-05-23T02:31:23.015658Z", |
| 370 | + "start_time": "2025-05-23T02:31:23.010172Z" |
421 | 371 | } |
422 | 372 | }, |
423 | 373 | "cell_type": "code", |
|
449 | 399 | ] |
450 | 400 | } |
451 | 401 | ], |
452 | | - "execution_count": 29 |
| 402 | + "execution_count": 14 |
453 | 403 | }, |
454 | 404 | { |
455 | 405 | "metadata": { |
456 | 406 | "ExecuteTime": { |
457 | | - "end_time": "2025-05-23T02:25:35.127867Z", |
458 | | - "start_time": "2025-05-23T02:25:35.115423Z" |
| 407 | + "end_time": "2025-05-23T02:31:23.043840Z", |
| 408 | + "start_time": "2025-05-23T02:31:23.039172Z" |
459 | 409 | } |
460 | 410 | }, |
461 | 411 | "cell_type": "code", |
462 | 412 | "source": "swap.payer_side_profits(value_dt, zero_curve,8,-0.004)", |
463 | 413 | "id": "5ef5f29ad5dfad00", |
464 | 414 | "outputs": [ |
465 | 415 | { |
466 | | - "ename": "AttributeError", |
467 | | - "evalue": "'IborSwap' object has no attribute 'payer_side_profits'", |
468 | | - "output_type": "error", |
469 | | - "traceback": [ |
470 | | - "\u001B[1;31m---------------------------------------------------------------------------\u001B[0m", |
471 | | - "\u001B[1;31mAttributeError\u001B[0m Traceback (most recent call last)", |
472 | | - "Cell \u001B[1;32mIn[30], line 1\u001B[0m\n\u001B[1;32m----> 1\u001B[0m \u001B[43mswap\u001B[49m\u001B[38;5;241;43m.\u001B[39;49m\u001B[43mpayer_side_profits\u001B[49m(value_dt, zero_curve,\u001B[38;5;241m8\u001B[39m,\u001B[38;5;241m-\u001B[39m\u001B[38;5;241m0.004\u001B[39m)\n", |
473 | | - "\u001B[1;31mAttributeError\u001B[0m: 'IborSwap' object has no attribute 'payer_side_profits'" |
474 | | - ] |
| 416 | + "data": { |
| 417 | + "text/plain": [ |
| 418 | + "-404610.6998889916" |
| 419 | + ] |
| 420 | + }, |
| 421 | + "execution_count": 15, |
| 422 | + "metadata": {}, |
| 423 | + "output_type": "execute_result" |
475 | 424 | } |
476 | 425 | ], |
477 | | - "execution_count": 30 |
| 426 | + "execution_count": 15 |
478 | 427 | } |
479 | 428 | ], |
480 | 429 | "metadata": { |
|
0 commit comments