Skip to content

Commit

Permalink
Test premiums green
Browse files Browse the repository at this point in the history
  • Loading branch information
ynouri committed May 24, 2018
1 parent 920268f commit 637bf57
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
18 changes: 0 additions & 18 deletions pysabr/examples/discount_factors.csv

This file was deleted.

18 changes: 18 additions & 0 deletions pysabr/examples/option_expiries.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Option_expiry,Year_frac
1D,0.002739726
1W,0.021917808
1M,0.084931507
2M,0.17260274
3M,0.246575342
6M,0.498630137
9M,0.750684932
1Y,1
1Y6M,1.498630137
2Y,2
3Y,3.008219178
5Y,5.002739726
7Y,7.005479452
10Y,10.00821918
15Y,15.01369863
20Y,20.01917808
30Y,30.01917808
16 changes: 8 additions & 8 deletions pysabr/tests/hagan_2002_lognormal_sabr/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pytest
import itertools
import pandas as pd
from pysabr.helpers import year_frac_from_maturity_label


# Path to vols, premiums and discount factors data
Expand All @@ -19,13 +18,13 @@
df_premiums.sort_index(inplace=True)

# Load discount factors
df_discount = pd.read_csv(PATH + 'discount_factors.csv')
df_option_expiries = pd.read_csv(PATH + 'option_expiries.csv')

# Cartesian product of all expiries and tenors
expiries = df_vols.index.levels[1]
tenors = df_vols.columns
all_points = list(itertools.product(*[expiries, tenors]))
# all_points = [('1Y', '10Y')] # for debugging
# all_points = [('1Y', '10Y'), ('1Y', '30Y'), ('9M', '10Y')] # for debugging
all_points_ids = ["{} into {}".format(e, t) for e, t in all_points]


Expand All @@ -41,12 +40,13 @@ def vol_cube(request):
df_vols.loc[idx[:, option_expiry], swap_tenor].
reset_index(level=1, drop=True)
)
expiry_year_frac = year_frac_from_maturity_label(option_expiry)
# Option expiry year fraction
i = df_option_expiries.Option_expiry == option_expiry
expiry_year_frac = df_option_expiries.loc[i].Year_frac.values[0]
# expiry_year_frac = year_frac_from_maturity_label(option_expiry)
vol_input = (p['Forward'], p['Shift'], expiry_year_frac,
p['Normal_ATM_vol'], p['Beta'], p['Rho'], p['Volvol'])
# Discount factor
df = df_discount[
df_discount['Option_expiry'] == '10Y'].Discount_factor.values[0]

# Target vols
vols_target = df_premiums.loc[
idx['SLN_vol', option_expiry, :], swap_tenor
Expand All @@ -56,4 +56,4 @@ def vol_cube(request):
idx['Call', option_expiry, :], swap_tenor
].reset_index(level=[0, 1], drop=True)
# Yields the tuple
yield (vol_input, df, vols_target, premiums_target)
yield (vol_input, vols_target, premiums_target)
6 changes: 3 additions & 3 deletions pysabr/tests/hagan_2002_lognormal_sabr/test_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@


N = 1e9 # We assume BPV = $100,000 (= 1e9 / 1e4)
MAX_ABS_ERROR_PREMIUM = 0.1 # Max absolute error on premium is $0.1
MAX_ABS_ERROR_PREMIUM = 10.0 # Max absolute error on premium is $10.0
MAX_ERROR_VOL = 0.0005 # Max error is 0.05%


def test_vols(vol_cube):
"""Test the full ATM SABR vol chain for Hagan's 2002 Lognormal model."""
logging.debug(vol_cube)
(f, s, t, v_atm_n, beta, rho, volvol), _, vols_target, _ = vol_cube
(f, s, t, v_atm_n, beta, rho, volvol), vols_target, _ = vol_cube
sabr = Hagan2002LognormalSABR(f/100, t, s/100, v_atm_n/1e4,
beta, rho, volvol)
strikes = vols_target.index
Expand All @@ -21,7 +21,7 @@ def test_vols(vol_cube):

def test_premiums(vol_cube):
"""Test the premiums."""
(f, s, t, v_atm_n, beta, rho, volvol), df, _, premiums_target = vol_cube
(f, s, t, v_atm_n, beta, rho, volvol), _, premiums_target = vol_cube
sabr = Hagan2002LognormalSABR(f/100, t, s/100, v_atm_n/1e4,
beta, rho, volvol)
strikes = premiums_target.index[premiums_target.index + s > 0.]
Expand Down

0 comments on commit 637bf57

Please sign in to comment.