├── BUILD
├── CONTRIBUTING.md
├── LICENSE
├── MANIFEST.in
├── README.md
├── WORKSPACE
├── api_docs
├── README.md
├── index.md
└── tf_quant_finance
│ ├── black_scholes.md
│ ├── black_scholes
│ ├── AveragingFrequency.md
│ ├── AveragingType.md
│ ├── ImpliedVolMethod.md
│ ├── ImpliedVolUnderlyingDistribution.md
│ ├── README.md
│ ├── approximations.md
│ ├── approximations
│ │ ├── adesi_whaley.md
│ │ └── bjerksund_stensland.md
│ ├── asian_option_price.md
│ ├── asset_or_nothing_price.md
│ ├── barrier_price.md
│ ├── binary_price.md
│ ├── brownian_bridge_double.md
│ ├── brownian_bridge_single.md
│ ├── implied_vol.md
│ ├── implied_vol_approx.md
│ ├── implied_vol_newton.md
│ ├── option_price.md
│ ├── option_price_binomial.md
│ ├── swaption_price.md
│ └── variance_swap_fair_strike.md
│ ├── datetime.md
│ ├── datetime
│ ├── BusinessDayConvention.md
│ ├── BusinessDaySchedule.md
│ ├── DateTensor.md
│ ├── HolidayCalendar.md
│ ├── Month.md
│ ├── PeriodTensor.md
│ ├── PeriodType.md
│ ├── PeriodicSchedule.md
│ ├── README.md
│ ├── WeekDay.md
│ ├── WeekendMask.md
│ ├── convert_to_date_tensor.md
│ ├── create_holiday_calendar.md
│ ├── dates_from_datetimes.md
│ ├── dates_from_np_datetimes.md
│ ├── dates_from_ordinals.md
│ ├── dates_from_tensor.md
│ ├── dates_from_tuples.md
│ ├── dates_from_year_month_day.md
│ ├── daycount_actual_360.md
│ ├── daycount_actual_365_actual.md
│ ├── daycount_actual_365_fixed.md
│ ├── daycount_actual_actual_isda.md
│ ├── daycount_thirty_360_isda.md
│ ├── periods.md
│ ├── periods
│ │ ├── day.md
│ │ ├── days.md
│ │ ├── month.md
│ │ ├── months.md
│ │ ├── week.md
│ │ ├── weeks.md
│ │ ├── year.md
│ │ └── years.md
│ ├── random_dates.md
│ ├── utils.md
│ └── utils
│ │ ├── days_in_leap_and_nonleap_years_between.md
│ │ ├── days_in_leap_years_between.md
│ │ ├── is_leap_year.md
│ │ ├── leap_days_between.md
│ │ ├── ordinal_to_year_month_day.md
│ │ └── year_month_day_to_ordinal.md
│ ├── experimental.md
│ ├── experimental
│ ├── README.md
│ ├── american_option_pricing.md
│ ├── american_option_pricing
│ │ ├── andersen_lake.md
│ │ └── andersen_lake
│ │ │ ├── andersen_lake.md
│ │ │ ├── calculate_exercise_boundary.md
│ │ │ ├── common.md
│ │ │ ├── d_minus.md
│ │ │ ├── d_plus.md
│ │ │ ├── divide_with_positive_denominator.md
│ │ │ ├── exercise_boundary.md
│ │ │ ├── exercise_boundary
│ │ │ ├── boundary_denominator.md
│ │ │ ├── boundary_numerator.md
│ │ │ └── cubic_interpolation.md
│ │ │ ├── machine_eps.md
│ │ │ ├── standard_normal_cdf.md
│ │ │ └── vanilla_prices.md
│ ├── finite_difference
│ │ └── README.md
│ ├── instruments.md
│ ├── instruments
│ │ ├── AverageType.md
│ │ ├── Bond.md
│ │ ├── CMSCashflowStream.md
│ │ ├── CMSCouponSpecs.md
│ │ ├── CMSSwap.md
│ │ ├── CapAndFloor.md
│ │ ├── DayCountConvention.md
│ │ ├── EurodollarFutures.md
│ │ ├── FixedCashflowStream.md
│ │ ├── FixedCouponSpecs.md
│ │ ├── FloatCouponSpecs.md
│ │ ├── FloatingCashflowStream.md
│ │ ├── FloatingRateNote.md
│ │ ├── ForwardRateAgreement.md
│ │ ├── InterestRateMarket.md
│ │ ├── InterestRateModelType.md
│ │ ├── InterestRateSwap.md
│ │ ├── OvernightIndexLinkedFutures.md
│ │ ├── RateCurve.md
│ │ ├── Swaption.md
│ │ └── ratecurve_from_discounting_function.md
│ ├── io.md
│ ├── io
│ │ ├── ArrayDictReader.md
│ │ ├── ArrayDictWriter.md
│ │ ├── decode_array.md
│ │ └── encode_array.md
│ ├── local_stochastic_volatility.md
│ ├── local_stochastic_volatility
│ │ ├── LSVVarianceModel.md
│ │ └── LocalStochasticVolatilityModel.md
│ ├── local_volatility.md
│ ├── local_volatility
│ │ └── LocalVolatilityModel.md
│ ├── lsm_algorithm.md
│ ├── lsm_algorithm
│ │ ├── least_square_mc.md
│ │ ├── least_square_mc_v2.md
│ │ ├── make_basket_put_payoff.md
│ │ ├── make_polynomial_basis.md
│ │ └── make_polynomial_basis_v2.md
│ ├── svi.md
│ └── svi
│ │ ├── calibration.md
│ │ ├── implied_volatility_from_raw_svi_parameters.md
│ │ └── total_variance_from_raw_svi_parameters.md
│ ├── math.md
│ ├── math
│ ├── README.md
│ ├── custom_loops.md
│ ├── diff.md
│ ├── fwd_gradient.md
│ ├── gradients.md
│ ├── integration.md
│ ├── integration
│ │ ├── IntegrationMethod.md
│ │ ├── gauss_kronrod.md
│ │ ├── gauss_legendre.md
│ │ ├── integrate.md
│ │ └── simpson.md
│ ├── interpolation.md
│ ├── interpolation
│ │ ├── README.md
│ │ ├── cubic.md
│ │ ├── cubic
│ │ │ ├── BoundaryConditionType.md
│ │ │ ├── SplineParameters.md
│ │ │ ├── build_spline.md
│ │ │ └── interpolate.md
│ │ ├── interpolation_2d.md
│ │ ├── interpolation_2d
│ │ │ └── Interpolation2D.md
│ │ ├── linear.md
│ │ └── linear
│ │ │ └── interpolate.md
│ ├── jacobian.md
│ ├── make_val_and_grad_fn.md
│ ├── optimizer.md
│ ├── optimizer
│ │ ├── ConjugateGradientParams.md
│ │ ├── README.md
│ │ ├── bfgs_minimize.md
│ │ ├── conjugate_gradient_minimize.md
│ │ ├── converged_all.md
│ │ ├── converged_any.md
│ │ ├── differential_evolution_minimize.md
│ │ ├── differential_evolution_one_step.md
│ │ ├── lbfgs_minimize.md
│ │ ├── nelder_mead_minimize.md
│ │ └── nelder_mead_one_step.md
│ ├── pad.md
│ ├── pad
│ │ ├── pad_date_tensors.md
│ │ └── pad_tensors.md
│ ├── pde.md
│ ├── pde
│ │ ├── README.md
│ │ ├── boundary_conditions.md
│ │ ├── boundary_conditions
│ │ │ ├── dirichlet.md
│ │ │ └── neumann.md
│ │ ├── fd_solvers.md
│ │ ├── fd_solvers
│ │ │ ├── solve_backward.md
│ │ │ └── solve_forward.md
│ │ ├── grids.md
│ │ ├── grids
│ │ │ ├── log_uniform_grid.md
│ │ │ ├── log_uniform_grid_with_extra_point.md
│ │ │ ├── rectangular_grid.md
│ │ │ ├── uniform_grid.md
│ │ │ └── uniform_grid_with_extra_point.md
│ │ ├── pde_solvers.pdf
│ │ ├── steppers.md
│ │ └── steppers
│ │ │ ├── composite_stepper.md
│ │ │ ├── composite_stepper
│ │ │ └── composite_scheme_step.md
│ │ │ ├── crank_nicolson.md
│ │ │ ├── crank_nicolson
│ │ │ ├── crank_nicolson_scheme.md
│ │ │ └── crank_nicolson_step.md
│ │ │ ├── douglas_adi.md
│ │ │ ├── douglas_adi
│ │ │ ├── douglas_adi_scheme.md
│ │ │ ├── douglas_adi_step.md
│ │ │ └── multidim_parabolic_equation_step.md
│ │ │ ├── explicit.md
│ │ │ ├── explicit
│ │ │ ├── explicit_scheme.md
│ │ │ └── explicit_step.md
│ │ │ ├── extrapolation.md
│ │ │ ├── extrapolation
│ │ │ ├── extrapolation_scheme.md
│ │ │ └── extrapolation_step.md
│ │ │ ├── implicit.md
│ │ │ ├── implicit
│ │ │ ├── implicit_scheme.md
│ │ │ └── implicit_step.md
│ │ │ ├── multidim_parabolic_equation_stepper.md
│ │ │ ├── oscillation_damped_crank_nicolson.md
│ │ │ ├── oscillation_damped_crank_nicolson
│ │ │ └── oscillation_damped_crank_nicolson_step.md
│ │ │ ├── parabolic_equation_stepper.md
│ │ │ ├── parabolic_equation_stepper
│ │ │ └── parabolic_equation_step.md
│ │ │ ├── weighted_implicit_explicit.md
│ │ │ └── weighted_implicit_explicit
│ │ │ ├── weighted_implicit_explicit_scheme.md
│ │ │ └── weighted_implicit_explicit_step.md
│ ├── piecewise.md
│ ├── piecewise
│ │ ├── PiecewiseConstantFunc.md
│ │ ├── convert_to_tensor_or_func.md
│ │ └── find_interval_index.md
│ ├── qmc.md
│ ├── qmc
│ │ ├── digital_net_sample.md
│ │ ├── lattice_rule_sample.md
│ │ ├── random_digital_shift.md
│ │ ├── random_scrambling_matrices.md
│ │ ├── random_scrambling_vectors.md
│ │ ├── scramble_generating_matrices.md
│ │ ├── sobol_generating_matrices.md
│ │ ├── sobol_sample.md
│ │ ├── utils.md
│ │ └── utils
│ │ │ ├── exp2.md
│ │ │ ├── filter_tensor.md
│ │ │ ├── get_shape.md
│ │ │ ├── log2.md
│ │ │ └── tent_transform.md
│ ├── random.md
│ ├── random
│ │ ├── RandomType.md
│ │ ├── halton.md
│ │ ├── halton
│ │ │ └── sample.md
│ │ ├── mv_normal_sample.md
│ │ ├── sobol.md
│ │ ├── sobol
│ │ │ ├── load_data.md
│ │ │ └── sample.md
│ │ ├── stateless_random_shuffle.md
│ │ └── uniform.md
│ ├── random_ops
│ │ └── README.md
│ ├── root_search.md
│ ├── root_search
│ │ ├── brentq.md
│ │ └── newton_root.md
│ ├── segment_ops.md
│ ├── segment_ops
│ │ ├── segment_cumsum.md
│ │ └── segment_diff.md
│ ├── value_and_gradient.md
│ └── value_and_jacobian.md
│ ├── models.md
│ ├── models
│ ├── GenericItoProcess.md
│ ├── GeometricBrownianMotion.md
│ ├── HestonModel.md
│ ├── ItoProcess.md
│ ├── JoinedItoProcess.md
│ ├── MultivariateGeometricBrownianMotion.md
│ ├── PathScale.md
│ ├── README.md
│ ├── ReturnsType.md
│ ├── SabrModel.md
│ ├── ValuationMethod.md
│ ├── cir.md
│ ├── cir
│ │ └── CirModel.md
│ ├── euler_sampling.md
│ ├── euler_sampling
│ │ └── sample.md
│ ├── heston.md
│ ├── heston
│ │ ├── approximations.md
│ │ ├── approximations
│ │ │ ├── asian_option_price.md
│ │ │ └── european_option_price.md
│ │ └── calibration.md
│ ├── hjm.md
│ ├── hjm
│ │ ├── CalibrationResult.md
│ │ ├── GaussianHJM.md
│ │ ├── QuasiGaussianHJM.md
│ │ ├── bond_option_price.md
│ │ ├── calibration_from_swaptions.md
│ │ ├── cap_floor_price.md
│ │ └── swaption_price.md
│ ├── hull_white.md
│ ├── hull_white
│ │ ├── CalibrationResult.md
│ │ ├── HullWhiteModel1F.md
│ │ ├── VectorHullWhiteModel.md
│ │ ├── bermudan_swaption_price.md
│ │ ├── bond_option_price.md
│ │ ├── calibration_from_cap_floors.md
│ │ ├── calibration_from_swaptions.md
│ │ ├── cap_floor_price.md
│ │ └── swaption_price.md
│ ├── legacy
│ │ └── README.md
│ ├── longstaff_schwartz.md
│ ├── longstaff_schwartz
│ │ ├── least_square_mc.md
│ │ ├── make_basket_put_payoff.md
│ │ └── make_polynomial_basis.md
│ ├── milstein_sampling.md
│ ├── milstein_sampling
│ │ └── sample.md
│ ├── realized_volatility.md
│ ├── sabr.md
│ └── sabr
│ │ ├── approximations.md
│ │ ├── approximations
│ │ ├── SabrApproximationType.md
│ │ ├── SabrImpliedVolatilityType.md
│ │ ├── european_option_price.md
│ │ └── implied_volatility.md
│ │ └── calibration.md
│ ├── rates.md
│ ├── rates
│ ├── README.md
│ ├── SwapCurveBuilderResult.md
│ ├── analytics.md
│ ├── analytics
│ │ ├── cashflows.md
│ │ ├── cashflows
│ │ │ ├── present_value.md
│ │ │ ├── pv_from_yields.md
│ │ │ └── yields_from_pv.md
│ │ ├── forwards.md
│ │ ├── forwards
│ │ │ ├── forward_rates.md
│ │ │ ├── forward_rates_from_yields.md
│ │ │ └── yields_from_forward_rates.md
│ │ ├── swap.md
│ │ └── swap
│ │ │ ├── equity_leg_cashflows.md
│ │ │ ├── equity_swap_price.md
│ │ │ ├── ir_swap_par_rate_and_annuity.md
│ │ │ ├── ir_swap_price.md
│ │ │ ├── rate_leg_cashflows.md
│ │ │ └── swap_price.md
│ ├── constant_fwd.md
│ ├── constant_fwd
│ │ └── interpolate.md
│ ├── forwards.md
│ ├── forwards
│ │ ├── forward_rates_from_yields.md
│ │ └── yields_from_forward_rates.md
│ ├── hagan_west.md
│ ├── hagan_west
│ │ ├── CurveBuilderResult.md
│ │ ├── README.md
│ │ ├── bond_curve.md
│ │ ├── monotone_convex.md
│ │ └── monotone_convex
│ │ │ ├── interpolate.md
│ │ │ ├── interpolate_forward_rate.md
│ │ │ └── interpolate_yields.md
│ ├── nelson_seigel_svensson.md
│ ├── nelson_seigel_svensson
│ │ ├── SvenssonParameters.md
│ │ └── interpolate.md
│ ├── swap_curve_bootstrap.md
│ └── swap_curve_fit.md
│ ├── types.md
│ ├── types
│ ├── BoolTensor.md
│ └── DateTensor.md
│ ├── utils.md
│ └── utils
│ ├── broadcast_common_batch_shape.md
│ ├── broadcast_tensors.md
│ ├── common_shape.md
│ ├── dataclass.md
│ ├── get_shape.md
│ └── iterate_nested.md
├── build_pip_pkg.sh
├── ci_build
├── Dockerfile
└── cloudbuild.yaml
├── setup.py
├── tf_quant_finance
├── BUILD
├── LICENSE
├── __init__.py
├── black_scholes
│ ├── BUILD
│ ├── README.md
│ ├── __init__.py
│ ├── approximations
│ │ ├── BUILD
│ │ ├── __init__.py
│ │ ├── american_option.py
│ │ └── american_option_test.py
│ ├── asian_prices.py
│ ├── asian_prices_test.py
│ ├── brownian_bridge.py
│ ├── brownian_bridge_test.py
│ ├── crr_binomial_tree.py
│ ├── crr_binomial_tree_test.py
│ ├── implied_vol_approximation.py
│ ├── implied_vol_approximation_test.py
│ ├── implied_vol_lib.py
│ ├── implied_vol_lib_test.py
│ ├── implied_vol_newton_root.py
│ ├── implied_vol_newton_root_test.py
│ ├── implied_vol_utils.py
│ ├── vanilla_prices.py
│ ├── vanilla_prices_test.py
│ ├── variance_swaps.py
│ └── variance_swaps_test.py
├── datetime
│ ├── BUILD
│ ├── README.md
│ ├── __init__.py
│ ├── bounded_holiday_calendar.py
│ ├── constants.py
│ ├── date_tensor.py
│ ├── date_tensor_test.py
│ ├── date_utils.py
│ ├── date_utils_test.py
│ ├── daycounts.py
│ ├── daycounts_test.py
│ ├── holiday_calendar.py
│ ├── holiday_calendar_factory.py
│ ├── holiday_calendar_test.py
│ ├── holiday_utils.py
│ ├── periods
│ │ ├── BUILD
│ │ ├── __init__.py
│ │ └── period_tensors.py
│ ├── schedules.py
│ ├── schedules_test.py
│ ├── tensor_wrapper.py
│ ├── test_data.py
│ └── unbounded_holiday_calendar.py
├── examples
│ ├── README.md
│ ├── demos
│ │ ├── README.md
│ │ └── option_pricing_basic
│ │ │ ├── common
│ │ │ ├── __init__.py
│ │ │ └── datatypes.py
│ │ │ ├── data_generator
│ │ │ ├── Dockerfile
│ │ │ ├── data_generation.py
│ │ │ ├── requirements.txt
│ │ │ └── requirements_nodeps.txt
│ │ │ ├── downloader
│ │ │ ├── Dockerfile
│ │ │ ├── app
│ │ │ │ └── main.py
│ │ │ └── requirements.txt
│ │ │ ├── k8s_configs
│ │ │ └── async_service.yaml
│ │ │ └── pricer
│ │ │ ├── Dockerfile
│ │ │ ├── app
│ │ │ ├── main.py
│ │ │ └── pricers.py
│ │ │ └── requirements.txt
│ └── jupyter_notebooks
│ │ ├── American_Option_Black_Scholes.ipynb
│ │ ├── Black_Scholes_Price_and_Implied_Vol.ipynb
│ │ ├── Dates_in_TFF.ipynb
│ │ ├── Forward_Backward_Diff.ipynb
│ │ ├── Introduction_to_TensorFlow_Part_1_-_Basics.ipynb
│ │ ├── Introduction_to_TensorFlow_Part_2_-_Debugging_and_Control_Flow.ipynb
│ │ ├── Introduction_to_TensorFlow_Part_3_-_Advanced_Tensor_Manipulation.ipynb
│ │ ├── Monte_Carlo_Euler_Scheme.ipynb
│ │ ├── Optimization.ipynb
│ │ ├── Root_Search.ipynb
│ │ ├── Swap_Curve_Fitting.ipynb
│ │ └── Vectorization_and_XLA_compilation.ipynb
├── experimental
│ ├── BUILD
│ ├── README.md
│ ├── __init__.py
│ ├── american_option_pricing
│ │ ├── BUILD
│ │ ├── __init__.py
│ │ ├── andersen_lake.py
│ │ ├── andersen_lake_test.py
│ │ ├── common.py
│ │ ├── exercise_boundary.py
│ │ └── exercise_boundary_test.py
│ ├── dev
│ │ └── Exact_Gaussian_HJM_WIP.ipynb
│ ├── finite_difference
│ │ ├── BUILD
│ │ ├── README.md
│ │ ├── __init__.py
│ │ └── methods.py
│ ├── instruments
│ │ ├── BUILD
│ │ ├── __init__.py
│ │ ├── bond.py
│ │ ├── bond_test.py
│ │ ├── cap_floor.py
│ │ ├── cap_floor_test.py
│ │ ├── cashflow_stream.py
│ │ ├── cashflow_stream_test.py
│ │ ├── cms_swap.py
│ │ ├── cms_swap_test.py
│ │ ├── eurodollar_futures.py
│ │ ├── eurodollar_futures_test.py
│ │ ├── floating_rate_note.py
│ │ ├── floating_rate_note_test.py
│ │ ├── forward_rate_agreement.py
│ │ ├── forward_rate_agreement_test.py
│ │ ├── interest_rate_swap.py
│ │ ├── interest_rate_swap_test.py
│ │ ├── overnight_index_linked_futures.py
│ │ ├── overnight_index_linked_futures_test.py
│ │ ├── rate_curve.py
│ │ ├── rate_curve_test.py
│ │ ├── rates_common.py
│ │ ├── swaption.py
│ │ └── swaption_test.py
│ ├── io.py
│ ├── io_test.py
│ ├── local_stochastic_volatility
│ │ ├── BUILD
│ │ ├── __init__.py
│ │ ├── local_stochastic_volatility_model.py
│ │ ├── local_stochastic_volatility_model_test.py
│ │ └── lsv_variance_model.py
│ ├── local_volatility
│ │ ├── BUILD
│ │ ├── __init__.py
│ │ ├── local_volatility_model.py
│ │ └── local_volatility_model_test.py
│ ├── lsm_algorithm
│ │ ├── BUILD
│ │ ├── __init__.py
│ │ ├── lsm.py
│ │ ├── lsm_test.py
│ │ ├── lsm_v2.py
│ │ ├── lsm_v2_test.py
│ │ ├── payoff.py
│ │ └── payoff_test.py
│ ├── notebooks
│ │ └── Cashflows_Rate_Curves.ipynb
│ ├── pricing_platform
│ │ ├── BUILD
│ │ ├── __init__.py
│ │ ├── framework
│ │ │ ├── BUILD
│ │ │ ├── __init__.py
│ │ │ ├── core
│ │ │ │ ├── BUILD
│ │ │ │ ├── __init__.py
│ │ │ │ ├── business_days.py
│ │ │ │ ├── currencies.py
│ │ │ │ ├── curve_types.py
│ │ │ │ ├── daycount_conventions.py
│ │ │ │ ├── implied_volatility_type.py
│ │ │ │ ├── instrument.py
│ │ │ │ ├── interpolation_method.py
│ │ │ │ ├── models.py
│ │ │ │ ├── processed_market_data.py
│ │ │ │ ├── rate_indices.py
│ │ │ │ └── types.py
│ │ │ ├── equity_instruments
│ │ │ │ ├── BUILD
│ │ │ │ ├── __init__.py
│ │ │ │ ├── american_option
│ │ │ │ │ ├── BUILD
│ │ │ │ │ ├── __init__.py
│ │ │ │ │ ├── american_option_impl.py
│ │ │ │ │ ├── american_option_impl_test.py
│ │ │ │ │ ├── proto_utils.py
│ │ │ │ │ ├── utils.py
│ │ │ │ │ └── utils_test.py
│ │ │ │ └── utils.py
│ │ │ ├── market_data
│ │ │ │ ├── BUILD
│ │ │ │ ├── README.md
│ │ │ │ ├── __init__.py
│ │ │ │ ├── market_data.md
│ │ │ │ ├── market_data.pdf
│ │ │ │ ├── market_data_config.py
│ │ │ │ ├── market_data_impl.py
│ │ │ │ ├── market_data_test.py
│ │ │ │ ├── rate_curve.py
│ │ │ │ ├── rate_curve_test.py
│ │ │ │ ├── utils.py
│ │ │ │ ├── utils_test.py
│ │ │ │ ├── volatility_surface.py
│ │ │ │ └── volatility_surface_test.py
│ │ │ ├── rate_instruments
│ │ │ │ ├── BUILD
│ │ │ │ ├── README.md
│ │ │ │ ├── __init__.py
│ │ │ │ ├── cashflow_streams.py
│ │ │ │ ├── cashflow_streams_test.py
│ │ │ │ ├── coupon_specs.py
│ │ │ │ ├── forward_rate_agreement
│ │ │ │ │ ├── BUILD
│ │ │ │ │ ├── __init__.py
│ │ │ │ │ ├── forward_rate_agreement_impl.py
│ │ │ │ │ ├── forward_rate_agreement_test.py
│ │ │ │ │ ├── proto_utils.py
│ │ │ │ │ └── proto_utils_test.py
│ │ │ │ ├── interest_rate_swap
│ │ │ │ │ ├── BUILD
│ │ │ │ │ ├── __init__.py
│ │ │ │ │ ├── interest_rate_swap_impl.py
│ │ │ │ │ ├── interest_rate_swap_test.py
│ │ │ │ │ ├── proto_utils.py
│ │ │ │ │ └── proto_utils_test.py
│ │ │ │ ├── swaption
│ │ │ │ │ ├── BUILD
│ │ │ │ │ ├── __init__.py
│ │ │ │ │ ├── proto_utils.py
│ │ │ │ │ ├── proto_utils_test.py
│ │ │ │ │ ├── swaption_impl.py
│ │ │ │ │ └── swaption_test.py
│ │ │ │ └── utils.py
│ │ │ └── utils.py
│ │ └── instrument_protos
│ │ │ ├── BUILD
│ │ │ ├── __init__.py
│ │ │ ├── all_instruments.proto
│ │ │ ├── american_equity_option.proto
│ │ │ ├── business_days.proto
│ │ │ ├── currencies.proto
│ │ │ ├── date.proto
│ │ │ ├── daycount_conventions.proto
│ │ │ ├── decimal.proto
│ │ │ ├── forward_rate_agreement.proto
│ │ │ ├── interest_rate_swap.proto
│ │ │ ├── metadata.proto
│ │ │ ├── period.proto
│ │ │ ├── rate_indices.proto
│ │ │ └── swaption.proto
│ └── svi
│ │ ├── BUILD
│ │ ├── __init__.py
│ │ ├── calibration.py
│ │ ├── calibration_test.py
│ │ ├── parameterizations.py
│ │ └── parameterizations_test.py
├── math
│ ├── BUILD
│ ├── README.md
│ ├── __init__.py
│ ├── custom_loops.py
│ ├── custom_loops_test.py
│ ├── diff_ops.py
│ ├── diff_ops_test.py
│ ├── gradient.py
│ ├── gradient_test.py
│ ├── integration
│ │ ├── BUILD
│ │ ├── __init__.py
│ │ ├── adaptive_update.py
│ │ ├── gauss_constants.py
│ │ ├── gauss_kronrod.py
│ │ ├── gauss_legendre.py
│ │ ├── integrate.py
│ │ ├── integration_test.py
│ │ └── simpson.py
│ ├── interpolation
│ │ ├── BUILD
│ │ ├── README.md
│ │ ├── __init__.py
│ │ ├── cubic
│ │ │ ├── BUILD
│ │ │ ├── __init__.py
│ │ │ ├── cubic_interpolation.py
│ │ │ └── cubic_interpolation_test.py
│ │ ├── interpolation_2d
│ │ │ ├── BUILD
│ │ │ ├── __init__.py
│ │ │ ├── interpolation_2d.py
│ │ │ └── interpolation_2d_test.py
│ │ └── linear
│ │ │ ├── BUILD
│ │ │ ├── __init__.py
│ │ │ ├── linear_interpolation.py
│ │ │ └── linear_interpolation_test.py
│ ├── jacobian.py
│ ├── jacobian_test.py
│ ├── optimizer
│ │ ├── BUILD
│ │ ├── README.md
│ │ ├── __init__.py
│ │ ├── conjugate_gradient.py
│ │ ├── conjugate_gradient_test.py
│ │ └── optimizer_test.py
│ ├── pad.py
│ ├── pad_test.py
│ ├── pde
│ │ ├── BUILD
│ │ ├── README.md
│ │ ├── __init__.py
│ │ ├── boundary_conditions.py
│ │ ├── fd_solvers.py
│ │ ├── grids.py
│ │ ├── pde_solvers.md
│ │ ├── pde_solvers.pdf
│ │ └── steppers
│ │ │ ├── BUILD
│ │ │ ├── __init__.py
│ │ │ ├── composite_stepper.py
│ │ │ ├── crank_nicolson.py
│ │ │ ├── douglas_adi.py
│ │ │ ├── douglas_adi_scheme_test.py
│ │ │ ├── explicit.py
│ │ │ ├── extrapolation.py
│ │ │ ├── implicit.py
│ │ │ ├── multidim_parabolic_equation_stepper.py
│ │ │ ├── multidim_parabolic_equation_stepper_test.py
│ │ │ ├── oscillation_damped_crank_nicolson.py
│ │ │ ├── parabolic_equation_stepper.py
│ │ │ ├── parabolic_equation_stepper_test.py
│ │ │ ├── time_marching_schemes_test.py
│ │ │ └── weighted_implicit_explicit.py
│ ├── piecewise.py
│ ├── piecewise_test.py
│ ├── qmc
│ │ ├── BUILD
│ │ ├── README.md
│ │ ├── __init__.py
│ │ ├── digital_net.py
│ │ ├── digital_net_test.py
│ │ ├── lattice_rule.py
│ │ ├── lattice_rule_test.py
│ │ ├── sobol.py
│ │ ├── sobol_test.py
│ │ ├── utils.py
│ │ └── utils_test.py
│ ├── random_ops
│ │ ├── BUILD
│ │ ├── README.md
│ │ ├── __init__.py
│ │ ├── halton
│ │ │ ├── BUILD
│ │ │ ├── __init__.py
│ │ │ ├── halton_impl.py
│ │ │ └── halton_test.py
│ │ ├── multivariate_normal.py
│ │ ├── multivariate_normal_test.py
│ │ ├── sobol
│ │ │ ├── BUILD
│ │ │ ├── __init__.py
│ │ │ ├── sobol_impl.py
│ │ │ └── sobol_test.py
│ │ ├── stateless.py
│ │ ├── stateless_test.py
│ │ ├── uniform.py
│ │ └── uniform_test.py
│ ├── root_search
│ │ ├── BUILD
│ │ ├── README.md
│ │ ├── __init__.py
│ │ ├── brent.py
│ │ ├── brent_test.py
│ │ ├── newton.py
│ │ ├── newton_test.py
│ │ └── utils.py
│ ├── segment_ops.py
│ └── segment_ops_test.py
├── models
│ ├── BUILD
│ ├── README.md
│ ├── __init__.py
│ ├── cir
│ │ ├── BUILD
│ │ ├── __init__.py
│ │ ├── cir_model.py
│ │ └── cir_test.py
│ ├── euler_sampling.py
│ ├── euler_sampling_test.py
│ ├── generic_ito_process.py
│ ├── generic_ito_process_test.py
│ ├── geometric_brownian_motion
│ │ ├── BUILD
│ │ ├── __init__.py
│ │ ├── geometric_brownian_motion_test.py
│ │ ├── geometric_brownian_motion_test_utils.py
│ │ ├── geometric_brownian_motion_test_utils_test.py
│ │ ├── multivariate_geometric_brownian_motion.py
│ │ └── univariate_geometric_brownian_motion.py
│ ├── heston
│ │ ├── BUILD
│ │ ├── __init__.py
│ │ ├── approximations
│ │ │ ├── BUILD
│ │ │ ├── __init__.py
│ │ │ ├── asian_prices.py
│ │ │ ├── asian_prices_test.py
│ │ │ ├── calibration.py
│ │ │ ├── calibration_test.py
│ │ │ ├── european_option.py
│ │ │ └── european_option_test.py
│ │ ├── heston_model.py
│ │ └── heston_model_test.py
│ ├── hjm
│ │ ├── BUILD
│ │ ├── __init__.py
│ │ ├── calibration.py
│ │ ├── calibration_test.py
│ │ ├── calibration_xla_test.py
│ │ ├── cap_floor.py
│ │ ├── cap_floor_test.py
│ │ ├── gaussian_hjm.py
│ │ ├── gaussian_hjm_test.py
│ │ ├── quasi_gaussian_hjm.py
│ │ ├── quasi_gaussian_hjm_test.py
│ │ ├── swaption_pricing.py
│ │ ├── swaption_pricing_test.py
│ │ ├── swaption_util.py
│ │ ├── zero_coupon_bond_option.py
│ │ ├── zero_coupon_bond_option_test.py
│ │ └── zero_coupon_bond_option_util.py
│ ├── hull_white
│ │ ├── BUILD
│ │ ├── __init__.py
│ │ ├── bermudan_swaption_test.py
│ │ ├── calibration.py
│ │ ├── calibration_test.py
│ │ ├── cap_floor.py
│ │ ├── cap_floor_test.py
│ │ ├── hull_white_test.py
│ │ ├── one_factor.py
│ │ ├── swaption.py
│ │ ├── swaption_test.py
│ │ ├── vector_hull_white.py
│ │ ├── zero_coupon_bond_option.py
│ │ └── zero_coupon_bond_option_test.py
│ ├── ito_process.py
│ ├── joined_ito_process.py
│ ├── joined_ito_process_test.py
│ ├── legacy
│ │ ├── BUILD
│ │ ├── README.md
│ │ ├── __init__.py
│ │ ├── brownian_motion.py
│ │ ├── brownian_motion_test.py
│ │ ├── brownian_motion_utils.py
│ │ ├── brownian_motion_utils_test.py
│ │ └── ito_process.py
│ ├── longstaff_schwartz
│ │ ├── BUILD
│ │ ├── __init__.py
│ │ ├── lsm.py
│ │ ├── lsm_test.py
│ │ ├── payoff_utils.py
│ │ └── payoff_utils_test.py
│ ├── milstein_sampling.py
│ ├── milstein_sampling_test.py
│ ├── realized_volatility.py
│ ├── realized_volatility_test.py
│ ├── sabr
│ │ ├── BUILD
│ │ ├── __init__.py
│ │ ├── approximations
│ │ │ ├── BUILD
│ │ │ ├── __init__.py
│ │ │ ├── calibration.py
│ │ │ ├── calibration_test.py
│ │ │ ├── european_options.py
│ │ │ ├── european_options_test.py
│ │ │ ├── implied_volatility.py
│ │ │ └── implied_volatility_test.py
│ │ ├── sabr_model.py
│ │ └── sabr_model_test.py
│ ├── utils.py
│ ├── utils_test.py
│ └── valuation_method.py
├── rates
│ ├── BUILD
│ ├── README.md
│ ├── __init__.py
│ ├── analytics
│ │ ├── BUILD
│ │ ├── README.md
│ │ ├── __init__.py
│ │ ├── cashflows.py
│ │ ├── cashflows_test.py
│ │ ├── forwards.py
│ │ ├── forwards_test.py
│ │ ├── swap.py
│ │ └── swap_test.py
│ ├── constant_fwd
│ │ ├── BUILD
│ │ ├── __init__.py
│ │ ├── constant_fwd_interpolation.py
│ │ └── constant_fwd_interpolation_test.py
│ ├── forwards.py
│ ├── hagan_west
│ │ ├── BUILD
│ │ ├── README.md
│ │ ├── __init__.py
│ │ ├── bond_curve.py
│ │ ├── bond_curve_test.py
│ │ ├── monotone_convex.py
│ │ └── monotone_convex_test.py
│ ├── nelson_seigel_svensson
│ │ ├── BUILD
│ │ ├── __init__.py
│ │ ├── nelson_seigel_svensson_interpolation.py
│ │ └── nelson_seigel_svensson_interpolation_test.py
│ ├── swap_curve_bootstrap.py
│ ├── swap_curve_common.py
│ ├── swap_curve_fit.py
│ └── swap_curve_test.py
├── types
│ ├── BUILD
│ ├── README
│ ├── __init__.py
│ └── data_types.py
└── utils
│ ├── BUILD
│ ├── README
│ ├── __init__.py
│ ├── dataclass.py
│ ├── dataclass_test.py
│ ├── shape_utils.py
│ ├── shape_utils_test.py
│ ├── tf_functions.py
│ └── tf_functions_test.py
└── third_party
└── sobol_data
├── BUILD
├── LICENSE
├── README.md
├── new-joe-kuo-6.21201
└── sobol_data.h
/BUILD:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | sh_binary(
16 | name = "build_pip_pkg",
17 | srcs = ["build_pip_pkg.sh"],
18 | data = [
19 | "LICENSE",
20 | "MANIFEST.in",
21 | "README.md",
22 | "setup.py",
23 | "//tf_quant_finance",
24 | "//third_party/sobol_data:LICENSE",
25 | "//third_party/sobol_data:new-joe-kuo-6.21201",
26 | ],
27 | )
28 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # How to Contribute
2 |
3 | We'd love to accept your patches and contributions to this project. There are
4 | just a few small guidelines you need to follow.
5 |
6 | ## Contributor License Agreement
7 |
8 | Contributions to this project must be accompanied by a Contributor License
9 | Agreement. You (or your employer) retain the copyright to your contribution;
10 | this simply gives us permission to use and redistribute your contributions as
11 | part of the project. Head over to to see
12 | your current agreements on file or to sign a new one.
13 |
14 | You generally only need to submit a CLA once, so if you've already submitted one
15 | (even if it was for a different project), you probably don't need to do it
16 | again.
17 |
18 | ## Code reviews
19 |
20 | All submissions, including submissions by project members, require review. We
21 | use GitHub pull requests for this purpose. Consult
22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more
23 | information on using pull requests.
24 |
25 | ## Community Guidelines
26 |
27 | This project follows [Google's Open Source Community
28 | Guidelines](https://opensource.google.com/conduct/).
29 |
--------------------------------------------------------------------------------
/MANIFEST.in:
--------------------------------------------------------------------------------
1 | recursive-include tf_quant_finance/third_party/ *
2 |
--------------------------------------------------------------------------------
/WORKSPACE:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | # ============================================================================
15 | workspace(name = "tf_quant_finance")
16 |
17 | load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
18 |
19 |
20 | # Load repository with py_proto_library definition
21 | http_archive(
22 | name = "com_google_protobuf",
23 | sha256 = "bba884e1dce7b9ba5bce566bfa2d23ea2c824aa928a9133139c5485cefa69139",
24 | urls = ["https://github.com/protocolbuffers/protobuf/archive/9ce8c330e736b99c2bb00bdc6a60f00ab600c283.zip"],
25 | strip_prefix = "protobuf-9ce8c330e736b99c2bb00bdc6a60f00ab600c283",
26 | )
27 |
28 | load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
29 |
30 | protobuf_deps()
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/black_scholes/AveragingFrequency.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | # tf_quant_finance.black_scholes.AveragingFrequency
16 |
17 |
18 |
19 |
21 |
22 | View source
23 |
24 |
25 |
26 | Averaging types for asian options.
27 |
28 |
29 |
30 | * `DISCRETE`: Option samples on discrete times
31 | * `CONTINUOUS`: Option samples continuously throughout lifetime
32 |
33 | ## Class Variables
34 |
35 | * `CONTINUOUS`
36 | * `DISCRETE`
37 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/black_scholes/AveragingType.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | # tf_quant_finance.black_scholes.AveragingType
16 |
17 |
18 |
19 |
21 |
22 | View source
23 |
24 |
25 |
26 | Averaging types for asian options.
27 |
28 |
29 |
30 | * `GEOMETRIC`: C = ( \prod S(t_i) ) ^ {\frac{1}{n}}
31 | * `ARITHMETIC`: C = \frac{1}{n} \sum S(t_i)
32 |
33 | ## Class Variables
34 |
35 | * `ARITHMETIC`
36 | * `GEOMETRIC`
37 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/black_scholes/ImpliedVolMethod.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | # tf_quant_finance.black_scholes.ImpliedVolMethod
16 |
17 |
18 |
19 |
21 |
22 | View source
23 |
24 |
25 |
26 | Implied volatility methods.
27 |
28 |
29 |
30 | * `FAST_APPROX`: A faster but approximate method.
31 | * `NEWTON`: Uses Newton root search to find an accurate value.
32 |
33 | ## Class Variables
34 |
35 | * `FAST_APPROX`
36 | * `NEWTON`
37 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/black_scholes/ImpliedVolUnderlyingDistribution.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | # tf_quant_finance.black_scholes.ImpliedVolUnderlyingDistribution
16 |
17 |
18 |
19 |
21 |
22 | View source
23 |
24 |
25 |
26 | Underying's distribution.
27 |
28 |
29 |
30 | * `LOG_NORMAL`: Lognormal distribution for the standard Black-Scholes models.
31 | * `NORMAL`: Normal distribution used in Bachelier model.
32 |
33 | ## Class Variables
34 |
35 | * `LOG_NORMAL`
36 | * `NORMAL`
37 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/black_scholes/README.md:
--------------------------------------------------------------------------------
1 | # Black Scholes Tools
2 |
3 | This module contains implementation of well-known results from the Black Scholes
4 | model. This includes analytically known pricing expressions (or approximations)
5 | for various derivatives as well as methods to compute implied volatility from
6 | prices.
7 |
8 | ## Pricing
9 |
10 | Currently, the following pricing formula are available:
11 | * Vanilla calls and puts.
12 | * Binary options.
13 |
14 |
15 | ## Utilities
16 |
17 | A very common task in finance is to convert market prices of options into
18 | implied volatilities. While there is no exact closed-form expression for this,
19 | this module provides methods to compute approximations. The available methods
20 | are:
21 |
22 | * A fast but approximate method to infer implied volatility based on the Polya
23 | approximation of the Normal CDF. This was proposed by Radiocic and Stefanica
24 | in Ref [1].
25 | * A more precise method based on Newton root finder. This method uses the
26 | Radiocic & Stefanica algorithm to initialize the root finder.
27 |
28 |
29 | ## References
30 |
31 | [1]: Dan Stefanica and Rados Radoicic. An explicit implied volatility formula.
32 | International Journal of Theoretical and Applied Finance,
33 | Vol. 20, no. 7, 2017.
34 | https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2908494
35 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/black_scholes/approximations.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.black_scholes.approximations
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Approximations to the black scholes formula.
25 |
26 |
27 |
28 | ## Functions
29 |
30 | [`adesi_whaley(...)`](../../tf_quant_finance/black_scholes/approximations/adesi_whaley.md): Computes American option prices using the Baron-Adesi Whaley approximation.
31 |
32 | [`bjerksund_stensland(...)`](../../tf_quant_finance/black_scholes/approximations/bjerksund_stensland.md): Computes prices of a batch of American options using Bjerksund-Stensland.
33 |
34 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/datetime/PeriodType.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | # tf_quant_finance.datetime.PeriodType
18 |
19 |
20 |
21 |
23 |
24 | View source
25 |
26 |
27 |
28 | Periods that can be added or subtracted from DateTensors.
29 |
30 |
31 |
32 |
33 | ## Class Variables
34 |
35 | * `DAY`
36 | * `MONTH`
37 | * `WEEK`
38 | * `YEAR`
39 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/datetime/WeekDay.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 | # tf_quant_finance.datetime.WeekDay
21 |
22 |
23 |
24 |
26 |
27 | View source
28 |
29 |
30 |
31 | Named days of the week. Values are zero-based with Monday = 0.
32 |
33 |
34 |
35 |
36 | ## Class Variables
37 |
38 | * `FRIDAY`
39 | * `MONDAY`
40 | * `SATURDAY`
41 | * `SUNDAY`
42 | * `THURSDAY`
43 | * `TUESDAY`
44 | * `WEDNESDAY`
45 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/datetime/WeekendMask.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 | # tf_quant_finance.datetime.WeekendMask
18 |
19 |
20 |
21 |
23 |
24 | View source
25 |
26 |
27 |
28 | Provides weekend masks for some of the common weekend patterns.
29 |
30 |
31 |
32 |
33 | ## Class Variables
34 |
35 | * `FRIDAY_SATURDAY`
36 | * `NONE`
37 | * `SATURDAY_SUNDAY`
38 | * `SUNDAY_ONLY`
39 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/datetime/dates_from_datetimes.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.datetime.dates_from_datetimes
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Creates DateTensor from a sequence of Python datetime objects.
25 |
26 | ```python
27 | tf_quant_finance.datetime.dates_from_datetimes(
28 | datetimes
29 | )
30 | ```
31 |
32 |
33 |
34 |
35 |
36 |
37 | #### Args:
38 |
39 |
40 | * `datetimes`: Sequence of Python datetime objects.
41 |
42 |
43 | #### Returns:
44 |
45 | DateTensor object.
46 |
47 |
48 | #### Example
49 |
50 | ```python
51 | import datetime
52 |
53 | dates = [datetime.date(2015, 4, 15), datetime.date(2017, 12, 30)]
54 | date_tensor = tff.datetime.dates_from_datetimes(dates)
55 | ```
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/datetime/dates_from_ordinals.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.datetime.dates_from_ordinals
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Creates DateTensor from tensors of ordinals.
25 |
26 | ```python
27 | tf_quant_finance.datetime.dates_from_ordinals(
28 | ordinals, validate=True
29 | )
30 | ```
31 |
32 |
33 |
34 |
35 |
36 |
37 | #### Args:
38 |
39 |
40 | * `ordinals`: Tensor of type int32. Each value is number of days since 1 Jan
41 | 0001. 1 Jan 0001 has `ordinal=1`.
42 | * `validate`: Whether to validate the dates.
43 |
44 |
45 | #### Returns:
46 |
47 | DateTensor object.
48 |
49 |
50 | #### Example
51 |
52 | ```python
53 | ordinals = tf.constant([
54 | 735703, # 2015-4-12
55 | 736693 # 2017-12-30
56 | ], dtype=tf.int32)
57 |
58 | date_tensor = tff.datetime.dates_from_ordinals(ordinals)
59 | ```
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/datetime/dates_from_tuples.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.datetime.dates_from_tuples
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Creates DateTensor from a sequence of year-month-day Tuples.
25 |
26 | ```python
27 | tf_quant_finance.datetime.dates_from_tuples(
28 | year_month_day_tuples, validate=True
29 | )
30 | ```
31 |
32 |
33 |
34 |
35 |
36 |
37 | #### Args:
38 |
39 |
40 | * `year_month_day_tuples`: Sequence of (year, month, day) Tuples. Months are
41 | 1-based; constants from Months enum can be used instead of ints. Days are
42 | also 1-based.
43 | * `validate`: Whether to validate the dates.
44 |
45 |
46 | #### Returns:
47 |
48 | DateTensor object.
49 |
50 |
51 | #### Example
52 |
53 | ```python
54 | date_tensor = tff.datetime.dates_from_tuples([(2015, 4, 15), (2017, 12, 30)])
55 | ```
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/datetime/periods/day.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.datetime.periods.day
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 |
25 |
26 | ```python
27 | tf_quant_finance.datetime.periods.day()
28 | ```
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/datetime/periods/days.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.datetime.periods.days
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 |
25 |
26 | ```python
27 | tf_quant_finance.datetime.periods.days(
28 | n
29 | )
30 | ```
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/datetime/periods/month.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.datetime.periods.month
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 |
25 |
26 | ```python
27 | tf_quant_finance.datetime.periods.month()
28 | ```
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/datetime/periods/months.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.datetime.periods.months
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 |
25 |
26 | ```python
27 | tf_quant_finance.datetime.periods.months(
28 | n
29 | )
30 | ```
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/datetime/periods/week.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.datetime.periods.week
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 |
25 |
26 | ```python
27 | tf_quant_finance.datetime.periods.week()
28 | ```
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/datetime/periods/weeks.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.datetime.periods.weeks
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 |
25 |
26 | ```python
27 | tf_quant_finance.datetime.periods.weeks(
28 | n
29 | )
30 | ```
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/datetime/periods/year.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.datetime.periods.year
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 |
25 |
26 | ```python
27 | tf_quant_finance.datetime.periods.year()
28 | ```
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/datetime/periods/years.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.datetime.periods.years
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 |
25 |
26 | ```python
27 | tf_quant_finance.datetime.periods.years(
28 | n
29 | )
30 | ```
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/datetime/utils/is_leap_year.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.datetime.utils.is_leap_year
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Calculates whether years are leap years.
25 |
26 | ```python
27 | tf_quant_finance.datetime.utils.is_leap_year(
28 | years
29 | )
30 | ```
31 |
32 |
33 |
34 |
35 |
36 |
37 | #### Args:
38 |
39 |
40 | * `years`: Tensor of int32 type. Elements should be positive.
41 |
42 |
43 | #### Returns:
44 |
45 | Tensor of bool type.
46 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/datetime/utils/ordinal_to_year_month_day.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.datetime.utils.ordinal_to_year_month_day
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Calculates years, months and dates Tensor given ordinals Tensor.
25 |
26 | ```python
27 | tf_quant_finance.datetime.utils.ordinal_to_year_month_day(
28 | ordinals
29 | )
30 | ```
31 |
32 |
33 |
34 |
35 |
36 |
37 | #### Args:
38 |
39 |
40 | * `ordinals`: Tensor of int32 type. Each element is number of days since 1 Jan
41 | 0001. 1 Jan 0001 has `ordinal = 1`.
42 |
43 |
44 | #### Returns:
45 |
46 | Tuple (years, months, days), each element is an int32 Tensor of the same
47 | shape as `ordinals`. `months` and `days` are one-based.
48 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/experimental/README.md:
--------------------------------------------------------------------------------
1 | # Experimental/Research module
2 |
3 | This module contains code related to ongoing research/experimental projects.
4 | None of the methods in this module are exported to the main library.
5 |
6 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/experimental/american_option_pricing.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.experimental.american_option_pricing
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | American option pricing method.
25 |
26 |
27 |
28 | ## Modules
29 |
30 | [`andersen_lake`](../../tf_quant_finance/experimental/american_option_pricing/andersen_lake.md) module: Calculating American option prices with Andersen-Lake approximation.
31 |
32 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/experimental/american_option_pricing/andersen_lake/d_minus.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.experimental.american_option_pricing.andersen_lake.d_minus
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 |
25 |
26 | ```python
27 | tf_quant_finance.experimental.american_option_pricing.andersen_lake.d_minus(
28 | tau, z, r, q, sigma
29 | )
30 | ```
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/experimental/american_option_pricing/andersen_lake/d_plus.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.experimental.american_option_pricing.andersen_lake.d_plus
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 |
25 |
26 | ```python
27 | tf_quant_finance.experimental.american_option_pricing.andersen_lake.d_plus(
28 | tau, z, r, q, sigma
29 | )
30 | ```
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/experimental/american_option_pricing/andersen_lake/divide_with_positive_denominator.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.experimental.american_option_pricing.andersen_lake.divide_with_positive_denominator
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Safely divides by a denominator which is mathematically always positive, but numerically can be zero.
25 |
26 | ```python
27 | tf_quant_finance.experimental.american_option_pricing.andersen_lake.divide_with_positive_denominator(
28 | a, b
29 | )
30 | ```
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/experimental/american_option_pricing/andersen_lake/machine_eps.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.experimental.american_option_pricing.andersen_lake.machine_eps
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Returns the machine epsilon for the supplied dtype.
25 |
26 | ```python
27 | tf_quant_finance.experimental.american_option_pricing.andersen_lake.machine_eps(
28 | dtype
29 | )
30 | ```
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/experimental/american_option_pricing/andersen_lake/standard_normal_cdf.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.experimental.american_option_pricing.andersen_lake.standard_normal_cdf
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 |
25 |
26 | ```python
27 | tf_quant_finance.experimental.american_option_pricing.andersen_lake.standard_normal_cdf(
28 | a
29 | )
30 | ```
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/experimental/instruments/AverageType.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | # tf_quant_finance.experimental.instruments.AverageType
16 |
17 |
18 |
19 |
21 |
22 | View source
23 |
24 |
25 |
26 | Averaging types.
27 |
28 |
29 |
30 |
31 | ## Class Variables
32 |
33 | * `ARITHMETIC_AVERAGE`
34 | * `COMPOUNDING`
35 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/experimental/instruments/DayCountConvention.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | # tf_quant_finance.experimental.instruments.DayCountConvention
17 |
18 |
19 |
20 |
22 |
23 | View source
24 |
25 |
26 |
27 | Day count conventions for accrual.
28 |
29 |
30 |
31 |
32 | ## Class Variables
33 |
34 | * `ACTUAL_360`
35 | * `ACTUAL_365`
36 | * `THIRTY_360_ISDA`
37 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/experimental/io/decode_array.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.experimental.io.decode_array
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Decodes a bytestring into a numpy array.
25 |
26 | ```python
27 | tf_quant_finance.experimental.io.decode_array(
28 | bytestring
29 | )
30 | ```
31 |
32 |
33 |
34 |
35 |
36 | The bytestring should be a serialized `TensorProto` instance. For more details
37 | see `tf.make_tensor_proto`.
38 |
39 | #### Args:
40 |
41 |
42 | * `bytestring`: The serialized `TensorProto`.
43 |
44 |
45 | #### Returns:
46 |
47 | A numpy array.
48 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/experimental/io/encode_array.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.experimental.io.encode_array
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Encodes a numpy array using `TensorProto` protocol buffer.
25 |
26 | ```python
27 | tf_quant_finance.experimental.io.encode_array(
28 | x
29 | )
30 | ```
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/experimental/local_stochastic_volatility.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.experimental.local_stochastic_volatility
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Local volatility model.
25 |
26 |
27 |
28 | ## Classes
29 |
30 | [`class LSVVarianceModel`](../../tf_quant_finance/experimental/local_stochastic_volatility/LSVVarianceModel.md): Implements Heston like variance process for the LSV models.
31 |
32 | [`class LocalStochasticVolatilityModel`](../../tf_quant_finance/experimental/local_stochastic_volatility/LocalStochasticVolatilityModel.md): Local stochastic volatility model.
33 |
34 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/experimental/local_volatility.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.experimental.local_volatility
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Local volatility model.
25 |
26 |
27 |
28 | ## Classes
29 |
30 | [`class LocalVolatilityModel`](../../tf_quant_finance/experimental/local_volatility/LocalVolatilityModel.md): Local volatility model for smile modeling.
31 |
32 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/experimental/svi.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.experimental.svi
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | SVI model.
25 |
26 |
27 |
28 | ## Functions
29 |
30 | [`calibration(...)`](../../tf_quant_finance/experimental/svi/calibration.md): Calibrates the SVI model parameters for a batch of volatility skews.
31 |
32 | [`implied_volatility_from_raw_svi_parameters(...)`](../../tf_quant_finance/experimental/svi/implied_volatility_from_raw_svi_parameters.md): Computes modeled implied volatility using raw SVI parameters.
33 |
34 | [`total_variance_from_raw_svi_parameters(...)`](../../tf_quant_finance/experimental/svi/total_variance_from_raw_svi_parameters.md): Computes modeled total variance using raw SVI parameters.
35 |
36 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/README.md:
--------------------------------------------------------------------------------
1 | # Ops for numerical methods.
2 |
3 | This module provides ops to perform various mathematical tasks commonly needed
4 | when building quantitative finance models. We do not aim to provide
5 | exhaustive coverage here. [Tensorflow](https://github.com/tensorflow/tensorflow)
6 | and [Tensorflow Probability](https://github.com/tensorflow/probability) provide
7 | a significant suite of methods already and the methods here are meant to
8 | build on those.
9 |
10 | Some of the modules/functions provided are:
11 |
12 | * [math.interpolation](interpolation): Ops to perform linear and
13 | cubic interpolation.
14 | * [math.optimizer](optimizer): Ops for numerical optimization.
15 | * [math.pde](pde): Ops to numerically solve partial differential
16 | equations using finite difference methods. Currently, only linear second
17 | order PDEs are supported as this is the most commonly needed case.
18 | * [math.random](random): Ops to compute low discrepancy sequences.
19 | * [math.root_search](root_search.py): Provides the Brent method for computing
20 | roots of functions in one dimension.
21 | * [math.segment_ops](segment_ops.py): Utility methods to apply some element
22 | wise ops in a segment.
23 |
24 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/custom_loops.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.math.custom_loops
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Custom implementations of loops for improved performance.
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/integration/IntegrationMethod.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | # tf_quant_finance.math.integration.IntegrationMethod
16 |
17 |
18 |
19 |
21 |
22 | View source
23 |
24 |
25 |
26 | Specifies which algorithm to use for the numeric integration.
27 |
28 |
29 |
30 | * `COMPOSITE_SIMPSONS_RULE`: Composite Simpson's 1/3 rule.
31 | * `GAUSS_LEGENDRE`: Gauss-Legendre quadrature method.
32 |
33 | ## Class Variables
34 |
35 | * `COMPOSITE_SIMPSONS_RULE`
36 | * `GAUSS_LEGENDRE`
37 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/interpolation.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.math.interpolation
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Ops related to interpolation.
25 |
26 |
27 |
28 | ## Modules
29 |
30 | [`cubic`](../../tf_quant_finance/math/interpolation/cubic.md) module: Cubic spline interpolation methods.
31 |
32 | [`interpolation_2d`](../../tf_quant_finance/math/interpolation/interpolation_2d.md) module: 2D - interpolation.
33 |
34 | [`linear`](../../tf_quant_finance/math/interpolation/linear.md) module: Linear interpolation.
35 |
36 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/interpolation/README.md:
--------------------------------------------------------------------------------
1 | # Interpolation Methods
2 |
3 | This module provides methods to perform linear and cubic interpolation.
4 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/interpolation/cubic.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.math.interpolation.cubic
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Cubic spline interpolation methods.
25 |
26 |
27 |
28 | ## Classes
29 |
30 | [`class BoundaryConditionType`](../../../tf_quant_finance/math/interpolation/cubic/BoundaryConditionType.md): Specifies which boundary condition type to use for the cubic interpolation.
31 |
32 | [`class SplineParameters`](../../../tf_quant_finance/math/interpolation/cubic/SplineParameters.md): Cubic spline parameters.
33 |
34 | ## Functions
35 |
36 | [`build_spline(...)`](../../../tf_quant_finance/math/interpolation/cubic/build_spline.md): Builds a SplineParameters interpolation object.
37 |
38 | [`interpolate(...)`](../../../tf_quant_finance/math/interpolation/cubic/interpolate.md): Interpolates spline values for the given `x` and the `spline_data`.
39 |
40 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/interpolation/interpolation_2d.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.math.interpolation.interpolation_2d
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | 2D - interpolation.
25 |
26 |
27 |
28 | ## Classes
29 |
30 | [`class Interpolation2D`](../../../tf_quant_finance/math/interpolation/interpolation_2d/Interpolation2D.md): Performs interpolation in a 2-dimensional space.
31 |
32 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/interpolation/linear.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.math.interpolation.linear
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Linear interpolation.
25 |
26 |
27 |
28 | ## Functions
29 |
30 | [`interpolate(...)`](../../../tf_quant_finance/math/interpolation/linear/interpolate.md): Performs linear interpolation for supplied points.
31 |
32 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/optimizer/README.md:
--------------------------------------------------------------------------------
1 | # Numerical Optimization Methods
2 |
3 | This module provides ops for numerical optimization.
4 |
5 | It includes the following optimization algorithms:
6 |
7 | * BFGS optimizer
8 | * L-BFGS optimizer
9 | * Nelder-Mead optimizer
10 | * Conjugate Gradient optimizer
11 |
12 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/optimizer/converged_all.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.math.optimizer.converged_all
14 |
15 |
16 |
17 |
19 |
20 |
21 |
22 | Condition to stop when all batch members have converged or failed.
23 |
24 | ```python
25 | tf_quant_finance.math.optimizer.converged_all(
26 | converged, failed
27 | )
28 | ```
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/optimizer/converged_any.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.math.optimizer.converged_any
14 |
15 |
16 |
17 |
19 |
20 |
21 |
22 | Condition to stop when any batch member converges, or all have failed.
23 |
24 | ```python
25 | tf_quant_finance.math.optimizer.converged_any(
26 | converged, failed
27 | )
28 | ```
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/optimizer/nelder_mead_one_step.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.math.optimizer.nelder_mead_one_step
14 |
15 |
16 |
17 |
19 |
20 |
21 |
22 | A single iteration of the Nelder Mead algorithm.
23 |
24 | ```python
25 | tf_quant_finance.math.optimizer.nelder_mead_one_step(
26 | current_simplex, current_objective_values, objective_function=None, dim=None,
27 | func_tolerance=None, position_tolerance=None, batch_evaluate_objective=False,
28 | reflection=None, expansion=None, contraction=None, shrinkage=None, name=None
29 | )
30 | ```
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/pad.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.math.pad
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Helper functions for padding multiple tensors.
25 |
26 |
27 |
28 | ## Functions
29 |
30 | [`pad_date_tensors(...)`](../../tf_quant_finance/math/pad/pad_date_tensors.md): Pads the innermost dimension of `DateTensor`s to a common shape.
31 |
32 | [`pad_tensors(...)`](../../tf_quant_finance/math/pad/pad_tensors.md): Pads the innermost dimension of `Tensor`s to a common shape.
33 |
34 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/pde.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.math.pde
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | PDE solver methods.
25 |
26 |
27 |
28 | ## Modules
29 |
30 | [`boundary_conditions`](../../tf_quant_finance/math/pde/boundary_conditions.md) module: Helper functions to construct boundary conditions of PDEs.
31 |
32 | [`fd_solvers`](../../tf_quant_finance/math/pde/fd_solvers.md) module: Functions for solving linear parabolic PDEs.
33 |
34 | [`grids`](../../tf_quant_finance/math/pde/grids.md) module: Functions to create grids suitable for PDE pricing.
35 |
36 | [`steppers`](../../tf_quant_finance/math/pde/steppers.md) module: Steppers for PDE solvers.
37 |
38 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/pde/README.md:
--------------------------------------------------------------------------------
1 | # Partial Differential Equation Solvers
2 |
3 | This package provides ops to compute numerical solutions of linear parabolic
4 | partial differential equations. See [pde_solvers.pdf](pde_solvers.pdf) for a
5 | detailed guide.
6 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/pde/boundary_conditions.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.math.pde.boundary_conditions
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Helper functions to construct boundary conditions of PDEs.
25 |
26 |
27 |
28 | ## Functions
29 |
30 | [`dirichlet(...)`](../../../tf_quant_finance/math/pde/boundary_conditions/dirichlet.md): Wrapper for Dirichlet boundary conditions to be used in PDE solvers.
31 |
32 | [`neumann(...)`](../../../tf_quant_finance/math/pde/boundary_conditions/neumann.md): Wrapper for Neumann boundary condition to be used in PDE solvers.
33 |
34 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/pde/fd_solvers.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.math.pde.fd_solvers
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Functions for solving linear parabolic PDEs.
25 |
26 |
27 |
28 | ## Functions
29 |
30 | [`solve_backward(...)`](../../../tf_quant_finance/math/pde/fd_solvers/solve_backward.md): Evolves a grid of function values backwards in time according to a PDE.
31 |
32 | [`solve_forward(...)`](../../../tf_quant_finance/math/pde/fd_solvers/solve_forward.md): Evolves a grid of function values forward in time according to a PDE.
33 |
34 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/pde/pde_solvers.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/tf-quant-finance/4c4b57e9808f5b60184d8fd5f7f43aaf5871313b/api_docs/tf_quant_finance/math/pde/pde_solvers.pdf
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/pde/steppers/composite_stepper.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.math.pde.steppers.composite_stepper
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Composition of two time marching schemes.
25 |
26 |
27 |
28 | ## Functions
29 |
30 | [`composite_scheme_step(...)`](../../../../tf_quant_finance/math/pde/steppers/composite_stepper/composite_scheme_step.md): Composes two time marching schemes.
31 |
32 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/pde/steppers/crank_nicolson.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.math.pde.steppers.crank_nicolson
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Crank-Nicolson time marching scheme for parabolic PDEs.
25 |
26 |
27 |
28 | ## Functions
29 |
30 | [`crank_nicolson_scheme(...)`](../../../../tf_quant_finance/math/pde/steppers/crank_nicolson/crank_nicolson_scheme.md): Constructs the time marching scheme.
31 |
32 | [`crank_nicolson_step(...)`](../../../../tf_quant_finance/math/pde/steppers/crank_nicolson/crank_nicolson_step.md): Creates a stepper function with Crank-Nicolson time marching scheme.
33 |
34 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/pde/steppers/crank_nicolson/crank_nicolson_scheme.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.math.pde.steppers.crank_nicolson.crank_nicolson_scheme
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Constructs the time marching scheme.
25 |
26 | ```python
27 | tf_quant_finance.math.pde.steppers.crank_nicolson.crank_nicolson_scheme(
28 | value_grid, t1, t2, equation_params_fn
29 | )
30 | ```
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/pde/steppers/douglas_adi.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.math.pde.steppers.douglas_adi
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Douglas ADI method for solving multidimensional parabolic PDEs.
25 |
26 |
27 |
28 | ## Functions
29 |
30 | [`douglas_adi_scheme(...)`](../../../../tf_quant_finance/math/pde/steppers/douglas_adi/douglas_adi_scheme.md): Applies Douglas time marching scheme (see [1] and Eq. 3.1 in [2]).
31 |
32 | [`douglas_adi_step(...)`](../../../../tf_quant_finance/math/pde/steppers/douglas_adi/douglas_adi_step.md): Creates a stepper function with Crank-Nicolson time marching scheme.
33 |
34 | [`multidim_parabolic_equation_step(...)`](../../../../tf_quant_finance/math/pde/steppers/douglas_adi/multidim_parabolic_equation_step.md): Performs one step in time to solve a multidimensional PDE.
35 |
36 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/pde/steppers/explicit.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.math.pde.steppers.explicit
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Explicit time marching scheme for parabolic PDEs.
25 |
26 |
27 |
28 | ## Functions
29 |
30 | [`explicit_scheme(...)`](../../../../tf_quant_finance/math/pde/steppers/explicit/explicit_scheme.md): Constructs the time marching scheme.
31 |
32 | [`explicit_step(...)`](../../../../tf_quant_finance/math/pde/steppers/explicit/explicit_step.md): Creates a stepper function with explicit time marching scheme.
33 |
34 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/pde/steppers/explicit/explicit_scheme.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.math.pde.steppers.explicit.explicit_scheme
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Constructs the time marching scheme.
25 |
26 | ```python
27 | tf_quant_finance.math.pde.steppers.explicit.explicit_scheme(
28 | value_grid, t1, t2, equation_params_fn
29 | )
30 | ```
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/pde/steppers/extrapolation.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.math.pde.steppers.extrapolation
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Extrapolation time marching scheme for parabolic PDEs.
25 |
26 |
27 |
28 | ## Functions
29 |
30 | [`extrapolation_scheme(...)`](../../../../tf_quant_finance/math/pde/steppers/extrapolation/extrapolation_scheme.md): Constructs extrapolation implicit-explicit scheme.
31 |
32 | [`extrapolation_step(...)`](../../../../tf_quant_finance/math/pde/steppers/extrapolation/extrapolation_step.md): Creates a stepper function with Extrapolation time marching scheme.
33 |
34 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/pde/steppers/implicit.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.math.pde.steppers.implicit
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Implicit time marching scheme for parabolic PDEs.
25 |
26 |
27 |
28 | ## Functions
29 |
30 | [`implicit_scheme(...)`](../../../../tf_quant_finance/math/pde/steppers/implicit/implicit_scheme.md): Constructs the time marching scheme.
31 |
32 | [`implicit_step(...)`](../../../../tf_quant_finance/math/pde/steppers/implicit/implicit_step.md): Creates a stepper function with implicit time marching scheme.
33 |
34 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/pde/steppers/implicit/implicit_scheme.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.math.pde.steppers.implicit.implicit_scheme
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Constructs the time marching scheme.
25 |
26 | ```python
27 | tf_quant_finance.math.pde.steppers.implicit.implicit_scheme(
28 | value_grid, t1, t2, equation_params_fn
29 | )
30 | ```
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/pde/steppers/multidim_parabolic_equation_stepper.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.math.pde.steppers.multidim_parabolic_equation_stepper
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Stepper for multidimensional parabolic PDE solving.
25 |
26 |
27 |
28 | ## Functions
29 |
30 | [`multidim_parabolic_equation_step(...)`](../../../../tf_quant_finance/math/pde/steppers/douglas_adi/multidim_parabolic_equation_step.md): Performs one step in time to solve a multidimensional PDE.
31 |
32 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/pde/steppers/oscillation_damped_crank_nicolson.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.math.pde.steppers.oscillation_damped_crank_nicolson
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Crank-Nicolson with oscillation damping time marching scheme.
25 |
26 |
27 |
28 | ## Functions
29 |
30 | [`oscillation_damped_crank_nicolson_step(...)`](../../../../tf_quant_finance/math/pde/steppers/oscillation_damped_crank_nicolson/oscillation_damped_crank_nicolson_step.md): Scheme similar to Crank-Nicolson, but ensuring damping of oscillations.
31 |
32 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/pde/steppers/parabolic_equation_stepper.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.math.pde.steppers.parabolic_equation_stepper
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Stepper for parabolic PDEs solving.
25 |
26 |
27 |
28 | ## Functions
29 |
30 | [`parabolic_equation_step(...)`](../../../../tf_quant_finance/math/pde/steppers/parabolic_equation_stepper/parabolic_equation_step.md): Performs one step of the one dimensional parabolic PDE solver.
31 |
32 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/pde/steppers/weighted_implicit_explicit.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.math.pde.steppers.weighted_implicit_explicit
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Weighted implicit-explicit time marching scheme for parabolic PDEs.
25 |
26 |
27 |
28 | ## Functions
29 |
30 | [`weighted_implicit_explicit_scheme(...)`](../../../../tf_quant_finance/math/pde/steppers/weighted_implicit_explicit/weighted_implicit_explicit_scheme.md): Constructs weighted implicit-explicit scheme.
31 |
32 | [`weighted_implicit_explicit_step(...)`](../../../../tf_quant_finance/math/pde/steppers/weighted_implicit_explicit/weighted_implicit_explicit_step.md): Creates a stepper function with weighted implicit-explicit scheme.
33 |
34 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/piecewise.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.math.piecewise
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Piecewise utility functions.
25 |
26 |
27 |
28 | ## Classes
29 |
30 | [`class PiecewiseConstantFunc`](../../tf_quant_finance/math/piecewise/PiecewiseConstantFunc.md): Creates a piecewise constant function.
31 |
32 | ## Functions
33 |
34 | [`convert_to_tensor_or_func(...)`](../../tf_quant_finance/math/piecewise/convert_to_tensor_or_func.md): Returns either a `PiecewiseConstantFunc` or x converted to a `Tensor`.
35 |
36 | [`find_interval_index(...)`](../../tf_quant_finance/math/piecewise/find_interval_index.md): Function to find the index of the interval where query points lies.
37 |
38 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/qmc/utils/exp2.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.math.qmc.utils.exp2
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Returns the point-wise base-2 exponentiation of a given `Tensor`.
25 |
26 | ```python
27 | tf_quant_finance.math.qmc.utils.exp2(
28 | value
29 | )
30 | ```
31 |
32 |
33 |
34 |
35 |
36 |
37 | #### Args:
38 |
39 |
40 | * `value`: Positive scalar `Tensor` of integers.
41 |
42 | #### Examples
43 |
44 | ```python
45 | import tensorflow as tf
46 | import tf_quant_finance as tff
47 |
48 | # Example: Computing the base-2 exponentiation of a range.
49 |
50 | tff.math.qmc.utils.exp2(tf.range(0, 5))
51 | # ==> tf.Tensor([1, 2, 4, 8, 16], shape=(5,), dtype=int32)
52 | ```
53 |
54 | #### Returns:
55 |
56 | `Tensor` with the same `shape` and `dtype` as `value` equal to `1 << value`.
57 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/qmc/utils/get_shape.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.math.qmc.utils.get_shape
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Returns the `shape` of a given `Tensor`.
25 |
26 | ```python
27 | tf_quant_finance.math.qmc.utils.get_shape(
28 | value
29 | )
30 | ```
31 |
32 |
33 |
34 |
35 |
36 |
37 | #### Args:
38 |
39 |
40 | * `value`: Scalar `Tensor of integers or real values.
41 |
42 |
43 | #### Returns:
44 |
45 | `Tensor` of integers with rank 1.
46 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/qmc/utils/log2.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.math.qmc.utils.log2
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Returns the point-wise base-2 logarithm a given `Tensor`.
25 |
26 | ```python
27 | tf_quant_finance.math.qmc.utils.log2(
28 | value
29 | )
30 | ```
31 |
32 |
33 |
34 |
35 |
36 | ```python
37 | import tensorflow as tf
38 | import tf_quant_finance as tff
39 |
40 | # Example: Computing the base-2 logarithm of a given vector.
41 |
42 | tff.math.qmc.utils.log2(tf.constant([1, 2, 4, 8, 16], dtype=tf.float32))
43 | # ==> tf.Tensor([0., 1., 2., 3., 4.], shape=(5,), dtype=float32)
44 | ```
45 |
46 | #### Args:
47 |
48 |
49 | * `value`: Positive scalar `Tensor` of real values.
50 |
51 |
52 | #### Returns:
53 |
54 | `Tensor` with the same `shape` and `dtype` as `value` equal to `ln(value) /
55 | ln(2)`.
56 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/random/halton.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.math.random.halton
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Halton sampling.
25 |
26 |
27 |
28 | ## Functions
29 |
30 | [`sample(...)`](../../../tf_quant_finance/math/random/halton/sample.md): Returns a sample from the `dim` dimensional Halton sequence.
31 |
32 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/random/sobol.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.math.random.sobol
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Sobol sampling.
25 |
26 |
27 |
28 | ## Functions
29 |
30 | [`load_data(...)`](../../../tf_quant_finance/math/random/sobol/load_data.md): Parses file 'new-joe-kuo-6.21201'.
31 |
32 | [`sample(...)`](../../../tf_quant_finance/math/random/sobol/sample.md): Returns num_results samples from the Sobol sequence of dimension dim.
33 |
34 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/random/sobol/load_data.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.math.random.sobol.load_data
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Parses file 'new-joe-kuo-6.21201'.
25 |
26 | ```python
27 | tf_quant_finance.math.random.sobol.load_data()
28 | ```
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/random_ops/README.md:
--------------------------------------------------------------------------------
1 | # Random and Low Discrepancy Sequences.
2 |
3 | This directory contains ops to efficiently generate random numbers and
4 | quasi-random low discrepancy sequences.
5 |
6 | For the random numbers, [TensorFlow](tensorflow.org) and
7 | [TensorFlow Probability](https://www.tensorflow.org/probability)
8 | already contain significant support. This module provides Sobol and Halton
9 | low discrepancy sequences as well as a multivariate normal sampler which
10 | supports using these sequences (i.e. draws from a gaussian copula with low
11 | discrepancy sequences).
12 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/root_search.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.math.root_search
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Ops related to root search.
25 |
26 |
27 |
28 | ## Functions
29 |
30 | [`brentq(...)`](../../tf_quant_finance/math/root_search/brentq.md): Finds root(s) of a function of single variable using Brent's method.
31 |
32 | [`newton_root(...)`](../../tf_quant_finance/math/root_search/newton_root.md): Finds roots of a scalar function using Newton's method.
33 |
34 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/math/segment_ops.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.math.segment_ops
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Element wise ops acting on segments of arrays.
25 |
26 |
27 |
28 | ## Functions
29 |
30 | [`segment_cumsum(...)`](../../tf_quant_finance/math/segment_ops/segment_cumsum.md): Computes cumulative sum of elements in a segment.
31 |
32 | [`segment_diff(...)`](../../tf_quant_finance/math/segment_ops/segment_diff.md): Computes difference of successive elements in a segment.
33 |
34 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/models/PathScale.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | # tf_quant_finance.models.PathScale
16 |
17 |
18 |
19 |
21 |
22 | View source
23 |
24 |
25 |
26 | Represents what scale a path is on.
27 |
28 |
29 |
30 | * `ORIGINAL`: Represents a path on its original scale.
31 | * `LOG`: Represents log scale values of a path.
32 |
33 | ## Class Variables
34 |
35 | * `LOG`
36 | * `ORIGINAL`
37 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/models/ReturnsType.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | # tf_quant_finance.models.ReturnsType
16 |
17 |
18 |
19 |
21 |
22 | View source
23 |
24 |
25 |
26 | Represents types of return processes.
27 |
28 |
29 |
30 | * `ABS`: Represents absolute returns.
31 | * `LOG`: Represents log returns.
32 |
33 | ## Class Variables
34 |
35 | * `ABS`
36 | * `LOG`
37 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/models/ValuationMethod.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | # tf_quant_finance.models.ValuationMethod
17 |
18 |
19 |
20 |
22 |
23 | View source
24 |
25 |
26 |
27 | Valuation methods.
28 |
29 |
30 |
31 | * `ANALYTIC`: Analytic valuation.
32 | * `MONTE_CARLO`: Valuation using Monte carlo simulations.
33 | * `FINITE_DIFFERENCE`: Valuation using finite difference methods/PDEs.
34 |
35 | ## Class Variables
36 |
37 | * `ANALYTIC`
38 | * `FINITE_DIFFERENCE`
39 | * `MONTE_CARLO`
40 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/models/cir.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.models.cir
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | CIR model.
25 |
26 |
27 |
28 | ## Classes
29 |
30 | [`class CirModel`](../../tf_quant_finance/models/cir/CirModel.md): Cox–Ingersoll–Ross model.
31 |
32 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/models/euler_sampling.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.models.euler_sampling
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | The Euler sampling method for ito processes.
25 |
26 |
27 |
28 | ## Functions
29 |
30 | [`sample(...)`](../../tf_quant_finance/models/euler_sampling/sample.md): Returns a sample paths from the process using Euler method.
31 |
32 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/models/heston.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.models.heston
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Heston model.
25 |
26 |
27 |
28 | ## Modules
29 |
30 | [`approximations`](../../tf_quant_finance/models/heston/approximations.md) module: Approximations to the Heston model.
31 |
32 | ## Classes
33 |
34 | [`class HestonModel`](../../tf_quant_finance/models/HestonModel.md): Heston Model with piecewise constant parameters.
35 |
36 | ## Functions
37 |
38 | [`calibration(...)`](../../tf_quant_finance/models/heston/calibration.md): Calibrates the Heston model using European option prices.
39 |
40 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/models/heston/approximations.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.models.heston.approximations
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Approximations to the Heston model.
25 |
26 |
27 |
28 | ## Functions
29 |
30 | [`asian_option_price(...)`](../../../tf_quant_finance/models/heston/approximations/asian_option_price.md): Computes the Heston price for a batch of asian options.
31 |
32 | [`calibration(...)`](../../../tf_quant_finance/models/heston/calibration.md): Calibrates the Heston model using European option prices.
33 |
34 | [`european_option_price(...)`](../../../tf_quant_finance/models/heston/approximations/european_option_price.md): Calculates European option prices under the Heston model.
35 |
36 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/models/legacy/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/tf-quant-finance/4c4b57e9808f5b60184d8fd5f7f43aaf5871313b/api_docs/tf_quant_finance/models/legacy/README.md
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/models/longstaff_schwartz.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.models.longstaff_schwartz
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | LSM algorithm methods.
25 |
26 |
27 |
28 | ## Functions
29 |
30 | [`least_square_mc(...)`](../../tf_quant_finance/models/longstaff_schwartz/least_square_mc.md): Values Amercian style options using the LSM algorithm.
31 |
32 | [`make_basket_put_payoff(...)`](../../tf_quant_finance/models/longstaff_schwartz/make_basket_put_payoff.md): Produces a callable from samples to payoff of a simple basket put option.
33 |
34 | [`make_polynomial_basis(...)`](../../tf_quant_finance/models/longstaff_schwartz/make_polynomial_basis.md): Produces a callable from samples to polynomial basis for use in regression.
35 |
36 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/models/milstein_sampling.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.models.milstein_sampling
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | The Milstein sampling method for ito processes.
25 |
26 |
27 |
28 | ## Functions
29 |
30 | [`sample(...)`](../../tf_quant_finance/models/milstein_sampling/sample.md): Returns a sample paths from the process using the Milstein method.
31 |
32 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/models/sabr.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.models.sabr
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Sabr model.
25 |
26 |
27 |
28 | ## Modules
29 |
30 | [`approximations`](../../tf_quant_finance/models/sabr/approximations.md) module: Approximate analytic solutions to the Sabr model.
31 |
32 | ## Classes
33 |
34 | [`class SabrModel`](../../tf_quant_finance/models/SabrModel.md): Implements the SABR model defined by the following equations.
35 |
36 | ## Functions
37 |
38 | [`calibration(...)`](../../tf_quant_finance/models/sabr/calibration.md): Calibrates the SABR model using European option prices.
39 |
40 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/models/sabr/approximations/SabrApproximationType.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 | # tf_quant_finance.models.sabr.approximations.SabrApproximationType
15 |
16 |
17 |
18 |
20 |
21 | View source
22 |
23 |
24 |
25 | Approximation to the SABR model.
26 |
27 |
28 |
29 | * `HAGAN`: Using the Hagan approximation [1].
30 |
31 | #### References
32 | [1] Hagan et al, Managing Smile Risk, Wilmott (2002), 1:84-108
33 |
34 | ## Class Variables
35 |
36 | * `HAGAN`
37 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/rates/README.md:
--------------------------------------------------------------------------------
1 | # Utilities related to rates.
2 |
3 | This module is a toolbox for performing common tasks related to interest rates.
4 | This includes some common pricing functions for swaps and bonds and for building
5 | and interpolating from rate curves.
6 |
7 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/rates/analytics.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.rates.analytics
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Functions to handle rates.
25 |
26 |
27 |
28 | ## Modules
29 |
30 | [`cashflows`](../../tf_quant_finance/rates/analytics/cashflows.md) module: Collection of functions to compute properties of cashflows.
31 |
32 | [`forwards`](../../tf_quant_finance/rates/analytics/forwards.md) module: Collection of functions to compute properties of forwards.
33 |
34 | [`swap`](../../tf_quant_finance/rates/analytics/swap.md) module: Collection of functions to create interest rate and equity swaps.
35 |
36 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/rates/analytics/cashflows.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.rates.analytics.cashflows
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Collection of functions to compute properties of cashflows.
25 |
26 |
27 |
28 | ## Functions
29 |
30 | [`present_value(...)`](../../../tf_quant_finance/rates/analytics/cashflows/present_value.md): Computes present value of a stream of cashflows given discount factors.
31 |
32 | [`pv_from_yields(...)`](../../../tf_quant_finance/rates/analytics/cashflows/pv_from_yields.md): Computes present value of cashflows given yields.
33 |
34 | [`yields_from_pv(...)`](../../../tf_quant_finance/rates/analytics/cashflows/yields_from_pv.md): Computes yields to maturity from present values of cashflows.
35 |
36 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/rates/analytics/forwards.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.rates.analytics.forwards
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Collection of functions to compute properties of forwards.
25 |
26 |
27 |
28 | ## Functions
29 |
30 | [`forward_rates(...)`](../../../tf_quant_finance/rates/analytics/forwards/forward_rates.md): Computes forward rates from daycount fractions and discount factors.
31 |
32 | [`forward_rates_from_yields(...)`](../../../tf_quant_finance/rates/analytics/forwards/forward_rates_from_yields.md): Computes forward rates given a set of zero rates.
33 |
34 | [`yields_from_forward_rates(...)`](../../../tf_quant_finance/rates/analytics/forwards/yields_from_forward_rates.md): Computes yield rates from discrete forward rates.
35 |
36 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/rates/constant_fwd.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.rates.constant_fwd
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Constant forward interpolation.
25 |
26 |
27 |
28 | ## Functions
29 |
30 | [`interpolate(...)`](../../tf_quant_finance/rates/constant_fwd/interpolate.md): Performs the constant forward interpolation for supplied points.
31 |
32 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/rates/forwards.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.rates.forwards
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Collection of functions to compute properties of forwards.
25 |
26 |
27 |
28 | ## Functions
29 |
30 | [`forward_rates_from_yields(...)`](../../tf_quant_finance/rates/forwards/forward_rates_from_yields.md): Computes forward rates given a set of zero rates. (deprecated)
31 |
32 | [`yields_from_forward_rates(...)`](../../tf_quant_finance/rates/forwards/yields_from_forward_rates.md): Computes yield rates from discrete forward rates. (deprecated)
33 |
34 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/rates/hagan_west.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.rates.hagan_west
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Hagan West algorithm for rate interpolation and bootstrapping.
25 |
26 |
27 |
28 | ## Modules
29 |
30 | [`monotone_convex`](../../tf_quant_finance/rates/hagan_west/monotone_convex.md) module: The monotone convex interpolation method.
31 |
32 | ## Classes
33 |
34 | [`class CurveBuilderResult`](../../tf_quant_finance/rates/hagan_west/CurveBuilderResult.md): Bond curve calibration results.
35 |
36 | ## Functions
37 |
38 | [`bond_curve(...)`](../../tf_quant_finance/rates/hagan_west/bond_curve.md): Constructs the bond discount rate curve using the Hagan-West algorithm.
39 |
40 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/rates/hagan_west/README.md:
--------------------------------------------------------------------------------
1 | # Hagan West Algorithm
2 |
3 |
4 | This module contains an implementation of the Hagan West procedure for
5 | bootstrapping and interpolating interest rate curves. The algorithm applies
6 | quadratic interpolation to the forward curve and the rate curve is computed
7 | by integrating the interpolated forward curve.
8 |
9 | The current implementation only supports building curves from bonds. The swap
10 | curve building will be added shortly.
11 |
12 | #TODO(b/140370128): Support swap curve building.
13 | #TODO(b/140370679): Add amelioration and positivity constraints.
14 |
15 |
16 | ## References
17 |
18 | [1]: Patrick Hagan & Graeme West. Interpolation Methods for Curve
19 | Construction. Applied Mathematical Finance. Vol 13, No. 2, pp 89-129.
20 | June 2006.
21 | https://www.researchgate.net/publication/24071726_Interpolation_Methods_for_Curve_Construction
22 |
23 | [2]: Patrick Hagan & Graeme West. Methods for Constructing a Yield Curve.
24 | Wilmott Magazine, pp. 70-81. May 2008.
25 | https://www.researchgate.net/profile/Patrick_Hagan3/publication/228463045_Methods_for_constructing_a_yield_curve/links/54db8cda0cf23fe133ad4d01.pdf
26 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/rates/nelson_seigel_svensson.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # Module: tf_quant_finance.rates.nelson_seigel_svensson
14 |
15 |
16 |
17 |
19 |
20 | View source
21 |
22 |
23 |
24 | Nelson Seigel Svensson interpolation.
25 |
26 |
27 |
28 | ## Classes
29 |
30 | [`class SvenssonParameters`](../../tf_quant_finance/rates/nelson_seigel_svensson/SvenssonParameters.md): Nelson Seigel Svensson interpolation parameters.
31 |
32 | ## Functions
33 |
34 | [`interpolate(...)`](../../tf_quant_finance/rates/nelson_seigel_svensson/interpolate.md): Performs Nelson Seigel Svensson interpolation for supplied points.
35 |
36 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/types/BoolTensor.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.types.BoolTensor
14 |
15 |
16 |
17 |
19 |
20 |
21 |
22 |
23 |
24 | ```python
25 | tf_quant_finance.types.BoolTensor(
26 | *args, **kwargs
27 | )
28 | ```
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/api_docs/tf_quant_finance/types/DateTensor.md:
--------------------------------------------------------------------------------
1 |
5 |
6 | *Last updated: 2023-03-16.*
7 |
8 |
9 |
10 |
11 |
12 |
13 | # tf_quant_finance.types.DateTensor
14 |
15 |
16 |
17 |
19 |
20 |
21 |
22 |
23 |
24 | ```python
25 | tf_quant_finance.types.DateTensor(
26 | *args, **kwargs
27 | )
28 | ```
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/ci_build/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM ubuntu:focal
2 |
3 | # sudo isn't really needed, but we include it for convenience
4 | RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y curl wget build-essential rsync sudo python3 python3-dev python3-distutils python-is-python3 git
5 |
6 | # Install the latest version of pip.
7 | RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
8 | RUN python3 get-pip.py
9 |
10 | # Install Bazel
11 | RUN echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list
12 | RUN curl https://bazel.build/bazel-release.pub.gpg | sudo apt-key add -
13 | RUN sudo apt-get update && sudo apt-get install -y bazel
14 |
15 | # Install pip packages
16 | RUN python3 -m pip install --upgrade numpy==1.22
17 | RUN python3 -m pip install --upgrade keras==2.12.0rc1 tensorboard==2.12 tensorflow==2.12.0rc1 tensorflow-probability==0.19.0 attrs
18 | RUN python3 -m pip install --upgrade protobuf==3.20.3
19 |
20 | # Change work directory
21 | WORKDIR /workspace
22 |
23 | ENTRYPOINT ["bazel"]
24 |
25 |
26 |
--------------------------------------------------------------------------------
/ci_build/cloudbuild.yaml:
--------------------------------------------------------------------------------
1 | steps:
2 | - name: gcr.io/cloud-builders/docker
3 | args:
4 | - build
5 | - '-t'
6 | - 'gcr.io/$PROJECT_ID/bazel-local:latest'
7 | - '-f'
8 | - '/workspace/ci_build/Dockerfile'
9 | - .
10 | id: Build Docker image
11 | - name: gcr.io/$PROJECT_ID/bazel-local
12 | args:
13 | - test
14 | - tf_quant_finance/...
15 | - '--test_summary=detailed'
16 | - '--test_output=errors'
17 | id: Run bazel test
18 | entrypoint: bazel
19 | timeout: 7200s
20 | logsBucket: 'gs://$_LOGS_BUCKET/'
21 | options:
22 | machineType: E2_HIGHCPU_32
23 | queueTtl: 1200s
24 |
--------------------------------------------------------------------------------
/tf_quant_finance/black_scholes/README.md:
--------------------------------------------------------------------------------
1 | # Black Scholes Tools
2 |
3 | This module contains implementation of well-known results from the Black Scholes
4 | model. This includes analytically known pricing expressions (or approximations)
5 | for various derivatives as well as methods to compute implied volatility from
6 | prices.
7 |
8 | ## Pricing
9 |
10 | Currently, the following pricing formula are available:
11 | * Vanilla calls and puts.
12 | * Binary options.
13 |
14 |
15 | ## Utilities
16 |
17 | A very common task in finance is to convert market prices of options into
18 | implied volatilities. While there is no exact closed-form expression for this,
19 | this module provides methods to compute approximations. The available methods
20 | are:
21 |
22 | * A fast but approximate method to infer implied volatility based on the Polya
23 | approximation of the Normal CDF. This was proposed by Radiocic and Stefanica
24 | in Ref [1].
25 | * A more precise method based on Newton root finder. This method uses the
26 | Radiocic & Stefanica algorithm to initialize the root finder.
27 |
28 |
29 | ## References
30 |
31 | [1]: Dan Stefanica and Rados Radoicic. An explicit implied volatility formula.
32 | International Journal of Theoretical and Applied Finance,
33 | Vol. 20, no. 7, 2017.
34 | https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2908494
35 |
--------------------------------------------------------------------------------
/tf_quant_finance/black_scholes/approximations/BUILD:
--------------------------------------------------------------------------------
1 | # Approximation methods in Black-Scholes market.
2 |
3 | # Placeholder: load py_library
4 | # Placeholder: load py_test
5 |
6 | package(
7 | default_visibility = ["//tf_quant_finance:__subpackages__"],
8 | licenses = ["notice"],
9 | )
10 |
11 | py_library(
12 | name = "approximations",
13 | srcs = ["__init__.py"],
14 | deps = [
15 | ":american_option",
16 | # tensorflow dep,
17 | ],
18 | )
19 |
20 | py_library(
21 | name = "american_option",
22 | srcs = ["american_option.py"],
23 | deps = [
24 | "//tf_quant_finance/black_scholes:implied_vol_newton_root",
25 | "//tf_quant_finance/black_scholes:vanilla_prices",
26 | "//tf_quant_finance/math",
27 | "//tf_quant_finance/math/root_search:newton",
28 | "//tf_quant_finance/types",
29 | # numpy dep,
30 | # tensorflow dep,
31 | ],
32 | )
33 |
34 | py_test(
35 | name = "american_option_test",
36 | srcs = ["american_option_test.py"],
37 | shard_count = 6,
38 | deps = [
39 | "//tf_quant_finance",
40 | # test util,
41 | # absl/testing:parameterized dep,
42 | # numpy dep,
43 | # tensorflow dep,
44 | ],
45 | )
46 |
--------------------------------------------------------------------------------
/tf_quant_finance/black_scholes/approximations/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Approximations to the black scholes formula."""
15 |
16 | from tf_quant_finance.black_scholes.approximations.american_option import adesi_whaley
17 | from tf_quant_finance.black_scholes.approximations.american_option import bjerksund_stensland
18 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
19 |
20 | _allowed_symbols = [
21 | 'adesi_whaley',
22 | 'bjerksund_stensland',
23 | ]
24 |
25 | remove_undocumented(__name__, _allowed_symbols)
26 |
--------------------------------------------------------------------------------
/tf_quant_finance/black_scholes/implied_vol_utils.py:
--------------------------------------------------------------------------------
1 | # Copyright 2021 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Util that is common to implied volitility implementations."""
15 |
16 | import enum
17 |
18 |
19 | @enum.unique
20 | class UnderlyingDistribution(enum.Enum):
21 | """Underying's distribution.
22 |
23 | * `LOG_NORMAL`: Lognormal distribution for the standard Black-Scholes models.
24 | * `NORMAL`: Normal distribution used in Bachelier model.
25 | """
26 | LOG_NORMAL = 1
27 | NORMAL = 2
28 |
--------------------------------------------------------------------------------
/tf_quant_finance/datetime/periods/BUILD:
--------------------------------------------------------------------------------
1 | # TODO(cyrilchimisov): describe this package.
2 |
3 | # Placeholder: load py_library
4 |
5 | package(
6 | default_visibility = ["//tf_quant_finance:__subpackages__"],
7 | licenses = ["notice"],
8 | )
9 |
10 | py_library(
11 | name = "periods",
12 | srcs = ["__init__.py"],
13 | deps = [
14 | ":period_tensors",
15 | # tensorflow dep,
16 | ],
17 | )
18 |
19 | py_library(
20 | name = "period_tensors",
21 | srcs = ["period_tensors.py"],
22 | deps = [
23 | "//tf_quant_finance/datetime:constants",
24 | "//tf_quant_finance/datetime:tensor_wrapper",
25 | # tensorflow dep,
26 | ],
27 | )
28 |
--------------------------------------------------------------------------------
/tf_quant_finance/examples/demos/README.md:
--------------------------------------------------------------------------------
1 | # Demos
2 |
--------------------------------------------------------------------------------
/tf_quant_finance/examples/demos/option_pricing_basic/common/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/tf-quant-finance/4c4b57e9808f5b60184d8fd5f7f43aaf5871313b/tf_quant_finance/examples/demos/option_pricing_basic/common/__init__.py
--------------------------------------------------------------------------------
/tf_quant_finance/examples/demos/option_pricing_basic/data_generator/requirements.txt:
--------------------------------------------------------------------------------
1 | attrs >= 18.2.0
2 | google-cloud-storage==1.28.0
3 | tf-nightly
4 | tfp-nightly
5 |
--------------------------------------------------------------------------------
/tf_quant_finance/examples/demos/option_pricing_basic/data_generator/requirements_nodeps.txt:
--------------------------------------------------------------------------------
1 | tff-nightly
2 |
--------------------------------------------------------------------------------
/tf_quant_finance/examples/demos/option_pricing_basic/downloader/requirements.txt:
--------------------------------------------------------------------------------
1 | Flask==1.1.2
2 | requests==2.23.0
3 | google-cloud-storage==1.28.0
4 | absl-py==0.9.0
5 | pyzmq==19.0.0
6 | numpy==1.21
7 |
--------------------------------------------------------------------------------
/tf_quant_finance/examples/demos/option_pricing_basic/pricer/Dockerfile:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | # An image to price options using TFF.
16 | # To build the image, it is necessary that docker build be invoked from the
17 | # parent folder of this file (i.e. from inside option_pricing_basic.).
18 | # Example container execution command:
19 | # $ docker build -f ./pricer/Dockerfile -t pricer .
20 | # $ docker run --name pricer-app -v /var/tmp/:/var/tmp/ -it pricer
21 | # With default settings, the process running in the container will expect
22 | # compute requests to arrive at ipc:///var/tmp/ipc/jobs.
23 |
24 | FROM python:3
25 |
26 | COPY ./pricer/requirements.txt /app/
27 |
28 | RUN pip install -r /app/requirements.txt
29 |
30 | COPY ./pricer/app /app/
31 | COPY ./common /app/common/
32 |
33 | VOLUME ["/var/tmp/"]
34 |
35 | WORKDIR /app
36 | ENTRYPOINT ["python3", "main.py"]
37 | CMD ["--alsologtostderr"]
38 |
--------------------------------------------------------------------------------
/tf_quant_finance/examples/demos/option_pricing_basic/pricer/requirements.txt:
--------------------------------------------------------------------------------
1 | absl-py==0.9.0
2 | pyzmq==19.0.0
3 | numpy==1.22.0
4 | tf-nightly
5 | tfp-nightly
6 | tff-nightly
7 |
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/BUILD:
--------------------------------------------------------------------------------
1 | # Experimental modules.
2 |
3 | # Placeholder: load py_library
4 | # Placeholder: load py_test
5 |
6 | package(
7 | default_visibility = ["//tf_quant_finance:__subpackages__"],
8 | licenses = ["notice"],
9 | )
10 |
11 | py_library(
12 | name = "experimental",
13 | srcs = ["__init__.py"],
14 | deps = [
15 | ":io",
16 | "//tf_quant_finance/experimental/american_option_pricing",
17 | "//tf_quant_finance/experimental/finite_difference",
18 | "//tf_quant_finance/experimental/instruments",
19 | "//tf_quant_finance/experimental/local_stochastic_volatility",
20 | "//tf_quant_finance/experimental/local_volatility",
21 | "//tf_quant_finance/experimental/lsm_algorithm",
22 | "//tf_quant_finance/experimental/pricing_platform",
23 | "//tf_quant_finance/experimental/svi",
24 | ],
25 | )
26 |
27 | filegroup(
28 | name = "docs",
29 | srcs = [
30 | "README.md",
31 | ],
32 | data = [
33 | "//tf_quant_finance/experimental/finite_difference:docs",
34 | ],
35 | )
36 |
37 | py_library(
38 | name = "io",
39 | srcs = ["io.py"],
40 | deps = [
41 | # numpy dep,
42 | # tensorflow dep,
43 | ],
44 | )
45 |
46 | py_test(
47 | name = "io_test",
48 | size = "small",
49 | srcs = ["io_test.py"],
50 | shard_count = 2,
51 | deps = [
52 | "//tf_quant_finance",
53 | # test util,
54 | # numpy dep,
55 | # tensorflow dep,
56 | ],
57 | )
58 |
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/README.md:
--------------------------------------------------------------------------------
1 | # Experimental/Research module
2 |
3 | This module contains code related to ongoing research/experimental projects.
4 | None of the methods in this module are exported to the main library.
5 |
6 |
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/american_option_pricing/__init__.py:
--------------------------------------------------------------------------------
1 | """American option pricing method."""
2 |
3 | from tf_quant_finance.experimental.american_option_pricing import andersen_lake
4 | from tf_quant_finance.experimental.american_option_pricing import exercise_boundary
5 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
6 |
7 |
8 | _allowed_symbols = [
9 | 'andersen_lake',
10 | ]
11 |
12 | remove_undocumented(__name__, _allowed_symbols)
13 |
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/finite_difference/BUILD:
--------------------------------------------------------------------------------
1 | # Finite difference methods.
2 |
3 | # Placeholder: load py_library
4 |
5 | package(
6 | default_visibility = ["//tf_quant_finance:__subpackages__"],
7 | licenses = ["notice"],
8 | )
9 |
10 | py_library(
11 | name = "finite_difference",
12 | srcs = ["__init__.py"],
13 | deps = [
14 | ":methods",
15 | ],
16 | )
17 |
18 | py_library(
19 | name = "methods",
20 | srcs = ["methods.py"],
21 | deps = [
22 | # autograd dep,
23 | # pandas dep,
24 | # sobol_seq dep,
25 | ],
26 | )
27 |
28 | filegroup(
29 | name = "docs",
30 | srcs = [
31 | "README.md",
32 | ],
33 | )
34 |
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/finite_difference/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | """Finite difference methods."""
16 |
17 | from tf_quant_finance.experimental.finite_difference import methods
18 |
19 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
20 |
21 | _allowed_symbols = [
22 | 'methods',
23 | ]
24 |
25 | remove_undocumented(__name__, _allowed_symbols)
26 |
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/local_stochastic_volatility/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Local volatility model."""
15 |
16 | from tf_quant_finance.experimental.local_stochastic_volatility.local_stochastic_volatility_model import LocalStochasticVolatilityModel
17 | from tf_quant_finance.experimental.local_stochastic_volatility.lsv_variance_model import LSVVarianceModel
18 |
19 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
20 |
21 | _allowed_symbols = [
22 | "LocalStochasticVolatilityModel",
23 | "LSVVarianceModel",
24 | ]
25 |
26 | remove_undocumented(__name__, _allowed_symbols)
27 |
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/local_volatility/BUILD:
--------------------------------------------------------------------------------
1 | # Local volatility model.
2 |
3 | # Placeholder: load py_library
4 | # Placeholder: load py_test
5 |
6 | package(
7 | default_visibility = ["//tf_quant_finance:__subpackages__"],
8 | licenses = ["notice"],
9 | )
10 |
11 | py_library(
12 | name = "local_volatility",
13 | srcs = ["__init__.py"],
14 | deps = [
15 | ":local_volatility_model",
16 | ],
17 | )
18 |
19 | py_library(
20 | name = "local_volatility_model",
21 | srcs = ["local_volatility_model.py"],
22 | deps = [
23 | "//tf_quant_finance/black_scholes",
24 | "//tf_quant_finance/datetime",
25 | "//tf_quant_finance/experimental/pricing_platform/framework/market_data:volatility_surface",
26 | "//tf_quant_finance/math",
27 | "//tf_quant_finance/math:piecewise",
28 | "//tf_quant_finance/math/interpolation",
29 | "//tf_quant_finance/models:euler_sampling",
30 | "//tf_quant_finance/models:generic_ito_process",
31 | "//tf_quant_finance/models:utils",
32 | # tensorflow dep,
33 | ],
34 | )
35 |
36 | py_test(
37 | name = "local_volatility_model_test",
38 | size = "large",
39 | timeout = "long",
40 | srcs = ["local_volatility_model_test.py"],
41 | shard_count = 30,
42 | tags = [
43 | "nomsan", # TODO(b/231568581)
44 | "notsan",
45 | ],
46 | deps = [
47 | "//tf_quant_finance",
48 | # test util,
49 | ],
50 | )
51 |
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/local_volatility/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | """Local volatility model."""
16 |
17 | from tf_quant_finance.experimental.local_volatility.local_volatility_model import LocalVolatilityModel
18 |
19 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
20 |
21 | _allowed_symbols = [
22 | "LocalVolatilityModel",
23 | ]
24 |
25 | remove_undocumented(__name__, _allowed_symbols)
26 |
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/pricing_platform/BUILD:
--------------------------------------------------------------------------------
1 | # Pricing platform
2 |
3 | # Placeholder: load py_library
4 |
5 | package(
6 | default_visibility = ["//visibility:public"],
7 | licenses = ["notice"],
8 | )
9 |
10 | py_library(
11 | name = "pricing_platform",
12 | srcs = ["__init__.py"],
13 | deps = [
14 | "//tf_quant_finance/experimental/pricing_platform/framework",
15 | "//tf_quant_finance/experimental/pricing_platform/instrument_protos",
16 | ],
17 | )
18 |
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/pricing_platform/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Pricing platform module."""
15 |
16 | from tf_quant_finance.experimental.pricing_platform import framework
17 | from tf_quant_finance.experimental.pricing_platform import instrument_protos
18 |
19 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
20 |
21 | _allowed_symbols = [
22 | "instrument_protos",
23 | "framework",
24 | ]
25 |
26 | remove_undocumented(__name__, _allowed_symbols)
27 |
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/pricing_platform/framework/BUILD:
--------------------------------------------------------------------------------
1 | # Framework for building graphs for portfolio pricing.
2 |
3 | # Placeholder: load py_library
4 |
5 | package(
6 | default_visibility = ["//tf_quant_finance:__subpackages__"],
7 | licenses = ["notice"],
8 | )
9 |
10 | py_library(
11 | name = "framework",
12 | srcs = ["__init__.py"],
13 | deps = [
14 | "//tf_quant_finance/experimental/pricing_platform/framework/core",
15 | "//tf_quant_finance/experimental/pricing_platform/framework/equity_instruments",
16 | "//tf_quant_finance/experimental/pricing_platform/framework/market_data",
17 | "//tf_quant_finance/experimental/pricing_platform/framework/rate_instruments",
18 | ],
19 | )
20 |
21 | py_library(
22 | name = "utils",
23 | srcs = ["utils.py"],
24 | )
25 |
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/pricing_platform/framework/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Framework module."""
15 |
16 | from tf_quant_finance.experimental.pricing_platform.framework import core
17 | from tf_quant_finance.experimental.pricing_platform.framework import equity_instruments
18 | from tf_quant_finance.experimental.pricing_platform.framework import market_data
19 | from tf_quant_finance.experimental.pricing_platform.framework import rate_instruments
20 |
21 |
22 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
23 |
24 | _allowed_symbols = [
25 | "core",
26 | "equity_instruments",
27 | "market_data",
28 | "rate_instruments",
29 | ]
30 |
31 | remove_undocumented(__name__, _allowed_symbols)
32 |
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/pricing_platform/framework/core/implied_volatility_type.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Supported implied volatilities."""
15 |
16 | import enum
17 |
18 |
19 | class ImpliedVolatilityType(enum.Enum):
20 | SWAPTION_NORMAL = 1
21 | SWAPTION_LOGNORMAL = 2
22 |
23 |
24 | __all__ = ["ImpliedVolatilityType"]
25 |
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/pricing_platform/framework/core/interpolation_method.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Supported interpolation methods."""
15 |
16 | import enum
17 |
18 |
19 | class InterpolationMethod(enum.Enum):
20 | LINEAR = "LINEAR"
21 | CUBIC = "CUBIC"
22 | CONSTANT_FORWARD = "CONSTANT_FORWARD"
23 |
24 |
25 | __all__ = ["InterpolationMethod"]
26 |
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/pricing_platform/framework/equity_instruments/BUILD:
--------------------------------------------------------------------------------
1 | # Equity instruments module
2 |
3 | # Placeholder: load py_library
4 |
5 | package(
6 | default_visibility = ["//tf_quant_finance:__subpackages__"],
7 | licenses = ["notice"],
8 | )
9 |
10 | py_library(
11 | name = "equity_instruments",
12 | srcs = ["__init__.py"],
13 | deps = [
14 | ":utils",
15 | "//tf_quant_finance/experimental/pricing_platform/framework/equity_instruments/american_option",
16 | ],
17 | )
18 |
19 | py_library(
20 | name = "utils",
21 | srcs = ["utils.py"],
22 | deps = [
23 | "//tf_quant_finance/experimental/pricing_platform/instrument_protos",
24 | ],
25 | )
26 |
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/pricing_platform/framework/equity_instruments/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Rate instruments module."""
15 |
16 | from tf_quant_finance.experimental.pricing_platform.framework.equity_instruments import american_option
17 | from tf_quant_finance.experimental.pricing_platform.framework.equity_instruments import utils
18 |
19 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
20 |
21 | _allowed_symbols = [
22 | "american_option",
23 | "utils",
24 | ]
25 |
26 | remove_undocumented(__name__, _allowed_symbols)
27 |
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/pricing_platform/framework/equity_instruments/american_option/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Equity American Option."""
15 |
16 | from tf_quant_finance.experimental.pricing_platform.framework.equity_instruments.american_option.american_option_impl import AmericanOption
17 | from tf_quant_finance.experimental.pricing_platform.framework.equity_instruments.american_option.american_option_impl import AmericanOptionConfig
18 |
19 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
20 |
21 | _allowed_symbols = [
22 | "AmericanOption",
23 | "AmericanOptionConfig",
24 | ]
25 |
26 | remove_undocumented(__name__, _allowed_symbols)
27 |
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/pricing_platform/framework/market_data/README.md:
--------------------------------------------------------------------------------
1 | Implementation of the ProcessedMarketData interface.
2 |
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/pricing_platform/framework/market_data/market_data.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/tf-quant-finance/4c4b57e9808f5b60184d8fd5f7f43aaf5871313b/tf_quant_finance/experimental/pricing_platform/framework/market_data/market_data.pdf
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/pricing_platform/framework/rate_instruments/README.md:
--------------------------------------------------------------------------------
1 | Financial instrumetns implementation.
2 |
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/pricing_platform/framework/rate_instruments/forward_rate_agreement/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Forward rate agreement."""
15 |
16 | from tf_quant_finance.experimental.pricing_platform.framework.rate_instruments.forward_rate_agreement.forward_rate_agreement_impl import ForwardRateAgreement
17 | from tf_quant_finance.experimental.pricing_platform.framework.rate_instruments.forward_rate_agreement.forward_rate_agreement_impl import ForwardRateAgreementConfig
18 |
19 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
20 |
21 | _allowed_symbols = [
22 | "ForwardRateAgreement",
23 | "ForwardRateAgreementConfig",
24 | ]
25 |
26 | remove_undocumented(__name__, _allowed_symbols)
27 |
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/pricing_platform/framework/rate_instruments/interest_rate_swap/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Interest rate swap."""
15 |
16 | from tf_quant_finance.experimental.pricing_platform.framework.rate_instruments.interest_rate_swap.interest_rate_swap_impl import InterestRateSwap
17 | from tf_quant_finance.experimental.pricing_platform.framework.rate_instruments.interest_rate_swap.interest_rate_swap_impl import InterestRateSwapConfig
18 |
19 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
20 |
21 | _allowed_symbols = [
22 | "InterestRateSwap",
23 | "InterestRateSwapConfig",
24 | ]
25 |
26 | remove_undocumented(__name__, _allowed_symbols)
27 |
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/pricing_platform/framework/rate_instruments/swaption/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Swaption."""
15 |
16 | from tf_quant_finance.experimental.pricing_platform.framework.rate_instruments.swaption.swaption_impl import Swaption
17 | from tf_quant_finance.experimental.pricing_platform.framework.rate_instruments.swaption.swaption_impl import SwaptionConfig
18 |
19 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
20 |
21 | _allowed_symbols = [
22 | "Swaption",
23 | "SwaptionConfig",
24 | ]
25 |
26 | remove_undocumented(__name__, _allowed_symbols)
27 |
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/pricing_platform/framework/rate_instruments/utils.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Common utilities."""
15 |
16 | from tf_quant_finance.experimental.pricing_platform.instrument_protos import decimal_pb2
17 |
18 | _NANO = 1e-9
19 |
20 |
21 | def decimal_to_double(decimal: decimal_pb2.Decimal) -> float:
22 | return decimal.units + decimal.nanos * _NANO
23 |
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/pricing_platform/framework/utils.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Common utility functions."""
15 |
16 | import hashlib
17 | import json
18 |
19 |
20 | def hasher(obj):
21 | """Returns non-cryptographic hash of a JSON-serializable object."""
22 | h = hashlib.md5(json.dumps(obj).encode())
23 | return h.hexdigest()
24 |
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/pricing_platform/instrument_protos/date.proto:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // https://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | syntax = "proto3";
15 |
16 | package tf_quant_finance.experimental.pricing_platform.instrument_protos;
17 |
18 | option java_multiple_files = true;
19 |
20 | // Date in the format CCYY-MM-DD where CC represents the century, YY the year,
21 | // MM the month and DD the day.
22 | message Date {
23 | // The year for the date.
24 | int32 year = 1;
25 | // The month of the year. Must be between 1 and 12.
26 | int32 month = 2;
27 | // The day of the month. Must be within the range for the month and year.
28 | int32 day = 3;
29 | }
30 |
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/pricing_platform/instrument_protos/daycount_conventions.proto:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // https://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | syntax = "proto3";
15 |
16 | package tf_quant_finance.experimental.pricing_platform.instrument_protos;
17 |
18 | option java_multiple_files = true;
19 |
20 | // Day count convention proto. Used to determine how to compute accrued
21 | // interest. See https://en.wikipedia.org/wiki/Day_count_convention
22 | enum DayCountConvention {
23 | // Unknown day count.
24 | DAY_COUNT_CONVENTION_UNKNOWN = 0;
25 | // Actual calendar day count
26 | ACTUAL_ACTUAL_ISDA = 1;
27 | // Actual day count assuming 360 days in a year
28 | ACTUAL_360 = 2;
29 | // Actual day count assuming 365 days in a year
30 | ACTUAL_365 = 3;
31 | // 30 days in a month, 360 days in a year
32 | CONVENTION_30_360 = 4;
33 | }
34 |
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/pricing_platform/instrument_protos/metadata.proto:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // https://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | syntax = "proto3";
15 |
16 | package tf_quant_finance.experimental.pricing_platform.instrument_protos;
17 |
18 | option java_multiple_files = true;
19 |
20 | // Holds metadata for an instrument.
21 | message InstrumentMetadata {
22 | // The type of the instrument. This should be the name of the containing
23 | // message (e.g. ForwardRateAgreement).
24 | string instrument_type = 1;
25 | // An arbitrary identifier for the instrument/trade. This ID should be
26 | // immutable once assigned to an instrument - in particular, aging events
27 | // shouldn't change this ID.
28 | string id = 2;
29 | // Counterparty to this trade.
30 | string counterparty = 3;
31 | }
32 |
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/pricing_platform/instrument_protos/period.proto:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // https://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 | syntax = "proto3";
15 |
16 | package tf_quant_finance.experimental.pricing_platform.instrument_protos;
17 |
18 | option java_multiple_files = true;
19 |
20 | // Period types
21 | enum PeriodType {
22 | TYPE_UNKNOWN = 0;
23 | DAY = 1;
24 | WEEK = 2;
25 | MONTH = 3;
26 | QUARTER = 4;
27 | YEAR = 5;
28 | }
29 |
30 | // Period message
31 | message Period {
32 | PeriodType type = 1;
33 | int32 amount = 2;
34 | }
35 |
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/pricing_platform/instrument_protos/swaption.proto:
--------------------------------------------------------------------------------
1 | // Copyright 2020 Google LLC
2 | //
3 | // Licensed under the Apache License, Version 2.0 (the "License");
4 | // you may not use this file except in compliance with the License.
5 | // You may obtain a copy of the License at
6 | //
7 | // https://www.apache.org/licenses/LICENSE-2.0
8 | //
9 | // Unless required by applicable law or agreed to in writing, software
10 | // distributed under the License is distributed on an "AS IS" BASIS,
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | // See the License for the specific language governing permissions and
13 | // limitations under the License.
14 |
15 | // Instrument protos for European swaptions.
16 | syntax = "proto3";
17 |
18 | package tf_quant_finance.experimental.pricing_platform.instrument_protos;
19 |
20 | import "tf_quant_finance/experimental/pricing_platform/instrument_protos/date.proto";
21 | import "tf_quant_finance/experimental/pricing_platform/instrument_protos/metadata.proto";
22 | import "tf_quant_finance/experimental/pricing_platform/instrument_protos/interest_rate_swap.proto";
23 |
24 | // Swaption proto
25 | message Swaption {
26 | // The expiry date (or the exercise date) of the swaption.
27 | Date expiry_date = 2;
28 | // Underlying swap for the swaption.
29 | InterestRateSwap swap = 3;
30 | // Common metadata needed to identify the trade.
31 | InstrumentMetadata metadata = 4;
32 | }
33 |
--------------------------------------------------------------------------------
/tf_quant_finance/experimental/svi/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2021 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """SVI model."""
15 |
16 | from tf_quant_finance.experimental.svi.calibration import calibration
17 | from tf_quant_finance.experimental.svi.parameterizations import implied_volatility_from_raw_svi_parameters
18 | from tf_quant_finance.experimental.svi.parameterizations import total_variance_from_raw_svi_parameters
19 |
20 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
21 |
22 | # pyformat: disable
23 | _allowed_symbols = [
24 | 'calibration',
25 | 'total_variance_from_raw_svi_parameters',
26 | 'implied_volatility_from_raw_svi_parameters',
27 | ]
28 | # pyformat: enable
29 |
30 | remove_undocumented(__name__, _allowed_symbols)
31 |
--------------------------------------------------------------------------------
/tf_quant_finance/math/README.md:
--------------------------------------------------------------------------------
1 | # Ops for numerical methods.
2 |
3 | This module provides ops to perform various mathematical tasks commonly needed
4 | when building quantitative finance models. We do not aim to provide
5 | exhaustive coverage here. [Tensorflow](https://github.com/tensorflow/tensorflow)
6 | and [Tensorflow Probability](https://github.com/tensorflow/probability) provide
7 | a significant suite of methods already and the methods here are meant to
8 | build on those.
9 |
10 | Some of the modules/functions provided are:
11 |
12 | * [math.interpolation](interpolation): Ops to perform linear and
13 | cubic interpolation.
14 | * [math.optimizer](optimizer): Ops for numerical optimization.
15 | * [math.pde](pde): Ops to numerically solve partial differential
16 | equations using finite difference methods. Currently, only linear second
17 | order PDEs are supported as this is the most commonly needed case.
18 | * [math.random](random): Ops to compute low discrepancy sequences.
19 | * [math.root_search](root_search.py): Provides the Brent method for computing
20 | roots of functions in one dimension.
21 | * [math.segment_ops](segment_ops.py): Utility methods to apply some element
22 | wise ops in a segment.
23 |
24 |
--------------------------------------------------------------------------------
/tf_quant_finance/math/integration/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | """Numerical integration methods."""
16 |
17 | from tf_quant_finance.math.integration.gauss_kronrod import gauss_kronrod
18 | from tf_quant_finance.math.integration.gauss_legendre import gauss_legendre
19 | from tf_quant_finance.math.integration.integrate import integrate
20 | from tf_quant_finance.math.integration.integrate import IntegrationMethod
21 | from tf_quant_finance.math.integration.simpson import simpson
22 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
23 |
24 | _allowed_symbols = [
25 | 'integrate',
26 | 'simpson',
27 | 'gauss_legendre',
28 | 'gauss_kronrod',
29 | 'IntegrationMethod',
30 | ]
31 |
32 | remove_undocumented(__name__, _allowed_symbols)
33 |
--------------------------------------------------------------------------------
/tf_quant_finance/math/interpolation/BUILD:
--------------------------------------------------------------------------------
1 | # Interpolation methods for one and two dimensions.
2 |
3 | # Placeholder: load py_library
4 |
5 | package(
6 | default_visibility = ["//tf_quant_finance:__subpackages__"],
7 | licenses = ["notice"],
8 | )
9 |
10 | py_library(
11 | name = "interpolation",
12 | srcs = ["__init__.py"],
13 | deps = [
14 | "//tf_quant_finance/math/interpolation/cubic",
15 | "//tf_quant_finance/math/interpolation/interpolation_2d",
16 | "//tf_quant_finance/math/interpolation/linear",
17 | # tensorflow dep,
18 | ],
19 | )
20 |
21 | filegroup(
22 | name = "docs",
23 | srcs = [
24 | "README.md",
25 | ],
26 | )
27 |
--------------------------------------------------------------------------------
/tf_quant_finance/math/interpolation/README.md:
--------------------------------------------------------------------------------
1 | # Interpolation Methods
2 |
3 | This module provides methods to perform linear and cubic interpolation.
4 |
--------------------------------------------------------------------------------
/tf_quant_finance/math/interpolation/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Ops related to interpolation."""
15 |
16 |
17 | from tf_quant_finance.math.interpolation import cubic
18 | from tf_quant_finance.math.interpolation import interpolation_2d
19 | from tf_quant_finance.math.interpolation import linear
20 |
21 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
22 |
23 | _allowed_symbols = [
24 | 'cubic',
25 | 'interpolation_2d',
26 | 'linear',
27 | ]
28 |
29 | remove_undocumented(__name__, _allowed_symbols)
30 |
--------------------------------------------------------------------------------
/tf_quant_finance/math/interpolation/cubic/BUILD:
--------------------------------------------------------------------------------
1 | # Cubic interpolation methods.
2 |
3 | # Placeholder: load py_library
4 | # Placeholder: load py_test
5 |
6 | package(
7 | default_visibility = ["//tf_quant_finance:__subpackages__"],
8 | licenses = ["notice"],
9 | )
10 |
11 | py_library(
12 | name = "cubic",
13 | srcs = ["__init__.py"],
14 | deps = [
15 | ":cubic_interpolation",
16 | # tensorflow dep,
17 | ],
18 | )
19 |
20 | py_library(
21 | name = "cubic_interpolation",
22 | srcs = ["cubic_interpolation.py"],
23 | deps = [
24 | "//tf_quant_finance/types",
25 | "//tf_quant_finance/utils",
26 | # tensorflow dep,
27 | # tensorflow_probability dep,
28 | ],
29 | )
30 |
31 | py_test(
32 | name = "cubic_interpolation_test",
33 | size = "medium",
34 | srcs = ["cubic_interpolation_test.py"],
35 | shard_count = 2,
36 | deps = [
37 | "//tf_quant_finance",
38 | # test util,
39 | # absl/testing:parameterized dep,
40 | # numpy dep,
41 | # tensorflow dep,
42 | # tensorflow_probability dep,
43 | ],
44 | )
45 |
--------------------------------------------------------------------------------
/tf_quant_finance/math/interpolation/cubic/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Cubic spline interpolation methods."""
15 |
16 | from tf_quant_finance.math.interpolation.cubic.cubic_interpolation import BoundaryConditionType
17 | from tf_quant_finance.math.interpolation.cubic.cubic_interpolation import build as build_spline
18 | from tf_quant_finance.math.interpolation.cubic.cubic_interpolation import interpolate
19 | from tf_quant_finance.math.interpolation.cubic.cubic_interpolation import SplineParameters
20 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
21 |
22 | _allowed_symbols = [
23 | 'build_spline',
24 | 'interpolate',
25 | 'SplineParameters',
26 | 'BoundaryConditionType',
27 | ]
28 |
29 | remove_undocumented(__name__, _allowed_symbols)
30 |
--------------------------------------------------------------------------------
/tf_quant_finance/math/interpolation/interpolation_2d/BUILD:
--------------------------------------------------------------------------------
1 | # Interpolation methods for two dimensions.
2 |
3 | # Placeholder: load py_library
4 | # Placeholder: load py_test
5 |
6 | package(
7 | default_visibility = ["//tf_quant_finance:__subpackages__"],
8 | licenses = ["notice"],
9 | )
10 |
11 | py_library(
12 | name = "interpolation_2d",
13 | srcs = ["__init__.py"],
14 | deps = [
15 | ":interpolation",
16 | # tensorflow dep,
17 | ],
18 | )
19 |
20 | py_library(
21 | name = "interpolation",
22 | srcs = ["interpolation_2d.py"],
23 | deps = [
24 | "//tf_quant_finance/math:piecewise",
25 | "//tf_quant_finance/math/interpolation/cubic",
26 | "//tf_quant_finance/types",
27 | # tensorflow dep,
28 | ],
29 | )
30 |
31 | py_test(
32 | name = "interpolation_2d_test",
33 | size = "medium",
34 | srcs = ["interpolation_2d_test.py"],
35 | shard_count = 3,
36 | deps = [
37 | "//tf_quant_finance",
38 | # test util,
39 | # numpy dep,
40 | # tensorflow dep,
41 | ],
42 | )
43 |
--------------------------------------------------------------------------------
/tf_quant_finance/math/interpolation/interpolation_2d/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """2D - interpolation."""
15 |
16 |
17 | from tf_quant_finance.math.interpolation.interpolation_2d import interpolation_2d
18 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
19 |
20 | Interpolation2D = interpolation_2d.Interpolation2D
21 | _allowed_symbols = [
22 | 'Interpolation2D',
23 | ]
24 |
25 | remove_undocumented(__name__, _allowed_symbols)
26 |
--------------------------------------------------------------------------------
/tf_quant_finance/math/interpolation/linear/BUILD:
--------------------------------------------------------------------------------
1 | # Interpolation methods for one and two dimensions.
2 |
3 | # Placeholder: load py_library
4 | # Placeholder: load py_test
5 |
6 | package(
7 | default_visibility = ["//tf_quant_finance:__subpackages__"],
8 | licenses = ["notice"],
9 | )
10 |
11 | py_library(
12 | name = "linear",
13 | srcs = ["__init__.py"],
14 | deps = [
15 | ":linear_interpolation",
16 | # tensorflow dep,
17 | ],
18 | )
19 |
20 | py_library(
21 | name = "linear_interpolation",
22 | srcs = ["linear_interpolation.py"],
23 | deps = [
24 | "//tf_quant_finance/math:piecewise",
25 | "//tf_quant_finance/types",
26 | "//tf_quant_finance/utils",
27 | # tensorflow dep,
28 | ],
29 | )
30 |
31 | py_test(
32 | name = "linear_interpolation_test",
33 | size = "small",
34 | srcs = ["linear_interpolation_test.py"],
35 | shard_count = 3,
36 | deps = [
37 | "//tf_quant_finance",
38 | # test util,
39 | # numpy dep,
40 | # tensorflow dep,
41 | ],
42 | )
43 |
--------------------------------------------------------------------------------
/tf_quant_finance/math/interpolation/linear/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Linear interpolation."""
15 |
16 |
17 | from tf_quant_finance.math.interpolation.linear.linear_interpolation import interpolate
18 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
19 |
20 | _allowed_symbols = [
21 | 'interpolate',
22 | ]
23 |
24 | remove_undocumented(__name__, _allowed_symbols)
25 |
--------------------------------------------------------------------------------
/tf_quant_finance/math/optimizer/BUILD:
--------------------------------------------------------------------------------
1 | # Optimization methods.
2 |
3 | # Placeholder: load py_library
4 | # Placeholder: load py_test
5 |
6 | package(
7 | default_visibility = ["//tf_quant_finance:__subpackages__"],
8 | licenses = ["notice"],
9 | )
10 |
11 | py_library(
12 | name = "optimizer",
13 | srcs = ["__init__.py"],
14 | deps = [
15 | ":conjugate_gradient",
16 | ],
17 | )
18 |
19 | py_test(
20 | name = "optimizer_test",
21 | size = "medium",
22 | srcs = ["optimizer_test.py"],
23 | deps = [
24 | "//tf_quant_finance",
25 | # test util,
26 | # numpy dep,
27 | # tensorflow dep,
28 | ],
29 | )
30 |
31 | py_library(
32 | name = "conjugate_gradient",
33 | srcs = ["conjugate_gradient.py"],
34 | deps = [
35 | "//tf_quant_finance/types",
36 | "//tf_quant_finance/utils",
37 | # attr dep,
38 | # tensorflow dep,
39 | # tensorflow_probability dep,
40 | ],
41 | )
42 |
43 | py_test(
44 | name = "conjugate_gradient_test",
45 | size = "medium",
46 | timeout = "long",
47 | srcs = ["conjugate_gradient_test.py"],
48 | shard_count = 10,
49 | deps = [
50 | "//tf_quant_finance",
51 | # test util,
52 | # numpy dep,
53 | # tensorflow dep,
54 | ],
55 | )
56 |
57 | filegroup(
58 | name = "docs",
59 | srcs = [
60 | "README.md",
61 | ],
62 | )
63 |
--------------------------------------------------------------------------------
/tf_quant_finance/math/optimizer/README.md:
--------------------------------------------------------------------------------
1 | # Numerical Optimization Methods
2 |
3 | This module provides ops for numerical optimization.
4 |
5 | It includes the following optimization algorithms:
6 |
7 | * BFGS optimizer
8 | * L-BFGS optimizer
9 | * Nelder-Mead optimizer
10 | * Conjugate Gradient optimizer
11 |
12 |
--------------------------------------------------------------------------------
/tf_quant_finance/math/pde/BUILD:
--------------------------------------------------------------------------------
1 | # PDE solver methods.
2 |
3 | # Placeholder: load py_library
4 |
5 | package(
6 | default_visibility = ["//tf_quant_finance:__subpackages__"],
7 | licenses = ["notice"],
8 | )
9 |
10 | py_library(
11 | name = "pde",
12 | srcs = ["__init__.py"],
13 | deps = [
14 | ":boundary_conditions",
15 | ":fd_solvers",
16 | ":grids",
17 | ],
18 | )
19 |
20 | py_library(
21 | name = "fd_solvers",
22 | srcs = ["fd_solvers.py"],
23 | deps = [
24 | "//tf_quant_finance/math/pde/steppers",
25 | # tensorflow dep,
26 | ],
27 | )
28 |
29 | py_library(
30 | name = "boundary_conditions",
31 | srcs = ["boundary_conditions.py"],
32 | deps = [],
33 | )
34 |
35 | py_library(
36 | name = "grids",
37 | srcs = ["grids.py"],
38 | deps = [
39 | # numpy dep,
40 | # tensorflow dep,
41 | ],
42 | )
43 |
44 | filegroup(
45 | name = "docs",
46 | srcs = [
47 | "README.md",
48 | "pde_solvers.pdf",
49 | ],
50 | )
51 |
--------------------------------------------------------------------------------
/tf_quant_finance/math/pde/README.md:
--------------------------------------------------------------------------------
1 | # Partial Differential Equation Solvers
2 |
3 | This package provides ops to compute numerical solutions of linear parabolic
4 | partial differential equations. See [pde_solvers.pdf](pde_solvers.pdf) for a
5 | detailed guide.
6 |
--------------------------------------------------------------------------------
/tf_quant_finance/math/pde/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """PDE solver methods."""
15 |
16 | from tf_quant_finance.math.pde import boundary_conditions
17 | from tf_quant_finance.math.pde import fd_solvers
18 | from tf_quant_finance.math.pde import grids
19 | from tf_quant_finance.math.pde import steppers
20 |
21 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
22 |
23 | _allowed_symbols = [
24 | 'grids',
25 | 'steppers',
26 | 'fd_solvers',
27 | 'boundary_conditions',
28 | ]
29 |
30 | remove_undocumented(__name__, _allowed_symbols)
31 |
--------------------------------------------------------------------------------
/tf_quant_finance/math/pde/pde_solvers.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/tf-quant-finance/4c4b57e9808f5b60184d8fd5f7f43aaf5871313b/tf_quant_finance/math/pde/pde_solvers.pdf
--------------------------------------------------------------------------------
/tf_quant_finance/math/qmc/README.md:
--------------------------------------------------------------------------------
1 | # Quasi Monte-Carlo Methods
2 |
3 | This package provides ops for low-discrepancy sequence generation for
4 | Quasi-Monte Carlo (QMC) integration (e.g., Sobol numbers). It provides methods
5 | for generating sequences as digital nets using generating matrices and lattice
6 | rules using generating vectors.
7 |
--------------------------------------------------------------------------------
/tf_quant_finance/math/random_ops/README.md:
--------------------------------------------------------------------------------
1 | # Random and Low Discrepancy Sequences.
2 |
3 | This directory contains ops to efficiently generate random numbers and
4 | quasi-random low discrepancy sequences.
5 |
6 | For the random numbers, [TensorFlow](tensorflow.org) and
7 | [TensorFlow Probability](https://www.tensorflow.org/probability)
8 | already contain significant support. This module provides Sobol and Halton
9 | low discrepancy sequences as well as a multivariate normal sampler which
10 | supports using these sequences (i.e. draws from a gaussian copula with low
11 | discrepancy sequences).
12 |
--------------------------------------------------------------------------------
/tf_quant_finance/math/random_ops/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Ops related to random or quasi random sampling."""
15 |
16 |
17 | from tf_quant_finance.math.random_ops import halton
18 | from tf_quant_finance.math.random_ops import sobol
19 | from tf_quant_finance.math.random_ops.multivariate_normal import multivariate_normal as mv_normal_sample
20 | from tf_quant_finance.math.random_ops.multivariate_normal import RandomType
21 | from tf_quant_finance.math.random_ops.stateless import stateless_random_shuffle
22 | from tf_quant_finance.math.random_ops.uniform import uniform
23 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
24 |
25 | _allowed_symbols = [
26 | 'halton',
27 | 'sobol',
28 | 'mv_normal_sample',
29 | 'RandomType',
30 | 'stateless_random_shuffle',
31 | 'uniform',
32 | ]
33 |
34 | remove_undocumented(__name__, _allowed_symbols)
35 |
--------------------------------------------------------------------------------
/tf_quant_finance/math/random_ops/halton/BUILD:
--------------------------------------------------------------------------------
1 | # Halton sequences
2 |
3 | # Placeholder: load py_library
4 | # Placeholder: load py_test
5 |
6 | package(
7 | default_visibility = ["//tf_quant_finance:__subpackages__"],
8 | licenses = ["notice"],
9 | )
10 |
11 | py_library(
12 | name = "halton",
13 | srcs = ["__init__.py"],
14 | deps = [
15 | ":halton_impl",
16 | # tensorflow dep,
17 | ],
18 | )
19 |
20 | py_library(
21 | name = "halton_impl",
22 | srcs = ["halton_impl.py"],
23 | deps = [
24 | "//tf_quant_finance/math/random_ops:stateless",
25 | "//tf_quant_finance/types",
26 | "//tf_quant_finance/utils",
27 | # numpy dep,
28 | # six dep,
29 | # tensorflow dep,
30 | ],
31 | )
32 |
33 | py_test(
34 | name = "halton_test",
35 | size = "medium",
36 | timeout = "long",
37 | srcs = ["halton_test.py"],
38 | shard_count = 2,
39 | deps = [
40 | # test util,
41 | "//tf_quant_finance/math",
42 | # numpy dep,
43 | # six dep,
44 | # tensorflow dep,
45 | # tensorflow_probability dep,
46 | ],
47 | )
48 |
--------------------------------------------------------------------------------
/tf_quant_finance/math/random_ops/halton/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Halton sampling."""
15 |
16 |
17 | from tf_quant_finance.math.random_ops.halton.halton_impl import HaltonParams
18 | from tf_quant_finance.math.random_ops.halton.halton_impl import sample
19 |
20 |
21 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
22 |
23 | _allowed_symbols = [
24 | 'sample',
25 | ]
26 |
27 | remove_undocumented(__name__, _allowed_symbols)
28 |
--------------------------------------------------------------------------------
/tf_quant_finance/math/random_ops/sobol/BUILD:
--------------------------------------------------------------------------------
1 | # Targets for Sobol sequence generation.
2 |
3 | # Placeholder: load py_library
4 | # Placeholder: load py_test
5 |
6 | package(
7 | default_visibility = ["//tf_quant_finance:__subpackages__"],
8 | licenses = ["notice"],
9 | )
10 |
11 | py_library(
12 | name = "sobol",
13 | srcs = ["__init__.py"],
14 | deps = [
15 | ":sobol_impl",
16 | # tensorflow dep,
17 | ],
18 | )
19 |
20 | py_library(
21 | name = "sobol_impl",
22 | srcs = ["sobol_impl.py"],
23 | data = ["//third_party/sobol_data:new-joe-kuo-6.21201"],
24 | deps = [
25 | "//tf_quant_finance/types",
26 | # numpy dep,
27 | # six dep,
28 | # tensorflow dep,
29 | ],
30 | )
31 |
32 | py_test(
33 | name = "sobol_test",
34 | size = "medium",
35 | srcs = ["sobol_test.py"],
36 | deps = [
37 | # test util,
38 | "//tf_quant_finance/math",
39 | # numpy dep,
40 | # tensorflow dep,
41 | # tensorflow_probability dep,
42 | ],
43 | )
44 |
--------------------------------------------------------------------------------
/tf_quant_finance/math/random_ops/sobol/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Sobol sampling."""
15 |
16 |
17 | from tf_quant_finance.math.random_ops.sobol.sobol_impl import load_data
18 | from tf_quant_finance.math.random_ops.sobol.sobol_impl import sample
19 |
20 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
21 |
22 | _allowed_symbols = [
23 | 'load_data',
24 | 'sample',
25 | ]
26 |
27 | remove_undocumented(__name__, _allowed_symbols)
28 |
--------------------------------------------------------------------------------
/tf_quant_finance/math/root_search/README.md:
--------------------------------------------------------------------------------
1 | # Root Search.
2 |
3 | This directory contains ops to do root search.
4 |
--------------------------------------------------------------------------------
/tf_quant_finance/math/root_search/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2021 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Ops related to root search."""
15 |
16 |
17 | from tf_quant_finance.math.root_search.brent import brentq
18 | from tf_quant_finance.math.root_search.newton import root_finder as newton_root
19 |
20 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
21 |
22 | _allowed_symbols = [
23 | 'brentq',
24 | 'newton_root',
25 | ]
26 |
27 | remove_undocumented(__name__, _allowed_symbols)
28 |
--------------------------------------------------------------------------------
/tf_quant_finance/math/root_search/utils.py:
--------------------------------------------------------------------------------
1 | # Copyright 2021 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Util common functions for brent and newton methods."""
15 |
16 | import numpy as np
17 | import tensorflow.compat.v2 as tf
18 |
19 |
20 | def default_relative_root_tolerance(dtype):
21 | """Returns the default relative root tolerance used for a TensorFlow dtype."""
22 | if dtype is None:
23 | dtype = tf.float64
24 | return 4 * np.finfo(dtype.as_numpy_dtype(0)).eps
25 |
--------------------------------------------------------------------------------
/tf_quant_finance/models/cir/BUILD:
--------------------------------------------------------------------------------
1 | # CIR model
2 |
3 | # Placeholder: load py_library
4 | # Placeholder: load py_test
5 |
6 | package(
7 | default_visibility = ["//tf_quant_finance:__subpackages__"],
8 | licenses = ["notice"],
9 | )
10 |
11 | py_library(
12 | name = "cir",
13 | srcs = ["__init__.py"],
14 | deps = [
15 | ":cir_model",
16 | ],
17 | )
18 |
19 | py_library(
20 | name = "cir_model",
21 | srcs = ["cir_model.py"],
22 | deps = [
23 | "//tf_quant_finance/math:piecewise",
24 | "//tf_quant_finance/math/random_ops",
25 | "//tf_quant_finance/models:generic_ito_process",
26 | "//tf_quant_finance/models:utils",
27 | # tensorflow dep,
28 | ],
29 | )
30 |
31 | py_test(
32 | name = "cir_test",
33 | size = "medium",
34 | timeout = "long",
35 | srcs = ["cir_test.py"],
36 | shard_count = 5,
37 | deps = [
38 | ":cir_model",
39 | "//tf_quant_finance",
40 | # test util,
41 | # absl/testing:parameterized dep,
42 | # numpy dep,
43 | # tensorflow dep,
44 | ],
45 | )
46 |
--------------------------------------------------------------------------------
/tf_quant_finance/models/cir/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2021 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """CIR model."""
15 |
16 | from tf_quant_finance.models.cir.cir_model import CirModel
17 |
18 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
19 |
20 | _allowed_symbols = [
21 | 'CirModel',
22 | ]
23 |
24 | remove_undocumented(__name__, _allowed_symbols)
25 |
--------------------------------------------------------------------------------
/tf_quant_finance/models/geometric_brownian_motion/__init__.py:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/tf-quant-finance/4c4b57e9808f5b60184d8fd5f7f43aaf5871313b/tf_quant_finance/models/geometric_brownian_motion/__init__.py
--------------------------------------------------------------------------------
/tf_quant_finance/models/heston/BUILD:
--------------------------------------------------------------------------------
1 | # Heston model
2 |
3 | # Placeholder: load py_library
4 | # Placeholder: load py_test
5 |
6 | package(
7 | default_visibility = ["//tf_quant_finance:__subpackages__"],
8 | licenses = ["notice"],
9 | )
10 |
11 | py_library(
12 | name = "heston",
13 | srcs = ["__init__.py"],
14 | deps = [
15 | ":heston_model",
16 | "//tf_quant_finance/models/heston/approximations",
17 | ],
18 | )
19 |
20 | py_library(
21 | name = "heston_model",
22 | srcs = ["heston_model.py"],
23 | deps = [
24 | "//tf_quant_finance/math:piecewise",
25 | "//tf_quant_finance/math/random_ops",
26 | "//tf_quant_finance/models:generic_ito_process",
27 | "//tf_quant_finance/models:utils",
28 | "//tf_quant_finance/types",
29 | "//tf_quant_finance/utils",
30 | # tensorflow dep,
31 | ],
32 | )
33 |
34 | py_test(
35 | name = "heston_model_test",
36 | size = "medium",
37 | timeout = "moderate",
38 | srcs = ["heston_model_test.py"],
39 | shard_count = 6,
40 | deps = [
41 | "//tf_quant_finance",
42 | # test util,
43 | # absl/testing:parameterized dep,
44 | # numpy dep,
45 | # tensorflow dep,
46 | ],
47 | )
48 |
--------------------------------------------------------------------------------
/tf_quant_finance/models/heston/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Heston model."""
15 |
16 | from tf_quant_finance.models.heston import approximations
17 | from tf_quant_finance.models.heston.approximations.calibration import calibration
18 | from tf_quant_finance.models.heston.heston_model import HestonModel
19 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
20 |
21 | _allowed_symbols = [
22 | 'approximations',
23 | 'calibration',
24 | 'HestonModel',
25 | ]
26 |
27 | remove_undocumented(__name__, _allowed_symbols)
28 |
--------------------------------------------------------------------------------
/tf_quant_finance/models/heston/approximations/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Approximations to the Heston model."""
15 |
16 | from tf_quant_finance.models.heston.approximations.asian_prices import asian_option_price
17 | from tf_quant_finance.models.heston.approximations.calibration import calibration
18 | from tf_quant_finance.models.heston.approximations.european_option import european_option_price
19 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
20 |
21 | _allowed_symbols = [
22 | 'asian_option_price',
23 | 'calibration',
24 | 'european_option_price',
25 | ]
26 |
27 | remove_undocumented(__name__, _allowed_symbols)
28 |
--------------------------------------------------------------------------------
/tf_quant_finance/models/legacy/README.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/google/tf-quant-finance/4c4b57e9808f5b60184d8fd5f7f43aaf5871313b/tf_quant_finance/models/legacy/README.md
--------------------------------------------------------------------------------
/tf_quant_finance/models/legacy/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Legacy tools to build Diffusion Models.
15 |
16 | TODO(b/147222558): brownian_motion.py currently uses an old version of
17 | ItoProcess interface. It should be updated to use the new interface, or merged
18 | with generic_ito_process.py. Then the "legacy" package should be removed.
19 | """
20 |
21 | from tf_quant_finance.models.legacy.brownian_motion import BrownianMotion
22 | from tf_quant_finance.models.legacy.ito_process import ItoProcess
23 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
24 |
25 | _allowed_symbols = [
26 | 'ItoProcess',
27 | 'BrownianMotion',
28 | ]
29 |
30 | remove_undocumented(__name__, _allowed_symbols)
31 |
--------------------------------------------------------------------------------
/tf_quant_finance/models/longstaff_schwartz/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2021 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 |
15 | """LSM algorithm methods."""
16 |
17 | from tf_quant_finance.models.longstaff_schwartz.lsm import least_square_mc
18 | from tf_quant_finance.models.longstaff_schwartz.lsm import make_polynomial_basis
19 | from tf_quant_finance.models.longstaff_schwartz.payoff_utils import make_basket_put_payoff
20 |
21 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
22 |
23 | _allowed_symbols = [
24 | "least_square_mc",
25 | "make_basket_put_payoff",
26 | "make_polynomial_basis",
27 | ]
28 |
29 | remove_undocumented(__name__, _allowed_symbols)
30 |
--------------------------------------------------------------------------------
/tf_quant_finance/models/sabr/BUILD:
--------------------------------------------------------------------------------
1 | # SABR model
2 |
3 | # Placeholder: load py_library
4 | # Placeholder: load py_test
5 |
6 | package(
7 | default_visibility = ["//tf_quant_finance:__subpackages__"],
8 | licenses = ["notice"],
9 | )
10 |
11 | py_library(
12 | name = "sabr",
13 | srcs = ["__init__.py"],
14 | deps = [
15 | ":sabr_model",
16 | "//tf_quant_finance/models/sabr/approximations",
17 | ],
18 | )
19 |
20 | py_library(
21 | name = "sabr_model",
22 | srcs = ["sabr_model.py"],
23 | deps = [
24 | "//tf_quant_finance/black_scholes:implied_vol_newton_root",
25 | "//tf_quant_finance/math/random_ops",
26 | "//tf_quant_finance/math/root_search:newton",
27 | "//tf_quant_finance/models:euler_sampling",
28 | "//tf_quant_finance/types",
29 | "//tf_quant_finance/utils",
30 | # tensorflow dep,
31 | ],
32 | )
33 |
34 | py_test(
35 | name = "sabr_model_test",
36 | size = "medium",
37 | timeout = "long",
38 | srcs = ["sabr_model_test.py"],
39 | shard_count = 12,
40 | deps = [
41 | ":sabr_model",
42 | "//tf_quant_finance",
43 | # test util,
44 | # absl/testing:parameterized dep,
45 | # numpy dep,
46 | # tensorflow dep,
47 | ],
48 | )
49 |
--------------------------------------------------------------------------------
/tf_quant_finance/models/sabr/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Sabr model."""
15 |
16 | from tf_quant_finance.models.sabr import approximations
17 | from tf_quant_finance.models.sabr.approximations.calibration import calibration
18 | from tf_quant_finance.models.sabr.sabr_model import SabrModel
19 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
20 |
21 | _allowed_symbols = [
22 | 'approximations',
23 | 'calibration',
24 | 'SabrModel',
25 | ]
26 |
27 | remove_undocumented(__name__, _allowed_symbols)
28 |
--------------------------------------------------------------------------------
/tf_quant_finance/models/valuation_method.py:
--------------------------------------------------------------------------------
1 | # Copyright 2021 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Valuation methods common to all models."""
15 |
16 | import enum
17 |
18 |
19 | @enum.unique
20 | class ValuationMethod(enum.Enum):
21 | """Valuation methods.
22 |
23 | * `ANALYTIC`: Analytic valuation.
24 | * `MONTE_CARLO`: Valuation using Monte carlo simulations.
25 | * `FINITE_DIFFERENCE`: Valuation using finite difference methods/PDEs.
26 | """
27 | ANALYTIC = 1
28 | MONTE_CARLO = 2
29 | FINITE_DIFFERENCE = 3
30 |
--------------------------------------------------------------------------------
/tf_quant_finance/rates/README.md:
--------------------------------------------------------------------------------
1 | # Utilities related to rates.
2 |
3 | This module is a toolbox for performing common tasks related to interest rates.
4 | This includes some common pricing functions for swaps and bonds and for building
5 | and interpolating from rate curves.
6 |
7 |
--------------------------------------------------------------------------------
/tf_quant_finance/rates/analytics/README.md:
--------------------------------------------------------------------------------
1 | # Analytics for rates instruments
2 |
3 | This module contains utilities for cashflow manipulations.
4 |
5 |
--------------------------------------------------------------------------------
/tf_quant_finance/rates/analytics/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2021 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Functions to handle rates."""
15 |
16 | from tf_quant_finance.rates.analytics import cashflows
17 | from tf_quant_finance.rates.analytics import forwards
18 | from tf_quant_finance.rates.analytics import swap
19 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
20 |
21 |
22 | _allowed_symbols = [
23 | 'cashflows',
24 | 'forwards',
25 | 'swap',
26 | ]
27 |
28 | remove_undocumented(__name__, _allowed_symbols)
29 |
--------------------------------------------------------------------------------
/tf_quant_finance/rates/constant_fwd/BUILD:
--------------------------------------------------------------------------------
1 | # Constant forward Interpolation for rate curves.
2 |
3 | # Placeholder: load py_library
4 | # Placeholder: load py_test
5 |
6 | package(
7 | default_visibility = ["//tf_quant_finance:__subpackages__"],
8 | licenses = ["notice"],
9 | )
10 |
11 | py_library(
12 | name = "constant_fwd",
13 | srcs = ["__init__.py"],
14 | deps = [
15 | ":constant_fwd_interpolation",
16 | # tensorflow dep,
17 | ],
18 | )
19 |
20 | py_library(
21 | name = "constant_fwd_interpolation",
22 | srcs = ["constant_fwd_interpolation.py"],
23 | deps = [
24 | # numpy dep,
25 | # tensorflow dep,
26 | ],
27 | )
28 |
29 | py_test(
30 | name = "constant_fwd_interpolation_test",
31 | size = "small",
32 | srcs = ["constant_fwd_interpolation_test.py"],
33 | shard_count = 2,
34 | deps = [
35 | ":constant_fwd_interpolation",
36 | "//tf_quant_finance",
37 | # test util,
38 | # absl/testing:parameterized dep,
39 | # numpy dep,
40 | # tensorflow dep,
41 | ],
42 | )
43 |
--------------------------------------------------------------------------------
/tf_quant_finance/rates/constant_fwd/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Constant forward interpolation."""
15 |
16 | from tf_quant_finance.rates.constant_fwd.constant_fwd_interpolation import interpolate
17 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
18 |
19 | _allowed_symbols = [
20 | 'interpolate',
21 | ]
22 |
23 | remove_undocumented(__name__, _allowed_symbols)
24 |
--------------------------------------------------------------------------------
/tf_quant_finance/rates/forwards.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Collection of functions to compute properties of forwards."""
15 |
16 | from tf_quant_finance.rates.analytics import forwards
17 | from tensorflow.python.util import deprecation # pylint: disable=g-direct-tensorflow-import
18 |
19 | forward_rates_from_yields = deprecation.deprecated_alias(
20 | 'tff.rates.forwards.forward_rates_from_yields',
21 | 'tff.rates.analytics.forwards.forward_rates_from_yields',
22 | forwards.forward_rates_from_yields)
23 |
24 | yields_from_forward_rates = deprecation.deprecated_alias(
25 | 'tff.rates.forwards.yields_from_forward_rates',
26 | 'tff.rates.analytics.forwards.yields_from_forward_rates',
27 | forwards.yields_from_forward_rates)
28 |
29 | __all__ = ['forward_rates_from_yields', 'yields_from_forward_rates']
30 |
--------------------------------------------------------------------------------
/tf_quant_finance/rates/hagan_west/README.md:
--------------------------------------------------------------------------------
1 | # Hagan West Algorithm
2 |
3 |
4 | This module contains an implementation of the Hagan West procedure for
5 | bootstrapping and interpolating interest rate curves. The algorithm applies
6 | quadratic interpolation to the forward curve and the rate curve is computed
7 | by integrating the interpolated forward curve.
8 |
9 | The current implementation only supports building curves from bonds. The swap
10 | curve building will be added shortly.
11 |
12 | #TODO(b/140370128): Support swap curve building.
13 | #TODO(b/140370679): Add amelioration and positivity constraints.
14 |
15 |
16 | ## References
17 |
18 | [1]: Patrick Hagan & Graeme West. Interpolation Methods for Curve
19 | Construction. Applied Mathematical Finance. Vol 13, No. 2, pp 89-129.
20 | June 2006.
21 | https://www.researchgate.net/publication/24071726_Interpolation_Methods_for_Curve_Construction
22 |
23 | [2]: Patrick Hagan & Graeme West. Methods for Constructing a Yield Curve.
24 | Wilmott Magazine, pp. 70-81. May 2008.
25 | https://www.researchgate.net/profile/Patrick_Hagan3/publication/228463045_Methods_for_constructing_a_yield_curve/links/54db8cda0cf23fe133ad4d01.pdf
26 |
--------------------------------------------------------------------------------
/tf_quant_finance/rates/hagan_west/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2019 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Hagan West algorithm for rate interpolation and bootstrapping."""
15 |
16 | from tf_quant_finance.rates.hagan_west import bond_curve as bond_curve_lib
17 | from tf_quant_finance.rates.hagan_west import monotone_convex
18 |
19 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
20 |
21 | bond_curve = bond_curve_lib.bond_curve
22 | CurveBuilderResult = bond_curve_lib.CurveBuilderResult
23 |
24 | _allowed_symbols = [
25 | 'bond_curve',
26 | 'monotone_convex',
27 | 'CurveBuilderResult',
28 | ]
29 |
30 | remove_undocumented(__name__, _allowed_symbols)
31 |
--------------------------------------------------------------------------------
/tf_quant_finance/rates/nelson_seigel_svensson/BUILD:
--------------------------------------------------------------------------------
1 | # Nelson Seigel Svensson Interpolation for rate curves.
2 |
3 | # Placeholder: load py_library
4 | # Placeholder: load py_test
5 |
6 | package(
7 | default_visibility = ["//tf_quant_finance:__subpackages__"],
8 | licenses = ["notice"],
9 | )
10 |
11 | py_library(
12 | name = "nelson_seigel_svensson",
13 | srcs = ["__init__.py"],
14 | deps = [
15 | ":nelson_seigel_svensson_interpolation",
16 | # tensorflow dep,
17 | ],
18 | )
19 |
20 | py_library(
21 | name = "nelson_seigel_svensson_interpolation",
22 | srcs = ["nelson_seigel_svensson_interpolation.py"],
23 | deps = [
24 | "//tf_quant_finance/types",
25 | "//tf_quant_finance/utils",
26 | # numpy dep,
27 | # tensorflow dep,
28 | ],
29 | )
30 |
31 | py_test(
32 | name = "nelson_seigel_svensson_interpolation_test",
33 | size = "small",
34 | srcs = ["nelson_seigel_svensson_interpolation_test.py"],
35 | shard_count = 2,
36 | deps = [
37 | ":nelson_seigel_svensson_interpolation",
38 | "//tf_quant_finance",
39 | # test util,
40 | # absl/testing:parameterized dep,
41 | # numpy dep,
42 | # tensorflow dep,
43 | ],
44 | )
45 |
--------------------------------------------------------------------------------
/tf_quant_finance/rates/nelson_seigel_svensson/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2021 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Nelson Seigel Svensson interpolation."""
15 |
16 | from tf_quant_finance.rates.nelson_seigel_svensson.nelson_seigel_svensson_interpolation import interpolate
17 | from tf_quant_finance.rates.nelson_seigel_svensson.nelson_seigel_svensson_interpolation import SvenssonParameters
18 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
19 |
20 | _allowed_symbols = [
21 | 'interpolate',
22 | 'SvenssonParameters'
23 | ]
24 |
25 | remove_undocumented(__name__, _allowed_symbols)
26 |
--------------------------------------------------------------------------------
/tf_quant_finance/types/BUILD:
--------------------------------------------------------------------------------
1 | # Typing utilities
2 |
3 | # Placeholder: load py_library
4 |
5 | package(
6 | default_visibility = ["//tf_quant_finance:__subpackages__"],
7 | licenses = ["notice"],
8 | )
9 |
10 | py_library(
11 | name = "types",
12 | srcs = ["__init__.py"],
13 | deps = [
14 | ":data_types",
15 | ],
16 | )
17 |
18 | py_library(
19 | name = "data_types",
20 | srcs = ["data_types.py"],
21 | deps = [
22 | "//tf_quant_finance/datetime",
23 | # numpy dep,
24 | # tensorflow dep,
25 | ],
26 | )
27 |
--------------------------------------------------------------------------------
/tf_quant_finance/types/README:
--------------------------------------------------------------------------------
1 | # Typing module
2 |
3 | Contains useful type definitions to be used for type annotations across the
4 | library.
--------------------------------------------------------------------------------
/tf_quant_finance/utils/README:
--------------------------------------------------------------------------------
1 | # Utilities
2 |
3 | Contains modules providing utility functions (e.g. graph manipulation,
4 | TF functions etc).
5 |
--------------------------------------------------------------------------------
/tf_quant_finance/utils/__init__.py:
--------------------------------------------------------------------------------
1 | # Copyright 2020 Google LLC
2 | #
3 | # Licensed under the Apache License, Version 2.0 (the "License");
4 | # you may not use this file except in compliance with the License.
5 | # You may obtain a copy of the License at
6 | #
7 | # https://www.apache.org/licenses/LICENSE-2.0
8 | #
9 | # Unless required by applicable law or agreed to in writing, software
10 | # distributed under the License is distributed on an "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | # See the License for the specific language governing permissions and
13 | # limitations under the License.
14 | """Utilities module."""
15 |
16 | from tf_quant_finance.utils.dataclass import dataclass
17 | from tf_quant_finance.utils.shape_utils import broadcast_common_batch_shape
18 | from tf_quant_finance.utils.shape_utils import broadcast_tensors
19 | from tf_quant_finance.utils.shape_utils import common_shape
20 | from tf_quant_finance.utils.shape_utils import get_shape
21 | from tf_quant_finance.utils.tf_functions import iterate_nested
22 |
23 | from tensorflow.python.util.all_util import remove_undocumented # pylint: disable=g-direct-tensorflow-import
24 |
25 | _allowed_symbols = [
26 | 'dataclass',
27 | 'broadcast_common_batch_shape',
28 | 'broadcast_tensors',
29 | 'common_shape',
30 | 'get_shape',
31 | 'iterate_nested'
32 | ]
33 |
34 | remove_undocumented(__name__, _allowed_symbols)
35 |
--------------------------------------------------------------------------------
/third_party/sobol_data/BUILD:
--------------------------------------------------------------------------------
1 | package(
2 | default_visibility = ["//visibility:public"],
3 | licenses = ["notice"],
4 | )
5 |
6 | exports_files(["LICENSE"])
7 |
8 | exports_files(["new-joe-kuo-6.21201"])
9 |
10 | cc_library(
11 | name = "sobol_data",
12 | hdrs = ["sobol_data.h"],
13 | compatible_with = ["//buildenv/target:non_prod"],
14 | )
15 |
--------------------------------------------------------------------------------
/third_party/sobol_data/README.md:
--------------------------------------------------------------------------------
1 | # Primitive polynomials and initial direction numbers for generating Sobol sequences
2 |
3 | This directory contains:
4 |
5 | * [new-joe-kuo-6.21201](new-joe-kuo-6.21201) - file downloaded from
6 | https://web.maths.unsw.edu.au/~fkuo/sobol/
7 |
8 | Program [sobol.cc](https://web.maths.unsw.edu.au/~fkuo/sobol/sobol.cc) for
9 | generating Sobol sequences and the accompanying direction numbers above are
10 | covered by a BSD-style licence (see [LICENSE](LICENSE)).
11 |
--------------------------------------------------------------------------------