quantark 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- quantark/__init__.py +3 -0
- quantark/_compat.py +150 -0
- quantark/asset/__init__.py +8 -0
- quantark/asset/bond/__init__.py +2 -0
- quantark/asset/bond/engine/__init__.py +44 -0
- quantark/asset/bond/engine/analytical/__init__.py +12 -0
- quantark/asset/bond/engine/analytical/black_engine.py +583 -0
- quantark/asset/bond/engine/analytical/bond_forward_engine.py +390 -0
- quantark/asset/bond/engine/analytical/bond_futures_engine.py +569 -0
- quantark/asset/bond/engine/convertible/__init__.py +12 -0
- quantark/asset/bond/engine/convertible/convertible_bond_engine.py +800 -0
- quantark/asset/bond/engine/discount/__init__.py +10 -0
- quantark/asset/bond/engine/discount/bond_discount_engine.py +517 -0
- quantark/asset/bond/engine/discount/frn_engine.py +913 -0
- quantark/asset/bond/engine/pde/__init__.py +14 -0
- quantark/asset/bond/engine/pde/convertible/__init__.py +21 -0
- quantark/asset/bond/engine/pde/convertible/jump_diffusion_engine.py +603 -0
- quantark/asset/bond/engine/pde/convertible/pde_params.py +59 -0
- quantark/asset/bond/engine/pde/convertible/tf_engine.py +546 -0
- quantark/asset/bond/engine/tree/__init__.py +14 -0
- quantark/asset/bond/engine/tree/convertible/__init__.py +21 -0
- quantark/asset/bond/engine/tree/convertible/binomial_engine.py +488 -0
- quantark/asset/bond/engine/tree/convertible/tree_params.py +72 -0
- quantark/asset/bond/engine/tree/convertible/trinomial_engine.py +1341 -0
- quantark/asset/bond/product/__init__.py +37 -0
- quantark/asset/bond/product/base_bond_product.py +114 -0
- quantark/asset/bond/product/convertible/__init__.py +16 -0
- quantark/asset/bond/product/convertible/convertible_bond.py +595 -0
- quantark/asset/bond/product/couponbond/__init__.py +12 -0
- quantark/asset/bond/product/couponbond/fixed_bond.py +285 -0
- quantark/asset/bond/product/couponbond/frn.py +538 -0
- quantark/asset/bond/product/forward/__init__.py +9 -0
- quantark/asset/bond/product/forward/base_bond_forward.py +92 -0
- quantark/asset/bond/product/forward/bond_forward.py +335 -0
- quantark/asset/bond/product/futures/__init__.py +8 -0
- quantark/asset/bond/product/futures/bond_futures.py +532 -0
- quantark/asset/bond/product/option/__init__.py +9 -0
- quantark/asset/bond/product/option/euro_short_term_bond_option.py +231 -0
- quantark/asset/bond/riskmeasures/__init__.py +13 -0
- quantark/asset/bond/riskmeasures/bond_greeks_calculator.py +484 -0
- quantark/asset/bond/schedule/__init__.py +21 -0
- quantark/asset/bond/schedule/cashflow.py +595 -0
- quantark/asset/equity/__init__.py +11 -0
- quantark/asset/equity/analysis/__init__.py +4 -0
- quantark/asset/equity/analysis/autocallable_path_analyzer.py +257 -0
- quantark/asset/equity/engine/__init__.py +84 -0
- quantark/asset/equity/engine/analytical/__init__.py +37 -0
- quantark/asset/equity/engine/analytical/american_option_engine.py +682 -0
- quantark/asset/equity/engine/analytical/asian_option_analytical_engine.py +1102 -0
- quantark/asset/equity/engine/analytical/barrier_analytical_engine.py +455 -0
- quantark/asset/equity/engine/analytical/black_scholes_engine.py +322 -0
- quantark/asset/equity/engine/analytical/deltaone_engine.py +340 -0
- quantark/asset/equity/engine/analytical/digital_option_engine.py +168 -0
- quantark/asset/equity/engine/analytical/double_barrier_option_engine.py +481 -0
- quantark/asset/equity/engine/analytical/double_sharkfin_option_analytical_engine.py +508 -0
- quantark/asset/equity/engine/analytical/one_touch_analytical_engine.py +302 -0
- quantark/asset/equity/engine/analytical/range_accrual_analytical_engine.py +396 -0
- quantark/asset/equity/engine/analytical/single_sharkfin_option_analytical_engine.py +229 -0
- quantark/asset/equity/engine/base_engine.py +137 -0
- quantark/asset/equity/engine/event_stats.py +85 -0
- quantark/asset/equity/engine/mc/__init__.py +31 -0
- quantark/asset/equity/engine/mc/american_option_mc_engine.py +485 -0
- quantark/asset/equity/engine/mc/asian_option_mc_engine.py +678 -0
- quantark/asset/equity/engine/mc/barrier_option_mc_engine.py +726 -0
- quantark/asset/equity/engine/mc/digital_option_mc_engine.py +419 -0
- quantark/asset/equity/engine/mc/double_sharkfin_option_mc_engine.py +676 -0
- quantark/asset/equity/engine/mc/euro_mc_engine.py +423 -0
- quantark/asset/equity/engine/mc/phoenix_mc_engine.py +1206 -0
- quantark/asset/equity/engine/mc/range_accrual_mc_engine.py +738 -0
- quantark/asset/equity/engine/mc/single_sharkfin_option_mc_engine.py +549 -0
- quantark/asset/equity/engine/mc/snowball_mc_engine.py +2250 -0
- quantark/asset/equity/engine/pde/__init__.py +36 -0
- quantark/asset/equity/engine/pde/american_pde_solver.py +211 -0
- quantark/asset/equity/engine/pde/barrier_pde_solver.py +692 -0
- quantark/asset/equity/engine/pde/base_pde_solver.py +994 -0
- quantark/asset/equity/engine/pde/double_barrier_pde_solver.py +510 -0
- quantark/asset/equity/engine/pde/double_one_touch_pde_solver.py +435 -0
- quantark/asset/equity/engine/pde/european_pde_solver.py +170 -0
- quantark/asset/equity/engine/pde/ko_reset_snowball_pde_solver.py +477 -0
- quantark/asset/equity/engine/pde/one_touch_pde_solver.py +439 -0
- quantark/asset/equity/engine/pde/phoenix_pde_solver.py +613 -0
- quantark/asset/equity/engine/pde/snowball_pde_solver.py +1810 -0
- quantark/asset/equity/engine/pde/spatial_grid.py +750 -0
- quantark/asset/equity/engine/pde/time_grid.py +308 -0
- quantark/asset/equity/engine/pde_engine.py +238 -0
- quantark/asset/equity/engine/quad/__init__.py +23 -0
- quantark/asset/equity/engine/quad/discrete_quad_engine.py +106 -0
- quantark/asset/equity/engine/quad/european_quad_engine.py +325 -0
- quantark/asset/equity/engine/quad/ko_reset_snowball_quad_engine.py +362 -0
- quantark/asset/equity/engine/quad/phoenix_quad_engine.py +614 -0
- quantark/asset/equity/engine/quad/quad_adapters.py +1260 -0
- quantark/asset/equity/engine/quad/quad_core.py +513 -0
- quantark/asset/equity/engine/quad/quad_math.py +219 -0
- quantark/asset/equity/engine/quad/snowball_quad_engine.py +1137 -0
- quantark/asset/equity/engine/validation/script/benchmark_check_american_analytical.py +117 -0
- quantark/asset/equity/engine/validation/script/benchmark_check_american_pde.py +114 -0
- quantark/asset/equity/engine/validation/script/benchmark_check_asian_analytical.py +440 -0
- quantark/asset/equity/engine/validation/script/benchmark_check_barrier_analytical.py +269 -0
- quantark/asset/equity/engine/validation/script/benchmark_check_barrier_pde_solver.py +636 -0
- quantark/asset/equity/engine/validation/script/benchmark_check_digital_option.py +256 -0
- quantark/asset/equity/engine/validation/script/benchmark_check_snowball_pde_solver.py +807 -0
- quantark/asset/equity/engine/validation/script/boundary_check_american_analytical.py +290 -0
- quantark/asset/equity/engine/validation/script/boundary_check_american_pde.py +242 -0
- quantark/asset/equity/engine/validation/script/boundary_check_asian_analytical.py +612 -0
- quantark/asset/equity/engine/validation/script/boundary_check_barrier_analytical.py +434 -0
- quantark/asset/equity/engine/validation/script/boundary_check_barrier_pde_solver.py +748 -0
- quantark/asset/equity/engine/validation/script/boundary_check_digital_option.py +575 -0
- quantark/asset/equity/engine/validation/script/boundary_check_snowball_pde_solver.py +1101 -0
- quantark/asset/equity/engine/validation/script/greeks_check_digital_option.py +349 -0
- quantark/asset/equity/engine/validation/script/mc_comparison_barrier_pde.py +270 -0
- quantark/asset/equity/engine/validation/script/quick_mc_compare.py +51 -0
- quantark/asset/equity/engine/validation/script/validation_stepdown_improved.py +97 -0
- quantark/asset/equity/param/__init__.py +24 -0
- quantark/asset/equity/param/engine_param_profiles.py +325 -0
- quantark/asset/equity/param/engine_params.py +728 -0
- quantark/asset/equity/process/__init__.py +7 -0
- quantark/asset/equity/process/bsm/__init__.py +7 -0
- quantark/asset/equity/process/bsm/bsm_process.py +108 -0
- quantark/asset/equity/process/bsm/qmc_brownian_bridge.py +401 -0
- quantark/asset/equity/process/bsm/qmc_path_generator.py +694 -0
- quantark/asset/equity/process/bsm/qmc_rqmc_driver.py +163 -0
- quantark/asset/equity/process/bsm/qmc_sobol.py +195 -0
- quantark/asset/equity/process/bsm/qmc_variance_reduction.py +292 -0
- quantark/asset/equity/product/__init__.py +8 -0
- quantark/asset/equity/product/base_equity_product.py +72 -0
- quantark/asset/equity/product/deltaone/__init__.py +22 -0
- quantark/asset/equity/product/deltaone/base_deltaone_product.py +147 -0
- quantark/asset/equity/product/deltaone/futures.py +485 -0
- quantark/asset/equity/product/deltaone/spot_instrument.py +118 -0
- quantark/asset/equity/product/option/__init__.py +104 -0
- quantark/asset/equity/product/option/american_option.py +114 -0
- quantark/asset/equity/product/option/asian_option.py +531 -0
- quantark/asset/equity/product/option/barrier_option.py +289 -0
- quantark/asset/equity/product/option/base_equity_option.py +659 -0
- quantark/asset/equity/product/option/digital_option.py +102 -0
- quantark/asset/equity/product/option/double_barrier_option.py +286 -0
- quantark/asset/equity/product/option/double_one_touch_option.py +310 -0
- quantark/asset/equity/product/option/double_sharkfin_option.py +466 -0
- quantark/asset/equity/product/option/european_vanilla_option.py +103 -0
- quantark/asset/equity/product/option/ko_reset_snowball_option.py +563 -0
- quantark/asset/equity/product/option/observation_schedule.py +530 -0
- quantark/asset/equity/product/option/one_touch_option.py +287 -0
- quantark/asset/equity/product/option/phoenix_config.py +116 -0
- quantark/asset/equity/product/option/phoenix_helpers.py +576 -0
- quantark/asset/equity/product/option/phoenix_option.py +1167 -0
- quantark/asset/equity/product/option/range_accrual_config.py +288 -0
- quantark/asset/equity/product/option/range_accrual_helpers.py +608 -0
- quantark/asset/equity/product/option/range_accrual_option.py +526 -0
- quantark/asset/equity/product/option/single_sharkfin_option.py +420 -0
- quantark/asset/equity/product/option/snowball_config.py +261 -0
- quantark/asset/equity/product/option/snowball_helpers.py +977 -0
- quantark/asset/equity/product/option/snowball_option.py +1242 -0
- quantark/asset/equity/report/__init__.py +15 -0
- quantark/asset/equity/report/autocallable_risk_report.py +2118 -0
- quantark/asset/equity/report/plotting.py +87 -0
- quantark/asset/equity/report/snowball_risk_comparison_report.py +2230 -0
- quantark/asset/equity/report/surfaces.py +123 -0
- quantark/asset/equity/report/term_structure.py +126 -0
- quantark/asset/equity/riskmeasures/__init__.py +7 -0
- quantark/asset/equity/riskmeasures/greeks_calculator.py +1204 -0
- quantark/asset/rate/__init__.py +58 -0
- quantark/asset/rate/engine/__init__.py +25 -0
- quantark/asset/rate/engine/cap_floor_engine.py +514 -0
- quantark/asset/rate/engine/fra_engine.py +286 -0
- quantark/asset/rate/engine/irs_discount_engine.py +891 -0
- quantark/asset/rate/engine/swaption_engine.py +587 -0
- quantark/asset/rate/product/__init__.py +67 -0
- quantark/asset/rate/product/cap_floor.py +550 -0
- quantark/asset/rate/product/fra.py +219 -0
- quantark/asset/rate/product/irs.py +1223 -0
- quantark/asset/rate/product/swaption.py +372 -0
- quantark/backtest/__init__.py +153 -0
- quantark/backtest/base.py +263 -0
- quantark/backtest/dashboard.py +874 -0
- quantark/backtest/equity/__init__.py +35 -0
- quantark/backtest/equity/config.py +118 -0
- quantark/backtest/equity/engine.py +408 -0
- quantark/backtest/equity/hedge_executor.py +374 -0
- quantark/backtest/equity/metrics.py +396 -0
- quantark/backtest/equity/results.py +232 -0
- quantark/backtest/equity/state.py +252 -0
- quantark/backtest/examples/__init__.py +4 -0
- quantark/backtest/examples/advanced_backtest.py +345 -0
- quantark/backtest/examples/basic_delta_hedge.py +246 -0
- quantark/backtest/examples/fi_dv01_hedge.py +267 -0
- quantark/backtest/fi/__init__.py +30 -0
- quantark/backtest/fi/config.py +114 -0
- quantark/backtest/fi/engine.py +378 -0
- quantark/backtest/fi/hedge_executor.py +254 -0
- quantark/backtest/fi/metrics.py +308 -0
- quantark/backtest/fi/results.py +193 -0
- quantark/backtest/fi/state.py +212 -0
- quantark/backtest/logger.py +393 -0
- quantark/backtest/otc/__init__.py +74 -0
- quantark/backtest/otc/_replay.py +637 -0
- quantark/backtest/otc/book_engine.py +587 -0
- quantark/backtest/otc/config.py +175 -0
- quantark/backtest/otc/dashboard.py +1006 -0
- quantark/backtest/otc/engine.py +420 -0
- quantark/backtest/otc/engine_factory.py +138 -0
- quantark/backtest/otc/market.py +216 -0
- quantark/backtest/otc/results.py +107 -0
- quantark/backtest/otc/state.py +166 -0
- quantark/backtest/report_generator.py +608 -0
- quantark/backtest/strategy/__init__.py +28 -0
- quantark/backtest/strategy/base_strategy.py +235 -0
- quantark/backtest/strategy/convexity_neutral_strategy.py +247 -0
- quantark/backtest/strategy/delta_neutral_strategy.py +283 -0
- quantark/backtest/strategy/dv01_neutral_strategy.py +283 -0
- quantark/backtest/transaction_costs.py +485 -0
- quantark/backtest/visualizer.py +1019 -0
- quantark/cashleg/__init__.py +31 -0
- quantark/cashleg/accrual_leg.py +120 -0
- quantark/cashleg/base.py +48 -0
- quantark/cashleg/base_amount.py +60 -0
- quantark/cashleg/deterministic_leg.py +39 -0
- quantark/cashleg/event_distribution.py +262 -0
- quantark/cashleg/fixed_payoff_leg.py +92 -0
- quantark/cashleg/leg_schedule.py +95 -0
- quantark/cashleg/leg_valuator.py +40 -0
- quantark/dynamicscenario/__init__.py +97 -0
- quantark/dynamicscenario/base.py +297 -0
- quantark/dynamicscenario/config.py +122 -0
- quantark/dynamicscenario/engine.py +703 -0
- quantark/dynamicscenario/equity/__init__.py +14 -0
- quantark/dynamicscenario/fi/__init__.py +24 -0
- quantark/dynamicscenario/fi/config.py +149 -0
- quantark/dynamicscenario/fi/engine.py +500 -0
- quantark/dynamicscenario/fi/results.py +503 -0
- quantark/dynamicscenario/path/__init__.py +17 -0
- quantark/dynamicscenario/path/day_path.py +397 -0
- quantark/dynamicscenario/path/fi_path_library.py +488 -0
- quantark/dynamicscenario/path/path_builder.py +726 -0
- quantark/dynamicscenario/path/path_library.py +620 -0
- quantark/dynamicscenario/report/__init__.py +12 -0
- quantark/dynamicscenario/report/dynamic_report.py +1175 -0
- quantark/dynamicscenario/report/visualizer.py +1586 -0
- quantark/dynamicscenario/results/__init__.py +19 -0
- quantark/dynamicscenario/results/dynamic_results.py +579 -0
- quantark/dynamicscenario/results/result_exporter.py +438 -0
- quantark/param/__init__.py +75 -0
- quantark/param/basis/__init__.py +19 -0
- quantark/param/basis/basis_yield.py +301 -0
- quantark/param/div/__init__.py +16 -0
- quantark/param/div/dividend_yield.py +123 -0
- quantark/param/index/__init__.py +52 -0
- quantark/param/index/rate_index.py +568 -0
- quantark/param/quote/__init__.py +7 -0
- quantark/param/quote/spot_quote.py +35 -0
- quantark/param/rrf/__init__.py +22 -0
- quantark/param/rrf/rate_curve.py +436 -0
- quantark/param/vol/__init__.py +6 -0
- quantark/param/vol/vol_surface.py +118 -0
- quantark/portfolio/__init__.py +61 -0
- quantark/portfolio/base.py +203 -0
- quantark/portfolio/equity/__init__.py +17 -0
- quantark/portfolio/equity/portfolio.py +391 -0
- quantark/portfolio/equity/position.py +368 -0
- quantark/portfolio/fi/__init__.py +14 -0
- quantark/portfolio/fi/portfolio.py +424 -0
- quantark/portfolio/fi/position.py +272 -0
- quantark/portfolio/portfolio_snapshot.py +221 -0
- quantark/portfolio/portfolio_storage.py +414 -0
- quantark/priceenv/__init__.py +7 -0
- quantark/priceenv/pricing_environment.py +196 -0
- quantark/rfq/__init__.py +32 -0
- quantark/rfq/builders.py +102 -0
- quantark/rfq/models.py +214 -0
- quantark/rfq/registry.py +611 -0
- quantark/rfq/service.py +237 -0
- quantark/simm/__init__.py +155 -0
- quantark/simm/calibration/__init__.py +206 -0
- quantark/simm/calibration/accessors.py +439 -0
- quantark/simm/calibration/commodity.py +156 -0
- quantark/simm/calibration/credit_non_qualifying.py +79 -0
- quantark/simm/calibration/credit_qualifying.py +130 -0
- quantark/simm/calibration/cross_risk.py +39 -0
- quantark/simm/calibration/equity.py +125 -0
- quantark/simm/calibration/fx.py +92 -0
- quantark/simm/calibration/ir.py +152 -0
- quantark/simm/calibration/version.py +33 -0
- quantark/simm/config.py +186 -0
- quantark/simm/crif/__init__.py +35 -0
- quantark/simm/crif/models.py +230 -0
- quantark/simm/crif/parser.py +585 -0
- quantark/simm/engines/__init__.py +62 -0
- quantark/simm/engines/aggregation/__init__.py +67 -0
- quantark/simm/engines/aggregation/addon.py +141 -0
- quantark/simm/engines/aggregation/bucket_aggregator.py +298 -0
- quantark/simm/engines/aggregation/concentration.py +349 -0
- quantark/simm/engines/aggregation/product_class_aggregator.py +183 -0
- quantark/simm/engines/aggregation/risk_class_aggregator.py +403 -0
- quantark/simm/engines/aggregation/simm_calculator.py +430 -0
- quantark/simm/engines/aggregation/weighted_sensitivity.py +272 -0
- quantark/simm/engines/base.py +231 -0
- quantark/simm/engines/classification/__init__.py +10 -0
- quantark/simm/engines/classification/bucket_mapper.py +347 -0
- quantark/simm/engines/factory.py +137 -0
- quantark/simm/engines/portfolio_adapter.py +336 -0
- quantark/simm/engines/result.py +176 -0
- quantark/simm/engines/risk_class/__init__.py +18 -0
- quantark/simm/engines/risk_class/equity_engine.py +263 -0
- quantark/simm/engines/risk_class/ir_engine.py +264 -0
- quantark/simm/report/__init__.py +17 -0
- quantark/simm/report/crif_export.py +284 -0
- quantark/simm/report/excel_generator.py +401 -0
- quantark/simm/report/html_generator.py +840 -0
- quantark/simm/results/__init__.py +38 -0
- quantark/simm/results/attribution.py +313 -0
- quantark/simm/results/simm_result.py +339 -0
- quantark/simm/results/whatif.py +268 -0
- quantark/simm/sensitivity.py +533 -0
- quantark/simm/taxonomy.py +416 -0
- quantark/stresstest/__init__.py +67 -0
- quantark/stresstest/base.py +116 -0
- quantark/stresstest/config.py +5 -0
- quantark/stresstest/engine.py +5 -0
- quantark/stresstest/equity/__init__.py +17 -0
- quantark/stresstest/equity/config.py +69 -0
- quantark/stresstest/equity/engine.py +272 -0
- quantark/stresstest/equity/report/__init__.py +7 -0
- quantark/stresstest/equity/report/report_generator.py +423 -0
- quantark/stresstest/equity/report/visualizer.py +328 -0
- quantark/stresstest/equity/results.py +145 -0
- quantark/stresstest/fi/__init__.py +15 -0
- quantark/stresstest/fi/config.py +59 -0
- quantark/stresstest/fi/engine.py +213 -0
- quantark/stresstest/fi/metrics.py +60 -0
- quantark/stresstest/fi/results.py +64 -0
- quantark/stresstest/report/__init__.py +12 -0
- quantark/stresstest/report/report_generator.py +5 -0
- quantark/stresstest/report/visualizer.py +5 -0
- quantark/stresstest/results/__init__.py +16 -0
- quantark/stresstest/results/result_aggregator.py +325 -0
- quantark/stresstest/results/result_exporter.py +286 -0
- quantark/stresstest/results/stress_results.py +5 -0
- quantark/stresstest/scenario/__init__.py +13 -0
- quantark/stresstest/scenario/scenario.py +242 -0
- quantark/stresstest/scenario/scenario_builder.py +376 -0
- quantark/stresstest/scenario/scenario_library.py +435 -0
- quantark/stresstest/scenario/scenario_storage.py +224 -0
- quantark/stresstest/stress/__init__.py +13 -0
- quantark/stresstest/stress/stress_applicator.py +590 -0
- quantark/stresstest/stress/stress_types.py +142 -0
- quantark/util/__init__.py +23 -0
- quantark/util/barrier_shift.py +44 -0
- quantark/util/calendar/__init__.py +27 -0
- quantark/util/calendar/business_calendar.py +584 -0
- quantark/util/calendar/day_counter.py +517 -0
- quantark/util/calendar/holidayfile/china.csv +1920 -0
- quantark/util/calendar/holidayfile/china_sse.csv +1462 -0
- quantark/util/enum/__init__.py +81 -0
- quantark/util/enum/bond_enums.py +112 -0
- quantark/util/enum/deltaone_enums.py +16 -0
- quantark/util/enum/engine_enums.py +137 -0
- quantark/util/enum/greeks_enums.py +29 -0
- quantark/util/enum/option_enums.py +221 -0
- quantark/util/exceptions.py +66 -0
- quantark/util/marketdata/__init__.py +39 -0
- quantark/util/marketdata/adapter/base_adapter.py +203 -0
- quantark/util/marketdata/adapter/mock_adapter.py +265 -0
- quantark/util/marketdata/converter.py +289 -0
- quantark/util/marketdata/example_usage.py +314 -0
- quantark/util/marketdata/generator/__init__.py +7 -0
- quantark/util/marketdata/generator/mock_generator.py +466 -0
- quantark/util/marketdata/models.py +358 -0
- quantark/util/marketdata/storage/__init__.py +7 -0
- quantark/util/marketdata/storage/parquet_storage.py +340 -0
- quantark/util/numerical/__init__.py +98 -0
- quantark/util/numerical/comparison.py +219 -0
- quantark/util/numerical/constants.py +98 -0
- quantark/util/numerical/formatting.py +380 -0
- quantark/util/numerical/pnl.py +17 -0
- quantark/util/numerical/safe_math.py +238 -0
- quantark/util/numerical/validation.py +315 -0
- quantark/var/__init__.py +39 -0
- quantark/var/attribution.py +398 -0
- quantark/var/backtest/__init__.py +7 -0
- quantark/var/backtest/var_backtester.py +309 -0
- quantark/var/base.py +63 -0
- quantark/var/config.py +219 -0
- quantark/var/engines/__init__.py +13 -0
- quantark/var/engines/historical.py +925 -0
- quantark/var/engines/monte_carlo.py +870 -0
- quantark/var/engines/parametric.py +1199 -0
- quantark/var/results/__init__.py +16 -0
- quantark/var/results/incremental_var_result.py +131 -0
- quantark/var/results/var_report.py +346 -0
- quantark/var/results/var_result.py +134 -0
- quantark/var/risk_factors/__init__.py +22 -0
- quantark/var/risk_factors/base.py +41 -0
- quantark/var/risk_factors/equity_factors.py +158 -0
- quantark/var/risk_factors/fi_factors.py +99 -0
- quantark-0.1.0.dist-info/METADATA +351 -0
- quantark-0.1.0.dist-info/RECORD +399 -0
- quantark-0.1.0.dist-info/WHEEL +4 -0
- quantark-0.1.0.dist-info/licenses/LICENSE +202 -0
- quantark-0.1.0.dist-info/licenses/NOTICE +2 -0
- quantark_compat.pth +1 -0
|
@@ -0,0 +1,434 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Boundary Check Script for Barrier Analytical Engine
|
|
3
|
+
Generated: 2025-12-25
|
|
4
|
+
"""
|
|
5
|
+
import math
|
|
6
|
+
import sys
|
|
7
|
+
from datetime import datetime
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import List, Optional
|
|
10
|
+
|
|
11
|
+
sys.path.insert(0, str(Path(__file__).parent.parent.parent.parent.parent.parent.parent))
|
|
12
|
+
|
|
13
|
+
from quantark.asset.equity.engine.analytical import ( # noqa: E402
|
|
14
|
+
BarrierAnalyticalEngine,
|
|
15
|
+
BlackScholesEngine,
|
|
16
|
+
)
|
|
17
|
+
from quantark.asset.equity.product.option import ( # noqa: E402
|
|
18
|
+
BarrierOption,
|
|
19
|
+
EuropeanVanillaOption,
|
|
20
|
+
ObservationSchedule,
|
|
21
|
+
)
|
|
22
|
+
from quantark.param import ( # noqa: E402
|
|
23
|
+
ContinuousDividendYield,
|
|
24
|
+
FlatRateCurve,
|
|
25
|
+
FlatVolSurface,
|
|
26
|
+
SpotQuote,
|
|
27
|
+
)
|
|
28
|
+
from quantark.priceenv import PricingEnvironment # noqa: E402
|
|
29
|
+
from quantark.util.enum import ( # noqa: E402
|
|
30
|
+
BarrierType,
|
|
31
|
+
ObservationFrequency,
|
|
32
|
+
ObservationType,
|
|
33
|
+
OptionType,
|
|
34
|
+
)
|
|
35
|
+
from quantark.util.numerical import Tolerance, is_close # noqa: E402
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class BoundaryCheckResults:
|
|
39
|
+
def __init__(self) -> None:
|
|
40
|
+
self.passed = []
|
|
41
|
+
self.failed = []
|
|
42
|
+
self.warnings = []
|
|
43
|
+
|
|
44
|
+
def add_result(self, test_name: str, passed: bool, message: str) -> None:
|
|
45
|
+
if passed:
|
|
46
|
+
self.passed.append((test_name, message))
|
|
47
|
+
else:
|
|
48
|
+
self.failed.append((test_name, message))
|
|
49
|
+
|
|
50
|
+
def add_warning(self, test_name: str, message: str) -> None:
|
|
51
|
+
self.warnings.append((test_name, message))
|
|
52
|
+
|
|
53
|
+
def summary(self) -> bool:
|
|
54
|
+
total = len(self.passed) + len(self.failed)
|
|
55
|
+
print(f"\n{'='*60}")
|
|
56
|
+
print("BOUNDARY CHECK SUMMARY")
|
|
57
|
+
print(f"{'='*60}")
|
|
58
|
+
print(f"Total Tests: {total}")
|
|
59
|
+
print(
|
|
60
|
+
f"Passed: {len(self.passed)} "
|
|
61
|
+
f"({100*len(self.passed)/total if total > 0 else 0:.1f}%)"
|
|
62
|
+
)
|
|
63
|
+
print(
|
|
64
|
+
f"Failed: {len(self.failed)} "
|
|
65
|
+
f"({100*len(self.failed)/total if total > 0 else 0:.1f}%)"
|
|
66
|
+
)
|
|
67
|
+
print(f"Warnings: {len(self.warnings)}")
|
|
68
|
+
|
|
69
|
+
if self.failed:
|
|
70
|
+
print("\nFailed Tests:")
|
|
71
|
+
for name, msg in self.failed:
|
|
72
|
+
print(f" - {name}: {msg}")
|
|
73
|
+
|
|
74
|
+
if self.warnings:
|
|
75
|
+
print("\nWarnings:")
|
|
76
|
+
for name, msg in self.warnings:
|
|
77
|
+
print(f" - {name}: {msg}")
|
|
78
|
+
|
|
79
|
+
return len(self.failed) == 0
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def create_pricing_env(spot=100.0, rate=0.05, vol=0.20, div=0.0):
|
|
83
|
+
"""Helper to create pricing environment."""
|
|
84
|
+
return PricingEnvironment(
|
|
85
|
+
spot_quote=SpotQuote(spot=spot),
|
|
86
|
+
vol_surface=FlatVolSurface(volatility=vol),
|
|
87
|
+
rate_curve=FlatRateCurve(rate=rate),
|
|
88
|
+
div_yield=ContinuousDividendYield(div_yield=div),
|
|
89
|
+
valuation_date=datetime(2024, 1, 1),
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def create_barrier_option(
|
|
94
|
+
strike: float,
|
|
95
|
+
maturity: float,
|
|
96
|
+
barrier: float,
|
|
97
|
+
option_type: OptionType,
|
|
98
|
+
barrier_type: BarrierType,
|
|
99
|
+
observation_type: ObservationType = ObservationType.CONTINUOUS,
|
|
100
|
+
observation_dates: Optional[List[float]] = None,
|
|
101
|
+
observation_schedule: Optional[ObservationSchedule] = None,
|
|
102
|
+
rebate: float = 0.0,
|
|
103
|
+
pay_at_hit: bool = False,
|
|
104
|
+
participation_rate: float = 1.0,
|
|
105
|
+
) -> BarrierOption:
|
|
106
|
+
option = BarrierOption(
|
|
107
|
+
strike=strike,
|
|
108
|
+
option_type=option_type,
|
|
109
|
+
barrier=barrier,
|
|
110
|
+
barrier_type=barrier_type,
|
|
111
|
+
maturity=maturity,
|
|
112
|
+
rebate=rebate,
|
|
113
|
+
pay_at_hit=pay_at_hit,
|
|
114
|
+
observation_type=observation_type,
|
|
115
|
+
observation_dates=observation_dates,
|
|
116
|
+
observation_schedule=observation_schedule,
|
|
117
|
+
participation_rate=participation_rate,
|
|
118
|
+
)
|
|
119
|
+
option.validate()
|
|
120
|
+
return option
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def test_near_expiry_intrinsic(results: BoundaryCheckResults) -> None:
|
|
124
|
+
"""Test: Near expiry -> intrinsic value (barrier far away)."""
|
|
125
|
+
spot = 100.0
|
|
126
|
+
strike = 95.0
|
|
127
|
+
barrier = 50.0
|
|
128
|
+
maturity = 1e-8
|
|
129
|
+
|
|
130
|
+
pricing_env = create_pricing_env(spot=spot, rate=0.05, vol=0.2)
|
|
131
|
+
option = create_barrier_option(
|
|
132
|
+
strike=strike,
|
|
133
|
+
maturity=maturity,
|
|
134
|
+
barrier=barrier,
|
|
135
|
+
option_type=OptionType.CALL,
|
|
136
|
+
barrier_type=BarrierType.DOWN_OUT,
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
engine = BarrierAnalyticalEngine()
|
|
140
|
+
price = engine.price(option, pricing_env)
|
|
141
|
+
intrinsic = max(spot - strike, 0.0)
|
|
142
|
+
|
|
143
|
+
passed = is_close(price, intrinsic, rel_tol=1e-4, abs_tol=1e-2)
|
|
144
|
+
results.add_result(
|
|
145
|
+
"Near expiry (T->0)",
|
|
146
|
+
passed,
|
|
147
|
+
f"Price={price:.6f}, Intrinsic={intrinsic:.6f}",
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def test_knock_in_out_parity_continuous(results: BoundaryCheckResults) -> None:
|
|
152
|
+
"""Test: KO + KI = Vanilla (continuous, no rebate)."""
|
|
153
|
+
pricing_env = create_pricing_env(spot=100.0, rate=0.03, vol=0.25)
|
|
154
|
+
engine = BarrierAnalyticalEngine()
|
|
155
|
+
bs_engine = BlackScholesEngine()
|
|
156
|
+
|
|
157
|
+
strike = 100.0
|
|
158
|
+
barrier = 120.0
|
|
159
|
+
maturity = 1.0
|
|
160
|
+
|
|
161
|
+
ko = create_barrier_option(
|
|
162
|
+
strike=strike,
|
|
163
|
+
maturity=maturity,
|
|
164
|
+
barrier=barrier,
|
|
165
|
+
option_type=OptionType.CALL,
|
|
166
|
+
barrier_type=BarrierType.UP_OUT,
|
|
167
|
+
)
|
|
168
|
+
ki = create_barrier_option(
|
|
169
|
+
strike=strike,
|
|
170
|
+
maturity=maturity,
|
|
171
|
+
barrier=barrier,
|
|
172
|
+
option_type=OptionType.CALL,
|
|
173
|
+
barrier_type=BarrierType.UP_IN,
|
|
174
|
+
)
|
|
175
|
+
vanilla = EuropeanVanillaOption(
|
|
176
|
+
strike=strike,
|
|
177
|
+
option_type=OptionType.CALL,
|
|
178
|
+
maturity=maturity,
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
ko_price = engine.price(ko, pricing_env)
|
|
182
|
+
ki_price = engine.price(ki, pricing_env)
|
|
183
|
+
vanilla_price = bs_engine.price(vanilla, pricing_env)
|
|
184
|
+
|
|
185
|
+
total = ko_price + ki_price
|
|
186
|
+
passed = is_close(
|
|
187
|
+
total,
|
|
188
|
+
vanilla_price,
|
|
189
|
+
rel_tol=1e-3,
|
|
190
|
+
abs_tol=2 * Tolerance.PRECISION,
|
|
191
|
+
)
|
|
192
|
+
results.add_result(
|
|
193
|
+
"KO + KI = Vanilla (continuous)",
|
|
194
|
+
passed,
|
|
195
|
+
f"KO+KI={total:.6f}, Vanilla={vanilla_price:.6f}",
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def test_knock_out_le_vanilla(results: BoundaryCheckResults) -> None:
|
|
200
|
+
"""Test: KO option value should not exceed vanilla value."""
|
|
201
|
+
pricing_env = create_pricing_env(spot=100.0, rate=0.03, vol=0.25)
|
|
202
|
+
engine = BarrierAnalyticalEngine()
|
|
203
|
+
bs_engine = BlackScholesEngine()
|
|
204
|
+
|
|
205
|
+
strike = 100.0
|
|
206
|
+
barrier = 120.0
|
|
207
|
+
maturity = 1.0
|
|
208
|
+
|
|
209
|
+
ko = create_barrier_option(
|
|
210
|
+
strike=strike,
|
|
211
|
+
maturity=maturity,
|
|
212
|
+
barrier=barrier,
|
|
213
|
+
option_type=OptionType.CALL,
|
|
214
|
+
barrier_type=BarrierType.UP_OUT,
|
|
215
|
+
)
|
|
216
|
+
vanilla = EuropeanVanillaOption(
|
|
217
|
+
strike=strike,
|
|
218
|
+
option_type=OptionType.CALL,
|
|
219
|
+
maturity=maturity,
|
|
220
|
+
)
|
|
221
|
+
|
|
222
|
+
ko_price = engine.price(ko, pricing_env)
|
|
223
|
+
vanilla_price = bs_engine.price(vanilla, pricing_env)
|
|
224
|
+
|
|
225
|
+
passed = ko_price <= vanilla_price + Tolerance.PRECISION
|
|
226
|
+
results.add_result(
|
|
227
|
+
"KO <= Vanilla",
|
|
228
|
+
passed,
|
|
229
|
+
f"KO={ko_price:.6f}, Vanilla={vanilla_price:.6f}",
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
def test_barrier_monotonicity_down_out_call(results: BoundaryCheckResults) -> None:
|
|
234
|
+
"""Test: Down-and-out call decreases as barrier moves up."""
|
|
235
|
+
pricing_env = create_pricing_env(spot=100.0, rate=0.04, vol=0.20)
|
|
236
|
+
engine = BarrierAnalyticalEngine()
|
|
237
|
+
|
|
238
|
+
strike = 100.0
|
|
239
|
+
maturity = 1.0
|
|
240
|
+
|
|
241
|
+
low_barrier = 70.0
|
|
242
|
+
high_barrier = 90.0
|
|
243
|
+
|
|
244
|
+
option_low = create_barrier_option(
|
|
245
|
+
strike=strike,
|
|
246
|
+
maturity=maturity,
|
|
247
|
+
barrier=low_barrier,
|
|
248
|
+
option_type=OptionType.CALL,
|
|
249
|
+
barrier_type=BarrierType.DOWN_OUT,
|
|
250
|
+
)
|
|
251
|
+
option_high = create_barrier_option(
|
|
252
|
+
strike=strike,
|
|
253
|
+
maturity=maturity,
|
|
254
|
+
barrier=high_barrier,
|
|
255
|
+
option_type=OptionType.CALL,
|
|
256
|
+
barrier_type=BarrierType.DOWN_OUT,
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
price_low = engine.price(option_low, pricing_env)
|
|
260
|
+
price_high = engine.price(option_high, pricing_env)
|
|
261
|
+
|
|
262
|
+
passed = price_high <= price_low + Tolerance.PRECISION
|
|
263
|
+
results.add_result(
|
|
264
|
+
"Down-and-out monotonicity (barrier up)",
|
|
265
|
+
passed,
|
|
266
|
+
f"LowH={price_low:.6f}, HighH={price_high:.6f}",
|
|
267
|
+
)
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
def test_immediate_knock_out_rebate(results: BoundaryCheckResults) -> None:
|
|
271
|
+
"""Test: Immediate KO returns rebate (hit vs expiry payment)."""
|
|
272
|
+
pricing_env = create_pricing_env(spot=105.0, rate=0.03, vol=0.2)
|
|
273
|
+
engine = BarrierAnalyticalEngine()
|
|
274
|
+
|
|
275
|
+
strike = 100.0
|
|
276
|
+
barrier = 100.0
|
|
277
|
+
maturity = 1.0
|
|
278
|
+
rebate = 5.0
|
|
279
|
+
|
|
280
|
+
pay_at_hit = create_barrier_option(
|
|
281
|
+
strike=strike,
|
|
282
|
+
maturity=maturity,
|
|
283
|
+
barrier=barrier,
|
|
284
|
+
option_type=OptionType.CALL,
|
|
285
|
+
barrier_type=BarrierType.UP_OUT,
|
|
286
|
+
rebate=rebate,
|
|
287
|
+
pay_at_hit=True,
|
|
288
|
+
)
|
|
289
|
+
pay_at_expiry = create_barrier_option(
|
|
290
|
+
strike=strike,
|
|
291
|
+
maturity=maturity,
|
|
292
|
+
barrier=barrier,
|
|
293
|
+
option_type=OptionType.CALL,
|
|
294
|
+
barrier_type=BarrierType.UP_OUT,
|
|
295
|
+
rebate=rebate,
|
|
296
|
+
pay_at_hit=False,
|
|
297
|
+
)
|
|
298
|
+
|
|
299
|
+
price_hit = engine.price(pay_at_hit, pricing_env)
|
|
300
|
+
price_expiry = engine.price(pay_at_expiry, pricing_env)
|
|
301
|
+
|
|
302
|
+
expected_hit = rebate
|
|
303
|
+
expected_expiry = rebate * math.exp(-0.03 * maturity)
|
|
304
|
+
|
|
305
|
+
passed_hit = is_close(price_hit, expected_hit, abs_tol=Tolerance.PRECISION)
|
|
306
|
+
passed_expiry = is_close(
|
|
307
|
+
price_expiry,
|
|
308
|
+
expected_expiry,
|
|
309
|
+
rel_tol=1e-6,
|
|
310
|
+
abs_tol=Tolerance.PRECISION,
|
|
311
|
+
)
|
|
312
|
+
|
|
313
|
+
results.add_result(
|
|
314
|
+
"Immediate KO rebate (pay at hit)",
|
|
315
|
+
passed_hit,
|
|
316
|
+
f"Price={price_hit:.6f}, Expected={expected_hit:.6f}",
|
|
317
|
+
)
|
|
318
|
+
results.add_result(
|
|
319
|
+
"Immediate KO rebate (pay at expiry)",
|
|
320
|
+
passed_expiry,
|
|
321
|
+
f"Price={price_expiry:.6f}, Expected={expected_expiry:.6f}",
|
|
322
|
+
)
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
def test_expiry_ko_ki_parity(results: BoundaryCheckResults) -> None:
|
|
326
|
+
"""Test: KO + KI = Vanilla for expiry-only monitoring."""
|
|
327
|
+
pricing_env = create_pricing_env(spot=100.0, rate=0.02, vol=0.18)
|
|
328
|
+
engine = BarrierAnalyticalEngine()
|
|
329
|
+
bs_engine = BlackScholesEngine()
|
|
330
|
+
|
|
331
|
+
strike = 100.0
|
|
332
|
+
barrier = 110.0
|
|
333
|
+
maturity = 1.0
|
|
334
|
+
|
|
335
|
+
ko = create_barrier_option(
|
|
336
|
+
strike=strike,
|
|
337
|
+
maturity=maturity,
|
|
338
|
+
barrier=barrier,
|
|
339
|
+
option_type=OptionType.CALL,
|
|
340
|
+
barrier_type=BarrierType.UP_OUT,
|
|
341
|
+
observation_type=ObservationType.EXPIRY,
|
|
342
|
+
)
|
|
343
|
+
ki = create_barrier_option(
|
|
344
|
+
strike=strike,
|
|
345
|
+
maturity=maturity,
|
|
346
|
+
barrier=barrier,
|
|
347
|
+
option_type=OptionType.CALL,
|
|
348
|
+
barrier_type=BarrierType.UP_IN,
|
|
349
|
+
observation_type=ObservationType.EXPIRY,
|
|
350
|
+
)
|
|
351
|
+
vanilla = EuropeanVanillaOption(
|
|
352
|
+
strike=strike,
|
|
353
|
+
option_type=OptionType.CALL,
|
|
354
|
+
maturity=maturity,
|
|
355
|
+
)
|
|
356
|
+
|
|
357
|
+
ko_price = engine.price(ko, pricing_env)
|
|
358
|
+
ki_price = engine.price(ki, pricing_env)
|
|
359
|
+
vanilla_price = bs_engine.price(vanilla, pricing_env)
|
|
360
|
+
|
|
361
|
+
total = ko_price + ki_price
|
|
362
|
+
passed = is_close(
|
|
363
|
+
total,
|
|
364
|
+
vanilla_price,
|
|
365
|
+
rel_tol=1e-3,
|
|
366
|
+
abs_tol=2 * Tolerance.PRECISION,
|
|
367
|
+
)
|
|
368
|
+
results.add_result(
|
|
369
|
+
"KO + KI = Vanilla (expiry monitoring)",
|
|
370
|
+
passed,
|
|
371
|
+
f"KO+KI={total:.6f}, Vanilla={vanilla_price:.6f}",
|
|
372
|
+
)
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
def test_continuous_vs_discrete_knock_out(results: BoundaryCheckResults) -> None:
|
|
376
|
+
"""Test: Continuous monitoring knocks out more easily than discrete."""
|
|
377
|
+
pricing_env = create_pricing_env(spot=100.0, rate=0.03, vol=0.25)
|
|
378
|
+
engine = BarrierAnalyticalEngine()
|
|
379
|
+
|
|
380
|
+
strike = 100.0
|
|
381
|
+
barrier = 110.0
|
|
382
|
+
maturity = 1.0
|
|
383
|
+
observation_dates = [i / 252 for i in range(1, 253)]
|
|
384
|
+
observation_schedule = ObservationSchedule.from_legacy(
|
|
385
|
+
observation_dates=observation_dates,
|
|
386
|
+
default_barrier=barrier,
|
|
387
|
+
default_payoff=0.0,
|
|
388
|
+
frequency=ObservationFrequency.DAILY,
|
|
389
|
+
)
|
|
390
|
+
|
|
391
|
+
continuous = create_barrier_option(
|
|
392
|
+
strike=strike,
|
|
393
|
+
maturity=maturity,
|
|
394
|
+
barrier=barrier,
|
|
395
|
+
option_type=OptionType.CALL,
|
|
396
|
+
barrier_type=BarrierType.UP_OUT,
|
|
397
|
+
observation_type=ObservationType.CONTINUOUS,
|
|
398
|
+
rebate=0.0,
|
|
399
|
+
)
|
|
400
|
+
discrete = create_barrier_option(
|
|
401
|
+
strike=strike,
|
|
402
|
+
maturity=maturity,
|
|
403
|
+
barrier=barrier,
|
|
404
|
+
option_type=OptionType.CALL,
|
|
405
|
+
barrier_type=BarrierType.UP_OUT,
|
|
406
|
+
observation_type=ObservationType.DISCRETE,
|
|
407
|
+
observation_schedule=observation_schedule,
|
|
408
|
+
rebate=0.0,
|
|
409
|
+
)
|
|
410
|
+
|
|
411
|
+
price_continuous = engine.price(continuous, pricing_env)
|
|
412
|
+
price_discrete = engine.price(discrete, pricing_env)
|
|
413
|
+
|
|
414
|
+
passed = price_continuous <= price_discrete + Tolerance.PRECISION
|
|
415
|
+
results.add_result(
|
|
416
|
+
"Continuous KO <= Discrete KO",
|
|
417
|
+
passed,
|
|
418
|
+
f"Continuous={price_continuous:.6f}, Discrete={price_discrete:.6f}",
|
|
419
|
+
)
|
|
420
|
+
|
|
421
|
+
|
|
422
|
+
if __name__ == "__main__":
|
|
423
|
+
results = BoundaryCheckResults()
|
|
424
|
+
|
|
425
|
+
test_near_expiry_intrinsic(results)
|
|
426
|
+
test_knock_in_out_parity_continuous(results)
|
|
427
|
+
test_knock_out_le_vanilla(results)
|
|
428
|
+
test_barrier_monotonicity_down_out_call(results)
|
|
429
|
+
test_immediate_knock_out_rebate(results)
|
|
430
|
+
test_expiry_ko_ki_parity(results)
|
|
431
|
+
test_continuous_vs_discrete_knock_out(results)
|
|
432
|
+
|
|
433
|
+
success = results.summary()
|
|
434
|
+
sys.exit(0 if success else 1)
|