API Documentation¶
Risk Factor Modeling¶
risk_factor_model.RiskFactor |
|||||
risk_factor_model.RiskFactorModel |
|
||||
risk_factor_model.RiskFactorState |
|
||||
risk_factor_model.RiskFactorProducer |
|
||||
risk_factor_model.MultiRiskFactorProducer |
|
||||
risk_factor_model.RiskFactorConsumer |
consumer of RiskFactorState |

-
class
risk_factor_model.
MultiRiskFactorProducer
(process_list, correlation=None, diffusion_driver=None)[source]¶ Bases:
timewave.stochasticproducer.CorrelatedGaussEvolutionProducer
Parameters: - process_list (list(RiskFactorModel)) –
- correlation (list(list(float)) or dict((RiskFactorModel, RiskFactorModel): float)) – correlation of diffusion drivers of risk factors
- diffusion_driver (list(RiskFactorModel)) – index of diffusion driver if correlation is given by simple matrix (list(list(float)))
initialize MultiRiskFactorProducer
-
class
risk_factor_model.
RiskFactor
[source]¶ Bases:
object
-
inner_factor
¶ RiskFactor typically move given data structure like yield curves, fx curves or volatility surfaces. The inner factor is the driven structure.
-
-
class
risk_factor_model.
RiskFactorConsumer
(*risk_factor_list)[source]¶ Bases:
timewave.consumers.QuietConsumer
consumer of RiskFactorState
Parameters: risk_factor_list (list(RiskFactor)) – list of risk factors which will be driven by risk factor state initialize RiskFactorConsumer
-
consume
(state)[source]¶ Parameters: state (RiskFactorState) – specific process state Return object: the new consumer state returns pair the first element is the list of updated simulated hw curves the second element is True (indicates Curve mapping)
-
initialize
(grid=None, num_of_paths=None, seed=None)[source]¶ Parameters: - grid (list(BusinessDate)) – list of Monte Carlo grid dates
- num_of_paths (int) – number of simulation path
- seed (hashable) – initial seed of random generators
sets pre calculation depending only on grid
-
start_date
= None¶ BusinessDate – valuation date
-
-
class
risk_factor_model.
RiskFactorModel
(inner_factor, start_value=0.0)[source]¶ Bases:
timewave.stochasticprocess.StochasticProcess
,risk_factor_model.RiskFactor
Parameters: - inner_factor (Curve or Volatility or object) – parameter object which is modeled by the risk factor model
- start_value (float or tuple) –
initialize risk factor model
-
evolve
(x, s, e, q)[source]¶ Parameters: - x (float) – current state value, i.e. value before evolution step
- s (BusinessDate) – current point in time, i.e. start point of next evolution step
- e (BusinessDate) – next point in time, i.e. end point of evolution step
- q (float) – standard normal random number to do step
Return float: next state value, i.e. value after evolution step
evolves process state x from s to e in time depending of standard normal random variable q
-
evolve_risk_factor
(x, s, e, q)[source]¶ Parameters: - x (float) – current state value, i.e. value before evolution step
- s (BusinessDate) – current point in time, i.e. start point of next evolution step
- e (BusinessDate) – next point in time, i.e. end point of evolution step
- q (float) – standard normal random number to do step
Return float: next state value, i.e. value after evolution step
evolves process state x from s to e in time depending of standard normal random variable q and sets risk factor at e to x after evolving from s.
-
get_numeraire
(value_date)[source]¶ Parameters: value_date (BusinessDate) – date of Return float: returns the numeraire value
-
pre_calculate
(s, e)[source]¶ Parameters: - s (BusinessDate) – start date pre calc step
- e (BusinessDate) – end date pre calc step
pre calculation depending only on dates and model data (RiskFactor method)
-
set_risk_factor
(factor_date, factor_value=None)[source]¶ Parameters: - factor_date (BusinessDate) – sets risk factor state at this date
- factor_value (float or tuple) – sets risk factor state to this value
sets risk factor state, method should be idempotent, i.e. setting same state twice must not change risk factor state at all (RiskFactor method)
-
class
risk_factor_model.
RiskFactorProducer
(process)[source]¶ Bases:
timewave.stochasticproducer.GaussEvolutionFunctionProducer
Parameters: process (RiskFactorModel) – producer for timewave simulation framework to evolve a RiskFactorModel depending of standard normal random values
Market Risk Factors¶
market_risk_factor.BrownianZeroRateCurve |
simple Brownian motion rate diffusion |
market_risk_factor.GBMFxCurve |
models fx spot rate as spot * x |

