|
1 | | -def SWExtrapolate(M_Target, M_Obs, b, ufr, alpha): |
| 1 | +import numpy as np |
| 2 | + |
| 3 | +def SWExtrapolate(M_Target: np.ndarray, M_Obs: np.ndarray, b: np.ndarray, ufr: float, alpha:float)->np.ndarray: |
2 | 4 | """ |
3 | | - Interpolate or extrapolate rates for targeted maturities using the Smith-Wilson algorithm. |
| 5 | + Interpolate or extrapolate rates for targeted maturities using the Smith-Wilson algorithm. |
| 6 | +
|
| 7 | + Calculates the rates for maturities specified in `M_Target` using the calibration vector `b` obtained |
| 8 | + from observed bond maturities in `M_Obs`. |
4 | 9 |
|
5 | | - Calculates the rates for maturities specified in `M_Target` using the calibration vector `b` obtained |
6 | | - from observed bond maturities in `M_Obs`. |
| 10 | + Arguments: |
| 11 | + M_Target: k x 1 ndarray representing each targeted bond maturity of interest. Example: M_Target = np.array([[1], [2], [3], [5]]) |
| 12 | + M_Obs: n x 1 ndarray representing the observed bond maturities used for calibrating the calibration vector `b`. Example: M_Obs = np.array([[1], [3]]) |
| 13 | + b: n x 1 ndarray representing the calibration vector calculated on observed bonds. |
| 14 | + ufr: Floating number representing the ultimate forward rate. Example: ufr = 0.042 |
| 15 | + alpha: Floating number representing the convergence speed parameter alpha. Example: alpha = 0.05 |
7 | 16 |
|
8 | | - Arguments: |
9 | | - M_Target: k x 1 ndarray representing each targeted bond maturity of interest. Example: M_Target = np.array([[1], [2], [3], [5]]) |
10 | | - M_Obs: n x 1 ndarray representing the observed bond maturities used for calibrating the calibration vector `b`. Example: M_Obs = np.array([[1], [3]]) |
11 | | - b: n x 1 ndarray representing the calibration vector calculated on observed bonds. |
12 | | - ufr: Floating number representing the ultimate forward rate. Example: ufr = 0.042 |
13 | | - alpha: Floating number representing the convergence speed parameter alpha. Example: alpha = 0.05 |
| 17 | + Returns: |
| 18 | + k x 1 ndarray representing the targeted rates for zero-coupon bonds. Each rate belongs to a targeted |
| 19 | + zero-coupon bond with a maturity from `M_Target`. Example: r = np.array([0.0024, 0.0029, 0.0034, 0.0039]) |
| 20 | +
|
| 21 | + For more information, refer to the documentation at: |
| 22 | + https://www.eiopa.europa.eu/sites/default/files/risk_free_interest_rate/12092019-technical_documentation.pdf |
| 23 | + """ |
14 | 24 |
|
15 | | - Returns: |
16 | | - k x 1 ndarray representing the targeted rates for zero-coupon bonds. Each rate belongs to a targeted |
17 | | - zero-coupon bond with a maturity from `M_Target`. Example: r = np.array([0.0024, 0.0029, 0.0034, 0.0039]) |
| 25 | + from SWHeart import SWHeart as SWHeart |
18 | 26 |
|
19 | | - For more information, refer to the documentation at: |
20 | | - https://www.eiopa.europa.eu/sites/default/files/risk_free_interest_rate/12092019-technical_documentation.pdf |
21 | | - """ |
22 | | - |
23 | | - import numpy as np |
24 | | - from SWHeart import SWHeart as SWHeart |
25 | | - C = np.identity(M_Obs.size) |
26 | | - d = np.exp(-np.log(1+ufr) * M_Obs) # Calculate vector d described in paragraph 138 |
27 | | - Q = np.diag(d) @ C # Matrix Q described in paragraph 139 |
28 | | - H = SWHeart(M_Target, M_Obs, alpha) # Heart of the Wilson function from paragraph 132 |
29 | | - p = np.exp(-np.log(1+ufr)* M_Target) + np.diag(np.exp(-np.log(1+ufr) * M_Target)) @ H @ Q @ b # Discount pricing function for targeted maturities from paragraph 147 |
30 | | - return p ** (-1/ M_Target) -1 # Convert obtained prices to rates and return prices |
| 27 | + C = np.identity(M_Obs.size) |
| 28 | + d = np.exp(-np.log(1+ufr) * M_Obs) # Calculate vector d described in paragraph 138 |
| 29 | + Q = np.diag(d) @ C # Matrix Q described in paragraph 139 |
| 30 | + H = SWHeart(M_Target, M_Obs, alpha) # Heart of the Wilson function from paragraph 132 |
| 31 | + p = np.exp(-np.log(1+ufr)* M_Target) + np.diag(np.exp(-np.log(1+ufr) * M_Target)) @ H @ Q @ b # Discount pricing function for targeted maturities from paragraph 147 |
| 32 | + return p ** (-1/ M_Target) -1 # Convert obtained prices to rates and return prices |
0 commit comments