Skip to content

Commit

Permalink
Fixed problem with Gaussian Loss Dbn.
Browse files Browse the repository at this point in the history
  • Loading branch information
domokane committed Feb 19, 2024
1 parent 81685a4 commit 34e3181
Show file tree
Hide file tree
Showing 20 changed files with 729 additions and 737 deletions.
2 changes: 1 addition & 1 deletion financepy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cr = "\n"

s = "####################################################################" + cr
s += "# FINANCEPY BETA Version " + str('0.34') + " - This build: 19 Feb 2024 at 04:06 #" + cr
s += "# FINANCEPY BETA Version " + str('0.34') + " - This build: 19 Feb 2024 at 21:02 #" + cr
s += "# This software is distributed FREE AND WITHOUT ANY WARRANTY #" + cr
s += "# Report bugs as issues at https://github.com/domokane/FinancePy #" + cr
s += "####################################################################"
Expand Down
4 changes: 3 additions & 1 deletion financepy/models/gauss_copula_onefactor.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ def gauss_approx_tranche_loss(k1, k2, mu, sigma):
d1 = (mu - k1) / sigma
d2 = (mu - k2) / sigma

gauss_approx_tranche_loss = (mu - k1) * N(d1) - (mu - k2) * N(d2) + sigma * np.exp(-0.5 * d1 * d1) * INVROOT2PI - sigma * np.exp(-0.5 * d2 * d2) * INVROOT2PI
gauss_approx_tranche_loss = ((mu - k1) * N(d1) - (mu - k2) * N(d2)
+ sigma * np.exp(-0.5 * d1 * d1) * INVROOT2PI
- sigma * np.exp(-0.5 * d2 * d2) * INVROOT2PI)

return gauss_approx_tranche_loss

Expand Down
6 changes: 3 additions & 3 deletions financepy/products/bonds/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from .bond import *
from .bond_zero import *
from .bond_annuity import *
from .zero_curve import *
from .bond_zero_curve import *
from .bond_convertible import *
from .bond_callable import *
from .bond_frn import *
from .bond_future import *
from .bond_market import *
from .bond_option import *
from .yield_curve import *
from .yield_curve_model import *
from .bond_yield_curve import *
from .curve_fits import *
from .bond_mortgage import *
16 changes: 8 additions & 8 deletions financepy/products/bonds/bond.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
from ...utils.math import npv
from ...market.curves.discount_curve import DiscountCurve
from ...market.curves.interpolator import InterpTypes
from .zero_curve import BondZeroCurve
from .bond_zero_curve import BondZeroCurve

# References https://www.dmo.gov.uk/media/15011/yldeqns_v1.pdf
# DO TRUE YIELD
Expand Down Expand Up @@ -390,7 +390,6 @@ def modified_duration(self,
###########################################################################

def key_rate_durations(self,
bond,
settle_dt: Date,
ytm: float,
key_rate_tenors: list = None,
Expand Down Expand Up @@ -455,7 +454,7 @@ def key_rate_durations(self,
mat_dt = settle_dt.add_years(tenor)

par_bond = Bond(settle_dt, mat_dt, cpn,
bond._freq_type, bond._dc_type)
self._freq_type, self._dc_type)

par_bonds.append(par_bond)

Expand All @@ -473,7 +472,7 @@ def key_rate_durations(self,
lin_zero_interp)

# calculate the dirty price of the bond using the discount curve
p_zero = bond.dirty_price_from_discount_curve(settle_dt,
p_zero = self.dirty_price_from_discount_curve(settle_dt,
par_crv)

# shift up by the yield of corresponding par bond
Expand All @@ -485,7 +484,8 @@ def key_rate_durations(self,
mat = settle_dt.add_years(tenor)

par_bond = Bond(settle_dt, mat, cpn,
bond._freq_type, bond._dc_type)
self._freq_type,
self._dc_type)

par_bonds.append(par_bond)

Expand All @@ -504,7 +504,7 @@ def key_rate_durations(self,

# calculate the full price of the bond
# using the discount curve with the key rate shifted up
p_up = bond.dirty_price_from_discount_curve(
p_up = self.dirty_price_from_discount_curve(
settle_dt, par_crv_up)

# create a curve again with the key rate shifted down
Expand All @@ -517,7 +517,7 @@ def key_rate_durations(self,
mat = settle_dt.add_years(tenor)

par_bond = Bond(settle_dt, mat, cpn,
bond._freq_type, bond._dc_type)
self._freq_type, self._dc_type)

par_bonds.append(par_bond)

Expand All @@ -535,7 +535,7 @@ def key_rate_durations(self,
lin_zero_interp)

# calculate the full price of the bond using
p_down = bond.dirty_price_from_discount_curve(
p_down = self.dirty_price_from_discount_curve(
settle_dt, par_crv_down)

# calculate the key rate duration
Expand Down
Loading

0 comments on commit 34e3181

Please sign in to comment.