Skip to content

Commit 757a193

Browse files
committed
Added new FXDoubleDigitalOption product
1 parent dfb8432 commit 757a193

19 files changed

+1045
-293
lines changed

.pylintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ load-plugins=
99
[MESSAGES CONTROL]
1010
# Start strict and tune over time; add/remove codes as you ratchet quality.
1111
disable=
12+
C0103, # missing-module-docstring
1213
C0114, # missing-module-docstring
1314
C0115, # missing-class-docstring
1415
C0116, # missing-function-docstring

financepy/market/curves/interpolator.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,14 @@ def interpolate(
6363

6464
raise FinError("Unknown input type" + type(t))
6565

66+
########################################################################################
6667

6768
@njit(
6869
float64(float64, float64[:], float64[:], int64),
6970
fastmath=True,
7071
cache=True,
7172
nogil=True,
7273
)
73-
74-
########################################################################################
75-
76-
7774
def _uinterpolate(t, times, dfs, method):
7875
"""Return the interpolated value of y given x and a vector of x and y.
7976
The values of x must be monotonic and increasing. The different schemes for
@@ -171,16 +168,14 @@ def _uinterpolate(t, times, dfs, method):
171168
raise FinError("Invalid interpolation scheme.")
172169

173170

171+
########################################################################################
172+
174173
@njit(
175174
float64[:](float64[:], float64[:], float64[:], int64),
176175
fastmath=True,
177176
cache=True,
178177
nogil=True,
179178
)
180-
181-
########################################################################################
182-
183-
184179
def _vinterpolate(x_values, x_vector, dfs, method):
185180
"""Return the interpolated values of y given x and a vector of x and y.
186181
The values of x must be monotonic and increasing. The different schemes for

financepy/products/credit/cds.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
########################################################################################
3636

3737

38+
3839
@njit(
3940
float64[:](
4041
float64,
@@ -280,7 +281,7 @@ def __init__(
280281
self._generate_adjusted_cds_payment_dts()
281282
self._calc_flows()
282283

283-
###########################################################################
284+
####################################################################################
284285

285286
def _generate_adjusted_cds_payment_dts(self):
286287
"""Generate CDS payment dates which have been holiday adjusted."""
@@ -300,13 +301,11 @@ def _generate_adjusted_cds_payment_dts(self):
300301
if self.dg_type == DateGenRuleTypes.BACKWARD:
301302

302303
# We start at end date and step backwards
303-
304304
next_dt = self.maturity_dt
305305

306306
unadjusted_schedule_dts.append(next_dt)
307307

308-
# the unadjusted dates start at end date and end at previous
309-
# cpn date
308+
# the unadjusted dates start at end date and end at previous cpn date
310309
while next_dt > start_dt:
311310
next_dt = next_dt.add_months(-num_months)
312311
unadjusted_schedule_dts.append(next_dt)
@@ -350,18 +349,15 @@ def _generate_adjusted_cds_payment_dts(self):
350349
# Accrual End = [19-MAY-2009, 19-AUG-2009, 19-NOV-2009, 20-MAR-2010]
351350

352351
else:
353-
354352
raise FinError("Unknown DateGenRuleType:" + str(self.dg_type))
355353

356354
# We only include dates which fall after the CDS start date
357355
self.payment_dts = adjusted_dts[1:]
358356

359-
# Accrual start dates run from previous cpn date to penultimate
360-
# cpn date
357+
# Accrual start dates run from previous cpn date to penultimate cpn date
361358
self.accrual_start_dts = adjusted_dts[:-1]
362359

363-
# Accrual end dates are one day before the start of the next
364-
# accrual period
360+
# Accrual end dates are one day before the start of the next accrual period
365361
self.accrual_end_dts = [
366362
date.add_days(-1) for date in self.accrual_start_dts[1:]
367363
]

financepy/products/credit/cds_curve.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
from ...utils.helpers import label_to_string
1717

1818

19+
from numba import njit, float64
20+
1921
########################################################################################
2022

2123

@@ -212,15 +214,18 @@ def build_curve(self):
212214
self._times = np.append(self._times, t_mat)
213215
self._qs = np.append(self._qs, q)
214216

215-
optimize.newton(
216-
f,
217-
x0=q,
218-
fprime=None,
219-
args=argtuple,
220-
tol=1e-7,
221-
maxiter=50,
222-
fprime2=None,
223-
)
217+
if 1==1:
218+
optimize.newton(
219+
f,
220+
x0=q,
221+
fprime=None,
222+
args=argtuple,
223+
tol=1e-7,
224+
maxiter=50,
225+
fprime2=None,
226+
)
227+
else:
228+
pass
224229

225230
###########################################################################
226231

financepy/products/credit/cds_index_portfolio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def max_spread(self, value_dt, step_in_dt, maturity_dt, issuer_curves):
192192

193193
####################################################################################
194194

195-
def spd_adjust_intrinsic(
195+
def spread_adjust_intrinsic(
196196
self,
197197
value_dt,
198198
issuer_curves,

financepy/products/equity/equity_compound_option.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def __init__(
7575
self.u_strike_price = float(u_strike_price)
7676
self.u_opt_type = u_opt_type
7777

78-
###########################################################################
78+
####################################################################################
7979

8080
def _preprocess_inputs(
8181
self,
@@ -157,7 +157,7 @@ def value(
157157

158158
return v
159159

160-
###########################################################################
160+
####################################################################################
161161

162162
def value_tree(
163163
self,
@@ -204,7 +204,7 @@ def __repr__(self):
204204
s += label_to_string("UND OPTION TYPE", self.u_opt_type)
205205
return s
206206

207-
###########################################################################
207+
####################################################################################
208208

209209
def _print(self):
210210
"""Simple print function for backward compatibility."""

financepy/products/fx/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from .fx_barrier_option import *
22
from .fx_digital_option import *
33
from .fx_double_digital_option import *
4+
from .fx_double_one_touch_option import *
45
from .fx_fixed_lookback_option import *
56
from .fx_float_lookback_option import *
67
from .fx_forward import *

financepy/products/fx/fx_double_digital_option.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@ def __init__(
3232
prem_currency: str,
3333
spot_days: int = 0,
3434
):
35-
"""Create the FX Double Digital Option object. Inputs include
36-
expiry date, upper strike, lower strike, currency pair,
37-
option type notional and the currency of the notional.
38-
An adjustment for spot days is enabled. All currency rates
35+
"""Create the FX Double Digital Option object. The option pays out
36+
the notional in the premium currency if the fx rate is between
37+
the upper and lower strike at maturity.
38+
The valuation is equivalent to the valuation of the difference of
39+
the value of two digital puts, one with the upper and the other
40+
with the lower strike. Inputs include expiry date, upper strike,
41+
lower strike, currency pair, option type notional and currency of
42+
notional. An adjustment for spot days is enabled. All currency rates
3943
must be entered in the price in domestic currency of one unit
4044
of foreign. And the currency pair should be in the form FORDOM
4145
where FOR is the foreign currency pair currency code and DOM is the

0 commit comments

Comments
 (0)