-
class
market_risk_factor.
BrownianZeroRateCurve
(x_list=None, y_list=None, y_inter=None, origin=None, day_count=None, forward_tenor=None, drift=0.0, volatility=0.0, inner_factor=None)[source]¶ Bases:
dcf.curve.ZeroRateCurve
,risk_factor_model.RiskFactorModel
simple Brownian motion rate diffusion
initializes Hull White curve
Parameters: - x_list (list(float)) –
- y_list (list(float)) –
- y_inter (list(interpolation)) –
- origin (BusinessDate) –
- day_count (DayCount) –
- forward_tenor (BusinessPeriod) –
- or function drift (float) –
- or function volatility (float) –
- inner_factor (RateCurve) –
-
class
market_risk_factor.
GBMFxCurve
(x_list=None, y_list=None, y_inter=None, origin=None, day_count=None, domestic_curve=None, foreign_curve=None, volatility=0.0, inner_factor=None)[source]¶ Bases:
dcf.fx.FxCurve
,risk_factor_model.RiskFactorModel
models fx spot rate as spot * x
Parameters: - x_list (list(BusinessDate)) –
- y_list (list(BusinessDate)) –
- y_inter (list()) –
- origin (BusinessDate) –
- day_count (DayCount) –
- domestic_curve (RateCurve) –
- foreign_curve (RateCurve) –
- or function volatility (float) –
- inner_factor (FxCurve) –
The Hull White Model¶
hullwhite_model.HullWhiteCurve |
calculation of discount factors in the Hull White model |

-
class
hullwhite_model.
HullWhiteCurve
(x_list=None, y_list=None, y_inter=None, origin=None, day_count=None, forward_tenor=None, mean_reversion=0.0, volatility=0.0, terminal_date=None, inner_factor=None)[source]¶ Bases:
dcf.curve.ZeroRateCurve
,risk_factor_model.RiskFactorModel
calculation of discount factors in the Hull White model
Parameters: - x_list (list(float)) –
- y_list (list(float)) –
- y_inter (list(interpolation)) –
- origin (BusinessDate) –
- day_count (DayCount) –
- forward_tenor (BusinessPeriod) – standard forward
- mean_reversion (float or function) – mean reversion speed of short rate process
- volatility (float or function) – short rate volatility
- terminal_date (BusinessDate) – date of terminal measure
- inner_factor (RateCurve) –
initializes Hull White curve
-
calc_integral_B
(t1, t2)[source]¶ returns the value of the helper function B
B(t1,t2)=∫t2t1I1(t1,τ)dτ=1a(1−e−a(t2−t1))Parameters: - t1 (float) – start time as year fraction / float
- t2 (float) – end time as year fraction / float
Return float:
-
calc_integral_I1
(t1, t2)[source]¶ Parameters: - t1 (float) – start time as year fraction / float
- t2 (float) – end time as year fraction / float
Returns: float
returns the value of the helper function I1
I1(t1,t2)=exp(−∫t2t1a(τ)dτ)=e−a(t2−t1)
-
calc_integral_I1_squared
(t1, t2)[source]¶ Parameters: - t1 (float) – start time as year fraction / float
- t2 (float) – end time as year fraction / float
Return float: returns the value of the helper function I1^2
I1(t1,t2)2=exp(−2∫t2t1a(τ)dτ)=e−2a(t2−t1)
-
calc_integral_I2
(s, t)[source]¶ Parameters: - s (float) – start time as year fraction / float
- t (float) – end time as year fraction / float
Return float: returns the value of the helper function Integrals
One of the deterministic terms of a step in the MC simulation is calculated here with last observation date for T-Bond numeraire T
∫tsσ2(u)I1(u,t)(B(u,t)−B(u,T))du+B(s,t)I1(s,t)∫s0σ2(u)I21(u,s)du
-
calc_integral_volatility_squared_with_I1
(t1, t2)[source]¶ Parameters: - t1 –
- t2 –
Return float: Calculates integral of integrand f with I1 between two time points t1 and t2 with t1≤t2 is as:
extrmVarr(t1,t2)=∫t2t1vol(u)2I1(u,t2)du
-
calc_integral_volatility_squared_with_I1_squared
(t1, t2)[source]¶ Parameters: - t1 –
- t2 –
Return float: calculates drift integral I2
-
classmethod
cast
(other, mean_reversion=0.0, volatility=0.0, terminal_date=None)[source]¶ Parameters: - other (ZeroRateCurve) –
- mean_reversion (float or function) – mean reversion speed of short rate process
- volatility (float or function) – short rate volatility
- terminal_date (BusinessDate) – date of terminal measure
Returns: HullWhiteCurve
build HullWhiteCurve i.e. Hull White model in terminal measure from ZeroRateCurve, mean reversion speed, volatility and terminal measure date.
-
evolve
(x, s, e, q)[source]¶ Parameters: - x –
- s –
- e –
- q –
Returns: evolve Hull White process of shortrate diviation math:: y = r - y
-
get_discount_factor
(start_date, end_date)[source]¶ Parameters: - start_date (BusinessDate) – start date
- end_date (BusinessDate) – end date
Return float: calculate the discount rate for the given start date and end date
Pu,y:BusinessDate×BusinessDate→Rand
(s,t)↦Pinit(s,t)exp(−12(B2(u,t)−B2(u,s))∫u0σ2(τ)I1(τ,t),dτ)e−(B(t,T)−B(t,S))ywith P_{\text{init}}(s,t) = \verb|Curve.get_discount_curve(s,t)|
Here the variables with subscript \textrm{pld} are dates (BusinessDate instances) and the variables without subscripts are year fractions between the correspondent \textrm{pld} variables and \verb|validity_date| in the default DCC (Act/365.25).
Multi Currency Hull White Model Extension¶
hullwhite_multicurrency_model.HullWhiteFxCurve |
|
||||
hullwhite_multicurrency_model.HullWhiteMultiCurrencyCurve |
initializes foreign Hull White curve in multi currency model |

