Skip to content

Commit e38db05

Browse files
committed
Renamed G_DAYS_IN_YEARS TO G_DAYS_IN_YEAR
1 parent b0a9c0b commit e38db05

File tree

91 files changed

+3278
-3362
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+3278
-3362
lines changed

financepy/market/curves/discount_curve.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from ...utils.date import Date
1010
from ...utils.error import FinError
11-
from ...utils.global_vars import G_DAYS_IN_YEARS, G_SMALL
11+
from ...utils.global_vars import G_DAYS_IN_YEAR, G_SMALL
1212
from ...utils.frequency import annual_frequency, FrequencyTypes
1313
from ...utils.day_count import DayCount, DayCountTypes
1414
from ...utils.math import test_monotonicity
@@ -64,7 +64,7 @@ def __init__(
6464
start_index = 1
6565

6666
for i in range(start_index, num_points):
67-
t = (df_dates[i] - value_dt) / G_DAYS_IN_YEARS
67+
t = (df_dates[i] - value_dt) / G_DAYS_IN_YEAR
6868
self._times.append(t)
6969
self._dfs.append(df_values[i])
7070

@@ -395,7 +395,7 @@ def fwd(self, dts: Date):
395395

396396
df1 = self.df(dts)
397397
df2 = self.df(dts_plus_one_days)
398-
dt = 1.0 / G_DAYS_IN_YEARS
398+
dt = 1.0 / G_DAYS_IN_YEAR
399399
fwd = np.log(df1 / df2) / (1.0 * dt)
400400

401401
if isinstance(dts, Date):

financepy/market/volatility/equity_vol_surface.py

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from ...utils.error import FinError
1414
from ...utils.date import Date
15-
from ...utils.global_vars import G_DAYS_IN_YEARS
15+
from ...utils.global_vars import G_DAYS_IN_YEAR
1616
from ...utils.global_types import OptionTypes
1717
from ...models.option_implied_dbn import option_implied_dbn
1818
from ...utils.helpers import check_argument_types, label_to_string
@@ -152,11 +152,7 @@ def _solve_to_horizon(
152152
fastmath=True,
153153
)
154154
def vol_function(
155-
vol_function_type_value: int,
156-
params: np.ndarray,
157-
f: float,
158-
k: float,
159-
t: float
155+
vol_function_type_value: int, params: np.ndarray, f: float, k: float, t: float
160156
) -> float:
161157
"""Return the volatility for a strike using a given polynomial
162158
interpolation following Section 3.9 of Iain Clark book."""
@@ -327,7 +323,7 @@ def vol_from_strike_dt(self, k: float, expiry_dt: Date) -> float:
327323
interpolation is done in variance space and then converted back to a
328324
lognormal volatility."""
329325

330-
t_exp = (expiry_dt - self.value_dt) / G_DAYS_IN_YEARS
326+
t_exp = (expiry_dt - self.value_dt) / G_DAYS_IN_YEAR
331327

332328
vol_type_value = self._vol_func_type.value
333329

@@ -402,7 +398,7 @@ def vol_from_strike_dt(self, k: float, expiry_dt: Date) -> float:
402398
# """ Interpolates the strike at a delta and expiry date. Linear
403399
# interpolation is used in strike."""
404400

405-
# t_exp = (expiry_dt - self.value_dt) / G_DAYS_IN_YEARS
401+
# t_exp = (expiry_dt - self.value_dt) / G_DAYS_IN_YEAR
406402

407403
# vol_type_value = self._vol_func_type.value
408404

@@ -497,7 +493,7 @@ def vol_from_delta_date(
497493
self,
498494
call_delta: float,
499495
expiry_dt: Date,
500-
delta_method = None,
496+
delta_method=None,
501497
) -> Tuple[float, float]:
502498
"""Interpolates the Black-Scholes volatility from the volatility
503499
surface given a call option delta and expiry date. Linear interpolation
@@ -509,7 +505,7 @@ def vol_from_delta_date(
509505
interpolation is done in variance space and then converted back to a
510506
lognormal volatility."""
511507

512-
t_exp = (expiry_dt - self.value_dt) / G_DAYS_IN_YEARS
508+
t_exp = (expiry_dt - self.value_dt) / G_DAYS_IN_YEAR
513509

514510
vol_type_value = self._vol_func_type.value
515511

@@ -611,7 +607,9 @@ def vol_from_delta_date(
611607

612608
####################################################################################
613609

614-
def _build_vol_surface(self, fin_solver_type: Any = FinSolverTypes.NELDER_MEAD) -> None:
610+
def _build_vol_surface(
611+
self, fin_solver_type: Any = FinSolverTypes.NELDER_MEAD
612+
) -> None:
615613
"""Main function to construct the vol surface."""
616614

617615
s = self._stock_price
@@ -666,7 +664,7 @@ def _build_vol_surface(self, fin_solver_type: Any = FinSolverTypes.NELDER_MEAD)
666664
for i in range(0, num_expiry_dts):
667665

668666
expiry_dt = self._expiry_dts[i]
669-
t_exp = (expiry_dt - spot_dt) / G_DAYS_IN_YEARS
667+
t_exp = (expiry_dt - spot_dt) / G_DAYS_IN_YEAR
670668

671669
dis_df = self._discount_curve.df_t(t_exp)
672670
div_df = self._dividend_curve.df_t(t_exp)
@@ -756,10 +754,7 @@ def check_calibration(self, verbose: bool) -> None:
756754
####################################################################################
757755

758756
def implied_dbns(
759-
self,
760-
low_s: float,
761-
high_s: float,
762-
num_intervals: int
757+
self, low_s: float, high_s: float, num_intervals: int
763758
) -> List[FinDistribution]:
764759
"""Calculate the pdf for each tenor horizon. Returns a list of
765760
FinDistribution objects, one for each tenor horizon."""

financepy/market/volatility/fx_vol_surface.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from ...utils.error import FinError
1616
from ...utils.date import Date
1717
from ...utils.tenor import Tenor
18-
from ...utils.global_vars import G_DAYS_IN_YEARS
18+
from ...utils.global_vars import G_DAYS_IN_YEAR
1919
from ...utils.global_types import OptionTypes
2020
from ...products.fx.fx_vanilla_option import FXVanillaOption
2121
from ...models.option_implied_dbn import option_implied_dbn
@@ -189,7 +189,7 @@ def solve_to_horizon_fast(
189189
rr_25d_vol: float,
190190
delta_method_value: int,
191191
vol_type_value: int,
192-
xopt: Sequence[float]
192+
xopt: Sequence[float],
193193
) -> Tuple[np.ndarray, float, float, float, float]:
194194

195195
c0 = xopt
@@ -295,11 +295,7 @@ def solve_to_horizon_fast(
295295
fastmath=True,
296296
)
297297
def vol_function(
298-
vol_function_type_value: int,
299-
params: np.ndarray,
300-
f: float,
301-
k: float,
302-
t: float
298+
vol_function_type_value: int, params: np.ndarray, f: float, k: float, t: float
303299
) -> float:
304300
"""Return the volatility for a strike using a given polynomial
305301
interpolation following Section 3.9 of Iain Clark book."""
@@ -386,7 +382,7 @@ def solver_for_smile_strike_fast(
386382
delta_target: float,
387383
delta_method_value: int,
388384
initial_guess: float,
389-
parameters: np.ndarray
385+
parameters: np.ndarray,
390386
) -> float:
391387
"""Solve for the strike that sets the delta of the option equal to the
392388
target value of delta allowing the volatility to be a function of the
@@ -426,7 +422,7 @@ def solve_for_strike(
426422
opt_type_value: int,
427423
delta_target: float,
428424
delta_method_value: int,
429-
volatility: float
425+
volatility: float,
430426
) -> float:
431427
"""This function determines the implied strike of an FX option
432428
given a delta and the other option details. It uses a one-dimensional
@@ -623,7 +619,7 @@ def volatility(self, k: float, expiry_dt: Date) -> float:
623619
index0 = 0
624620
index1 = 0
625621

626-
t = (expiry_dt - self.value_dt) / G_DAYS_IN_YEARS
622+
t = (expiry_dt - self.value_dt) / G_DAYS_IN_YEAR
627623

628624
num_curves = self.num_vol_curves
629625

@@ -722,7 +718,7 @@ def build_vol_surface(self) -> None:
722718
for i in range(0, num_vol_curves):
723719

724720
expiry_dt = self.expiry_dts[i]
725-
t_exp = (expiry_dt - spot_dt) / G_DAYS_IN_YEARS
721+
t_exp = (expiry_dt - spot_dt) / G_DAYS_IN_YEAR
726722

727723
dom_df = self.domestic_curve.df_t(t_exp)
728724
for_df = self.foreign_curve.df_t(t_exp)
@@ -859,7 +855,7 @@ def solver_for_smile_strike(
859855
opt_type_value: int,
860856
delta_target: float,
861857
tenor_index: int,
862-
initial_value: float
858+
initial_value: float,
863859
) -> float:
864860
"""Solve for the strike that sets the delta of the option equal to the
865861
target value of delta allowing the volatility to be a function of the
@@ -1259,10 +1255,7 @@ def check_calibration(self, verbose: bool, tol: float = 1e-5) -> None:
12591255
###########################################################################
12601256

12611257
def implied_dbns(
1262-
self,
1263-
low_fx: float,
1264-
high_fx: float,
1265-
num_intervals: int
1258+
self, low_fx: float, high_fx: float, num_intervals: int
12661259
) -> List[FinDistribution]:
12671260
"""Calculate the pdf for each tenor horizon. Returns a list of
12681261
FinDistribution objects, one for each tenor horizon."""

financepy/market/volatility/fx_vol_surface_plus.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
from ...utils.error import FinError
1717
from ...utils.date import Date
18-
from ...utils.global_vars import G_DAYS_IN_YEARS
18+
from ...utils.global_vars import G_DAYS_IN_YEAR
1919
from ...utils.global_types import OptionTypes
2020
from ...products.fx.fx_vanilla_option import FXVanillaOption
2121
from ...models.option_implied_dbn import option_implied_dbn
@@ -88,11 +88,7 @@ def _g(kk: float, *args: Any) -> float:
8888

8989

9090
@njit(float64(float64, float64[:], float64[:]), fastmath=True, cache=True)
91-
def _interpolate_gap(
92-
k: float,
93-
strikes: np.ndarray,
94-
gaps: np.ndarray
95-
) -> float:
91+
def _interpolate_gap(k: float, strikes: np.ndarray, gaps: np.ndarray) -> float:
9692

9793
if k <= strikes[0]:
9894
return 0.0
@@ -609,8 +605,20 @@ def _solve_to_horizon(
609605
x_inits: Sequence[float],
610606
ginits: Sequence[float],
611607
fin_solver_type: Any,
612-
tol: float
613-
) -> Tuple[np.ndarray, np.ndarray, np.ndarray, float, float, float, float, float, float, float, float]:
608+
tol: float,
609+
) -> Tuple[
610+
np.ndarray,
611+
np.ndarray,
612+
np.ndarray,
613+
float,
614+
float,
615+
float,
616+
float,
617+
float,
618+
float,
619+
float,
620+
float,
621+
]:
614622

615623
###########################################################################
616624
# Determine the price of a market strangle from market strangle
@@ -951,7 +959,7 @@ def vol_function(
951959
gaps: np.ndarray,
952960
f: float,
953961
k: float,
954-
t: float
962+
t: float,
955963
) -> float:
956964
"""Return the volatility for a strike using a given polynomial
957965
interpolation following Section 3.9 of Iain Clark book."""
@@ -1059,7 +1067,7 @@ def _solver_for_smile_strike(
10591067
initial_guess: float,
10601068
parameters: np.ndarray,
10611069
strikes: np.ndarray,
1062-
gaps: np.ndarray
1070+
gaps: np.ndarray,
10631071
) -> float:
10641072
"""Solve for the strike that sets the delta of the option equal to the
10651073
target value of delta allowing the volatility to be a function of the
@@ -1103,7 +1111,7 @@ def solve_for_strike(
11031111
opt_type_value: int,
11041112
delta_target: float,
11051113
delta_method_value: int,
1106-
volatility: float
1114+
volatility: float,
11071115
) -> float:
11081116
"""This function determines the implied strike of an FX option
11091117
given a delta and the other option details. It uses a one-dimensional
@@ -1362,7 +1370,7 @@ def vol_from_strike_dt(self, kk: float, expiry_dt: Date) -> float:
13621370
interpolation is done in variance space and then converted back to a
13631371
lognormal volatility."""
13641372

1365-
t_exp = (expiry_dt - self.value_dt) / G_DAYS_IN_YEARS
1373+
t_exp = (expiry_dt - self.value_dt) / G_DAYS_IN_YEAR
13661374

13671375
vol_type_value = self.vol_func_type.value
13681376

@@ -1450,15 +1458,12 @@ def vol_from_strike_dt(self, kk: float, expiry_dt: Date) -> float:
14501458
###########################################################################
14511459

14521460
def delta_to_strike(
1453-
self,
1454-
call_delta: float,
1455-
expiry_dt: Date,
1456-
delta_method: Optional[Any]
1461+
self, call_delta: float, expiry_dt: Date, delta_method: Optional[Any]
14571462
) -> float:
14581463
"""Interpolates the strike at a delta and expiry date. Linear
14591464
time to expiry interpolation is used in strike."""
14601465

1461-
t_exp = (expiry_dt - self.value_dt) / G_DAYS_IN_YEARS
1466+
t_exp = (expiry_dt - self.value_dt) / G_DAYS_IN_YEAR
14621467

14631468
vol_type_value = self.vol_func_type.value
14641469

@@ -1562,7 +1567,7 @@ def vol_from_delta_date(
15621567
self,
15631568
call_delta: float,
15641569
expiry_dt: Date,
1565-
delta_method: Optional[FinFXDeltaMethod] = None
1570+
delta_method: Optional[FinFXDeltaMethod] = None,
15661571
) -> Tuple[float, float]:
15671572
"""Interpolates the Black-Scholes volatility from the volatility
15681573
surface given a call option delta and expiry date. Linear interpolation
@@ -1574,7 +1579,7 @@ def vol_from_delta_date(
15741579
interpolation is done in variance space and then converted back to a
15751580
lognormal volatility."""
15761581

1577-
t_exp = (expiry_dt - self.value_dt) / G_DAYS_IN_YEARS
1582+
t_exp = (expiry_dt - self.value_dt) / G_DAYS_IN_YEAR
15781583

15791584
vol_type_value = self.vol_func_type.value
15801585

@@ -1704,9 +1709,7 @@ def vol_from_delta_date(
17041709
###########################################################################
17051710

17061711
def _build_vol_surface(
1707-
self,
1708-
fin_solver_type: Any = FinSolverTypes.NELDER_MEAD,
1709-
tol: float = 1e-8
1712+
self, fin_solver_type: Any = FinSolverTypes.NELDER_MEAD, tol: float = 1e-8
17101713
) -> None:
17111714
"""Main function to construct the vol surface."""
17121715

@@ -1764,7 +1767,7 @@ def _build_vol_surface(
17641767
for i in range(0, num_vol_curves):
17651768

17661769
expiry_dt = self.expiry_dts[i]
1767-
t_exp = (expiry_dt - spot_dt) / G_DAYS_IN_YEARS
1770+
t_exp = (expiry_dt - spot_dt) / G_DAYS_IN_YEAR
17681771

17691772
dom_df = self.domestic_curve.df(expiry_dt)
17701773
for_df = self.foreign_curve.df(expiry_dt)
@@ -2609,10 +2612,7 @@ def check_calibration(self, verbose: bool, tol: float = 1e-6) -> None:
26092612
###########################################################################
26102613

26112614
def implied_dbns(
2612-
self,
2613-
low_fx: float,
2614-
high_fx: float,
2615-
num_intervals: int
2615+
self, low_fx: float, high_fx: float, num_intervals: int
26162616
) -> List[FinDistribution]:
26172617
"""Calculate the pdf for each tenor horizon. Returns a list of
26182618
FinDistribution objects, one for each tenor horizon."""

financepy/market/volatility/ibor_cap_vol_curve.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from ...utils.error import FinError
88
from ...utils.date import Date
99
from ...utils.helpers import label_to_string
10-
from ...utils.global_vars import G_DAYS_IN_YEARS
10+
from ...utils.global_vars import G_DAYS_IN_YEAR
1111
from ...utils.day_count import DayCount, DayCountTypes
1212

1313
# TODO: Calibration
@@ -19,6 +19,7 @@
1919

2020
from typing import Any, Sequence, Union
2121

22+
2223
class IborCapVolCurve:
2324
"""Class to manage a term structure of cap (flat) volatilities and to
2425
do the conversion to caplet (spot) volatilities. This does not manage a
@@ -98,7 +99,7 @@ def generate_caplet_vols(self) -> None:
9899
num_caps = len(self._cap_maturity_dts)
99100

100101
for dt in self._cap_maturity_dts:
101-
t = (dt - self._curve_dt) / G_DAYS_IN_YEARS
102+
t = (dt - self._curve_dt) / G_DAYS_IN_YEAR
102103
self.times.append(t)
103104
tau = day_counter.year_frac(prev_dt, dt)[0]
104105
self._taus.append(tau)
@@ -133,7 +134,7 @@ def caplet_vol(self, dt: Union[Any, float]) -> float:
133134
The volatility interpolation is piecewise flat."""
134135

135136
if isinstance(dt, Date):
136-
t = (dt - self._curve_dt) / G_DAYS_IN_YEARS
137+
t = (dt - self._curve_dt) / G_DAYS_IN_YEAR
137138
else:
138139
t = dt
139140

@@ -164,7 +165,7 @@ def cap_vol(self, dt: Union[Any, float]) -> float:
164165
is piecewise flat."""
165166

166167
if isinstance(dt, Date):
167-
t = (dt - self._curve_dt) / G_DAYS_IN_YEARS
168+
t = (dt - self._curve_dt) / G_DAYS_IN_YEAR
168169
else:
169170
t = dt
170171

0 commit comments

Comments
 (0)