├── .github ├── FUNDING.yml └── workflows │ ├── pylint.yml │ ├── run-golden-tests.yml │ └── run-unit-tests.yml ├── .gitignore ├── .pylintrc ├── CHANGELOG.md ├── FinancePyManual.pdf ├── LICENSE ├── README.md ├── book ├── ALL FINANCEPY │ ├── README.md │ ├── cleanErrors.bat │ ├── finutils │ │ ├── FINCALENDAR_IntroductionToUsingCalendars.ipynb │ │ ├── FINDATES_TestingDateInternals.ipynb │ │ ├── FINDATE_CreatingAndManipulatingFinDates.ipynb │ │ ├── FINDAYCOUNT_Introduction.ipynb │ │ ├── FINSCHEDULE_ExamplesOfScheduleGeneration.ipynb │ │ └── FINSCHEDULE_ScheduleGenerationTestCases.ipynb │ ├── market │ │ ├── curves │ │ │ ├── FINDISCOUNTCURVEFLAT_ExaminationOfDiscountCurveFlat.ipynb │ │ │ ├── FINDISCOUNTCURVENSS_IntroductionToTheNelsonSiegelSvenssonCurve.ipynb │ │ │ ├── FINDISCOUNTCURVENS_ExaminingTheNelsonSiegelCurve.ipynb │ │ │ ├── FINDISCOUNTCURVEPOLY_SimpleAnalysis.ipynb │ │ │ ├── FINDISCOUNTCURVEZERO_ConvertZeroCurveToDiscountCurve.ipynb │ │ │ ├── FINDISCOUNTCURVE_AnalysisOfInterpolationSchemes.ipynb │ │ │ └── FINDISCOUNTCURVE_Introduction.ipynb │ │ └── volatility │ │ │ ├── EquityVolSurfaceConstructionSVI.ipynb │ │ │ ├── FXVolSurfaceConstructionPartOne.ipynb │ │ │ ├── FXVolSurfaceConstructionPartThree.ipynb │ │ │ ├── FXVolSurfaceConstructionPartTwo.ipynb │ │ │ └── SimpleBuildFXVolatilitySurface25Delta.ipynb │ ├── models │ │ ├── CHOLESKY CHECK.ipynb │ │ ├── FINGBMPROCESS_generatePaths.ipynb │ │ ├── FINITE_DIFFERENCE.ipynb │ │ ├── FINITE_DIFFERENCE_PSOR.ipynb │ │ ├── FINMODEL_GAUSSIANCOPULA_PortfolioLossDistributionBuilder.ipynb │ │ ├── FINMODEL_SABRSHIFTED_InterestRates.ipynb │ │ ├── FINMODEL_SABRSHIFTED_VolatilitySmile.ipynb │ │ ├── FINMODEL_SABR_InterestRates.ipynb │ │ ├── FINVOLFUNCTIONS_SSVI_MODEL.ipynb │ │ └── MERTON_CREDIT_MODEL.ipynb │ ├── products │ │ ├── bonds │ │ │ ├── FINANNUITY_Valuation.ipynb │ │ │ ├── FINBONDCONVERTIBLE_ComparisonWithQLExample.ipynb │ │ │ ├── FINBONDCONVERTIBLE_ValuationAndConvergenceTest.ipynb │ │ │ ├── FINBONDEMBEDDEDOPTION_Valuation.ipynb │ │ │ ├── FINBONDFRN_CitigroupExample.ipynb │ │ │ ├── FINBONDFRN_ComparisonWithML_PROBLEM.ipynb │ │ │ ├── FINBONDFUTURES_ExampleContracts.ipynb │ │ │ ├── FINBONDMARKET_DatabaseOfConventions.ipynb │ │ │ ├── FINBONDMORTGAGE_SimpleCalculator.ipynb │ │ │ ├── FINBONDOPTION_All_Models_Valuation_Analysis.ipynb │ │ │ ├── FINBONDOPTION_BK_ModelValuationAnalysis.ipynb │ │ │ ├── FINBONDOPTION_HW_EXAMPLE_MATCH_DERIVA_GEN.ipynb │ │ │ ├── FINBONDOPTION_HW_Model_Jamshidian.ipynb │ │ │ ├── FINBONDOPTION_Tree_Convergence_With_Volatility.ipynb │ │ │ ├── FINBONDOPTION_Tree_Convergence_Zero_Vol.ipynb │ │ │ ├── FINBONDYIELDCURVES_FittingExample.ipynb │ │ │ ├── FINBONDYIELDCURVE_FittingToBondMarketPrices.ipynb │ │ │ ├── FINBONDZEROCURVE_BootstrapOutstandingBonds.ipynb │ │ │ ├── FINBOND_CalculateOptionAdjustedSpread.ipynb │ │ │ ├── FINBOND_CalculatePriceUsingSurvivalCurve.ipynb │ │ │ ├── FINBOND_CalculatingTheAssetSwapSpread.ipynb │ │ │ ├── FINBOND_ComparisonWithQLExample.ipynb │ │ │ ├── FINBOND_DiscountingBondCashflowsFinDiscountCurve.ipynb │ │ │ ├── FINBOND_ExampleAppleCorp.ipynb │ │ │ ├── FINBOND_ExampleUSTreasury_CUSIP_91282CFX4.ipynb │ │ │ ├── FINBOND_Key_Rate_Durations_Example.ipynb │ │ │ ├── FINBOND_QuantStackExchangeQuestion.ipynb │ │ │ └── data │ │ │ │ └── giltBondPrices.txt │ │ ├── credit │ │ │ ├── FINCDSBASKET_ValuationModelComparison_REPAIR.ipynb │ │ │ ├── FINCDSCURVE_BuildingASurvivalCurve.ipynb │ │ │ ├── FINCDSINDEXOPTION_CompareValuationApproaches.ipynb │ │ │ ├── FINCDSINDEX_ValuingCDSIndex.ipynb │ │ │ ├── FINCDSOPTION_ValuingCDSOption.ipynb │ │ │ ├── FINCDSTRANCHE_CalculatingFairSpread.ipynb │ │ │ ├── FINCDS_ComparisonWithMarkitCDSModel.ipynb │ │ │ ├── FINCDS_ComparisonWithMarkitCDSModelV2.ipynb │ │ │ ├── FINCDS_CreatingAndValuingACDS.ipynb │ │ │ ├── FINCDS_ForwardAndBackward.ipynb │ │ │ ├── FINCDS_ValuingCDSCompareToMarkit.ipynb │ │ │ ├── FINCDS_ValuingCDSCompareToMarkitV2.ipynb │ │ │ └── data │ │ │ │ └── CDX_NA_IG_S7_SPREADS.csv │ │ ├── equity │ │ │ ├── EQUITY_AMERICANOPTION_BARONE_ADESI_WHALEY_APPROX.ipynb │ │ │ ├── EQUITY_AMERICANOPTION_BJERKSUND_STENSLAND_APPROX.ipynb │ │ │ ├── EQUITY_AMERICANOPTION_ComparisonWithQLExample.ipynb │ │ │ ├── EQUITY_AMERICANOPTION_ComparisonWithQLExample_CHECK.ipynb │ │ │ ├── EQUITY_ASIAN_OPTIONS.ipynb │ │ │ ├── EQUITY_BARRIER_OPTIONS.ipynb │ │ │ ├── EQUITY_BASKET_OPTIONS.ipynb │ │ │ ├── EQUITY_CHOOSER_OPTION.ipynb │ │ │ ├── EQUITY_CHOOSER_OPTION_ComparisonWithML.ipynb │ │ │ ├── EQUITY_CLIQUET_OPTION.ipynb │ │ │ ├── EQUITY_COMPOUND_OPTION_CompareWithML.ipynb │ │ │ ├── EQUITY_DIGITALOPTION_BasicValuation.ipynb │ │ │ ├── EQUITY_DIGITAL_CASH_OR_NOTHING_OPTION.ipynb │ │ │ ├── EQUITY_FIXED_LOOKBACK_OPTION.ipynb │ │ │ ├── EQUITY_FLOAT_LOOKBACK_OPTION.ipynb │ │ │ ├── EQUITY_ONE_TOUCH_OPTION.ipynb │ │ │ ├── EQUITY_RAINBOW_OPTION.ipynb │ │ │ ├── EQUITY_VANILLA_AMERICAN_STYLE_OPTION_REPAIR.ipynb │ │ │ ├── EQUITY_VANILLA_EUROPEAN_STYLE_MONTE_CARLO_SOBOL.ipynb │ │ │ ├── EQUITY_VANILLA_EUROPEAN_STYLE_MONTE_CARLO_TIMINGS.ipynb │ │ │ ├── EQUITY_VANILLA_EUROPEAN_STYLE_OPTION HIGH VOL LIMIT.ipynb │ │ │ ├── EQUITY_VANILLA_EUROPEAN_STYLE_OPTION.ipynb │ │ │ ├── EQUITY_VANILLA_EUROPEAN_STYLE_OPTION_VECTORISATION.ipynb │ │ │ ├── EQUITY_VANILLA_OPTION_IntradayValuationAndGreeks.ipynb │ │ │ ├── EQUITY_VANILLA_OPTION_ValuationAndGreeks_ERROR.ipynb │ │ │ └── EQUITY_VARIANCESWAP_Basic_Example.ipynb │ │ ├── fx │ │ │ ├── FXOneTouchOption.ipynb │ │ │ └── FXOptionAnalysisAndDeltas.ipynb │ │ └── rates │ │ │ ├── FINIBORBERMUDANSWAPTION_All_Valuation_Models.ipynb │ │ │ ├── FINIBORBERMUDANSWAPTION_Hull_White_Tree.ipynb │ │ │ ├── FINIBORCAPFLOOR_ComparisonWithQLExample.ipynb │ │ │ ├── FINIBORCAPFLOOR_ValuationAcrossAllModels.ipynb │ │ │ ├── FINIBORDUALCURVE_BuildingASimpleDualIborCurve.ipynb │ │ │ ├── FINIBORDUALCURVE_BuildingEuriborDualCurveFollowingQLExample.ipynb │ │ │ ├── FINIBORDUALCURVE_BuildingEuriborDualCurveSwapValuationQLExampleDeriscope.ipynb │ │ │ ├── FINIBORDUALCURVE_BuildingUSDDualCurveSwapValuationQLExampleDeriscope.ipynb │ │ │ ├── FINIBORDUALCURVE_Building_EURIBOR_DualCurve_Bloomberg_Example.ipynb │ │ │ ├── FINIBORDUALCURVE_ValueUSDSwapUsingDifferentCurveBuildingAssumptions.ipynb │ │ │ ├── FINIBORSINGLECURVE_AnalysisOfForwards.ipynb │ │ │ ├── FINIBORSINGLECURVE_BuildingASimpleIborCurve.ipynb │ │ │ ├── FINIBORSINGLECURVE_BuildingAnIborCurve.ipynb │ │ │ ├── FINIBORSINGLECURVE_BuildingIborCurveInterpolationCOMPLEX.ipynb │ │ │ ├── FINIBORSINGLECURVE_BuildingIborCurveInterpolationSIMPLE.ipynb │ │ │ ├── FINIBORSINGLECURVE_BuildingInterpolationChoice.ipynb │ │ │ ├── FINIBORSINGLECURVE_ReplicatingBBGExample.ipynb │ │ │ ├── FINIBORSINGLECURVE_ReplicatingQuantlibExample.ipynb │ │ │ ├── FINIBORSWAPTION_All_Models_Analysis.ipynb │ │ │ ├── FINIBORSWAPTION_ComparisonWithMLExample.ipynb │ │ │ ├── FINIBORSWAPTION_ComparisonWithQLExample.ipynb │ │ │ ├── FINIBORSWAPTION_ValuingAcrossModels.ipynb │ │ │ ├── FINIBORSWAP_BusinessDayConventions.ipynb │ │ │ ├── FINIBORSWAP_ComparisonWithQLExample.ipynb │ │ │ ├── FINIBORSWAP_DefiningAFixedFloatingSwap.ipynb │ │ │ ├── FINIBORSWAP_SettingTheScheduleDirectly.ipynb │ │ │ ├── FINOISCURVE_BuildingAnOISCurveWithMeetingDates.ipynb │ │ │ └── FINOISCURVE_BuildingEONIACurveFollowingQLExample.ipynb │ └── testNotebooks.py ├── black_scholes_wiener_processes.ipynb ├── bond risk measures │ ├── FINBOND_CalculatingTheAssetSwapSpread.ipynb │ ├── FINBOND_ExampleAppleCorp.ipynb │ ├── FINBOND_ExampleUSTreasury_CUSIP_91282CFX4.ipynb │ └── FINBOND_Key_Rate_Durations_Example.ipynb ├── convertible_bonds │ ├── FINBONDCONVERTIBLE_ComparisonWithQLExample.ipynb │ └── FINBONDCONVERTIBLE_ValuationAndConvergenceTest.ipynb ├── corporate bonds │ ├── BondMarketConventionsTable.ipynb │ ├── FINBONDFUTURES_ExampleContracts.ipynb │ ├── FINBONDYIELDCURVES_FittingExample.ipynb │ ├── FINBONDYIELDCURVE_FittingToBondMarketPrices.ipynb │ ├── FINBONDZEROCURVE_BootstrapOutstandingBonds.ipynb │ ├── FINBOND_CalculateOptionAdjustedSpread.ipynb │ ├── FINBOND_CalculatePriceUsingSurvivalCurve.ipynb │ ├── FINBOND_CalculatingTheAssetSwapSpread.ipynb │ ├── FINBOND_ComparisonWithQLExample.ipynb │ ├── FINBOND_DiscountingBondCashflowsFinDiscountCurve.ipynb │ ├── FINBOND_ExampleAppleCorp.ipynb │ └── SimpleUSTreasuryExample.ipynb └── government_bonds │ ├── BondMarketConventionsTable.ipynb │ ├── Chapter_Bonds_ExampleUSTreasury_CUSIP_91282CFX4.ipynb │ ├── FINBONDFUTURES_ExampleContracts.ipynb │ ├── FINBONDMARKET_DatabaseOfConventions.ipynb │ ├── FINBONDYIELDCURVES_FittingExample.ipynb │ ├── FINBONDYIELDCURVE_FittingToBondMarketPrices.ipynb │ ├── FINBONDZEROCURVE_BootstrapOutstandingBonds.ipynb │ ├── FINBOND_CalculateOptionAdjustedSpread.ipynb │ ├── FINBOND_CalculatePriceUsingSurvivalCurve.ipynb │ ├── FINBOND_CalculatingTheAssetSwapSpread.ipynb │ ├── FINBOND_ComparisonWithQLExample.ipynb │ ├── FINBOND_DiscountingBondCashflowsFinDiscountCurve.ipynb │ ├── FINBOND_ExampleAppleCorp.ipynb │ └── SimpleUSTreasuryExample.ipynb ├── docs ├── FinancePyManual.pdf ├── generate.py ├── head.tex ├── index.md ├── make_user_guide.py └── tail.tex ├── financepy ├── __init.py ├── __init__.py ├── __init__.template ├── market │ ├── README.md │ ├── __init__.py │ ├── curves │ │ ├── README.md │ │ ├── __init__.py │ │ ├── composite_discount_curve.py │ │ ├── discount_curve.py │ │ ├── discount_curve_flat.py │ │ ├── discount_curve_ns.py │ │ ├── discount_curve_nss.py │ │ ├── discount_curve_poly.py │ │ ├── discount_curve_pwf.py │ │ ├── discount_curve_pwf_onf.py │ │ ├── discount_curve_pwl.py │ │ ├── discount_curve_zeros.py │ │ └── interpolator.py │ ├── prices │ │ ├── README.md │ │ └── __init__.py │ └── volatility │ │ ├── README.md │ │ ├── __init__.py │ │ ├── equity_vol_curve.py │ │ ├── equity_vol_surface.py │ │ ├── fx_vol_surface.py │ │ ├── fx_vol_surface_plus.py │ │ ├── ibor_cap_vol_curve.py │ │ ├── ibor_cap_vol_curve_fn.py │ │ └── swaption_vol_surface.py ├── models │ ├── README.md │ ├── __init__.py │ ├── bachelier.py │ ├── bdt_tree.py │ ├── bk_tree.py │ ├── black.py │ ├── black_scholes.py │ ├── black_scholes_analytic.py │ ├── black_scholes_mc.py │ ├── black_scholes_mc_tests.py │ ├── black_shifted.py │ ├── bond_analytics.py │ ├── cir_montecarlo.py │ ├── equity_barrier_models.py │ ├── equity_crr_tree.py │ ├── equity_lsmc.py │ ├── finite_difference.py │ ├── finite_difference_PSOR.py │ ├── gauss_copula.py │ ├── gauss_copula_lhp.py │ ├── gauss_copula_lhplus.py │ ├── gauss_copula_onefactor.py │ ├── gbm_process_simulator.py │ ├── heston.py │ ├── hw_tree.py │ ├── lmm_mc.py │ ├── loss_dbn_builder.py │ ├── merton_firm.py │ ├── merton_firm_mkt.py │ ├── model.py │ ├── option_implied_dbn.py │ ├── process_simulator.py │ ├── rates_ho_lee.py │ ├── sabr.py │ ├── sabr_shifted.py │ ├── sobol.py │ ├── sobolcoeff.npz │ ├── student_t_copula.py │ ├── vasicek_mc.py │ └── volatility_fns.py ├── products │ ├── __init__.py │ ├── bonds │ │ ├── README.md │ │ ├── __init__.py │ │ ├── bond.py │ │ ├── bond_annuity.py │ │ ├── bond_callable.py │ │ ├── bond_convertible.py │ │ ├── bond_frn.py │ │ ├── bond_future.py │ │ ├── bond_market.py │ │ ├── bond_mortgage.py │ │ ├── bond_option.py │ │ ├── bond_portfolio.py │ │ ├── bond_yield_curve.py │ │ ├── bond_zero.py │ │ ├── bond_zero_curve.py │ │ ├── curve_fits.py │ │ └── yield_curve.py │ ├── credit │ │ ├── README.md │ │ ├── __init__.py │ │ ├── cds.py │ │ ├── cds_basket.py │ │ ├── cds_curve.py │ │ ├── cds_index_option.py │ │ ├── cds_index_portfolio.py │ │ ├── cds_option.py │ │ └── cds_tranche.py │ ├── equity │ │ ├── README.md │ │ ├── __init__.py │ │ ├── equity_american_option.py │ │ ├── equity_asian_option.py │ │ ├── equity_barrier_option.py │ │ ├── equity_basket_option.py │ │ ├── equity_binomial_tree.py │ │ ├── equity_chooser_option.py │ │ ├── equity_cliquet_option.py │ │ ├── equity_compound_option.py │ │ ├── equity_digital_option.py │ │ ├── equity_fixed_lookback_option.py │ │ ├── equity_float_lookback_option.py │ │ ├── equity_forward.py │ │ ├── equity_index_option.py │ │ ├── equity_model_types.py │ │ ├── equity_one_touch_option.py │ │ ├── equity_option.py │ │ ├── equity_rainbow_option.py │ │ ├── equity_swap.py │ │ ├── equity_swap_leg.py │ │ ├── equity_vanilla_option.py │ │ └── equity_variance_swap.py │ ├── fx │ │ ├── README.md │ │ ├── __init__.py │ │ ├── fx_barrier_option.py │ │ ├── fx_digital_option.py │ │ ├── fx_double_digital_option.py │ │ ├── fx_fixed_lookback_option.py │ │ ├── fx_float_lookback_option.py │ │ ├── fx_forward.py │ │ ├── fx_mkt_conventions.py │ │ ├── fx_one_touch_option.py │ │ ├── fx_option.py │ │ ├── fx_rainbow_option.py │ │ ├── fx_vanilla_option.py │ │ └── fx_variance_swap.py │ ├── inflation │ │ ├── FinInflationBond.py │ │ ├── FinInflationIndexCurve.py │ │ ├── FinInflationSwap.py │ │ ├── FinInflationSwapCurve.py │ │ └── __init__.py │ └── rates │ │ ├── README.md │ │ ├── __init__.py │ │ ├── callable_swap.py │ │ ├── dual_curve.py │ │ ├── ibor_basis_swap.py │ │ ├── ibor_benchmarks_report.py │ │ ├── ibor_bermudan_swaption.py │ │ ├── ibor_cap_floor.py │ │ ├── ibor_conventions.py │ │ ├── ibor_curve_risk_engine.py │ │ ├── ibor_deposit.py │ │ ├── ibor_fra.py │ │ ├── ibor_future.py │ │ ├── ibor_lmm_products.py │ │ ├── ibor_single_curve.py │ │ ├── ibor_single_curve_par_shocker.py │ │ ├── ibor_single_curve_smoothing_calibrator.py │ │ ├── ibor_swap.py │ │ ├── ibor_swaption.py │ │ ├── ois.py │ │ ├── ois_basis_swap.py │ │ ├── ois_curve.py │ │ ├── swap_fixed_leg.py │ │ ├── swap_float_leg.py │ │ └── swaps │ │ ├── FinFixedFixedXCcySwap.py │ │ ├── FinFixedIborXCcySwap.py │ │ ├── FinIborIborSwap.py │ │ ├── FinIborIborXCcySwap.py │ │ └── __init__.py └── utils │ ├── README.md │ ├── __init__.py │ ├── amount.py │ ├── calendar.py │ ├── currency.py │ ├── date.py │ ├── day_count.py │ ├── distribution.py │ ├── error.py │ ├── frequency.py │ ├── global_types.py │ ├── global_vars.py │ ├── helpers.py │ ├── latex.py │ ├── math.py │ ├── polyfit.py │ ├── schedule.py │ ├── singleton.py │ ├── solver_1d.py │ ├── solver_cg.py │ ├── solver_nm.py │ ├── stats.py │ ├── tenor.py │ └── tension_spline.py ├── golden_tests ├── FinTestCases.py ├── README.md ├── TestFinAmount.py ├── TestFinBond.py ├── TestFinBondAnnuity.py ├── TestFinBondConvertible.py ├── TestFinBondEmbeddedOptionBK.py ├── TestFinBondEmbeddedOptionHW.py ├── TestFinBondFRN.py ├── TestFinBondFutures.py ├── TestFinBondMortgage.py ├── TestFinBondOptionBDTModel.py ├── TestFinBondOptionBKModel.py ├── TestFinBondOptionHWModel.py ├── TestFinBondPortfolio.py ├── TestFinBondYieldCurve.py ├── TestFinBondZSpread.py ├── TestFinBondZeroCoupon.py ├── TestFinBondZeroCurve.py ├── TestFinCDS.py ├── TestFinCDSBasket.py ├── TestFinCDSCurve.py ├── TestFinCDSIndex.py ├── TestFinCDSIndexAdjustHazards.py ├── TestFinCDSIndexAdjustSpreads.py ├── TestFinCDSIndexOption.py ├── TestFinCDSIndexPortfolio.py ├── TestFinCDSOption.py ├── TestFinCDSTranche.py ├── TestFinCalendar.py ├── TestFinDate.py ├── TestFinDateAdjust.py ├── TestFinDayCount.py ├── TestFinDiscountCurve.py ├── TestFinDiscountCurveFlat.py ├── TestFinDiscountCurveNS.py ├── TestFinDiscountCurveNSS.py ├── TestFinDiscountCurvePolynomial.py ├── TestFinDiscountCurveZeros.py ├── TestFinDiscountCurves.py ├── TestFinEquityAmericanMC.py ├── TestFinEquityAmericanOption.py ├── TestFinEquityAsianOption.py ├── TestFinEquityBarrierOption.py ├── TestFinEquityBasketOption.py ├── TestFinEquityBinomialTree.py ├── TestFinEquityChooserOption.py ├── TestFinEquityCliquetOption.py ├── TestFinEquityCompoundOption.py ├── TestFinEquityDigitalOption.py ├── TestFinEquityForward.py ├── TestFinEquityLookbackOption.py ├── TestFinEquityOneTouchOption.py ├── TestFinEquityRainbowOption.py ├── TestFinEquitySwap.py ├── TestFinEquityVanillaOption.py ├── TestFinEquityVarianceSwap.py ├── TestFinEquityVolSurface.py ├── TestFinFXAmericanOption.py ├── TestFinFXBarrierOption.py ├── TestFinFXDigitalOption.py ├── TestFinFXDoubleDigitalOption.py ├── TestFinFXForward.py ├── TestFinFXLookbackOption.py ├── TestFinFXOneTouchOption.py ├── TestFinFXOptionSABR.py ├── TestFinFXVanillaOption.py ├── TestFinFXVolSurface.py ├── TestFinFXVolSurfacePlus.py ├── TestFinGBMProcess.py ├── TestFinIborBenchmarksReport.py ├── TestFinIborBermudanSwaption.py ├── TestFinIborCapFloor.py ├── TestFinIborCapVolCurve.py ├── TestFinIborCurveParRateShock.py ├── TestFinIborCurveRiskEngine.py ├── TestFinIborDualCurve.py ├── TestFinIborFuture.py ├── TestFinIborLMMProducts.py ├── TestFinIborSingleCurve.py ├── TestFinIborSwap.py ├── TestFinIborSwaption.py ├── TestFinInflationBond.py ├── TestFinInflationIndexCurve.py ├── TestFinInterpolate.py ├── TestFinInterpolatedForwards.py ├── TestFinLossDbnBuilder.py ├── TestFinMath.py ├── TestFinMathAccruedInterp.py ├── TestFinModelBlack.py ├── TestFinModelBlackScholes.py ├── TestFinModelBlack_SABR_HW.py ├── TestFinModelCIR.py ├── TestFinModelHeston.py ├── TestFinModelMerton.py ├── TestFinModelRatesBDT.py ├── TestFinModelRatesBK.py ├── TestFinModelRatesHW.py ├── TestFinModelRatesLMM.py ├── TestFinModelSABR.py ├── TestFinModelShiftedSABR.py ├── TestFinNumbaNumpySpeed.py ├── TestFinOIS.py ├── TestFinOISCurve.py ├── TestFinOptionImpliedDbn.py ├── TestFinPieceCurve.py ├── TestFinProcessSimulator.py ├── TestFinSchedule.py ├── TestFinSobol.py ├── TestFinStatistics.py ├── TestFinSwapLegs.py ├── TestFinSwaptionVolSurface.py ├── TestFinVasicekRateModel.py ├── TestFinVolatilityCurve.py ├── __init__.py ├── compare │ └── .gitkeep ├── data │ ├── CDX_NA_IG_S7_SPREADS.csv │ ├── DowJonesPricesFromYahoo.pkl │ ├── GBP_OIS_20120919.csv │ ├── ff_assets.pkl │ ├── ff_factors.pkl │ ├── gilt_bond_prices.txt │ ├── ibor_benchmarks_example.csv │ ├── test_cases_bond_ror.csv │ └── test_cases_bond_zero_ror.csv ├── differences │ └── .gitkeep ├── golden │ ├── .gitkeep │ ├── TestFinAmount_GOLDEN.testLog │ ├── TestFinBondAnnuity_GOLDEN.testLog │ ├── TestFinBondConvertible_GOLDEN.testLog │ ├── TestFinBondEmbeddedOptionBK_GOLDEN.testLog │ ├── TestFinBondEmbeddedOptionHW_GOLDEN.testLog │ ├── TestFinBondFRN_GOLDEN.testLog │ ├── TestFinBondFutures_GOLDEN.testLog │ ├── TestFinBondMortgage_GOLDEN.testLog │ ├── TestFinBondOptionBDTModel_GOLDEN.testLog │ ├── TestFinBondOptionBKModel_GOLDEN.testLog │ ├── TestFinBondOptionHWModel_GOLDEN.testLog │ ├── TestFinBondPortfolio_GOLDEN.testLog │ ├── TestFinBondYieldCurve_GOLDEN.testLog │ ├── TestFinBondZeroCoupon_GOLDEN.testLog │ ├── TestFinBondZeroCurve_GOLDEN.testLog │ ├── TestFinBond_GOLDEN.testLog │ ├── TestFinCDSBasket_GOLDEN.testLog │ ├── TestFinCDSCurve_GOLDEN.testLog │ ├── TestFinCDSIndexAdjustHazards_GOLDEN.testLog │ ├── TestFinCDSIndexAdjustSpreads_GOLDEN.testLog │ ├── TestFinCDSIndexOption_GOLDEN.testLog │ ├── TestFinCDSIndexPortfolio_GOLDEN.testLog │ ├── TestFinCDSIndex_GOLDEN.testLog │ ├── TestFinCDSOption_GOLDEN.testLog │ ├── TestFinCDSTranche_GOLDEN.testLog │ ├── TestFinCDS_GOLDEN.testLog │ ├── TestFinCalendar_GOLDEN.testLog │ ├── TestFinDateAdjust_GOLDEN.testLog │ ├── TestFinDate_GOLDEN.testLog │ ├── TestFinDayCount_GOLDEN.testLog │ ├── TestFinDiscountCurveFlat_GOLDEN.testLog │ ├── TestFinDiscountCurveNSS_GOLDEN.testLog │ ├── TestFinDiscountCurveNS_GOLDEN.testLog │ ├── TestFinDiscountCurvePolynomial_GOLDEN.testLog │ ├── TestFinDiscountCurveZeros_GOLDEN.testLog │ ├── TestFinDiscountCurve_GOLDEN.testLog │ ├── TestFinDiscountCurves_GOLDEN.testLog │ ├── TestFinEquityAmericanMC_GOLDEN.testLog │ ├── TestFinEquityAmericanOption_GOLDEN.testLog │ ├── TestFinEquityAsianOption_GOLDEN.testLog │ ├── TestFinEquityBarrierOption_GOLDEN.testLog │ ├── TestFinEquityBasketOption_GOLDEN.testLog │ ├── TestFinEquityBinomialTree_GOLDEN.testLog │ ├── TestFinEquityChooserOption_GOLDEN.testLog │ ├── TestFinEquityCliquetOption_GOLDEN.testLog │ ├── TestFinEquityCompoundOption_GOLDEN.testLog │ ├── TestFinEquityDigitalOption_GOLDEN.testLog │ ├── TestFinEquityForward_GOLDEN.testLog │ ├── TestFinEquityLookbackOption_GOLDEN.testLog │ ├── TestFinEquityOneTouchOption_GOLDEN.testLog │ ├── TestFinEquityRainbowOption_GOLDEN.testLog │ ├── TestFinEquitySwap_GOLDEN.testLog │ ├── TestFinEquityVanillaOption_GOLDEN.testLog │ ├── TestFinEquityVarianceSwap_GOLDEN.testLog │ ├── TestFinEquityVolSurface_GOLDEN.testLog │ ├── TestFinFXAmericanOption_GOLDEN.testLog │ ├── TestFinFXBarrierOption_GOLDEN.testLog │ ├── TestFinFXBasketOption_GOLDEN.testLog │ ├── TestFinFXChooserOption_FINISH_GOLDEN.testLog │ ├── TestFinFXCompoundOption_GOLDEN.testLog │ ├── TestFinFXDigitalOption_GOLDEN.testLog │ ├── TestFinFXDoubleDigitalOption_GOLDEN.testLog │ ├── TestFinFXForward_GOLDEN.testLog │ ├── TestFinFXLookbackOption_GOLDEN.testLog │ ├── TestFinFXOneTouchOption_GOLDEN.testLog │ ├── TestFinFXOptionSABR_GOLDEN.testLog │ ├── TestFinFXVanillaOption_GOLDEN.testLog │ ├── TestFinFXVolSurfacePlus_GOLDEN.testLog │ ├── TestFinFXVolSurface_GOLDEN.testLog │ ├── TestFinFixedIborSwap_GOLDEN.testLog │ ├── TestFinFixedOIRSwap_GOLDEN.testLog │ ├── TestFinIborBermudanSwaption_GOLDEN.testLog │ ├── TestFinIborCapFloor_GOLDEN.testLog │ ├── TestFinIborCapVolCurve_GOLDEN.testLog │ ├── TestFinIborCurve_GOLDEN.testLog │ ├── TestFinIborDualCurve_GOLDEN.testLog │ ├── TestFinIborFuture_GOLDEN.testLog │ ├── TestFinIborLMMProducts_GOLDEN.testLog │ ├── TestFinIborSingleCurve_GOLDEN.testLog │ ├── TestFinIborSwap_GOLDEN.testLog │ ├── TestFinIborSwaption_GOLDEN.testLog │ ├── TestFinInflationBond_GOLDEN.testLog │ ├── TestFinInflationIndexCurve_GOLDEN.testLog │ ├── TestFinInterpolate_GOLDEN.testLog │ ├── TestFinInterpolatedForwards_GOLDEN.testLog │ ├── TestFinLossDbnBuilder_GOLDEN.testLog │ ├── TestFinMathAccruedInterp_GOLDEN.testLog │ ├── TestFinMath_GOLDEN.testLog │ ├── TestFinModelBlackScholes_GOLDEN.testLog │ ├── TestFinModelBlack_GOLDEN.testLog │ ├── TestFinModelBlack_SABR_HW_GOLDEN.testLog │ ├── TestFinModelCIR_GOLDEN.testLog │ ├── TestFinModelHeston_GOLDEN.testLog │ ├── TestFinModelMerton_GOLDEN.testLog │ ├── TestFinModelRatesBDT_GOLDEN.testLog │ ├── TestFinModelRatesBK_GOLDEN.testLog │ ├── TestFinModelRatesHW_GOLDEN.testLog │ ├── TestFinModelRatesLMM_GOLDEN.testLog │ ├── TestFinModelSABR_GOLDEN.testLog │ ├── TestFinModelShiftedSABR_GOLDEN.testLog │ ├── TestFinNumbaNumpySpeed_GOLDEN.testLog │ ├── TestFinOIRSwap_GOLDEN.testLog │ ├── TestFinOISCurve_GOLDEN.testLog │ ├── TestFinOISSingleCurve_GOLDEN.testLog │ ├── TestFinOIS_GOLDEN.testLog │ ├── TestFinOptionImpliedDbn_GOLDEN.testLog │ ├── TestFinOvernightIndexSwap_GOLDEN.testLog │ ├── TestFinPieceCurve_GOLDEN.testLog │ ├── TestFinProcessSimulator_GOLDEN.testLog │ ├── TestFinSchedule_GOLDEN.testLog │ ├── TestFinSobol_GOLDEN.testLog │ ├── TestFinStatistics_GOLDEN.testLog │ ├── TestFinSwapLegs_GOLDEN.testLog │ ├── TestFinSwaptionVolSurface_GOLDEN.testLog │ ├── TestFinVasicekRateModel_GOLDEN.testLog │ ├── TestFinVolatilityCurve_GOLDEN.testLog │ └── testfingbmprocess_GOLDEN.testLog ├── helpers.py └── run_all_tests.py ├── images └── logo.jpg ├── mkdocs.yml ├── notebooks ├── README.md ├── cleanErrors.bat ├── finutils │ ├── FINCALENDAR_IntroductionToUsingCalendars.ipynb │ ├── FINDATES_TestingDateInternals.ipynb │ ├── FINDATE_CreatingAndManipulatingFinDates.ipynb │ ├── FINDAYCOUNT_Introduction.ipynb │ ├── FINSCHEDULE_ExamplesOfScheduleGeneration.ipynb │ ├── FINSCHEDULE_ScheduleGenerationTestCases.ipynb │ └── TENSIONSPLINE_Example.ipynb ├── market │ ├── curves │ │ ├── FINDISCOUNTCURVEFLAT_ExaminationOfDiscountCurveFlat.ipynb │ │ ├── FINDISCOUNTCURVENSS_IntroductionToTheNelsonSiegelSvenssonCurve.ipynb │ │ ├── FINDISCOUNTCURVENS_ExaminingTheNelsonSiegelCurve.ipynb │ │ ├── FINDISCOUNTCURVEPOLY_SimpleAnalysis.ipynb │ │ ├── FINDISCOUNTCURVEZERO_ConvertZeroCurveToDiscountCurve.ipynb │ │ ├── FINDISCOUNTCURVE_AnalysisOfInterpolationSchemes.ipynb │ │ ├── FINDISCOUNTCURVE_Introduction.ipynb │ │ └── FINDISCOUNTCURVE_PieceWiseFlatOverNightForwardRateDiscountCurve.ipynb │ └── volatility │ │ ├── EquityVolSurfaceConstructionSVI.ipynb │ │ ├── FXVolSurfaceConstructionPartOne.ipynb │ │ ├── FXVolSurfaceConstructionPartThree.ipynb │ │ ├── FXVolSurfaceConstructionPartTwo.ipynb │ │ └── SimpleBuildFXVolatilitySurface25Delta.ipynb ├── models │ ├── CHOLESKY CHECK.ipynb │ ├── FINGBMPROCESS_generatePaths.ipynb │ ├── FINITE_DIFFERENCE.ipynb │ ├── FINITE_DIFFERENCE_PSOR.ipynb │ ├── FINMODEL_GAUSSIANCOPULA_PortfolioLossDistributionBuilder.ipynb │ ├── FINMODEL_SABRSHIFTED_InterestRates.ipynb │ ├── FINMODEL_SABRSHIFTED_VolatilitySmile.ipynb │ ├── FINMODEL_SABR_InterestRates.ipynb │ ├── FINVOLFUNCTIONS_SSVI_MODEL.ipynb │ └── MERTON_CREDIT_MODEL.ipynb ├── products │ ├── bonds │ │ ├── FINANNUITY_Valuation.ipynb │ │ ├── FINBONDCONVERTIBLE_ComparisonWithQLExample.ipynb │ │ ├── FINBONDCONVERTIBLE_ValuationAndConvergenceTest.ipynb │ │ ├── FINBONDEMBEDDEDOPTION_Valuation.ipynb │ │ ├── FINBONDFRN_CitigroupExample.ipynb │ │ ├── FINBONDFRN_ComparisonWithML_PROBLEM.ipynb │ │ ├── FINBONDFUTURES_ExampleContracts.ipynb │ │ ├── FINBONDMARKET_DatabaseOfConventions.ipynb │ │ ├── FINBONDMORTGAGE_SimpleCalculator.ipynb │ │ ├── FINBONDOPTION_All_Models_Valuation_Analysis.ipynb │ │ ├── FINBONDOPTION_BK_ModelValuationAnalysis.ipynb │ │ ├── FINBONDOPTION_HW_EXAMPLE_MATCH_DERIVA_GEN.ipynb │ │ ├── FINBONDOPTION_HW_Model_Jamshidian.ipynb │ │ ├── FINBONDOPTION_Tree_Convergence_With_Volatility.ipynb │ │ ├── FINBONDOPTION_Tree_Convergence_Zero_Vol.ipynb │ │ ├── FINBONDYIELDCURVES_FittingExample.ipynb │ │ ├── FINBONDYIELDCURVE_FittingToAswAndZSpreads.ipynb │ │ ├── FINBONDYIELDCURVE_FittingToBondMarketPrices.ipynb │ │ ├── FINBONDZEROCURVE_BootstrapOutstandingBonds.ipynb │ │ ├── FINBOND_CalculateOptionAdjustedSpread.ipynb │ │ ├── FINBOND_CalculatePriceUsingSurvivalCurve.ipynb │ │ ├── FINBOND_CalculatingTheAssetSwapSpread.ipynb │ │ ├── FINBOND_ComparisonWithQLExample.ipynb │ │ ├── FINBOND_DiscountingBondCashflowsFinDiscountCurve.ipynb │ │ ├── FINBOND_ExampleAppleCorp.ipynb │ │ ├── FINBOND_ExampleUSTreasury_CUSIP_91282CFX4.ipynb │ │ ├── FINBOND_Key_Rate_Durations_Example.ipynb │ │ ├── FINBOND_QuantStackExchangeQuestion.ipynb │ │ └── data │ │ │ ├── GBP_OIS_20120919.csv │ │ │ ├── Key_rate_duration_US91282CFB28.png │ │ │ ├── Yield_curve_data_for_krds.png │ │ │ └── giltBondPrices.txt │ ├── credit │ │ ├── FINCDSBASKET_ValuationModelComparison_REPAIR.ipynb │ │ ├── FINCDSCURVE_BuildingASurvivalCurve.ipynb │ │ ├── FINCDSINDEXOPTION_CompareValuationApproaches.ipynb │ │ ├── FINCDSINDEX_ValuingCDSIndex.ipynb │ │ ├── FINCDSOPTION_ValuingCDSOption.ipynb │ │ ├── FINCDSTRANCHE_CalculatingFairSpread.ipynb │ │ ├── FINCDS_ComparisonWithMarkitCDSModel.ipynb │ │ ├── FINCDS_ComparisonWithMarkitCDSModelV2.ipynb │ │ ├── FINCDS_CreatingAndValuingACDS.ipynb │ │ ├── FINCDS_ForwardAndBackward.ipynb │ │ ├── FINCDS_ValuingCDSCompareToMarkit.ipynb │ │ ├── FINCDS_ValuingCDSCompareToMarkitV2.ipynb │ │ └── data │ │ │ └── CDX_NA_IG_S7_SPREADS.csv │ ├── equity │ │ ├── EQUITY_AMERICANOPTION_BARONE_ADESI_WHALEY_APPROX.ipynb │ │ ├── EQUITY_AMERICANOPTION_BJERKSUND_STENSLAND_APPROX.ipynb │ │ ├── EQUITY_AMERICANOPTION_ComparisonWithQLExample.ipynb │ │ ├── EQUITY_AMERICANOPTION_ComparisonWithQLExample_CHECK.ipynb │ │ ├── EQUITY_ASIAN_OPTIONS.ipynb │ │ ├── EQUITY_BARRIER_OPTIONS.ipynb │ │ ├── EQUITY_BASKET_OPTIONS.ipynb │ │ ├── EQUITY_CHOOSER_OPTION.ipynb │ │ ├── EQUITY_CHOOSER_OPTION_ComparisonWithML.ipynb │ │ ├── EQUITY_CLIQUET_OPTION.ipynb │ │ ├── EQUITY_COMPOUND_OPTION_CompareWithML.ipynb │ │ ├── EQUITY_DIGITALOPTION_BasicValuation.ipynb │ │ ├── EQUITY_DIGITAL_CASH_OR_NOTHING_OPTION.ipynb │ │ ├── EQUITY_FIXED_LOOKBACK_OPTION.ipynb │ │ ├── EQUITY_FLOAT_LOOKBACK_OPTION.ipynb │ │ ├── EQUITY_ONE_TOUCH_OPTION.ipynb │ │ ├── EQUITY_RAINBOW_OPTION.ipynb │ │ ├── EQUITY_VANILLA_AMERICAN_STYLE_OPTION_REPAIR.ipynb │ │ ├── EQUITY_VANILLA_EUROPEAN_STYLE_MONTE_CARLO_SOBOL.ipynb │ │ ├── EQUITY_VANILLA_EUROPEAN_STYLE_MONTE_CARLO_TIMINGS.ipynb │ │ ├── EQUITY_VANILLA_EUROPEAN_STYLE_OPTION HIGH VOL LIMIT.ipynb │ │ ├── EQUITY_VANILLA_EUROPEAN_STYLE_OPTION.ipynb │ │ ├── EQUITY_VANILLA_EUROPEAN_STYLE_OPTION_VECTORISATION.ipynb │ │ ├── EQUITY_VANILLA_OPTION_IntradayValuationAndGreeks.ipynb │ │ ├── EQUITY_VANILLA_OPTION_ValuationAndGreeks_ERROR.ipynb │ │ └── EQUITY_VARIANCESWAP_Basic_Example.ipynb │ ├── fx │ │ ├── FXOneTouchOption.ipynb │ │ └── FXOptionAnalysisAndDeltas.ipynb │ └── rates │ │ ├── FINIBORBERMUDANSWAPTION_All_Valuation_Models.ipynb │ │ ├── FINIBORBERMUDANSWAPTION_Hull_White_Tree.ipynb │ │ ├── FINIBORCAPFLOOR_ComparisonWithQLExample.ipynb │ │ ├── FINIBORCAPFLOOR_ValuationAcrossAllModels.ipynb │ │ ├── FINIBORDUALCURVE_BuildingASimpleDualIborCurve.ipynb │ │ ├── FINIBORDUALCURVE_BuildingEuriborDualCurveFollowingQLExample.ipynb │ │ ├── FINIBORDUALCURVE_BuildingEuriborDualCurveSwapValuationQLExampleDeriscope.ipynb │ │ ├── FINIBORDUALCURVE_BuildingUSDDualCurveSwapValuationQLExampleDeriscope.ipynb │ │ ├── FINIBORDUALCURVE_Building_EURIBOR_DualCurve_Bloomberg_Example.ipynb │ │ ├── FINIBORDUALCURVE_ValueUSDSwapUsingDifferentCurveBuildingAssumptions.ipynb │ │ ├── FINIBORSINGLECURVE_AnalysisOfForwards.ipynb │ │ ├── FINIBORSINGLECURVE_BuildingASimpleIborCurve.ipynb │ │ ├── FINIBORSINGLECURVE_BuildingAnIborCurve.ipynb │ │ ├── FINIBORSINGLECURVE_BuildingIborCurveInterpolationCOMPLEX.ipynb │ │ ├── FINIBORSINGLECURVE_BuildingIborCurveInterpolationSIMPLE.ipynb │ │ ├── FINIBORSINGLECURVE_BuildingInterpolationChoice.ipynb │ │ ├── FINIBORSINGLECURVE_IborCurveApplyParBump.ipynb │ │ ├── FINIBORSINGLECURVE_IborCurveCalibrateSmooth.ipynb │ │ ├── FINIBORSINGLECURVE_ReplicatingBBGExample.ipynb │ │ ├── FINIBORSINGLECURVE_ReplicatingQuantlibExample.ipynb │ │ ├── FINIBORSWAPTION_All_Models_Analysis.ipynb │ │ ├── FINIBORSWAPTION_ComparisonWithMLExample.ipynb │ │ ├── FINIBORSWAPTION_ComparisonWithQLExample.ipynb │ │ ├── FINIBORSWAPTION_ValuingAcrossModels.ipynb │ │ ├── FINIBORSWAP_BusinessDayConventions.ipynb │ │ ├── FINIBORSWAP_ComparisonWithQLExample.ipynb │ │ ├── FINIBORSWAP_DefiningAFixedFloatingSwap.ipynb │ │ ├── FINIBORSWAP_SettingTheScheduleDirectly.ipynb │ │ ├── FINOISCURVE_BuildingAnOISCurveWithMeetingDates.ipynb │ │ └── FINOISCURVE_BuildingEONIACurveFollowingQLExample.ipynb └── testNotebooks.py ├── requirements-dev.txt ├── requirements.txt ├── setup.py ├── unit_tests ├── data │ ├── CDX_NA_IG_S7_SPREADS.csv │ ├── GBP_OIS_20120919.csv │ ├── gilt_bond_prices.txt │ ├── ibor_benchmarks_example.csv │ ├── test_cases_bond_cfets.csv │ ├── test_cases_bond_ror.csv │ └── test_cases_bond_zero_ror.csv ├── helpers.py ├── test_FinAmount.py ├── test_FinBond.py ├── test_FinBondAnnuity.py ├── test_FinBondConvertible.py ├── test_FinBondEmbeddedOption.py ├── test_FinBondFRN.py ├── test_FinBondFutures.py ├── test_FinBondMortgage.py ├── test_FinBondOption.py ├── test_FinBondPortfolio.py ├── test_FinBondYieldCurve.py ├── test_FinBondZSpread.py ├── test_FinBondZeroCurve.py ├── test_FinCDS.py ├── test_FinCDSBasket.py ├── test_FinCDSCurve.py ├── test_FinCDSIndex.py ├── test_FinCDSIndexAdjustHazards.py ├── test_FinCDSIndexAdjustSpreads.py ├── test_FinCDSIndexOption.py ├── test_FinCDSIndexPortfolio.py ├── test_FinCDSOption.py ├── test_FinCDSTranche.py ├── test_FinCalendar.py ├── test_FinDateAdjust.py ├── test_FinDayCount.py ├── test_FinDiscountCurveComposite.py ├── test_FinDiscountCurveFlat.py ├── test_FinDiscountCurveNS.py ├── test_FinDiscountCurveNSS.py ├── test_FinDiscountCurvePWFONF.py ├── test_FinDiscountCurveZeros.py ├── test_FinEquityAmericanOption.py ├── test_FinEquityAsianOption.py ├── test_FinEquityBarrierOption.py ├── test_FinEquityBasketOption.py ├── test_FinEquityBinomialTree.py ├── test_FinEquityChooserOption.py ├── test_FinEquityCliquetOption.py ├── test_FinEquityCompoundOption.py ├── test_FinEquityDigitalOption.py ├── test_FinEquityForward.py ├── test_FinEquityIndexOption.py ├── test_FinEquityLookbackOption.py ├── test_FinEquityOneTouchOption.py ├── test_FinEquityRainbowOption.py ├── test_FinEquitySwap.py ├── test_FinEquityVanillaOption.py ├── test_FinEquityVarianceSwap.py ├── test_FinEquityVolSurface.py ├── test_FinFXAmericanOption.py ├── test_FinFXBarrierOption.py ├── test_FinFXForward.py ├── test_FinFXLookbackOption.py ├── test_FinFXOptionSABR.py ├── test_FinFXVanillaOption.py ├── test_FinFXVolSurface.py ├── test_FinFXVolSurfacePlus.py ├── test_FinIborBenchmarksReport.py ├── test_FinIborBermudanSwaption.py ├── test_FinIborCapFloor.py ├── test_FinIborCapVolCurve.py ├── test_FinIborCurveParRateShock.py ├── test_FinIborCurveRiskEngine.py ├── test_FinIborDualCurve.py ├── test_FinIborFuture.py ├── test_FinIborSingleCurve.py ├── test_FinIborSingleCurveSmoothCalibrator.py ├── test_FinIborSwap.py ├── test_FinIborSwaption.py ├── test_FinInflationBond.py ├── test_FinInflationIndexCurve.py ├── test_FinInterpolate.py ├── test_FinInterpolatedForwards.py ├── test_FinLossDbnBuilder.py ├── test_FinMath.py ├── test_FinModelBlack.py ├── test_FinModelBlackScholes.py ├── test_FinModelCIR.py ├── test_FinModelHeston.py ├── test_FinModelMerton.py ├── test_FinModelRatesBDT.py ├── test_FinModelRatesBK.py ├── test_FinModelRatesHW.py ├── test_FinModelRatesLMM.py ├── test_FinModelSABR.py ├── test_FinModelShiftedSABR.py ├── test_FinOIS.py ├── test_FinOISCurve.py ├── test_FinSchedule.py ├── test_FinSobol.py ├── test_FinStatistics.py ├── test_FinSwapLegs.py ├── test_FinVasicekRateModel.py ├── test_TensionSpline.py ├── test_date.py ├── test_finite_difference.py ├── test_finite_difference_PSOR.py ├── test_lsmc.py └── test_tenor.py └── version.py /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | patreon: domokane 4 | -------------------------------------------------------------------------------- /.github/workflows/pylint.yml: -------------------------------------------------------------------------------- 1 | name: Pylint 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | runs-on: ubuntu-latest 8 | strategy: 9 | matrix: 10 | python-version: ["3.8"] 11 | steps: 12 | - uses: actions/checkout@v3 13 | - name: Set up Python ${{ matrix.python-version }} 14 | uses: actions/setup-python@v3 15 | with: 16 | python-version: ${{ matrix.python-version }} 17 | - name: Install dependencies 18 | run: | 19 | python -m pip install --upgrade pip 20 | pip install pylint 21 | - name: Analysing the code with pylint 22 | run: | 23 | pylint --rcfile=.pylintrc financepy 24 | 25 | -------------------------------------------------------------------------------- /.github/workflows/run-golden-tests.yml: -------------------------------------------------------------------------------- 1 | name: golden tests 2 | 3 | on: [push, pull_request] 4 | 5 | env: 6 | PYTHON_VERSION: 3.11 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: checkout repo content 13 | uses: actions/checkout@v4 14 | - name: setup python 15 | uses: actions/setup-python@v4 16 | with: 17 | python-version: ${{ env.PYTHON_VERSION }} 18 | - name: Install dependencies and package 19 | run: | 20 | pip install -r requirements.txt 21 | pip install -r requirements-dev.txt 22 | python setup.py install 23 | - name: Run tests 24 | run: 25 | python golden_tests/run_all_tests.py 26 | - name: Archive code coverage results 27 | uses: actions/upload-artifact@v4 28 | with: 29 | name: result-differences-file-upload 30 | path: golden_tests/differences/*.testLog 31 | -------------------------------------------------------------------------------- /.github/workflows/run-unit-tests.yml: -------------------------------------------------------------------------------- 1 | name: unit test action 2 | 3 | on: [push, pull_request] 4 | 5 | env: 6 | PYTHON_VERSION: 3.11 7 | 8 | jobs: 9 | build: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: checkout repo content 13 | uses: actions/checkout@v4 14 | - name: setup python 15 | uses: actions/setup-python@v4 16 | with: 17 | python-version: ${{ env.PYTHON_VERSION }} 18 | - name: install dependencies 19 | run: | 20 | python -m pip install --upgrade pip 21 | pip install -r requirements.txt 22 | pip install -r requirements-dev.txt 23 | pip install pytest 24 | pip install -e . 25 | - name: show package is importable 26 | run: | 27 | python -c "import financepy as fp" 28 | - name: list dependencies 29 | run: | 30 | pip list 31 | - name: unit tests 32 | run: | 33 | pytest -vv 34 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## CHANGE LOG 2 | 1 May 2024 version 0.360 released 3 | - Fixed all notebooks to ensure they all work with current version 4 | - Unit tests complete with success 5 | - Gradually removing underscore prefix from class member variable names 6 | - Adjustments to accrued interest calculations for FRN (need a consistent interface) 7 | 8 | 19 February 2024 version 0.350 released 9 | - A lot of various pep8 fixes - should all be nearly done soon 10 | - Fixed a bug in gauss_approx_tranche_loss 11 | 12 | 9 December 2023 version 0.34 released 13 | - A lot of various pep8 fixes - should all be nearly done soon 14 | - Some minor bug fixes 15 | 16 | 10 November 2023 version 0.33 released 17 | - Tidied up key rate code 18 | - Fixed unit tests for pytest 19 | - Fixed vectorisation of barrier options 20 | - Various pep8 fixes 21 | 22 | 28 August 2023 - version 0.32 released 23 | - Fixed bug in Bond OAS and ASW 24 | 25 | 24 August 2023 - Version 0.31 released 26 | 27 | - Schedule 28 | - Corrected bug in schedule generation 29 | - Corrected bug in CDS protection leg integral 30 | 31 | - Many Bond Classes have been amended 32 | - Changed FULL price to DIRTY price in functions UPDATE YOUR CODE PLEASE. APOLS for inconvenience. 33 | - Removed face amount from bond class - how much you buy is not intrinsic to a bond 34 | - Made number of ex-dividend days a member of bond class 35 | - Added adjustment for ex-dividend dates to yield calculations 36 | - Revised accrued and principal functions to take face amount as input 37 | - Updated document 38 | 39 | 29 May 2023 - Version 0.30 released 40 | - Added PrettyPrint to required dependencies 41 | 42 | 22 Nov 22 43 | Version 0.260 has been released and pushed to PyPI 44 | - Create Date from python datetime 45 | - Zero coupon bond class 46 | - Fixed bug in bond payment date 47 | 48 | 31-Aug-2022 49 | Version 0.240 has just been released and pushed to PyPI with changes 50 | - Negative terms in date class 51 | - Recovery rates do not default to standard value for CDS curves 52 | 53 | 54 | -------------------------------------------------------------------------------- /FinancePyManual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/domokane/FinancePy/7ca2a16354076cad672c03add5c3fb444159223b/FinancePyManual.pdf -------------------------------------------------------------------------------- /book/ALL FINANCEPY/README.md: -------------------------------------------------------------------------------- 1 | # Using FinancePy in a Jupyter Notebook 2 | 3 | Once financepy has been installed, it is easy to get started. 4 | 5 | Just download the project and examine the set of Jupyter Notebooks in this notebooks folder. 6 | 7 | These have been organised according to the same directory structure as the project. 8 | 9 | A pdf manual describing all of the functions can be found in the project directory. 10 | -------------------------------------------------------------------------------- /book/ALL FINANCEPY/cleanErrors.bat: -------------------------------------------------------------------------------- 1 | del /S ERROR_*.ipynb 2 | -------------------------------------------------------------------------------- /book/ALL FINANCEPY/testNotebooks.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Sun Jan 17 12:36:01 2021 4 | 5 | @author: Dominic 6 | """ 7 | 8 | import os 9 | 10 | import nbformat 11 | 12 | from nbconvert.preprocessors import ExecutePreprocessor 13 | from nbconvert.preprocessors import CellExecutionError 14 | 15 | import glob 16 | from os.path import dirname, join 17 | 18 | print("Looking in folder:", dirname(__file__)) 19 | 20 | notebooks = sorted( 21 | glob.glob(join(dirname(__file__), "./products/*/*.ipynb"), recursive=True)) 22 | 23 | ############################################################################### 24 | 25 | 26 | def notebook_run_new(notebook_filepathname): 27 | """Execute a notebook via nbconvert and collect output. 28 | :returns (parsed nb object, execution errors) 29 | """ 30 | 31 | dirname, filename = os.path.split(notebook_filepathname) 32 | 33 | os.chdir(dirname) 34 | 35 | nb = nbformat.read(open(notebook), as_version=4) 36 | ep = ExecutePreprocessor(timeout=600, kernel_name='python3') 37 | 38 | # notebook_filename_err = dirname + "//ERROR_" + filename 39 | 40 | try: 41 | 42 | out = ep.preprocess(nb, {'metadata': {'path': ".//"}}) 43 | 44 | # Save notebook 45 | with open(notebook_filepathname, mode='w', encoding='utf-8') as f: 46 | nbformat.write(nb, f) 47 | 48 | except CellExecutionError: 49 | 50 | msg = 'Error executing the notebook "%s".\n\n' % filename 51 | print(msg) 52 | 53 | # with open(notebook_filename_err, mode='w', encoding='utf-8') as f: 54 | # nbformat.write(nb, f) 55 | 56 | pass 57 | 58 | ############################################################################### 59 | 60 | 61 | print("Starting") 62 | n = 0 63 | m = len(notebooks) 64 | print(n, m) 65 | for notebook in notebooks[n:m+1]: 66 | dirname, filename = os.path.split(notebook) 67 | print("Checking Notebook", n+1, "of", m, ":", filename) 68 | notebook_run_new(notebook) 69 | n = n + 1 70 | -------------------------------------------------------------------------------- /docs/FinancePyManual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/domokane/FinancePy/7ca2a16354076cad672c03add5c3fb444159223b/docs/FinancePyManual.pdf -------------------------------------------------------------------------------- /docs/generate.py: -------------------------------------------------------------------------------- 1 | """Generate the code reference pages.""" 2 | 3 | from pathlib import Path 4 | import mkdocs_gen_files 5 | 6 | root = Path(__file__).parent.parent 7 | print(root) 8 | src = root / "financepy" 9 | 10 | for path in sorted(src.rglob("*.py")): 11 | module_path = path.relative_to(src).with_suffix("") 12 | doc_path = path.relative_to(src).with_suffix(".md") 13 | full_doc_path = Path("reference", doc_path) 14 | 15 | parts = tuple(module_path.parts) 16 | 17 | if parts[-1] == "__init__": 18 | parts = parts[:-1] 19 | elif parts[-1] == "__main__": 20 | continue 21 | 22 | if not parts: 23 | continue 24 | 25 | with mkdocs_gen_files.open(full_doc_path, "w") as fd: 26 | identifier = ".".join(("financepy",) + parts) 27 | if not identifier.strip(): 28 | continue 29 | print("::: " + identifier, file=fd) 30 | 31 | mkdocs_gen_files.set_edit_path(full_doc_path, path.relative_to(root)) 32 | -------------------------------------------------------------------------------- /docs/tail.tex: -------------------------------------------------------------------------------- 1 | \end{document} 2 | -------------------------------------------------------------------------------- /financepy/__init.py: -------------------------------------------------------------------------------- 1 | cr = "\n" 2 | 3 | s = "####################################################################" + cr 4 | s += "# FINANCEPY BETA Version " + str('0.360') + " - This build: 30 Sep 2024 at 13:30 #" + cr 5 | s += "# This software is distributed FREE AND WITHOUT ANY WARRANTY #" + cr 6 | s += "# Report bugs as issues at https://github.com/domokane/FinancePy #" + cr 7 | s += "####################################################################" 8 | s += cr 9 | 10 | print(s) 11 | -------------------------------------------------------------------------------- /financepy/__init__.py: -------------------------------------------------------------------------------- 1 | cr = "\n" 2 | 3 | s = "####################################################################" + cr 4 | s += "# FINANCEPY BETA Version " + str('0.370') + " - This build: 28 Oct 2024 at 20:29 #" + cr 5 | s += "# This software is distributed FREE AND WITHOUT ANY WARRANTY #" + cr 6 | s += "# Report bugs as issues at https://github.com/domokane/FinancePy #" + cr 7 | s += "####################################################################" 8 | s += cr 9 | 10 | print(s) 11 | -------------------------------------------------------------------------------- /financepy/__init__.template: -------------------------------------------------------------------------------- 1 | cr = "\n" 2 | 3 | s = "####################################################################" + cr 4 | s += "# FINANCEPY BETA Version " + str(__version__) + " - This build: __dateandtime__ #" + cr 5 | s += "# This software is distributed FREE AND WITHOUT ANY WARRANTY #" + cr 6 | s += "# Report bugs as issues at https://github.com/domokane/FinancePy #" + cr 7 | s += "####################################################################" 8 | s += cr 9 | 10 | print(s) 11 | -------------------------------------------------------------------------------- /financepy/market/README.md: -------------------------------------------------------------------------------- 1 | # Market 2 | ## Overview 3 | This folder contains a range of market data needed to price the products. These are separated into three categories: 4 | 5 | * Curves - These are interest rate and credit curves needed to discount future cash flows. 6 | * Prices - Market prices 7 | * Volatility - Volatility term structures and surfaces for various product types. -------------------------------------------------------------------------------- /financepy/market/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/domokane/FinancePy/7ca2a16354076cad672c03add5c3fb444159223b/financepy/market/__init__.py -------------------------------------------------------------------------------- /financepy/market/curves/__init__.py: -------------------------------------------------------------------------------- 1 | from .interpolator import * 2 | from .discount_curve import * 3 | from .discount_curve_flat import * 4 | from .discount_curve_ns import * 5 | from .discount_curve_nss import * 6 | from .discount_curve_pwf import * 7 | from .discount_curve_pwl import * 8 | from .discount_curve_poly import * 9 | from .discount_curve_zeros import * 10 | -------------------------------------------------------------------------------- /financepy/market/prices/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/domokane/FinancePy/7ca2a16354076cad672c03add5c3fb444159223b/financepy/market/prices/README.md -------------------------------------------------------------------------------- /financepy/market/prices/__init__.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | -------------------------------------------------------------------------------- /financepy/market/volatility/README.md: -------------------------------------------------------------------------------- 1 | # Market Volatility 2 | These modules create a family of curve types related to the market volatility. There are three types of class: 3 | 4 | 1. Term structures of volatility i.e. volatility as a function of option expiry date. 5 | 2. Volatility curves which are smile/skews so store volatility as a function of option strike. 6 | 3. Volatility surfaces which hold volatility as a function of option expiry date AND option strike. 7 | 8 | The classes are as follows: 9 | 10 | ### equity_vol_surface 11 | Constructs an equity volatility surface that fits to a grid of market volatilities at a set of strikes and expiry dates. It implements the SVI parametric form for fitting and interpolating volatilities. It also provides plotting of the volatility curve and surfaces. 12 | 13 | ### FinFXVolSurface 14 | FX volatility as a function of option expiry and strike. This class constructs the surface from the ATM volatility plus a choice of 10 and 25 delta strangles and risk reversals or both. This is done for multiple expiry dates. A number of curve fitting choices are possible including polynomial in delta and SABR. 15 | 16 | ## FinIborCapFloorVol 17 | Libor cap/floor volatility as a function of option expiry (cap/floor start date). Takes in cap (flat) volatility and bootstraps the caplet volatility. This is assumed to be piecewise flat. 18 | 19 | ## FinIborCapFloorVolFn 20 | Parametric function for storing the cap and caplet volatilities based on form proposed by Rebonato. -------------------------------------------------------------------------------- /financepy/market/volatility/__init__.py: -------------------------------------------------------------------------------- 1 | from .equity_vol_curve import * 2 | from .equity_vol_surface import * 3 | # from .fx_vol_surface import * 4 | from .fx_vol_surface_plus import * 5 | from .ibor_cap_vol_curve import * 6 | -------------------------------------------------------------------------------- /financepy/market/volatility/ibor_cap_vol_curve_fn.py: -------------------------------------------------------------------------------- 1 | ############################################################################## 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################## 4 | 5 | import numpy as np 6 | 7 | from ...utils.error import FinError 8 | from ...utils.date import Date 9 | from ...utils.global_vars import g_days_in_year 10 | 11 | ############################################################################### 12 | # TODO: Market calibration (fitting) 13 | ############################################################################### 14 | 15 | 16 | class IborCapVolCurveFn: 17 | """Class to manage a term structure of caplet volatilities using the 18 | parametric form suggested by Rebonato (1999).""" 19 | 20 | def __init__(self, curve_dt, a, b, c, d): 21 | 22 | self._curve_dt = curve_dt 23 | self._a = a 24 | self._b = b 25 | self._c = c 26 | self._d = d 27 | 28 | ########################################################################### 29 | 30 | def cap_floorlet_vol(self, dt): 31 | """Return the caplet volatility.""" 32 | 33 | if isinstance(dt, Date): 34 | t = (dt - self._curve_dt) / g_days_in_year 35 | else: 36 | t = dt 37 | 38 | vol = (self._a + self._b * t) * np.exp(-self._c * t) + self._d 39 | 40 | if vol < 0.0: 41 | raise FinError("Negative volatility. Not permitted.") 42 | 43 | return vol 44 | 45 | 46 | ############################################################################### 47 | -------------------------------------------------------------------------------- /financepy/models/__init__.py: -------------------------------------------------------------------------------- 1 | # from .FinMertonCreditModel import * 2 | # from .FinModelBachelier import * 3 | # from .FinModelBlack import * 4 | # from .FinModelBlackScholes import * 5 | # from .FinModelBlackShifted import * 6 | # from .FinModelCRRTree import * 7 | # from .FinModelGaussianCopula import * 8 | # from .FinModelGaussianCopula1F import * 9 | # from .FinModelGaussianCopulaLHP import * 10 | # from .FinModelHeston import * 11 | # from .FinModelLHPlus import * 12 | # from .FinModelLossDbnBuilder import * 13 | # from .BDTTree import * 14 | # from .BKTree import * 15 | # from .FinModelRatesCIR import * 16 | # from .FinModelRatesHL import * 17 | # from .HWTree import * 18 | # from .FinModelRatesLMM import * 19 | # from .FinModelRatesVasicek import * 20 | # from .SABR import * 21 | # from .SABRShifted import * 22 | # from .FinModelStudentTCopula import * 23 | # from .FinProcessSimulator import * 24 | -------------------------------------------------------------------------------- /financepy/models/bond_analytics.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/domokane/FinancePy/7ca2a16354076cad672c03add5c3fb444159223b/financepy/models/bond_analytics.py -------------------------------------------------------------------------------- /financepy/models/gauss_copula.py: -------------------------------------------------------------------------------- 1 | ############################################################################## 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################## 4 | 5 | # TODO: Use Numba to speed this up more. 6 | 7 | import numpy as np 8 | 9 | from ..utils.math import N 10 | from ..utils.helpers import uniform_to_default_time 11 | 12 | ############################################################################### 13 | # TODO: 14 | ############################################################################### 15 | 16 | 17 | def default_times_gc(issuer_curves, 18 | corr_matrix, 19 | num_trials, 20 | seed): 21 | """ Generate a matrix of default times by credit and trial using a 22 | Gaussian copula model using a full rank correlation matrix. """ 23 | 24 | np.random.seed(seed) 25 | num_credits = len(issuer_curves) 26 | x = np.random.normal(0.0, 1.0, size=(num_credits, num_trials)) 27 | c = np.linalg.cholesky(corr_matrix) 28 | y = np.dot(c, x) 29 | 30 | corr_times = np.empty(shape=(num_credits, 2 * num_trials)) 31 | 32 | for i_credit in range(0, num_credits): 33 | issuer_curve = issuer_curves[i_credit] 34 | for i_trial in range(0, num_trials): 35 | g = y[i_credit, i_trial] 36 | u1 = 1.0 - N(g) 37 | u2 = 1.0 - u1 38 | times = issuer_curve._times 39 | values = issuer_curve._values 40 | t1 = uniform_to_default_time(u1, times, values) 41 | t2 = uniform_to_default_time(u2, times, values) 42 | corr_times[i_credit, i_trial] = t1 43 | corr_times[i_credit, num_trials + i_trial] = t2 44 | 45 | return corr_times 46 | 47 | ########################################################################## 48 | -------------------------------------------------------------------------------- /financepy/models/model.py: -------------------------------------------------------------------------------- 1 | ############################################################################## 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################## 4 | 5 | ############################################################################### 6 | 7 | class Model(): 8 | 9 | def __init__(self): 10 | pass 11 | 12 | ############################################################################### 13 | -------------------------------------------------------------------------------- /financepy/models/option_implied_dbn.py: -------------------------------------------------------------------------------- 1 | ############################################################################## 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################## 4 | 5 | # TODO Fix this 6 | 7 | import numpy as np 8 | # from numba import njit, float64 9 | 10 | from ..utils.global_types import OptionTypes 11 | from ..utils.error import FinError 12 | 13 | from .black_scholes_analytic import bs_value 14 | 15 | ############################################################################### 16 | # Analytical Black Scholes model implementation and approximations 17 | ############################################################################### 18 | 19 | 20 | # @njit(float64[:](float64, float64, float64, float64, float64[:], 21 | # float64[:]), cache=True, fastmath=True) 22 | def option_implied_dbn(s, t, r, q, strikes, sigmas): 23 | """ This function calculates the option smile/skew-implied probability 24 | density function times the interval width. """ 25 | 26 | if len(strikes) != len(sigmas): 27 | raise FinError("Strike and Sigma vector do not have same length.") 28 | 29 | num_steps = len(strikes) 30 | 31 | sigma = sigmas[0] 32 | strike = strikes[0] 33 | 34 | sigma = sigmas[1] 35 | strike = strikes[1] 36 | 37 | inflator = np.exp((r-0) * t) 38 | dK = strikes[1] - strikes[0] 39 | values = np.zeros(num_steps) 40 | 41 | for ik in range(0, num_steps): 42 | strike = strikes[ik] 43 | sigma = sigmas[ik] 44 | v = bs_value(s, t, strike, r, q, sigma, 45 | OptionTypes.EUROPEAN_CALL.value) 46 | 47 | values[ik] = v 48 | 49 | # Calculate the density rho(K) dK 50 | densitydk = np.zeros(num_steps) 51 | 52 | for ik in range(1, num_steps-1): 53 | d2VdK2 = (values[ik+1] - 2.0 * values[ik] + values[ik-1]) / dK 54 | 55 | # print("%d %12.8f %12.8f %12.8f" % 56 | # (ik, strikes[ik], values[ik], d2VdK2)) 57 | 58 | densitydk[ik] = d2VdK2 * inflator 59 | 60 | return densitydk 61 | 62 | ############################################################################### 63 | -------------------------------------------------------------------------------- /financepy/models/sobolcoeff.npz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/domokane/FinancePy/7ca2a16354076cad672c03add5c3fb444159223b/financepy/models/sobolcoeff.npz -------------------------------------------------------------------------------- /financepy/models/student_t_copula.py: -------------------------------------------------------------------------------- 1 | ############################################################################## 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################## 4 | 5 | from math import sqrt 6 | import numpy as np 7 | from scipy.stats import t as student 8 | 9 | from ..utils.helpers import uniform_to_default_time 10 | 11 | ############################################################################### 12 | 13 | 14 | class StudentTCopula(): 15 | 16 | def default_times(self, 17 | issuer_curves, 18 | corr_matrix, 19 | degrees_of_freedom, 20 | num_trials, 21 | seed): 22 | 23 | np.random.seed(seed) 24 | num_credits = len(issuer_curves) 25 | x = np.random.normal(0.0, 1.0, size=(num_credits, num_trials)) 26 | c = np.linalg.cholesky(corr_matrix) 27 | y = np.dot(c, x) 28 | 29 | corr_times = np.empty(shape=(num_credits, 2 * num_trials)) 30 | 31 | for i_trial in range(0, num_trials): 32 | chi2 = np.random.chisquare(degrees_of_freedom) 33 | c = sqrt(chi2 / degrees_of_freedom) 34 | for i_credit in range(0, num_credits): 35 | issuer_curve = issuer_curves[i_credit] 36 | g = y[i_credit, i_trial] / c 37 | u1 = student.cdf(g, degrees_of_freedom) 38 | u2 = 1.0 - u1 39 | times = issuer_curve.times() 40 | values = issuer_curve.values() 41 | t1 = uniform_to_default_time(u1, times, values) 42 | t2 = uniform_to_default_time(u2, times, values) 43 | corr_times[i_credit, i_trial] = t1 44 | corr_times[i_credit, i_trial + num_trials] = t2 45 | 46 | return corr_times 47 | 48 | ############################################################################### 49 | -------------------------------------------------------------------------------- /financepy/products/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/domokane/FinancePy/7ca2a16354076cad672c03add5c3fb444159223b/financepy/products/__init__.py -------------------------------------------------------------------------------- /financepy/products/bonds/__init__.py: -------------------------------------------------------------------------------- 1 | from .bond import * 2 | from .bond_zero import * 3 | from .bond_annuity import * 4 | from .bond_zero_curve import * 5 | from .bond_convertible import * 6 | from .bond_callable import * 7 | from .bond_frn import * 8 | from .bond_future import * 9 | from .bond_market import * 10 | from .bond_option import * 11 | from .bond_yield_curve import * 12 | from .curve_fits import * 13 | from .bond_mortgage import * 14 | -------------------------------------------------------------------------------- /financepy/products/credit/README.md: -------------------------------------------------------------------------------- 1 | This folder contains a set of credit-related assets ranging from CDS to CDS options, to CDS indices, CDS index options and then to CDS tranches. They are as follows: 2 | * CDS is a credit default swap contract. It includes schedule generation, contract valuation and risk-management functionality. 3 | * CDSBasket is a credit default basket such as a first-to-default basket. The class includes valuation according to the Gaussian copula. 4 | * CDSCurve is a discount curve and survival curve constructed from discount rates and CDS spreads. 5 | * CDSIndexOption is an option on an index of CDS such as CDX or iTraxx. A full valuation model is included. 6 | * CDSIndexPortfolio is a portfolio of CDS contracts. 7 | * CDSOption is an option on a single CDS. The strike is expressed in spread terms and the option is European style. It is different from an option on a CDS index option. A suitable pricing model is provided which adjusts for the risk that the reference credit defaults before the option expiry date. 8 | * CDSTranche is a synthetic CDO tranche. This is a financial derivative which takes a loss if the total loss on the portfolio exceeds a lower threshold K1 and which is wiped out if it exceeds a higher threshold K2. The value depends on the default correlation between the assets in the portfolio of credits. This also includes a valuation model based on the Gaussian copula model. 9 | 10 | ### FinCDSCurve 11 | This is a curve that has been calibrated to fit the market term structure of CDS contracts given a recovery rate assumption and a IborSingleCurve discount curve. It also contains a IborCurve object for discounting. It has methods for fitting the curve and also for extracting survival probabilities. 12 | -------------------------------------------------------------------------------- /financepy/products/credit/__init__.py: -------------------------------------------------------------------------------- 1 | from .cds import * 2 | from .cds_curve import * 3 | from .cds_basket import * 4 | from .cds_index_option import * 5 | from .cds_index_portfolio import * 6 | from .cds_option import * 7 | from .cds_tranche import * 8 | -------------------------------------------------------------------------------- /financepy/products/equity/README.md: -------------------------------------------------------------------------------- 1 | #Equity Products 2 | This folder contains a set of Equity-related products. It includes: 3 | 4 | ## EquityVanillaOption 5 | Handles simple European-style call and put options on a dividend paying stock with analytical and monte-carlo valuations. 6 | 7 | ## EquityAmericanOption 8 | Handles America-style call and put options on a dividend paying stock with tree-based valuations. 9 | 10 | ## EquityAsianOption 11 | Handles call and put options where the payoff is determined by the average-stock price over some period before expiry. 12 | 13 | ## EquityBasketOption 14 | Handles call and put options on a basket of assets, with an analytical and Monte-Carlo valuation according to Black-Scholes model. 15 | 16 | ## EquityCompoundOption 17 | Handles options to choose to enter into a call or put option. Has an analytical valuation model for European style options and a tree model if either or both options are American style exercise. 18 | 19 | ## EquityDigitalOption 20 | Handles European-style options to receive cash or nothing, or to receive the asset or nothing. Has an analytical valuation model for European style options. 21 | 22 | ## EquityFixedLookbackOption 23 | Handles European-style options to receive the positive difference between the strike and the minimum (put) or maximum (call) of the stock price over the option life. 24 | 25 | ## EquityFloatLookbackOption 26 | Handles an equity option in which the strike of the option is not fixed but is set at expiry to equal the minimum stock price in the case of a call or the maximum stock price in the case of a put. In other words the buyer of the call gets to buy the asset at the lowest price over the period before expiry while the buyer of the put gets to sell the asset at the highest price before expiry. """ 27 | 28 | ## EquityBarrierOption 29 | Handles an option which either knocks-in or knocks-out if a specified barrier is crossed from above or below, resulting in owning or not owning a call or a put option. There are eight variations which are all valued. 30 | 31 | ## EquityRainbowOption 32 | TBD 33 | 34 | ## EquityVarianceSwap 35 | TBD 36 | 37 | Products that have not yet been implemented include: 38 | * Power Options 39 | * Ratchet Options 40 | * Forward Start Options 41 | * Log Options 42 | -------------------------------------------------------------------------------- /financepy/products/equity/__init__.py: -------------------------------------------------------------------------------- 1 | from .equity_asian_option import * 2 | from .equity_american_option import * 3 | from .equity_barrier_option import * 4 | from .equity_basket_option import * 5 | from .equity_binomial_tree import * 6 | from .equity_chooser_option import * 7 | from .equity_cliquet_option import * 8 | from .equity_compound_option import * 9 | from .equity_digital_option import * 10 | from .equity_fixed_lookback_option import * 11 | from .equity_float_lookback_option import * 12 | from .equity_model_types import * 13 | from .equity_option import * 14 | from .equity_rainbow_option import * 15 | from .equity_vanilla_option import * 16 | from .equity_variance_swap import * 17 | from .equity_one_touch_option import * 18 | from .equity_forward import * 19 | from .equity_swap_leg import * 20 | from .equity_swap import * 21 | 22 | # dividend_curve = FinDiscountCurveFlat(value_dt, dividend_yield) 23 | -------------------------------------------------------------------------------- /financepy/products/equity/equity_model_types.py: -------------------------------------------------------------------------------- 1 | ############################################################################## 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################## 4 | 5 | from ...utils.helpers import label_to_string 6 | 7 | ############################################################################### 8 | 9 | 10 | class EquityModel: 11 | """ This is a parent class for equity models. """ 12 | 13 | def __init__(self): 14 | pass 15 | 16 | ############################################################################### 17 | 18 | 19 | # class EquityModelBlackScholes(EquityModel): 20 | # def __init__(self, 21 | # volatility: float, 22 | # implementation, parameters): 23 | 24 | # check_argument_types(self.__init__, locals()) 25 | 26 | # self.volatility = volatility 27 | # self.implementation = implementation 28 | # self.parameters = parameters 29 | 30 | # def __repr__(self): 31 | # s = label_to_string("OBJECT TYPE", type(self).__name__) 32 | # s += label_to_string("VOLATILITY", self.volatility) 33 | # s += label_to_string("IMPLEMENTATION", self.implementation) 34 | # s += label_to_string("PARAMETERS", self.parameters) 35 | # return s 36 | 37 | ############################################################################### 38 | 39 | 40 | class EquityModelHeston(EquityModel): 41 | def __init__(self, volatility, mean_reversion): 42 | self.parentType = EquityModel 43 | self.volatility = volatility 44 | self.mean_reversion = mean_reversion 45 | self.implementation = 0 46 | 47 | def __repr__(self): 48 | s = label_to_string("OBJECT TYPE", type(self).__name__) 49 | s += label_to_string("VOLATILITY", self.volatility) 50 | s += label_to_string("MEAN REVERSION", self.mean_reversion) 51 | s += label_to_string("IMPLEMENTATION", self.implementation) 52 | return s 53 | 54 | ############################################################################### 55 | -------------------------------------------------------------------------------- /financepy/products/fx/README.md: -------------------------------------------------------------------------------- 1 | # FX Derivatives 2 | ## Overview 3 | These modules price and produce the sensitivity measures needed to hedge a range of FX Options and other derivatives with an FX underlying. 4 | 5 | ## FX Forwards 6 | Calculate the price and breakeven forward FX Rate of an FX Forward contract. 7 | 8 | ## FX Vanilla Option 9 | 10 | ## FX Option 11 | This is a class from which other classes inherit and is used to perform simple 12 | perturbatory calculation of option Greeks. 13 | 14 | ## FX Barrier Options 15 | 16 | ## FX Basket Options 17 | 18 | ## FX Digital Options 19 | 20 | ## FX Fixed Lookback Option 21 | 22 | ## FX Float Lookback Option 23 | 24 | ## FX Rainbow Option 25 | 26 | ## FX Variance Swap 27 | 28 | -------------------------------------------------------------------------------- /financepy/products/fx/__init__.py: -------------------------------------------------------------------------------- 1 | from .fx_barrier_option import * 2 | from .fx_digital_option import * 3 | from .fx_double_digital_option import * 4 | from .fx_fixed_lookback_option import * 5 | from .fx_float_lookback_option import * 6 | from .fx_forward import * 7 | from .fx_mkt_conventions import * 8 | from .fx_option import * 9 | from .fx_rainbow_option import * 10 | from .fx_vanilla_option import * 11 | from .fx_variance_swap import * 12 | from .fx_one_touch_option import * 13 | -------------------------------------------------------------------------------- /financepy/products/inflation/__init__.py: -------------------------------------------------------------------------------- 1 | from .FinInflationBond import * 2 | -------------------------------------------------------------------------------- /financepy/products/rates/__init__.py: -------------------------------------------------------------------------------- 1 | from .callable_swap import * 2 | from .ibor_bermudan_swaption import * 3 | from .ibor_benchmarks_report import * 4 | from .ibor_cap_floor import * 5 | from .ibor_deposit import * 6 | from .ibor_fra import * 7 | from .ibor_future import * 8 | from .ibor_conventions import * 9 | from .ibor_swap import * 10 | from .ibor_swaption import * 11 | from .ois_basis_swap import * 12 | from .ois_curve import * 13 | from .ois import * 14 | from .ibor_single_curve import * 15 | from .ibor_single_curve_par_shocker import * 16 | from .ibor_single_curve_smoothing_calibrator import * 17 | from .dual_curve import * 18 | from .swap_fixed_leg import * 19 | from .swap_float_leg import * 20 | -------------------------------------------------------------------------------- /financepy/products/rates/ibor_conventions.py: -------------------------------------------------------------------------------- 1 | ############################################################################## 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################## 4 | 5 | ########################################################################## 6 | # THIS IS UNFINISHED 7 | ########################################################################## 8 | 9 | from ...utils.day_count import DayCountTypes 10 | from ...utils.calendar import CalendarTypes 11 | 12 | ########################################################################## 13 | 14 | 15 | class IborConventions: 16 | 17 | def __init__(self, currency_name: str, index_name: str = "LIBOR"): 18 | 19 | if currency_name == "USD" and index_name == "LIBOR": 20 | self.spot_lag = 2 21 | self.dc_type = DayCountTypes.THIRTY_E_360_ISDA 22 | self.cal_type = CalendarTypes.TARGET 23 | elif currency_name == "EUR" and index_name == "EURIBOR": 24 | self.spot_lag = 2 25 | self.dc_type = DayCountTypes.THIRTY_E_360_ISDA 26 | self.cal_type = CalendarTypes.TARGET 27 | else: 28 | pass 29 | 30 | 31 | ############################################################################### 32 | -------------------------------------------------------------------------------- /financepy/products/rates/swaps/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/domokane/FinancePy/7ca2a16354076cad672c03add5c3fb444159223b/financepy/products/rates/swaps/__init__.py -------------------------------------------------------------------------------- /financepy/utils/__init__.py: -------------------------------------------------------------------------------- 1 | from .calendar import * 2 | from .currency import * 3 | from .date import * 4 | from .day_count import * 5 | from .frequency import * 6 | from .global_vars import * 7 | from .global_types import * 8 | from .helpers import * 9 | from .math import * 10 | from .stats import * 11 | from .schedule import * 12 | from .error import * 13 | from .currency import * 14 | from .amount import * 15 | from .distribution import * 16 | -------------------------------------------------------------------------------- /financepy/utils/amount.py: -------------------------------------------------------------------------------- 1 | ############################################################################## 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################## 4 | 5 | 6 | from .helpers import check_argument_types 7 | from .currency import CurrencyTypes 8 | from .math import ONE_MILLION 9 | 10 | ############################################################################### 11 | 12 | 13 | class Amount: 14 | """ An Amount is a holder for an amount in a specific currency. """ 15 | 16 | def __init__(self, 17 | notional: float = ONE_MILLION, 18 | currency_type: CurrencyTypes = CurrencyTypes.NONE): 19 | """ Create Amount object. """ 20 | 21 | check_argument_types(self.__init__, locals()) 22 | 23 | self.notional = notional 24 | self.currency_type = currency_type 25 | 26 | def __repr__(self): 27 | """ Print out amount object. """ 28 | 29 | s = "" 30 | if self.currency_type != CurrencyTypes.NONE: 31 | s += self.currency_type.name 32 | s += " " 33 | 34 | s += '{:,.2f}'.format(self.notional) 35 | 36 | return s 37 | 38 | def amount(self): 39 | return self.notional 40 | 41 | def _print(self): 42 | """ Print out the details of the schedule and the actual dates. This 43 | can be used for providing transparency on schedule calculations. """ 44 | print(self) 45 | 46 | ############################################################################### 47 | -------------------------------------------------------------------------------- /financepy/utils/currency.py: -------------------------------------------------------------------------------- 1 | ############################################################################## 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################## 4 | 5 | # This is an exhaustive list of all option types 6 | 7 | from enum import Enum 8 | 9 | ############################################################################### 10 | 11 | 12 | class CurrencyTypes(Enum): 13 | USD = 1 14 | EUR = 2 15 | GBP = 3 16 | CHF = 4 17 | CAD = 5 18 | AUD = 6 19 | NZD = 7 20 | DKK = 8 21 | SEK = 9 22 | HKD = 10 23 | NONE = 11 24 | 25 | ############################################################################### 26 | -------------------------------------------------------------------------------- /financepy/utils/distribution.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | 6 | import numpy as np 7 | from .error import FinError 8 | 9 | 10 | class FinDistribution(): 11 | """ Container class for a probability density function. """ 12 | 13 | def __init__(self, x, y): 14 | """ Initialise FinDistribution with x values and associated vector of 15 | density times dx values. """ 16 | 17 | if len(x) != len(y): 18 | raise FinError("Length of x and y not the same") 19 | 20 | self._x = np.array(x) 21 | self._densitydx = np.array(y) 22 | 23 | def sum(self): 24 | """ This should equal 1.0 for the entire distribution. """ 25 | return np.sum(self._densitydx) 26 | 27 | ############################################################################### 28 | -------------------------------------------------------------------------------- /financepy/utils/error.py: -------------------------------------------------------------------------------- 1 | ############################################################################## 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################## 4 | 5 | ############################################################################### 6 | # Suppress error traceback messages in Jupyter Notebook 7 | ############################################################################### 8 | 9 | import traceback 10 | import sys 11 | 12 | # iPython dependency is only loaded if required. 13 | 14 | IPYTHON = None 15 | 16 | try: 17 | from IPython import get_ipython 18 | 19 | ipython = get_ipython() 20 | except Exception: 21 | pass 22 | 23 | 24 | def _hide_traceback( 25 | exc_tuple=None, 26 | filename=None, 27 | tb_offset=None, 28 | exception_only=False, 29 | running_compiled_code=False, 30 | ): 31 | """Avoid long error message""" 32 | etype, value, _ = sys.exc_info() 33 | ip = IPYTHON.InteractiveTB 34 | 35 | if ipython is not None: 36 | msg = IPYTHON._showtraceback( 37 | etype, value, ip.get_exception_only(etype, value) 38 | ) 39 | else: 40 | msg = None 41 | return msg 42 | 43 | 44 | ############################################################################## 45 | 46 | 47 | def func_name(): 48 | """Get error message""" 49 | return traceback.extract_stack(None, 2)[0][2] 50 | 51 | 52 | def suppress_traceback(): 53 | # print(sys.tracebacklimit) 54 | # print(ipython.showtrackeback) 55 | """Avoid long error message""" 56 | 57 | sys.tracebacklimit = 0 58 | ipython.showtraceback = _hide_traceback 59 | 60 | 61 | ############################################################################### 62 | 63 | 64 | class FinError(Exception): 65 | """Simple error class specific to FinPy. Need to decide how to handle 66 | FinancePy errors. Work in progress.""" 67 | 68 | def __init__(self, message: str): 69 | """Create FinError object by passing a message string.""" 70 | self._message = message 71 | 72 | def _print(self): 73 | print("FinError:", self._message) 74 | 75 | 76 | ############################################################################### 77 | -------------------------------------------------------------------------------- /financepy/utils/frequency.py: -------------------------------------------------------------------------------- 1 | ############################################################################## 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################## 4 | 5 | from ..utils.error import FinError 6 | 7 | ############################################################################### 8 | 9 | from enum import Enum 10 | 11 | 12 | class FrequencyTypes(Enum): 13 | ZERO = -1 14 | SIMPLE = 0 15 | ANNUAL = 1 16 | SEMI_ANNUAL = 2 17 | TRI_ANNUAL = 3 18 | QUARTERLY = 4 19 | MONTHLY = 12 20 | CONTINUOUS = 99 21 | 22 | ############################################################################### 23 | 24 | 25 | def annual_frequency(freq_type: FrequencyTypes): 26 | """ This is a function that takes in a Frequency Type and returns a 27 | float value for the number of times a year a payment occurs.""" 28 | if isinstance(freq_type, FrequencyTypes) is False: 29 | print("FinFrequency:", freq_type) 30 | raise FinError("Unknown frequency type") 31 | 32 | if freq_type == FrequencyTypes.CONTINUOUS: 33 | return -1 34 | elif freq_type == FrequencyTypes.ZERO: 35 | # This means that there is no coupon and I use 1 to avoid div by zero 36 | return 1.0 37 | elif freq_type == FrequencyTypes.ANNUAL: 38 | return 1.0 39 | elif freq_type == FrequencyTypes.SEMI_ANNUAL: 40 | return 2.0 41 | elif freq_type == FrequencyTypes.TRI_ANNUAL: 42 | return 3.0 43 | elif freq_type == FrequencyTypes.QUARTERLY: 44 | return 4.0 45 | elif freq_type == FrequencyTypes.MONTHLY: 46 | return 12.0 47 | 48 | ############################################################################### 49 | -------------------------------------------------------------------------------- /financepy/utils/global_vars.py: -------------------------------------------------------------------------------- 1 | ############################################################################## 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################## 4 | 5 | 6 | ############################################################################### 7 | 8 | g_days_in_year = 365.0 # .242 9 | g_small = 1e-12 10 | g_notebook_mode = False 11 | g_basis_point = 1e-4 12 | g_percent = 1e-2 13 | 14 | ############################################################################### 15 | -------------------------------------------------------------------------------- /financepy/utils/singleton.py: -------------------------------------------------------------------------------- 1 | from __future__ import print_function, division 2 | 3 | __author__ = "saeedamen" # Saeed Amen / saeed@cuemacro.com 4 | 5 | 6 | class Singleton(type): 7 | """Singleton type which is used to ensure there is only one instance 8 | across the whole project.""" 9 | 10 | _instances = {} 11 | 12 | def __call__(cls, *args, **kwargs): 13 | if cls not in cls._instances.keys(): 14 | cls._instances[cls] = super(Singleton, cls).__call__( 15 | *args, **kwargs 16 | ) 17 | return cls._instances[cls] 18 | -------------------------------------------------------------------------------- /golden_tests/README.md: -------------------------------------------------------------------------------- 1 | # Test Suite 2 | 3 | This folder contains the logic for performing comparison testing of code to ensure that code does not inadvertently get broken. 4 | 5 | The code tests here can be very broad in type. 6 | 7 | The test is based on the prior creation of a Golden version of the file output which is stored in the Golden folder. There is a file for each test file. This is considered to be correct and any output that deviates from this is deemed to be incorrect. Creation of the Golden files is done by setting the value of the global flag as follows: 8 | 9 | globalTestCaseMode = FinTestCaseMode.SAVE_TEST_CASES 10 | 11 | This can be found under FinTestCase.py 12 | 13 | When you wish to run the tests to check if anything has changed, you need to set the global flag to 14 | 15 | globalTestCaseMode = FinTestCaseMode.ANALYSE_TEST_CASES 16 | 17 | ## RunAllTests.py 18 | 19 | This file executes all of the test files which each report on any errors found. 20 | 21 | 22 | ## Output 23 | 24 | Any change is registered as an error. No matter what the precision. -------------------------------------------------------------------------------- /golden_tests/TestFinAmount.py: -------------------------------------------------------------------------------- 1 | ############################################################################## 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################## 4 | 5 | import sys 6 | sys.path.append("..") 7 | 8 | from financepy.utils.currency import CurrencyTypes 9 | from financepy.utils.amount import Amount 10 | from FinTestCases import FinTestCases, globalTestCaseMode 11 | 12 | test_cases = FinTestCases(__file__, globalTestCaseMode) 13 | 14 | ########################################################################## 15 | 16 | 17 | def test_amount(): 18 | 19 | test_cases.header("LABEL", "AMOUNT") 20 | x = Amount(101000.232) 21 | 22 | test_cases.print("Amount", x) 23 | 24 | x = Amount(101000.232, CurrencyTypes.CAD) 25 | 26 | test_cases.print("Amount", x) 27 | 28 | ############################################################################### 29 | 30 | 31 | test_amount() 32 | 33 | test_cases.compareTestCases() 34 | -------------------------------------------------------------------------------- /golden_tests/TestFinBondMortgage.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | import sys 6 | 7 | sys.path.append("..") 8 | 9 | from FinTestCases import FinTestCases, globalTestCaseMode 10 | from financepy.products.bonds.bond_mortgage import BondMortgageTypes 11 | from financepy.products.bonds.bond_mortgage import BondMortgage 12 | from financepy.utils.date import Date 13 | 14 | 15 | test_cases = FinTestCases(__file__, globalTestCaseMode) 16 | 17 | 18 | ############################################################################### 19 | 20 | 21 | def test_BondMortgage(): 22 | 23 | principal = 130000 24 | start_dt = Date(23, 2, 2018) 25 | end_dt = start_dt.add_tenor("10Y") 26 | mortgage = BondMortgage(start_dt, end_dt, principal) 27 | 28 | rate = 0.035 29 | mortgage.generate_flows(rate, BondMortgageTypes.REPAYMENT) 30 | 31 | num_flows = len(mortgage.schedule.adjusted_dts) 32 | 33 | test_cases.header( 34 | "PAYMENT DATE", "INTEREST", "PRINCIPAL", "OUTSTANDING", "TOTAL" 35 | ) 36 | 37 | for i in range(0, num_flows): 38 | test_cases.print( 39 | mortgage.schedule.adjusted_dts[i], 40 | mortgage.interest_flows[i], 41 | mortgage.principal_flows[i], 42 | mortgage.principal_remaining[i], 43 | mortgage.total_flows[i], 44 | ) 45 | 46 | mortgage.generate_flows(rate, BondMortgageTypes.INTEREST_ONLY) 47 | 48 | test_cases.header( 49 | "PAYMENT DATE", "INTEREST", "PRINCIPAL", "OUTSTANDING", "TOTAL" 50 | ) 51 | 52 | for i in range(0, num_flows): 53 | test_cases.print( 54 | mortgage.schedule.adjusted_dts[i], 55 | mortgage.interest_flows[i], 56 | mortgage.principal_flows[i], 57 | mortgage.principal_remaining[i], 58 | mortgage.total_flows[i], 59 | ) 60 | 61 | 62 | ############################################################################### 63 | 64 | 65 | test_BondMortgage() 66 | test_cases.compareTestCases() 67 | -------------------------------------------------------------------------------- /golden_tests/TestFinCalendar.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | import sys 6 | sys.path.append("..") 7 | 8 | from FinTestCases import FinTestCases, globalTestCaseMode 9 | from financepy.utils.calendar import Calendar, CalendarTypes 10 | from financepy.utils.date import set_date_format, DateFormatTypes 11 | from financepy.utils.date import Date 12 | 13 | 14 | test_cases = FinTestCases(__file__, globalTestCaseMode) 15 | 16 | ############################################################################### 17 | 18 | 19 | def test_Calendar(): 20 | 21 | set_date_format(DateFormatTypes.US_LONGEST) 22 | end_dt = Date(31, 12, 2030) 23 | 24 | for cal_type in CalendarTypes: 25 | 26 | test_cases.banner("================================") 27 | test_cases.banner("================================") 28 | 29 | test_cases.header("CALENDAR", "HOLIDAY") 30 | test_cases.print("STARTING", cal_type) 31 | 32 | cal = Calendar(cal_type) 33 | next_dt = Date(31, 12, 2020) 34 | 35 | while next_dt < end_dt: 36 | next_dt = next_dt.add_days(1) 37 | 38 | if next_dt.d == 1 and next_dt.m == 1: 39 | test_cases.banner("================================") 40 | # print("=========================") 41 | 42 | is_holidayDay = cal.is_holiday(next_dt) 43 | if is_holidayDay is True: 44 | test_cases.print(cal, next_dt) 45 | # print(cal, next_dt) 46 | 47 | set_date_format(DateFormatTypes.US_LONG) 48 | 49 | ############################################################################### 50 | 51 | 52 | test_Calendar() 53 | test_cases.compareTestCases() 54 | -------------------------------------------------------------------------------- /golden_tests/TestFinDayCount.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | import sys 6 | sys.path.append("..") 7 | 8 | from FinTestCases import FinTestCases, globalTestCaseMode 9 | from financepy.utils.frequency import FrequencyTypes 10 | from financepy.utils.day_count import DayCount, DayCountTypes 11 | from financepy.utils.date import Date 12 | 13 | test_cases = FinTestCases(__file__, globalTestCaseMode) 14 | 15 | ############################################################################## 16 | 17 | 18 | def test_FinDayCount(): 19 | 20 | test_cases.header("DAY_COUNT_METHOD", "START", "END", "ALPHA") 21 | 22 | finFreq = FrequencyTypes.ANNUAL 23 | 24 | for day_count_method in DayCountTypes: 25 | 26 | start_dt = Date(1, 1, 2019) 27 | next_dt = start_dt 28 | num_days = 20 29 | day_count = DayCount(day_count_method) 30 | 31 | for _ in range(0, num_days): 32 | next_dt = next_dt.add_days(7) 33 | dcf = day_count.year_frac( 34 | start_dt, next_dt, next_dt, finFreq) 35 | 36 | test_cases.print( 37 | str(day_count_method), 38 | str(start_dt), 39 | str(next_dt), 40 | dcf[0]) 41 | 42 | 43 | test_FinDayCount() 44 | test_cases.compareTestCases() 45 | -------------------------------------------------------------------------------- /golden_tests/TestFinDiscountCurveFlat.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | from FinTestCases import FinTestCases, globalTestCaseMode 6 | from financepy.utils.frequency import FrequencyTypes 7 | from financepy.utils.date import Date 8 | from financepy.market.curves.discount_curve_flat import DiscountCurveFlat 9 | import sys 10 | sys.path.append("..") 11 | 12 | 13 | test_cases = FinTestCases(__file__, globalTestCaseMode) 14 | 15 | ############################################################################## 16 | 17 | 18 | def test_FinFlatCurve(): 19 | 20 | curve_dt = Date(1, 1, 2019) 21 | months = range(1, 60, 3) 22 | dates = curve_dt.add_months(months) 23 | test_cases.header("COMPOUNDING", "DFS") 24 | compounding = FrequencyTypes.CONTINUOUS 25 | 26 | flat_curve = DiscountCurveFlat(curve_dt, 0.05, compounding) 27 | dfs = flat_curve.df(dates) 28 | test_cases.print(compounding, dfs) 29 | 30 | compounding = FrequencyTypes.ANNUAL 31 | flat_curve = DiscountCurveFlat(curve_dt, 0.05, compounding) 32 | dfs = flat_curve.df(dates) 33 | test_cases.print(compounding, dfs) 34 | 35 | compounding = FrequencyTypes.SEMI_ANNUAL 36 | flat_curve = DiscountCurveFlat(curve_dt, 0.05, compounding) 37 | dfs = flat_curve.df(dates) 38 | test_cases.print(compounding, dfs) 39 | 40 | compounding = FrequencyTypes.QUARTERLY 41 | flat_curve = DiscountCurveFlat(curve_dt, 0.05, compounding) 42 | dfs = flat_curve.df(dates) 43 | test_cases.print(compounding, dfs) 44 | 45 | compounding = FrequencyTypes.MONTHLY 46 | flat_curve = DiscountCurveFlat(curve_dt, 0.05, compounding) 47 | dfs = flat_curve.df(dates) 48 | test_cases.print(compounding, dfs) 49 | 50 | ############################################################################### 51 | 52 | 53 | test_FinFlatCurve() 54 | test_cases.compareTestCases() 55 | -------------------------------------------------------------------------------- /golden_tests/TestFinDiscountCurvePolynomial.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | from FinTestCases import FinTestCases, globalTestCaseMode 6 | from financepy.utils.date import Date 7 | from financepy.market.curves.discount_curve_poly import DiscountCurvePoly 8 | import numpy as np 9 | 10 | import sys 11 | sys.path.append("..") 12 | 13 | 14 | test_cases = FinTestCases(__file__, globalTestCaseMode) 15 | 16 | ############################################################################## 17 | # TODO 18 | # Inherit from FinDiscountCurve and add df method 19 | # Put in a convention for the rate 20 | # Use Frequency object 21 | ############################################################################## 22 | 23 | PLOT_GRAPHS = False 24 | 25 | 26 | def test_FinDiscountCurvePolynomial(): 27 | 28 | times = np.linspace(0.00, 10.0, 21) 29 | curve_dt = Date(2, 2, 2019) 30 | dates = curve_dt.add_years(times) 31 | coeffs = [0.0004, -0.0001, 0.00000010] 32 | curve1 = DiscountCurvePoly(curve_dt, coeffs) 33 | zeros = curve1.zero_rate(dates) 34 | fwds = curve1.fwd(dates) 35 | 36 | if PLOT_GRAPHS: 37 | import matplotlib.pyplot as plt 38 | plt.figure(figsize=(6, 4)) 39 | plt.plot(times, zeros, label="Zeros") 40 | plt.plot(times, fwds, label="Forwards") 41 | plt.xlabel('Time (years)') 42 | plt.ylabel('Zero Rate') 43 | plt.legend(loc='best') 44 | 45 | 46 | test_FinDiscountCurvePolynomial() 47 | test_cases.compareTestCases() 48 | -------------------------------------------------------------------------------- /golden_tests/TestFinEquityCliquetOption.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | import sys 6 | sys.path.append("..") 7 | 8 | from financepy.products.equity.equity_cliquet_option import EquityCliquetOption 9 | from financepy.models.black_scholes import BlackScholes 10 | from financepy.market.curves.discount_curve_flat import DiscountCurveFlat 11 | from financepy.utils.frequency import FrequencyTypes 12 | from financepy.utils.date import Date 13 | from financepy.utils.global_types import OptionTypes 14 | from FinTestCases import FinTestCases, globalTestCaseMode 15 | 16 | test_cases = FinTestCases(__file__, globalTestCaseMode) 17 | 18 | ############################################################################### 19 | 20 | 21 | def test_EquityCliquetOption(): 22 | 23 | start_dt = Date(1, 1, 2014) 24 | final_expiry_dt = Date(1, 1, 2017) 25 | freq_type = FrequencyTypes.QUARTERLY 26 | option_type = OptionTypes.EUROPEAN_CALL 27 | 28 | cliquetOption = EquityCliquetOption(start_dt, 29 | final_expiry_dt, 30 | option_type, 31 | freq_type) 32 | 33 | value_dt = Date(1, 1, 2015) 34 | stock_price = 100.0 35 | volatility = 0.20 36 | interest_rate = 0.05 37 | dividend_yield = 0.02 38 | model = BlackScholes(volatility) 39 | discount_curve = DiscountCurveFlat(value_dt, interest_rate) 40 | dividend_curve = DiscountCurveFlat(value_dt, dividend_yield) 41 | 42 | v = cliquetOption.value(value_dt, 43 | stock_price, 44 | discount_curve, 45 | dividend_curve, 46 | model) 47 | 48 | test_cases.header("LABEL", "VALUE") 49 | test_cases.print("FINANCEPY", v) 50 | 51 | ############################################################################### 52 | 53 | 54 | test_EquityCliquetOption() 55 | test_cases.compareTestCases() 56 | -------------------------------------------------------------------------------- /golden_tests/TestFinEquityForward.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | import sys 6 | 7 | sys.path.append("..") 8 | 9 | from financepy.products.equity.equity_forward import EquityForward 10 | from financepy.utils.date import Date 11 | from financepy.utils.global_types import FinLongShort 12 | from financepy.market.curves.discount_curve_flat import DiscountCurveFlat 13 | from FinTestCases import FinTestCases, globalTestCaseMode 14 | 15 | test_cases = FinTestCases(__file__, globalTestCaseMode) 16 | 17 | ########################################################################## 18 | 19 | 20 | def test_EquityForward(): 21 | 22 | value_dt = Date(13, 2, 2018) 23 | expiry_dt = value_dt.add_months(12) 24 | 25 | stock_price = 130.0 26 | forward_price = 125.0 # Locked 27 | discount_rate = 0.05 28 | dividend_rate = 0.02 29 | 30 | ########################################################################### 31 | 32 | expiry_dt = value_dt.add_months(12) 33 | notional = 100.0 34 | 35 | discount_curve = DiscountCurveFlat(value_dt, discount_rate) 36 | dividend_curve = DiscountCurveFlat(value_dt, dividend_rate) 37 | 38 | equityForward = EquityForward( 39 | expiry_dt, forward_price, notional, FinLongShort.LONG 40 | ) 41 | 42 | test_cases.header("SPOT FX", "FX FWD", "VALUE_BS") 43 | 44 | fwd_price = equityForward.forward( 45 | value_dt, stock_price, discount_curve, dividend_curve 46 | ) 47 | 48 | fwd_value = equityForward.value( 49 | value_dt, stock_price, discount_curve, dividend_curve 50 | ) 51 | 52 | # print(stock_price, fwd_price, fwd_value) 53 | test_cases.print(stock_price, fwd_price, fwd_value) 54 | 55 | 56 | ############################################################################### 57 | 58 | 59 | test_EquityForward() 60 | test_cases.compareTestCases() 61 | -------------------------------------------------------------------------------- /golden_tests/TestFinFXDoubleDigitalOption.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | import time 6 | import sys 7 | sys.path.append("..") 8 | 9 | import numpy as np 10 | 11 | from financepy.products.fx.fx_double_digital_option import FXDoubleDigitalOption 12 | from financepy.models.black_scholes import BlackScholes 13 | from financepy.market.curves.discount_curve_flat import DiscountCurveFlat 14 | from financepy.utils.date import Date 15 | from FinTestCases import FinTestCases, globalTestCaseMode 16 | 17 | 18 | test_cases = FinTestCases(__file__, globalTestCaseMode) 19 | 20 | ########################################################################## 21 | 22 | 23 | def test_FinFXDoubleDigitalOption(): 24 | 25 | value_dt = Date(10, 4, 2020) 26 | expiry_dt = Date(18, 9, 2020) 27 | 28 | for_name = "EUR" 29 | dom_name = "USD" 30 | for_cc_rate = 0.03460 # EUR 31 | dom_cc_rate = 0.02940 # USD 32 | 33 | currency_pair = for_name + dom_name # Always FORDOM 34 | spot_fx_rate = 1.20 35 | 36 | domestic_curve = DiscountCurveFlat(value_dt, dom_cc_rate) 37 | foreign_curve = DiscountCurveFlat(value_dt, for_cc_rate) 38 | 39 | volatility = 0.20 40 | 41 | notional = 1.0 42 | 43 | upper_strike = 1.4 44 | lower_strike = 1.1 45 | 46 | model = BlackScholes(volatility) 47 | 48 | double_digital_option = FXDoubleDigitalOption( 49 | expiry_dt, 50 | upper_strike, 51 | lower_strike, 52 | currency_pair, 53 | notional, 54 | "USD", 55 | ) 56 | 57 | spot_fx_rate = np.linspace(0.01, 2.0, 10) 58 | 59 | value = double_digital_option.value( 60 | value_dt, 61 | spot_fx_rate, 62 | domestic_curve, 63 | foreign_curve, 64 | model) 65 | 66 | ############################################################################### 67 | 68 | 69 | test_FinFXDoubleDigitalOption() 70 | test_cases.compareTestCases() 71 | -------------------------------------------------------------------------------- /golden_tests/TestFinGBMProcess.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | import time 6 | import numpy as np 7 | from os.path import dirname, join 8 | 9 | import sys 10 | 11 | sys.path.append("..") 12 | 13 | from FinTestCases import FinTestCases, globalTestCaseMode 14 | from financepy.utils.global_types import SwapTypes 15 | from financepy.models.gbm_process_simulator import get_assets_paths_times 16 | from financepy.utils.math import corr_matrix_generator 17 | 18 | test_cases = FinTestCases(__file__, globalTestCaseMode) 19 | 20 | 21 | def testFinGBMProcess(): 22 | 23 | num_assets = 3 24 | num_paths = 6 25 | num_time_steps = 1 26 | t = 1.0 27 | mus = 0.03 * np.ones(num_assets) 28 | stock_prices = 100.0 * np.ones(num_assets) 29 | volatilities = 0.2 * np.ones(num_assets) 30 | rho = 0.8 31 | corr_matrix = corr_matrix_generator(rho, num_assets) 32 | seed = 1912 33 | 34 | times, paths = get_assets_paths_times( 35 | num_assets, 36 | num_paths, 37 | num_time_steps, 38 | t, 39 | mus, 40 | stock_prices, 41 | volatilities, 42 | corr_matrix, 43 | seed, 44 | ) 45 | 46 | 47 | ############################################################################### 48 | 49 | 50 | testFinGBMProcess() 51 | test_cases.compareTestCases() 52 | -------------------------------------------------------------------------------- /golden_tests/TestFinIborCapVolCurve.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | import numpy as np 6 | 7 | import sys 8 | 9 | sys.path.append("..") 10 | 11 | from financepy.utils.day_count import DayCountTypes 12 | from financepy.utils.date import Date 13 | from financepy.market.volatility.ibor_cap_vol_curve import IborCapVolCurve 14 | from FinTestCases import FinTestCases, globalTestCaseMode 15 | 16 | test_cases = FinTestCases(__file__, globalTestCaseMode) 17 | 18 | ########################################################################## 19 | 20 | 21 | def test_FinCapVolCurve(): 22 | 23 | # Reproduces example in Table 32.1 of Hull Book 24 | value_dt = Date(1, 1, 2020) 25 | 26 | capVolDates = [] 27 | capletVolTenor = "1Y" 28 | num_periods = 10 29 | capletDt = value_dt 30 | 31 | capVolDates.append(value_dt) 32 | 33 | for i in range(0, num_periods): 34 | capletDt = capletDt.add_tenor(capletVolTenor) 35 | capVolDates.append(capletDt) 36 | 37 | capVolatilities = [ 38 | 0.0, 39 | 15.50, 40 | 18.25, 41 | 17.91, 42 | 17.74, 43 | 17.27, 44 | 16.79, 45 | 16.30, 46 | 16.01, 47 | 15.76, 48 | 15.54, 49 | ] 50 | capVolatilities = np.array(capVolatilities) / 100.0 51 | 52 | day_count_type = DayCountTypes.ACT_ACT_ISDA 53 | vol_curve = IborCapVolCurve( 54 | value_dt, capVolDates, capVolatilities, day_count_type 55 | ) 56 | 57 | test_cases.header("DATE", "CAPVOL", "CAPLETVOL") 58 | for dt in capVolDates: 59 | capFloorVol = vol_curve.cap_vol(dt) 60 | capFloorLetVol = vol_curve.caplet_vol(dt) 61 | test_cases.print( 62 | "%s" % dt, 63 | "%7.3f" % (capFloorVol * 100.0), 64 | "%7.2f" % (capFloorLetVol * 100.0), 65 | ) 66 | 67 | 68 | ########################################################################## 69 | 70 | 71 | test_FinCapVolCurve() 72 | test_cases.compareTestCases() 73 | -------------------------------------------------------------------------------- /golden_tests/TestFinIborFuture.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | import sys 6 | sys.path.append("..") 7 | 8 | from financepy.products.rates.ibor_future import IborFuture 9 | from financepy.utils.date import Date, set_date_format, DateFormatTypes 10 | from FinTestCases import FinTestCases, globalTestCaseMode 11 | 12 | test_cases = FinTestCases(__file__, globalTestCaseMode) 13 | 14 | set_date_format(DateFormatTypes.UK_LONG) 15 | 16 | ############################################################################### 17 | 18 | 19 | def test_FinIborFuture(): 20 | 21 | todayDate = Date(5, 5, 2020) 22 | 23 | test_cases.header("VALUES") 24 | 25 | for i in range(1, 12): 26 | fut = IborFuture(todayDate, i, "3M") 27 | test_cases.print(fut) 28 | 29 | fra = fut.to_fra(0.020, 0.0) 30 | test_cases.print(fra) 31 | 32 | ############################################################################### 33 | 34 | 35 | test_FinIborFuture() 36 | test_cases.compareTestCases() 37 | -------------------------------------------------------------------------------- /golden_tests/TestFinInflationIndexCurve.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | import sys 6 | sys.path.append("..") 7 | 8 | from financepy.utils.date import Date 9 | from financepy.products.inflation.FinInflationIndexCurve import FinInflationIndexCurve 10 | from FinTestCases import FinTestCases, globalTestCaseMode 11 | 12 | test_cases = FinTestCases(__file__, globalTestCaseMode) 13 | 14 | ############################################################################## 15 | 16 | 17 | def test_FinInflationIndexCurve(): 18 | 19 | # Create a curve from times and discount factors 20 | indexDates = [Date(15, 1, 2008), Date(1, 4, 2008), Date(1, 5, 2008)] 21 | indexValues = [209.49645, 214.823, 216.632] 22 | lag = 3 # months 23 | 24 | curve = FinInflationIndexCurve(indexDates, indexValues, lag) 25 | 26 | refDate = Date(22, 7, 2008) 27 | 28 | test_cases.header("LABEL", "VALUE") 29 | 30 | value = curve.index_value(refDate) 31 | value = curve.index_value(refDate) 32 | value = curve.index_value(refDate) 33 | value = curve.index_value(refDate) 34 | 35 | test_cases.print(refDate, value) 36 | 37 | index_ratio = curve.index_ratio(refDate) 38 | test_cases.print(refDate, index_ratio) 39 | 40 | # print(curve) 41 | 42 | ############################################################################### 43 | 44 | 45 | test_FinInflationIndexCurve() 46 | test_cases.compareTestCases() 47 | -------------------------------------------------------------------------------- /golden_tests/TestFinInterpolatedForwards.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | import sys 6 | sys.path.append("..") 7 | 8 | import numpy as np 9 | from financepy.utils.date import Date 10 | from financepy.market.curves.interpolator import InterpTypes 11 | from financepy.market.curves.discount_curve import DiscountCurve 12 | from FinTestCases import FinTestCases, globalTestCaseMode 13 | 14 | 15 | test_cases = FinTestCases(__file__, globalTestCaseMode) 16 | 17 | PLOT_GRAPHS = False 18 | 19 | ############################################################################### 20 | 21 | 22 | def test_FinInterpolatedForwards(): 23 | 24 | import matplotlib.pyplot as plt 25 | 26 | tValues = np.array([0.0, 3.0, 5.0, 10.0]) 27 | rValues = np.array([0.04, 0.07, 0.08, 0.09]) 28 | df_values = np.exp(-tValues*rValues) 29 | tInterpValues = np.linspace(0.0, 12.0, 49) 30 | 31 | curve_dt = Date(1, 1, 2019) 32 | 33 | tDates = curve_dt.add_years(tValues) 34 | tInterpDates = curve_dt.add_years(tInterpValues) 35 | 36 | for interp_type in InterpTypes: 37 | 38 | discount_curve = DiscountCurve( 39 | curve_dt, tDates, df_values, interp_type) 40 | dfInterpValues = discount_curve.df(tInterpDates) 41 | fwdInterpValues = discount_curve.fwd(tInterpDates) 42 | zeroInterpValues = discount_curve.zero_rate(tInterpDates) 43 | 44 | if PLOT_GRAPHS: 45 | plt.figure(figsize=(8, 6)) 46 | plt.plot(tValues, df_values, 'o', color='g', label="DFS:") 47 | plt.plot(tInterpValues, dfInterpValues, color='r', 48 | label="DF:" + str(interp_type)) 49 | plt.legend() 50 | plt.figure(figsize=(8, 6)) 51 | plt.plot(tInterpValues, fwdInterpValues, color='r', 52 | label="FWD:" + str(interp_type)) 53 | plt.plot(tInterpValues, zeroInterpValues, color='b', 54 | label="ZERO:" + str(interp_type)) 55 | plt.plot(tValues, rValues, 'o', color='g', label="ZERO RATES") 56 | plt.legend() 57 | 58 | ############################################################################### 59 | 60 | 61 | test_FinInterpolatedForwards() 62 | test_cases.compareTestCases() 63 | -------------------------------------------------------------------------------- /golden_tests/TestFinMathAccruedInterp.py: -------------------------------------------------------------------------------- 1 | ############################################################################## 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################## 4 | 5 | import sys 6 | sys.path.append("..") 7 | 8 | import matplotlib.pyplot as plt 9 | import numpy as np 10 | from financepy.utils.math import accrued_interpolator 11 | from FinTestCases import FinTestCases, globalTestCaseMode 12 | 13 | 14 | test_cases = FinTestCases(__file__, globalTestCaseMode) 15 | 16 | pltGraph = False 17 | 18 | ########################################################################## 19 | 20 | 21 | def test_FinMathAccdInterpolator(): 22 | 23 | cpn_times = [0.0, 4.000087613144162, 24 | 4.495649459810208, 5.002162949496498] 25 | cpn_flows = [0.0, 0.0, 0.03461111111111111, 0.035194444444444445] 26 | 27 | tree_times = [0., 0.12498563, 0.24997125, 0.37495688, 0.4999425, 0.62492813, 28 | 0.74991376, 0.87489938, 0.99988501, 1.12487063, 1.24985626, 1.37484189, 29 | 1.49982751, 1.62481314, 1.74979876, 1.87478439, 1.99977002, 2.12475564, 30 | 2.24974127, 2.37472689, 2.49971252, 2.62469815, 2.74968377, 2.8746694, 31 | 2.99965502, 3.12464065, 3.24962628, 3.3746119, 3.49959753, 3.62458315, 32 | 3.74956878, 3.87455441, 3.99954003, 4.12452566, 4.24951128, 4.37449691, 33 | 4.49948253, 4.62446816, 4.74945379, 4.87443941, 4.99942504, 5.12441066] 34 | 35 | cpn_times = np.array(cpn_times) 36 | cpn_flows = np.array(cpn_flows) 37 | 38 | values = [] 39 | 40 | for t in tree_times: 41 | v = accrued_interpolator(t, cpn_times, cpn_flows) 42 | values.append(v) 43 | 44 | test_cases.header("VALUE") 45 | test_cases.print(values) 46 | 47 | if pltGraph: 48 | plt.plot(tree_times, values) 49 | 50 | ########################################################################## 51 | 52 | 53 | test_FinMathAccdInterpolator() 54 | test_cases.compareTestCases() 55 | -------------------------------------------------------------------------------- /golden_tests/TestFinPieceCurve.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | from FinTestCases import FinTestCases, globalTestCaseMode 6 | import sys 7 | sys.path.append("..") 8 | 9 | # import numpy as np 10 | 11 | 12 | test_cases = FinTestCases(__file__, globalTestCaseMode) 13 | 14 | ########################################################################## 15 | # 16 | # def test_FinPieceCurve(): 17 | # 18 | # times = np.linspace(0.0, 1.0, 5) 19 | # values = np.ones(5) * 0.05 20 | # 21 | # flat_curve = FinPieceCurve(times,values) 22 | # 23 | # dfs = flat_curve.df(times, 0) 24 | # test_cases.print(dfs) 25 | # dfs = flat_curve.df(times, 1) 26 | # test_cases.print(dfs) 27 | # dfs = flat_curve.df(times, 2) 28 | # test_cases.print(dfs) 29 | # dfs = flat_curve.df(times, -1) 30 | # test_cases.print(dfs) 31 | 32 | ########################################################################## 33 | 34 | 35 | # test_FinPieceCurve() 36 | test_cases.compareTestCases() 37 | -------------------------------------------------------------------------------- /golden_tests/TestFinSobol.py: -------------------------------------------------------------------------------- 1 | from numba import jit 2 | import time 3 | from financepy.models.sobol import get_uniform_sobol, get_gaussian_sobol 4 | from FinTestCases import FinTestCases, globalTestCaseMode 5 | import sys 6 | sys.path.append("..") 7 | 8 | 9 | test_cases = FinTestCases(__file__, globalTestCaseMode) 10 | 11 | ############################################################################### 12 | 13 | 14 | def test_FinSobol(): 15 | 16 | num_points = 1000 17 | dimensions = 3 18 | 19 | points = get_uniform_sobol(num_points, dimensions) 20 | 21 | for d in range(dimensions): 22 | av = 0.0 23 | var = 0.0 24 | 25 | for point in points[:, d]: 26 | av += point 27 | var += point ** 2 28 | 29 | av /= num_points 30 | var /= num_points 31 | 32 | avError = abs(av - (1/2)) 33 | varError = abs(var - (1/3)) 34 | assert(avError < 0.002) 35 | assert(varError < 0.002) 36 | 37 | numRepeats = 100 38 | numDimensions = 10 39 | 40 | test_cases.header("LABEL", "TIME") 41 | start = time.time() 42 | for _ in range(numRepeats): 43 | get_uniform_sobol(1000, numDimensions) 44 | end = time.time() 45 | test_cases.print("Average time taken", (end - start) / numRepeats) 46 | 47 | start = time.time() 48 | for _ in range(numRepeats): 49 | get_gaussian_sobol(1000, numDimensions) 50 | end = time.time() 51 | test_cases.print("Average time taken", (end - start) / numRepeats) 52 | 53 | 54 | ############################################################################### 55 | 56 | @jit(cache=True, nopython=True) 57 | def test_FinSobolCache(): 58 | return get_uniform_sobol(2, 2) 59 | 60 | ############################################################################### 61 | 62 | 63 | test_FinSobol() 64 | test_FinSobolCache() 65 | test_cases.compareTestCases() 66 | -------------------------------------------------------------------------------- /golden_tests/TestFinVasicekRateModel.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | import sys 6 | sys.path.append("..") 7 | import time 8 | 9 | import numpy as np 10 | from financepy.models.vasicek_mc import zero_price, zero_price_mc 11 | from FinTestCases import FinTestCases, globalTestCaseMode 12 | 13 | test_cases = FinTestCases(__file__, globalTestCaseMode) 14 | 15 | ############################################################################### 16 | 17 | 18 | def test_FinModelRatesVasicek(): 19 | 20 | r0 = 0.05 21 | a = 0.10 22 | b = 0.05 23 | sigma = 0.05 24 | t = 5.0 25 | 26 | p = zero_price(r0, a, b, sigma, t) 27 | 28 | num_paths = 1000 29 | dt = 0.02 30 | seed = 1968 31 | 32 | test_cases.header("TIME", "T", "P", "P_MC", "P_MC2") 33 | 34 | for t in np.linspace(0, 10, 21): 35 | start = time.time() 36 | p_MC = zero_price_mc(r0, a, b, sigma, t, dt, num_paths, seed) 37 | p_MC2 = zero_price_mc(r0, a, b, sigma, t, dt, 10 * num_paths, seed) 38 | p = zero_price(r0, a, b, sigma, t) 39 | end = time.time() 40 | elapsed = end - start 41 | test_cases.print(elapsed, t, p, p_MC, p_MC2) 42 | 43 | 44 | ############################################################################### 45 | 46 | 47 | test_FinModelRatesVasicek() 48 | test_cases.compareTestCases() 49 | -------------------------------------------------------------------------------- /golden_tests/TestFinVolatilityCurve.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | import numpy as np 6 | from financepy.market.volatility.equity_vol_curve import EquityVolCurve 7 | from financepy.utils.date import Date 8 | from FinTestCases import FinTestCases, globalTestCaseMode 9 | import sys 10 | 11 | sys.path.append("..") 12 | 13 | 14 | test_cases = FinTestCases(__file__, globalTestCaseMode) 15 | 16 | PLOT_GRAPHS = False 17 | 18 | ############################################################################### 19 | 20 | 21 | def test_FinVolatilityCurve(): 22 | 23 | value_dt = Date(20, 6, 2012) 24 | expiry_dt = Date(20, 12, 2012) 25 | strikes = np.linspace(70, 130, 7) 26 | vols = np.array([0.23, 0.24, 0.267, 0.29, 0.31, 0.33, 0.35]) 27 | polynomial = 5 28 | vol_curve = EquityVolCurve(value_dt, expiry_dt, strikes, vols, polynomial) 29 | 30 | interp_strikes = np.linspace(50, 150, 10) 31 | interp_vols = vol_curve.volatility(interp_strikes) 32 | 33 | if PLOT_GRAPHS: 34 | import matplotlib.pyplot as plt 35 | 36 | plt.plot(strikes, vols, "o", interp_strikes, interp_vols) 37 | plt.show() 38 | 39 | 40 | ############################################################################### 41 | 42 | 43 | test_FinVolatilityCurve() 44 | test_cases.compareTestCases() 45 | -------------------------------------------------------------------------------- /golden_tests/__init__.py: -------------------------------------------------------------------------------- 1 | from FinTestCases import FinTestCases, FinTestCaseMode 2 | -------------------------------------------------------------------------------- /golden_tests/compare/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/domokane/FinancePy/7ca2a16354076cad672c03add5c3fb444159223b/golden_tests/compare/.gitkeep -------------------------------------------------------------------------------- /golden_tests/data/DowJonesPricesFromYahoo.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/domokane/FinancePy/7ca2a16354076cad672c03add5c3fb444159223b/golden_tests/data/DowJonesPricesFromYahoo.pkl -------------------------------------------------------------------------------- /golden_tests/data/ff_assets.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/domokane/FinancePy/7ca2a16354076cad672c03add5c3fb444159223b/golden_tests/data/ff_assets.pkl -------------------------------------------------------------------------------- /golden_tests/data/ff_factors.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/domokane/FinancePy/7ca2a16354076cad672c03add5c3fb444159223b/golden_tests/data/ff_factors.pkl -------------------------------------------------------------------------------- /golden_tests/data/gilt_bond_prices.txt: -------------------------------------------------------------------------------- 1 | epic description coupon maturity bid ask change income yield gross redemption yield 2 | TR13 Uk Gilt Treasury Stk 4.5 07-Mar-13 101.92 102.07 -0.01 4.41 0.22 3 | T813 Uk Gilt Treasury Stk 8 27-Sep-13 107.86 107.98 -0.03 7.41 0.23 4 | TR14 Uk Gilt Treasury Stk 2.25 07-Mar-14 102.9 103.05 0.01 2.18 0.22 5 | T514 Uk Gilt Treasury Stk 5 07-Sep-14 109.28 109.43 0.02 4.57 0.23 6 | TR15 Uk Gilt Treasury Stk 2.75 22-Jan-15 105.57 105.68 0.05 2.6 0.33 7 | T4T Uk Gilt Treasury Stk 4.75 07-Sep-15 112.92 113.04 0.04 4.2 0.35 8 | TY8 Uk Gilt Treasury Stk 8 07-Dec-15 124.39 124.55 0.04 6.43 0.34 9 | TS16 Uk Gilt Treasury Stk 2 22-Jan-16 104.92 105.04 0.07 1.91 0.49 10 | T16 Uk Gilt Treasury Stk 4 07-Sep-16 113.44 113.55 0.08 3.52 0.56 11 | TR17 Uk Gilt Treasury Stk 8.75 25-Aug-17 138.48 138.66 0.14 6.31 0.77 12 | T18 Uk Gilt Treasury Stk 5 07-Mar-18 121.74 121.84 0.16 4.11 0.91 13 | T19 Uk Gilt Treasury Stk 4.5 07-Mar-19 121.28 121.41 0.23 3.71 1.07 14 | TR19 Uk Gilt Treasury Stk 3.75 07-Sep-19 116.5 117.13 0.26 3.21 1.22 15 | TS20 Uk Gilt Treasury Stk 4.75 07-Mar-20 124.24 124.36 0.28 3.82 1.32 16 | TR20 Uk Gilt Treasury Stk 3.75 07-Sep-20 117.25 117.5 0.32 3.19 1.43 17 | TR21 Uk Gilt Treasury Stk 8 07-Jun-21 152.25 153.61 0.42 5.23 1.5 18 | TY21 Uk Gilt Treasury Stk 3.75 07-Sep-21 117.62 117.77 0.38 3.19 1.62 19 | TR22 Uk Gilt Treasury Stk 4 07-Mar-22 119.92 120.12 0.41 3.33 1.7 20 | TR25 Uk Gilt Treasury Stk 5 07-Mar-25 131.89 132.19 0.52 3.79 2.07 21 | TR27 Uk Gilt Treasury Stk 4.25 07-Dec-27 123.78 124.33 0.58 3.43 2.36 22 | TR28 Uk Gilt Treasury Stk 6 07-Dec-28 148.21 148.26 0.68 4.05 2.39 23 | TR30 Uk Gilt Treasury Stk 4.75 07-Dec-30 130.96 131.14 0.55 3.62 2.6 24 | TR32 Uk Gilt Treasury Stk 4.25 07-Jun-32 122.93 123.08 0.54 3.46 2.73 25 | T34 Uk Gilt Treasury Stk 4.5 07-Sep-34 126.09 126.18 0.58 3.57 2.89 26 | T4Q Uk Gilt Treasury Stk 4.25 07-Mar-36 121.46 121.71 0.53 3.5 2.97 27 | TR38 Uk Gilt Treasury Stk 4.75 07-Dec-38 130.7 130.8 0.55 3.63 3.04 28 | T39 Uk Gilt Treasury Stk 4.25 07-Sep-39 120.9 121.15 0.54 3.51 3.09 29 | T40 Uk Gilt Treasury Stk 4.25 07-Dec-40 120.55 120.93 0.53 3.52 3.14 30 | T42 Uk Gilt Treasury Stk 4.5 07-Dec-42 125.77 126.07 0.58 3.57 3.16 31 | T46 Uk Gilt Treasury Stk 4.25 07-Dec-46 120.93 121.37 0.56 3.51 3.22 32 | T49 Uk Gilt Treasury Stk 4.25 07-Dec-49 120.99 121.34 0.53 3.51 3.26 33 | TR4Q Uk Gilt Treasury Stk 4.25 07-Dec-55 122.49 122.9 0.55 3.46 3.27 34 | TR60 Uk Gilt Treasury Stk 4 22-Jan-60 117.6 118.06 0.51 3.39 3.26 -------------------------------------------------------------------------------- /golden_tests/data/ibor_benchmarks_example.csv: -------------------------------------------------------------------------------- 1 | ,type,start_date,maturity_date,day_count_type,notional,contract_rate,market_rate,spot_pvbp,fwd_pvbp,unit_value,value,fixed_leg_type,fixed_freq_type 2 | 0,IborDeposit,06-Oct-01,09-Oct-01,ACT_360,100,0.042,0.042,0.00833,0.00833,1,100,NaN,NaN 3 | 1,IborDeposit,09-Oct-01,09-Jan-02,ACT_360,100,0.042,0.042,0.252753,0.252842,1,100,NaN,NaN 4 | 2,IborFRA,09-Jan-02,09-Apr-02,ACT_360,100,0.042,0.042,0.244689,0.247402,0,0,PAY,NaN 5 | 3,IborSwap,09-Oct-01,09-Oct-02,THIRTY_E_360_ISDA,1000000,0.042,0.042,0.968858,0.969197,0,0,PAY,SEMI_ANNUAL 6 | 4,IborSwap,09-Oct-01,09-Oct-03,THIRTY_E_360_ISDA,1000000,0.043,0.043,1.897071,1.897735,0,0,PAY,SEMI_ANNUAL 7 | 5,IborSwap,09-Oct-01,11-Oct-04,THIRTY_E_360_ISDA,1000000,0.047,0.047,2.782943,2.783917,0,0,PAY,SEMI_ANNUAL 8 | 6,IborSwap,09-Oct-01,09-Oct-06,THIRTY_E_360_ISDA,1000000,0.054,0.054,4.381878,4.383412,0,0,PAY,SEMI_ANNUAL 9 | 7,IborSwap,09-Oct-01,09-Oct-08,THIRTY_E_360_ISDA,1000000,0.057,0.057,5.789357,5.791383,0,0,PAY,SEMI_ANNUAL 10 | 8,IborSwap,09-Oct-01,10-Oct-11,THIRTY_E_360_ISDA,1000000,0.06,0.06,7.575903,7.578554,0,-0.000013,PAY,SEMI_ANNUAL 11 | 9,IborSwap,09-Oct-01,09-Oct-13,THIRTY_E_360_ISDA,1000000,0.061,0.061,8.57742,8.580422,0,0,PAY,SEMI_ANNUAL 12 | 10,IborSwap,09-Oct-01,10-Oct-16,THIRTY_E_360_ISDA,1000000,0.059,0.059,9.899371,9.902836,0,-0.000001,PAY,SEMI_ANNUAL 13 | 11,IborSwap,09-Oct-01,11-Oct-21,THIRTY_E_360_ISDA,1000000,0.056,0.056,11.766369,11.770487,0,-0.000037,PAY,SEMI_ANNUAL 14 | 12,IborSwap,09-Oct-01,09-Oct-26,THIRTY_E_360_ISDA,1000000,0.0555,0.0555,13.250223,13.25486,0,-0.000111,PAY,SEMI_ANNUAL 15 | -------------------------------------------------------------------------------- /golden_tests/data/test_cases_bond_ror.csv: -------------------------------------------------------------------------------- 1 | bond_code,buy_date,buy_ytm,buy_price,sell_date,sell_ytm,sell_price,simple_return,irr,note 2 | 210215.IB,2022/10/8,0.03,101.1388892,2023/12/8,0.033,99.50854719,0.012619776,0.012684992, 3 | 210215.IB,2022/10/9,0.05,86.93892387,2023/12/9,0.055,86.0114561,0.021608021,0.021726748, 4 | 210215.IB,2021/10/10,0.045,89.37097146,2023/12/10,0.041,94.33608106,0.057854349,0.057303426, 5 | 210215.IB,2021/10/11,0.032,99.56478807,2022/12/11,0.04,94.35496199,-0.017984056,-0.018131188, 6 | 210215.IB,2022/10/12,0.028,102.7401287,2022/12/12,0.025,105.5828341,0.165559758,0.177402478, 7 | 210215.IB,2022/10/13,0.036,96.64561565,2023/8/13,0.035,100.214665,0.044339386,0.044502077, 8 | 210215.IB,2022/10/14,0.029,101.9682359,2023/12/7,0.024,105.7655301,0.059094924,0.059199324, 9 | 210215.IB,2022/10/15,0.018,111.0512814,2024/12/6,0.042,94.45553255,-0.04346994,-0.045524839, 10 | 210215.IB,2022/10/16,-0.011,140.015924,2023/6/5,-0.012,140.0860028,0.000787435,0.000787547, 11 | 210215.IB,2022/10/17,-0.006,134.4315191,2025/12/4,0.003,116.8223425,-0.019578361,-0.020582882, 12 | 210215.IB,2022/10/18,-0.025,157.1465555,2026/9/3,-0.017,128.559942,-0.03153752,-0.03419871, 13 | 210215.IB,2022/10/19,-0.009,137.7404361,2027/4/2,-0.028,130.2061017,0.008060011,0.008288744, 14 | 210215.IB,2022/10/20,0.011,117.3492014,2025/7/20,-0.002,123.2173526,0.037510845,0.037266639, 15 | 210215.IB,2022/10/21,0.007,121.1247945,2023/8/21,-0.011,138.7109447,0.174323929,0.176770967, 16 | 210215.IB,2022/10/22,0.007,121.1271094,2028/12/22,0,109.36,0.009299417,0.009737208, 17 | 210215.IB,2022/10/23,0.017,111.9647539,2022/10/24,99999.99,0.00011371,-364.9996293,-364.9996293,True IRR is -1 which is beyond the brentq limit. 18 | 210215.IB,2022/10/26,0.011,117.3703067,2023/9/26,0.65,6.650108017,-0.99885602,-0.93552592, 19 | 210215.IB,2022/10/24,0.027,103.6260512,2022/10/25,0.025,105.2405365,5.686669801,5.686669801,True IRR is 281.259169 which is beyond the brentq limit. 20 | -------------------------------------------------------------------------------- /golden_tests/data/test_cases_bond_zero_ror.csv: -------------------------------------------------------------------------------- 1 | bond_code,buy_date,buy_ytm,buy_price,sell_date,sell_ytm,sell_price,simple_return,irr,note 2 | 092103011.IB,2021/10/7,0.037,96.84857394,2022/3/21,0.09,96.29590545,-0.012623518,-0.012579879, 3 | 092103011.IB,2021/10/8,0.03,97.43726642,2022/8/22,999.99,15.43353432,-0.965993649,-0.879367888, 4 | 092103011.IB,2021/10/6,0.07,94.18382619,2021/12/7,0.039,97.29700912,0.194594018,0.211000758, 5 | 092103011.IB,2021/10/7,0.3,79.12421418,2021/10/28,0.2,85.88235294,1.484537815,3.155915761, 6 | -------------------------------------------------------------------------------- /golden_tests/differences/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/domokane/FinancePy/7ca2a16354076cad672c03add5c3fb444159223b/golden_tests/differences/.gitkeep -------------------------------------------------------------------------------- /golden_tests/golden/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/domokane/FinancePy/7ca2a16354076cad672c03add5c3fb444159223b/golden_tests/golden/.gitkeep -------------------------------------------------------------------------------- /golden_tests/golden/TestFinAmount_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_142939 2 | HEADER,LABEL,AMOUNT, 3 | RESULTS,Amount,101,000.23, 4 | RESULTS,Amount,CAD 101,000.23, 5 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinBondConvertible_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_142941 2 | HEADER,LABEL, 3 | RESULTS,NO CALLS OR PUTS, 4 | HEADER,TIME,NUMSTEPS,PRICE, 5 | RESULTS,0.00199413,5,{'cbprice': 1096.15275, 'bond': 123.53434451658003, 'delta': 11.286322001863674, 'gamma': 0.1870652835104549, 'theta': 0.4751923691532599}, 6 | RESULTS,0.00000000,10,{'cbprice': 1124.4702210998516, 'bond': 123.53434451658003, 'delta': 37.00542873918339, 'gamma': 0.45403874809126554, 'theta': -6.376909194742964}, 7 | RESULTS,0.00099778,20,{'cbprice': 1126.2804668920173, 'bond': 123.53434451658002, 'delta': 37.09945668257613, 'gamma': 0.01710928200987063, 'theta': 598.2514199321721}, 8 | HEADER,LABEL, 9 | RESULTS,DIVIDENDS, 10 | HEADER,TIME,NUMSTEPS,PRICE, 11 | RESULTS,0.00000000,5,{'cbprice': 1096.15275, 'bond': 123.53434451658003, 'delta': 12.05500279382374, 'gamma': 0.18929016293487083, 'theta': 0.4751923691532599}, 12 | RESULTS,0.00000000,20,{'cbprice': 1108.7106639229305, 'bond': 123.53434451658002, 'delta': 38.320647641227595, 'gamma': 0.0024096763057534086, 'theta': 607.6855912311041}, 13 | RESULTS,0.00000000,80,{'cbprice': 1114.4722328942562, 'bond': 123.53434451657998, 'delta': 38.25740289779197, 'gamma': 0.04361203905053884, 'theta': 1007.4601931923423}, 14 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinBondEmbeddedOptionBK_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_142941 2 | HEADER,BOND PRICE,PRICE, 3 | RESULTS,Bond Pure Price:,102.07456540, 4 | HEADER,TIME,Numtime_steps,BondWithOption,BondPure, 5 | RESULTS,0.00000000,100,102.35076939,102.06026369, 6 | RESULTS,0.01500702,150,102.33894782,102.06026367, 7 | HEADER,BOND PRICE,PRICE, 8 | RESULTS,Bond Pure Price:,95.07340584, 9 | HEADER,TIME,Numtime_steps,BondWithOption,BondPure, 10 | RESULTS,0.00000000,100,89.76141599,95.06192734, 11 | RESULTS,0.00000000,150,89.77403998,95.06192781, 12 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinBondEmbeddedOptionHW_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_142941 2 | HEADER,BOND PRICE,PRICE, 3 | RESULTS,Bond Pure Price:,102.07456540, 4 | HEADER,TIME,Numtime_steps,BondWithOption,BondPure, 5 | RESULTS,0.00000000,50,102.88071963,102.06026370, 6 | RESULTS,0.00000000,100,102.87330242,102.06026370, 7 | RESULTS,0.00000000,150,102.87030874,102.06026370, 8 | RESULTS,0.00900650,200,102.87313897,102.06026370, 9 | RESULTS,0.00503612,250,102.87147557,102.06026370, 10 | RESULTS,0.00600290,300,102.87041560,102.06026370, 11 | RESULTS,0.00897598,350,102.87203084,102.06026370, 12 | RESULTS,0.01046896,400,102.87123240,102.06026370, 13 | RESULTS,0.01466799,450,102.87049956,102.06026370, 14 | RESULTS,0.01761031,500,102.87172729,102.06026370, 15 | RESULTS,0.02170205,550,102.86961951,102.06026370, 16 | RESULTS,0.02215934,600,102.87068081,102.06026370, 17 | RESULTS,0.04124522,650,102.87021161,102.06026370, 18 | RESULTS,0.05154204,700,102.86985270,102.06026370, 19 | RESULTS,0.05406022,750,102.87073418,102.06026370, 20 | RESULTS,0.04732203,800,102.87034342,102.06026370, 21 | RESULTS,0.06245255,850,102.87007002,102.06026370, 22 | RESULTS,0.06360507,900,102.87071840,102.06026370, 23 | RESULTS,0.06292129,950,102.87037997,102.06026370, 24 | HEADER,BOND PRICE,PRICE, 25 | RESULTS,Bond Pure Price:,94.63182976, 26 | HEADER,TIME,Numtime_steps,BondWithOption,BondPure, 27 | RESULTS,0.00000000,100,68.86652588,95.06192803, 28 | RESULTS,0.00000000,150,68.92084368,95.06192803, 29 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinBondFRN_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20240731_173913 2 | BANNER,BLOOMBERG CITIGROUP FRN EXAMPLE 3 | HEADER,FIELD,VALUE, 4 | RESULTS,Discount Margin (bp) = ,103.19847467, 5 | RESULTS,Dirty Price = ,97.02662156, 6 | RESULTS,Last Coupon Date = ,10-MAY-2017, 7 | RESULTS,Accrued Days = ,71, 8 | RESULTS,Accrued Amount = ,0.00233622, 9 | RESULTS,Dollar Principal = ,97.02428534, 10 | RESULTS,Dollar Rate Duration = ,5.11480985, 11 | RESULTS,Modified Rate Duration = ,0.05271553, 12 | RESULTS,Macauley Duration = ,0.05300765, 13 | RESULTS,Convexity = ,0.00005558, 14 | RESULTS,Dollar Credit Duration = ,401.06359017, 15 | RESULTS,Modified Credit Duration = ,4.13354174, 16 | BANNER,BLOOMBERG CITIGROUP FRN EXAMPLE II 17 | HEADER,FIELD,VALUE, 18 | RESULTS,Discount Margin (bp) = ,123.06229098, 19 | RESULTS,Dirty Price = ,93.13148611, 20 | RESULTS,Last Coupon Date = ,03-FEB-2014, 21 | RESULTS,Accrued Days = ,55, 22 | RESULTS,Accrued Amount = ,0.00051486, 23 | RESULTS,Dollar Principal = ,93.13097125, 24 | RESULTS,Dollar Rate Duration = ,31.89582765, 25 | RESULTS,Modified Rate Duration = ,0.34248168, 26 | RESULTS,Macauley Duration = ,0.34516609, 27 | RESULTS,Convexity = ,0.00234587, 28 | RESULTS,Principal = ,93.13097125, 29 | RESULTS,Dollar Credit Duration = ,563.26238203, 30 | RESULTS,Modified Credit Duration = ,6.04803387, 31 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinBondYieldCurve_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20240731_174050 2 | HEADER,PARAMETER,VALUE, 3 | RESULTS,values,[ 3.53695541e-07 -5.03221108e-05 2.30547697e-03 -1.54434702e-03], 4 | HEADER,PARAMETER,VALUE, 5 | RESULTS,values,[-1.44771535e-09 1.78395721e-07 -7.41468170e-06 9.06222841e-05 6 | 1.35360732e-03 4.15140112e-07], 7 | HEADER,PARAMETER,VALUE, 8 | RESULTS,beta_1,-0.09364839, 9 | RESULTS,beta_2,0.09210325, 10 | RESULTS,beta_3,0.25878568, 11 | RESULTS,tau,35.78538026, 12 | HEADER,PARAMETER,VALUE, 13 | RESULTS,beta_1,0.04601881, 14 | RESULTS,beta_2,-0.04327272, 15 | RESULTS,beta_3,-0.05226095, 16 | RESULTS,beta_4,-0.03756485, 17 | RESULTS,tau_1,3.17744997, 18 | RESULTS,tau_2,100.00000000, 19 | RESULTS,19-SEP-2030,0.026018581814958648, 20 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinBondZeroCoupon_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_142945 2 | HEADER,YTM,accrued, 3 | RESULTS,-0.23317309,0.05523077, 4 | HEADER,bond_code,buy_date,buy_ytm,buy_price,sell_date,sell_ytm,sell_price,simple_return,irr, 5 | RESULTS,092103011.IB,07-OCT-2021,0.03700000,96.84857394,21-MAR-2022,0.09000000,96.29590544,-0.01262352,-0.01257988, 6 | RESULTS,092103011.IB,08-OCT-2021,0.03000000,97.43726642,22-AUG-2022,999.99000000,15.43353432,-0.96599365,-0.87936789, 7 | RESULTS,092103011.IB,06-OCT-2021,0.07000000,94.18382618,07-DEC-2021,0.03900000,97.29700912,0.19459402,0.21100076, 8 | RESULTS,092103011.IB,07-OCT-2021,0.30000000,79.12421418,28-OCT-2021,0.20000000,85.88235294,1.48453782,3.15591576, 9 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinBondZeroCurve_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_142945 2 | HEADER,DATE,ZERO RATE, 3 | RESULTS,07-MAR-2013,0.00223651, 4 | RESULTS,27-SEP-2013,0.00234610, 5 | RESULTS,07-MAR-2014,0.00217793, 6 | RESULTS,07-SEP-2014,0.00230178, 7 | RESULTS,22-JAN-2015,0.00336336, 8 | RESULTS,07-SEP-2015,0.00352979, 9 | RESULTS,07-DEC-2015,0.00347948, 10 | RESULTS,22-JAN-2016,0.00499348, 11 | RESULTS,07-SEP-2016,0.00568825, 12 | RESULTS,25-AUG-2017,0.00822352, 13 | RESULTS,07-MAR-2018,0.00950710, 14 | RESULTS,07-MAR-2019,0.01127175, 15 | RESULTS,07-SEP-2019,0.01281502, 16 | RESULTS,07-MAR-2020,0.01404876, 17 | RESULTS,07-SEP-2020,0.01509025, 18 | RESULTS,07-JUN-2021,0.01666140, 19 | RESULTS,07-SEP-2021,0.01714429, 20 | RESULTS,07-MAR-2022,0.01809815, 21 | RESULTS,07-MAR-2025,0.02256407, 22 | RESULTS,07-DEC-2027,0.02562121, 23 | RESULTS,07-DEC-2028,0.02678669, 24 | RESULTS,07-DEC-2030,0.02881625, 25 | RESULTS,07-JUN-2032,0.03023887, 26 | RESULTS,07-SEP-2034,0.03244900, 27 | RESULTS,07-MAR-2036,0.03330047, 28 | RESULTS,07-DEC-2038,0.03450988, 29 | RESULTS,07-SEP-2039,0.03492375, 30 | RESULTS,07-DEC-2040,0.03549834, 31 | RESULTS,07-DEC-2042,0.03587425, 32 | RESULTS,07-DEC-2046,0.03627216, 33 | RESULTS,07-DEC-2049,0.03672070, 34 | RESULTS,07-DEC-2055,0.03595150, 35 | RESULTS,22-JAN-2060,0.03509800, 36 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinCDSCurve_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143008 2 | HEADER,T,Q, 3 | RESULTS,0.00000000,1.00000000, 4 | RESULTS,1.00000000,0.99156915, 5 | RESULTS,2.00273973,0.97984002, 6 | RESULTS,3.00273973,0.96480510, 7 | RESULTS,4.00273973,0.94646366, 8 | RESULTS,5.00273973,0.92485409, 9 | RESULTS,6.00547945,0.89999085, 10 | RESULTS,7.00547945,0.87202803, 11 | RESULTS,8.00547945,0.84101722, 12 | RESULTS,9.00547945,0.80706706, 13 | RESULTS,10.00821918,0.77024806, 14 | HEADER,CONTRACT,VALUE, 15 | RESULTS,1,{'dirty_pv': -8.585558134655003e-06, 'clean_pv': -8.585558134655003e-06}, 16 | RESULTS,2,{'dirty_pv': 0.006416023903511814, 'clean_pv': 0.006416023903511814}, 17 | RESULTS,3,{'dirty_pv': -5.106915705255233e-05, 'clean_pv': -5.106915705255233e-05}, 18 | RESULTS,4,{'dirty_pv': -9.598848191672005e-05, 'clean_pv': -9.598848191672005e-05}, 19 | RESULTS,5,{'dirty_pv': -0.0001639612964936532, 'clean_pv': -0.0001639612964936532}, 20 | RESULTS,6,{'dirty_pv': -0.00026531744515523314, 'clean_pv': -0.00026531744515523314}, 21 | RESULTS,7,{'dirty_pv': 0.018623579788254574, 'clean_pv': 0.018623579788254574}, 22 | RESULTS,8,{'dirty_pv': 0.009548901769449003, 'clean_pv': 0.009548901769449003}, 23 | RESULTS,9,{'dirty_pv': -0.0008203024626709521, 'clean_pv': -0.0008203024626709521}, 24 | RESULTS,10,{'dirty_pv': -0.0011491132609080523, 'clean_pv': -0.0011491132609080523}, 25 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinCDSIndexAdjustHazards_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143008 2 | HEADER,LABEL,VALUE, 3 | RESULTS,AVERAGE SPD 3Y,19.82213091, 4 | RESULTS,AVERAGE SPD 5Y,36.03565060, 5 | RESULTS,AVERAGE SPD 7Y,50.13360376, 6 | RESULTS,AVERAGE SPD 10Y,63.66216268, 7 | BANNER,=================================================================== 8 | HEADER,LABEL,VALUE, 9 | RESULTS,INTRINSIC SPD 3Y,19.67894090, 10 | RESULTS,INTRINSIC SPD 5Y,35.53938109, 11 | RESULTS,INTRINSIC SPD 7Y,49.01210849, 12 | RESULTS,INTRINSIC SPD 10Y,61.41402249, 13 | BANNER,=================================================================== 14 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinCDSIndexAdjustSpreads_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143009 2 | HEADER,LABEL,VALUE, 3 | RESULTS,AVERAGE SPD 3Y,19.82213043, 4 | RESULTS,AVERAGE SPD 5Y,36.03565060, 5 | RESULTS,AVERAGE SPD 7Y,50.13360376, 6 | RESULTS,AVERAGE SPD 10Y,63.66216268, 7 | HEADER,LABEL,VALUE, 8 | RESULTS,INTRINSIC SPD 3Y,19.67867465, 9 | RESULTS,INTRINSIC SPD 5Y,35.53895399, 10 | RESULTS,INTRINSIC SPD 7Y,49.01158230, 11 | RESULTS,INTRINSIC SPD 10Y,61.41344237, 12 | HEADER,TIME, 13 | RESULTS,4.95716381, 14 | HEADER,LABEL,VALUE, 15 | RESULTS,ADJUSTED INTRINSIC SPD 3Y:,20.00002389, 16 | RESULTS,ADJUSTED INTRINSIC SPD 5Y:,37.01163093, 17 | RESULTS,ADJUSTED INTRINSIC SPD 7Y,50.01449391, 18 | RESULTS,ADJUSTED INTRINSIC SPD 10Y,63.01598016, 19 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinCDSIndexOption_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143015 2 | BANNER,======================= CDS INDEX OPTION ========================== 3 | HEADER,TIME,STRIKE,INDEX,PAY,RECEIVER,G(K),X,EXPH,ABPAY,ABREC, 4 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinCDSIndexPortfolio_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143015 2 | HEADER,LABEL,VALUE, 3 | RESULTS,AVERAGE SPD 3Y,19.82213091, 4 | RESULTS,AVERAGE SPD 5Y,36.03565060, 5 | RESULTS,AVERAGE SPD 7Y,50.13360376, 6 | RESULTS,AVERAGE SPD 10Y,63.66216268, 7 | HEADER,LABEL,VALUE, 8 | RESULTS,INTRINSIC SPD 3Y,19.67894090, 9 | RESULTS,INTRINSIC SPD 5Y,35.53938109, 10 | RESULTS,INTRINSIC SPD 7Y,49.01210849, 11 | RESULTS,INTRINSIC SPD 10Y,61.41402249, 12 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinCDSIndex_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143008 2 | HEADER,LABEL,VALUE, 3 | RESULTS,PAR SPREAD,48.37497284, 4 | RESULTS,DIRTY VALUE,27065.68366432, 5 | RESULTS,CLEAN VALUE,32621.23921988, 6 | RESULTS,CLEAN PRICE,99.67378761, 7 | RESULTS,ACCRUED DAYS,50.00000000, 8 | RESULTS,ACCRUED COUPON,-5555.55555556, 9 | RESULTS,PROTECTION LEG PV,188424.67814501, 10 | RESULTS,PREMIUM LEG PV,161358.99448069, 11 | RESULTS,DIRTY RPV01,dirty_rpv01, 12 | RESULTS,CLEAN RPV01,clean_rpv01, 13 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinDateAdjust_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143019 2 | HEADER,NO ADJUSTMENTS,DATE, 3 | RESULTS,Date:,28-FEB-2008, 4 | RESULTS,Date:,28-AUG-2008, 5 | RESULTS,Date:,28-FEB-2009, 6 | RESULTS,Date:,28-AUG-2009, 7 | RESULTS,Date:,28-FEB-2010, 8 | RESULTS,Date:,28-AUG-2010, 9 | RESULTS,Date:,28-FEB-2011, 10 | BANNER, 11 | HEADER,NO WEEKENDS AND FOLLOWING,DATE, 12 | RESULTS,Date:,28-FEB-2008, 13 | RESULTS,Date:,28-AUG-2008, 14 | RESULTS,Date:,02-MAR-2009, 15 | RESULTS,Date:,28-AUG-2009, 16 | RESULTS,Date:,01-MAR-2010, 17 | RESULTS,Date:,30-AUG-2010, 18 | RESULTS,Date:,28-FEB-2011, 19 | BANNER, 20 | HEADER,NO WEEKENDS AND MODIFIED FOLLOWING,DATE, 21 | RESULTS,Date:,28-FEB-2008, 22 | RESULTS,Date:,28-AUG-2008, 23 | RESULTS,Date:,27-FEB-2009, 24 | RESULTS,Date:,28-AUG-2009, 25 | RESULTS,Date:,26-FEB-2010, 26 | RESULTS,Date:,30-AUG-2010, 27 | RESULTS,Date:,28-FEB-2011, 28 | BANNER, 29 | HEADER,NO WEEKENDS AND US HOLIDAYS AND MODIFIED FOLLOWING,DATE, 30 | RESULTS,Date:,04-JUL-2008, 31 | RESULTS,Date:,05-JAN-2009, 32 | RESULTS,Date:,06-JUL-2009, 33 | RESULTS,Date:,04-JAN-2010, 34 | RESULTS,Date:,06-JUL-2010, 35 | RESULTS,Date:,04-JAN-2011, 36 | RESULTS,Date:,05-JUL-2011, 37 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinDiscountCurveFlat_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143020 2 | HEADER,COMPOUNDING,DFS, 3 | RESULTS,FrequencyTypes.CONTINUOUS,[0.99576243 0.98369602 0.97137654 0.95921136 0.94720951 0.9356348 4 | 0.92394904 0.91240924 0.9010031 0.89008496 0.87893784 0.86793033 5 | 0.85706066 0.84667501 0.83607154 0.82560087 0.81526132 0.80538218 6 | 0.79529585 0.78533584], 7 | RESULTS,FrequencyTypes.ANNUAL,[0.99586475 0.98408736 0.97205937 0.96017839 0.94845336 0.9371422 8 | 0.9257191 0.91443523 0.90327869 0.89259625 0.8816865 0.8709101 9 | 0.86026542 0.85009166 0.83970143 0.82943819 0.8193004 0.80961111 10 | 0.79971565 0.78994114], 11 | RESULTS,FrequencyTypes.SEMI_ANNUAL,[0.99581442 0.98389486 0.97172346 0.95970263 0.94784137 0.93640048 12 | 0.92484807 0.91343818 0.90215872 0.89136018 0.8803335 0.86944322 13 | 0.85868766 0.84840945 0.83791409 0.82754857 0.81731127 0.80752833 14 | 0.7975387 0.78767264], 15 | RESULTS,FrequencyTypes.QUARTERLY,[0.99578864 0.98379625 0.97155142 0.95945899 0.94752799 0.93602071 16 | 0.92440215 0.9129278 0.90158549 0.8907276 0.87964114 0.86869267 17 | 0.85788048 0.84754893 0.8369999 0.82658217 0.8162941 0.80646338 18 | 0.79642572 0.786513 ], 19 | RESULTS,FrequencyTypes.MONTHLY,[0.99577121 0.98372961 0.97143515 0.95929435 0.94731625 0.93576413 20 | 0.92410089 0.91258301 0.90119826 0.89030031 0.87917351 0.86818577 21 | 0.85733536 0.84696783 0.83638259 0.82592965 0.81560734 0.80574441 22 | 0.79567438 0.7857302 ], 23 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinDiscountCurveNSS_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20240731_182237 2 | HEADER,FACTOR LOADING ON ZERO RATES, 3 | RESULTS,[0.99997788 0.9852199 0.98522167 0.98558092 0.98549138], 4 | RESULTS,[1.0000889 0.56282044 0.3617399 0.25676859 0.19577024], 5 | RESULTS,[1.11022302e-04 2.79969608e-01 2.80867982e-01 2.33542270e-01 6 | 1.89130049e-01], 7 | RESULTS,[-0. 0.18933444 0.09847297 0.06574109 0.04927457], 8 | HEADER,beta_1,beta_2,beta_3,beta_4,ZEROS, 9 | RESULTS,0.03000000,-0.02000000,-0.02000000,0.08000000,[0.00999201 0.02784755 0.02458233 0.0250205 0.0258087 ], 10 | RESULTS,0.04000000,-0.02000000,-0.02000000,0.08000000,[0.01998401 0.03769975 0.03443455 0.03487631 0.03566361], 11 | RESULTS,0.05000000,-0.02000000,-0.02000000,0.08000000,[0.02997602 0.04755195 0.04428676 0.04473212 0.04551853], 12 | RESULTS,0.06000000,-0.02000000,-0.02000000,0.08000000,[0.03996803 0.05740415 0.05413898 0.05458793 0.05537344], 13 | RESULTS,0.07000000,-0.02000000,-0.02000000,0.08000000,[0.04996004 0.06725635 0.0639912 0.06444373 0.06522836], 14 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinDiscountCurveNS_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20240731_182155 2 | HEADER,FACTOR LOADING ON ZERO RATES, 3 | RESULTS,[0.99997788 0.98522227 0.98552995 0.98558144 0.98549138], 4 | RESULTS,[1.0000889 0.56220765 0.3617652 0.25659811 0.19577024], 5 | RESULTS,[1.11022302e-04 2.80130010e-01 2.80931229e-01 2.33435325e-01 6 | 1.89130049e-01], 7 | HEADER,beta_1,beta_2,beta_3,ZEROS, 8 | RESULTS,0.03000000,-0.02000000,0.02000000,[0.00999201 0.02391512 0.02794922 0.02910419 0.02943194], 9 | RESULTS,0.04000000,-0.02000000,0.02000000,[0.01998401 0.03376734 0.03780452 0.03896 0.03928685], 10 | RESULTS,0.05000000,-0.02000000,0.02000000,[0.02997602 0.04361956 0.04765982 0.04881582 0.04914177], 11 | RESULTS,0.06000000,-0.02000000,0.02000000,[0.03996803 0.05347178 0.05751512 0.05867163 0.05899668], 12 | RESULTS,0.07000000,-0.02000000,0.02000000,[0.04996004 0.06332401 0.06737042 0.06852745 0.06885159], 13 | RESULTS,0.06000000,-0.04000000,0.02000000,[0.01998401 0.04222763 0.05027981 0.05353967 0.05508127], 14 | RESULTS,0.06000000,-0.02000000,0.02000000,[0.03996803 0.05347178 0.05751512 0.05867163 0.05899668], 15 | RESULTS,0.06000000,0.00000000,0.02000000,[0.05995204 0.06471594 0.06475042 0.06380359 0.06291208], 16 | RESULTS,0.06000000,0.02000000,0.02000000,[0.08004708 0.07596009 0.07198573 0.06893556 0.06682749], 17 | RESULTS,0.06000000,0.04000000,0.02000000,[0.10003109 0.08720424 0.07922103 0.07406752 0.07074289], 18 | RESULTS,0.06000000,-0.02000000,-0.02000000,[0.03996803 0.04226658 0.04627787 0.04933422 0.05143148], 19 | RESULTS,0.06000000,-0.02000000,0.00000000,[0.03996803 0.04786918 0.05189649 0.05400292 0.05521408], 20 | RESULTS,0.06000000,-0.02000000,0.02000000,[0.03996803 0.05347178 0.05751512 0.05867163 0.05899668], 21 | RESULTS,0.06000000,-0.02000000,0.04000000,[0.03996803 0.05907438 0.06313374 0.06334034 0.06277928], 22 | RESULTS,0.06000000,-0.02000000,0.06000000,[0.03996803 0.06467698 0.06875237 0.06800904 0.06656188], 23 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinDiscountCurvePolynomial_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143020 2 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinDiscountCurveZeros_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143020 2 | HEADER,T,DF, 3 | RESULTS,01-JAN-2018,1.01058759, 4 | RESULTS,01-JUL-2018,0.98129189, 5 | RESULTS,01-JAN-2019,0.95238095, 6 | RESULTS,01-JUL-2019,0.92864041, 7 | RESULTS,01-JAN-2020,0.90511288, 8 | RESULTS,01-JUL-2020,0.88156244, 9 | RESULTS,01-JAN-2021,0.85837605, 10 | RESULTS,01-JUL-2021,0.83522893, 11 | RESULTS,01-JAN-2022,0.81233785, 12 | RESULTS,01-JUL-2022,0.78960744, 13 | RESULTS,01-JAN-2023,0.76715211, 14 | RESULTS,01-JUL-2023,0.74490922, 15 | RESULTS,01-JAN-2024,0.72295859, 16 | RESULTS,01-JUL-2024,0.70120755, 17 | RESULTS,01-JAN-2025,0.67988263, 18 | RESULTS,01-JUL-2025,0.65879850, 19 | RESULTS,01-JAN-2026,0.63803498, 20 | RESULTS,01-JUL-2026,0.61760755, 21 | RESULTS,01-JAN-2027,0.59751179, 22 | RESULTS,01-JUL-2027,0.57778300, 23 | RESULTS,01-JAN-2028,0.55839478, 24 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinDiscountCurve_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143019 2 | HEADER,T,DF,ZERORATE,CC_FWD,MM_FWD,SURVPROB, 3 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinEquityAmericanMC_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143020 2 | BANNER,================== EUROPEAN PUT ======================= 3 | HEADER,OPTION_TYPE,VALUE,DELTA,GAMMA,THETA, 4 | RESULTS,EUROPEAN_PUT_BS,7.08327660,-0.36695745,370.56056472,-2.90411556, 5 | HEADER,OPTION_TYPE,NUMSTEPS,VALUE DELTA GAMMA THETA,TIME, 6 | RESULTS,EUROPEAN_PUT_TREE,100,7.08327660,0.00099730, 7 | BANNER,================== AMERICAN PUT ======================= 8 | HEADER,OPTION_TYPE,NUMSTEPS,VALUE DELTA GAMMA THETA,TIME, 9 | RESULTS,AMERICAN_PUT,100,7.25834295,0.00000000, 10 | BANNER,================== EUROPEAN CALL ======================= 11 | HEADER,OPTION_TYPE,VALUE,DELTA,GAMMA,THETA, 12 | RESULTS,EUROPEAN_CALL_BS,8.03452188,0.59383199,370.56056321,-3.80548735, 13 | HEADER,OPTION_TYPE,NUMSTEPS,VALUE DELTA GAMMA THETA,TIME, 14 | RESULTS,EUROPEAN_CALL_TREE,100,8.03452188,0.00000000, 15 | BANNER,================== AMERICAN CALL ======================= 16 | HEADER,OPTION_TYPE,NUMSTEPS,VALUE DELTA GAMMA THETA,TIME, 17 | RESULTS,AMERICAN_TREE_CALL,100,8.05558979,0.00000000, 18 | RESULTS,AMERICAN_LSMC_CALL,100,7.96190263,0.97899580, 19 | BANNER,================== AMERICAN PUT ======================= 20 | HEADER,OPTION_TYPE,NUMSTEPS,VALUE DELTA GAMMA THETA,TIME, 21 | RESULTS,AMERICAN_TREE_PUT,100,7.25834295,0.00051856, 22 | RESULTS,AMERICAN_PUT,100,7.16111647,1.00566602, 23 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinEquityAmericanOption_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143022 2 | BANNER,================== EUROPEAN PUT ======================= 3 | HEADER,OPTION_TYPE,VALUE,DELTA,GAMMA,THETA, 4 | RESULTS,EUROPEAN_PUT_BS,7.04314012,-0.29865485,1746.02971637,-2.88053962, 5 | HEADER,OPTION_TYPE,NUMSTEPS,VALUE DELTA GAMMA THETA,TIME, 6 | RESULTS,EUROPEAN_PUT_TREE,100,7.08327660,0.00000000, 7 | RESULTS,EUROPEAN_PUT_TREE,200,7.08347499,0.00000000, 8 | RESULTS,EUROPEAN_PUT_TREE,1000,7.08360939,0.00797844, 9 | BANNER,================== AMERICAN PUT ======================= 10 | HEADER,OPTION_TYPE,NUMSTEPS,VALUE DELTA GAMMA THETA,TIME, 11 | RESULTS,AMERICAN_PUT,100,7.25834295,0.00000000, 12 | RESULTS,AMERICAN_PUT,200,7.25697508,0.00099587, 13 | RESULTS,AMERICAN_PUT,1000,7.25579737,0.00797915, 14 | BANNER,================== EUROPEAN CALL ======================= 15 | HEADER,OPTION_TYPE,VALUE,DELTA,GAMMA,THETA, 16 | RESULTS,EUROPEAN_CALL_BS,8.03485467,0.58117907,117.44532848,-3.80589315, 17 | HEADER,OPTION_TYPE,NUMSTEPS,VALUE DELTA GAMMA THETA,TIME, 18 | RESULTS,EUROPEAN_CALL_TREE,100,8.03452188,0.00000000, 19 | RESULTS,EUROPEAN_CALL_TREE,200,8.03472026,0.00099754, 20 | RESULTS,EUROPEAN_CALL_TREE,1000,8.03485467,0.00698066, 21 | BANNER,================== AMERICAN CALL ======================= 22 | HEADER,OPTION_TYPE,NUMSTEPS,VALUE DELTA GAMMA THETA,TIME, 23 | RESULTS,AMERICAN_TREE_CALL,100,8.05558979,0.00000000, 24 | RESULTS,AMERICAN_TREE_CALL,200,8.05583395,0.00000000, 25 | RESULTS,AMERICAN_TREE_CALL,1000,8.05600602,0.00698042, 26 | BANNER,================== AMERICAN PUT ======================= 27 | HEADER,OPTION_TYPE,NUMSTEPS,VALUE DELTA GAMMA THETA,TIME, 28 | RESULTS,AMERICAN_TREE_PUT,100,7.25834295,0.00099587, 29 | RESULTS,AMERICAN_TREE_PUT,200,7.25697508,0.00000000, 30 | RESULTS,AMERICAN_TREE_PUT,1000,7.25579737,0.00698137, 31 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinEquityAsianOption_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143022 2 | HEADER,K,Geometric,Turnbull_Wakeman,Curran,FastMC,FastMC_CV, 3 | RESULTS,5000,12.33795295,12.53805370,12.53683981,12.42305501,12.52691423, 4 | HEADER,NUMPATHS,VALUE,TIME,VALUE_MC,TIME,VALUE_MC_CV,TIME, 5 | RESULTS,5000,12.52691423,0.02892232,12.42305501,0.02293873,12.52691423,0.03045750, 6 | HEADER,Date,Geometric,Turnbull_Wakeman,Curran,FastMC,FastMC_CV, 7 | RESULTS,01-APR-2014,17.38079386,17.75007733,17.75079160,17.73111481,17.73551523, 8 | RESULTS,01-JUN-2014,15.69593824,16.07089992,16.07126672,16.05784274,16.05415988, 9 | RESULTS,01-AUG-2014,13.87170964,14.25306878,14.25296811,14.24692144,14.23318718, 10 | RESULTS,01-FEB-2015,6.89557769,7.22981371,7.22649892,7.36925071,7.20144439, 11 | RESULTS,01-APR-2015,4.01479122,4.22296663,4.21786931,4.29774076,4.20092072, 12 | RESULTS,01-JUN-2015,1.55148718,1.65094125,1.64484731,1.74827621,1.64397939, 13 | RESULTS,01-AUG-2015,0.16724468,0.18593090,0.18280027,0.21746441,0.18851870, 14 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinEquityBinomialTree_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143026 2 | BANNER,================== EUROPEAN PUT ======================= 3 | HEADER,BS Value,BS Delta,BS Gamma,BS Theta, 4 | RESULTS,7.08363803,-0.38548246,0.01854899,-2.90151087, 5 | HEADER,NumSteps,Results,TIME, 6 | RESULTS,100,[ 7.10496862 -0.38649007 0.01867141 -2.94532419],0.00099707, 7 | RESULTS,500,[ 7.10526703 -0.38629401 0.01858097 -2.92744888],0.00099587, 8 | RESULTS,1000,[ 7.10529823 -0.38626945 0.01856972 -2.92522516],0.00697088, 9 | BANNER,================== AMERICAN PUT ======================= 10 | HEADER,NumSteps,Results,TIME, 11 | RESULTS,100,[ 7.27532551 -0.40079893 0.01996485 -3.18029106],0.00000000, 12 | RESULTS,500,[ 7.27311049 -0.40062522 0.01988436 -3.16451988],0.00099730, 13 | RESULTS,1000,[ 7.2728132 -0.40060397 0.0198744 -3.16257053],0.00797820, 14 | BANNER,================== EUROPEAN CALL ======================= 15 | HEADER,BS Value,BS Delta,BS Gamma,BS Theta, 16 | RESULTS,8.03488330,0.57530698,0.01854899,-3.80275642, 17 | HEADER,NumSteps,Results,TIME, 18 | RESULTS,100,[ 8.01749534 0.57468186 0.01867141 -3.81113332],0.00000000, 19 | RESULTS,500,[ 8.01779375 0.57457222 0.01858097 -3.79255828],0.00102830, 20 | RESULTS,1000,[ 8.01782495 0.5745584 0.01856972 -3.79024673],0.00798059, 21 | BANNER,================== AMERICAN CALL ======================= 22 | HEADER,NumSteps,Results,TIME, 23 | RESULTS,100,[ 8.03985089 0.57754292 0.01894644 -3.86756381],0.00099683, 24 | RESULTS,500,[ 8.04020774 0.57745516 0.01885854 -3.84950689],0.00199461, 25 | RESULTS,1000,[ 8.04024588 0.57744407 0.0188476 -3.84726072],0.00797844, 26 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinEquityChooserOption_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143026 2 | HEADER,,,,,,, 3 | RESULTS,FINANCEPY,6.03421210,HAUG,6.05080000,MC,6.05870436, 4 | HEADER,,,,,,, 5 | RESULTS,FINANCEPY,8.93159521,MATLAB,8.93080000,MC,8.93555524, 6 | HEADER,,,,,,, 7 | RESULTS,FINANCEPY,1.10521387,DERIVICOM,1.09890000,MC,1.10949701, 8 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinEquityCliquetOption_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143026 2 | HEADER,LABEL,VALUE, 3 | RESULTS,FINANCEPY,34.52865128, 4 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinEquityDigitalOption_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143026 2 | HEADER,NumLoops,ValueBS,ValueMC,TIME, 3 | RESULTS,10000,0.46929021,0.46957441,0.00099802, 4 | RESULTS,20000,0.46929021,0.46974087,0.00099707, 5 | RESULTS,40000,0.46929021,0.46940794,0.00199413, 6 | RESULTS,80000,0.46929021,0.46935443,0.00498724, 7 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinEquityForward_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143026 2 | HEADER,SPOT FX,FX FWD,VALUE_BS, 3 | RESULTS,130.00000000,133.95908941,852.21494673, 4 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinEquityLookbackOption_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143026 2 | HEADER,VALUE, 3 | RESULTS,25.93687971, 4 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinEquityOneTouchOption_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143026 2 | HEADER,================================= CASH ONLY, 3 | HEADER,TYPE,VALUE,VALUE_MC, 4 | RESULTS, TouchOptionTypes.DOWN_AND_IN_CASH_AT_HIT , 10.15381, 10.20050, 5 | RESULTS, TouchOptionTypes.DOWN_AND_IN_CASH_AT_EXPIRY , 9.77218, 9.82371, 6 | RESULTS, TouchOptionTypes.DOWN_AND_OUT_CASH_OR_NOTHING , 4.49627, 4.44473, 7 | HEADER,TYPE,VALUE,VALUE_MC, 8 | RESULTS, TouchOptionTypes.UP_AND_IN_CASH_AT_HIT , 11.28531, 11.07631, 9 | RESULTS, TouchOptionTypes.UP_AND_IN_CASH_AT_EXPIRY , 10.86668, 10.67302, 10 | RESULTS, TouchOptionTypes.UP_AND_OUT_CASH_OR_NOTHING , 3.40176, 3.59542, 11 | BANNER,================= ASSET ONLY 12 | HEADER,TYPE,VALUE,VALUE_MC, 13 | RESULTS, TouchOptionTypes.DOWN_AND_IN_ASSET_AT_HIT , 67.69205, 68.00333, 14 | RESULTS, TouchOptionTypes.DOWN_AND_IN_ASSET_AT_EXPIRY , 66.91760, 68.84921, 15 | RESULTS, TouchOptionTypes.DOWN_AND_OUT_ASSET_OR_NOTHING , 36.51916, 36.33674, 16 | RESULTS, TouchOptionTypes.UP_AND_IN_ASSET_AT_HIT , 75.23538, 73.84206, 17 | RESULTS, TouchOptionTypes.UP_AND_IN_ASSET_AT_EXPIRY , 74.38596, 74.80159, 18 | RESULTS, TouchOptionTypes.UP_AND_OUT_ASSET_OR_NOTHING , 19.19968, 20.16362, 19 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinEquitySwap_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143027 2 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinEquityVarianceSwap_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143028 2 | HEADER,LABEL,VALUE, 3 | RESULTS,REPLICATION VARIANCE:,0.04467304, 4 | RESULTS,DERMAN SKEW APPROX for K:,0.04235066, 5 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinEquityVolSurface_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143028 2 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinFXAmericanOption_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143028 2 | HEADER,SPOT FX RATE,VALUE_BS,VOL_IN,IMPLD_VOL, 3 | RESULTS,0.50000000,0.00000000,0.00000000,0.00000000, 4 | RESULTS,0.70000000,0.00000000,0.00000000,-0.00000000, 5 | RESULTS,0.90000000,0.00001146,0.00001017,-0.00000130, 6 | RESULTS,1.10000000,0.00488443,0.00491712,0.00003269, 7 | RESULTS,1.30000000,0.07354894,0.07511506,0.00156612, 8 | RESULTS,1.50000000,0.23856280,0.25000000,0.01143720, 9 | RESULTS,1.70000000,0.43066956,0.45000000,0.01933044, 10 | RESULTS,1.90000000,0.62470970,0.65000000,0.02529030, 11 | RESULTS,0.50000000,0.73391462,0.75000000,0.01608538, 12 | RESULTS,0.70000000,0.53982552,0.55000000,0.01017448, 13 | RESULTS,0.90000000,0.34574787,0.35000000,0.00425213, 14 | RESULTS,1.10000000,0.15653173,0.15675231,0.00022058, 15 | RESULTS,1.30000000,0.03110714,0.03111872,0.00001158, 16 | RESULTS,1.50000000,0.00203189,0.00200783,-0.00002405, 17 | RESULTS,1.70000000,0.00004955,0.00004507,-0.00000448, 18 | RESULTS,1.90000000,0.00000058,0.00000043,-0.00000015, 19 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinFXBasketOption_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20210116_214949 2 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinFXCompoundOption_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20210116_214949 2 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinFXDigitalOption_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143034 2 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinFXDoubleDigitalOption_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230810_234149 2 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinFXForward_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143034 2 | HEADER,SPOT FX,FX FWD,VALUE_BS, 3 | RESULTS,1.30000000,1.33875579,{'value': -2.4977970215119303, 'cash_dom': -249.77970215119302, 'cash_for': -192.13823242399462, 'not_dom': 136.5, 'not_for': 100.0, 'ccy_dom': 'USD', 'ccy_for': 'EUR'}, 4 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinFXOneTouchOption_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143038 2 | HEADER,================================= CASH ONLY, 3 | HEADER,TYPE,VALUE,VALUE_MC, 4 | RESULTS, TouchOptionTypes.DOWN_AND_IN_CASH_AT_HIT , 1.01538, 0.98444, 5 | RESULTS, TouchOptionTypes.DOWN_AND_IN_CASH_AT_EXPIRY , 0.97722, 0.94698, 6 | RESULTS, TouchOptionTypes.DOWN_AND_OUT_CASH_OR_NOTHING , 0.44963, 0.47986, 7 | HEADER,TYPE,VALUE,VALUE_MC, 8 | RESULTS, TouchOptionTypes.UP_AND_IN_CASH_AT_HIT , 1.12853, 1.12132, 9 | RESULTS, TouchOptionTypes.UP_AND_IN_CASH_AT_EXPIRY , 1.08667, 1.08004, 10 | RESULTS, TouchOptionTypes.UP_AND_OUT_CASH_OR_NOTHING , 0.34018, 0.34680, 11 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinFXOptionSABR_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143042 2 | HEADER,OPTION,FX_RATE,VALUE_BS,VOL_IN,DIFF, 3 | RESULTS,CALL:, 0.500000,0.0000000,0.0000000,0.0000000, 4 | RESULTS,CALL:, 0.600000,0.0000000,0.0000000,-0.0000000, 5 | RESULTS,CALL:, 0.700000,0.0000000,0.0000000,-0.0000000, 6 | RESULTS,CALL:, 0.800000,0.0000001,0.0000000,-0.0000000, 7 | RESULTS,CALL:, 0.900000,0.0000115,0.0000102,-0.0000013, 8 | RESULTS,CALL:, 1.000000,0.0004200,0.0004126,-0.0000074, 9 | RESULTS,CALL:, 1.100000,0.0048844,0.0049171,0.0000327, 10 | RESULTS,CALL:, 1.200000,0.0251252,0.0254783,0.0003531, 11 | RESULTS,CALL:, 1.300000,0.0735489,0.0751151,0.0015661, 12 | RESULTS,CALL:, 1.400000,0.1486059,0.1534889,0.0048830, 13 | RESULTS,CALL:, 1.500000,0.2385628,0.2500000,0.0114372, 14 | RESULTS,CALL:, 1.600000,0.3339289,0.3500000,0.0160711, 15 | RESULTS,CALL:, 1.700000,0.4306696,0.4500000,0.0193304, 16 | RESULTS,CALL:, 1.800000,0.5276703,0.5500000,0.0223297, 17 | RESULTS,CALL:, 1.900000,0.6247097,0.6500000,0.0252903, 18 | HEADER,OPTION,FX_RATE,VALUE_BS,VOL_IN,DIFF, 19 | RESULTS,PUT:, 0.500000,0.7339146,0.7500000,0.0160854, 20 | RESULTS,PUT:, 0.600000,0.6368701,0.6500000,0.0131299, 21 | RESULTS,PUT:, 0.700000,0.5398255,0.5500000,0.0101745, 22 | RESULTS,PUT:, 0.800000,0.4427810,0.4500000,0.0072190, 23 | RESULTS,PUT:, 0.900000,0.3457479,0.3500000,0.0042521, 24 | RESULTS,PUT:, 1.000000,0.2491119,0.2504124,0.0013005, 25 | RESULTS,PUT:, 1.100000,0.1565317,0.1567523,0.0002206, 26 | RESULTS,PUT:, 1.200000,0.0797279,0.0797675,0.0000396, 27 | RESULTS,PUT:, 1.300000,0.0311071,0.0311187,0.0000116, 28 | RESULTS,PUT:, 1.400000,0.0091196,0.0091228,0.0000033, 29 | RESULTS,PUT:, 1.500000,0.0020319,0.0020078,-0.0000241, 30 | RESULTS,PUT:, 1.600000,0.0003534,0.0003398,-0.0000137, 31 | RESULTS,PUT:, 1.700000,0.0000495,0.0000451,-0.0000045, 32 | RESULTS,PUT:, 1.800000,0.0000058,0.0000049,-0.0000009, 33 | RESULTS,PUT:, 1.900000,0.0000006,0.0000004,-0.0000001, 34 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinFXVolSurfacePlus_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143042 2 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinFXVolSurface_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143042 2 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinFixedIborSwap_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20201013_225205 2 | HEADER,LABEL,DATE,VALUE, 3 | RESULTS,DEPO VALUE:,WED 02 JAN 2019,100.00000000, 4 | RESULTS,FRA VALUE:,SAT 19 JAN 2019,0.00000000, 5 | RESULTS,FRA VALUE:,TUE 19 FEB 2019,-0.00000000, 6 | RESULTS,FRA VALUE:,TUE 19 MAR 2019,0.00000000, 7 | RESULTS,FRA VALUE:,FRI 19 APR 2019,0.00000000, 8 | RESULTS,FRA VALUE:,SUN 19 MAY 2019,-0.00000000, 9 | RESULTS,FRA VALUE:,WED 19 JUN 2019,-0.00000000, 10 | RESULTS,FRA VALUE:,FRI 19 JUL 2019,0.00000000, 11 | RESULTS,FRA VALUE:,MON 19 AUG 2019,-0.00000000, 12 | RESULTS,FRA VALUE:,THU 19 SEP 2019,-0.00000000, 13 | RESULTS,FRA VALUE:,SAT 19 OCT 2019,-0.00000000, 14 | RESULTS,FRA VALUE:,TUE 19 NOV 2019,0.00000000, 15 | RESULTS,FRA VALUE:,THU 19 DEC 2019,0.00000000, 16 | RESULTS,SWAP VALUE:,WED 02 DEC 2020,0.00000000, 17 | RESULTS,SWAP VALUE:,THU 02 DEC 2021,0.00000000, 18 | RESULTS,SWAP VALUE:,FRI 02 DEC 2022,-0.00000000, 19 | RESULTS,SWAP VALUE:,MON 04 DEC 2023,-0.00000000, 20 | RESULTS,SWAP VALUE:,MON 02 DEC 2024,0.00000000, 21 | RESULTS,SWAP VALUE:,TUE 02 DEC 2025,0.00000000, 22 | RESULTS,SWAP VALUE:,WED 02 DEC 2026,0.00000000, 23 | RESULTS,SWAP VALUE:,THU 02 DEC 2027,0.00000000, 24 | RESULTS,SWAP VALUE:,MON 04 DEC 2028,0.00000000, 25 | RESULTS,SWAP VALUE:,MON 03 DEC 2029,0.00000000, 26 | RESULTS,SWAP VALUE:,MON 02 DEC 2030,0.00000000, 27 | RESULTS,SWAP VALUE:,FRI 02 DEC 2033,0.00000000, 28 | RESULTS,SWAP VALUE:,THU 02 DEC 2038,0.00000000, 29 | RESULTS,SWAP VALUE:,WED 02 DEC 2043,0.00000000, 30 | RESULTS,SWAP VALUE:,WED 02 DEC 2048,0.00000000, 31 | RESULTS,SWAP VALUE:,TUE 02 DEC 2053,0.00000000, 32 | RESULTS,SWAP VALUE:,MON 02 DEC 2058,0.00000000, 33 | RESULTS,SWAP VALUE:,MON 03 DEC 2063,0.00000000, 34 | RESULTS,SWAP VALUE:,MON 03 DEC 2068,0.00000000, 35 | HEADER,LABEL,VALUE, 36 | RESULTS,SWAP_VALUE USING ONE_CURVE,394338.06293987, 37 | RESULTS,BLOOMBERG VALUE,388147.00000000, 38 | RESULTS,DIFFERENCE VALUE,-6191.06293987, 39 | HEADER,LABEL,VALUE, 40 | RESULTS,Swap Value on a Notional of $1M:,0.00585365, 41 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinFixedOIRSwap_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20201013_222822 2 | HEADER,LABEL,VALUE, 3 | RESULTS,SWAP_VALUE,40789.45261646, 4 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinIborCapFloor_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143042 2 | HEADER,CORRECT PRICE,MODEL_PRICE, 3 | RESULTS,517.29000000,517.65433399, 4 | HEADER,START,END,VOL,VALUE, 5 | RESULTS, 22-JUN-2020,21-JUN-2021, 20.65552,3044.58678, 6 | RESULTS, 21-JUN-2021,20-JUN-2022, 17.20688,3437.67963, 7 | HEADER,LABEL,VALUE, 8 | RESULTS,CAPLETS->CAP: ,6482.26641160, 9 | HEADER,LABEL,STRIKE,BLK,BLK_SHFTD,SABR,SABR_SHFTD,HW,BACH, 10 | RESULTS,CAP,0.02000000,28889.24449181,28889.24821392,28889.24447951,28889.24448328,82406.60402608,28889.37604382, 11 | RESULTS,CAP,0.03500000,14367.21806435,14412.07118874,14352.40316772,14352.40405498,72894.03577478,14397.77160836, 12 | RESULTS,CAP,0.05000000,1904.96135010,2399.13328036,516.93236951,569.78611166,63709.54243477,1910.00232419, 13 | RESULTS,CAP,0.06500000,93.43477872,244.25095376,0.29373508,1.02913034,58523.57235815,46.70935562, 14 | RESULTS,CAP,0.08000000,3.09232853,21.25854316,0.00227795,0.01871342,53647.59082332,0.15777023, 15 | HEADER,LABEL,STRIKE,BLK,BLK_SHFTD,SABR,SABR_SHFTD,HW,BACH, 16 | RESULTS,FLR,0.02000000,0.00001231,0.00373442,0.00000000,0.00000378,51868.15397914,0.13156431, 17 | RESULTS,FLR,0.03500000,14.81491029,59.66803467,0.00001366,0.00090092,56892.08473900,45.36845430, 18 | RESULTS,FLR,0.05000000,2089.39952148,2583.57145173,701.37054089,754.22428304,62244.09041016,2094.44049557, 19 | RESULTS,FLR,0.06500000,14814.71427554,14965.53045058,14721.57323190,14722.30862716,71594.61934471,14767.98885244, 20 | RESULTS,FLR,0.08000000,29261.21315080,29279.37936543,29258.12310021,29258.13953569,81255.13682104,29258.27859249, 21 | HEADER,LABEL,STRIKE,BLK,BLK_SHFTD,SABR,SABR SHFTD,HW,BACH, 22 | RESULTS,PUT_CALL,0.02000000,28889.24447950,28889.24447950,28889.24447950,28889.24447950,30538.45004694,28889.24447950, 23 | RESULTS,PUT_CALL,0.03500000,14352.40315406,14352.40315406,14352.40315406,14352.40315406,16001.95103578,14352.40315406, 24 | RESULTS,PUT_CALL,0.05000000,-184.43817138,-184.43817138,-184.43817138,-184.43817138,1465.45202461,-184.43817138, 25 | RESULTS,PUT_CALL,0.06500000,-14721.27949682,-14721.27949682,-14721.27949682,-14721.27949682,-13071.04698656,-14721.27949682, 26 | RESULTS,PUT_CALL,0.08000000,-29258.12082226,-29258.12082226,-29258.12082226,-29258.12082226,-27607.54599773,-29258.12082226, 27 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinIborCapVolCurve_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143042 2 | HEADER,DATE,CAPVOL,CAPLETVOL, 3 | RESULTS,01-JAN-2020, 15.500, 15.50, 4 | RESULTS,01-JAN-2021, 15.500, 15.50, 5 | RESULTS,01-JAN-2022, 18.250, 20.64, 6 | RESULTS,01-JAN-2023, 17.910, 17.21, 7 | RESULTS,01-JAN-2024, 17.740, 17.22, 8 | RESULTS,01-JAN-2025, 17.270, 15.25, 9 | RESULTS,01-JAN-2026, 16.790, 14.15, 10 | RESULTS,01-JAN-2027, 16.300, 12.98, 11 | RESULTS,01-JAN-2028, 16.010, 13.81, 12 | RESULTS,01-JAN-2029, 15.760, 13.60, 13 | RESULTS,01-JAN-2030, 15.540, 13.40, 14 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinIborDualCurve_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143042 2 | BANNER,====================================================== 3 | BANNER,SINGLE CURVE VALUATION 4 | HEADER,LABEL,VALUE, 5 | RESULTS,VALUE:,-0.00000450, 6 | RESULTS,FIXED:,-53707.66672110, 7 | RESULTS,FLOAT:,53707.66671660, 8 | BANNER,====================================================== 9 | BANNER,SINGLE CURVE VALUATION TO SWAP SETTLEMENT DATE 10 | HEADER,LABEL,VALUE, 11 | RESULTS,VALUE:,-0.00000450, 12 | RESULTS,FIXED:,-53714.55068289, 13 | RESULTS,FLOAT:,53714.55067839, 14 | BANNER,====================================================== 15 | HEADER,VALUATION TO TODAY DATE, PV, 16 | RESULTS,VALUE:,0.00000000, 17 | RESULTS,FIXED:,-55524.56419682, 18 | RESULTS,FLOAT:,55401.71888978, 19 | HEADER,VALUATION TO SWAP SETTLEMENT DATE, PV, 20 | RESULTS,VALUE:,0.00000000, 21 | RESULTS,FIXED:,-55524.57089412, 22 | RESULTS,FLOAT:,55524.57089412, 23 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinIborLMMProducts_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143043 2 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinIborSingleCurve_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143043 2 | HEADER,VALUATION TO TODAY DATE, PV, 3 | RESULTS,VALUE:,-0.00000450, 4 | RESULTS,FIXED:,53707.66672110, 5 | RESULTS,FLOAT:,53707.66671660, 6 | HEADER,VALUATION TO SWAP SETTLEMENT DATE, PV, 7 | RESULTS,VALUE:,-0.00000450, 8 | RESULTS,FIXED:,53714.55068289, 9 | RESULTS,FLOAT:,53714.55067839, 10 | HEADER,METHOD,TIME, 11 | RESULTS,NON-LINEAR SOLVER BOOTSTRAP,0.06679995, 12 | RESULTS,LINEAR SWAP BOOTSTRAP,0.06602092, 13 | HEADER,LABEL,DATE,VALUE, 14 | RESULTS,DEPO,23-MAR-2018,100.00000000, 15 | RESULTS,DEPO,23-APR-2018,100.00000000, 16 | RESULTS,DEPO,23-AUG-2018,100.00000000, 17 | RESULTS,DEPO,25-FEB-2019,100.00000000, 18 | HEADER,DATE,MATDATE,VALUE, 19 | RESULTS,FRA:,23-JUN-2018,0.00000000, 20 | RESULTS,FRA:,23-SEP-2018,0.00000000, 21 | HEADER,SETTLEMENT DATE,DF, 22 | RESULTS,18-SEP-2019,1.00000000, 23 | HEADER,DATE,DF, 24 | RESULTS,18-OCT-2019,0.99585062, 25 | RESULTS,18-NOV-2019,0.99173554, 26 | RESULTS,18-DEC-2019,0.98765432, 27 | RESULTS,18-MAR-2020,0.97563743, 28 | RESULTS,18-JUN-2020,0.96391406, 29 | RESULTS,18-SEP-2020,0.95246937, 30 | RESULTS,19-SEP-2022,0.86176535, 31 | RESULTS,18-SEP-2023,0.82035038, 32 | RESULTS,18-SEP-2024,0.78071732, 33 | RESULTS,18-SEP-2025,0.74309761, 34 | RESULTS,18-SEP-2026,0.70729099, 35 | RESULTS,20-SEP-2027,0.67302985, 36 | RESULTS,18-SEP-2028,0.64068542, 37 | RESULTS,18-SEP-2029,0.60981331, 38 | RESULTS,18-SEP-2030,0.58042907, 39 | RESULTS,18-SEP-2031,0.55246074, 40 | RESULTS,18-SEP-2034,0.47631942, 41 | RESULTS,19-SEP-2039,0.37199888, 42 | RESULTS,19-SEP-2044,0.29052660, 43 | RESULTS,20-SEP-2049,0.22689908, 44 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinIborSwap_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143045 2 | HEADER,LABEL,DATE,VALUE, 3 | RESULTS,DEPO VALUE:,02-JAN-2019,100.00000000, 4 | RESULTS,FRA VALUE:,19-JAN-2019,0.00000000, 5 | RESULTS,FRA VALUE:,19-FEB-2019,-0.00000000, 6 | RESULTS,FRA VALUE:,19-MAR-2019,0.00000000, 7 | RESULTS,FRA VALUE:,19-APR-2019,-0.00000000, 8 | RESULTS,FRA VALUE:,19-MAY-2019,0.00000000, 9 | RESULTS,FRA VALUE:,19-JUN-2019,-0.00000000, 10 | RESULTS,FRA VALUE:,19-JUL-2019,-0.00000000, 11 | RESULTS,FRA VALUE:,19-AUG-2019,-0.00000000, 12 | RESULTS,FRA VALUE:,19-SEP-2019,-0.00000000, 13 | RESULTS,FRA VALUE:,19-OCT-2019,0.00000000, 14 | RESULTS,FRA VALUE:,19-NOV-2019,-0.00000000, 15 | RESULTS,FRA VALUE:,19-DEC-2019,0.00000000, 16 | RESULTS,SWAP VALUE:,02-DEC-2020,0.00000000, 17 | RESULTS,SWAP VALUE:,02-DEC-2021,-0.00000003, 18 | RESULTS,SWAP VALUE:,02-DEC-2022,-0.00000043, 19 | RESULTS,SWAP VALUE:,04-DEC-2023,-0.00000117, 20 | RESULTS,SWAP VALUE:,02-DEC-2024,-0.00000993, 21 | RESULTS,SWAP VALUE:,02-DEC-2025,-0.00001835, 22 | RESULTS,SWAP VALUE:,02-DEC-2026,-0.00002708, 23 | RESULTS,SWAP VALUE:,02-DEC-2027,-0.00003827, 24 | RESULTS,SWAP VALUE:,04-DEC-2028,-0.00009182, 25 | RESULTS,SWAP VALUE:,03-DEC-2029,0.00000000, 26 | RESULTS,SWAP VALUE:,02-DEC-2030,0.00000000, 27 | RESULTS,SWAP VALUE:,02-DEC-2033,-0.00000000, 28 | RESULTS,SWAP VALUE:,02-DEC-2038,-0.00000002, 29 | RESULTS,SWAP VALUE:,02-DEC-2043,-0.00000001, 30 | RESULTS,SWAP VALUE:,02-DEC-2048,-0.00000001, 31 | RESULTS,SWAP VALUE:,02-DEC-2053,-0.00000001, 32 | RESULTS,SWAP VALUE:,02-DEC-2058,-0.00000001, 33 | RESULTS,SWAP VALUE:,03-DEC-2063,-0.00000000, 34 | RESULTS,SWAP VALUE:,03-DEC-2068,-0.00000002, 35 | HEADER,LABEL,VALUE, 36 | RESULTS,SWAP_VALUE USING ONE_CURVE,318901.60149235, 37 | RESULTS,BLOOMBERG VALUE,388147.00000000, 38 | RESULTS,DIFFERENCE VALUE,69245.39850765, 39 | HEADER,LABEL,VALUE, 40 | RESULTS,Swap Value on a Notional of $1M:,785.30005662, 41 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinInflationBond_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20240731_184358 2 | BANNER,BLOOMBERG US TIPS EXAMPLE 3 | HEADER,FIELD,VALUE, 4 | RESULTS,Current Yield = ,0.01201518, 5 | RESULTS,UK DMO REAL Yield To Maturity = ,-0.00100000, 6 | RESULTS,US STREET REAL Yield To Maturity = ,-0.00100000, 7 | RESULTS,US TREASURY REAL Yield To Maturity = ,-0.00100000, 8 | RESULTS,Dirty Price from REAL YTM = ,104.05540085, 9 | RESULTS,Clean Price from Real YTM = ,104.03502041, 10 | RESULTS,Accrued Days = ,6.00000000, 11 | RESULTS,REAL Accrued Interest = ,0.02038043, 12 | RESULTS,Clean Price from Real YTM = ,104.03502041, 13 | RESULTS,Inflation Accrued = ,0.02286377, 14 | RESULTS,Flat Price from Real YTM = ,116.69230692, 15 | RESULTS,Inflation Principal = ,116.73423825, 16 | RESULTS,Dollar Duration = ,305.92972171, 17 | RESULTS,Modified Duration = ,2.94006577, 18 | RESULTS,Macauley Duration = ,2.93859573, 19 | RESULTS,Convexity = ,0.10195467, 20 | BANNER,============================= 21 | BANNER,QUANT FINANCE US TIPS EXAMPLE 22 | BANNER,============================= 23 | HEADER,FIELD,VALUE, 24 | RESULTS,Current Yield = ,0.00120152, 25 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinInflationIndexCurve_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143046 2 | HEADER,LABEL,VALUE, 3 | RESULTS,22-JUL-2008,216.04845161, 4 | RESULTS,22-JUL-2008,1.03127500, 5 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinInterpolatedForwards_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143046 2 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinLossDbnBuilder_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143046 2 | HEADER,BETA,BUILDER,LOSS0,LOSS1,LOSS2,LOSS3,TIME, 3 | RESULTS,0.00000000,FULL_GCD,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000, 4 | RESULTS,0.00000000,ADJ_BIN,0.00000000,0.00000000,0.00000000,0.00000000,0.00000000, 5 | RESULTS,0.10000000,FULL_GCD,0.00000000,0.00000000,0.00000000,0.00000000,0.00394678, 6 | RESULTS,0.10000000,ADJ_BIN,0.00000000,0.00000000,0.00000000,0.00000000,0.00087428, 7 | RESULTS,0.20000000,FULL_GCD,0.00000000,0.00000003,0.00000015,0.00000065,0.00054002, 8 | RESULTS,0.20000000,ADJ_BIN,0.00000000,0.00000003,0.00000015,0.00000065,0.00000000, 9 | RESULTS,0.30000000,FULL_GCD,0.00000238,0.00001371,0.00004520,0.00011204,0.00000000, 10 | RESULTS,0.30000000,ADJ_BIN,0.00000238,0.00001371,0.00004520,0.00011204,0.00000000, 11 | RESULTS,0.40000000,FULL_GCD,0.00013849,0.00045649,0.00095543,0.00161966,0.00000000, 12 | RESULTS,0.40000000,ADJ_BIN,0.00013849,0.00045649,0.00095543,0.00161966,0.00000000, 13 | RESULTS,0.50000000,FULL_GCD,0.00184069,0.00370584,0.00543777,0.00701166,0.00000000, 14 | RESULTS,0.50000000,ADJ_BIN,0.00184069,0.00370584,0.00543777,0.00701166,0.00000000, 15 | RESULTS,0.60000000,FULL_GCD,0.01088602,0.01372330,0.01513831,0.01591002,0.00635648, 16 | RESULTS,0.60000000,ADJ_BIN,0.01088602,0.01372330,0.01513831,0.01591002,0.00000000, 17 | RESULTS,0.70000000,FULL_GCD,0.03998436,0.03107888,0.02744729,0.02516264,0.00000000, 18 | RESULTS,0.70000000,ADJ_BIN,0.03998436,0.03107888,0.02744729,0.02516264,0.00000000, 19 | RESULTS,0.80000000,FULL_GCD,0.11013214,0.04811336,0.03408983,0.03174249,0.00000000, 20 | RESULTS,0.80000000,ADJ_BIN,0.11013214,0.04811336,0.03408983,0.03174249,0.00000000, 21 | RESULTS,0.00000000,ADJ_BIN,0.00285681,0.00282447,0.00484487,0.00538236,0.00000000, 22 | RESULTS,0.00000000,ADJ_BIN,0.00285681,0.00564893,0.00816410,0.01038737,0.00000000, 23 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinMathAccruedInterp_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143046 2 | HEADER,VALUE, 3 | RESULTS,[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.008691022311649949, 0.017420288315911765, 0.026149555018595207, 0.00026633599813865054, 0.008950803245226789, 0.017635270492314867, 0.02631973704456575, 0.03500420429165389, 0.0], 4 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinModelBlackScholes_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143046 2 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinModelBlack_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143046 2 | HEADER,ITEM,CALL,PUT, 3 | RESULTS,VALUE,0.00045992,0.01645992, 4 | RESULTS,DELTA,0.11083470,-0.88916530, 5 | RESULTS,GAMMA,19.65938047,19.65938047, 6 | RESULTS,THETA,-0.00045452,-0.00045452, 7 | RESULTS,VEGA,0.00909050,0.00909050, 8 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinModelBlack_SABR_HW_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143046 2 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinModelCIR_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143046 2 | HEADER,MATURITY,TIME,FORMULA,EULER,LOGNORM,MILSTEIN,KJ,EXACT, 3 | RESULTS,0.00000000,0.00000000,1.00000000,1.00000000,1.00000000,1.00000000,1.00000000,1.00000000, 4 | RESULTS,0.50000000,0.00688148,0.97534757,0.97621921,0.97623013,0.97622204,0.97621937,0.97631837, 5 | RESULTS,1.00000000,0.01389837,0.95150115,0.95207034,0.95213488,0.95210026,0.95208067,0.95281997, 6 | RESULTS,1.50000000,0.02092838,0.92856957,0.92872537,0.92868976,0.92869639,0.92864714,0.92909750, 7 | RESULTS,2.00000000,0.02762651,0.90659982,0.90512382,0.90526700,0.90517777,0.90509699,0.90733366, 8 | RESULTS,2.50000000,0.03473854,0.88559399,0.88307894,0.88307117,0.88304023,0.88291258,0.88748017, 9 | RESULTS,3.00000000,0.04125547,0.86552351,0.86092490,0.86066752,0.86071196,0.86053331,0.86498441, 10 | RESULTS,3.50000000,0.04789042,0.84634049,0.84206415,0.84175615,0.84191396,0.84165266,0.84842269, 11 | RESULTS,4.00000000,0.05352998,0.82798632,0.82246165,0.82244932,0.82248211,0.82212897,0.82842060, 12 | RESULTS,4.50000000,0.05711722,0.81039791,0.80677618,0.80711516,0.80702490,0.80661816,0.80957838, 13 | RESULTS,5.00000000,0.07552409,0.79351192,0.79127392,0.79124101,0.79142291,0.79089593,0.79217801, 14 | RESULTS,5.50000000,0.06942105,0.77726757,0.77336874,0.77230089,0.77289927,0.77234254,0.77821597, 15 | RESULTS,6.00000000,0.08346105,0.76160824,0.75724563,0.75730166,0.75710109,0.75652486,0.76274584, 16 | RESULTS,6.50000000,0.10313416,0.74648231,0.74152058,0.74104579,0.74135343,0.74066375,0.74415979, 17 | RESULTS,7.00000000,0.09015989,0.73184348,0.72103622,0.72152480,0.72151346,0.72077177,0.72885319, 18 | RESULTS,7.50000000,0.10424900,0.71765067,0.70949507,0.70954919,0.70965269,0.70883536,0.71852908, 19 | RESULTS,8.00000000,0.11726618,0.70386773,0.69645528,0.69691469,0.69670973,0.69589669,0.70867289, 20 | RESULTS,8.50000000,0.11238766,0.69046305,0.68682620,0.68707191,0.68732563,0.68635644,0.69597567, 21 | RESULTS,9.00000000,0.12293649,0.67740912,0.67083371,0.67103194,0.67109929,0.67006471,0.67395472, 22 | RESULTS,9.50000000,0.14797759,0.66468197,0.65931635,0.65971995,0.65969401,0.65859019,0.66494877, 23 | RESULTS,10.00000000,0.13018513,0.65226084,0.64923183,0.64991162,0.65013777,0.64899378,0.65569557, 24 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinModelMerton_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143050 2 | HEADER,MERTON MARKET MODEL,VALUE, 3 | RESULTS,ASSET VALUE,[6.42098297 6.01092687 7.30630268 5.99055699 6.3231438 ], 4 | RESULTS,EQUITY VALUE,[2.6406 2.6817 3.977 2.947 2.528 ], 5 | RESULTS,DEBT VALUE,[3.7803834 3.32922679 3.32930268 3.04355679 3.79514391], 6 | RESULTS,ASSET VOLATILITY,[0.30096715 0.17533526 0.1698839 0.22626183 0.25109488], 7 | RESULTS,EQUITY VOL,[0.7103 0.3929 0.3121 0.4595 0.6181], 8 | RESULTS,CREDIT SPREAD,[6.46892742e-03 2.28875552e-05 9.30381978e-08 1.23981005e-04 9 | 2.57202875e-03], 10 | RESULTS,LEVERAGE,[1.60524574 1.71740768 2.08751505 1.87204906 1.58078595], 11 | RESULTS,PROD DEFAULT,[6.37907587e-02 7.67718957e-04 4.71700046e-06 2.62226986e-03 12 | 3.44082691e-02], 13 | HEADER,BASIC MERTON MODEL,VALUE, 14 | RESULTS,ASSET VALUE,[6.42098297 6.01092687 7.30630268 5.99055699 6.3231438 ], 15 | RESULTS,EQUITY VALUE,[2.64059957 2.68170008 3.977 2.9470002 2.52799989], 16 | RESULTS,DEBT VALUE,[3.7803834 3.32922679 3.32930268 3.04355679 3.79514391], 17 | RESULTS,ASSET VOLATILITY,[0.30096715 0.17533526 0.1698839 0.22626183 0.25109488], 18 | RESULTS,EQUITY VOL,[0.71030005 0.39289999 0.31209999 0.45949999 0.61809997], 19 | RESULTS,CREDIT SPREAD,[6.46892742e-03 2.28875552e-05 9.30381978e-08 1.23981005e-04 20 | 2.57202875e-03], 21 | RESULTS,LEVERAGE,[1.60524574 1.71740768 2.08751505 1.87204906 1.58078595], 22 | RESULTS,PROD DEFAULT,[6.37907587e-02 7.67718957e-04 4.71700046e-06 2.62226986e-03 23 | 3.44082691e-02], 24 | RESULTS,DISTANCE DEFAULT,[1.52370861 3.16790101 4.42975544 2.79161697 1.81962233], 25 | HEADER,BASIC MERTON MODEL,VALUE, 26 | RESULTS,ASSET VALUE,140.0, 27 | RESULTS,EQUITY VALUE,45.11060979, 28 | RESULTS,DEBT VALUE,94.88939021, 29 | RESULTS,ASSET VOLATILITY,0.2, 30 | RESULTS,EQUITY VOL,0.60762558, 31 | RESULTS,CREDIT SPREAD,24.58286316, 32 | RESULTS,LEVERAGE,1.40000000, 33 | RESULTS,PROD DEFAULT,0.03344881, 34 | RESULTS,DISTANCE DEFAULT,1.83236118, 35 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinModelRatesBK_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143051 2 | BANNER,=== HULL INITIAL EXAMPLE SECTION 28.7 ED 6 PG 668 ==== 3 | HEADER,LABEL,VALUE, 4 | RESULTS,QTREE,[[0. 0. 1. 0. 0. ] 5 | [0. 0.16382955 0.65531819 0.16382955 0. ] 6 | [0.01898617 0.21257665 0.50091503 0.21121891 0.01874207] 7 | [0.04070894 0.21932843 0.42317527 0.21640346 0.03949609] 8 | [0.0598431 0.21180704 0.37752965 0.20750273 0.05692575]], 9 | RESULTS,RTREE,[[0. 0. 0.03430719 0. 0. ] 10 | [0. 0.03058812 0.04155168 0.05644484 0. ] 11 | [0.02586744 0.03513898 0.04773367 0.06484262 0.08808384] 12 | [0.02879013 0.03910923 0.05312696 0.072169 0.09803618] 13 | [0. 0. 0. 0. 0. ]], 14 | RESULTS,PU AT LAST TIME,[0.08081043 0.22777795 0.16666667 0.11767749 0.86060952], 15 | RESULTS,PDM AT LAST TIME,[0.05858005 0.65454456 0.66666667 0.65454456 0.05858005], 16 | RESULTS,PD AT LAST TIME,[0.86060952 0.11767749 0.16666667 0.22777795 0.08081043], 17 | HEADER,LABEL,VALUE, 18 | RESULTS,Fixed Income Price:,99.54204787, 19 | HEADER,time_steps,TIME,VALUE, 20 | RESULTS,100,0.00000000,{'call': 0.7011136881889506, 'put': 7.960524204024168}, 21 | RESULTS,200,0.00094414,{'call': 0.699814792845399, 'put': 7.960524137262581}, 22 | RESULTS,300,0.00000000,{'call': 0.6864947372769393, 'put': 7.960524114743592}, 23 | RESULTS,500,0.01370382,{'call': 0.6922247266590768, 'put': 7.960524080947081}, 24 | RESULTS,1000,0.04786539,{'call': 0.6946099807812406, 'put': 7.960523663904297}, 25 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinModelRatesLMM_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143051 2 | HEADER,COMMENTS,VALUES, 3 | BANNER,Ratchet ONE FACTOR IMPLEMENTATION 4 | RESULTS,FINANCEPY GETS:,[0. 0.19416301 0.20566708 0.20134505 0.19417154 0.1872349 5 | 0.17975222 0.17239495 0.16624589 0.15955793 0.15313157], 6 | RESULTS,HULL GETS:,[0. 0.196 0.207 0.201 0.194 0.187 0.189 0.172 0.167 0.16 0.153], 7 | BANNER,STICKY CAPLETS ONE FACTOR IMPLEMENTATION 8 | RESULTS,FINANCEPY GETS:,[0. 0.19416301 0.33388521 0.41060374 0.45813348 0.48470596 9 | 0.49779326 0.5015095 0.49996354 0.49454323 0.48645804], 10 | RESULTS,HULL GETS:,[0.0, 0.196, 0.336, 0.412, 0.458, 0.484, 0.498, 0.502, 0.501, 0.497, 0.488], 11 | BANNER,RATCHET - NUM FACTORS 1F 12 | RESULTS,FINANCEPY GETS:,[0. 0.19416301 0.20568746 0.20137193 0.19419716 0.18725571 13 | 0.1797732 0.17241518 0.1662614 0.15957538 0.15314754], 14 | RESULTS,HULL GETS:,[0.0, 0.196, 0.207, 0.201, 0.194, 0.187, 0.189, 0.172, 0.167, 0.16, 0.153], 15 | BANNER,STICKY RATCHET - NUM FACTORS 1 16 | RESULTS,FINANCEPY GETS:,[0. 0.19416301 0.33391875 0.41064963 0.45818544 0.48476413 17 | 0.49785592 0.50157564 0.50002888 0.49461167 0.48652723], 18 | RESULTS,HULL GETS:,[0.0, 0.196, 0.336, 0.412, 0.458, 0.484, 0.498, 0.502, 0.501, 0.497, 0.488], 19 | BANNER,RATCHET - NUM FACTORS:2 20 | RESULTS,FINANCEPY GETS:,[0. 0.19426335 0.2072705 0.20468533 0.19896482 0.19320108 21 | 0.1866015 0.17976072 0.17393754 0.16746863 0.16130014], 22 | RESULTS,HULL GETS:,[0.0, 0.194, 0.207, 0.205, 0.198, 0.193, 0.189, 0.18, 0.174, 0.168, 0.162], 23 | BANNER,STICKY RATCHET - NUM FACTORS:2 24 | RESULTS,FINANCEPY GETS:,[0. 0.19426335 0.33485572 0.41337429 0.4638572 0.4940203 25 | 0.51120847 0.51923694 0.52236199 0.52172775 0.51795547], 26 | RESULTS,HULL GETS:,[0.0, 0.196, 0.334, 0.413, 0.462, 0.492, 0.512, 0.52, 0.523, 0.523, 0.519], 27 | BANNER,RATCHET - NUM FACTORS:3 28 | RESULTS,FINANCEPY GETS:,[0. 0.19421003 0.20883823 0.20829442 0.20424068 0.19978832 29 | 0.19394328 0.18771726 0.18230354 0.1761402 0.16976085], 30 | RESULTS,HULL GETS:,[0.0, 0.194, 0.207, 0.205, 0.198, 0.193, 0.189, 0.18, 0.174, 0.168, 0.162], 31 | BANNER,STICKY RATCHET - NUM FACTORS:3 32 | RESULTS,FINANCEPY GETS:,[0. 0.19421003 0.33571793 0.41626747 0.47001947 0.5039211 33 | 0.52307641 0.53276693 0.53765529 0.53849857 0.53644049], 34 | RESULTS,HULL GETS:,[0.0, 0.195, 0.336, 0.418, 0.472, 0.506, 0.524, 0.533, 0.537, 0.537, 0.534], 35 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinModelSABR_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143101 2 | HEADER,ALPHA,BETA,RHO,VOL, 3 | RESULTS,0.10000000,0.50000000,-0.80000000,0.44510068, 4 | RESULTS,0.10000000,0.50000000,0.00000000,0.47026174, 5 | RESULTS,0.10000000,0.50000000,0.80000000,0.48866521, 6 | RESULTS,0.10000000,1.00000000,-0.80000000,0.08685875, 7 | RESULTS,0.10000000,1.00000000,0.00000000,0.10237368, 8 | RESULTS,0.10000000,1.00000000,0.80000000,0.11362353, 9 | RESULTS,0.10000000,2.00000000,-0.80000000,0.00771773, 10 | RESULTS,0.10000000,2.00000000,0.00000000,0.01217822, 11 | RESULTS,0.10000000,2.00000000,0.80000000,0.01482261, 12 | RESULTS,0.20000000,0.50000000,-0.80000000,0.89713164, 13 | RESULTS,0.20000000,0.50000000,0.00000000,0.95249970, 14 | RESULTS,0.20000000,0.50000000,0.80000000,0.99539397, 15 | RESULTS,0.20000000,1.00000000,-0.80000000,0.18430715, 16 | RESULTS,0.20000000,1.00000000,0.00000000,0.20230621, 17 | RESULTS,0.20000000,1.00000000,0.80000000,0.21631162, 18 | RESULTS,0.20000000,2.00000000,-0.80000000,0.00965335, 19 | RESULTS,0.20000000,2.00000000,0.00000000,0.01642762, 20 | RESULTS,0.20000000,2.00000000,0.80000000,0.02048364, 21 | RESULTS,0.30000000,0.50000000,-0.80000000,1.35597958, 22 | RESULTS,0.30000000,0.50000000,0.00000000,1.45989684, 23 | RESULTS,0.30000000,0.50000000,0.80000000,1.54539213, 24 | RESULTS,0.30000000,1.00000000,-0.80000000,0.28021111, 25 | RESULTS,0.30000000,1.00000000,0.00000000,0.30276465, 26 | RESULTS,0.30000000,1.00000000,0.80000000,0.32065048, 27 | RESULTS,0.30000000,2.00000000,-0.80000000,0.01157207, 28 | RESULTS,0.30000000,2.00000000,0.00000000,0.02043910, 29 | RESULTS,0.30000000,2.00000000,0.80000000,0.02563790, 30 | HEADER,TEST,CALIBRATION ERROR, 31 | RESULTS,LOGNORMAL CASE,0.00000000, 32 | RESULTS,SABR CASE,0.00000000, 33 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinModelShiftedSABR_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143101 2 | HEADER,TEST,CALIBRATION ERROR, 3 | RESULTS,LOGNORMAL CASE,0.00000000, 4 | RESULTS,SABR CASE,0.00000001, 5 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinNumbaNumpySpeed_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143101 2 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinOIRSwap_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20201013_114307 2 | HEADER,LABEL,VALUE, 3 | RESULTS,SWAP_VALUE,-35534.43367127, 4 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinOISCurve_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143101 2 | HEADER,VALUATION TO TODAY DATE, PV, 3 | RESULTS,VALUE:,-0.00000449, 4 | RESULTS,FIXED:,53708.27804888, 5 | RESULTS,FLOAT:,53708.27804438, 6 | HEADER,VALUATION TO SWAP SETTLEMENT DATE, PV, 7 | RESULTS,VALUE:,-0.00000449, 8 | RESULTS,FIXED:,53714.30200912, 9 | RESULTS,FLOAT:,53714.30200462, 10 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinOISSingleCurve_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20201015_183506 2 | HEADER,VALUATION TO TODAY DATE, PV, 3 | RESULTS,VALUE:,-0.00000000, 4 | RESULTS,FIXED:,53707.36262580, 5 | RESULTS,FLOAT:,53707.36262580, 6 | HEADER,VALUATION TO SWAP SETTLEMENT DATE, PV, 7 | RESULTS,VALUE:,-0.00000000, 8 | RESULTS,FIXED:,53714.30206665, 9 | RESULTS,FLOAT:,53714.30206665, 10 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinOIS_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143101 2 | HEADER,LABEL,VALUE, 3 | RESULTS,SWAP_VALUE,43915.60192636, 4 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinOptionImpliedDbn_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143101 2 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinOvernightIndexSwap_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20201012_135125 2 | HEADER,LABEL,VALUE, 3 | RESULTS,SWAP_VALUE,-35534.43367127, 4 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinPieceCurve_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143101 2 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinProcessSimulator_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143101 2 | BANNER,######################## GBM NORMAL ############################### 3 | HEADER,PROCESS,TIME, 4 | RESULTS,GBM NORMAL,0.07077622, 5 | BANNER,######################## GBM ANTITHETIC ########################### 6 | RESULTS,GBM ANTITHETIC,0.09690809, 7 | BANNER,###################### HESTON EULER ############################### 8 | RESULTS,HESTON EULER,0.11363363, 9 | BANNER,###################### HESTON EULERLOG ############################ 10 | RESULTS,HESTON EULERLOG,0.12326646, 11 | BANNER,###################### HESTON QUADEXP ############################# 12 | RESULTS,HESTON QUADEXP,0.20139360, 13 | BANNER,######################## VASICEK NORMAL ########################### 14 | RESULTS,VASICEK_NORMAL,0.05554318, 15 | BANNER,####################### VASICEK ANTITHETIC ######################## 16 | RESULTS,VASICEK_NORMAL ANTI,0.05823064, 17 | BANNER,############################# CIR ################################# 18 | RESULTS,CIR,0.06811237, 19 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinSobol_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143102 2 | HEADER,LABEL,TIME, 3 | RESULTS,Average time taken,0.00006980, 4 | RESULTS,Average time taken,0.00018441, 5 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinStatistics_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143102 2 | HEADER,l,Mean,SD, 3 | RESULTS,0,0.00166471,1.00057817, 4 | RESULTS,1,0.00166471,1.00057817, 5 | RESULTS,2,0.00166471,1.00057817, 6 | RESULTS,3,0.00166471,1.00057817, 7 | RESULTS,4,0.00166471,1.00057817, 8 | RESULTS,5,0.00166471,1.00057817, 9 | RESULTS,6,0.00166471,1.00057817, 10 | RESULTS,7,0.00166471,1.00057817, 11 | RESULTS,8,0.00166471,1.00057817, 12 | RESULTS,9,0.00166471,1.00057817, 13 | HEADER,Corr,Measured, 14 | RESULTS,0.00000000,-0.00025640, 15 | RESULTS,0.10000000,0.09974093, 16 | RESULTS,0.20000000,0.19974620, 17 | RESULTS,0.30000000,0.29975947, 18 | RESULTS,0.40000000,0.39978051, 19 | RESULTS,0.50000000,0.49980880, 20 | RESULTS,0.60000000,0.59984347, 21 | RESULTS,0.70000000,0.69988314, 22 | RESULTS,0.80000000,0.79992569, 23 | RESULTS,0.90000000,0.89996753, 24 | RESULTS,1.00000000,1.00000000, 25 | HEADER,TIME, 26 | RESULTS,0.27864456, 27 | HEADER,l,Mean,SD, 28 | RESULTS,0,0.00166471,1.00057817, 29 | RESULTS,1,0.00166471,1.00057817, 30 | RESULTS,2,0.00166471,1.00057817, 31 | RESULTS,3,0.00166471,1.00057817, 32 | RESULTS,4,0.00166471,1.00057817, 33 | RESULTS,5,0.00166471,1.00057817, 34 | RESULTS,6,0.00166471,1.00057817, 35 | RESULTS,7,0.00166471,1.00057817, 36 | RESULTS,8,0.00166471,1.00057817, 37 | RESULTS,9,0.00166471,1.00057817, 38 | HEADER,TIME, 39 | RESULTS,0.02770853, 40 | HEADER,Corr,Measured, 41 | RESULTS,0.00000000,-0.00025640, 42 | RESULTS,0.10000000,0.09974093, 43 | RESULTS,0.20000000,0.19974620, 44 | RESULTS,0.30000000,0.29975947, 45 | RESULTS,0.40000000,0.39978051, 46 | RESULTS,0.50000000,0.49980880, 47 | RESULTS,0.60000000,0.59984347, 48 | RESULTS,0.70000000,0.69988314, 49 | RESULTS,0.80000000,0.79992569, 50 | RESULTS,0.90000000,0.89996753, 51 | RESULTS,1.00000000,1.00000000, 52 | HEADER,TIME, 53 | RESULTS,0.18030405, 54 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinSwapLegs_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143103 2 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinSwaptionVolSurface_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143103 2 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinVasicekRateModel_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143103 2 | HEADER,TIME,T,P,P_MC,P_MC2, 3 | RESULTS,0.00099921,0.00000000,1.00000000,1.00000000,1.00000000, 4 | RESULTS,0.00997210,0.50000000,0.97535885,0.97465275,0.97527233, 5 | RESULTS,0.01634479,1.00000000,0.95159745,0.95040094,0.95136247, 6 | RESULTS,0.02859831,1.50000000,0.92891184,0.92619701,0.92865358, 7 | RESULTS,0.03412962,2.00000000,0.90744425,0.90278928,0.90673229, 8 | RESULTS,0.04304695,2.50000000,0.88729328,0.88220920,0.88713728, 9 | RESULTS,0.04735994,3.00000000,0.86852256,0.86039270,0.86764704, 10 | RESULTS,0.05549264,3.50000000,0.85116814,0.83970966,0.85011573, 11 | RESULTS,0.05552030,4.00000000,0.83524475,0.82624221,0.83361110, 12 | RESULTS,0.07650185,4.50000000,0.82075087,0.81498731,0.82047127, 13 | RESULTS,0.07415533,5.00000000,0.80767300,0.80415662,0.80580747, 14 | RESULTS,0.07636619,5.50000000,0.79598901,0.78980023,0.79609920, 15 | RESULTS,0.08410811,6.00000000,0.78567089,0.77142253,0.78230881, 16 | RESULTS,0.09728122,6.50000000,0.77668693,0.77466881,0.77930949, 17 | RESULTS,0.11207700,7.00000000,0.76900343,0.75933176,0.76457561, 18 | RESULTS,0.11243367,7.50000000,0.76258602,0.75671282,0.76199310, 19 | RESULTS,0.11600208,8.00000000,0.75740064,0.74886298,0.74846002, 20 | RESULTS,0.12392926,8.50000000,0.75341440,0.75036005,0.75151008, 21 | RESULTS,0.13198280,9.00000000,0.75059605,0.73353362,0.74311123, 22 | RESULTS,0.13807487,9.50000000,0.74891647,0.75232611,0.74401754, 23 | RESULTS,0.14610910,10.00000000,0.74834891,0.73924343,0.74714816, 24 | -------------------------------------------------------------------------------- /golden_tests/golden/TestFinVolatilityCurve_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20230823_143104 2 | -------------------------------------------------------------------------------- /golden_tests/golden/testfingbmprocess_GOLDEN.testLog: -------------------------------------------------------------------------------- 1 | File Created on:20240731_183554 2 | -------------------------------------------------------------------------------- /images/logo.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/domokane/FinancePy/7ca2a16354076cad672c03add5c3fb444159223b/images/logo.jpg -------------------------------------------------------------------------------- /mkdocs.yml: -------------------------------------------------------------------------------- 1 | site_name: financepy 2 | 3 | theme: 4 | name: readthedocs 5 | 6 | plugins: 7 | - search 8 | - mkdocstrings 9 | - gen-files: 10 | scripts: 11 | - docs/generate.py -------------------------------------------------------------------------------- /notebooks/README.md: -------------------------------------------------------------------------------- 1 | # Using FinancePy in a Jupyter Notebook 2 | 3 | Once financepy has been installed, it is easy to get started. 4 | 5 | Just download the project and examine the set of Jupyter Notebooks in this notebooks folder. 6 | 7 | These have been organised according to the same directory structure as the project. 8 | 9 | A pdf manual describing all of the functions can be found in the project directory. 10 | -------------------------------------------------------------------------------- /notebooks/cleanErrors.bat: -------------------------------------------------------------------------------- 1 | del /S ERROR_*.ipynb 2 | -------------------------------------------------------------------------------- /notebooks/products/bonds/data/Key_rate_duration_US91282CFB28.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/domokane/FinancePy/7ca2a16354076cad672c03add5c3fb444159223b/notebooks/products/bonds/data/Key_rate_duration_US91282CFB28.png -------------------------------------------------------------------------------- /notebooks/products/bonds/data/Yield_curve_data_for_krds.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/domokane/FinancePy/7ca2a16354076cad672c03add5c3fb444159223b/notebooks/products/bonds/data/Yield_curve_data_for_krds.png -------------------------------------------------------------------------------- /notebooks/testNotebooks.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Created on Sun Jan 17 12:36:01 2021 4 | 5 | @author: Dominic 6 | """ 7 | 8 | import os 9 | 10 | import nbformat 11 | 12 | from nbconvert.preprocessors import ExecutePreprocessor 13 | from nbconvert.preprocessors import CellExecutionError 14 | 15 | import glob 16 | from os.path import dirname, join 17 | 18 | print("Looking in folder:", dirname(__file__)) 19 | 20 | notebooks = sorted( 21 | glob.glob(join(dirname(__file__), "./products/*/*.ipynb"), recursive=True)) 22 | 23 | ############################################################################### 24 | 25 | 26 | def notebook_run_new(notebook_filepathname): 27 | """Execute a notebook via nbconvert and collect output. 28 | :returns (parsed nb object, execution errors) 29 | """ 30 | 31 | dirname, filename = os.path.split(notebook_filepathname) 32 | 33 | os.chdir(dirname) 34 | 35 | nb = nbformat.read(open(notebook), as_version=4) 36 | ep = ExecutePreprocessor(timeout=600, kernel_name='python3') 37 | 38 | # notebook_filename_err = dirname + "//ERROR_" + filename 39 | 40 | try: 41 | 42 | out = ep.preprocess(nb, {'metadata': {'path': ".//"}}) 43 | 44 | # Save notebook 45 | with open(notebook_filepathname, mode='w', encoding='utf-8') as f: 46 | nbformat.write(nb, f) 47 | 48 | except CellExecutionError: 49 | 50 | msg = 'Error executing the notebook "%s".\n\n' % filename 51 | print(msg) 52 | 53 | # with open(notebook_filename_err, mode='w', encoding='utf-8') as f: 54 | # nbformat.write(nb, f) 55 | 56 | pass 57 | 58 | ############################################################################### 59 | 60 | 61 | print("Starting") 62 | n = 0 63 | m = len(notebooks) 64 | print(n, m) 65 | for notebook in notebooks[n:m+1]: 66 | dirname, filename = os.path.split(notebook) 67 | print("Checking Notebook", n+1, "of", m, ":", filename) 68 | notebook_run_new(notebook) 69 | n = n + 1 70 | -------------------------------------------------------------------------------- /requirements-dev.txt: -------------------------------------------------------------------------------- 1 | ##### Imports used in Test files but not required by financepy 2 | matplotlib==3.8.4 3 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | ##### Imports required by core library 2 | numba==0.60.0 3 | numpy==1.26.4 4 | scipy==1.13.1 5 | llvmlite==0.43.0 6 | ipython==8.25.0 7 | pandas==2.1.2 8 | prettytable==3.9.0 -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | from version import __version__ 3 | import setuptools 4 | 5 | with open("README.md", "r") as fh: 6 | long_description = fh.read() 7 | 8 | with open("version.py", "r") as fh: 9 | version_number = fh.read() 10 | start = version_number.find('"') 11 | end = version_number[start + 1 :].find('"') 12 | version_number_str = str(version_number[start + 1 : start + end + 1]) 13 | version_number_str = version_number_str.replace("\n", "") 14 | 15 | print(">>>" + version_number_str + "<<<") 16 | 17 | ############################################################################### 18 | cr = "\n" 19 | 20 | if 1 == 1: 21 | with open("financepy//__init__.template", "r") as file: 22 | filedata = file.read() 23 | 24 | # Replace the target string 25 | filedata = filedata.replace("__version__", "'" + str(__version__) + "'") 26 | 27 | now = datetime.now() 28 | dt_string = now.strftime("%d %b %Y at %H:%M") 29 | 30 | # Replace the target string 31 | filedata = filedata.replace("__dateandtime__", dt_string) 32 | 33 | # Write the file out again 34 | with open("./financepy//__init__.py", "w") as file: 35 | file.write(filedata) 36 | 37 | ############################################################################### 38 | 39 | setuptools.setup( 40 | name="financepy", 41 | version=version_number_str, 42 | author="Dominic O'Kane", 43 | author_email="dominic.okane@edhec.edu", 44 | description="A Finance Securities Valuation Library", 45 | long_description=long_description, 46 | long_description_content_type="text/markdown", 47 | url="https://github.com/domokane/FinancePy", 48 | keywords=["FINANCE", "OPTIONS", "BONDS", "VALUATION", "DERIVATIVES"], 49 | install_requires=[ 50 | "numpy", 51 | "numba", 52 | "scipy", 53 | "llvmlite", 54 | "ipython", 55 | "matplotlib", 56 | "pandas", 57 | "prettytable", 58 | ], 59 | package_data={ 60 | "": ["*.npz"], 61 | }, 62 | include_package_date=True, 63 | packages=setuptools.find_packages(), 64 | classifiers=[ 65 | "Development Status :: 2 - Pre-Alpha", 66 | "Programming Language :: Python :: 3", 67 | "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", 68 | "Operating System :: OS Independent", 69 | ], 70 | python_requires=">=3.6", 71 | ) 72 | -------------------------------------------------------------------------------- /unit_tests/data/gilt_bond_prices.txt: -------------------------------------------------------------------------------- 1 | epic description coupon maturity bid ask change income yield gross redemption yield 2 | TR13 Uk Gilt Treasury Stk 4.5 07-Mar-13 101.92 102.07 -0.01 4.41 0.22 3 | T813 Uk Gilt Treasury Stk 8 27-Sep-13 107.86 107.98 -0.03 7.41 0.23 4 | TR14 Uk Gilt Treasury Stk 2.25 07-Mar-14 102.9 103.05 0.01 2.18 0.22 5 | T514 Uk Gilt Treasury Stk 5 07-Sep-14 109.28 109.43 0.02 4.57 0.23 6 | TR15 Uk Gilt Treasury Stk 2.75 22-Jan-15 105.57 105.68 0.05 2.6 0.33 7 | T4T Uk Gilt Treasury Stk 4.75 07-Sep-15 112.92 113.04 0.04 4.2 0.35 8 | TY8 Uk Gilt Treasury Stk 8 07-Dec-15 124.39 124.55 0.04 6.43 0.34 9 | TS16 Uk Gilt Treasury Stk 2 22-Jan-16 104.92 105.04 0.07 1.91 0.49 10 | T16 Uk Gilt Treasury Stk 4 07-Sep-16 113.44 113.55 0.08 3.52 0.56 11 | TR17 Uk Gilt Treasury Stk 8.75 25-Aug-17 138.48 138.66 0.14 6.31 0.77 12 | T18 Uk Gilt Treasury Stk 5 07-Mar-18 121.74 121.84 0.16 4.11 0.91 13 | T19 Uk Gilt Treasury Stk 4.5 07-Mar-19 121.28 121.41 0.23 3.71 1.07 14 | TR19 Uk Gilt Treasury Stk 3.75 07-Sep-19 116.5 117.13 0.26 3.21 1.22 15 | TS20 Uk Gilt Treasury Stk 4.75 07-Mar-20 124.24 124.36 0.28 3.82 1.32 16 | TR20 Uk Gilt Treasury Stk 3.75 07-Sep-20 117.25 117.5 0.32 3.19 1.43 17 | TR21 Uk Gilt Treasury Stk 8 07-Jun-21 152.25 153.61 0.42 5.23 1.5 18 | TY21 Uk Gilt Treasury Stk 3.75 07-Sep-21 117.62 117.77 0.38 3.19 1.62 19 | TR22 Uk Gilt Treasury Stk 4 07-Mar-22 119.92 120.12 0.41 3.33 1.7 20 | TR25 Uk Gilt Treasury Stk 5 07-Mar-25 131.89 132.19 0.52 3.79 2.07 21 | TR27 Uk Gilt Treasury Stk 4.25 07-Dec-27 123.78 124.33 0.58 3.43 2.36 22 | TR28 Uk Gilt Treasury Stk 6 07-Dec-28 148.21 148.26 0.68 4.05 2.39 23 | TR30 Uk Gilt Treasury Stk 4.75 07-Dec-30 130.96 131.14 0.55 3.62 2.6 24 | TR32 Uk Gilt Treasury Stk 4.25 07-Jun-32 122.93 123.08 0.54 3.46 2.73 25 | T34 Uk Gilt Treasury Stk 4.5 07-Sep-34 126.09 126.18 0.58 3.57 2.89 26 | T4Q Uk Gilt Treasury Stk 4.25 07-Mar-36 121.46 121.71 0.53 3.5 2.97 27 | TR38 Uk Gilt Treasury Stk 4.75 07-Dec-38 130.7 130.8 0.55 3.63 3.04 28 | T39 Uk Gilt Treasury Stk 4.25 07-Sep-39 120.9 121.15 0.54 3.51 3.09 29 | T40 Uk Gilt Treasury Stk 4.25 07-Dec-40 120.55 120.93 0.53 3.52 3.14 30 | T42 Uk Gilt Treasury Stk 4.5 07-Dec-42 125.77 126.07 0.58 3.57 3.16 31 | T46 Uk Gilt Treasury Stk 4.25 07-Dec-46 120.93 121.37 0.56 3.51 3.22 32 | T49 Uk Gilt Treasury Stk 4.25 07-Dec-49 120.99 121.34 0.53 3.51 3.26 33 | TR4Q Uk Gilt Treasury Stk 4.25 07-Dec-55 122.49 122.9 0.55 3.46 3.27 34 | TR60 Uk Gilt Treasury Stk 4 22-Jan-60 117.6 118.06 0.51 3.39 3.26 -------------------------------------------------------------------------------- /unit_tests/data/ibor_benchmarks_example.csv: -------------------------------------------------------------------------------- 1 | ,type,start_date,maturity_date,day_count_type,notional,contract_rate,market_rate,spot_pvbp,fwd_pvbp,unit_value,value,fixed_leg_type,fixed_freq_type 2 | 0,IborDeposit,06-Oct-01,09-Oct-01,ACT_360,100,0.042,0.042,0.00833,0.00833,1,100,NaN,NaN 3 | 1,IborDeposit,09-Oct-01,09-Jan-02,ACT_360,100,0.042,0.042,0.252753,0.252842,1,100,NaN,NaN 4 | 2,IborFRA,09-Jan-02,09-Apr-02,ACT_360,100,0.042,0.042,0.244689,0.247402,0,0,PAY,NaN 5 | 3,IborSwap,09-Oct-01,09-Oct-02,THIRTY_E_360_ISDA,1000000,0.042,0.042,0.968858,0.969197,0,0,PAY,SEMI_ANNUAL 6 | 4,IborSwap,09-Oct-01,09-Oct-03,THIRTY_E_360_ISDA,1000000,0.043,0.043,1.897071,1.897735,0,0,PAY,SEMI_ANNUAL 7 | 5,IborSwap,09-Oct-01,11-Oct-04,THIRTY_E_360_ISDA,1000000,0.047,0.047,2.782943,2.783917,0,0,PAY,SEMI_ANNUAL 8 | 6,IborSwap,09-Oct-01,09-Oct-06,THIRTY_E_360_ISDA,1000000,0.054,0.054,4.381878,4.383412,0,0,PAY,SEMI_ANNUAL 9 | 7,IborSwap,09-Oct-01,09-Oct-08,THIRTY_E_360_ISDA,1000000,0.057,0.057,5.789357,5.791383,0,0,PAY,SEMI_ANNUAL 10 | 8,IborSwap,09-Oct-01,10-Oct-11,THIRTY_E_360_ISDA,1000000,0.06,0.06,7.575903,7.578554,0,-0.000013,PAY,SEMI_ANNUAL 11 | 9,IborSwap,09-Oct-01,09-Oct-13,THIRTY_E_360_ISDA,1000000,0.061,0.061,8.57742,8.580422,0,0,PAY,SEMI_ANNUAL 12 | 10,IborSwap,09-Oct-01,10-Oct-16,THIRTY_E_360_ISDA,1000000,0.059,0.059,9.899371,9.902836,0,-0.000001,PAY,SEMI_ANNUAL 13 | 11,IborSwap,09-Oct-01,11-Oct-21,THIRTY_E_360_ISDA,1000000,0.056,0.056,11.766369,11.770487,0,-0.000037,PAY,SEMI_ANNUAL 14 | 12,IborSwap,09-Oct-01,09-Oct-26,THIRTY_E_360_ISDA,1000000,0.0555,0.0555,13.250223,13.25486,0,-0.000111,PAY,SEMI_ANNUAL 15 | -------------------------------------------------------------------------------- /unit_tests/data/test_cases_bond_cfets.csv: -------------------------------------------------------------------------------- 1 | bond_code,settlement_date,dirty_price,ytm,ttm,freq,issue_date,maturity_date,coupon 2 | 210009.IB,2023/1/19,101.6214,2.86,8.36,2,2021/5/27,2031/5/27,3.02 3 | 130222.IB,2023/1/19,103.7177,1.8553,0.22,1,2013/4/11,2023/4/11,4.15 4 | 080002.IB,2023/1/19,101.5,5.2143,0.11,2,2008/2/28,2023/2/28,4.16 5 | 104590.IB,2024/1/5,102.5,3.3157,0.27,1,2019/4/12,2024/4/12,3.41 6 | 104590.IB,2024/3/1,102.5,7.7366,0.12,1,2019/4/12,2024/4/12,3.41 7 | 104590.IB,2023/1/5,102.5,3.4039,1.27,1,2019/4/12,2024/4/12,3.41 8 | 104590.IB,2023/3/1,102.5,3.8871,1.12,1,2019/4/12,2024/4/12,3.41 9 | 090011.IB,2024/1/5,101,1.938,0.43,2,2009/6/11,2024/6/11,3.69 10 | 090011.IB,2024/3/1,101,3.002,0.28,2,2009/6/11,2024/6/11,3.69 11 | 090011.IB,2023/1/5,101,3.1512,1.43,2,2009/6/11,2024/6/11,3.69 12 | 090011.IB,2023/3/1,101,3.5345,1.28,2,2009/6/11,2024/6/11,3.69 13 | 030003.IB,2023/1/5,100.747253,3.3841,0.2795,2,2003/4/17,2023/4/17,3.4 14 | 050004.IB,2025/1/5,100.579033,4.1202,0.3562,2,2005/5/15,2025/5/15,4.11 15 | 060009.IB,2026/3/1,100.660714,3.6858,0.3205,2,2006/6/26,2026/6/26,3.7 16 | -------------------------------------------------------------------------------- /unit_tests/data/test_cases_bond_ror.csv: -------------------------------------------------------------------------------- 1 | bond_code,buy_date,buy_ytm,buy_price,sell_date,sell_ytm,sell_price,simple_return,irr,note 2 | 210215.IB,2022/10/8,0.03,101.1388892,2023/12/8,0.033,99.50854719,0.012619776,0.012684992, 3 | 210215.IB,2022/10/9,0.05,86.93892387,2023/12/9,0.055,86.0114561,0.021608021,0.021726748, 4 | 210215.IB,2021/10/10,0.045,89.37097146,2023/12/10,0.041,94.33608106,0.057854349,0.057303426, 5 | 210215.IB,2021/10/11,0.032,99.56478807,2022/12/11,0.04,94.35496199,-0.017984056,-0.018131188, 6 | 210215.IB,2022/10/12,0.028,102.7401287,2022/12/12,0.025,105.5828341,0.165559758,0.177402478, 7 | 210215.IB,2022/10/13,0.036,96.64561565,2023/8/13,0.035,100.214665,0.044339386,0.044502077, 8 | 210215.IB,2022/10/14,0.029,101.9682359,2023/12/7,0.024,105.7655301,0.059094924,0.059199324, 9 | 210215.IB,2022/10/15,0.018,111.0512814,2024/12/6,0.042,94.45553255,-0.04346994,-0.045524839, 10 | 210215.IB,2022/10/16,-0.011,140.015924,2023/6/5,-0.012,140.0860028,0.000787435,0.000787547, 11 | 210215.IB,2022/10/17,-0.006,134.4315191,2025/12/4,0.003,116.8223425,-0.019578361,-0.020582882, 12 | 210215.IB,2022/10/18,-0.025,157.1465555,2026/9/3,-0.017,128.559942,-0.03153752,-0.03419871, 13 | 210215.IB,2022/10/19,-0.009,137.7404361,2027/4/2,-0.028,130.2061017,0.008060011,0.008288744, 14 | 210215.IB,2022/10/20,0.011,117.3492014,2025/7/20,-0.002,123.2173526,0.037510845,0.037266639, 15 | 210215.IB,2022/10/21,0.007,121.1247945,2023/8/21,-0.011,138.7109447,0.174323929,0.176770967, 16 | 210215.IB,2022/10/22,0.007,121.1271094,2028/12/22,0,109.36,0.009299417,0.009737208, 17 | 210215.IB,2022/10/23,0.017,111.9647539,2022/10/24,99999.99,0.00011371,-364.9996293,-364.9996293,True IRR is -1 which is beyond the brentq limit. 18 | 210215.IB,2022/10/26,0.011,117.3703067,2023/9/26,0.65,6.650108017,-0.99885602,-0.93552592, 19 | 210215.IB,2022/10/24,0.027,103.6260512,2022/10/25,0.025,105.2405365,5.686669801,5.686669801,True IRR is 281.259169 which is beyond the brentq limit. 20 | -------------------------------------------------------------------------------- /unit_tests/data/test_cases_bond_zero_ror.csv: -------------------------------------------------------------------------------- 1 | bond_code,buy_date,buy_ytm,buy_price,sell_date,sell_ytm,sell_price,simple_return,irr,note 2 | 092103011.IB,2021/10/7,0.037,96.84857394,2022/3/21,0.09,96.29590545,-0.012623518,-0.012579879, 3 | 092103011.IB,2021/10/8,0.03,97.43726642,2022/8/22,999.99,15.43353432,-0.965993649,-0.879367888, 4 | 092103011.IB,2021/10/6,0.07,94.18382619,2021/12/7,0.039,97.29700912,0.194594018,0.211000758, 5 | 092103011.IB,2021/10/7,0.3,79.12421418,2021/10/28,0.2,85.88235294,1.484537815,3.155915761, 6 | -------------------------------------------------------------------------------- /unit_tests/test_FinAmount.py: -------------------------------------------------------------------------------- 1 | ############################################################################## 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################## 4 | 5 | from financepy.utils.currency import CurrencyTypes 6 | from financepy.utils.amount import Amount 7 | 8 | ########################################################################## 9 | 10 | 11 | def test_Amount(): 12 | 13 | amt = Amount(101000.232) 14 | assert amt.amount() == 101000.232 15 | 16 | amt = Amount(101000.232, CurrencyTypes.CAD) 17 | assert repr(amt) == "CAD 101,000.23" 18 | 19 | 20 | ############################################################################### 21 | -------------------------------------------------------------------------------- /unit_tests/test_FinBondMortgage.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | from financepy.products.bonds.bond_mortgage import BondMortgageTypes 6 | from financepy.products.bonds.bond_mortgage import BondMortgage 7 | from financepy.utils.date import Date 8 | 9 | 10 | principal = 130000 11 | start_dt = Date(23, 2, 2018) 12 | end_dt = start_dt.add_tenor("10Y") 13 | mortgage = BondMortgage(start_dt, end_dt, principal) 14 | 15 | rate = 0.035 16 | 17 | 18 | def test_bond_mortgage_repayment(): 19 | mortgage.generate_flows(rate, BondMortgageTypes.REPAYMENT) 20 | i = 10 21 | assert mortgage.schedule.adjusted_dts[i] == Date(24, 12, 2018) 22 | assert round(mortgage.interest_flows[i], 4) == 355.0955 23 | assert round(mortgage.principal_flows[i], 4) == 930.4208 24 | assert round(mortgage.principal_remaining[i], 4) == 120816.6155 25 | assert round(mortgage.total_flows[i], 4) == 1285.5163 26 | 27 | 28 | def test_bond_mortgage_interest(): 29 | mortgage.generate_flows(rate, BondMortgageTypes.INTEREST_ONLY) 30 | i = 10 31 | assert mortgage.schedule.adjusted_dts[i] == Date(24, 12, 2018) 32 | assert round(mortgage.interest_flows[i], 4) == 379.1667 33 | assert round(mortgage.principal_flows[i], 4) == 0.0000 34 | assert round(mortgage.principal_remaining[i], 4) == 130000.0000 35 | assert round(mortgage.total_flows[i], 4) == 379.1667 36 | -------------------------------------------------------------------------------- /unit_tests/test_FinBondZeroCurve.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | from financepy.products.bonds.bond_zero_curve import BondZeroCurve 6 | from financepy.products.bonds.bond import Bond 7 | from financepy.utils.date import Date, from_datetime 8 | from financepy.utils.day_count import DayCountTypes 9 | from financepy.utils.frequency import FrequencyTypes 10 | import datetime as dt 11 | import os 12 | 13 | 14 | import pandas as pd 15 | 16 | path = os.path.join(os.path.dirname(__file__), "./data/gilt_bond_prices.txt") 17 | bond_dataframe = pd.read_csv(path, sep="\t") 18 | bond_dataframe["mid"] = 0.5 * (bond_dataframe["bid"] + bond_dataframe["ask"]) 19 | 20 | freq_type = FrequencyTypes.SEMI_ANNUAL 21 | dc_type = DayCountTypes.ACT_ACT_ICMA 22 | settlement = Date(19, 9, 2012) 23 | 24 | bonds = [] 25 | clean_prices = [] 26 | 27 | for _, bondRow in bond_dataframe.iterrows(): 28 | date_string = bondRow["maturity"] 29 | mat_date_time = dt.datetime.strptime(date_string, "%d-%b-%y") 30 | maturity_dt = from_datetime(mat_date_time) 31 | issue_dt = Date(maturity_dt.d, maturity_dt.m, 2000) 32 | coupon = bondRow["coupon"] / 100.0 33 | clean_price = bondRow["mid"] 34 | bond = Bond(issue_dt, maturity_dt, coupon, freq_type, dc_type) 35 | bonds.append(bond) 36 | clean_prices.append(clean_price) 37 | 38 | bondCurve = BondZeroCurve(settlement, bonds, clean_prices) 39 | 40 | 41 | def test_zero_curve(): 42 | 43 | maturity_dt = Date(7, 3, 2013) 44 | zero_rate = bondCurve.zero_rate(maturity_dt) 45 | assert round(zero_rate, 4) == 0.0022 46 | 47 | maturity_dt = Date(7, 9, 2019) 48 | zero_rate = bondCurve.zero_rate(maturity_dt) 49 | assert round(zero_rate, 4) == 0.0128 50 | 51 | maturity_dt = Date(22, 1, 2060) 52 | zero_rate = bondCurve.zero_rate(maturity_dt) 53 | assert round(zero_rate, 4) == 0.0351 54 | -------------------------------------------------------------------------------- /unit_tests/test_FinCDSIndex.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | from helpers import build_Ibor_Curve, buildIssuerCurve 6 | from financepy.utils.global_types import SwapTypes 7 | from financepy.utils.date import Date 8 | from financepy.utils.day_count import DayCountTypes 9 | from financepy.utils.frequency import FrequencyTypes 10 | from financepy.products.credit.cds_curve import CDSCurve 11 | from financepy.products.rates.ibor_single_curve import IborSingleCurve 12 | from financepy.products.rates.ibor_swap import IborSwap 13 | from financepy.utils.math import ONE_MILLION 14 | from financepy.products.credit.cds import CDS 15 | 16 | 17 | # We treat an index as a CDS contract with a flat CDS curve 18 | tradeDate = Date(7, 2, 2006) 19 | libor_curve = build_Ibor_Curve(tradeDate) 20 | issuer_curve = buildIssuerCurve(tradeDate, libor_curve) 21 | step_in_dt = tradeDate.add_days(1) 22 | value_dt = step_in_dt 23 | maturity_dt = Date(20, 6, 2010) 24 | 25 | cdsRecovery = 0.40 26 | notional = 10.0 * ONE_MILLION 27 | long_protection = True 28 | index_cpn = 0.004 29 | 30 | cdsIndexContract = CDS(step_in_dt, 31 | maturity_dt, 32 | index_cpn, 33 | notional, 34 | long_protection) 35 | 36 | 37 | def test_cds_index(): 38 | spd = cdsIndexContract.par_spread( 39 | value_dt, issuer_curve, cdsRecovery) * 10000.0 40 | assert round(spd, 4) == 48.3748 41 | 42 | v = cdsIndexContract.value(value_dt, issuer_curve, cdsRecovery) 43 | assert round(v['dirty_pv'], 4) == 27064.9906 44 | assert round(v['clean_pv'], 4) == 32620.5461 45 | 46 | p = cdsIndexContract.clean_price(value_dt, issuer_curve, cdsRecovery) 47 | assert round(p, 4) == 99.6738 48 | 49 | accrued_days = cdsIndexContract.accrued_days() 50 | assert accrued_days == 50.0 51 | 52 | accrued_interest = cdsIndexContract.accrued_interest() 53 | assert round(accrued_interest, 4) == -5555.5556 54 | 55 | prot_pv = cdsIndexContract.prot_leg_pv( 56 | value_dt, issuer_curve, cdsRecovery) 57 | assert round(prot_pv, 4) == 188423.9948 58 | 59 | premPV = cdsIndexContract.premium_leg_pv( 60 | value_dt, issuer_curve, cdsRecovery) 61 | assert round(premPV, 4) == 161359.0042 62 | -------------------------------------------------------------------------------- /unit_tests/test_FinCDSOption.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | from helpers import buildFullIssuerCurve 6 | from financepy.utils.date import Date 7 | from financepy.products.credit.cds_option import CDSOption 8 | 9 | 10 | # This reproduces example on page 38 of Open Gamma note on CDS Option 11 | tradeDate = Date(5, 2, 2014) 12 | _, issuer_curve = buildFullIssuerCurve(tradeDate) 13 | step_in_dt = tradeDate.add_days(1) 14 | value_dt = step_in_dt 15 | expiry_dt = Date(20, 3, 2014) 16 | maturity_dt = Date(20, 6, 2019) 17 | notional = 100.0 18 | 19 | 20 | def test_cds_option(): 21 | volatility = 0.3 22 | 23 | strike_result = [ 24 | (100, 4.0007), 25 | (150, 1.5874), 26 | (200, 0.0955), 27 | (300, 0.0) 28 | ] 29 | 30 | for strike, result in strike_result: 31 | cdsOption = CDSOption(expiry_dt, 32 | maturity_dt, 33 | strike / 10000.0, 34 | notional) 35 | 36 | v = cdsOption.value(value_dt, 37 | issuer_curve, 38 | volatility) 39 | 40 | vol = cdsOption.implied_volatility(value_dt, 41 | issuer_curve, 42 | v) 43 | 44 | assert round(v, 4) == result 45 | assert vol == 0.3 46 | -------------------------------------------------------------------------------- /unit_tests/test_FinCalendar.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | from financepy.utils.calendar import Calendar, CalendarTypes 6 | from financepy.utils.date import set_date_format, DateFormatTypes 7 | from financepy.utils.date import Date 8 | import sys 9 | 10 | # Between 3rd of January 2020 and 3rd of January 2030 11 | bus_days_in_decade = { 12 | "CalendarTypes.NONE": 2609, 13 | "CalendarTypes.WEEKEND": 2609, 14 | "CalendarTypes.AUSTRALIA": 2517, 15 | "CalendarTypes.CANADA": 2502, 16 | "CalendarTypes.FRANCE": 2507, 17 | "CalendarTypes.GERMANY": 2529, 18 | "CalendarTypes.ITALY": 2519, 19 | "CalendarTypes.JAPAN": 2466, 20 | "CalendarTypes.NEW_ZEALAND": 2520, 21 | "CalendarTypes.NORWAY": 2526, 22 | "CalendarTypes.SWEDEN": 2514, 23 | "CalendarTypes.SWITZERLAND": 2530, 24 | "CalendarTypes.TARGET": 2562, 25 | "CalendarTypes.UNITED_STATES": 2507, 26 | "CalendarTypes.UNITED_KINGDOM": 2527 27 | } 28 | 29 | 30 | def test_add_business_day(): 31 | for cal_type in CalendarTypes: 32 | num_days = bus_days_in_decade[str(cal_type)] 33 | cal = Calendar(cal_type) 34 | start = Date(3, 1, 2020) 35 | end = Date(3, 1, 2030) 36 | 37 | assert cal.add_business_days(start, num_days) == end, \ 38 | f"Landed on incorrect business day using {cal_type}" 39 | -------------------------------------------------------------------------------- /unit_tests/test_FinDiscountCurveZeros.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | from financepy.market.curves.discount_curve_zeros import DiscountCurveZeros 6 | from financepy.market.curves.interpolator import InterpTypes 7 | from financepy.utils.date import Date 8 | from financepy.utils.frequency import FrequencyTypes 9 | from financepy.utils.day_count import DayCountTypes 10 | import numpy as np 11 | 12 | 13 | def test_FinDiscountCurveZeros(): 14 | start_dt = Date(1, 1, 2018) 15 | times = np.linspace(1.0, 10.0, 10) 16 | dates = start_dt.add_years(times) 17 | zero_rates = np.linspace(5.0, 6.0, 10)/100 18 | freq_type = FrequencyTypes.ANNUAL 19 | day_count_type = DayCountTypes.ACT_ACT_ISDA 20 | 21 | curve = DiscountCurveZeros(start_dt, 22 | dates, 23 | zero_rates, 24 | freq_type, 25 | day_count_type, 26 | InterpTypes.FLAT_FWD_RATES) 27 | 28 | date = start_dt.add_years(0) 29 | df = curve.df(date) 30 | assert round(df, 4) == 1.0106 31 | 32 | date = start_dt.add_years(2.5) 33 | df = curve.df(date) 34 | assert round(df, 4) == 0.8816 35 | 36 | date = start_dt.add_years(5) 37 | df = curve.df(date) 38 | assert round(df, 4) == 0.7672 39 | 40 | date = start_dt.add_years(7.5) 41 | df = curve.df(date) 42 | assert round(df, 4) == 0.6588 43 | 44 | date = start_dt.add_years(10) 45 | df = curve.df(date) 46 | assert round(df, 4) == 0.5584 47 | -------------------------------------------------------------------------------- /unit_tests/test_FinEquityAmericanOption.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | from financepy.utils.date import Date 6 | from financepy.models.black_scholes import BlackScholes, BlackScholesTypes 7 | from financepy.market.curves.discount_curve_flat import DiscountCurveFlat 8 | from financepy.utils.global_types import OptionTypes 9 | from financepy.products.equity.equity_american_option import EquityAmericanOption 10 | 11 | 12 | value_dt = Date(1, 1, 2016) 13 | expiry_dt = Date(1, 1, 2017) 14 | stock_price = 50.0 15 | interest_rate = 0.06 16 | dividend_yield = 0.04 17 | volatility = 0.40 18 | strike_price = 50.0 19 | num_steps = 100 20 | 21 | discount_curve = DiscountCurveFlat(value_dt, interest_rate) 22 | dividend_curve = DiscountCurveFlat(value_dt, dividend_yield) 23 | 24 | model = BlackScholes(volatility, 25 | BlackScholesTypes.CRR_TREE, 26 | num_steps) 27 | 28 | 29 | def test_european_put(): 30 | put_option = EquityAmericanOption( 31 | expiry_dt, strike_price, OptionTypes.EUROPEAN_PUT) 32 | 33 | value = put_option.value(value_dt, stock_price, 34 | discount_curve, dividend_curve, model) 35 | 36 | assert round(value, 4) == 7.0833 37 | 38 | 39 | def test_american_put(): 40 | put_option = EquityAmericanOption( 41 | expiry_dt, strike_price, OptionTypes.AMERICAN_PUT) 42 | 43 | value = put_option.value(value_dt, stock_price, 44 | discount_curve, dividend_curve, model) 45 | 46 | assert round(value, 4) == 7.2583 47 | 48 | 49 | def test_european_call(): 50 | call_option = EquityAmericanOption( 51 | expiry_dt, strike_price, OptionTypes.EUROPEAN_CALL) 52 | 53 | value = call_option.value(value_dt, stock_price, 54 | discount_curve, dividend_curve, model) 55 | 56 | assert round(value, 4) == 8.0345 57 | 58 | 59 | def test_american_call(): 60 | call_option = EquityAmericanOption( 61 | expiry_dt, strike_price, OptionTypes.AMERICAN_CALL) 62 | 63 | value = call_option.value(value_dt, stock_price, discount_curve, 64 | dividend_curve, model) 65 | 66 | assert round(value, 4) == 8.0556 67 | -------------------------------------------------------------------------------- /unit_tests/test_FinEquityCliquetOption.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | from financepy.utils.global_types import OptionTypes 6 | from financepy.utils.date import Date 7 | from financepy.utils.frequency import FrequencyTypes 8 | from financepy.market.curves.discount_curve_flat import DiscountCurveFlat 9 | from financepy.models.black_scholes import BlackScholes 10 | from financepy.products.equity.equity_cliquet_option import EquityCliquetOption 11 | 12 | 13 | def test_EquityCliquetOption(): 14 | 15 | start_dt = Date(1, 1, 2014) 16 | final_expiry_dt = Date(1, 1, 2017) 17 | freq_type = FrequencyTypes.QUARTERLY 18 | option_type = OptionTypes.EUROPEAN_CALL 19 | 20 | cliquetOption = EquityCliquetOption(start_dt, 21 | final_expiry_dt, 22 | option_type, 23 | freq_type) 24 | 25 | value_dt = Date(1, 1, 2015) 26 | stock_price = 100.0 27 | volatility = 0.20 28 | interest_rate = 0.05 29 | dividend_yield = 0.02 30 | model = BlackScholes(volatility) 31 | discount_curve = DiscountCurveFlat(value_dt, interest_rate) 32 | dividend_curve = DiscountCurveFlat(value_dt, dividend_yield) 33 | 34 | v = cliquetOption.value(value_dt, 35 | stock_price, 36 | discount_curve, 37 | dividend_curve, 38 | model) 39 | 40 | assert round(v, 4) == 34.5287 41 | -------------------------------------------------------------------------------- /unit_tests/test_FinEquityDigitalOption.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | from financepy.utils.global_types import OptionTypes 6 | from financepy.products.equity.equity_digital_option import EquityDigitalOption, FinDigitalOptionTypes 7 | from financepy.models.black_scholes import BlackScholes 8 | from financepy.market.curves.discount_curve_flat import DiscountCurveFlat 9 | from financepy.utils.date import Date 10 | import sys 11 | sys.path.append("./..") 12 | 13 | 14 | underlying_type = FinDigitalOptionTypes.CASH_OR_NOTHING 15 | 16 | value_dt = Date(1, 1, 2015) 17 | expiry_dt = Date(1, 1, 2016) 18 | stock_price = 100.0 19 | volatility = 0.30 20 | interest_rate = 0.05 21 | dividend_yield = 0.01 22 | discount_curve = DiscountCurveFlat(value_dt, interest_rate) 23 | dividend_curve = DiscountCurveFlat(value_dt, dividend_yield) 24 | 25 | model = BlackScholes(volatility) 26 | 27 | num_paths = 40000 28 | 29 | 30 | def test_value(): 31 | 32 | call_option = EquityDigitalOption( 33 | expiry_dt, 100.0, OptionTypes.EUROPEAN_CALL, underlying_type) 34 | value = call_option.value( 35 | value_dt, 36 | stock_price, 37 | discount_curve, 38 | dividend_curve, 39 | model) 40 | value_mc = call_option.value_mc( 41 | value_dt, 42 | stock_price, 43 | discount_curve, 44 | dividend_curve, 45 | model, 46 | num_paths) 47 | 48 | assert round(value, 4) == 0.4693 49 | assert round(value_mc, 4) == 0.4694 50 | 51 | 52 | def test_greeks(): 53 | call_option = EquityDigitalOption( 54 | expiry_dt, 100.0, OptionTypes.EUROPEAN_CALL, underlying_type) 55 | 56 | delta = call_option.delta( 57 | value_dt, 58 | stock_price, 59 | discount_curve, 60 | dividend_curve, 61 | model) 62 | vega = call_option.vega( 63 | value_dt, 64 | stock_price, 65 | discount_curve, 66 | dividend_curve, 67 | model) 68 | theta = call_option.theta( 69 | value_dt, 70 | stock_price, 71 | discount_curve, 72 | dividend_curve, 73 | model) 74 | 75 | assert round(delta, 4) == 0.0126 76 | assert round(vega, 4) == -0.0035 77 | assert round(theta, 4) == 0.0266 78 | -------------------------------------------------------------------------------- /unit_tests/test_FinEquityForward.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | from financepy.market.curves.discount_curve_flat import DiscountCurveFlat 6 | from financepy.utils.global_types import FinLongShort 7 | from financepy.utils.date import Date 8 | from financepy.products.equity.equity_forward import EquityForward 9 | 10 | 11 | def test_equity_forward(): 12 | 13 | value_dt = Date(13, 2, 2018) 14 | expiry_dt = value_dt.add_months(12) 15 | 16 | stock_price = 130.0 17 | forward_price = 125.0 # Locked 18 | discount_rate = 0.05 19 | dividend_rate = 0.02 20 | 21 | expiry_dt = value_dt.add_months(12) 22 | notional = 100.0 23 | 24 | discount_curve = DiscountCurveFlat(value_dt, discount_rate) 25 | dividend_curve = DiscountCurveFlat(value_dt, dividend_rate) 26 | 27 | equityForward = EquityForward( 28 | expiry_dt, forward_price, notional, FinLongShort.LONG 29 | ) 30 | 31 | fwd_price = equityForward.forward( 32 | value_dt, stock_price, discount_curve, dividend_curve 33 | ) 34 | 35 | fwd_value = equityForward.value( 36 | value_dt, stock_price, discount_curve, dividend_curve 37 | ) 38 | 39 | assert round(fwd_price, 4) == 133.9591 40 | assert round(fwd_value, 4) == 852.2149 41 | -------------------------------------------------------------------------------- /unit_tests/test_FinEquityVanillaOption.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | from financepy.utils.global_types import OptionTypes 6 | from financepy.products.equity.equity_vanilla_option import EquityVanillaOption 7 | from financepy.market.curves.discount_curve_flat import DiscountCurveFlat 8 | from financepy.models.black_scholes import BlackScholes 9 | from financepy.utils.date import Date 10 | 11 | 12 | expiry_date = Date(1, 7, 2015) 13 | call_option = EquityVanillaOption( 14 | expiry_date, 100.0, OptionTypes.EUROPEAN_CALL 15 | ) 16 | call_option_vector = EquityVanillaOption( 17 | [expiry_date] * 3, 100.0, OptionTypes.EUROPEAN_CALL 18 | ) 19 | put_option = EquityVanillaOption(expiry_date, 100.0, OptionTypes.EUROPEAN_PUT) 20 | 21 | value_date = Date(1, 1, 2015) 22 | stock_price = 100 23 | volatility = 0.30 24 | interest_rate = 0.05 25 | dividend_yield = 0.01 26 | model = BlackScholes(volatility) 27 | discount_curve = DiscountCurveFlat(value_date, interest_rate) 28 | dividend_curve = DiscountCurveFlat(value_date, dividend_yield) 29 | 30 | 31 | def test_call_option(): 32 | v = call_option.value( 33 | value_date, stock_price, discount_curve, dividend_curve, model 34 | ) 35 | call_option_vector.value( 36 | value_date, stock_price, discount_curve, dividend_curve, model 37 | ) == [v] * 3 38 | assert v.round(4) == 9.3021 39 | 40 | 41 | def test_greeks(): 42 | 43 | delta = call_option.delta( 44 | value_date, stock_price, discount_curve, dividend_curve, model 45 | ) 46 | 47 | vega = call_option.vega( 48 | value_date, stock_price, discount_curve, dividend_curve, model 49 | ) 50 | 51 | theta = call_option.theta( 52 | value_date, stock_price, discount_curve, dividend_curve, model 53 | ) 54 | 55 | rho = call_option.rho( 56 | value_date, stock_price, discount_curve, dividend_curve, model 57 | ) 58 | 59 | assert [round(x, 4) for x in (delta, vega, theta, rho)] == [ 60 | 0.5762, 61 | 27.4034, 62 | -10.1289, 63 | 23.9608, 64 | ] 65 | 66 | 67 | def test_put_option(): 68 | v = put_option.value( 69 | value_date, stock_price, discount_curve, dividend_curve, model 70 | ) 71 | assert v.round(4) == 7.3478 72 | -------------------------------------------------------------------------------- /unit_tests/test_FinEquityVarianceSwap.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | from financepy.market.curves.discount_curve_flat import DiscountCurveFlat 6 | from financepy.products.equity.equity_variance_swap import EquityVarianceSwap 7 | from financepy.market.volatility.equity_vol_curve import EquityVolCurve 8 | from financepy.utils.date import Date 9 | import numpy as np 10 | 11 | 12 | def vol_skew(K, atm_vol, atmK, skew): 13 | v = atm_vol + skew * (K - atmK) 14 | return v 15 | 16 | 17 | def test_equity_variance_swap(): 18 | start_dt = Date(20, 3, 2018) 19 | tenor = "3M" 20 | strike = 0.3 * 0.3 21 | 22 | vol_swap = EquityVarianceSwap(start_dt, tenor, strike) 23 | 24 | value_dt = Date(20, 3, 2018) 25 | stock_price = 100.0 26 | dividend_yield = 0.0 27 | dividend_curve = DiscountCurveFlat(value_dt, dividend_yield) 28 | 29 | maturity_dt = start_dt.add_months(3) 30 | 31 | atm_vol = 0.20 32 | atmK = 100.0 33 | skew = -0.02 / 5.0 # defined as dsigma/dK 34 | strikes = np.linspace(50.0, 135.0, 18) 35 | vols = vol_skew(strikes, atm_vol, atmK, skew) 36 | vol_curve = EquityVolCurve(value_dt, maturity_dt, strikes, vols) 37 | 38 | strike_spacing = 5.0 39 | num_call_options = 10 40 | num_put_options = 10 41 | r = 0.05 42 | 43 | discount_curve = DiscountCurveFlat(value_dt, r) 44 | 45 | use_forward = False 46 | 47 | k1 = vol_swap.fair_strike( 48 | value_dt, 49 | stock_price, 50 | dividend_curve, 51 | vol_curve, 52 | num_call_options, 53 | num_put_options, 54 | strike_spacing, 55 | discount_curve, 56 | use_forward, 57 | ) 58 | assert round(k1, 4) == 0.0447 59 | 60 | k2 = vol_swap.fair_strike_approx(value_dt, stock_price, strikes, vols) 61 | assert round(k2, 4) == 0.0424 62 | -------------------------------------------------------------------------------- /unit_tests/test_FinIborFuture.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | from financepy.utils.date import Date, set_date_format, DateFormatTypes 6 | from financepy.products.rates.ibor_future import IborFuture 7 | 8 | set_date_format(DateFormatTypes.UK_LONG) 9 | 10 | 11 | def test_FinIborFuture(): 12 | 13 | todayDate = Date(5, 5, 2020) 14 | 15 | i = 1 16 | fut = IborFuture(todayDate, i, "3M") 17 | fra = fut.to_fra(0.020, 0.0) 18 | assert fut.delivery_dt == Date(17, 6, 2020) 19 | assert fra.start_dt == Date(17, 6, 2020) 20 | 21 | i = 4 22 | fut = IborFuture(todayDate, i, "3M") 23 | fra = fut.to_fra(0.020, 0.0) 24 | assert fut.delivery_dt == Date(17, 3, 2021) 25 | assert fra.start_dt == Date(17, 3, 2021) 26 | 27 | i = 7 28 | fut = IborFuture(todayDate, i, "3M") 29 | fra = fut.to_fra(0.020, 0.0) 30 | assert fut.delivery_dt == Date(15, 12, 2021) 31 | assert fra.start_dt == Date(15, 12, 2021) 32 | 33 | i = 10 34 | fut = IborFuture(todayDate, i, "3M") 35 | fra = fut.to_fra(0.020, 0.0) 36 | assert fut.delivery_dt == Date(21, 9, 2022) 37 | assert fra.start_dt == Date(21, 9, 2022) 38 | -------------------------------------------------------------------------------- /unit_tests/test_FinInflationIndexCurve.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | from financepy.products.inflation.FinInflationIndexCurve import FinInflationIndexCurve 6 | from financepy.utils.date import Date 7 | 8 | 9 | def test_FinInflationIndexCurve(): 10 | # Create a curve from times and discount factors 11 | indexDates = [Date(15, 1, 2008), Date(1, 4, 2008), Date(1, 5, 2008)] 12 | indexValues = [209.49645, 214.823, 216.632] 13 | lag = 3 # months 14 | 15 | curve = FinInflationIndexCurve(indexDates, indexValues, lag) 16 | refDate = Date(22, 7, 2008) 17 | 18 | value = curve.index_value(refDate) 19 | assert round(value, 4) == 216.0485 20 | 21 | index_ratio = curve.index_ratio(refDate) 22 | assert round(index_ratio, 4) == 1.0313 23 | -------------------------------------------------------------------------------- /unit_tests/test_FinLossDbnBuilder.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | from financepy.models.gauss_copula_onefactor import loss_dbn_hetero_adj_binomial 6 | from financepy.models.gauss_copula_onefactor import loss_dbn_recursion_gcd 7 | import numpy as np 8 | 9 | 10 | def test_FinLossDbnBuilder(): 11 | num_steps = 25 12 | 13 | num_credits = 125 14 | defaultProb = 0.30 15 | loss_ratio = np.ones(num_credits) 16 | loss_units = np.ones(num_credits) 17 | 18 | beta_results = [ 19 | (0.0, [0.0, 0.0, 0.0, 0.0]), 20 | (0.1, [0.0, 0.0, 0.0, 0.0]), 21 | (0.2, [0.0, 0.0, 0.0002, 0.0007]), 22 | (0.3, [0.0024, 0.0137, 0.0452, 0.112]), 23 | (0.4, [0.1385, 0.4565, 0.9554, 1.6197]), 24 | (0.5, [1.8407, 3.7058, 5.4378, 7.0117]), 25 | (0.6, [10.886, 13.7233, 15.1383, 15.91]), 26 | (0.7, [39.9844, 31.0789, 27.4473, 25.1626]), 27 | (0.8, [110.1321, 48.1134, 34.0898, 31.7425]) 28 | ] 29 | 30 | for beta, results in beta_results: 31 | 32 | default_probs = np.ones(num_credits) * defaultProb 33 | beta_vector = np.ones(num_credits) * beta 34 | 35 | dbn1 = loss_dbn_recursion_gcd(num_credits, 36 | default_probs, 37 | loss_units, 38 | beta_vector, 39 | num_steps) 40 | assert [round(x * 1000, 4) for x in dbn1[:4]] == results 41 | 42 | dbn2 = loss_dbn_hetero_adj_binomial(num_credits, 43 | default_probs, 44 | loss_ratio, 45 | beta_vector, 46 | num_steps) 47 | assert [round(x * 1000, 4) for x in dbn2[:4]] == results 48 | -------------------------------------------------------------------------------- /unit_tests/test_FinMath.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | from financepy.utils.math import normcdf_slow, N, normcdf_integrate 6 | from financepy.utils.math import accrued_interpolator 7 | import numpy as np 8 | 9 | 10 | x = -3.0 11 | 12 | 13 | def test_normcdf1(): 14 | result = N(x) 15 | assert round(result, 5) == 0.00135 16 | 17 | 18 | def test_normcdf2(): 19 | result = normcdf_slow(x) 20 | assert round(result, 5) == 0.00135 21 | 22 | 23 | def test_normcdf_integrate(): 24 | result = normcdf_integrate(x) 25 | assert round(result, 5) == 0.00135 26 | 27 | 28 | def test_accrued_interpolator(): 29 | cpn_times = [0.0, 4.000087613144162, 30 | 4.495649459810208, 5.002162949496498] 31 | cpn_flows = [0.0, 0.0, 0.03461111111111111, 0.035194444444444445] 32 | 33 | tree_times = [0., 0.12498563, 0.24997125, 0.37495688, 0.4999425, 0.62492813, 34 | 0.74991376, 0.87489938, 0.99988501, 1.12487063, 1.24985626, 1.37484189, 35 | 1.49982751, 1.62481314, 1.74979876, 1.87478439, 1.99977002, 2.12475564, 36 | 2.24974127, 2.37472689, 2.49971252, 2.62469815, 2.74968377, 2.8746694, 37 | 2.99965502, 3.12464065, 3.24962628, 3.3746119, 3.49959753, 3.62458315, 38 | 3.74956878, 3.87455441, 3.99954003, 4.12452566, 4.24951128, 4.37449691, 39 | 4.49948253, 4.62446816, 4.74945379, 4.87443941, 4.99942504, 5.12441066] 40 | 41 | cpn_times = np.array(cpn_times) 42 | cpn_flows = np.array(cpn_flows) 43 | 44 | values = [] 45 | for t in tree_times: 46 | v = accrued_interpolator(t, cpn_times, cpn_flows) 47 | values.append(v) 48 | 49 | assert [round(x * 1000, 6) for x in values] == \ 50 | [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 51 | 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 52 | 0.0, 0.0, 0.0, 0.0, 0.0, 8.691022, 17.420288, 26.149555, 0.266336, 53 | 8.950803, 17.63527, 26.319737, 35.004204, 0.0] 54 | -------------------------------------------------------------------------------- /unit_tests/test_FinModelCIR.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | from financepy.models.cir_montecarlo import CIRNumericalScheme 6 | from financepy.models.cir_montecarlo import zero_price_mc, zero_price 7 | import numpy as np 8 | 9 | r0 = 0.05 10 | a = 0.20 11 | b = 0.05 12 | sigma = 0.20 13 | t = 5.0 14 | 15 | num_paths = 2000 16 | dt = 0.05 17 | seed = 1968 18 | 19 | 20 | def test_model_CIR(): 21 | p = zero_price(r0, a, b, sigma, t) 22 | p_MC1 = zero_price_mc(r0, a, b, sigma, t, dt, num_paths, seed, 23 | CIRNumericalScheme.EULER.value) 24 | p_MC2 = zero_price_mc(r0, a, b, sigma, t, dt, num_paths, seed, 25 | CIRNumericalScheme.LOGNORMAL.value) 26 | p_MC3 = zero_price_mc(r0, a, b, sigma, t, dt, num_paths, seed, 27 | CIRNumericalScheme.MILSTEIN.value) 28 | p_MC4 = zero_price_mc(r0, a, b, sigma, t, dt, num_paths, seed, 29 | CIRNumericalScheme.KAHLJACKEL.value) 30 | p_MC5 = zero_price_mc(r0, a, b, sigma, t, dt, num_paths, seed, 31 | CIRNumericalScheme.EXACT.value) 32 | 33 | assert round(p, 4) == 0.7935 34 | assert round(p_MC1, 4) == 0.7913 35 | assert round(p_MC2, 4) == 0.7912 36 | assert round(p_MC3, 4) == 0.7914 37 | assert round(p_MC4, 4) == 0.7909 38 | assert round(p_MC5, 4) == 0.7922 39 | -------------------------------------------------------------------------------- /unit_tests/test_FinModelHeston.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | from financepy.utils.date import Date 6 | from financepy.products.equity.equity_vanilla_option import EquityVanillaOption 7 | from financepy.utils.global_types import OptionTypes 8 | from financepy.models.heston import Heston, HestonNumericalScheme 9 | import numpy as np 10 | 11 | 12 | # Reference see table 4.1 of Rouah book 13 | value_dt = Date(1, 1, 2015) 14 | expiry_dt = Date(1, 4, 2015) 15 | v0 = 0.05 # initial variance of volatility 16 | theta = 0.05 # long term variance 17 | kappa = 2.0 # speed of variance reversion 18 | sigma = 0.10 # volatility of variance 19 | rho = -0.9 # correlation 20 | interest_rate = 0.05 21 | dividend_yield = 0.01 22 | seed = 2838 23 | 24 | num_steps = 100 25 | num_paths = 20000 26 | stock_price = 100.0 27 | 28 | 29 | def test_heston(): 30 | rho = -0.90000 31 | sigma = 0.75000 32 | strike_price = 105.00 33 | hestonModel = Heston(v0, kappa, theta, sigma, rho) 34 | 35 | call_option = EquityVanillaOption( 36 | expiry_dt, strike_price, OptionTypes.EUROPEAN_CALL) 37 | 38 | value_mc_Heston = hestonModel.value_mc( 39 | value_dt, 40 | call_option, 41 | stock_price, 42 | interest_rate, 43 | dividend_yield, 44 | num_paths, 45 | num_steps, 46 | seed) 47 | valueGatheral = hestonModel.value_gatheral( 48 | value_dt, call_option, stock_price, interest_rate, dividend_yield) 49 | valueLewisRouah = hestonModel.value_lewis_rouah( 50 | value_dt, call_option, stock_price, interest_rate, dividend_yield) 51 | valueLewis = hestonModel.value_lewis( 52 | value_dt, call_option, stock_price, interest_rate, dividend_yield) 53 | valueWeber = hestonModel.value_weber( 54 | value_dt, call_option, stock_price, interest_rate, dividend_yield) 55 | 56 | assert round(value_mc_Heston, 4) == 1.7333 57 | assert round(valueGatheral, 4) == 1.8416 58 | assert round(valueLewisRouah, 4) == 1.8416 59 | assert round(valueLewis, 4) == 1.8416 60 | assert round(valueWeber, 4) == 1.8416 61 | -------------------------------------------------------------------------------- /unit_tests/test_FinModelShiftedSABR.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | from financepy.utils.global_types import OptionTypes 6 | from financepy.models.sabr_shifted import SABRShifted 7 | import numpy as np 8 | 9 | 10 | def test_ShiftedSABR(): 11 | alpha = 0.0 12 | beta = 0.5 13 | rho = -0.09 14 | nu = 0.1 15 | shift = 0.02 16 | 17 | strikeVol = 0.1 18 | 19 | f = 0.043 20 | k = 0.050 21 | r = 0.03 22 | t_exp = 2.0 23 | 24 | call_optionType = OptionTypes.EUROPEAN_CALL 25 | put_optionType = OptionTypes.EUROPEAN_PUT 26 | 27 | df = np.exp(-r * t_exp) 28 | 29 | # SABR equivalent to lognormal (Black) model (i.e. beta = 1, rho = 0, nu = 0, shift = 0) 30 | modelSABR_01 = SABRShifted(0.0, 1.0, 0.0, 0.0, 0.0) 31 | modelSABR_01.set_alpha_from_black_vol(strikeVol, f, k, t_exp) 32 | 33 | impliedLognormalVol = modelSABR_01.black_vol(f, k, t_exp) 34 | impliedATMLognormalVol = modelSABR_01.black_vol(k, k, t_exp) 35 | impliedLognormalSmile = impliedLognormalVol - impliedATMLognormalVol 36 | 37 | assert impliedLognormalSmile == 0.0, "In lognormal model, smile should be flat" 38 | calibrationError = round(strikeVol - impliedLognormalVol, 6) 39 | assert calibrationError == 0.0 40 | 41 | # Volatility: pure SABR dynamics 42 | modelSABR_02 = SABRShifted(alpha, beta, rho, nu, shift) 43 | modelSABR_02.set_alpha_from_black_vol(strikeVol, f, k, t_exp) 44 | 45 | impliedLognormalVol = modelSABR_02.black_vol(f, k, t_exp) 46 | impliedATMLognormalVol = modelSABR_02.black_vol(k, k, t_exp) 47 | impliedLognormalSmile = impliedLognormalVol - impliedATMLognormalVol 48 | calibrationError = round(strikeVol - impliedLognormalVol, 6) 49 | assert calibrationError == 0.0 50 | 51 | # Valuation: pure SABR dynamics 52 | valueCall = modelSABR_02.value(f, k, t_exp, df, call_optionType) 53 | valuePut = modelSABR_02.value(f, k, t_exp, df, put_optionType) 54 | assert round((valueCall - valuePut), 12) == round(df*(f - k), 12), \ 55 | "The method called 'value()' doesn't comply with Call-Put parity" 56 | 57 | # TODO: adding Call-Put parity test for all sensitivities 58 | -------------------------------------------------------------------------------- /unit_tests/test_FinOIS.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | from financepy.utils.global_types import SwapTypes 6 | from financepy.utils.date import Date 7 | from financepy.utils.day_count import DayCountTypes 8 | from financepy.utils.frequency import FrequencyTypes 9 | from financepy.market.curves.discount_curve_flat import DiscountCurveFlat 10 | from financepy.products.rates.ois import OIS 11 | from financepy.utils.math import ONE_MILLION 12 | 13 | 14 | def test_FinFixedOIS(): 15 | # Here I follow the example in 16 | # https://blog.deriscope.com/index.php/en/excel-quantlib-overnight-index-swap 17 | 18 | effective_dt = Date(30, 11, 2018) 19 | end_dt = Date(30, 11, 2023) 20 | 21 | end_dt = effective_dt.add_months(60) 22 | oisRate = 0.04 23 | fixed_leg_type = SwapTypes.PAY 24 | fixed_freq_type = FrequencyTypes.ANNUAL 25 | fixedDayCount = DayCountTypes.ACT_360 26 | float_freq_type = FrequencyTypes.ANNUAL 27 | floatDayCount = DayCountTypes.ACT_360 28 | float_spread = 0.0 29 | notional = ONE_MILLION 30 | payment_lag = 1 31 | 32 | ois = OIS(effective_dt, 33 | end_dt, 34 | fixed_leg_type, 35 | oisRate, 36 | fixed_freq_type, 37 | fixedDayCount, 38 | notional, 39 | payment_lag, 40 | float_spread, 41 | float_freq_type, 42 | floatDayCount) 43 | 44 | value_dt = effective_dt 45 | marketRate = 0.05 46 | oisCurve = DiscountCurveFlat(value_dt, marketRate, 47 | FrequencyTypes.ANNUAL) 48 | 49 | v = ois.value(effective_dt, oisCurve) 50 | assert round(v, 4) == 43915.6019 51 | -------------------------------------------------------------------------------- /unit_tests/test_FinSobol.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | from financepy.models.sobol import get_uniform_sobol 6 | 7 | 8 | def test_FinSobol(): 9 | 10 | num_points = 1000 11 | dimensions = 3 12 | 13 | points = get_uniform_sobol(num_points, dimensions) 14 | 15 | for d in range(dimensions): 16 | av = 0.0 17 | var = 0.0 18 | 19 | for point in points[:, d]: 20 | av += point 21 | var += point ** 2 22 | 23 | av /= num_points 24 | var /= num_points 25 | 26 | avError = abs(av - (1/2)) 27 | varError = abs(var - (1/3)) 28 | assert(avError < 0.002) 29 | assert(varError < 0.002) 30 | -------------------------------------------------------------------------------- /unit_tests/test_FinStatistics.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | from financepy.utils.stats import mean, stdev, correlation 6 | import numpy as np 7 | seed = 1972 8 | np.random.seed(seed) 9 | num_trials = 1000000 10 | x = np.random.normal(0.0, 1.0, size=(num_trials)) 11 | y = np.random.normal(0.0, 1.0, size=(num_trials)) 12 | 13 | 14 | def test_mean(): 15 | np_result = x.mean() 16 | fp_result = mean(x) 17 | assert round(fp_result, 10) == round(np_result, 10) 18 | 19 | 20 | def test_stdev(): 21 | np_result = x.std() 22 | fp_result = stdev(x) 23 | assert round(fp_result, 10) == round(np_result, 10) 24 | 25 | # TODO: tests for stderr, var, moment 26 | 27 | 28 | def test_correlation(): 29 | beta = 0.4 30 | z = x * beta + y * np.sqrt(1.0 - beta * beta) 31 | 32 | np_result = np.corrcoef(x, z)[0, 1] 33 | fp_result = correlation(x, z) 34 | assert round(fp_result, 10) == round(np_result, 10) 35 | -------------------------------------------------------------------------------- /unit_tests/test_FinVasicekRateModel.py: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Copyright (C) 2018, 2019, 2020 Dominic O'Kane 3 | ############################################################################### 4 | 5 | from financepy.models.vasicek_mc import zero_price, zero_price_mc 6 | 7 | 8 | def test_FinModelRatesVasicek(): 9 | r0 = 0.05 10 | a = 0.10 11 | b = 0.05 12 | sigma = 0.05 13 | 14 | num_paths = 1000 15 | dt = 0.02 16 | seed = 1968 17 | 18 | t = 0.0 19 | p_MC = zero_price_mc(r0, a, b, sigma, t, dt, num_paths, seed) 20 | p_MC2 = zero_price_mc(r0, a, b, sigma, t, dt, 10 * num_paths, seed) 21 | p = zero_price(r0, a, b, sigma, t) 22 | assert round(p, 4) == 1.0 23 | assert round(p_MC, 4) == 1.0 24 | assert round(p_MC2, 4) == 1.0 25 | 26 | t = 5.0 27 | p_MC = zero_price_mc(r0, a, b, sigma, t, dt, num_paths, seed) 28 | p_MC2 = zero_price_mc(r0, a, b, sigma, t, dt, 10 * num_paths, seed) 29 | p = zero_price(r0, a, b, sigma, t) 30 | assert round(p, 4) == 0.8077 31 | assert round(p_MC, 4) == 0.8042 32 | assert round(p_MC2, 4) == 0.8058 33 | 34 | t = 7.5 35 | p_MC = zero_price_mc(r0, a, b, sigma, t, dt, num_paths, seed) 36 | p_MC2 = zero_price_mc(r0, a, b, sigma, t, dt, 10 * num_paths, seed) 37 | p = zero_price(r0, a, b, sigma, t) 38 | assert round(p, 4) == 0.7626 39 | assert round(p_MC, 4) == 0.7567 40 | assert round(p_MC2, 4) == 0.7620 41 | 42 | t = 10.0 43 | p_MC = zero_price_mc(r0, a, b, sigma, t, dt, num_paths, seed) 44 | p_MC2 = zero_price_mc(r0, a, b, sigma, t, dt, 10 * num_paths, seed) 45 | p = zero_price(r0, a, b, sigma, t) 46 | assert round(p, 4) == 0.7483 47 | assert round(p_MC, 4) == 0.7392 48 | assert round(p_MC2, 4) == 0.7471 49 | -------------------------------------------------------------------------------- /unit_tests/test_TensionSpline.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | import numpy as np 3 | 4 | from financepy.utils.global_vars import * 5 | from financepy.utils.tension_spline import TensionSpline 6 | from financepy.utils.global_vars import g_small 7 | 8 | 9 | 10 | @pytest.mark.parametrize('n_knots', [1, 2, 3, 4, 5]) 11 | def test_TensorSpline_Recovers_Inputs(n_knots): 12 | x = np.arange(n_knots) 13 | y = x*0.1 + np.arange(n_knots) % 2 14 | sigma = 1.0 15 | ts = TensionSpline(x, y, sigma) 16 | y_out = ts(x) 17 | relerr = np.linalg.norm(y-y_out)/(np.linalg.norm(y) + g_small) 18 | assert relerr <= g_small 19 | 20 | 21 | def test_TensorSpline_Values(): 22 | n_knots = 4 23 | x = np.arange(n_knots) 24 | y = x*0.1 + np.arange(n_knots) % 2 25 | sigma = 1.0 26 | ts = TensionSpline(x, y, sigma) 27 | 28 | xs = np.linspace(x[0]-1, x[-1]+1, 2*n_knots+1, endpoint=True) 29 | y_out = ts(xs) 30 | 31 | y_expected = [0.0, 0.0, 0.42195359, 1.0955618, 0.65, 0.2044382, 0.87804641, 1.3, 1.3, ] 32 | relerr = np.linalg.norm(y_expected-y_out)/np.linalg.norm(y_expected) 33 | assert relerr <= g_small*1e4 # some rounding errors expected 34 | 35 | 36 | # if __name__ == '__main__': 37 | # test_TensorSpline_Recovers_Inputs(2) 38 | # test_TensorSpline_Values() 39 | -------------------------------------------------------------------------------- /unit_tests/test_tenor.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from financepy.utils.tenor import Tenor, TenorUnit 4 | 5 | 6 | @pytest.mark.parametrize('tenor_string,num_periods,units', 7 | [ 8 | (None, 0, TenorUnit.NONE), 9 | ('', 0, TenorUnit.NONE), 10 | ('on', 1, TenorUnit.DAYS), 11 | ('TN', 1, TenorUnit.DAYS), 12 | ('5d', 5, TenorUnit.DAYS), 13 | ('-7w', -7, TenorUnit.WEEKS), 14 | ('12M', 12, TenorUnit.MONTHS), 15 | ('-3Y', -3, TenorUnit.YEARS), 16 | ]) 17 | def test_tenor_create(tenor_string, num_periods, units): 18 | tenor = Tenor(tenor_string) 19 | assert tenor._num_periods == num_periods 20 | assert tenor._units.name == units.name 21 | 22 | 23 | @pytest.mark.parametrize('tenor_string', ['5d', '-7w', '12M', '-3Y', ]) 24 | def test_tenor_to_string(tenor_string): 25 | tenor = Tenor(tenor_string) 26 | assert f'{tenor}' == tenor_string.upper() 27 | 28 | 29 | @pytest.mark.parametrize('tenor,mult,result', 30 | [ 31 | ('5d', 5, '25d'), 32 | ('-7w', 3, '-21W'), 33 | ('12M', 2, '24M'), 34 | ('-3Y', -2, '6Y'), 35 | ]) 36 | def test_tenor_multiply(tenor, mult, result): 37 | t1 = Tenor(tenor) 38 | t2 = t1 * mult 39 | t3 = mult*t1 40 | res = Tenor(result) 41 | assert t2 == res 42 | assert t3 == res 43 | 44 | 45 | @pytest.mark.parametrize('tenor1,tenor2,result', 46 | [ 47 | ('5d', '10d', '15d'), 48 | ('7w', '3d', '52D'), 49 | ('1M', '1D', '29D'), 50 | ('1Y', '1W', '49w'), 51 | ('12M', '1Y', '24M'), 52 | ('-3Y', '-2Y', '-5Y'), 53 | ]) 54 | def test_tenor_add(tenor1, tenor2, result): 55 | t1 = Tenor(tenor1) 56 | t2 = Tenor(tenor2) 57 | res = Tenor(result) 58 | assert t1 + t2 == res 59 | 60 | 61 | # if __name__ == '__main__': 62 | # # test_tenor_create(None, 0, TenorUnit.NONE) 63 | # # test_tenor_multiply('5d', 5, '25d') 64 | # test_tenor_add('5d', '10d', '15d') 65 | -------------------------------------------------------------------------------- /version.py: -------------------------------------------------------------------------------- 1 | __version__ = "0.370" 2 | --------------------------------------------------------------------------------