-
class
hullwhite_multicurrency_model.
HullWhiteFxCurve
(x_list=None, y_list=None, y_inter=None, origin=None, day_count=None, domestic_curve=None, foreign_curve=None, volatility=0.0, domestic_correlation=0.0, foreign_correlation=0.0, rate_correlation=0.0, inner_factor=None)[source]¶ Bases:
market_risk_factor.GBMFxCurve
Parameters: - x_list (list(BusinessDate)) –
- y_list (list(BusinessDate)) –
- y_inter (list()) –
- origin (BusinessDate) –
- day_count (DayCount) –
- domestic_curve (HullWhiteCurve) –
- foreign_curve (HullWhiteCurve) –
- volatility (float or function or Curve) –
- domestic_correlation (float) –
- foreign_correlation (float) –
- rate_correlation (float) –
- inner_factor (GBMFxCurve or FxCurve) –
-
classmethod
cast
(fx_curve, domestic_curve, foreign_curve, volatility=0.0, correlation=None)[source]¶ Parameters: - fx_curve (GBMFxCurve or FxCurve) – FxCurve to retrieve factor expectation
- domestic_curve (HullWhiteCurve) – domestic HullWhiteCurve
- foreign_curve (HullWhiteCurve) – foreign HullWhiteCurve
- volatility (float or function) – fx spot forward volatility
- correlation (dict(RiskFactorModel, RiskFactorModel)) – correlation matrix indexed by risk factors
Build HullWhiteFxCurve from HullWhiteCurves and GBMFxCurve. Terminal measure date in foreign_curve is ignored since it is taken from domestic_curve.
-
evolve
(x, s, e, q)[source]¶ Parameters: - x (float) – current state value, i.e. value before evolution step
- s (BusinessDate) – current point in time, i.e. start point of next evolution step
- e (BusinessDate) – next point in time, i.e. end point of evolution step
- q (float) – standard normal random number to do step
Return float: next state value, i.e. value after evolution step
evolves process state x from s to e in time depending of standard normal random variable q
-
class
hullwhite_multicurrency_model.
HullWhiteMultiCurrencyCurve
(x_list=None, y_list=None, y_inter=None, origin=None, day_count=None, forward_tenor=None, mean_reversion=0.0001, volatility=0.0, domestic_curve=None, fx_curve=None, foreign_correlation=0.0, rate_correlation=0.0, inner_factor=None)[source]¶ Bases:
hullwhite_model.HullWhiteCurve
initializes foreign Hull White curve in multi currency modelParameters: - x_list (list(float)) –
- y_list (list(float)) –
- y_inter (list(interpolation)) –
- origin (BusinessDate) –
- day_count (DayCount) –
- forward_tenor (BusinessPeriod) –
- or function mean_reversion (float) – volatility of foreign short rate process
- or function volatility (float) – volatility of foreign short rate process
- domestic_curve (HullWhiteCurve) – domestic rate HullWhite process
- or GBMFxCurve fx_curve (HullWhiteFxCurve) – fx curve with volatility of ln(fx) process
- foreign_correlation (float) – correlation of ln(fx) process and foreign rate process
- rate_correlation (float) – correlation of domestic rate process and foreign rate process
- inner_factor (RateCurve) –
-
calc_integral_I2
(s, t)[source]¶ calculates the following integral (see formula for the step in the MC evolution)
\begin{split}\textrm{Var}(\chi(t) | \mathcal{F}_s) = \int_s^t \sigma^2_d(u)B^2_d(u, T) + \sigma^2_f(u)B^2_f(u,T) + \sigma^2_{FX}(u) \\ + 2\left(- \rho_{d,f} B_f(u, T)\sigma_f(u)B_d(u, T)\sigma_d(u) + \left( - \rho_{f,FX} B_f(u, T)\sigma_f(u) + \rho_{d,FX} B_d(u, T)\sigma_d(u) \right) \sigma_{FX}(u) \right)\,\mathrm{d}u\end{split}Parameters: - s (float) –
- t (float) –
Return float:
-
classmethod
cast
(foreign_curve, domestic_curve, fx_curve)[source]¶ Parameters: - foreign_curve (HullWhiteCurve) –
- domestic_curve (HullWhiteCurve) –
- fx_curve (HullWhiteFxCurve) –
Return HullWhiteMultiCurrencyCurve: build HullWhiteMultiCurrencyCurve from HullWhiteCurves and HullWhiteFxCurve. Terminal measure date in foreign_curve is ignored since it is taken from domestic_curve.