@insiderfinance/totalfinance 0.1.0
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.
- package/LICENSE +201 -0
- package/README.md +339 -0
- package/STABILITY.md +23 -0
- package/modules/backtest/dist/artifacts.d.ts +23 -0
- package/modules/backtest/dist/artifacts.d.ts.map +1 -0
- package/modules/backtest/dist/artifacts.js +22 -0
- package/modules/backtest/dist/artifacts.js.map +1 -0
- package/modules/backtest/dist/broker.d.ts +265 -0
- package/modules/backtest/dist/broker.d.ts.map +1 -0
- package/modules/backtest/dist/broker.js +1228 -0
- package/modules/backtest/dist/broker.js.map +1 -0
- package/modules/backtest/dist/costs.d.ts +67 -0
- package/modules/backtest/dist/costs.d.ts.map +1 -0
- package/modules/backtest/dist/costs.js +171 -0
- package/modules/backtest/dist/costs.js.map +1 -0
- package/modules/backtest/dist/cross-sectional/engine.d.ts +21 -0
- package/modules/backtest/dist/cross-sectional/engine.d.ts.map +1 -0
- package/modules/backtest/dist/cross-sectional/engine.js +1399 -0
- package/modules/backtest/dist/cross-sectional/engine.js.map +1 -0
- package/modules/backtest/dist/cross-sectional/folds.d.ts +134 -0
- package/modules/backtest/dist/cross-sectional/folds.d.ts.map +1 -0
- package/modules/backtest/dist/cross-sectional/folds.js +375 -0
- package/modules/backtest/dist/cross-sectional/folds.js.map +1 -0
- package/modules/backtest/dist/cross-sectional/grid.d.ts +142 -0
- package/modules/backtest/dist/cross-sectional/grid.d.ts.map +1 -0
- package/modules/backtest/dist/cross-sectional/grid.js +394 -0
- package/modules/backtest/dist/cross-sectional/grid.js.map +1 -0
- package/modules/backtest/dist/cross-sectional/index.d.ts +18 -0
- package/modules/backtest/dist/cross-sectional/index.d.ts.map +1 -0
- package/modules/backtest/dist/cross-sectional/index.js +15 -0
- package/modules/backtest/dist/cross-sectional/index.js.map +1 -0
- package/modules/backtest/dist/cross-sectional/types.d.ts +331 -0
- package/modules/backtest/dist/cross-sectional/types.d.ts.map +1 -0
- package/modules/backtest/dist/cross-sectional/types.js +12 -0
- package/modules/backtest/dist/cross-sectional/types.js.map +1 -0
- package/modules/backtest/dist/cross-sectional/validate.d.ts +22 -0
- package/modules/backtest/dist/cross-sectional/validate.d.ts.map +1 -0
- package/modules/backtest/dist/cross-sectional/validate.js +489 -0
- package/modules/backtest/dist/cross-sectional/validate.js.map +1 -0
- package/modules/backtest/dist/diagnostics.d.ts +16 -0
- package/modules/backtest/dist/diagnostics.d.ts.map +1 -0
- package/modules/backtest/dist/diagnostics.js +63 -0
- package/modules/backtest/dist/diagnostics.js.map +1 -0
- package/modules/backtest/dist/environment/bench.d.ts +34 -0
- package/modules/backtest/dist/environment/bench.d.ts.map +1 -0
- package/modules/backtest/dist/environment/bench.js +724 -0
- package/modules/backtest/dist/environment/bench.js.map +1 -0
- package/modules/backtest/dist/environment/environment.d.ts +5 -0
- package/modules/backtest/dist/environment/environment.d.ts.map +1 -0
- package/modules/backtest/dist/environment/environment.js +618 -0
- package/modules/backtest/dist/environment/environment.js.map +1 -0
- package/modules/backtest/dist/environment/episode.d.ts +4 -0
- package/modules/backtest/dist/environment/episode.d.ts.map +1 -0
- package/modules/backtest/dist/environment/episode.js +121 -0
- package/modules/backtest/dist/environment/episode.js.map +1 -0
- package/modules/backtest/dist/environment/episodes.d.ts +14 -0
- package/modules/backtest/dist/environment/episodes.d.ts.map +1 -0
- package/modules/backtest/dist/environment/episodes.js +644 -0
- package/modules/backtest/dist/environment/episodes.js.map +1 -0
- package/modules/backtest/dist/environment/features.d.ts +31 -0
- package/modules/backtest/dist/environment/features.d.ts.map +1 -0
- package/modules/backtest/dist/environment/features.js +157 -0
- package/modules/backtest/dist/environment/features.js.map +1 -0
- package/modules/backtest/dist/environment/index.d.ts +14 -0
- package/modules/backtest/dist/environment/index.d.ts.map +1 -0
- package/modules/backtest/dist/environment/index.js +12 -0
- package/modules/backtest/dist/environment/index.js.map +1 -0
- package/modules/backtest/dist/environment/limits.d.ts +63 -0
- package/modules/backtest/dist/environment/limits.d.ts.map +1 -0
- package/modules/backtest/dist/environment/limits.js +253 -0
- package/modules/backtest/dist/environment/limits.js.map +1 -0
- package/modules/backtest/dist/environment/reward.d.ts +5 -0
- package/modules/backtest/dist/environment/reward.d.ts.map +1 -0
- package/modules/backtest/dist/environment/reward.js +80 -0
- package/modules/backtest/dist/environment/reward.js.map +1 -0
- package/modules/backtest/dist/environment/types.d.ts +540 -0
- package/modules/backtest/dist/environment/types.d.ts.map +1 -0
- package/modules/backtest/dist/environment/types.js +2 -0
- package/modules/backtest/dist/environment/types.js.map +1 -0
- package/modules/backtest/dist/environment/validate.d.ts +23 -0
- package/modules/backtest/dist/environment/validate.d.ts.map +1 -0
- package/modules/backtest/dist/environment/validate.js +264 -0
- package/modules/backtest/dist/environment/validate.js.map +1 -0
- package/modules/backtest/dist/event-driven.d.ts +111 -0
- package/modules/backtest/dist/event-driven.d.ts.map +1 -0
- package/modules/backtest/dist/event-driven.js +325 -0
- package/modules/backtest/dist/event-driven.js.map +1 -0
- package/modules/backtest/dist/execution/conformance.d.ts +33 -0
- package/modules/backtest/dist/execution/conformance.d.ts.map +1 -0
- package/modules/backtest/dist/execution/conformance.js +269 -0
- package/modules/backtest/dist/execution/conformance.js.map +1 -0
- package/modules/backtest/dist/execution/fill-models.d.ts +35 -0
- package/modules/backtest/dist/execution/fill-models.d.ts.map +1 -0
- package/modules/backtest/dist/execution/fill-models.js +375 -0
- package/modules/backtest/dist/execution/fill-models.js.map +1 -0
- package/modules/backtest/dist/execution/fill-order.d.ts +55 -0
- package/modules/backtest/dist/execution/fill-order.d.ts.map +1 -0
- package/modules/backtest/dist/execution/fill-order.js +156 -0
- package/modules/backtest/dist/execution/fill-order.js.map +1 -0
- package/modules/backtest/dist/execution/index.d.ts +33 -0
- package/modules/backtest/dist/execution/index.d.ts.map +1 -0
- package/modules/backtest/dist/execution/index.js +27 -0
- package/modules/backtest/dist/execution/index.js.map +1 -0
- package/modules/backtest/dist/execution/intrabar.d.ts +46 -0
- package/modules/backtest/dist/execution/intrabar.d.ts.map +1 -0
- package/modules/backtest/dist/execution/intrabar.js +130 -0
- package/modules/backtest/dist/execution/intrabar.js.map +1 -0
- package/modules/backtest/dist/execution/normalized.d.ts +56 -0
- package/modules/backtest/dist/execution/normalized.d.ts.map +1 -0
- package/modules/backtest/dist/execution/normalized.js +154 -0
- package/modules/backtest/dist/execution/normalized.js.map +1 -0
- package/modules/backtest/dist/execution/policy.d.ts +84 -0
- package/modules/backtest/dist/execution/policy.d.ts.map +1 -0
- package/modules/backtest/dist/execution/policy.js +341 -0
- package/modules/backtest/dist/execution/policy.js.map +1 -0
- package/modules/backtest/dist/execution/types.d.ts +217 -0
- package/modules/backtest/dist/execution/types.d.ts.map +1 -0
- package/modules/backtest/dist/execution/types.js +8 -0
- package/modules/backtest/dist/execution/types.js.map +1 -0
- package/modules/backtest/dist/execution/validate.d.ts +35 -0
- package/modules/backtest/dist/execution/validate.d.ts.map +1 -0
- package/modules/backtest/dist/execution/validate.js +666 -0
- package/modules/backtest/dist/execution/validate.js.map +1 -0
- package/modules/backtest/dist/generated/validation-specs.d.ts +12 -0
- package/modules/backtest/dist/generated/validation-specs.d.ts.map +1 -0
- package/modules/backtest/dist/generated/validation-specs.js +1129 -0
- package/modules/backtest/dist/generated/validation-specs.js.map +1 -0
- package/modules/backtest/dist/index.d.ts +33 -0
- package/modules/backtest/dist/index.d.ts.map +1 -0
- package/modules/backtest/dist/index.js +28 -0
- package/modules/backtest/dist/index.js.map +1 -0
- package/modules/backtest/dist/options/chain.d.ts +68 -0
- package/modules/backtest/dist/options/chain.d.ts.map +1 -0
- package/modules/backtest/dist/options/chain.js +303 -0
- package/modules/backtest/dist/options/chain.js.map +1 -0
- package/modules/backtest/dist/options/engine.d.ts +28 -0
- package/modules/backtest/dist/options/engine.d.ts.map +1 -0
- package/modules/backtest/dist/options/engine.js +1859 -0
- package/modules/backtest/dist/options/engine.js.map +1 -0
- package/modules/backtest/dist/options/index.d.ts +23 -0
- package/modules/backtest/dist/options/index.d.ts.map +1 -0
- package/modules/backtest/dist/options/index.js +21 -0
- package/modules/backtest/dist/options/index.js.map +1 -0
- package/modules/backtest/dist/options/tearsheet.d.ts +77 -0
- package/modules/backtest/dist/options/tearsheet.d.ts.map +1 -0
- package/modules/backtest/dist/options/tearsheet.js +205 -0
- package/modules/backtest/dist/options/tearsheet.js.map +1 -0
- package/modules/backtest/dist/options/types.d.ts +571 -0
- package/modules/backtest/dist/options/types.d.ts.map +1 -0
- package/modules/backtest/dist/options/types.js +19 -0
- package/modules/backtest/dist/options/types.js.map +1 -0
- package/modules/backtest/dist/paper/index.d.ts +13 -0
- package/modules/backtest/dist/paper/index.d.ts.map +1 -0
- package/modules/backtest/dist/paper/index.js +12 -0
- package/modules/backtest/dist/paper/index.js.map +1 -0
- package/modules/backtest/dist/paper/paper.d.ts +8 -0
- package/modules/backtest/dist/paper/paper.d.ts.map +1 -0
- package/modules/backtest/dist/paper/paper.js +950 -0
- package/modules/backtest/dist/paper/paper.js.map +1 -0
- package/modules/backtest/dist/paper/types.d.ts +190 -0
- package/modules/backtest/dist/paper/types.d.ts.map +1 -0
- package/modules/backtest/dist/paper/types.js +3 -0
- package/modules/backtest/dist/paper/types.js.map +1 -0
- package/modules/backtest/dist/paper/validate.d.ts +9 -0
- package/modules/backtest/dist/paper/validate.d.ts.map +1 -0
- package/modules/backtest/dist/paper/validate.js +112 -0
- package/modules/backtest/dist/paper/validate.js.map +1 -0
- package/modules/backtest/dist/portfolio/adapters.d.ts +37 -0
- package/modules/backtest/dist/portfolio/adapters.d.ts.map +1 -0
- package/modules/backtest/dist/portfolio/adapters.js +555 -0
- package/modules/backtest/dist/portfolio/adapters.js.map +1 -0
- package/modules/backtest/dist/portfolio/engine.d.ts +35 -0
- package/modules/backtest/dist/portfolio/engine.d.ts.map +1 -0
- package/modules/backtest/dist/portfolio/engine.js +1300 -0
- package/modules/backtest/dist/portfolio/engine.js.map +1 -0
- package/modules/backtest/dist/portfolio/index.d.ts +12 -0
- package/modules/backtest/dist/portfolio/index.d.ts.map +1 -0
- package/modules/backtest/dist/portfolio/index.js +11 -0
- package/modules/backtest/dist/portfolio/index.js.map +1 -0
- package/modules/backtest/dist/portfolio/types.d.ts +418 -0
- package/modules/backtest/dist/portfolio/types.d.ts.map +1 -0
- package/modules/backtest/dist/portfolio/types.js +8 -0
- package/modules/backtest/dist/portfolio/types.js.map +1 -0
- package/modules/backtest/dist/portfolio/validate.d.ts +26 -0
- package/modules/backtest/dist/portfolio/validate.d.ts.map +1 -0
- package/modules/backtest/dist/portfolio/validate.js +556 -0
- package/modules/backtest/dist/portfolio/validate.js.map +1 -0
- package/modules/backtest/dist/run-artifacts.d.ts +425 -0
- package/modules/backtest/dist/run-artifacts.d.ts.map +1 -0
- package/modules/backtest/dist/run-artifacts.js +1843 -0
- package/modules/backtest/dist/run-artifacts.js.map +1 -0
- package/modules/backtest/dist/signals.d.ts +110 -0
- package/modules/backtest/dist/signals.d.ts.map +1 -0
- package/modules/backtest/dist/signals.js +207 -0
- package/modules/backtest/dist/signals.js.map +1 -0
- package/modules/backtest/dist/tearsheet.d.ts +126 -0
- package/modules/backtest/dist/tearsheet.d.ts.map +1 -0
- package/modules/backtest/dist/tearsheet.js +266 -0
- package/modules/backtest/dist/tearsheet.js.map +1 -0
- package/modules/backtest/dist/types.d.ts +175 -0
- package/modules/backtest/dist/types.d.ts.map +1 -0
- package/modules/backtest/dist/types.js +29 -0
- package/modules/backtest/dist/types.js.map +1 -0
- package/modules/backtest/dist/validate.d.ts +13 -0
- package/modules/backtest/dist/validate.d.ts.map +1 -0
- package/modules/backtest/dist/validate.js +37 -0
- package/modules/backtest/dist/validate.js.map +1 -0
- package/modules/backtest/dist/vectorized.d.ts +53 -0
- package/modules/backtest/dist/vectorized.d.ts.map +1 -0
- package/modules/backtest/dist/vectorized.js +383 -0
- package/modules/backtest/dist/vectorized.js.map +1 -0
- package/modules/backtest/dist/walk-forward.d.ts +57 -0
- package/modules/backtest/dist/walk-forward.d.ts.map +1 -0
- package/modules/backtest/dist/walk-forward.js +125 -0
- package/modules/backtest/dist/walk-forward.js.map +1 -0
- package/modules/backtest/etc/backtest.api.md +139 -0
- package/modules/backtest/src/artifacts.ts +54 -0
- package/modules/backtest/src/broker.ts +1529 -0
- package/modules/backtest/src/costs.ts +225 -0
- package/modules/backtest/src/cross-sectional/engine.ts +1608 -0
- package/modules/backtest/src/cross-sectional/folds.ts +718 -0
- package/modules/backtest/src/cross-sectional/grid.ts +646 -0
- package/modules/backtest/src/cross-sectional/index.ts +76 -0
- package/modules/backtest/src/cross-sectional/types.ts +363 -0
- package/modules/backtest/src/cross-sectional/validate.ts +906 -0
- package/modules/backtest/src/diagnostics.ts +66 -0
- package/modules/backtest/src/environment/bench.ts +1022 -0
- package/modules/backtest/src/environment/environment.ts +766 -0
- package/modules/backtest/src/environment/episode.ts +146 -0
- package/modules/backtest/src/environment/episodes.ts +786 -0
- package/modules/backtest/src/environment/features.ts +184 -0
- package/modules/backtest/src/environment/index.ts +79 -0
- package/modules/backtest/src/environment/limits.ts +383 -0
- package/modules/backtest/src/environment/reward.ts +98 -0
- package/modules/backtest/src/environment/types.ts +595 -0
- package/modules/backtest/src/environment/validate.ts +415 -0
- package/modules/backtest/src/event-driven.ts +528 -0
- package/modules/backtest/src/execution/conformance.ts +346 -0
- package/modules/backtest/src/execution/fill-models.ts +410 -0
- package/modules/backtest/src/execution/fill-order.ts +261 -0
- package/modules/backtest/src/execution/index.ts +91 -0
- package/modules/backtest/src/execution/intrabar.ts +185 -0
- package/modules/backtest/src/execution/normalized.ts +216 -0
- package/modules/backtest/src/execution/policy.ts +447 -0
- package/modules/backtest/src/execution/types.ts +239 -0
- package/modules/backtest/src/execution/validate.ts +889 -0
- package/modules/backtest/src/generated/validation-specs.ts +1132 -0
- package/modules/backtest/src/index.ts +157 -0
- package/modules/backtest/src/options/chain.ts +410 -0
- package/modules/backtest/src/options/engine.ts +2240 -0
- package/modules/backtest/src/options/index.ts +68 -0
- package/modules/backtest/src/options/tearsheet.ts +327 -0
- package/modules/backtest/src/options/types.ts +573 -0
- package/modules/backtest/src/paper/index.ts +27 -0
- package/modules/backtest/src/paper/paper.ts +1288 -0
- package/modules/backtest/src/paper/types.ts +221 -0
- package/modules/backtest/src/paper/validate.ts +168 -0
- package/modules/backtest/src/portfolio/adapters.ts +651 -0
- package/modules/backtest/src/portfolio/engine.ts +1518 -0
- package/modules/backtest/src/portfolio/index.ts +64 -0
- package/modules/backtest/src/portfolio/types.ts +456 -0
- package/modules/backtest/src/portfolio/validate.ts +861 -0
- package/modules/backtest/src/run-artifacts.ts +2873 -0
- package/modules/backtest/src/signals.ts +267 -0
- package/modules/backtest/src/tearsheet.ts +425 -0
- package/modules/backtest/src/types.ts +200 -0
- package/modules/backtest/src/validate.ts +43 -0
- package/modules/backtest/src/vectorized.ts +541 -0
- package/modules/backtest/src/walk-forward.ts +215 -0
- package/modules/calendars/dist/cboe.d.ts +15 -0
- package/modules/calendars/dist/cboe.d.ts.map +1 -0
- package/modules/calendars/dist/cboe.js +16 -0
- package/modules/calendars/dist/cboe.js.map +1 -0
- package/modules/calendars/dist/crypto.d.ts +15 -0
- package/modules/calendars/dist/crypto.d.ts.map +1 -0
- package/modules/calendars/dist/crypto.js +16 -0
- package/modules/calendars/dist/crypto.js.map +1 -0
- package/modules/calendars/dist/expirations.d.ts +35 -0
- package/modules/calendars/dist/expirations.d.ts.map +1 -0
- package/modules/calendars/dist/expirations.js +158 -0
- package/modules/calendars/dist/expirations.js.map +1 -0
- package/modules/calendars/dist/index.d.ts +16 -0
- package/modules/calendars/dist/index.d.ts.map +1 -0
- package/modules/calendars/dist/index.js +13 -0
- package/modules/calendars/dist/index.js.map +1 -0
- package/modules/calendars/dist/nyse.d.ts +11 -0
- package/modules/calendars/dist/nyse.d.ts.map +1 -0
- package/modules/calendars/dist/nyse.js +12 -0
- package/modules/calendars/dist/nyse.js.map +1 -0
- package/modules/calendars/dist/trading-calendar.d.ts +32 -0
- package/modules/calendars/dist/trading-calendar.d.ts.map +1 -0
- package/modules/calendars/dist/trading-calendar.js +67 -0
- package/modules/calendars/dist/trading-calendar.js.map +1 -0
- package/modules/calendars/dist/us-market.d.ts +29 -0
- package/modules/calendars/dist/us-market.d.ts.map +1 -0
- package/modules/calendars/dist/us-market.js +72 -0
- package/modules/calendars/dist/us-market.js.map +1 -0
- package/modules/calendars/etc/calendars.api.md +22 -0
- package/modules/calendars/src/cboe.ts +17 -0
- package/modules/calendars/src/crypto.ts +17 -0
- package/modules/calendars/src/expirations.ts +200 -0
- package/modules/calendars/src/index.ts +23 -0
- package/modules/calendars/src/nyse.ts +13 -0
- package/modules/calendars/src/trading-calendar.ts +85 -0
- package/modules/calendars/src/us-market.ts +86 -0
- package/modules/cli/dist/bin.d.ts +9 -0
- package/modules/cli/dist/bin.d.ts.map +1 -0
- package/modules/cli/dist/bin.js +458 -0
- package/modules/cli/dist/bin.js.map +1 -0
- package/modules/cli/dist/commands.d.ts +7 -0
- package/modules/cli/dist/commands.d.ts.map +1 -0
- package/modules/cli/dist/commands.js +17 -0
- package/modules/cli/dist/commands.js.map +1 -0
- package/modules/cli/dist/exit-codes.d.ts +20 -0
- package/modules/cli/dist/exit-codes.d.ts.map +1 -0
- package/modules/cli/dist/exit-codes.js +19 -0
- package/modules/cli/dist/exit-codes.js.map +1 -0
- package/modules/cli/dist/index.d.ts +13 -0
- package/modules/cli/dist/index.d.ts.map +1 -0
- package/modules/cli/dist/index.js +10 -0
- package/modules/cli/dist/index.js.map +1 -0
- package/modules/cli/etc/cli.api.md +25 -0
- package/modules/cli/src/bin.ts +530 -0
- package/modules/cli/src/commands.ts +19 -0
- package/modules/cli/src/exit-codes.ts +21 -0
- package/modules/cli/src/index.ts +29 -0
- package/modules/commodities/dist/forwards.d.ts +274 -0
- package/modules/commodities/dist/forwards.d.ts.map +1 -0
- package/modules/commodities/dist/forwards.js +359 -0
- package/modules/commodities/dist/forwards.js.map +1 -0
- package/modules/commodities/dist/index.d.ts +10 -0
- package/modules/commodities/dist/index.d.ts.map +1 -0
- package/modules/commodities/dist/index.js +10 -0
- package/modules/commodities/dist/index.js.map +1 -0
- package/modules/commodities/dist/internal.d.ts +6 -0
- package/modules/commodities/dist/internal.d.ts.map +1 -0
- package/modules/commodities/dist/internal.js +6 -0
- package/modules/commodities/dist/internal.js.map +1 -0
- package/modules/commodities/dist/term-structure.d.ts +327 -0
- package/modules/commodities/dist/term-structure.d.ts.map +1 -0
- package/modules/commodities/dist/term-structure.js +416 -0
- package/modules/commodities/dist/term-structure.js.map +1 -0
- package/modules/commodities/etc/commodities.api.md +53 -0
- package/modules/commodities/src/forwards.ts +791 -0
- package/modules/commodities/src/index.ts +10 -0
- package/modules/commodities/src/internal.ts +6 -0
- package/modules/commodities/src/term-structure.ts +828 -0
- package/modules/core/dist/artifacts/analysis-artifact.d.ts +140 -0
- package/modules/core/dist/artifacts/analysis-artifact.d.ts.map +1 -0
- package/modules/core/dist/artifacts/analysis-artifact.js +356 -0
- package/modules/core/dist/artifacts/analysis-artifact.js.map +1 -0
- package/modules/core/dist/artifacts/calculation-comparison.d.ts +125 -0
- package/modules/core/dist/artifacts/calculation-comparison.d.ts.map +1 -0
- package/modules/core/dist/artifacts/calculation-comparison.js +444 -0
- package/modules/core/dist/artifacts/calculation-comparison.js.map +1 -0
- package/modules/core/dist/artifacts/canonical-scan.d.ts +58 -0
- package/modules/core/dist/artifacts/canonical-scan.d.ts.map +1 -0
- package/modules/core/dist/artifacts/canonical-scan.js +250 -0
- package/modules/core/dist/artifacts/canonical-scan.js.map +1 -0
- package/modules/core/dist/artifacts/comparison.d.ts +179 -0
- package/modules/core/dist/artifacts/comparison.d.ts.map +1 -0
- package/modules/core/dist/artifacts/comparison.js +383 -0
- package/modules/core/dist/artifacts/comparison.js.map +1 -0
- package/modules/core/dist/artifacts/content-hash.d.ts +38 -0
- package/modules/core/dist/artifacts/content-hash.d.ts.map +1 -0
- package/modules/core/dist/artifacts/content-hash.js +170 -0
- package/modules/core/dist/artifacts/content-hash.js.map +1 -0
- package/modules/core/dist/artifacts/deep-freeze.d.ts +8 -0
- package/modules/core/dist/artifacts/deep-freeze.d.ts.map +1 -0
- package/modules/core/dist/artifacts/deep-freeze.js +16 -0
- package/modules/core/dist/artifacts/deep-freeze.js.map +1 -0
- package/modules/core/dist/artifacts/fitted-model-kit.d.ts +123 -0
- package/modules/core/dist/artifacts/fitted-model-kit.d.ts.map +1 -0
- package/modules/core/dist/artifacts/fitted-model-kit.js +281 -0
- package/modules/core/dist/artifacts/fitted-model-kit.js.map +1 -0
- package/modules/core/dist/artifacts/fitted-model-summary.d.ts +73 -0
- package/modules/core/dist/artifacts/fitted-model-summary.d.ts.map +1 -0
- package/modules/core/dist/artifacts/fitted-model-summary.js +254 -0
- package/modules/core/dist/artifacts/fitted-model-summary.js.map +1 -0
- package/modules/core/dist/artifacts/index.d.ts +52 -0
- package/modules/core/dist/artifacts/index.d.ts.map +1 -0
- package/modules/core/dist/artifacts/index.js +47 -0
- package/modules/core/dist/artifacts/index.js.map +1 -0
- package/modules/core/dist/artifacts/market-snapshot.d.ts +189 -0
- package/modules/core/dist/artifacts/market-snapshot.d.ts.map +1 -0
- package/modules/core/dist/artifacts/market-snapshot.js +517 -0
- package/modules/core/dist/artifacts/market-snapshot.js.map +1 -0
- package/modules/core/dist/artifacts/migration.d.ts +60 -0
- package/modules/core/dist/artifacts/migration.d.ts.map +1 -0
- package/modules/core/dist/artifacts/migration.js +106 -0
- package/modules/core/dist/artifacts/migration.js.map +1 -0
- package/modules/core/dist/artifacts/numeric-comparison.d.ts +12 -0
- package/modules/core/dist/artifacts/numeric-comparison.d.ts.map +1 -0
- package/modules/core/dist/artifacts/numeric-comparison.js +53 -0
- package/modules/core/dist/artifacts/numeric-comparison.js.map +1 -0
- package/modules/core/dist/artifacts/scenario-set.d.ts +97 -0
- package/modules/core/dist/artifacts/scenario-set.d.ts.map +1 -0
- package/modules/core/dist/artifacts/scenario-set.js +249 -0
- package/modules/core/dist/artifacts/scenario-set.js.map +1 -0
- package/modules/core/dist/artifacts/table-handle.d.ts +96 -0
- package/modules/core/dist/artifacts/table-handle.d.ts.map +1 -0
- package/modules/core/dist/artifacts/table-handle.js +253 -0
- package/modules/core/dist/artifacts/table-handle.js.map +1 -0
- package/modules/core/dist/assumptions.d.ts +52 -0
- package/modules/core/dist/assumptions.d.ts.map +1 -0
- package/modules/core/dist/assumptions.js +13 -0
- package/modules/core/dist/assumptions.js.map +1 -0
- package/modules/core/dist/calendar.d.ts +98 -0
- package/modules/core/dist/calendar.d.ts.map +1 -0
- package/modules/core/dist/calendar.js +301 -0
- package/modules/core/dist/calendar.js.map +1 -0
- package/modules/core/dist/canonical-json.d.ts +63 -0
- package/modules/core/dist/canonical-json.d.ts.map +1 -0
- package/modules/core/dist/canonical-json.js +241 -0
- package/modules/core/dist/canonical-json.js.map +1 -0
- package/modules/core/dist/computed.d.ts +31 -0
- package/modules/core/dist/computed.d.ts.map +1 -0
- package/modules/core/dist/computed.js +40 -0
- package/modules/core/dist/computed.js.map +1 -0
- package/modules/core/dist/contracts.d.ts +59 -0
- package/modules/core/dist/contracts.d.ts.map +1 -0
- package/modules/core/dist/contracts.js +9 -0
- package/modules/core/dist/contracts.js.map +1 -0
- package/modules/core/dist/dates.d.ts +31 -0
- package/modules/core/dist/dates.d.ts.map +1 -0
- package/modules/core/dist/dates.js +126 -0
- package/modules/core/dist/dates.js.map +1 -0
- package/modules/core/dist/diagnostics.d.ts +278 -0
- package/modules/core/dist/diagnostics.d.ts.map +1 -0
- package/modules/core/dist/diagnostics.js +287 -0
- package/modules/core/dist/diagnostics.js.map +1 -0
- package/modules/core/dist/errors.d.ts +324 -0
- package/modules/core/dist/errors.d.ts.map +1 -0
- package/modules/core/dist/errors.js +363 -0
- package/modules/core/dist/errors.js.map +1 -0
- package/modules/core/dist/facade.d.ts +97 -0
- package/modules/core/dist/facade.d.ts.map +1 -0
- package/modules/core/dist/facade.js +354 -0
- package/modules/core/dist/facade.js.map +1 -0
- package/modules/core/dist/index.d.ts +45 -0
- package/modules/core/dist/index.d.ts.map +1 -0
- package/modules/core/dist/index.js +23 -0
- package/modules/core/dist/index.js.map +1 -0
- package/modules/core/dist/invariants.d.ts +112 -0
- package/modules/core/dist/invariants.d.ts.map +1 -0
- package/modules/core/dist/invariants.js +240 -0
- package/modules/core/dist/invariants.js.map +1 -0
- package/modules/core/dist/market-data.d.ts +219 -0
- package/modules/core/dist/market-data.d.ts.map +1 -0
- package/modules/core/dist/market-data.js +183 -0
- package/modules/core/dist/market-data.js.map +1 -0
- package/modules/core/dist/numeric.d.ts +46 -0
- package/modules/core/dist/numeric.d.ts.map +1 -0
- package/modules/core/dist/numeric.js +145 -0
- package/modules/core/dist/numeric.js.map +1 -0
- package/modules/core/dist/orders.d.ts +28 -0
- package/modules/core/dist/orders.d.ts.map +1 -0
- package/modules/core/dist/orders.js +49 -0
- package/modules/core/dist/orders.js.map +1 -0
- package/modules/core/dist/pricing.d.ts +418 -0
- package/modules/core/dist/pricing.d.ts.map +1 -0
- package/modules/core/dist/pricing.js +987 -0
- package/modules/core/dist/pricing.js.map +1 -0
- package/modules/core/dist/provenance.d.ts +25 -0
- package/modules/core/dist/provenance.d.ts.map +1 -0
- package/modules/core/dist/provenance.js +75 -0
- package/modules/core/dist/provenance.js.map +1 -0
- package/modules/core/dist/schema/index.d.ts +14 -0
- package/modules/core/dist/schema/index.d.ts.map +1 -0
- package/modules/core/dist/schema/index.js +12 -0
- package/modules/core/dist/schema/index.js.map +1 -0
- package/modules/core/dist/schema/json-schema-guard.d.ts +21 -0
- package/modules/core/dist/schema/json-schema-guard.d.ts.map +1 -0
- package/modules/core/dist/schema/json-schema-guard.js +114 -0
- package/modules/core/dist/schema/json-schema-guard.js.map +1 -0
- package/modules/core/dist/schema/json-schema.d.ts +33 -0
- package/modules/core/dist/schema/json-schema.d.ts.map +1 -0
- package/modules/core/dist/schema/json-schema.js +3 -0
- package/modules/core/dist/schema/json-schema.js.map +1 -0
- package/modules/core/dist/schema/payloads.d.ts +429 -0
- package/modules/core/dist/schema/payloads.d.ts.map +1 -0
- package/modules/core/dist/schema/payloads.js +323 -0
- package/modules/core/dist/schema/payloads.js.map +1 -0
- package/modules/core/dist/schema/schema.d.ts +282 -0
- package/modules/core/dist/schema/schema.d.ts.map +1 -0
- package/modules/core/dist/schema/schema.js +780 -0
- package/modules/core/dist/schema/schema.js.map +1 -0
- package/modules/core/dist/schema/standard.d.ts +32 -0
- package/modules/core/dist/schema/standard.d.ts.map +1 -0
- package/modules/core/dist/schema/standard.js +8 -0
- package/modules/core/dist/schema/standard.js.map +1 -0
- package/modules/core/dist/symbology.d.ts +30 -0
- package/modules/core/dist/symbology.d.ts.map +1 -0
- package/modules/core/dist/symbology.js +126 -0
- package/modules/core/dist/symbology.js.map +1 -0
- package/modules/core/dist/time.d.ts +122 -0
- package/modules/core/dist/time.d.ts.map +1 -0
- package/modules/core/dist/time.js +349 -0
- package/modules/core/dist/time.js.map +1 -0
- package/modules/core/dist/validation-codes.d.ts +24 -0
- package/modules/core/dist/validation-codes.d.ts.map +1 -0
- package/modules/core/dist/validation-codes.js +24 -0
- package/modules/core/dist/validation-codes.js.map +1 -0
- package/modules/core/dist/validation.d.ts +117 -0
- package/modules/core/dist/validation.d.ts.map +1 -0
- package/modules/core/dist/validation.js +415 -0
- package/modules/core/dist/validation.js.map +1 -0
- package/modules/core/etc/core.api.md +157 -0
- package/modules/core/src/artifacts/analysis-artifact.ts +515 -0
- package/modules/core/src/artifacts/calculation-comparison.ts +641 -0
- package/modules/core/src/artifacts/canonical-scan.ts +358 -0
- package/modules/core/src/artifacts/comparison.ts +586 -0
- package/modules/core/src/artifacts/content-hash.ts +183 -0
- package/modules/core/src/artifacts/deep-freeze.ts +15 -0
- package/modules/core/src/artifacts/fitted-model-kit.ts +402 -0
- package/modules/core/src/artifacts/fitted-model-summary.ts +478 -0
- package/modules/core/src/artifacts/index.ts +155 -0
- package/modules/core/src/artifacts/market-snapshot.ts +787 -0
- package/modules/core/src/artifacts/migration.ts +195 -0
- package/modules/core/src/artifacts/numeric-comparison.ts +71 -0
- package/modules/core/src/artifacts/scenario-set.ts +383 -0
- package/modules/core/src/artifacts/table-handle.ts +329 -0
- package/modules/core/src/assumptions.ts +62 -0
- package/modules/core/src/calendar.ts +407 -0
- package/modules/core/src/canonical-json.ts +289 -0
- package/modules/core/src/computed.ts +55 -0
- package/modules/core/src/contracts.ts +63 -0
- package/modules/core/src/dates.ts +163 -0
- package/modules/core/src/diagnostics.ts +397 -0
- package/modules/core/src/errors.ts +404 -0
- package/modules/core/src/facade.ts +436 -0
- package/modules/core/src/index.ts +185 -0
- package/modules/core/src/invariants.ts +339 -0
- package/modules/core/src/market-data.ts +481 -0
- package/modules/core/src/numeric.ts +205 -0
- package/modules/core/src/orders.ts +71 -0
- package/modules/core/src/pricing.ts +1647 -0
- package/modules/core/src/provenance.ts +121 -0
- package/modules/core/src/schema/index.ts +61 -0
- package/modules/core/src/schema/json-schema-guard.ts +172 -0
- package/modules/core/src/schema/json-schema.ts +52 -0
- package/modules/core/src/schema/payloads.ts +364 -0
- package/modules/core/src/schema/schema.ts +986 -0
- package/modules/core/src/schema/standard.ts +40 -0
- package/modules/core/src/symbology.ts +170 -0
- package/modules/core/src/time.ts +458 -0
- package/modules/core/src/validation-codes.ts +23 -0
- package/modules/core/src/validation.ts +607 -0
- package/modules/crypto/dist/carry.d.ts +176 -0
- package/modules/crypto/dist/carry.d.ts.map +1 -0
- package/modules/crypto/dist/carry.js +349 -0
- package/modules/crypto/dist/carry.js.map +1 -0
- package/modules/crypto/dist/curve.d.ts +69 -0
- package/modules/crypto/dist/curve.d.ts.map +1 -0
- package/modules/crypto/dist/curve.js +180 -0
- package/modules/crypto/dist/curve.js.map +1 -0
- package/modules/crypto/dist/index.d.ts +20 -0
- package/modules/crypto/dist/index.d.ts.map +1 -0
- package/modules/crypto/dist/index.js +16 -0
- package/modules/crypto/dist/index.js.map +1 -0
- package/modules/crypto/dist/inverse.d.ts +61 -0
- package/modules/crypto/dist/inverse.d.ts.map +1 -0
- package/modules/crypto/dist/inverse.js +89 -0
- package/modules/crypto/dist/inverse.js.map +1 -0
- package/modules/crypto/dist/liquidation.d.ts +67 -0
- package/modules/crypto/dist/liquidation.d.ts.map +1 -0
- package/modules/crypto/dist/liquidation.js +103 -0
- package/modules/crypto/dist/liquidation.js.map +1 -0
- package/modules/crypto/etc/crypto.api.md +45 -0
- package/modules/crypto/src/carry.ts +656 -0
- package/modules/crypto/src/curve.ts +273 -0
- package/modules/crypto/src/index.ts +62 -0
- package/modules/crypto/src/inverse.ts +172 -0
- package/modules/crypto/src/liquidation.ts +174 -0
- package/modules/fixed-income/dist/artifacts.d.ts +24 -0
- package/modules/fixed-income/dist/artifacts.d.ts.map +1 -0
- package/modules/fixed-income/dist/artifacts.js +21 -0
- package/modules/fixed-income/dist/artifacts.js.map +1 -0
- package/modules/fixed-income/dist/bonds.d.ts +298 -0
- package/modules/fixed-income/dist/bonds.d.ts.map +1 -0
- package/modules/fixed-income/dist/bonds.js +951 -0
- package/modules/fixed-income/dist/bonds.js.map +1 -0
- package/modules/fixed-income/dist/conventions.d.ts +77 -0
- package/modules/fixed-income/dist/conventions.d.ts.map +1 -0
- package/modules/fixed-income/dist/conventions.js +266 -0
- package/modules/fixed-income/dist/conventions.js.map +1 -0
- package/modules/fixed-income/dist/convertible.d.ts +76 -0
- package/modules/fixed-income/dist/convertible.d.ts.map +1 -0
- package/modules/fixed-income/dist/convertible.js +182 -0
- package/modules/fixed-income/dist/convertible.js.map +1 -0
- package/modules/fixed-income/dist/credit.d.ts +227 -0
- package/modules/fixed-income/dist/credit.d.ts.map +1 -0
- package/modules/fixed-income/dist/credit.js +653 -0
- package/modules/fixed-income/dist/credit.js.map +1 -0
- package/modules/fixed-income/dist/cross-currency.d.ts +82 -0
- package/modules/fixed-income/dist/cross-currency.d.ts.map +1 -0
- package/modules/fixed-income/dist/cross-currency.js +93 -0
- package/modules/fixed-income/dist/cross-currency.js.map +1 -0
- package/modules/fixed-income/dist/curve-data.d.ts +70 -0
- package/modules/fixed-income/dist/curve-data.d.ts.map +1 -0
- package/modules/fixed-income/dist/curve-data.js +254 -0
- package/modules/fixed-income/dist/curve-data.js.map +1 -0
- package/modules/fixed-income/dist/curve-mappers.d.ts +57 -0
- package/modules/fixed-income/dist/curve-mappers.d.ts.map +1 -0
- package/modules/fixed-income/dist/curve-mappers.js +131 -0
- package/modules/fixed-income/dist/curve-mappers.js.map +1 -0
- package/modules/fixed-income/dist/curve-state.d.ts +47 -0
- package/modules/fixed-income/dist/curve-state.d.ts.map +1 -0
- package/modules/fixed-income/dist/curve-state.js +33 -0
- package/modules/fixed-income/dist/curve-state.js.map +1 -0
- package/modules/fixed-income/dist/curves.d.ts +198 -0
- package/modules/fixed-income/dist/curves.d.ts.map +1 -0
- package/modules/fixed-income/dist/curves.js +803 -0
- package/modules/fixed-income/dist/curves.js.map +1 -0
- package/modules/fixed-income/dist/fitted-model-artifacts.d.ts +277 -0
- package/modules/fixed-income/dist/fitted-model-artifacts.d.ts.map +1 -0
- package/modules/fixed-income/dist/fitted-model-artifacts.js +839 -0
- package/modules/fixed-income/dist/fitted-model-artifacts.js.map +1 -0
- package/modules/fixed-income/dist/fitted-model-families.d.ts +170 -0
- package/modules/fixed-income/dist/fitted-model-families.d.ts.map +1 -0
- package/modules/fixed-income/dist/fitted-model-families.js +461 -0
- package/modules/fixed-income/dist/fitted-model-families.js.map +1 -0
- package/modules/fixed-income/dist/futures.d.ts +264 -0
- package/modules/fixed-income/dist/futures.d.ts.map +1 -0
- package/modules/fixed-income/dist/futures.js +630 -0
- package/modules/fixed-income/dist/futures.js.map +1 -0
- package/modules/fixed-income/dist/generated/validation-specs.d.ts +12 -0
- package/modules/fixed-income/dist/generated/validation-specs.d.ts.map +1 -0
- package/modules/fixed-income/dist/generated/validation-specs.js +556 -0
- package/modules/fixed-income/dist/generated/validation-specs.js.map +1 -0
- package/modules/fixed-income/dist/index.d.ts +36 -0
- package/modules/fixed-income/dist/index.d.ts.map +1 -0
- package/modules/fixed-income/dist/index.js +37 -0
- package/modules/fixed-income/dist/index.js.map +1 -0
- package/modules/fixed-income/dist/inflation.d.ts +174 -0
- package/modules/fixed-income/dist/inflation.d.ts.map +1 -0
- package/modules/fixed-income/dist/inflation.js +335 -0
- package/modules/fixed-income/dist/inflation.js.map +1 -0
- package/modules/fixed-income/dist/lattice.d.ts +156 -0
- package/modules/fixed-income/dist/lattice.d.ts.map +1 -0
- package/modules/fixed-income/dist/lattice.js +433 -0
- package/modules/fixed-income/dist/lattice.js.map +1 -0
- package/modules/fixed-income/dist/models.d.ts +187 -0
- package/modules/fixed-income/dist/models.d.ts.map +1 -0
- package/modules/fixed-income/dist/models.js +580 -0
- package/modules/fixed-income/dist/models.js.map +1 -0
- package/modules/fixed-income/dist/pricer.d.ts +48 -0
- package/modules/fixed-income/dist/pricer.d.ts.map +1 -0
- package/modules/fixed-income/dist/pricer.js +445 -0
- package/modules/fixed-income/dist/pricer.js.map +1 -0
- package/modules/fixed-income/dist/rates.d.ts +305 -0
- package/modules/fixed-income/dist/rates.d.ts.map +1 -0
- package/modules/fixed-income/dist/rates.js +686 -0
- package/modules/fixed-income/dist/rates.js.map +1 -0
- package/modules/fixed-income/dist/validate.d.ts +28 -0
- package/modules/fixed-income/dist/validate.d.ts.map +1 -0
- package/modules/fixed-income/dist/validate.js +123 -0
- package/modules/fixed-income/dist/validate.js.map +1 -0
- package/modules/fixed-income/dist/xva.d.ts +88 -0
- package/modules/fixed-income/dist/xva.d.ts.map +1 -0
- package/modules/fixed-income/dist/xva.js +316 -0
- package/modules/fixed-income/dist/xva.js.map +1 -0
- package/modules/fixed-income/etc/fixed-income.api.md +195 -0
- package/modules/fixed-income/src/artifacts.ts +60 -0
- package/modules/fixed-income/src/bonds.ts +1514 -0
- package/modules/fixed-income/src/conventions.ts +387 -0
- package/modules/fixed-income/src/convertible.ts +286 -0
- package/modules/fixed-income/src/credit.ts +1065 -0
- package/modules/fixed-income/src/cross-currency.ts +176 -0
- package/modules/fixed-income/src/curve-data.ts +381 -0
- package/modules/fixed-income/src/curve-mappers.ts +170 -0
- package/modules/fixed-income/src/curve-state.ts +70 -0
- package/modules/fixed-income/src/curves.ts +1169 -0
- package/modules/fixed-income/src/fitted-model-artifacts.ts +1414 -0
- package/modules/fixed-income/src/fitted-model-families.ts +834 -0
- package/modules/fixed-income/src/futures.ts +1018 -0
- package/modules/fixed-income/src/generated/validation-specs.ts +559 -0
- package/modules/fixed-income/src/index.ts +241 -0
- package/modules/fixed-income/src/inflation.ts +554 -0
- package/modules/fixed-income/src/lattice.ts +675 -0
- package/modules/fixed-income/src/models.ts +897 -0
- package/modules/fixed-income/src/pricer.ts +624 -0
- package/modules/fixed-income/src/rates.ts +1086 -0
- package/modules/fixed-income/src/validate.ts +169 -0
- package/modules/fixed-income/src/xva.ts +466 -0
- package/modules/foreign-exchange/dist/exposure.d.ts +140 -0
- package/modules/foreign-exchange/dist/exposure.d.ts.map +1 -0
- package/modules/foreign-exchange/dist/exposure.js +253 -0
- package/modules/foreign-exchange/dist/exposure.js.map +1 -0
- package/modules/foreign-exchange/dist/forwards.d.ts +159 -0
- package/modules/foreign-exchange/dist/forwards.d.ts.map +1 -0
- package/modules/foreign-exchange/dist/forwards.js +310 -0
- package/modules/foreign-exchange/dist/forwards.js.map +1 -0
- package/modules/foreign-exchange/dist/index.d.ts +11 -0
- package/modules/foreign-exchange/dist/index.d.ts.map +1 -0
- package/modules/foreign-exchange/dist/index.js +11 -0
- package/modules/foreign-exchange/dist/index.js.map +1 -0
- package/modules/foreign-exchange/dist/internal.d.ts +6 -0
- package/modules/foreign-exchange/dist/internal.d.ts.map +1 -0
- package/modules/foreign-exchange/dist/internal.js +6 -0
- package/modules/foreign-exchange/dist/internal.js.map +1 -0
- package/modules/foreign-exchange/dist/spot.d.ts +150 -0
- package/modules/foreign-exchange/dist/spot.d.ts.map +1 -0
- package/modules/foreign-exchange/dist/spot.js +289 -0
- package/modules/foreign-exchange/dist/spot.js.map +1 -0
- package/modules/foreign-exchange/etc/foreign-exchange.api.md +52 -0
- package/modules/foreign-exchange/src/exposure.ts +485 -0
- package/modules/foreign-exchange/src/forwards.ts +595 -0
- package/modules/foreign-exchange/src/index.ts +11 -0
- package/modules/foreign-exchange/src/internal.ts +6 -0
- package/modules/foreign-exchange/src/spot.ts +530 -0
- package/modules/fundamentals/dist/analyze.d.ts +90 -0
- package/modules/fundamentals/dist/analyze.d.ts.map +1 -0
- package/modules/fundamentals/dist/analyze.js +293 -0
- package/modules/fundamentals/dist/analyze.js.map +1 -0
- package/modules/fundamentals/dist/index.d.ts +17 -0
- package/modules/fundamentals/dist/index.d.ts.map +1 -0
- package/modules/fundamentals/dist/index.js +15 -0
- package/modules/fundamentals/dist/index.js.map +1 -0
- package/modules/fundamentals/dist/periods.d.ts +47 -0
- package/modules/fundamentals/dist/periods.d.ts.map +1 -0
- package/modules/fundamentals/dist/periods.js +106 -0
- package/modules/fundamentals/dist/periods.js.map +1 -0
- package/modules/fundamentals/dist/ratio-heads.d.ts +47 -0
- package/modules/fundamentals/dist/ratio-heads.d.ts.map +1 -0
- package/modules/fundamentals/dist/ratio-heads.js +766 -0
- package/modules/fundamentals/dist/ratio-heads.js.map +1 -0
- package/modules/fundamentals/dist/ratio-internals.d.ts +187 -0
- package/modules/fundamentals/dist/ratio-internals.d.ts.map +1 -0
- package/modules/fundamentals/dist/ratio-internals.js +299 -0
- package/modules/fundamentals/dist/ratio-internals.js.map +1 -0
- package/modules/fundamentals/dist/ratios.d.ts +9 -0
- package/modules/fundamentals/dist/ratios.d.ts.map +1 -0
- package/modules/fundamentals/dist/ratios.js +8 -0
- package/modules/fundamentals/dist/ratios.js.map +1 -0
- package/modules/fundamentals/dist/score-heads.d.ts +130 -0
- package/modules/fundamentals/dist/score-heads.d.ts.map +1 -0
- package/modules/fundamentals/dist/score-heads.js +364 -0
- package/modules/fundamentals/dist/score-heads.js.map +1 -0
- package/modules/fundamentals/dist/scores.d.ts +6 -0
- package/modules/fundamentals/dist/scores.d.ts.map +1 -0
- package/modules/fundamentals/dist/scores.js +6 -0
- package/modules/fundamentals/dist/scores.js.map +1 -0
- package/modules/fundamentals/dist/statement-contracts.d.ts +170 -0
- package/modules/fundamentals/dist/statement-contracts.d.ts.map +1 -0
- package/modules/fundamentals/dist/statement-contracts.js +207 -0
- package/modules/fundamentals/dist/statement-contracts.js.map +1 -0
- package/modules/fundamentals/dist/statement-utilities.d.ts +190 -0
- package/modules/fundamentals/dist/statement-utilities.d.ts.map +1 -0
- package/modules/fundamentals/dist/statement-utilities.js +501 -0
- package/modules/fundamentals/dist/statement-utilities.js.map +1 -0
- package/modules/fundamentals/dist/statements.d.ts +8 -0
- package/modules/fundamentals/dist/statements.d.ts.map +1 -0
- package/modules/fundamentals/dist/statements.js +7 -0
- package/modules/fundamentals/dist/statements.js.map +1 -0
- package/modules/fundamentals/etc/fundamentals.api.md +110 -0
- package/modules/fundamentals/src/analyze.ts +401 -0
- package/modules/fundamentals/src/index.ts +24 -0
- package/modules/fundamentals/src/periods.ts +197 -0
- package/modules/fundamentals/src/ratio-heads.ts +945 -0
- package/modules/fundamentals/src/ratio-internals.ts +562 -0
- package/modules/fundamentals/src/ratios.ts +23 -0
- package/modules/fundamentals/src/score-heads.ts +651 -0
- package/modules/fundamentals/src/scores.ts +6 -0
- package/modules/fundamentals/src/statement-contracts.ts +393 -0
- package/modules/fundamentals/src/statement-utilities.ts +833 -0
- package/modules/fundamentals/src/statements.ts +22 -0
- package/modules/http/dist/bin.d.ts +7 -0
- package/modules/http/dist/bin.d.ts.map +1 -0
- package/modules/http/dist/bin.js +167 -0
- package/modules/http/dist/bin.js.map +1 -0
- package/modules/http/dist/index.d.ts +10 -0
- package/modules/http/dist/index.d.ts.map +1 -0
- package/modules/http/dist/index.js +8 -0
- package/modules/http/dist/index.js.map +1 -0
- package/modules/http/dist/openapi.d.ts +38 -0
- package/modules/http/dist/openapi.d.ts.map +1 -0
- package/modules/http/dist/openapi.js +431 -0
- package/modules/http/dist/openapi.js.map +1 -0
- package/modules/http/dist/security.d.ts +21 -0
- package/modules/http/dist/security.d.ts.map +1 -0
- package/modules/http/dist/security.js +116 -0
- package/modules/http/dist/security.js.map +1 -0
- package/modules/http/dist/server.d.ts +63 -0
- package/modules/http/dist/server.d.ts.map +1 -0
- package/modules/http/dist/server.js +544 -0
- package/modules/http/dist/server.js.map +1 -0
- package/modules/http/etc/http.api.md +15 -0
- package/modules/http/etc/openapi.json +51958 -0
- package/modules/http/src/bin.ts +190 -0
- package/modules/http/src/index.ts +10 -0
- package/modules/http/src/openapi.ts +488 -0
- package/modules/http/src/security.ts +158 -0
- package/modules/http/src/server.ts +941 -0
- package/modules/math/dist/bivariate.d.ts +17 -0
- package/modules/math/dist/bivariate.d.ts.map +1 -0
- package/modules/math/dist/bivariate.js +123 -0
- package/modules/math/dist/bivariate.js.map +1 -0
- package/modules/math/dist/distributions.d.ts +66 -0
- package/modules/math/dist/distributions.d.ts.map +1 -0
- package/modules/math/dist/distributions.js +465 -0
- package/modules/math/dist/distributions.js.map +1 -0
- package/modules/math/dist/filters.d.ts +96 -0
- package/modules/math/dist/filters.d.ts.map +1 -0
- package/modules/math/dist/filters.js +347 -0
- package/modules/math/dist/filters.js.map +1 -0
- package/modules/math/dist/index.d.ts +34 -0
- package/modules/math/dist/index.d.ts.map +1 -0
- package/modules/math/dist/index.js +23 -0
- package/modules/math/dist/index.js.map +1 -0
- package/modules/math/dist/integration.d.ts +58 -0
- package/modules/math/dist/integration.d.ts.map +1 -0
- package/modules/math/dist/integration.js +176 -0
- package/modules/math/dist/integration.js.map +1 -0
- package/modules/math/dist/interpolation.d.ts +57 -0
- package/modules/math/dist/interpolation.d.ts.map +1 -0
- package/modules/math/dist/interpolation.js +464 -0
- package/modules/math/dist/interpolation.js.map +1 -0
- package/modules/math/dist/linalg.d.ts +251 -0
- package/modules/math/dist/linalg.d.ts.map +1 -0
- package/modules/math/dist/linalg.js +1503 -0
- package/modules/math/dist/linalg.js.map +1 -0
- package/modules/math/dist/lowdiscrepancy.d.ts +21 -0
- package/modules/math/dist/lowdiscrepancy.d.ts.map +1 -0
- package/modules/math/dist/lowdiscrepancy.js +200 -0
- package/modules/math/dist/lowdiscrepancy.js.map +1 -0
- package/modules/math/dist/montecarlo.d.ts +58 -0
- package/modules/math/dist/montecarlo.d.ts.map +1 -0
- package/modules/math/dist/montecarlo.js +248 -0
- package/modules/math/dist/montecarlo.js.map +1 -0
- package/modules/math/dist/normal.d.ts +40 -0
- package/modules/math/dist/normal.d.ts.map +1 -0
- package/modules/math/dist/normal.js +157 -0
- package/modules/math/dist/normal.js.map +1 -0
- package/modules/math/dist/optimize.d.ts +83 -0
- package/modules/math/dist/optimize.d.ts.map +1 -0
- package/modules/math/dist/optimize.js +784 -0
- package/modules/math/dist/optimize.js.map +1 -0
- package/modules/math/dist/random.d.ts +76 -0
- package/modules/math/dist/random.d.ts.map +1 -0
- package/modules/math/dist/random.js +261 -0
- package/modules/math/dist/random.js.map +1 -0
- package/modules/math/dist/regression.d.ts +58 -0
- package/modules/math/dist/regression.d.ts.map +1 -0
- package/modules/math/dist/regression.js +283 -0
- package/modules/math/dist/regression.js.map +1 -0
- package/modules/math/dist/resource-validation.d.ts +18 -0
- package/modules/math/dist/resource-validation.d.ts.map +1 -0
- package/modules/math/dist/resource-validation.js +60 -0
- package/modules/math/dist/resource-validation.js.map +1 -0
- package/modules/math/dist/sobol-data.d.ts +36 -0
- package/modules/math/dist/sobol-data.d.ts.map +1 -0
- package/modules/math/dist/sobol-data.js +172 -0
- package/modules/math/dist/sobol-data.js.map +1 -0
- package/modules/math/dist/solvers.d.ts +90 -0
- package/modules/math/dist/solvers.d.ts.map +1 -0
- package/modules/math/dist/solvers.js +663 -0
- package/modules/math/dist/solvers.js.map +1 -0
- package/modules/math/dist/statistics-internal.d.ts +73 -0
- package/modules/math/dist/statistics-internal.d.ts.map +1 -0
- package/modules/math/dist/statistics-internal.js +217 -0
- package/modules/math/dist/statistics-internal.js.map +1 -0
- package/modules/math/dist/statistics.d.ts +113 -0
- package/modules/math/dist/statistics.d.ts.map +1 -0
- package/modules/math/dist/statistics.js +545 -0
- package/modules/math/dist/statistics.js.map +1 -0
- package/modules/math/dist/timeseries.d.ts +131 -0
- package/modules/math/dist/timeseries.d.ts.map +1 -0
- package/modules/math/dist/timeseries.js +502 -0
- package/modules/math/dist/timeseries.js.map +1 -0
- package/modules/math/etc/math.api.md +178 -0
- package/modules/math/src/bivariate.ts +124 -0
- package/modules/math/src/distributions.ts +481 -0
- package/modules/math/src/filters.ts +452 -0
- package/modules/math/src/index.ts +223 -0
- package/modules/math/src/integration.ts +259 -0
- package/modules/math/src/interpolation.ts +588 -0
- package/modules/math/src/linalg.ts +1892 -0
- package/modules/math/src/lowdiscrepancy.ts +241 -0
- package/modules/math/src/montecarlo.ts +326 -0
- package/modules/math/src/normal.ts +161 -0
- package/modules/math/src/optimize.ts +943 -0
- package/modules/math/src/random.ts +372 -0
- package/modules/math/src/regression.ts +340 -0
- package/modules/math/src/resource-validation.ts +79 -0
- package/modules/math/src/sobol-data.ts +187 -0
- package/modules/math/src/solvers.ts +859 -0
- package/modules/math/src/statistics-internal.ts +256 -0
- package/modules/math/src/statistics.ts +636 -0
- package/modules/math/src/timeseries.ts +611 -0
- package/modules/options/dist/american-iv.d.ts +116 -0
- package/modules/options/dist/american-iv.d.ts.map +1 -0
- package/modules/options/dist/american-iv.js +385 -0
- package/modules/options/dist/american-iv.js.map +1 -0
- package/modules/options/dist/arbitrage.d.ts +42 -0
- package/modules/options/dist/arbitrage.d.ts.map +1 -0
- package/modules/options/dist/arbitrage.js +79 -0
- package/modules/options/dist/arbitrage.js.map +1 -0
- package/modules/options/dist/bachelier.d.ts +68 -0
- package/modules/options/dist/bachelier.d.ts.map +1 -0
- package/modules/options/dist/bachelier.js +348 -0
- package/modules/options/dist/bachelier.js.map +1 -0
- package/modules/options/dist/batch.d.ts +82 -0
- package/modules/options/dist/batch.d.ts.map +1 -0
- package/modules/options/dist/batch.js +346 -0
- package/modules/options/dist/batch.js.map +1 -0
- package/modules/options/dist/black-scholes.d.ts +42 -0
- package/modules/options/dist/black-scholes.d.ts.map +1 -0
- package/modules/options/dist/black-scholes.js +334 -0
- package/modules/options/dist/black-scholes.js.map +1 -0
- package/modules/options/dist/black76.d.ts +77 -0
- package/modules/options/dist/black76.d.ts.map +1 -0
- package/modules/options/dist/black76.js +400 -0
- package/modules/options/dist/black76.js.map +1 -0
- package/modules/options/dist/bsm.d.ts +120 -0
- package/modules/options/dist/bsm.d.ts.map +1 -0
- package/modules/options/dist/bsm.js +414 -0
- package/modules/options/dist/bsm.js.map +1 -0
- package/modules/options/dist/chain-greeks.d.ts +69 -0
- package/modules/options/dist/chain-greeks.d.ts.map +1 -0
- package/modules/options/dist/chain-greeks.js +154 -0
- package/modules/options/dist/chain-greeks.js.map +1 -0
- package/modules/options/dist/chain-health.d.ts +254 -0
- package/modules/options/dist/chain-health.d.ts.map +1 -0
- package/modules/options/dist/chain-health.js +746 -0
- package/modules/options/dist/chain-health.js.map +1 -0
- package/modules/options/dist/contract.d.ts +73 -0
- package/modules/options/dist/contract.d.ts.map +1 -0
- package/modules/options/dist/contract.js +226 -0
- package/modules/options/dist/contract.js.map +1 -0
- package/modules/options/dist/dividend-term-structure.d.ts +76 -0
- package/modules/options/dist/dividend-term-structure.d.ts.map +1 -0
- package/modules/options/dist/dividend-term-structure.js +180 -0
- package/modules/options/dist/dividend-term-structure.js.map +1 -0
- package/modules/options/dist/dividends.d.ts +34 -0
- package/modules/options/dist/dividends.d.ts.map +1 -0
- package/modules/options/dist/dividends.js +51 -0
- package/modules/options/dist/dividends.js.map +1 -0
- package/modules/options/dist/engine-bsm.d.ts +22 -0
- package/modules/options/dist/engine-bsm.d.ts.map +1 -0
- package/modules/options/dist/engine-bsm.js +236 -0
- package/modules/options/dist/engine-bsm.js.map +1 -0
- package/modules/options/dist/engines/american-approx.d.ts +29 -0
- package/modules/options/dist/engines/american-approx.d.ts.map +1 -0
- package/modules/options/dist/engines/american-approx.js +483 -0
- package/modules/options/dist/engines/american-approx.js.map +1 -0
- package/modules/options/dist/engines/bounds.d.ts +49 -0
- package/modules/options/dist/engines/bounds.d.ts.map +1 -0
- package/modules/options/dist/engines/bounds.js +58 -0
- package/modules/options/dist/engines/bounds.js.map +1 -0
- package/modules/options/dist/engines/engine-factory.d.ts +92 -0
- package/modules/options/dist/engines/engine-factory.d.ts.map +1 -0
- package/modules/options/dist/engines/engine-factory.js +372 -0
- package/modules/options/dist/engines/engine-factory.js.map +1 -0
- package/modules/options/dist/engines/fd-greeks.d.ts +84 -0
- package/modules/options/dist/engines/fd-greeks.d.ts.map +1 -0
- package/modules/options/dist/engines/fd-greeks.js +343 -0
- package/modules/options/dist/engines/fd-greeks.js.map +1 -0
- package/modules/options/dist/engines/fdm.d.ts +78 -0
- package/modules/options/dist/engines/fdm.d.ts.map +1 -0
- package/modules/options/dist/engines/fdm.js +218 -0
- package/modules/options/dist/engines/fdm.js.map +1 -0
- package/modules/options/dist/engines/scalar-pricing.d.ts +24 -0
- package/modules/options/dist/engines/scalar-pricing.d.ts.map +1 -0
- package/modules/options/dist/engines/scalar-pricing.js +2 -0
- package/modules/options/dist/engines/scalar-pricing.js.map +1 -0
- package/modules/options/dist/engines/tree.d.ts +78 -0
- package/modules/options/dist/engines/tree.d.ts.map +1 -0
- package/modules/options/dist/engines/tree.js +247 -0
- package/modules/options/dist/engines/tree.js.map +1 -0
- package/modules/options/dist/engines.d.ts +272 -0
- package/modules/options/dist/engines.d.ts.map +1 -0
- package/modules/options/dist/engines.js +1309 -0
- package/modules/options/dist/engines.js.map +1 -0
- package/modules/options/dist/equity-lattice.d.ts +58 -0
- package/modules/options/dist/equity-lattice.d.ts.map +1 -0
- package/modules/options/dist/equity-lattice.js +139 -0
- package/modules/options/dist/equity-lattice.js.map +1 -0
- package/modules/options/dist/exercise.d.ts +80 -0
- package/modules/options/dist/exercise.d.ts.map +1 -0
- package/modules/options/dist/exercise.js +266 -0
- package/modules/options/dist/exercise.js.map +1 -0
- package/modules/options/dist/exotics.d.ts +640 -0
- package/modules/options/dist/exotics.d.ts.map +1 -0
- package/modules/options/dist/exotics.js +2880 -0
- package/modules/options/dist/exotics.js.map +1 -0
- package/modules/options/dist/facade-util.d.ts +51 -0
- package/modules/options/dist/facade-util.d.ts.map +1 -0
- package/modules/options/dist/facade-util.js +93 -0
- package/modules/options/dist/facade-util.js.map +1 -0
- package/modules/options/dist/generated/validation-specs.d.ts +12 -0
- package/modules/options/dist/generated/validation-specs.d.ts.map +1 -0
- package/modules/options/dist/generated/validation-specs.js +2616 -0
- package/modules/options/dist/generated/validation-specs.js.map +1 -0
- package/modules/options/dist/heston.d.ts +160 -0
- package/modules/options/dist/heston.d.ts.map +1 -0
- package/modules/options/dist/heston.js +983 -0
- package/modules/options/dist/heston.js.map +1 -0
- package/modules/options/dist/index.d.ts +65 -0
- package/modules/options/dist/index.d.ts.map +1 -0
- package/modules/options/dist/index.js +58 -0
- package/modules/options/dist/index.js.map +1 -0
- package/modules/options/dist/iv.d.ts +85 -0
- package/modules/options/dist/iv.d.ts.map +1 -0
- package/modules/options/dist/iv.js +424 -0
- package/modules/options/dist/iv.js.map +1 -0
- package/modules/options/dist/lattice.d.ts +7 -0
- package/modules/options/dist/lattice.d.ts.map +1 -0
- package/modules/options/dist/lattice.js +7 -0
- package/modules/options/dist/lattice.js.map +1 -0
- package/modules/options/dist/local-volatility.d.ts +128 -0
- package/modules/options/dist/local-volatility.d.ts.map +1 -0
- package/modules/options/dist/local-volatility.js +333 -0
- package/modules/options/dist/local-volatility.js.map +1 -0
- package/modules/options/dist/market.d.ts +19 -0
- package/modules/options/dist/market.d.ts.map +1 -0
- package/modules/options/dist/market.js +58 -0
- package/modules/options/dist/market.js.map +1 -0
- package/modules/options/dist/mc/complex.d.ts +23 -0
- package/modules/options/dist/mc/complex.d.ts.map +1 -0
- package/modules/options/dist/mc/complex.js +42 -0
- package/modules/options/dist/mc/complex.js.map +1 -0
- package/modules/options/dist/mc/core.d.ts +151 -0
- package/modules/options/dist/mc/core.d.ts.map +1 -0
- package/modules/options/dist/mc/core.js +319 -0
- package/modules/options/dist/mc/core.js.map +1 -0
- package/modules/options/dist/monte-carlo.d.ts +66 -0
- package/modules/options/dist/monte-carlo.d.ts.map +1 -0
- package/modules/options/dist/monte-carlo.js +388 -0
- package/modules/options/dist/monte-carlo.js.map +1 -0
- package/modules/options/dist/parity.d.ts +191 -0
- package/modules/options/dist/parity.d.ts.map +1 -0
- package/modules/options/dist/parity.js +566 -0
- package/modules/options/dist/parity.js.map +1 -0
- package/modules/options/dist/payoff-kernel.d.ts +33 -0
- package/modules/options/dist/payoff-kernel.d.ts.map +1 -0
- package/modules/options/dist/payoff-kernel.js +27 -0
- package/modules/options/dist/payoff-kernel.js.map +1 -0
- package/modules/options/dist/payoff.d.ts +34 -0
- package/modules/options/dist/payoff.d.ts.map +1 -0
- package/modules/options/dist/payoff.js +60 -0
- package/modules/options/dist/payoff.js.map +1 -0
- package/modules/options/dist/pricer.d.ts +44 -0
- package/modules/options/dist/pricer.d.ts.map +1 -0
- package/modules/options/dist/pricer.js +179 -0
- package/modules/options/dist/pricer.js.map +1 -0
- package/modules/options/dist/pro.d.ts +82 -0
- package/modules/options/dist/pro.d.ts.map +1 -0
- package/modules/options/dist/pro.js +177 -0
- package/modules/options/dist/pro.js.map +1 -0
- package/modules/options/dist/quote.d.ts +18 -0
- package/modules/options/dist/quote.d.ts.map +1 -0
- package/modules/options/dist/quote.js +26 -0
- package/modules/options/dist/quote.js.map +1 -0
- package/modules/options/dist/resource-validation-internal.d.ts +8 -0
- package/modules/options/dist/resource-validation-internal.d.ts.map +1 -0
- package/modules/options/dist/resource-validation-internal.js +23 -0
- package/modules/options/dist/resource-validation-internal.js.map +1 -0
- package/modules/options/dist/sabr.d.ts +153 -0
- package/modules/options/dist/sabr.d.ts.map +1 -0
- package/modules/options/dist/sabr.js +515 -0
- package/modules/options/dist/sabr.js.map +1 -0
- package/modules/options/dist/schema.d.ts +120 -0
- package/modules/options/dist/schema.d.ts.map +1 -0
- package/modules/options/dist/schema.js +62 -0
- package/modules/options/dist/schema.js.map +1 -0
- package/modules/options/dist/time.d.ts +44 -0
- package/modules/options/dist/time.d.ts.map +1 -0
- package/modules/options/dist/time.js +76 -0
- package/modules/options/dist/time.js.map +1 -0
- package/modules/options/dist/types.d.ts +115 -0
- package/modules/options/dist/types.d.ts.map +1 -0
- package/modules/options/dist/types.js +3 -0
- package/modules/options/dist/types.js.map +1 -0
- package/modules/options/etc/options.api.md +230 -0
- package/modules/options/src/american-iv.ts +547 -0
- package/modules/options/src/arbitrage.ts +134 -0
- package/modules/options/src/bachelier.ts +515 -0
- package/modules/options/src/batch.ts +496 -0
- package/modules/options/src/black-scholes.ts +501 -0
- package/modules/options/src/black76.ts +573 -0
- package/modules/options/src/bsm.ts +575 -0
- package/modules/options/src/chain-greeks.ts +242 -0
- package/modules/options/src/chain-health.ts +1083 -0
- package/modules/options/src/contract.ts +329 -0
- package/modules/options/src/dividend-term-structure.ts +303 -0
- package/modules/options/src/dividends.ts +75 -0
- package/modules/options/src/engine-bsm.ts +306 -0
- package/modules/options/src/engines/american-approx.ts +669 -0
- package/modules/options/src/engines/bounds.ts +106 -0
- package/modules/options/src/engines/engine-factory.ts +502 -0
- package/modules/options/src/engines/fd-greeks.ts +426 -0
- package/modules/options/src/engines/fdm.ts +302 -0
- package/modules/options/src/engines/scalar-pricing.ts +27 -0
- package/modules/options/src/engines/tree.ts +350 -0
- package/modules/options/src/engines.ts +1845 -0
- package/modules/options/src/equity-lattice.ts +224 -0
- package/modules/options/src/exercise.ts +422 -0
- package/modules/options/src/exotics.ts +3966 -0
- package/modules/options/src/facade-util.ts +137 -0
- package/modules/options/src/generated/validation-specs.ts +2621 -0
- package/modules/options/src/heston.ts +1348 -0
- package/modules/options/src/index.ts +325 -0
- package/modules/options/src/iv.ts +591 -0
- package/modules/options/src/lattice.ts +6 -0
- package/modules/options/src/local-volatility.ts +493 -0
- package/modules/options/src/market.ts +74 -0
- package/modules/options/src/mc/complex.ts +55 -0
- package/modules/options/src/mc/core.ts +538 -0
- package/modules/options/src/monte-carlo.ts +567 -0
- package/modules/options/src/parity.ts +928 -0
- package/modules/options/src/payoff-kernel.ts +39 -0
- package/modules/options/src/payoff.ts +81 -0
- package/modules/options/src/pricer.ts +217 -0
- package/modules/options/src/pro.ts +272 -0
- package/modules/options/src/quote.ts +34 -0
- package/modules/options/src/resource-validation-internal.ts +31 -0
- package/modules/options/src/sabr.ts +716 -0
- package/modules/options/src/schema.ts +73 -0
- package/modules/options/src/time.ts +104 -0
- package/modules/options/src/types.ts +124 -0
- package/modules/performance/dist/activity.d.ts +24 -0
- package/modules/performance/dist/activity.d.ts.map +1 -0
- package/modules/performance/dist/activity.js +137 -0
- package/modules/performance/dist/activity.js.map +1 -0
- package/modules/performance/dist/analyze.d.ts +85 -0
- package/modules/performance/dist/analyze.d.ts.map +1 -0
- package/modules/performance/dist/analyze.js +203 -0
- package/modules/performance/dist/analyze.js.map +1 -0
- package/modules/performance/dist/annualization-internal.d.ts +21 -0
- package/modules/performance/dist/annualization-internal.d.ts.map +1 -0
- package/modules/performance/dist/annualization-internal.js +34 -0
- package/modules/performance/dist/annualization-internal.js.map +1 -0
- package/modules/performance/dist/drawdown.d.ts +34 -0
- package/modules/performance/dist/drawdown.d.ts.map +1 -0
- package/modules/performance/dist/drawdown.js +99 -0
- package/modules/performance/dist/drawdown.js.map +1 -0
- package/modules/performance/dist/flow-aware.d.ts +388 -0
- package/modules/performance/dist/flow-aware.d.ts.map +1 -0
- package/modules/performance/dist/flow-aware.js +888 -0
- package/modules/performance/dist/flow-aware.js.map +1 -0
- package/modules/performance/dist/index.d.ts +26 -0
- package/modules/performance/dist/index.d.ts.map +1 -0
- package/modules/performance/dist/index.js +25 -0
- package/modules/performance/dist/index.js.map +1 -0
- package/modules/performance/dist/metrics.d.ts +13 -0
- package/modules/performance/dist/metrics.d.ts.map +1 -0
- package/modules/performance/dist/metrics.js +87 -0
- package/modules/performance/dist/metrics.js.map +1 -0
- package/modules/performance/dist/ratios.d.ts +55 -0
- package/modules/performance/dist/ratios.d.ts.map +1 -0
- package/modules/performance/dist/ratios.js +168 -0
- package/modules/performance/dist/ratios.js.map +1 -0
- package/modules/performance/dist/relative.d.ts +33 -0
- package/modules/performance/dist/relative.d.ts.map +1 -0
- package/modules/performance/dist/relative.js +150 -0
- package/modules/performance/dist/relative.js.map +1 -0
- package/modules/performance/dist/returns.d.ts +18 -0
- package/modules/performance/dist/returns.d.ts.map +1 -0
- package/modules/performance/dist/returns.js +70 -0
- package/modules/performance/dist/returns.js.map +1 -0
- package/modules/performance/dist/rolling.d.ts +36 -0
- package/modules/performance/dist/rolling.d.ts.map +1 -0
- package/modules/performance/dist/rolling.js +102 -0
- package/modules/performance/dist/rolling.js.map +1 -0
- package/modules/performance/dist/sector-performance-internal.d.ts +61 -0
- package/modules/performance/dist/sector-performance-internal.d.ts.map +1 -0
- package/modules/performance/dist/sector-performance-internal.js +216 -0
- package/modules/performance/dist/sector-performance-internal.js.map +1 -0
- package/modules/performance/dist/sector-performance.d.ts +288 -0
- package/modules/performance/dist/sector-performance.d.ts.map +1 -0
- package/modules/performance/dist/sector-performance.js +690 -0
- package/modules/performance/dist/sector-performance.js.map +1 -0
- package/modules/performance/dist/sharpe.d.ts +74 -0
- package/modules/performance/dist/sharpe.d.ts.map +1 -0
- package/modules/performance/dist/sharpe.js +157 -0
- package/modules/performance/dist/sharpe.js.map +1 -0
- package/modules/performance/etc/performance.api.md +109 -0
- package/modules/performance/src/activity.ts +182 -0
- package/modules/performance/src/analyze.ts +305 -0
- package/modules/performance/src/annualization-internal.ts +43 -0
- package/modules/performance/src/drawdown.ts +132 -0
- package/modules/performance/src/flow-aware.ts +1518 -0
- package/modules/performance/src/index.ts +89 -0
- package/modules/performance/src/metrics.ts +150 -0
- package/modules/performance/src/ratios.ts +243 -0
- package/modules/performance/src/relative.ts +278 -0
- package/modules/performance/src/returns.ts +80 -0
- package/modules/performance/src/rolling.ts +155 -0
- package/modules/performance/src/sector-performance-internal.ts +293 -0
- package/modules/performance/src/sector-performance.ts +1263 -0
- package/modules/performance/src/sharpe.ts +256 -0
- package/modules/portfolio/dist/allocation.d.ts +227 -0
- package/modules/portfolio/dist/allocation.d.ts.map +1 -0
- package/modules/portfolio/dist/allocation.js +545 -0
- package/modules/portfolio/dist/allocation.js.map +1 -0
- package/modules/portfolio/dist/events.d.ts +502 -0
- package/modules/portfolio/dist/events.d.ts.map +1 -0
- package/modules/portfolio/dist/events.js +1061 -0
- package/modules/portfolio/dist/events.js.map +1 -0
- package/modules/portfolio/dist/index.d.ts +47 -0
- package/modules/portfolio/dist/index.d.ts.map +1 -0
- package/modules/portfolio/dist/index.js +34 -0
- package/modules/portfolio/dist/index.js.map +1 -0
- package/modules/portfolio/dist/internal.d.ts +101 -0
- package/modules/portfolio/dist/internal.d.ts.map +1 -0
- package/modules/portfolio/dist/internal.js +356 -0
- package/modules/portfolio/dist/internal.js.map +1 -0
- package/modules/portfolio/dist/ledger.d.ts +129 -0
- package/modules/portfolio/dist/ledger.d.ts.map +1 -0
- package/modules/portfolio/dist/ledger.js +271 -0
- package/modules/portfolio/dist/ledger.js.map +1 -0
- package/modules/portfolio/dist/lifecycle-corporate.d.ts +49 -0
- package/modules/portfolio/dist/lifecycle-corporate.d.ts.map +1 -0
- package/modules/portfolio/dist/lifecycle-corporate.js +462 -0
- package/modules/portfolio/dist/lifecycle-corporate.js.map +1 -0
- package/modules/portfolio/dist/lifecycle-derivatives.d.ts +59 -0
- package/modules/portfolio/dist/lifecycle-derivatives.d.ts.map +1 -0
- package/modules/portfolio/dist/lifecycle-derivatives.js +422 -0
- package/modules/portfolio/dist/lifecycle-derivatives.js.map +1 -0
- package/modules/portfolio/dist/marks.d.ts +44 -0
- package/modules/portfolio/dist/marks.d.ts.map +1 -0
- package/modules/portfolio/dist/marks.js +81 -0
- package/modules/portfolio/dist/marks.js.map +1 -0
- package/modules/portfolio/dist/monitor.d.ts +222 -0
- package/modules/portfolio/dist/monitor.d.ts.map +1 -0
- package/modules/portfolio/dist/monitor.js +1806 -0
- package/modules/portfolio/dist/monitor.js.map +1 -0
- package/modules/portfolio/dist/performance.d.ts +78 -0
- package/modules/portfolio/dist/performance.d.ts.map +1 -0
- package/modules/portfolio/dist/performance.js +146 -0
- package/modules/portfolio/dist/performance.js.map +1 -0
- package/modules/portfolio/dist/pnl.d.ts +154 -0
- package/modules/portfolio/dist/pnl.d.ts.map +1 -0
- package/modules/portfolio/dist/pnl.js +548 -0
- package/modules/portfolio/dist/pnl.js.map +1 -0
- package/modules/portfolio/dist/policy-grammar.d.ts +358 -0
- package/modules/portfolio/dist/policy-grammar.d.ts.map +1 -0
- package/modules/portfolio/dist/policy-grammar.js +1198 -0
- package/modules/portfolio/dist/policy-grammar.js.map +1 -0
- package/modules/portfolio/dist/policy.d.ts +24 -0
- package/modules/portfolio/dist/policy.d.ts.map +1 -0
- package/modules/portfolio/dist/policy.js +20 -0
- package/modules/portfolio/dist/policy.js.map +1 -0
- package/modules/portfolio/dist/rebalance.d.ts +281 -0
- package/modules/portfolio/dist/rebalance.d.ts.map +1 -0
- package/modules/portfolio/dist/rebalance.js +1236 -0
- package/modules/portfolio/dist/rebalance.js.map +1 -0
- package/modules/portfolio/dist/reconciliation.d.ts +150 -0
- package/modules/portfolio/dist/reconciliation.d.ts.map +1 -0
- package/modules/portfolio/dist/reconciliation.js +392 -0
- package/modules/portfolio/dist/reconciliation.js.map +1 -0
- package/modules/portfolio/dist/reducer-kernel.d.ts +92 -0
- package/modules/portfolio/dist/reducer-kernel.d.ts.map +1 -0
- package/modules/portfolio/dist/reducer-kernel.js +320 -0
- package/modules/portfolio/dist/reducer-kernel.js.map +1 -0
- package/modules/portfolio/dist/snapshot.d.ts +128 -0
- package/modules/portfolio/dist/snapshot.d.ts.map +1 -0
- package/modules/portfolio/dist/snapshot.js +205 -0
- package/modules/portfolio/dist/snapshot.js.map +1 -0
- package/modules/portfolio/dist/state.d.ts +196 -0
- package/modules/portfolio/dist/state.d.ts.map +1 -0
- package/modules/portfolio/dist/state.js +1093 -0
- package/modules/portfolio/dist/state.js.map +1 -0
- package/modules/portfolio/dist/timeline.d.ts +107 -0
- package/modules/portfolio/dist/timeline.d.ts.map +1 -0
- package/modules/portfolio/dist/timeline.js +220 -0
- package/modules/portfolio/dist/timeline.js.map +1 -0
- package/modules/portfolio/dist/trade/grant.d.ts +21 -0
- package/modules/portfolio/dist/trade/grant.d.ts.map +1 -0
- package/modules/portfolio/dist/trade/grant.js +411 -0
- package/modules/portfolio/dist/trade/grant.js.map +1 -0
- package/modules/portfolio/dist/trade/index.d.ts +20 -0
- package/modules/portfolio/dist/trade/index.d.ts.map +1 -0
- package/modules/portfolio/dist/trade/index.js +17 -0
- package/modules/portfolio/dist/trade/index.js.map +1 -0
- package/modules/portfolio/dist/trade/journal.d.ts +23 -0
- package/modules/portfolio/dist/trade/journal.d.ts.map +1 -0
- package/modules/portfolio/dist/trade/journal.js +352 -0
- package/modules/portfolio/dist/trade/journal.js.map +1 -0
- package/modules/portfolio/dist/trade/plan.d.ts +25 -0
- package/modules/portfolio/dist/trade/plan.d.ts.map +1 -0
- package/modules/portfolio/dist/trade/plan.js +285 -0
- package/modules/portfolio/dist/trade/plan.js.map +1 -0
- package/modules/portfolio/dist/trade/policy.d.ts +5 -0
- package/modules/portfolio/dist/trade/policy.d.ts.map +1 -0
- package/modules/portfolio/dist/trade/policy.js +133 -0
- package/modules/portfolio/dist/trade/policy.js.map +1 -0
- package/modules/portfolio/dist/trade/preflight.d.ts +3 -0
- package/modules/portfolio/dist/trade/preflight.d.ts.map +1 -0
- package/modules/portfolio/dist/trade/preflight.js +381 -0
- package/modules/portfolio/dist/trade/preflight.js.map +1 -0
- package/modules/portfolio/dist/trade/reconcile.d.ts +8 -0
- package/modules/portfolio/dist/trade/reconcile.d.ts.map +1 -0
- package/modules/portfolio/dist/trade/reconcile.js +240 -0
- package/modules/portfolio/dist/trade/reconcile.js.map +1 -0
- package/modules/portfolio/dist/trade/types.d.ts +559 -0
- package/modules/portfolio/dist/trade/types.d.ts.map +1 -0
- package/modules/portfolio/dist/trade/types.js +36 -0
- package/modules/portfolio/dist/trade/types.js.map +1 -0
- package/modules/portfolio/dist/trade/validate.d.ts +36 -0
- package/modules/portfolio/dist/trade/validate.d.ts.map +1 -0
- package/modules/portfolio/dist/trade/validate.js +776 -0
- package/modules/portfolio/dist/trade/validate.js.map +1 -0
- package/modules/portfolio/etc/portfolio.api.md +236 -0
- package/modules/portfolio/src/allocation.ts +844 -0
- package/modules/portfolio/src/events.ts +1968 -0
- package/modules/portfolio/src/index.ts +295 -0
- package/modules/portfolio/src/internal.ts +523 -0
- package/modules/portfolio/src/ledger.ts +420 -0
- package/modules/portfolio/src/lifecycle-corporate.ts +888 -0
- package/modules/portfolio/src/lifecycle-derivatives.ts +735 -0
- package/modules/portfolio/src/marks.ts +140 -0
- package/modules/portfolio/src/monitor.ts +2421 -0
- package/modules/portfolio/src/performance.ts +237 -0
- package/modules/portfolio/src/pnl.ts +840 -0
- package/modules/portfolio/src/policy-grammar.ts +1891 -0
- package/modules/portfolio/src/policy.ts +119 -0
- package/modules/portfolio/src/rebalance.ts +1742 -0
- package/modules/portfolio/src/reconciliation.ts +621 -0
- package/modules/portfolio/src/reducer-kernel.ts +512 -0
- package/modules/portfolio/src/snapshot.ts +372 -0
- package/modules/portfolio/src/state.ts +1776 -0
- package/modules/portfolio/src/timeline.ts +359 -0
- package/modules/portfolio/src/trade/grant.ts +514 -0
- package/modules/portfolio/src/trade/index.ts +96 -0
- package/modules/portfolio/src/trade/journal.ts +432 -0
- package/modules/portfolio/src/trade/plan.ts +424 -0
- package/modules/portfolio/src/trade/policy.ts +153 -0
- package/modules/portfolio/src/trade/preflight.ts +605 -0
- package/modules/portfolio/src/trade/reconcile.ts +276 -0
- package/modules/portfolio/src/trade/types.ts +637 -0
- package/modules/portfolio/src/trade/validate.ts +1213 -0
- package/modules/research/dist/artifacts.d.ts +25 -0
- package/modules/research/dist/artifacts.d.ts.map +1 -0
- package/modules/research/dist/artifacts.js +22 -0
- package/modules/research/dist/artifacts.js.map +1 -0
- package/modules/research/dist/events.d.ts +238 -0
- package/modules/research/dist/events.d.ts.map +1 -0
- package/modules/research/dist/events.js +844 -0
- package/modules/research/dist/events.js.map +1 -0
- package/modules/research/dist/factors.d.ts +330 -0
- package/modules/research/dist/factors.d.ts.map +1 -0
- package/modules/research/dist/factors.js +891 -0
- package/modules/research/dist/factors.js.map +1 -0
- package/modules/research/dist/index.d.ts +11 -0
- package/modules/research/dist/index.d.ts.map +1 -0
- package/modules/research/dist/index.js +13 -0
- package/modules/research/dist/index.js.map +1 -0
- package/modules/research/dist/observations.d.ts +77 -0
- package/modules/research/dist/observations.d.ts.map +1 -0
- package/modules/research/dist/observations.js +201 -0
- package/modules/research/dist/observations.js.map +1 -0
- package/modules/research/dist/point-in-time.d.ts +17 -0
- package/modules/research/dist/point-in-time.d.ts.map +1 -0
- package/modules/research/dist/point-in-time.js +34 -0
- package/modules/research/dist/point-in-time.js.map +1 -0
- package/modules/research/dist/research-hygiene.d.ts +126 -0
- package/modules/research/dist/research-hygiene.d.ts.map +1 -0
- package/modules/research/dist/research-hygiene.js +290 -0
- package/modules/research/dist/research-hygiene.js.map +1 -0
- package/modules/research/dist/research-run-artifacts.d.ts +315 -0
- package/modules/research/dist/research-run-artifacts.d.ts.map +1 -0
- package/modules/research/dist/research-run-artifacts.js +766 -0
- package/modules/research/dist/research-run-artifacts.js.map +1 -0
- package/modules/research/dist/research-run-kinds.d.ts +135 -0
- package/modules/research/dist/research-run-kinds.d.ts.map +1 -0
- package/modules/research/dist/research-run-kinds.js +470 -0
- package/modules/research/dist/research-run-kinds.js.map +1 -0
- package/modules/research/dist/screening.d.ts +215 -0
- package/modules/research/dist/screening.d.ts.map +1 -0
- package/modules/research/dist/screening.js +616 -0
- package/modules/research/dist/screening.js.map +1 -0
- package/modules/research/dist/universe.d.ts +131 -0
- package/modules/research/dist/universe.d.ts.map +1 -0
- package/modules/research/dist/universe.js +294 -0
- package/modules/research/dist/universe.js.map +1 -0
- package/modules/research/etc/research.api.md +109 -0
- package/modules/research/src/artifacts.ts +68 -0
- package/modules/research/src/events.ts +1358 -0
- package/modules/research/src/factors.ts +1322 -0
- package/modules/research/src/index.ts +28 -0
- package/modules/research/src/observations.ts +360 -0
- package/modules/research/src/point-in-time.ts +44 -0
- package/modules/research/src/research-hygiene.ts +544 -0
- package/modules/research/src/research-run-artifacts.ts +1464 -0
- package/modules/research/src/research-run-kinds.ts +723 -0
- package/modules/research/src/screening.ts +957 -0
- package/modules/research/src/universe.ts +494 -0
- package/modules/risk/dist/attribution.d.ts +166 -0
- package/modules/risk/dist/attribution.d.ts.map +1 -0
- package/modules/risk/dist/attribution.js +278 -0
- package/modules/risk/dist/attribution.js.map +1 -0
- package/modules/risk/dist/book-var.d.ts +113 -0
- package/modules/risk/dist/book-var.d.ts.map +1 -0
- package/modules/risk/dist/book-var.js +487 -0
- package/modules/risk/dist/book-var.js.map +1 -0
- package/modules/risk/dist/book.d.ts +95 -0
- package/modules/risk/dist/book.d.ts.map +1 -0
- package/modules/risk/dist/book.js +201 -0
- package/modules/risk/dist/book.js.map +1 -0
- package/modules/risk/dist/covariance.d.ts +96 -0
- package/modules/risk/dist/covariance.d.ts.map +1 -0
- package/modules/risk/dist/covariance.js +183 -0
- package/modules/risk/dist/covariance.js.map +1 -0
- package/modules/risk/dist/evt.d.ts +188 -0
- package/modules/risk/dist/evt.d.ts.map +1 -0
- package/modules/risk/dist/evt.js +625 -0
- package/modules/risk/dist/evt.js.map +1 -0
- package/modules/risk/dist/expected-returns.d.ts +139 -0
- package/modules/risk/dist/expected-returns.d.ts.map +1 -0
- package/modules/risk/dist/expected-returns.js +350 -0
- package/modules/risk/dist/expected-returns.js.map +1 -0
- package/modules/risk/dist/factor.d.ts +66 -0
- package/modules/risk/dist/factor.d.ts.map +1 -0
- package/modules/risk/dist/factor.js +133 -0
- package/modules/risk/dist/factor.js.map +1 -0
- package/modules/risk/dist/frontier.d.ts +158 -0
- package/modules/risk/dist/frontier.d.ts.map +1 -0
- package/modules/risk/dist/frontier.js +1183 -0
- package/modules/risk/dist/frontier.js.map +1 -0
- package/modules/risk/dist/index.d.ts +47 -0
- package/modules/risk/dist/index.d.ts.map +1 -0
- package/modules/risk/dist/index.js +43 -0
- package/modules/risk/dist/index.js.map +1 -0
- package/modules/risk/dist/input-description.d.ts +3 -0
- package/modules/risk/dist/input-description.d.ts.map +1 -0
- package/modules/risk/dist/input-description.js +24 -0
- package/modules/risk/dist/input-description.js.map +1 -0
- package/modules/risk/dist/kelly.d.ts +217 -0
- package/modules/risk/dist/kelly.d.ts.map +1 -0
- package/modules/risk/dist/kelly.js +731 -0
- package/modules/risk/dist/kelly.js.map +1 -0
- package/modules/risk/dist/linalg.d.ts +27 -0
- package/modules/risk/dist/linalg.d.ts.map +1 -0
- package/modules/risk/dist/linalg.js +89 -0
- package/modules/risk/dist/linalg.js.map +1 -0
- package/modules/risk/dist/numeric-vector.d.ts +9 -0
- package/modules/risk/dist/numeric-vector.d.ts.map +1 -0
- package/modules/risk/dist/numeric-vector.js +112 -0
- package/modules/risk/dist/numeric-vector.js.map +1 -0
- package/modules/risk/dist/optimize.d.ts +231 -0
- package/modules/risk/dist/optimize.d.ts.map +1 -0
- package/modules/risk/dist/optimize.js +1258 -0
- package/modules/risk/dist/optimize.js.map +1 -0
- package/modules/risk/dist/optimizer-validation.d.ts +26 -0
- package/modules/risk/dist/optimizer-validation.d.ts.map +1 -0
- package/modules/risk/dist/optimizer-validation.js +306 -0
- package/modules/risk/dist/optimizer-validation.js.map +1 -0
- package/modules/risk/dist/options-internal.d.ts +18 -0
- package/modules/risk/dist/options-internal.d.ts.map +1 -0
- package/modules/risk/dist/options-internal.js +49 -0
- package/modules/risk/dist/options-internal.js.map +1 -0
- package/modules/risk/dist/pnl-explain.d.ts +169 -0
- package/modules/risk/dist/pnl-explain.d.ts.map +1 -0
- package/modules/risk/dist/pnl-explain.js +327 -0
- package/modules/risk/dist/pnl-explain.js.map +1 -0
- package/modules/risk/dist/portfolio.d.ts +322 -0
- package/modules/risk/dist/portfolio.d.ts.map +1 -0
- package/modules/risk/dist/portfolio.js +547 -0
- package/modules/risk/dist/portfolio.js.map +1 -0
- package/modules/risk/dist/research-protocol.d.ts +74 -0
- package/modules/risk/dist/research-protocol.d.ts.map +1 -0
- package/modules/risk/dist/research-protocol.js +193 -0
- package/modules/risk/dist/research-protocol.js.map +1 -0
- package/modules/risk/dist/research.d.ts +255 -0
- package/modules/risk/dist/research.d.ts.map +1 -0
- package/modules/risk/dist/research.js +752 -0
- package/modules/risk/dist/research.js.map +1 -0
- package/modules/risk/dist/scenario.d.ts +279 -0
- package/modules/risk/dist/scenario.d.ts.map +1 -0
- package/modules/risk/dist/scenario.js +458 -0
- package/modules/risk/dist/scenario.js.map +1 -0
- package/modules/risk/dist/sizing.d.ts +14 -0
- package/modules/risk/dist/sizing.d.ts.map +1 -0
- package/modules/risk/dist/sizing.js +12 -0
- package/modules/risk/dist/sizing.js.map +1 -0
- package/modules/risk/dist/strategy-shape.d.ts +84 -0
- package/modules/risk/dist/strategy-shape.d.ts.map +1 -0
- package/modules/risk/dist/strategy-shape.js +17 -0
- package/modules/risk/dist/strategy-shape.js.map +1 -0
- package/modules/risk/dist/value-at-risk.d.ts +240 -0
- package/modules/risk/dist/value-at-risk.d.ts.map +1 -0
- package/modules/risk/dist/value-at-risk.js +743 -0
- package/modules/risk/dist/value-at-risk.js.map +1 -0
- package/modules/risk/etc/risk.api.md +228 -0
- package/modules/risk/src/attribution.ts +480 -0
- package/modules/risk/src/book-var.ts +717 -0
- package/modules/risk/src/book.ts +327 -0
- package/modules/risk/src/covariance.ts +293 -0
- package/modules/risk/src/evt.ts +899 -0
- package/modules/risk/src/expected-returns.ts +572 -0
- package/modules/risk/src/factor.ts +199 -0
- package/modules/risk/src/frontier.ts +1570 -0
- package/modules/risk/src/index.ts +281 -0
- package/modules/risk/src/input-description.ts +15 -0
- package/modules/risk/src/kelly.ts +1119 -0
- package/modules/risk/src/linalg.ts +100 -0
- package/modules/risk/src/numeric-vector.ts +153 -0
- package/modules/risk/src/optimize.ts +1769 -0
- package/modules/risk/src/optimizer-validation.ts +467 -0
- package/modules/risk/src/options-internal.ts +73 -0
- package/modules/risk/src/pnl-explain.ts +544 -0
- package/modules/risk/src/portfolio.ts +911 -0
- package/modules/risk/src/research-protocol.ts +277 -0
- package/modules/risk/src/research.ts +1076 -0
- package/modules/risk/src/scenario.ts +728 -0
- package/modules/risk/src/sizing.ts +15 -0
- package/modules/risk/src/strategy-shape.ts +90 -0
- package/modules/risk/src/value-at-risk.ts +1102 -0
- package/modules/scenarios/dist/aggregates.d.ts +27 -0
- package/modules/scenarios/dist/aggregates.d.ts.map +1 -0
- package/modules/scenarios/dist/aggregates.js +262 -0
- package/modules/scenarios/dist/aggregates.js.map +1 -0
- package/modules/scenarios/dist/fx.d.ts +69 -0
- package/modules/scenarios/dist/fx.d.ts.map +1 -0
- package/modules/scenarios/dist/fx.js +349 -0
- package/modules/scenarios/dist/fx.js.map +1 -0
- package/modules/scenarios/dist/index.d.ts +6 -0
- package/modules/scenarios/dist/index.d.ts.map +1 -0
- package/modules/scenarios/dist/index.js +6 -0
- package/modules/scenarios/dist/index.js.map +1 -0
- package/modules/scenarios/dist/internal/behaviors.d.ts +28 -0
- package/modules/scenarios/dist/internal/behaviors.d.ts.map +1 -0
- package/modules/scenarios/dist/internal/behaviors.js +169 -0
- package/modules/scenarios/dist/internal/behaviors.js.map +1 -0
- package/modules/scenarios/dist/internal/data.d.ts +35 -0
- package/modules/scenarios/dist/internal/data.d.ts.map +1 -0
- package/modules/scenarios/dist/internal/data.js +194 -0
- package/modules/scenarios/dist/internal/data.js.map +1 -0
- package/modules/scenarios/dist/internal/failures.d.ts +18 -0
- package/modules/scenarios/dist/internal/failures.d.ts.map +1 -0
- package/modules/scenarios/dist/internal/failures.js +184 -0
- package/modules/scenarios/dist/internal/failures.js.map +1 -0
- package/modules/scenarios/dist/internal/results.d.ts +18 -0
- package/modules/scenarios/dist/internal/results.d.ts.map +1 -0
- package/modules/scenarios/dist/internal/results.js +100 -0
- package/modules/scenarios/dist/internal/results.js.map +1 -0
- package/modules/scenarios/dist/market-resolution.d.ts +32 -0
- package/modules/scenarios/dist/market-resolution.d.ts.map +1 -0
- package/modules/scenarios/dist/market-resolution.js +296 -0
- package/modules/scenarios/dist/market-resolution.js.map +1 -0
- package/modules/scenarios/dist/portfolio.d.ts +11 -0
- package/modules/scenarios/dist/portfolio.d.ts.map +1 -0
- package/modules/scenarios/dist/portfolio.js +419 -0
- package/modules/scenarios/dist/portfolio.js.map +1 -0
- package/modules/scenarios/dist/run.d.ts +4 -0
- package/modules/scenarios/dist/run.d.ts.map +1 -0
- package/modules/scenarios/dist/run.js +933 -0
- package/modules/scenarios/dist/run.js.map +1 -0
- package/modules/scenarios/dist/spot-pricer.d.ts +21 -0
- package/modules/scenarios/dist/spot-pricer.d.ts.map +1 -0
- package/modules/scenarios/dist/spot-pricer.js +97 -0
- package/modules/scenarios/dist/spot-pricer.js.map +1 -0
- package/modules/scenarios/dist/targets.d.ts +18 -0
- package/modules/scenarios/dist/targets.d.ts.map +1 -0
- package/modules/scenarios/dist/targets.js +507 -0
- package/modules/scenarios/dist/targets.js.map +1 -0
- package/modules/scenarios/dist/taylor.d.ts +23 -0
- package/modules/scenarios/dist/taylor.d.ts.map +1 -0
- package/modules/scenarios/dist/taylor.js +209 -0
- package/modules/scenarios/dist/taylor.js.map +1 -0
- package/modules/scenarios/dist/transform.d.ts +31 -0
- package/modules/scenarios/dist/transform.d.ts.map +1 -0
- package/modules/scenarios/dist/transform.js +318 -0
- package/modules/scenarios/dist/transform.js.map +1 -0
- package/modules/scenarios/dist/types.d.ts +591 -0
- package/modules/scenarios/dist/types.d.ts.map +1 -0
- package/modules/scenarios/dist/types.js +2 -0
- package/modules/scenarios/dist/types.js.map +1 -0
- package/modules/scenarios/dist/work.d.ts +85 -0
- package/modules/scenarios/dist/work.d.ts.map +1 -0
- package/modules/scenarios/dist/work.js +629 -0
- package/modules/scenarios/dist/work.js.map +1 -0
- package/modules/scenarios/etc/scenarios.api.md +76 -0
- package/modules/scenarios/src/aggregates.ts +429 -0
- package/modules/scenarios/src/fx.ts +563 -0
- package/modules/scenarios/src/index.ts +5 -0
- package/modules/scenarios/src/internal/behaviors.ts +249 -0
- package/modules/scenarios/src/internal/data.ts +258 -0
- package/modules/scenarios/src/internal/failures.ts +219 -0
- package/modules/scenarios/src/internal/results.ts +131 -0
- package/modules/scenarios/src/market-resolution.ts +436 -0
- package/modules/scenarios/src/portfolio.ts +639 -0
- package/modules/scenarios/src/run.ts +1417 -0
- package/modules/scenarios/src/spot-pricer.ts +129 -0
- package/modules/scenarios/src/targets.ts +729 -0
- package/modules/scenarios/src/taylor.ts +287 -0
- package/modules/scenarios/src/transform.ts +468 -0
- package/modules/scenarios/src/types.ts +713 -0
- package/modules/scenarios/src/work.ts +1055 -0
- package/modules/strategy/dist/auto-range.d.ts +14 -0
- package/modules/strategy/dist/auto-range.d.ts.map +1 -0
- package/modules/strategy/dist/auto-range.js +19 -0
- package/modules/strategy/dist/auto-range.js.map +1 -0
- package/modules/strategy/dist/builders.d.ts +75 -0
- package/modules/strategy/dist/builders.d.ts.map +1 -0
- package/modules/strategy/dist/builders.js +112 -0
- package/modules/strategy/dist/builders.js.map +1 -0
- package/modules/strategy/dist/calendars.d.ts +70 -0
- package/modules/strategy/dist/calendars.d.ts.map +1 -0
- package/modules/strategy/dist/calendars.js +149 -0
- package/modules/strategy/dist/calendars.js.map +1 -0
- package/modules/strategy/dist/classify.d.ts +77 -0
- package/modules/strategy/dist/classify.d.ts.map +1 -0
- package/modules/strategy/dist/classify.js +144 -0
- package/modules/strategy/dist/classify.js.map +1 -0
- package/modules/strategy/dist/explain.d.ts +77 -0
- package/modules/strategy/dist/explain.d.ts.map +1 -0
- package/modules/strategy/dist/explain.js +300 -0
- package/modules/strategy/dist/explain.js.map +1 -0
- package/modules/strategy/dist/from-chain.d.ts +88 -0
- package/modules/strategy/dist/from-chain.d.ts.map +1 -0
- package/modules/strategy/dist/from-chain.js +457 -0
- package/modules/strategy/dist/from-chain.js.map +1 -0
- package/modules/strategy/dist/index.d.ts +102 -0
- package/modules/strategy/dist/index.d.ts.map +1 -0
- package/modules/strategy/dist/index.js +41 -0
- package/modules/strategy/dist/index.js.map +1 -0
- package/modules/strategy/dist/legs.d.ts +47 -0
- package/modules/strategy/dist/legs.d.ts.map +1 -0
- package/modules/strategy/dist/legs.js +87 -0
- package/modules/strategy/dist/legs.js.map +1 -0
- package/modules/strategy/dist/manifest.d.ts +116 -0
- package/modules/strategy/dist/manifest.d.ts.map +1 -0
- package/modules/strategy/dist/manifest.js +376 -0
- package/modules/strategy/dist/manifest.js.map +1 -0
- package/modules/strategy/dist/optimizer.d.ts +184 -0
- package/modules/strategy/dist/optimizer.d.ts.map +1 -0
- package/modules/strategy/dist/optimizer.js +404 -0
- package/modules/strategy/dist/optimizer.js.map +1 -0
- package/modules/strategy/dist/position.d.ts +181 -0
- package/modules/strategy/dist/position.d.ts.map +1 -0
- package/modules/strategy/dist/position.js +1693 -0
- package/modules/strategy/dist/position.js.map +1 -0
- package/modules/strategy/dist/probability.d.ts +192 -0
- package/modules/strategy/dist/probability.d.ts.map +1 -0
- package/modules/strategy/dist/probability.js +106 -0
- package/modules/strategy/dist/probability.js.map +1 -0
- package/modules/strategy/dist/scanner.d.ts +147 -0
- package/modules/strategy/dist/scanner.d.ts.map +1 -0
- package/modules/strategy/dist/scanner.js +438 -0
- package/modules/strategy/dist/scanner.js.map +1 -0
- package/modules/strategy/dist/strategies.d.ts +187 -0
- package/modules/strategy/dist/strategies.d.ts.map +1 -0
- package/modules/strategy/dist/strategies.js +541 -0
- package/modules/strategy/dist/strategies.js.map +1 -0
- package/modules/strategy/dist/svg.d.ts +35 -0
- package/modules/strategy/dist/svg.d.ts.map +1 -0
- package/modules/strategy/dist/svg.js +298 -0
- package/modules/strategy/dist/svg.js.map +1 -0
- package/modules/strategy/dist/thesis-distribution.d.ts +79 -0
- package/modules/strategy/dist/thesis-distribution.d.ts.map +1 -0
- package/modules/strategy/dist/thesis-distribution.js +125 -0
- package/modules/strategy/dist/thesis-distribution.js.map +1 -0
- package/modules/strategy/dist/types.d.ts +370 -0
- package/modules/strategy/dist/types.d.ts.map +1 -0
- package/modules/strategy/dist/types.js +8 -0
- package/modules/strategy/dist/types.js.map +1 -0
- package/modules/strategy/dist/validate.d.ts +63 -0
- package/modules/strategy/dist/validate.d.ts.map +1 -0
- package/modules/strategy/dist/validate.js +146 -0
- package/modules/strategy/dist/validate.js.map +1 -0
- package/modules/strategy/etc/strategy.api.md +174 -0
- package/modules/strategy/src/auto-range.ts +21 -0
- package/modules/strategy/src/builders.ts +221 -0
- package/modules/strategy/src/calendars.ts +245 -0
- package/modules/strategy/src/classify.ts +215 -0
- package/modules/strategy/src/explain.ts +471 -0
- package/modules/strategy/src/from-chain.ts +643 -0
- package/modules/strategy/src/index.ts +212 -0
- package/modules/strategy/src/legs.ts +140 -0
- package/modules/strategy/src/manifest.ts +756 -0
- package/modules/strategy/src/optimizer.ts +679 -0
- package/modules/strategy/src/position.ts +2084 -0
- package/modules/strategy/src/probability.ts +301 -0
- package/modules/strategy/src/scanner.ts +711 -0
- package/modules/strategy/src/strategies.ts +1018 -0
- package/modules/strategy/src/svg.ts +415 -0
- package/modules/strategy/src/thesis-distribution.ts +188 -0
- package/modules/strategy/src/types.ts +380 -0
- package/modules/strategy/src/validate.ts +207 -0
- package/modules/structure/OPTION-FLOW-DRIFT.md +126 -0
- package/modules/structure/dist/exposure.d.ts +350 -0
- package/modules/structure/dist/exposure.d.ts.map +1 -0
- package/modules/structure/dist/exposure.js +917 -0
- package/modules/structure/dist/exposure.js.map +1 -0
- package/modules/structure/dist/flow.d.ts +247 -0
- package/modules/structure/dist/flow.d.ts.map +1 -0
- package/modules/structure/dist/flow.js +643 -0
- package/modules/structure/dist/flow.js.map +1 -0
- package/modules/structure/dist/index.d.ts +20 -0
- package/modules/structure/dist/index.d.ts.map +1 -0
- package/modules/structure/dist/index.js +16 -0
- package/modules/structure/dist/index.js.map +1 -0
- package/modules/structure/dist/market-day.d.ts +29 -0
- package/modules/structure/dist/market-day.d.ts.map +1 -0
- package/modules/structure/dist/market-day.js +43 -0
- package/modules/structure/dist/market-day.js.map +1 -0
- package/modules/structure/dist/option-flow-drift.d.ts +184 -0
- package/modules/structure/dist/option-flow-drift.d.ts.map +1 -0
- package/modules/structure/dist/option-flow-drift.js +475 -0
- package/modules/structure/dist/option-flow-drift.js.map +1 -0
- package/modules/structure/dist/supplied-exposure.d.ts +191 -0
- package/modules/structure/dist/supplied-exposure.d.ts.map +1 -0
- package/modules/structure/dist/supplied-exposure.js +421 -0
- package/modules/structure/dist/supplied-exposure.js.map +1 -0
- package/modules/structure/etc/structure.api.md +72 -0
- package/modules/structure/src/exposure.ts +1330 -0
- package/modules/structure/src/flow.ts +955 -0
- package/modules/structure/src/index.ts +83 -0
- package/modules/structure/src/market-day.ts +47 -0
- package/modules/structure/src/option-flow-drift.ts +726 -0
- package/modules/structure/src/supplied-exposure.ts +671 -0
- package/modules/technical-analysis/dist/aliases.d.ts +42 -0
- package/modules/technical-analysis/dist/aliases.d.ts.map +1 -0
- package/modules/technical-analysis/dist/aliases.js +413 -0
- package/modules/technical-analysis/dist/aliases.js.map +1 -0
- package/modules/technical-analysis/dist/bands.d.ts +31 -0
- package/modules/technical-analysis/dist/bands.d.ts.map +1 -0
- package/modules/technical-analysis/dist/bands.js +79 -0
- package/modules/technical-analysis/dist/bands.js.map +1 -0
- package/modules/technical-analysis/dist/bars.d.ts +113 -0
- package/modules/technical-analysis/dist/bars.d.ts.map +1 -0
- package/modules/technical-analysis/dist/bars.js +374 -0
- package/modules/technical-analysis/dist/bars.js.map +1 -0
- package/modules/technical-analysis/dist/builtin-metadata.d.ts +1817 -0
- package/modules/technical-analysis/dist/builtin-metadata.d.ts.map +1 -0
- package/modules/technical-analysis/dist/builtin-metadata.js +1399 -0
- package/modules/technical-analysis/dist/builtin-metadata.js.map +1 -0
- package/modules/technical-analysis/dist/candle-aliases.d.ts +56 -0
- package/modules/technical-analysis/dist/candle-aliases.d.ts.map +1 -0
- package/modules/technical-analysis/dist/candle-aliases.js +246 -0
- package/modules/technical-analysis/dist/candle-aliases.js.map +1 -0
- package/modules/technical-analysis/dist/candle-talib.d.ts +114 -0
- package/modules/technical-analysis/dist/candle-talib.d.ts.map +1 -0
- package/modules/technical-analysis/dist/candle-talib.js +185 -0
- package/modules/technical-analysis/dist/candle-talib.js.map +1 -0
- package/modules/technical-analysis/dist/candlesticks.d.ts +103 -0
- package/modules/technical-analysis/dist/candlesticks.d.ts.map +1 -0
- package/modules/technical-analysis/dist/candlesticks.js +1009 -0
- package/modules/technical-analysis/dist/candlesticks.js.map +1 -0
- package/modules/technical-analysis/dist/chart-types.d.ts +205 -0
- package/modules/technical-analysis/dist/chart-types.d.ts.map +1 -0
- package/modules/technical-analysis/dist/chart-types.js +633 -0
- package/modules/technical-analysis/dist/chart-types.js.map +1 -0
- package/modules/technical-analysis/dist/columns.d.ts +24 -0
- package/modules/technical-analysis/dist/columns.d.ts.map +1 -0
- package/modules/technical-analysis/dist/columns.js +71 -0
- package/modules/technical-analysis/dist/columns.js.map +1 -0
- package/modules/technical-analysis/dist/cycle.d.ts +174 -0
- package/modules/technical-analysis/dist/cycle.d.ts.map +1 -0
- package/modules/technical-analysis/dist/cycle.js +489 -0
- package/modules/technical-analysis/dist/cycle.js.map +1 -0
- package/modules/technical-analysis/dist/discover.d.ts +100 -0
- package/modules/technical-analysis/dist/discover.d.ts.map +1 -0
- package/modules/technical-analysis/dist/discover.js +273 -0
- package/modules/technical-analysis/dist/discover.js.map +1 -0
- package/modules/technical-analysis/dist/divergence.d.ts +82 -0
- package/modules/technical-analysis/dist/divergence.d.ts.map +1 -0
- package/modules/technical-analysis/dist/divergence.js +269 -0
- package/modules/technical-analysis/dist/divergence.js.map +1 -0
- package/modules/technical-analysis/dist/features-ext.d.ts +162 -0
- package/modules/technical-analysis/dist/features-ext.d.ts.map +1 -0
- package/modules/technical-analysis/dist/features-ext.js +633 -0
- package/modules/technical-analysis/dist/features-ext.js.map +1 -0
- package/modules/technical-analysis/dist/features.d.ts +10 -0
- package/modules/technical-analysis/dist/features.d.ts.map +1 -0
- package/modules/technical-analysis/dist/features.js +10 -0
- package/modules/technical-analysis/dist/features.js.map +1 -0
- package/modules/technical-analysis/dist/framework.d.ts +353 -0
- package/modules/technical-analysis/dist/framework.d.ts.map +1 -0
- package/modules/technical-analysis/dist/framework.js +999 -0
- package/modules/technical-analysis/dist/framework.js.map +1 -0
- package/modules/technical-analysis/dist/fuzzy.d.ts +33 -0
- package/modules/technical-analysis/dist/fuzzy.d.ts.map +1 -0
- package/modules/technical-analysis/dist/fuzzy.js +80 -0
- package/modules/technical-analysis/dist/fuzzy.js.map +1 -0
- package/modules/technical-analysis/dist/generated/validation-specs.d.ts +12 -0
- package/modules/technical-analysis/dist/generated/validation-specs.d.ts.map +1 -0
- package/modules/technical-analysis/dist/generated/validation-specs.js +1052 -0
- package/modules/technical-analysis/dist/generated/validation-specs.js.map +1 -0
- package/modules/technical-analysis/dist/index.d.ts +132 -0
- package/modules/technical-analysis/dist/index.d.ts.map +1 -0
- package/modules/technical-analysis/dist/index.js +100 -0
- package/modules/technical-analysis/dist/index.js.map +1 -0
- package/modules/technical-analysis/dist/indicator-metadata.d.ts +21 -0
- package/modules/technical-analysis/dist/indicator-metadata.d.ts.map +1 -0
- package/modules/technical-analysis/dist/indicator-metadata.js +23 -0
- package/modules/technical-analysis/dist/indicator-metadata.js.map +1 -0
- package/modules/technical-analysis/dist/limits.d.ts +19 -0
- package/modules/technical-analysis/dist/limits.d.ts.map +1 -0
- package/modules/technical-analysis/dist/limits.js +19 -0
- package/modules/technical-analysis/dist/limits.js.map +1 -0
- package/modules/technical-analysis/dist/macd.d.ts +29 -0
- package/modules/technical-analysis/dist/macd.d.ts.map +1 -0
- package/modules/technical-analysis/dist/macd.js +61 -0
- package/modules/technical-analysis/dist/macd.js.map +1 -0
- package/modules/technical-analysis/dist/math.d.ts +69 -0
- package/modules/technical-analysis/dist/math.d.ts.map +1 -0
- package/modules/technical-analysis/dist/math.js +124 -0
- package/modules/technical-analysis/dist/math.js.map +1 -0
- package/modules/technical-analysis/dist/microstructure.d.ts +252 -0
- package/modules/technical-analysis/dist/microstructure.d.ts.map +1 -0
- package/modules/technical-analysis/dist/microstructure.js +552 -0
- package/modules/technical-analysis/dist/microstructure.js.map +1 -0
- package/modules/technical-analysis/dist/momentum-ext.d.ts +619 -0
- package/modules/technical-analysis/dist/momentum-ext.d.ts.map +1 -0
- package/modules/technical-analysis/dist/momentum-ext.js +1772 -0
- package/modules/technical-analysis/dist/momentum-ext.js.map +1 -0
- package/modules/technical-analysis/dist/momentum.d.ts +15 -0
- package/modules/technical-analysis/dist/momentum.d.ts.map +1 -0
- package/modules/technical-analysis/dist/momentum.js +14 -0
- package/modules/technical-analysis/dist/momentum.js.map +1 -0
- package/modules/technical-analysis/dist/moving-averages.d.ts +344 -0
- package/modules/technical-analysis/dist/moving-averages.d.ts.map +1 -0
- package/modules/technical-analysis/dist/moving-averages.js +1279 -0
- package/modules/technical-analysis/dist/moving-averages.js.map +1 -0
- package/modules/technical-analysis/dist/nan-policy.d.ts +42 -0
- package/modules/technical-analysis/dist/nan-policy.d.ts.map +1 -0
- package/modules/technical-analysis/dist/nan-policy.js +60 -0
- package/modules/technical-analysis/dist/nan-policy.js.map +1 -0
- package/modules/technical-analysis/dist/oscillators.d.ts +377 -0
- package/modules/technical-analysis/dist/oscillators.d.ts.map +1 -0
- package/modules/technical-analysis/dist/oscillators.js +1225 -0
- package/modules/technical-analysis/dist/oscillators.js.map +1 -0
- package/modules/technical-analysis/dist/output-meta.d.ts +71 -0
- package/modules/technical-analysis/dist/output-meta.d.ts.map +1 -0
- package/modules/technical-analysis/dist/output-meta.js +399 -0
- package/modules/technical-analysis/dist/output-meta.js.map +1 -0
- package/modules/technical-analysis/dist/overlap-ext.d.ts +206 -0
- package/modules/technical-analysis/dist/overlap-ext.d.ts.map +1 -0
- package/modules/technical-analysis/dist/overlap-ext.js +550 -0
- package/modules/technical-analysis/dist/overlap-ext.js.map +1 -0
- package/modules/technical-analysis/dist/overlap.d.ts +11 -0
- package/modules/technical-analysis/dist/overlap.d.ts.map +1 -0
- package/modules/technical-analysis/dist/overlap.js +10 -0
- package/modules/technical-analysis/dist/overlap.js.map +1 -0
- package/modules/technical-analysis/dist/performance-ext.d.ts +21 -0
- package/modules/technical-analysis/dist/performance-ext.d.ts.map +1 -0
- package/modules/technical-analysis/dist/performance-ext.js +31 -0
- package/modules/technical-analysis/dist/performance-ext.js.map +1 -0
- package/modules/technical-analysis/dist/pipeline.d.ts +105 -0
- package/modules/technical-analysis/dist/pipeline.d.ts.map +1 -0
- package/modules/technical-analysis/dist/pipeline.js +224 -0
- package/modules/technical-analysis/dist/pipeline.js.map +1 -0
- package/modules/technical-analysis/dist/price-action-ext.d.ts +90 -0
- package/modules/technical-analysis/dist/price-action-ext.d.ts.map +1 -0
- package/modules/technical-analysis/dist/price-action-ext.js +511 -0
- package/modules/technical-analysis/dist/price-action-ext.js.map +1 -0
- package/modules/technical-analysis/dist/price-action.d.ts +348 -0
- package/modules/technical-analysis/dist/price-action.d.ts.map +1 -0
- package/modules/technical-analysis/dist/price-action.js +613 -0
- package/modules/technical-analysis/dist/price-action.js.map +1 -0
- package/modules/technical-analysis/dist/registry.d.ts +84 -0
- package/modules/technical-analysis/dist/registry.d.ts.map +1 -0
- package/modules/technical-analysis/dist/registry.js +625 -0
- package/modules/technical-analysis/dist/registry.js.map +1 -0
- package/modules/technical-analysis/dist/resample.d.ts +77 -0
- package/modules/technical-analysis/dist/resample.d.ts.map +1 -0
- package/modules/technical-analysis/dist/resample.js +239 -0
- package/modules/technical-analysis/dist/resample.js.map +1 -0
- package/modules/technical-analysis/dist/rsi.d.ts +36 -0
- package/modules/technical-analysis/dist/rsi.d.ts.map +1 -0
- package/modules/technical-analysis/dist/rsi.js +95 -0
- package/modules/technical-analysis/dist/rsi.js.map +1 -0
- package/modules/technical-analysis/dist/series.d.ts +40 -0
- package/modules/technical-analysis/dist/series.d.ts.map +1 -0
- package/modules/technical-analysis/dist/series.js +125 -0
- package/modules/technical-analysis/dist/series.js.map +1 -0
- package/modules/technical-analysis/dist/signal.d.ts +140 -0
- package/modules/technical-analysis/dist/signal.d.ts.map +1 -0
- package/modules/technical-analysis/dist/signal.js +353 -0
- package/modules/technical-analysis/dist/signal.js.map +1 -0
- package/modules/technical-analysis/dist/snapshot-cardinality.d.ts +17 -0
- package/modules/technical-analysis/dist/snapshot-cardinality.d.ts.map +1 -0
- package/modules/technical-analysis/dist/snapshot-cardinality.js +53 -0
- package/modules/technical-analysis/dist/snapshot-cardinality.js.map +1 -0
- package/modules/technical-analysis/dist/snapshot-envelope.d.ts +19 -0
- package/modules/technical-analysis/dist/snapshot-envelope.d.ts.map +1 -0
- package/modules/technical-analysis/dist/snapshot-envelope.js +87 -0
- package/modules/technical-analysis/dist/snapshot-envelope.js.map +1 -0
- package/modules/technical-analysis/dist/statistics.d.ts +146 -0
- package/modules/technical-analysis/dist/statistics.d.ts.map +1 -0
- package/modules/technical-analysis/dist/statistics.js +524 -0
- package/modules/technical-analysis/dist/statistics.js.map +1 -0
- package/modules/technical-analysis/dist/stream-validation.d.ts +14 -0
- package/modules/technical-analysis/dist/stream-validation.d.ts.map +1 -0
- package/modules/technical-analysis/dist/stream-validation.js +35 -0
- package/modules/technical-analysis/dist/stream-validation.js.map +1 -0
- package/modules/technical-analysis/dist/transforms.d.ts +77 -0
- package/modules/technical-analysis/dist/transforms.d.ts.map +1 -0
- package/modules/technical-analysis/dist/transforms.js +246 -0
- package/modules/technical-analysis/dist/transforms.js.map +1 -0
- package/modules/technical-analysis/dist/trend-ext.d.ts +121 -0
- package/modules/technical-analysis/dist/trend-ext.d.ts.map +1 -0
- package/modules/technical-analysis/dist/trend-ext.js +691 -0
- package/modules/technical-analysis/dist/trend-ext.js.map +1 -0
- package/modules/technical-analysis/dist/trend.d.ts +373 -0
- package/modules/technical-analysis/dist/trend.d.ts.map +1 -0
- package/modules/technical-analysis/dist/trend.js +1159 -0
- package/modules/technical-analysis/dist/trend.js.map +1 -0
- package/modules/technical-analysis/dist/validate.d.ts +61 -0
- package/modules/technical-analysis/dist/validate.d.ts.map +1 -0
- package/modules/technical-analysis/dist/validate.js +334 -0
- package/modules/technical-analysis/dist/validate.js.map +1 -0
- package/modules/technical-analysis/dist/volatility-ext.d.ts +98 -0
- package/modules/technical-analysis/dist/volatility-ext.d.ts.map +1 -0
- package/modules/technical-analysis/dist/volatility-ext.js +535 -0
- package/modules/technical-analysis/dist/volatility-ext.js.map +1 -0
- package/modules/technical-analysis/dist/volatility.d.ts +239 -0
- package/modules/technical-analysis/dist/volatility.d.ts.map +1 -0
- package/modules/technical-analysis/dist/volatility.js +709 -0
- package/modules/technical-analysis/dist/volatility.js.map +1 -0
- package/modules/technical-analysis/dist/volume-core.d.ts +273 -0
- package/modules/technical-analysis/dist/volume-core.d.ts.map +1 -0
- package/modules/technical-analysis/dist/volume-core.js +847 -0
- package/modules/technical-analysis/dist/volume-core.js.map +1 -0
- package/modules/technical-analysis/dist/volume-ext.d.ts +61 -0
- package/modules/technical-analysis/dist/volume-ext.d.ts.map +1 -0
- package/modules/technical-analysis/dist/volume-ext.js +270 -0
- package/modules/technical-analysis/dist/volume-ext.js.map +1 -0
- package/modules/technical-analysis/dist/volume.d.ts +15 -0
- package/modules/technical-analysis/dist/volume.d.ts.map +1 -0
- package/modules/technical-analysis/dist/volume.js +15 -0
- package/modules/technical-analysis/dist/volume.js.map +1 -0
- package/modules/technical-analysis/dist/warmup.d.ts +38 -0
- package/modules/technical-analysis/dist/warmup.d.ts.map +1 -0
- package/modules/technical-analysis/dist/warmup.js +269 -0
- package/modules/technical-analysis/dist/warmup.js.map +1 -0
- package/modules/technical-analysis/etc/technical-analysis.api.md +663 -0
- package/modules/technical-analysis/src/aliases.ts +466 -0
- package/modules/technical-analysis/src/bands.ts +113 -0
- package/modules/technical-analysis/src/bars.ts +456 -0
- package/modules/technical-analysis/src/builtin-metadata.ts +1686 -0
- package/modules/technical-analysis/src/candle-aliases.ts +289 -0
- package/modules/technical-analysis/src/candle-talib.ts +215 -0
- package/modules/technical-analysis/src/candlesticks.ts +1024 -0
- package/modules/technical-analysis/src/chart-types.ts +813 -0
- package/modules/technical-analysis/src/columns.ts +87 -0
- package/modules/technical-analysis/src/cycle.ts +625 -0
- package/modules/technical-analysis/src/discover.ts +390 -0
- package/modules/technical-analysis/src/divergence.ts +388 -0
- package/modules/technical-analysis/src/features-ext.ts +866 -0
- package/modules/technical-analysis/src/features.ts +9 -0
- package/modules/technical-analysis/src/framework.ts +1331 -0
- package/modules/technical-analysis/src/fuzzy.ts +92 -0
- package/modules/technical-analysis/src/generated/validation-specs.ts +1055 -0
- package/modules/technical-analysis/src/index.ts +825 -0
- package/modules/technical-analysis/src/indicator-metadata.ts +43 -0
- package/modules/technical-analysis/src/limits.ts +19 -0
- package/modules/technical-analysis/src/macd.ts +95 -0
- package/modules/technical-analysis/src/math.ts +181 -0
- package/modules/technical-analysis/src/microstructure.ts +870 -0
- package/modules/technical-analysis/src/momentum-ext.ts +2348 -0
- package/modules/technical-analysis/src/momentum.ts +16 -0
- package/modules/technical-analysis/src/moving-averages.ts +1525 -0
- package/modules/technical-analysis/src/nan-policy.ts +58 -0
- package/modules/technical-analysis/src/oscillators.ts +1586 -0
- package/modules/technical-analysis/src/output-meta.ts +466 -0
- package/modules/technical-analysis/src/overlap-ext.ts +792 -0
- package/modules/technical-analysis/src/overlap.ts +12 -0
- package/modules/technical-analysis/src/performance-ext.ts +57 -0
- package/modules/technical-analysis/src/pipeline.ts +270 -0
- package/modules/technical-analysis/src/price-action-ext.ts +675 -0
- package/modules/technical-analysis/src/price-action.ts +955 -0
- package/modules/technical-analysis/src/registry.ts +784 -0
- package/modules/technical-analysis/src/resample.ts +335 -0
- package/modules/technical-analysis/src/rsi.ts +120 -0
- package/modules/technical-analysis/src/series.ts +168 -0
- package/modules/technical-analysis/src/signal.ts +429 -0
- package/modules/technical-analysis/src/snapshot-cardinality.ts +83 -0
- package/modules/technical-analysis/src/snapshot-envelope.ts +131 -0
- package/modules/technical-analysis/src/statistics.ts +720 -0
- package/modules/technical-analysis/src/stream-validation.ts +42 -0
- package/modules/technical-analysis/src/transforms.ts +351 -0
- package/modules/technical-analysis/src/trend-ext.ts +957 -0
- package/modules/technical-analysis/src/trend.ts +1529 -0
- package/modules/technical-analysis/src/validate.ts +555 -0
- package/modules/technical-analysis/src/volatility-ext.ts +781 -0
- package/modules/technical-analysis/src/volatility.ts +963 -0
- package/modules/technical-analysis/src/volume-core.ts +1106 -0
- package/modules/technical-analysis/src/volume-ext.ts +380 -0
- package/modules/technical-analysis/src/volume.ts +14 -0
- package/modules/technical-analysis/src/warmup.ts +322 -0
- package/modules/totalfinance/dist/backtest.d.ts +3 -0
- package/modules/totalfinance/dist/backtest.d.ts.map +1 -0
- package/modules/totalfinance/dist/backtest.js +3 -0
- package/modules/totalfinance/dist/backtest.js.map +1 -0
- package/modules/totalfinance/dist/calendars.d.ts +3 -0
- package/modules/totalfinance/dist/calendars.d.ts.map +1 -0
- package/modules/totalfinance/dist/calendars.js +3 -0
- package/modules/totalfinance/dist/calendars.js.map +1 -0
- package/modules/totalfinance/dist/commodities.d.ts +2 -0
- package/modules/totalfinance/dist/commodities.d.ts.map +1 -0
- package/modules/totalfinance/dist/commodities.js +2 -0
- package/modules/totalfinance/dist/commodities.js.map +1 -0
- package/modules/totalfinance/dist/core.d.ts +3 -0
- package/modules/totalfinance/dist/core.d.ts.map +1 -0
- package/modules/totalfinance/dist/core.js +3 -0
- package/modules/totalfinance/dist/core.js.map +1 -0
- package/modules/totalfinance/dist/crypto.d.ts +3 -0
- package/modules/totalfinance/dist/crypto.d.ts.map +1 -0
- package/modules/totalfinance/dist/crypto.js +3 -0
- package/modules/totalfinance/dist/crypto.js.map +1 -0
- package/modules/totalfinance/dist/fixed-income.d.ts +3 -0
- package/modules/totalfinance/dist/fixed-income.d.ts.map +1 -0
- package/modules/totalfinance/dist/fixed-income.js +3 -0
- package/modules/totalfinance/dist/fixed-income.js.map +1 -0
- package/modules/totalfinance/dist/foreign-exchange.d.ts +2 -0
- package/modules/totalfinance/dist/foreign-exchange.d.ts.map +1 -0
- package/modules/totalfinance/dist/foreign-exchange.js +2 -0
- package/modules/totalfinance/dist/foreign-exchange.js.map +1 -0
- package/modules/totalfinance/dist/fundamentals.d.ts +3 -0
- package/modules/totalfinance/dist/fundamentals.d.ts.map +1 -0
- package/modules/totalfinance/dist/fundamentals.js +3 -0
- package/modules/totalfinance/dist/fundamentals.js.map +1 -0
- package/modules/totalfinance/dist/index.d.ts +90 -0
- package/modules/totalfinance/dist/index.d.ts.map +1 -0
- package/modules/totalfinance/dist/index.js +68 -0
- package/modules/totalfinance/dist/index.js.map +1 -0
- package/modules/totalfinance/dist/math.d.ts +3 -0
- package/modules/totalfinance/dist/math.d.ts.map +1 -0
- package/modules/totalfinance/dist/math.js +3 -0
- package/modules/totalfinance/dist/math.js.map +1 -0
- package/modules/totalfinance/dist/options.d.ts +3 -0
- package/modules/totalfinance/dist/options.d.ts.map +1 -0
- package/modules/totalfinance/dist/options.js +3 -0
- package/modules/totalfinance/dist/options.js.map +1 -0
- package/modules/totalfinance/dist/performance.d.ts +3 -0
- package/modules/totalfinance/dist/performance.d.ts.map +1 -0
- package/modules/totalfinance/dist/performance.js +3 -0
- package/modules/totalfinance/dist/performance.js.map +1 -0
- package/modules/totalfinance/dist/portfolio.d.ts +2 -0
- package/modules/totalfinance/dist/portfolio.d.ts.map +1 -0
- package/modules/totalfinance/dist/portfolio.js +2 -0
- package/modules/totalfinance/dist/portfolio.js.map +1 -0
- package/modules/totalfinance/dist/research.d.ts +2 -0
- package/modules/totalfinance/dist/research.d.ts.map +1 -0
- package/modules/totalfinance/dist/research.js +2 -0
- package/modules/totalfinance/dist/research.js.map +1 -0
- package/modules/totalfinance/dist/risk.d.ts +3 -0
- package/modules/totalfinance/dist/risk.d.ts.map +1 -0
- package/modules/totalfinance/dist/risk.js +3 -0
- package/modules/totalfinance/dist/risk.js.map +1 -0
- package/modules/totalfinance/dist/scenarios.d.ts +2 -0
- package/modules/totalfinance/dist/scenarios.d.ts.map +1 -0
- package/modules/totalfinance/dist/scenarios.js +2 -0
- package/modules/totalfinance/dist/scenarios.js.map +1 -0
- package/modules/totalfinance/dist/strategy.d.ts +3 -0
- package/modules/totalfinance/dist/strategy.d.ts.map +1 -0
- package/modules/totalfinance/dist/strategy.js +3 -0
- package/modules/totalfinance/dist/strategy.js.map +1 -0
- package/modules/totalfinance/dist/structure.d.ts +3 -0
- package/modules/totalfinance/dist/structure.d.ts.map +1 -0
- package/modules/totalfinance/dist/structure.js +3 -0
- package/modules/totalfinance/dist/structure.js.map +1 -0
- package/modules/totalfinance/dist/technical-analysis.d.ts +3 -0
- package/modules/totalfinance/dist/technical-analysis.d.ts.map +1 -0
- package/modules/totalfinance/dist/technical-analysis.js +3 -0
- package/modules/totalfinance/dist/technical-analysis.js.map +1 -0
- package/modules/totalfinance/dist/valuation.d.ts +3 -0
- package/modules/totalfinance/dist/valuation.d.ts.map +1 -0
- package/modules/totalfinance/dist/valuation.js +3 -0
- package/modules/totalfinance/dist/valuation.js.map +1 -0
- package/modules/totalfinance/dist/volatility.d.ts +3 -0
- package/modules/totalfinance/dist/volatility.d.ts.map +1 -0
- package/modules/totalfinance/dist/volatility.js +3 -0
- package/modules/totalfinance/dist/volatility.js.map +1 -0
- package/modules/totalfinance/etc/totalfinance.api.md +73 -0
- package/modules/totalfinance/src/backtest.ts +2 -0
- package/modules/totalfinance/src/calendars.ts +2 -0
- package/modules/totalfinance/src/commodities.ts +1 -0
- package/modules/totalfinance/src/core.ts +2 -0
- package/modules/totalfinance/src/crypto.ts +2 -0
- package/modules/totalfinance/src/fixed-income.ts +2 -0
- package/modules/totalfinance/src/foreign-exchange.ts +1 -0
- package/modules/totalfinance/src/fundamentals.ts +2 -0
- package/modules/totalfinance/src/index.ts +129 -0
- package/modules/totalfinance/src/math.ts +2 -0
- package/modules/totalfinance/src/options.ts +2 -0
- package/modules/totalfinance/src/performance.ts +2 -0
- package/modules/totalfinance/src/portfolio.ts +1 -0
- package/modules/totalfinance/src/research.ts +1 -0
- package/modules/totalfinance/src/risk.ts +2 -0
- package/modules/totalfinance/src/scenarios.ts +1 -0
- package/modules/totalfinance/src/strategy.ts +2 -0
- package/modules/totalfinance/src/structure.ts +2 -0
- package/modules/totalfinance/src/technical-analysis.ts +2 -0
- package/modules/totalfinance/src/valuation.ts +2 -0
- package/modules/totalfinance/src/volatility.ts +2 -0
- package/modules/valuation/dist/adjusted-present-value.d.ts +62 -0
- package/modules/valuation/dist/adjusted-present-value.d.ts.map +1 -0
- package/modules/valuation/dist/adjusted-present-value.js +85 -0
- package/modules/valuation/dist/adjusted-present-value.js.map +1 -0
- package/modules/valuation/dist/capital-budgeting.d.ts +84 -0
- package/modules/valuation/dist/capital-budgeting.d.ts.map +1 -0
- package/modules/valuation/dist/capital-budgeting.js +204 -0
- package/modules/valuation/dist/capital-budgeting.js.map +1 -0
- package/modules/valuation/dist/cash-flows.d.ts +11 -0
- package/modules/valuation/dist/cash-flows.d.ts.map +1 -0
- package/modules/valuation/dist/cash-flows.js +10 -0
- package/modules/valuation/dist/cash-flows.js.map +1 -0
- package/modules/valuation/dist/comparable.d.ts +101 -0
- package/modules/valuation/dist/comparable.d.ts.map +1 -0
- package/modules/valuation/dist/comparable.js +194 -0
- package/modules/valuation/dist/comparable.js.map +1 -0
- package/modules/valuation/dist/corporate-primitives.d.ts +185 -0
- package/modules/valuation/dist/corporate-primitives.d.ts.map +1 -0
- package/modules/valuation/dist/corporate-primitives.js +337 -0
- package/modules/valuation/dist/corporate-primitives.js.map +1 -0
- package/modules/valuation/dist/corporate.d.ts +14 -0
- package/modules/valuation/dist/corporate.d.ts.map +1 -0
- package/modules/valuation/dist/corporate.js +13 -0
- package/modules/valuation/dist/corporate.js.map +1 -0
- package/modules/valuation/dist/discounted-cash-flow.d.ts +269 -0
- package/modules/valuation/dist/discounted-cash-flow.d.ts.map +1 -0
- package/modules/valuation/dist/discounted-cash-flow.js +611 -0
- package/modules/valuation/dist/discounted-cash-flow.js.map +1 -0
- package/modules/valuation/dist/discounting.d.ts +124 -0
- package/modules/valuation/dist/discounting.d.ts.map +1 -0
- package/modules/valuation/dist/discounting.js +235 -0
- package/modules/valuation/dist/discounting.js.map +1 -0
- package/modules/valuation/dist/equity-valuation.d.ts +104 -0
- package/modules/valuation/dist/equity-valuation.d.ts.map +1 -0
- package/modules/valuation/dist/equity-valuation.js +164 -0
- package/modules/valuation/dist/equity-valuation.js.map +1 -0
- package/modules/valuation/dist/flows.d.ts +30 -0
- package/modules/valuation/dist/flows.d.ts.map +1 -0
- package/modules/valuation/dist/flows.js +77 -0
- package/modules/valuation/dist/flows.js.map +1 -0
- package/modules/valuation/dist/forecasting.d.ts +205 -0
- package/modules/valuation/dist/forecasting.d.ts.map +1 -0
- package/modules/valuation/dist/forecasting.js +359 -0
- package/modules/valuation/dist/forecasting.js.map +1 -0
- package/modules/valuation/dist/index.d.ts +9 -0
- package/modules/valuation/dist/index.d.ts.map +1 -0
- package/modules/valuation/dist/index.js +10 -0
- package/modules/valuation/dist/index.js.map +1 -0
- package/modules/valuation/dist/leveraged-buyout.d.ts +160 -0
- package/modules/valuation/dist/leveraged-buyout.d.ts.map +1 -0
- package/modules/valuation/dist/leveraged-buyout.js +326 -0
- package/modules/valuation/dist/leveraged-buyout.js.map +1 -0
- package/modules/valuation/dist/loans.d.ts +148 -0
- package/modules/valuation/dist/loans.d.ts.map +1 -0
- package/modules/valuation/dist/loans.js +518 -0
- package/modules/valuation/dist/loans.js.map +1 -0
- package/modules/valuation/dist/probabilistic.d.ts +88 -0
- package/modules/valuation/dist/probabilistic.d.ts.map +1 -0
- package/modules/valuation/dist/probabilistic.js +239 -0
- package/modules/valuation/dist/probabilistic.js.map +1 -0
- package/modules/valuation/dist/solvers.d.ts +90 -0
- package/modules/valuation/dist/solvers.d.ts.map +1 -0
- package/modules/valuation/dist/solvers.js +238 -0
- package/modules/valuation/dist/solvers.js.map +1 -0
- package/modules/valuation/etc/valuation.api.md +162 -0
- package/modules/valuation/src/adjusted-present-value.ts +181 -0
- package/modules/valuation/src/capital-budgeting.ts +329 -0
- package/modules/valuation/src/cash-flows.ts +11 -0
- package/modules/valuation/src/comparable.ts +340 -0
- package/modules/valuation/src/corporate-primitives.ts +665 -0
- package/modules/valuation/src/corporate.ts +36 -0
- package/modules/valuation/src/discounted-cash-flow.ts +1083 -0
- package/modules/valuation/src/discounting.ts +437 -0
- package/modules/valuation/src/equity-valuation.ts +313 -0
- package/modules/valuation/src/flows.ts +144 -0
- package/modules/valuation/src/forecasting.ts +666 -0
- package/modules/valuation/src/index.ts +10 -0
- package/modules/valuation/src/leveraged-buyout.ts +560 -0
- package/modules/valuation/src/loans.ts +778 -0
- package/modules/valuation/src/probabilistic.ts +438 -0
- package/modules/valuation/src/solvers.ts +397 -0
- package/modules/volatility/dist/analytics.d.ts +133 -0
- package/modules/volatility/dist/analytics.d.ts.map +1 -0
- package/modules/volatility/dist/analytics.js +320 -0
- package/modules/volatility/dist/analytics.js.map +1 -0
- package/modules/volatility/dist/arbitrage.d.ts +118 -0
- package/modules/volatility/dist/arbitrage.d.ts.map +1 -0
- package/modules/volatility/dist/arbitrage.js +397 -0
- package/modules/volatility/dist/arbitrage.js.map +1 -0
- package/modules/volatility/dist/artifacts.d.ts +24 -0
- package/modules/volatility/dist/artifacts.d.ts.map +1 -0
- package/modules/volatility/dist/artifacts.js +22 -0
- package/modules/volatility/dist/artifacts.js.map +1 -0
- package/modules/volatility/dist/calibration-limits.d.ts +13 -0
- package/modules/volatility/dist/calibration-limits.d.ts.map +1 -0
- package/modules/volatility/dist/calibration-limits.js +46 -0
- package/modules/volatility/dist/calibration-limits.js.map +1 -0
- package/modules/volatility/dist/calibration-start.d.ts +13 -0
- package/modules/volatility/dist/calibration-start.d.ts.map +1 -0
- package/modules/volatility/dist/calibration-start.js +55 -0
- package/modules/volatility/dist/calibration-start.js.map +1 -0
- package/modules/volatility/dist/earnings.d.ts +152 -0
- package/modules/volatility/dist/earnings.d.ts.map +1 -0
- package/modules/volatility/dist/earnings.js +340 -0
- package/modules/volatility/dist/earnings.js.map +1 -0
- package/modules/volatility/dist/essvi.d.ts +115 -0
- package/modules/volatility/dist/essvi.d.ts.map +1 -0
- package/modules/volatility/dist/essvi.js +362 -0
- package/modules/volatility/dist/essvi.js.map +1 -0
- package/modules/volatility/dist/estimate.d.ts +14 -0
- package/modules/volatility/dist/estimate.d.ts.map +1 -0
- package/modules/volatility/dist/estimate.js +18 -0
- package/modules/volatility/dist/estimate.js.map +1 -0
- package/modules/volatility/dist/event.d.ts +155 -0
- package/modules/volatility/dist/event.d.ts.map +1 -0
- package/modules/volatility/dist/event.js +319 -0
- package/modules/volatility/dist/event.js.map +1 -0
- package/modules/volatility/dist/fitted-model-artifacts.d.ts +378 -0
- package/modules/volatility/dist/fitted-model-artifacts.d.ts.map +1 -0
- package/modules/volatility/dist/fitted-model-artifacts.js +1139 -0
- package/modules/volatility/dist/fitted-model-artifacts.js.map +1 -0
- package/modules/volatility/dist/fitted-model-families.d.ts +287 -0
- package/modules/volatility/dist/fitted-model-families.d.ts.map +1 -0
- package/modules/volatility/dist/fitted-model-families.js +1251 -0
- package/modules/volatility/dist/fitted-model-families.js.map +1 -0
- package/modules/volatility/dist/forecast.d.ts +195 -0
- package/modules/volatility/dist/forecast.d.ts.map +1 -0
- package/modules/volatility/dist/forecast.js +493 -0
- package/modules/volatility/dist/forecast.js.map +1 -0
- package/modules/volatility/dist/generated/validation-specs.d.ts +12 -0
- package/modules/volatility/dist/generated/validation-specs.d.ts.map +1 -0
- package/modules/volatility/dist/generated/validation-specs.js +2181 -0
- package/modules/volatility/dist/generated/validation-specs.js.map +1 -0
- package/modules/volatility/dist/heston-surface.d.ts +67 -0
- package/modules/volatility/dist/heston-surface.d.ts.map +1 -0
- package/modules/volatility/dist/heston-surface.js +135 -0
- package/modules/volatility/dist/heston-surface.js.map +1 -0
- package/modules/volatility/dist/index.d.ts +64 -0
- package/modules/volatility/dist/index.d.ts.map +1 -0
- package/modules/volatility/dist/index.js +68 -0
- package/modules/volatility/dist/index.js.map +1 -0
- package/modules/volatility/dist/local-volatility.d.ts +34 -0
- package/modules/volatility/dist/local-volatility.d.ts.map +1 -0
- package/modules/volatility/dist/local-volatility.js +59 -0
- package/modules/volatility/dist/local-volatility.js.map +1 -0
- package/modules/volatility/dist/metrics.d.ts +41 -0
- package/modules/volatility/dist/metrics.d.ts.map +1 -0
- package/modules/volatility/dist/metrics.js +117 -0
- package/modules/volatility/dist/metrics.js.map +1 -0
- package/modules/volatility/dist/min-variance-delta.d.ts +61 -0
- package/modules/volatility/dist/min-variance-delta.d.ts.map +1 -0
- package/modules/volatility/dist/min-variance-delta.js +101 -0
- package/modules/volatility/dist/min-variance-delta.js.map +1 -0
- package/modules/volatility/dist/observed-skew.d.ts +137 -0
- package/modules/volatility/dist/observed-skew.d.ts.map +1 -0
- package/modules/volatility/dist/observed-skew.js +461 -0
- package/modules/volatility/dist/observed-skew.js.map +1 -0
- package/modules/volatility/dist/otm-strip.d.ts +39 -0
- package/modules/volatility/dist/otm-strip.d.ts.map +1 -0
- package/modules/volatility/dist/otm-strip.js +181 -0
- package/modules/volatility/dist/otm-strip.js.map +1 -0
- package/modules/volatility/dist/risk-reversal.d.ts +89 -0
- package/modules/volatility/dist/risk-reversal.d.ts.map +1 -0
- package/modules/volatility/dist/risk-reversal.js +176 -0
- package/modules/volatility/dist/risk-reversal.js.map +1 -0
- package/modules/volatility/dist/sabr-delta.d.ts +67 -0
- package/modules/volatility/dist/sabr-delta.d.ts.map +1 -0
- package/modules/volatility/dist/sabr-delta.js +153 -0
- package/modules/volatility/dist/sabr-delta.js.map +1 -0
- package/modules/volatility/dist/sabr.d.ts +62 -0
- package/modules/volatility/dist/sabr.d.ts.map +1 -0
- package/modules/volatility/dist/sabr.js +262 -0
- package/modules/volatility/dist/sabr.js.map +1 -0
- package/modules/volatility/dist/skew.d.ts +63 -0
- package/modules/volatility/dist/skew.d.ts.map +1 -0
- package/modules/volatility/dist/skew.js +147 -0
- package/modules/volatility/dist/skew.js.map +1 -0
- package/modules/volatility/dist/ssvi-kernel.d.ts +90 -0
- package/modules/volatility/dist/ssvi-kernel.d.ts.map +1 -0
- package/modules/volatility/dist/ssvi-kernel.js +103 -0
- package/modules/volatility/dist/ssvi-kernel.js.map +1 -0
- package/modules/volatility/dist/ssvi.d.ts +181 -0
- package/modules/volatility/dist/ssvi.d.ts.map +1 -0
- package/modules/volatility/dist/ssvi.js +490 -0
- package/modules/volatility/dist/ssvi.js.map +1 -0
- package/modules/volatility/dist/sticky-regime.d.ts +47 -0
- package/modules/volatility/dist/sticky-regime.d.ts.map +1 -0
- package/modules/volatility/dist/sticky-regime.js +81 -0
- package/modules/volatility/dist/sticky-regime.js.map +1 -0
- package/modules/volatility/dist/surface-pca.d.ts +111 -0
- package/modules/volatility/dist/surface-pca.d.ts.map +1 -0
- package/modules/volatility/dist/surface-pca.js +297 -0
- package/modules/volatility/dist/surface-pca.js.map +1 -0
- package/modules/volatility/dist/surface.d.ts +286 -0
- package/modules/volatility/dist/surface.d.ts.map +1 -0
- package/modules/volatility/dist/surface.js +1105 -0
- package/modules/volatility/dist/surface.js.map +1 -0
- package/modules/volatility/dist/svi.d.ts +133 -0
- package/modules/volatility/dist/svi.d.ts.map +1 -0
- package/modules/volatility/dist/svi.js +491 -0
- package/modules/volatility/dist/svi.js.map +1 -0
- package/modules/volatility/dist/swaption-cube.d.ts +125 -0
- package/modules/volatility/dist/swaption-cube.d.ts.map +1 -0
- package/modules/volatility/dist/swaption-cube.js +334 -0
- package/modules/volatility/dist/swaption-cube.js.map +1 -0
- package/modules/volatility/dist/tail-risk.d.ts +65 -0
- package/modules/volatility/dist/tail-risk.d.ts.map +1 -0
- package/modules/volatility/dist/tail-risk.js +155 -0
- package/modules/volatility/dist/tail-risk.js.map +1 -0
- package/modules/volatility/dist/term.d.ts +121 -0
- package/modules/volatility/dist/term.d.ts.map +1 -0
- package/modules/volatility/dist/term.js +336 -0
- package/modules/volatility/dist/term.js.map +1 -0
- package/modules/volatility/dist/vanna-volga.d.ts +278 -0
- package/modules/volatility/dist/vanna-volga.d.ts.map +1 -0
- package/modules/volatility/dist/vanna-volga.js +833 -0
- package/modules/volatility/dist/vanna-volga.js.map +1 -0
- package/modules/volatility/dist/variance-index.d.ts +101 -0
- package/modules/volatility/dist/variance-index.d.ts.map +1 -0
- package/modules/volatility/dist/variance-index.js +240 -0
- package/modules/volatility/dist/variance-index.js.map +1 -0
- package/modules/volatility/dist/volatility-spot-beta.d.ts +57 -0
- package/modules/volatility/dist/volatility-spot-beta.d.ts.map +1 -0
- package/modules/volatility/dist/volatility-spot-beta.js +136 -0
- package/modules/volatility/dist/volatility-spot-beta.js.map +1 -0
- package/modules/volatility/etc/volatility.api.md +207 -0
- package/modules/volatility/src/analytics.ts +513 -0
- package/modules/volatility/src/arbitrage.ts +561 -0
- package/modules/volatility/src/artifacts.ts +62 -0
- package/modules/volatility/src/calibration-limits.ts +61 -0
- package/modules/volatility/src/calibration-start.ts +79 -0
- package/modules/volatility/src/earnings.ts +548 -0
- package/modules/volatility/src/essvi.ts +528 -0
- package/modules/volatility/src/estimate.ts +21 -0
- package/modules/volatility/src/event.ts +542 -0
- package/modules/volatility/src/fitted-model-artifacts.ts +1844 -0
- package/modules/volatility/src/fitted-model-families.ts +1681 -0
- package/modules/volatility/src/forecast.ts +757 -0
- package/modules/volatility/src/generated/validation-specs.ts +2184 -0
- package/modules/volatility/src/heston-surface.ts +215 -0
- package/modules/volatility/src/index.ts +285 -0
- package/modules/volatility/src/local-volatility.ts +104 -0
- package/modules/volatility/src/metrics.ts +176 -0
- package/modules/volatility/src/min-variance-delta.ts +167 -0
- package/modules/volatility/src/observed-skew.ts +684 -0
- package/modules/volatility/src/otm-strip.ts +234 -0
- package/modules/volatility/src/risk-reversal.ts +316 -0
- package/modules/volatility/src/sabr-delta.ts +238 -0
- package/modules/volatility/src/sabr.ts +375 -0
- package/modules/volatility/src/skew.ts +244 -0
- package/modules/volatility/src/ssvi-kernel.ts +134 -0
- package/modules/volatility/src/ssvi.ts +707 -0
- package/modules/volatility/src/sticky-regime.ts +150 -0
- package/modules/volatility/src/surface-pca.ts +439 -0
- package/modules/volatility/src/surface.ts +1499 -0
- package/modules/volatility/src/svi.ts +687 -0
- package/modules/volatility/src/swaption-cube.ts +539 -0
- package/modules/volatility/src/tail-risk.ts +254 -0
- package/modules/volatility/src/term.ts +587 -0
- package/modules/volatility/src/vanna-volga.ts +1337 -0
- package/modules/volatility/src/variance-index.ts +396 -0
- package/modules/volatility/src/volatility-spot-beta.ts +252 -0
- package/modules/workflows/dist/capabilities.d.ts +8 -0
- package/modules/workflows/dist/capabilities.d.ts.map +1 -0
- package/modules/workflows/dist/capabilities.js +50 -0
- package/modules/workflows/dist/capabilities.js.map +1 -0
- package/modules/workflows/dist/envelope-schema.d.ts +36 -0
- package/modules/workflows/dist/envelope-schema.d.ts.map +1 -0
- package/modules/workflows/dist/envelope-schema.js +152 -0
- package/modules/workflows/dist/envelope-schema.js.map +1 -0
- package/modules/workflows/dist/index.d.ts +33 -0
- package/modules/workflows/dist/index.d.ts.map +1 -0
- package/modules/workflows/dist/index.js +27 -0
- package/modules/workflows/dist/index.js.map +1 -0
- package/modules/workflows/dist/json-safe.d.ts +7 -0
- package/modules/workflows/dist/json-safe.d.ts.map +1 -0
- package/modules/workflows/dist/json-safe.js +23 -0
- package/modules/workflows/dist/json-safe.js.map +1 -0
- package/modules/workflows/dist/local/file-lock.d.ts +23 -0
- package/modules/workflows/dist/local/file-lock.d.ts.map +1 -0
- package/modules/workflows/dist/local/file-lock.js +198 -0
- package/modules/workflows/dist/local/file-lock.js.map +1 -0
- package/modules/workflows/dist/local/file-stores.d.ts +33 -0
- package/modules/workflows/dist/local/file-stores.d.ts.map +1 -0
- package/modules/workflows/dist/local/file-stores.js +376 -0
- package/modules/workflows/dist/local/file-stores.js.map +1 -0
- package/modules/workflows/dist/local/index.d.ts +15 -0
- package/modules/workflows/dist/local/index.d.ts.map +1 -0
- package/modules/workflows/dist/local/index.js +12 -0
- package/modules/workflows/dist/local/index.js.map +1 -0
- package/modules/workflows/dist/local/job-worker.d.ts +28 -0
- package/modules/workflows/dist/local/job-worker.d.ts.map +1 -0
- package/modules/workflows/dist/local/job-worker.js +56 -0
- package/modules/workflows/dist/local/job-worker.js.map +1 -0
- package/modules/workflows/dist/local/jobs.d.ts +51 -0
- package/modules/workflows/dist/local/jobs.d.ts.map +1 -0
- package/modules/workflows/dist/local/jobs.js +313 -0
- package/modules/workflows/dist/local/jobs.js.map +1 -0
- package/modules/workflows/dist/local/local-runner.d.ts +39 -0
- package/modules/workflows/dist/local/local-runner.d.ts.map +1 -0
- package/modules/workflows/dist/local/local-runner.js +102 -0
- package/modules/workflows/dist/local/local-runner.js.map +1 -0
- package/modules/workflows/dist/local/profiles.d.ts +27 -0
- package/modules/workflows/dist/local/profiles.d.ts.map +1 -0
- package/modules/workflows/dist/local/profiles.js +77 -0
- package/modules/workflows/dist/local/profiles.js.map +1 -0
- package/modules/workflows/dist/operation-kit.d.ts +10 -0
- package/modules/workflows/dist/operation-kit.d.ts.map +1 -0
- package/modules/workflows/dist/operation-kit.js +193 -0
- package/modules/workflows/dist/operation-kit.js.map +1 -0
- package/modules/workflows/dist/operation.d.ts +210 -0
- package/modules/workflows/dist/operation.d.ts.map +1 -0
- package/modules/workflows/dist/operation.js +255 -0
- package/modules/workflows/dist/operation.js.map +1 -0
- package/modules/workflows/dist/operations-analysis.d.ts +188 -0
- package/modules/workflows/dist/operations-analysis.d.ts.map +1 -0
- package/modules/workflows/dist/operations-analysis.js +908 -0
- package/modules/workflows/dist/operations-analysis.js.map +1 -0
- package/modules/workflows/dist/operations-compute.d.ts +21 -0
- package/modules/workflows/dist/operations-compute.d.ts.map +1 -0
- package/modules/workflows/dist/operations-compute.js +1227 -0
- package/modules/workflows/dist/operations-compute.js.map +1 -0
- package/modules/workflows/dist/operations-journey.d.ts +27 -0
- package/modules/workflows/dist/operations-journey.d.ts.map +1 -0
- package/modules/workflows/dist/operations-journey.js +2445 -0
- package/modules/workflows/dist/operations-journey.js.map +1 -0
- package/modules/workflows/dist/operations-trade.d.ts +3 -0
- package/modules/workflows/dist/operations-trade.d.ts.map +1 -0
- package/modules/workflows/dist/operations-trade.js +648 -0
- package/modules/workflows/dist/operations-trade.js.map +1 -0
- package/modules/workflows/dist/preview.d.ts +16 -0
- package/modules/workflows/dist/preview.d.ts.map +1 -0
- package/modules/workflows/dist/preview.js +30 -0
- package/modules/workflows/dist/preview.js.map +1 -0
- package/modules/workflows/dist/registry.d.ts +26 -0
- package/modules/workflows/dist/registry.d.ts.map +1 -0
- package/modules/workflows/dist/registry.js +110 -0
- package/modules/workflows/dist/registry.js.map +1 -0
- package/modules/workflows/dist/runtime.d.ts +76 -0
- package/modules/workflows/dist/runtime.d.ts.map +1 -0
- package/modules/workflows/dist/runtime.js +445 -0
- package/modules/workflows/dist/runtime.js.map +1 -0
- package/modules/workflows/dist/stores-trade.d.ts +101 -0
- package/modules/workflows/dist/stores-trade.d.ts.map +1 -0
- package/modules/workflows/dist/stores-trade.js +275 -0
- package/modules/workflows/dist/stores-trade.js.map +1 -0
- package/modules/workflows/dist/stores.d.ts +109 -0
- package/modules/workflows/dist/stores.d.ts.map +1 -0
- package/modules/workflows/dist/stores.js +393 -0
- package/modules/workflows/dist/stores.js.map +1 -0
- package/modules/workflows/dist/trade-wire-common-schemas.d.ts +57 -0
- package/modules/workflows/dist/trade-wire-common-schemas.d.ts.map +1 -0
- package/modules/workflows/dist/trade-wire-common-schemas.js +286 -0
- package/modules/workflows/dist/trade-wire-common-schemas.js.map +1 -0
- package/modules/workflows/dist/trade-wire-ledger-schemas.d.ts +102 -0
- package/modules/workflows/dist/trade-wire-ledger-schemas.d.ts.map +1 -0
- package/modules/workflows/dist/trade-wire-ledger-schemas.js +321 -0
- package/modules/workflows/dist/trade-wire-ledger-schemas.js.map +1 -0
- package/modules/workflows/dist/trade-wire-market-schemas.d.ts +5 -0
- package/modules/workflows/dist/trade-wire-market-schemas.d.ts.map +1 -0
- package/modules/workflows/dist/trade-wire-market-schemas.js +84 -0
- package/modules/workflows/dist/trade-wire-market-schemas.js.map +1 -0
- package/modules/workflows/dist/trade-wire-schemas.d.ts +1134 -0
- package/modules/workflows/dist/trade-wire-schemas.d.ts.map +1 -0
- package/modules/workflows/dist/trade-wire-schemas.js +755 -0
- package/modules/workflows/dist/trade-wire-schemas.js.map +1 -0
- package/modules/workflows/dist/version.d.ts +3 -0
- package/modules/workflows/dist/version.d.ts.map +1 -0
- package/modules/workflows/dist/version.js +3 -0
- package/modules/workflows/dist/version.js.map +1 -0
- package/modules/workflows/dist/wire-schemas.d.ts +84 -0
- package/modules/workflows/dist/wire-schemas.d.ts.map +1 -0
- package/modules/workflows/dist/wire-schemas.js +88 -0
- package/modules/workflows/dist/wire-schemas.js.map +1 -0
- package/modules/workflows/etc/workflows.api.md +95 -0
- package/modules/workflows/src/capabilities.ts +67 -0
- package/modules/workflows/src/envelope-schema.ts +170 -0
- package/modules/workflows/src/index.ts +118 -0
- package/modules/workflows/src/json-safe.ts +19 -0
- package/modules/workflows/src/local/file-lock.ts +200 -0
- package/modules/workflows/src/local/file-stores.ts +452 -0
- package/modules/workflows/src/local/index.ts +20 -0
- package/modules/workflows/src/local/job-worker.ts +74 -0
- package/modules/workflows/src/local/jobs.ts +458 -0
- package/modules/workflows/src/local/local-runner.ts +170 -0
- package/modules/workflows/src/local/profiles.ts +113 -0
- package/modules/workflows/src/operation-kit.ts +234 -0
- package/modules/workflows/src/operation.ts +607 -0
- package/modules/workflows/src/operations-analysis.ts +1058 -0
- package/modules/workflows/src/operations-compute.ts +1458 -0
- package/modules/workflows/src/operations-journey.ts +2744 -0
- package/modules/workflows/src/operations-trade.ts +946 -0
- package/modules/workflows/src/preview.ts +34 -0
- package/modules/workflows/src/registry.ts +150 -0
- package/modules/workflows/src/runtime.ts +633 -0
- package/modules/workflows/src/stores-trade.ts +463 -0
- package/modules/workflows/src/stores.ts +608 -0
- package/modules/workflows/src/trade-wire-common-schemas.ts +337 -0
- package/modules/workflows/src/trade-wire-ledger-schemas.ts +359 -0
- package/modules/workflows/src/trade-wire-market-schemas.ts +103 -0
- package/modules/workflows/src/trade-wire-schemas.ts +906 -0
- package/modules/workflows/src/version.ts +2 -0
- package/modules/workflows/src/wire-schemas.ts +100 -0
- package/package.json +1008 -0
|
@@ -0,0 +1,2880 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Exotic option engines (spec §9.3): barrier, Asian, and lookback options.
|
|
3
|
+
*
|
|
4
|
+
* Each family pairs a closed-form analytic price with a Monte-Carlo engine that converges to it, so
|
|
5
|
+
* the analytic value and the simulation independently corroborate one another:
|
|
6
|
+
*
|
|
7
|
+
* • **barrier** — Reiner–Rubinstein / Haug single-barrier formulas (continuous monitoring), and a
|
|
8
|
+
* Monte-Carlo engine with the **Brownian-bridge** crossing correction so discrete monitoring
|
|
9
|
+
* converges to the continuous price;
|
|
10
|
+
* • **asian** — the exact discrete *geometric*-average price, used both as a result and as the
|
|
11
|
+
* control variate for the *arithmetic*-average Monte-Carlo (correlation ≈ 0.99 ⇒ huge variance
|
|
12
|
+
* reduction);
|
|
13
|
+
* • **lookback** — Conze–Viswanathan / Goldman–Sosin–Gatto floating- and fixed-strike formulas,
|
|
14
|
+
* and a Monte-Carlo engine with the **Broadie–Glasserman–Kou** discrete-monitoring correction.
|
|
15
|
+
*
|
|
16
|
+
* Exotic results are value envelopes (`Computed<number>`); the Monte-Carlo variants add `result.mc`.
|
|
17
|
+
*/
|
|
18
|
+
import { CONVENTIONS_VERSION, DEFAULT_GREEK_UNITS, ErrorCode, InputError, UnsupportedError, ensureEnum, ensureFinite, ensurePositive, validateClosedRequest, warning, requireArgumentArray, requireArgumentObject, wrongShapeError, finiteOrNull, WarningCode, } from '../../core/dist/index.js';
|
|
19
|
+
import { VALIDATION_SPECS } from './generated/validation-specs.js';
|
|
20
|
+
import { cholesky, normalCdf, normalPdf } from '../../math/dist/index.js';
|
|
21
|
+
import { blackScholesGreeks, blackScholesPrice } from './bsm.js';
|
|
22
|
+
import { finiteDifferenceExtendedGreeks } from './engines/fd-greeks.js';
|
|
23
|
+
import { gbmPathUnchecked, gbmTerminal, monteCarloEstimate, } from './mc/core.js';
|
|
24
|
+
const N = normalCdf;
|
|
25
|
+
const npdf = normalPdf;
|
|
26
|
+
const DAYS_PER_YEAR = 365;
|
|
27
|
+
/**
|
|
28
|
+
* Generated closed-request specs (spec 3B.1b): the runtime allowlists are PROJECTED from the
|
|
29
|
+
* checker-derived inventory, never hand-written, so declaration and enforcement cannot drift.
|
|
30
|
+
* Resolved at module load — a stale key fails at import, not on the call that trips over it.
|
|
31
|
+
*/
|
|
32
|
+
function specOf(key) {
|
|
33
|
+
const spec = VALIDATION_SPECS[key];
|
|
34
|
+
if (spec === undefined) {
|
|
35
|
+
throw new Error(`exotics: no generated validation spec for '${key}' — run \`pnpm validation:update\``);
|
|
36
|
+
}
|
|
37
|
+
return spec;
|
|
38
|
+
}
|
|
39
|
+
function assumptions(t, q, model, engine) {
|
|
40
|
+
return {
|
|
41
|
+
conventionsVersion: CONVENTIONS_VERSION,
|
|
42
|
+
dayCount: 'ACT/365F',
|
|
43
|
+
compounding: 'continuous',
|
|
44
|
+
timeToExpiryYears: t,
|
|
45
|
+
dividendModel: q === 0 ? 'none' : 'continuousYield',
|
|
46
|
+
model,
|
|
47
|
+
engine,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function monteCarloStatistics(est) {
|
|
51
|
+
return {
|
|
52
|
+
standardError: est.standardError,
|
|
53
|
+
confidenceInterval: est.confidenceInterval,
|
|
54
|
+
paths: est.paths,
|
|
55
|
+
seed: est.seed,
|
|
56
|
+
method: est.method,
|
|
57
|
+
varianceReduction: est.varianceReduction,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function validateBarrier(input, functionName) {
|
|
61
|
+
requireArgumentObject(functionName, 'input', input);
|
|
62
|
+
ensurePositive(input.spot, 'spot', functionName);
|
|
63
|
+
ensurePositive(input.strike, 'strike', functionName);
|
|
64
|
+
ensurePositive(input.barrier, 'barrier', functionName);
|
|
65
|
+
ensurePositive(input.timeToExpiryYears, 'timeToExpiryYears', functionName);
|
|
66
|
+
ensurePositive(input.volatility, 'volatility', functionName);
|
|
67
|
+
ensureFinite(input.riskFreeRate, 'riskFreeRate', functionName);
|
|
68
|
+
const q = input.dividendYield ?? 0;
|
|
69
|
+
ensureFinite(q, 'dividendYield', functionName);
|
|
70
|
+
return q;
|
|
71
|
+
}
|
|
72
|
+
/** Reiner–Rubinstein / Haug single-barrier price (continuous monitoring, zero rebate). */
|
|
73
|
+
function barrierAnalytic(input) {
|
|
74
|
+
const { type, barrierType, spot: S, strike: K, barrier: H, timeToExpiryYears: T, riskFreeRate: r, dividendYield: q, volatility: sigma, } = input;
|
|
75
|
+
const isDown = barrierType === 'down-in' || barrierType === 'down-out';
|
|
76
|
+
const isOut = barrierType === 'down-out' || barrierType === 'up-out';
|
|
77
|
+
const knocked = isDown ? S <= H : S >= H;
|
|
78
|
+
const vanilla = blackScholesPrice({
|
|
79
|
+
type,
|
|
80
|
+
spot: S,
|
|
81
|
+
strike: K,
|
|
82
|
+
timeToExpiryYears: T,
|
|
83
|
+
riskFreeRate: r,
|
|
84
|
+
dividendYield: q,
|
|
85
|
+
volatility: sigma,
|
|
86
|
+
});
|
|
87
|
+
if (knocked)
|
|
88
|
+
return isOut ? 0 : vanilla;
|
|
89
|
+
const b = r - q;
|
|
90
|
+
const sqrtT = Math.sqrt(T);
|
|
91
|
+
const phi = type === 'call' ? 1 : -1;
|
|
92
|
+
const eta = isDown ? 1 : -1;
|
|
93
|
+
const mu = (b - 0.5 * sigma * sigma) / (sigma * sigma);
|
|
94
|
+
const vol = sigma * sqrtT;
|
|
95
|
+
const x1 = Math.log(S / K) / vol + (1 + mu) * vol;
|
|
96
|
+
const x2 = Math.log(S / H) / vol + (1 + mu) * vol;
|
|
97
|
+
const y1 = Math.log((H * H) / (S * K)) / vol + (1 + mu) * vol;
|
|
98
|
+
const y2 = Math.log(H / S) / vol + (1 + mu) * vol;
|
|
99
|
+
const eqr = Math.exp((b - r) * T);
|
|
100
|
+
const er = Math.exp(-r * T);
|
|
101
|
+
const HS2mu1 = Math.pow(H / S, 2 * (mu + 1));
|
|
102
|
+
const HS2mu = Math.pow(H / S, 2 * mu);
|
|
103
|
+
const A = phi * S * eqr * N(phi * x1) - phi * K * er * N(phi * x1 - phi * vol);
|
|
104
|
+
const B = phi * S * eqr * N(phi * x2) - phi * K * er * N(phi * x2 - phi * vol);
|
|
105
|
+
const C = phi * S * eqr * HS2mu1 * N(eta * y1) - phi * K * er * HS2mu * N(eta * y1 - eta * vol);
|
|
106
|
+
const D = phi * S * eqr * HS2mu1 * N(eta * y2) - phi * K * er * HS2mu * N(eta * y2 - eta * vol);
|
|
107
|
+
const kGtH = K > H;
|
|
108
|
+
let knockIn;
|
|
109
|
+
if (type === 'call' && isDown)
|
|
110
|
+
knockIn = kGtH ? C : A - B + D;
|
|
111
|
+
else if (type === 'call' && !isDown)
|
|
112
|
+
knockIn = kGtH ? A : B - C + D;
|
|
113
|
+
else if (type === 'put' && isDown)
|
|
114
|
+
knockIn = kGtH ? B - C + D : A;
|
|
115
|
+
else
|
|
116
|
+
knockIn = kGtH ? A - B + D : C; // put, up
|
|
117
|
+
return isOut ? Math.max(0, vanilla - knockIn) : Math.max(0, knockIn);
|
|
118
|
+
}
|
|
119
|
+
/** Survival probability of a discrete path against a continuous barrier (Brownian-bridge corrected). */
|
|
120
|
+
function barrierSurvival(input) {
|
|
121
|
+
const { path, barrier: H, isDown, volatility: sigma, timeStepYears } = input;
|
|
122
|
+
let surv = 1;
|
|
123
|
+
const v = sigma * sigma * timeStepYears;
|
|
124
|
+
for (let k = 0; k < path.length - 1; k++) {
|
|
125
|
+
const a = path[k];
|
|
126
|
+
const c = path[k + 1];
|
|
127
|
+
if (isDown) {
|
|
128
|
+
if (a <= H || c <= H)
|
|
129
|
+
return 0;
|
|
130
|
+
surv *= 1 - Math.exp((-2 * Math.log(a / H) * Math.log(c / H)) / v);
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
if (a >= H || c >= H)
|
|
134
|
+
return 0;
|
|
135
|
+
surv *= 1 - Math.exp((-2 * Math.log(H / a) * Math.log(H / c)) / v);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return surv;
|
|
139
|
+
}
|
|
140
|
+
const BARRIER_PRICE_SPEC = specOf('barrier.price#0');
|
|
141
|
+
const BARRIER_MC_INPUT_SPEC = specOf('barrier.monteCarloPrice#0');
|
|
142
|
+
const BARRIER_MC_OPTIONS_SPEC = specOf('barrier.monteCarloPrice#1');
|
|
143
|
+
const BARRIER_EXAMPLE = () => "barrier.price({ type: 'call', barrierType: 'up-out', spot: 100, strike: 105, barrier: 120, timeToExpiryYears: 0.25, riskFreeRate: 0.04, volatility: 0.2 })";
|
|
144
|
+
export const barrier = {
|
|
145
|
+
/** Continuous-monitoring single-barrier price (Reiner–Rubinstein / Haug, zero rebate). */
|
|
146
|
+
price(input) {
|
|
147
|
+
const functionName = 'barrier.price';
|
|
148
|
+
validateClosedRequest(functionName, input, BARRIER_PRICE_SPEC, {
|
|
149
|
+
exampleCall: BARRIER_EXAMPLE,
|
|
150
|
+
});
|
|
151
|
+
const { type, barrierType } = input;
|
|
152
|
+
const q = validateBarrier(input, functionName);
|
|
153
|
+
const value = barrierAnalytic({
|
|
154
|
+
type,
|
|
155
|
+
barrierType,
|
|
156
|
+
spot: input.spot,
|
|
157
|
+
strike: input.strike,
|
|
158
|
+
barrier: input.barrier,
|
|
159
|
+
timeToExpiryYears: input.timeToExpiryYears,
|
|
160
|
+
riskFreeRate: input.riskFreeRate,
|
|
161
|
+
dividendYield: q,
|
|
162
|
+
volatility: input.volatility,
|
|
163
|
+
});
|
|
164
|
+
const diagnostics = {
|
|
165
|
+
engine: `barrier-${barrierType}`,
|
|
166
|
+
method: 'reiner-rubinstein',
|
|
167
|
+
converged: Number.isFinite(value),
|
|
168
|
+
warnings: [],
|
|
169
|
+
};
|
|
170
|
+
return {
|
|
171
|
+
value,
|
|
172
|
+
assumptions: assumptions(input.timeToExpiryYears, q, 'barrier', `barrier-${barrierType}`),
|
|
173
|
+
diagnostics,
|
|
174
|
+
};
|
|
175
|
+
},
|
|
176
|
+
/** Brownian-bridge-corrected Monte-Carlo barrier price (converges to the continuous analytic). */
|
|
177
|
+
monteCarloPrice(input, options) {
|
|
178
|
+
const functionName = 'barrier.monteCarloPrice';
|
|
179
|
+
validateClosedRequest(functionName, input, BARRIER_MC_INPUT_SPEC, {
|
|
180
|
+
exampleCall: BARRIER_EXAMPLE,
|
|
181
|
+
});
|
|
182
|
+
validateClosedRequest(functionName, options, BARRIER_MC_OPTIONS_SPEC, {
|
|
183
|
+
exampleCall: BARRIER_EXAMPLE,
|
|
184
|
+
argumentName: 'options',
|
|
185
|
+
});
|
|
186
|
+
const { type, barrierType } = input;
|
|
187
|
+
const q = validateBarrier(input, functionName);
|
|
188
|
+
const { spot: S, strike: K, barrier: H, timeToExpiryYears: T, riskFreeRate: r, volatility: sigma, } = input;
|
|
189
|
+
const steps = options.steps ?? 100;
|
|
190
|
+
const timeStepYears = T / steps;
|
|
191
|
+
const df = Math.exp(-r * T);
|
|
192
|
+
const isDown = barrierType === 'down-in' || barrierType === 'down-out';
|
|
193
|
+
const isOut = barrierType === 'down-out' || barrierType === 'up-out';
|
|
194
|
+
const payoff = (z) => {
|
|
195
|
+
const path = gbmPathUnchecked({
|
|
196
|
+
spot: S,
|
|
197
|
+
riskFreeRate: r,
|
|
198
|
+
dividendYield: q,
|
|
199
|
+
volatility: sigma,
|
|
200
|
+
timeToExpiryYears: T,
|
|
201
|
+
shocks: z,
|
|
202
|
+
});
|
|
203
|
+
const ST = path[steps];
|
|
204
|
+
const intrinsic = type === 'call' ? Math.max(ST - K, 0) : Math.max(K - ST, 0);
|
|
205
|
+
const surv = barrierSurvival({
|
|
206
|
+
path,
|
|
207
|
+
barrier: H,
|
|
208
|
+
isDown,
|
|
209
|
+
volatility: sigma,
|
|
210
|
+
timeStepYears,
|
|
211
|
+
});
|
|
212
|
+
return df * intrinsic * (isOut ? surv : 1 - surv);
|
|
213
|
+
};
|
|
214
|
+
const est = monteCarloEstimate({
|
|
215
|
+
dimensions: steps,
|
|
216
|
+
payoff,
|
|
217
|
+
options,
|
|
218
|
+
controlVariate: undefined,
|
|
219
|
+
label: functionName,
|
|
220
|
+
});
|
|
221
|
+
const diagnostics = {
|
|
222
|
+
engine: `barrier-${barrierType}`,
|
|
223
|
+
method: est.method === 'pseudo'
|
|
224
|
+
? 'monte-carlo-brownian-bridge'
|
|
225
|
+
: `monte-carlo-${est.method}-brownian-bridge`,
|
|
226
|
+
converged: est.converged,
|
|
227
|
+
iterations: est.paths,
|
|
228
|
+
warnings: est.warnings,
|
|
229
|
+
};
|
|
230
|
+
return {
|
|
231
|
+
value: est.value,
|
|
232
|
+
assumptions: assumptions(input.timeToExpiryYears, q, 'barrier', `barrier-${barrierType}-mc`),
|
|
233
|
+
diagnostics,
|
|
234
|
+
monteCarlo: monteCarloStatistics(est),
|
|
235
|
+
};
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
function validateAsian(input, functionName) {
|
|
239
|
+
ensurePositive(input.spot, 'spot', functionName);
|
|
240
|
+
ensurePositive(input.strike, 'strike', functionName);
|
|
241
|
+
ensurePositive(input.timeToExpiryYears, 'timeToExpiryYears', functionName);
|
|
242
|
+
ensureFinite(input.riskFreeRate, 'riskFreeRate', functionName);
|
|
243
|
+
const q = input.dividendYield ?? 0;
|
|
244
|
+
ensureFinite(q, 'dividendYield', functionName);
|
|
245
|
+
return q;
|
|
246
|
+
}
|
|
247
|
+
/** Exact discrete geometric-average Asian price (the average's geometric mean is lognormal). */
|
|
248
|
+
function geometricAsian(input) {
|
|
249
|
+
const { type, spot: S, strike: K, timeToExpiryYears: T, riskFreeRate: r, dividendYield: q, volatility: sigma, averagingPoints: m, } = input;
|
|
250
|
+
const timeStepYears = T / m;
|
|
251
|
+
// t_i = i·dt, i=1..m → t̄ = dt·(m+1)/2 ; Σ_{i,j} min(t_i,t_j) = dt·m(m+1)(2m+1)/6
|
|
252
|
+
const tBar = timeStepYears * ((m + 1) / 2);
|
|
253
|
+
const varSum = timeStepYears * ((m * (m + 1) * (2 * m + 1)) / 6);
|
|
254
|
+
const muG = Math.log(S) + (r - q - 0.5 * sigma * sigma) * tBar;
|
|
255
|
+
const varG = (sigma * sigma * varSum) / (m * m);
|
|
256
|
+
const sigG = Math.sqrt(varG);
|
|
257
|
+
const d1 = (muG - Math.log(K) + varG) / sigG;
|
|
258
|
+
const d2 = d1 - sigG;
|
|
259
|
+
const eG = Math.exp(muG + 0.5 * varG);
|
|
260
|
+
const er = Math.exp(-r * T);
|
|
261
|
+
return type === 'call' ? er * (eG * N(d1) - K * N(d2)) : er * (K * N(-d2) - eG * N(-d1));
|
|
262
|
+
}
|
|
263
|
+
const ASIAN_GEOMETRIC_SPEC = specOf('asian.geometricPrice#0');
|
|
264
|
+
const ASIAN_MC_INPUT_SPEC = specOf('asian.monteCarloPrice#0');
|
|
265
|
+
const ASIAN_MC_OPTIONS_SPEC = specOf('asian.monteCarloPrice#1');
|
|
266
|
+
const ASIAN_EXAMPLE = () => "asian.geometricPrice({ type: 'call', spot: 100, strike: 105, timeToExpiryYears: 0.25, riskFreeRate: 0.04, volatility: 0.2 })";
|
|
267
|
+
export const asian = {
|
|
268
|
+
/** Exact discrete geometric-average Asian price. */
|
|
269
|
+
geometricPrice(input) {
|
|
270
|
+
const functionName = 'asian.geometricPrice';
|
|
271
|
+
validateClosedRequest(functionName, input, ASIAN_GEOMETRIC_SPEC, {
|
|
272
|
+
exampleCall: ASIAN_EXAMPLE,
|
|
273
|
+
});
|
|
274
|
+
const { type } = input;
|
|
275
|
+
const q = validateAsian(input, functionName);
|
|
276
|
+
const sigma = requireSigma(input, functionName);
|
|
277
|
+
const m = input.averagingPoints ?? 50;
|
|
278
|
+
requirePoints(m, functionName);
|
|
279
|
+
const value = geometricAsian({
|
|
280
|
+
type,
|
|
281
|
+
spot: input.spot,
|
|
282
|
+
strike: input.strike,
|
|
283
|
+
timeToExpiryYears: input.timeToExpiryYears,
|
|
284
|
+
riskFreeRate: input.riskFreeRate,
|
|
285
|
+
dividendYield: q,
|
|
286
|
+
volatility: sigma,
|
|
287
|
+
averagingPoints: m,
|
|
288
|
+
});
|
|
289
|
+
const diagnostics = {
|
|
290
|
+
engine: 'asian-geometric',
|
|
291
|
+
method: 'closed-form',
|
|
292
|
+
converged: Number.isFinite(value),
|
|
293
|
+
warnings: [],
|
|
294
|
+
};
|
|
295
|
+
return {
|
|
296
|
+
value,
|
|
297
|
+
assumptions: assumptions(input.timeToExpiryYears, q, 'asian-geometric', 'asian-geometric'),
|
|
298
|
+
diagnostics,
|
|
299
|
+
};
|
|
300
|
+
},
|
|
301
|
+
/** Arithmetic-average Asian price by Monte-Carlo, with the geometric Asian as control variate. */
|
|
302
|
+
monteCarloPrice(input, options) {
|
|
303
|
+
const functionName = 'asian.monteCarloPrice';
|
|
304
|
+
validateClosedRequest(functionName, input, ASIAN_MC_INPUT_SPEC, {
|
|
305
|
+
exampleCall: ASIAN_EXAMPLE,
|
|
306
|
+
});
|
|
307
|
+
validateClosedRequest(functionName, options, ASIAN_MC_OPTIONS_SPEC, {
|
|
308
|
+
exampleCall: ASIAN_EXAMPLE,
|
|
309
|
+
argumentName: 'options',
|
|
310
|
+
});
|
|
311
|
+
const { type } = input;
|
|
312
|
+
const q = validateAsian(input, functionName);
|
|
313
|
+
const sigma = requireSigma(input, functionName);
|
|
314
|
+
const { spot: S, strike: K, timeToExpiryYears: T, riskFreeRate: r } = input;
|
|
315
|
+
const m = options.averagingPoints ?? 50;
|
|
316
|
+
requirePoints(m, functionName);
|
|
317
|
+
const df = Math.exp(-r * T);
|
|
318
|
+
const geoMean = geometricAsian({
|
|
319
|
+
type,
|
|
320
|
+
spot: S,
|
|
321
|
+
strike: K,
|
|
322
|
+
timeToExpiryYears: T,
|
|
323
|
+
riskFreeRate: r,
|
|
324
|
+
dividendYield: q,
|
|
325
|
+
volatility: sigma,
|
|
326
|
+
averagingPoints: m,
|
|
327
|
+
});
|
|
328
|
+
const averages = (z) => {
|
|
329
|
+
const path = gbmPathUnchecked({
|
|
330
|
+
spot: S,
|
|
331
|
+
riskFreeRate: r,
|
|
332
|
+
dividendYield: q,
|
|
333
|
+
volatility: sigma,
|
|
334
|
+
timeToExpiryYears: T,
|
|
335
|
+
shocks: z,
|
|
336
|
+
});
|
|
337
|
+
let sum = 0;
|
|
338
|
+
let logSum = 0;
|
|
339
|
+
for (let i = 1; i <= m; i++) {
|
|
340
|
+
sum += path[i];
|
|
341
|
+
logSum += Math.log(path[i]);
|
|
342
|
+
}
|
|
343
|
+
return { arith: sum / m, geo: Math.exp(logSum / m) };
|
|
344
|
+
};
|
|
345
|
+
const payoff = (z) => {
|
|
346
|
+
const { arith } = averages(z);
|
|
347
|
+
return df * (type === 'call' ? Math.max(arith - K, 0) : Math.max(K - arith, 0));
|
|
348
|
+
};
|
|
349
|
+
const control = {
|
|
350
|
+
estimate: (z) => {
|
|
351
|
+
const { geo } = averages(z);
|
|
352
|
+
return df * (type === 'call' ? Math.max(geo - K, 0) : Math.max(K - geo, 0));
|
|
353
|
+
},
|
|
354
|
+
mean: geoMean,
|
|
355
|
+
};
|
|
356
|
+
const est = monteCarloEstimate({
|
|
357
|
+
dimensions: m,
|
|
358
|
+
payoff,
|
|
359
|
+
options,
|
|
360
|
+
controlVariate: control,
|
|
361
|
+
label: functionName,
|
|
362
|
+
});
|
|
363
|
+
const diagnostics = {
|
|
364
|
+
engine: 'asian-arithmetic',
|
|
365
|
+
method: est.method === 'pseudo'
|
|
366
|
+
? 'monte-carlo-geometric-control'
|
|
367
|
+
: `monte-carlo-${est.method}-geometric-control`,
|
|
368
|
+
converged: est.converged,
|
|
369
|
+
iterations: est.paths,
|
|
370
|
+
warnings: est.warnings,
|
|
371
|
+
};
|
|
372
|
+
return {
|
|
373
|
+
value: est.value,
|
|
374
|
+
assumptions: assumptions(input.timeToExpiryYears, q, 'asian-arithmetic', 'asian-arithmetic-mc'),
|
|
375
|
+
diagnostics,
|
|
376
|
+
monteCarlo: monteCarloStatistics(est),
|
|
377
|
+
};
|
|
378
|
+
},
|
|
379
|
+
};
|
|
380
|
+
const LOOKBACK_STRIKES = ['floating', 'fixed'];
|
|
381
|
+
/** Broadie–Glasserman–Kou discrete-monitoring shift constant β = ζ(1/2)/√(2π). */
|
|
382
|
+
const BGK_BETA = 0.5826;
|
|
383
|
+
function bSafe(r, q) {
|
|
384
|
+
// The lookback closed form has a 1/(r−q) factor; nudge the cost-of-carry off zero to avoid the
|
|
385
|
+
// removable singularity (negligible price impact, flagged to the caller).
|
|
386
|
+
const b = r - q;
|
|
387
|
+
return Math.abs(b) < 1e-6 ? (b >= 0 ? 1e-6 : -1e-6) : b;
|
|
388
|
+
}
|
|
389
|
+
function floatingLookback(input) {
|
|
390
|
+
const { type, spot: S, timeToExpiryYears: T, riskFreeRate: r, dividendYield: q, volatility: sigma, runningMin: sMin, runningMax: sMax, } = input;
|
|
391
|
+
const b = bSafe(r, q);
|
|
392
|
+
const sqrtT = Math.sqrt(T);
|
|
393
|
+
const vol = sigma * sqrtT;
|
|
394
|
+
const eqr = Math.exp((b - r) * T);
|
|
395
|
+
const er = Math.exp(-r * T);
|
|
396
|
+
const twoB = (2 * b) / (sigma * sigma);
|
|
397
|
+
if (type === 'call') {
|
|
398
|
+
const m = sMin;
|
|
399
|
+
const a1 = (Math.log(S / m) + (b + 0.5 * sigma * sigma) * T) / vol;
|
|
400
|
+
const a2 = a1 - vol;
|
|
401
|
+
return (S * eqr * N(a1) -
|
|
402
|
+
m * er * N(a2) +
|
|
403
|
+
S *
|
|
404
|
+
er *
|
|
405
|
+
((sigma * sigma) / (2 * b)) *
|
|
406
|
+
(Math.pow(S / m, -twoB) * N(-a1 + twoB * vol) - Math.exp(b * T) * N(-a1)));
|
|
407
|
+
}
|
|
408
|
+
const M = sMax;
|
|
409
|
+
const b1 = (Math.log(S / M) + (b + 0.5 * sigma * sigma) * T) / vol;
|
|
410
|
+
const b2 = b1 - vol;
|
|
411
|
+
return (M * er * N(-b2) -
|
|
412
|
+
S * eqr * N(-b1) +
|
|
413
|
+
S *
|
|
414
|
+
er *
|
|
415
|
+
((sigma * sigma) / (2 * b)) *
|
|
416
|
+
(-Math.pow(S / M, -twoB) * N(b1 - twoB * vol) + Math.exp(b * T) * N(b1)));
|
|
417
|
+
}
|
|
418
|
+
function fixedLookback(input) {
|
|
419
|
+
const { type, spot: S, strike: K, timeToExpiryYears: T, riskFreeRate: r, dividendYield: q, volatility: sigma, runningMin: sMin, runningMax: sMax, } = input;
|
|
420
|
+
const b = bSafe(r, q);
|
|
421
|
+
const sqrtT = Math.sqrt(T);
|
|
422
|
+
const vol = sigma * sqrtT;
|
|
423
|
+
const eqr = Math.exp((b - r) * T);
|
|
424
|
+
const er = Math.exp(-r * T);
|
|
425
|
+
const twoB = (2 * b) / (sigma * sigma);
|
|
426
|
+
const carry = (S * er * sigma * sigma) / (2 * b);
|
|
427
|
+
if (type === 'call') {
|
|
428
|
+
if (K > sMax) {
|
|
429
|
+
const d1 = (Math.log(S / K) + (b + 0.5 * sigma * sigma) * T) / vol;
|
|
430
|
+
const d2 = d1 - vol;
|
|
431
|
+
return (S * eqr * N(d1) -
|
|
432
|
+
K * er * N(d2) +
|
|
433
|
+
carry * (-Math.pow(S / K, -twoB) * N(d1 - twoB * vol) + Math.exp(b * T) * N(d1)));
|
|
434
|
+
}
|
|
435
|
+
const M = sMax;
|
|
436
|
+
const e1 = (Math.log(S / M) + (b + 0.5 * sigma * sigma) * T) / vol;
|
|
437
|
+
const e2 = e1 - vol;
|
|
438
|
+
return (er * (M - K) +
|
|
439
|
+
S * eqr * N(e1) -
|
|
440
|
+
M * er * N(e2) +
|
|
441
|
+
carry * (-Math.pow(S / M, -twoB) * N(e1 - twoB * vol) + Math.exp(b * T) * N(e1)));
|
|
442
|
+
}
|
|
443
|
+
// put
|
|
444
|
+
if (K < sMin) {
|
|
445
|
+
const f1 = (Math.log(S / K) + (b + 0.5 * sigma * sigma) * T) / vol;
|
|
446
|
+
const f2 = f1 - vol;
|
|
447
|
+
return (K * er * N(-f2) -
|
|
448
|
+
S * eqr * N(-f1) +
|
|
449
|
+
carry * (Math.pow(S / K, -twoB) * N(-f1 + twoB * vol) - Math.exp(b * T) * N(-f1)));
|
|
450
|
+
}
|
|
451
|
+
const m = sMin;
|
|
452
|
+
const g1 = (Math.log(S / m) + (b + 0.5 * sigma * sigma) * T) / vol;
|
|
453
|
+
const g2 = g1 - vol;
|
|
454
|
+
return (er * (K - m) -
|
|
455
|
+
S * eqr * N(-g1) +
|
|
456
|
+
m * er * N(-g2) +
|
|
457
|
+
carry * (Math.pow(S / m, -twoB) * N(-g1 + twoB * vol) - Math.exp(b * T) * N(-g1)));
|
|
458
|
+
}
|
|
459
|
+
function validateLookback(input, strikeType, functionName) {
|
|
460
|
+
ensureEnum(strikeType, LOOKBACK_STRIKES, 'strikeType', functionName);
|
|
461
|
+
requireArgumentObject(functionName, 'input', input);
|
|
462
|
+
ensurePositive(input.spot, 'spot', functionName);
|
|
463
|
+
ensurePositive(input.timeToExpiryYears, 'timeToExpiryYears', functionName);
|
|
464
|
+
ensurePositive(input.volatility, 'volatility', functionName);
|
|
465
|
+
ensureFinite(input.riskFreeRate, 'riskFreeRate', functionName);
|
|
466
|
+
const q = input.dividendYield ?? 0;
|
|
467
|
+
ensureFinite(q, 'dividendYield', functionName);
|
|
468
|
+
if (strikeType === 'fixed') {
|
|
469
|
+
if (typeof input.strike !== 'number') {
|
|
470
|
+
throw new InputError(`${functionName}: fixed-strike lookbacks require a strike.`, {
|
|
471
|
+
code: ErrorCode.InputMissingField,
|
|
472
|
+
context: { field: 'strike' },
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
ensurePositive(input.strike, 'strike', functionName);
|
|
476
|
+
}
|
|
477
|
+
const sMin = input.runningMin ?? input.spot;
|
|
478
|
+
const sMax = input.runningMax ?? input.spot;
|
|
479
|
+
ensurePositive(sMin, 'runningMin', functionName);
|
|
480
|
+
ensurePositive(sMax, 'runningMax', functionName);
|
|
481
|
+
const warnings = [];
|
|
482
|
+
if (Math.abs(input.riskFreeRate - q) < 1e-6) {
|
|
483
|
+
warnings.push(warning(WarningCode.LookbackZeroCarry, 'Cost of carry r−q ≈ 0; the closed form has a removable singularity there and is evaluated at a small ε offset.', 'info', { riskFreeRate: input.riskFreeRate, dividendYield: q }));
|
|
484
|
+
}
|
|
485
|
+
return { q, sMin, sMax, warnings };
|
|
486
|
+
}
|
|
487
|
+
const LOOKBACK_PRICE_SPEC = specOf('lookback.price#0');
|
|
488
|
+
const LOOKBACK_MC_INPUT_SPEC = specOf('lookback.monteCarloPrice#0');
|
|
489
|
+
const LOOKBACK_MC_OPTIONS_SPEC = specOf('lookback.monteCarloPrice#1');
|
|
490
|
+
const LOOKBACK_EXAMPLE = () => "lookback.price({ type: 'call', strikeType: 'floating', spot: 100, timeToExpiryYears: 0.25, riskFreeRate: 0.04, volatility: 0.2 })";
|
|
491
|
+
export const lookback = {
|
|
492
|
+
/** Continuous-monitoring lookback price (Conze–Viswanathan / Goldman–Sosin–Gatto). */
|
|
493
|
+
price(input) {
|
|
494
|
+
const functionName = 'lookback.price';
|
|
495
|
+
validateClosedRequest(functionName, input, LOOKBACK_PRICE_SPEC, {
|
|
496
|
+
exampleCall: LOOKBACK_EXAMPLE,
|
|
497
|
+
});
|
|
498
|
+
const { type, strikeType } = input;
|
|
499
|
+
const { q, sMin, sMax, warnings } = validateLookback(input, strikeType, functionName);
|
|
500
|
+
const sigma = input.volatility;
|
|
501
|
+
const value = strikeType === 'floating'
|
|
502
|
+
? floatingLookback({
|
|
503
|
+
type,
|
|
504
|
+
spot: input.spot,
|
|
505
|
+
timeToExpiryYears: input.timeToExpiryYears,
|
|
506
|
+
riskFreeRate: input.riskFreeRate,
|
|
507
|
+
dividendYield: q,
|
|
508
|
+
volatility: sigma,
|
|
509
|
+
runningMin: sMin,
|
|
510
|
+
runningMax: sMax,
|
|
511
|
+
})
|
|
512
|
+
: fixedLookback({
|
|
513
|
+
type,
|
|
514
|
+
spot: input.spot,
|
|
515
|
+
strike: input.strike,
|
|
516
|
+
timeToExpiryYears: input.timeToExpiryYears,
|
|
517
|
+
riskFreeRate: input.riskFreeRate,
|
|
518
|
+
dividendYield: q,
|
|
519
|
+
volatility: sigma,
|
|
520
|
+
runningMin: sMin,
|
|
521
|
+
runningMax: sMax,
|
|
522
|
+
});
|
|
523
|
+
const diagnostics = {
|
|
524
|
+
engine: `lookback-${strikeType}`,
|
|
525
|
+
method: 'conze-viswanathan',
|
|
526
|
+
converged: Number.isFinite(value),
|
|
527
|
+
warnings,
|
|
528
|
+
};
|
|
529
|
+
return {
|
|
530
|
+
value: Math.max(0, value),
|
|
531
|
+
assumptions: assumptions(input.timeToExpiryYears, q, `lookback-${strikeType}`, `lookback-${strikeType}`),
|
|
532
|
+
diagnostics,
|
|
533
|
+
};
|
|
534
|
+
},
|
|
535
|
+
/** Monte-Carlo lookback price with the Broadie–Glasserman–Kou discrete-monitoring correction. */
|
|
536
|
+
monteCarloPrice(input, options) {
|
|
537
|
+
const functionName = 'lookback.monteCarloPrice';
|
|
538
|
+
validateClosedRequest(functionName, input, LOOKBACK_MC_INPUT_SPEC, {
|
|
539
|
+
exampleCall: LOOKBACK_EXAMPLE,
|
|
540
|
+
});
|
|
541
|
+
validateClosedRequest(functionName, options, LOOKBACK_MC_OPTIONS_SPEC, {
|
|
542
|
+
exampleCall: LOOKBACK_EXAMPLE,
|
|
543
|
+
argumentName: 'options',
|
|
544
|
+
});
|
|
545
|
+
const { type, strikeType } = input;
|
|
546
|
+
const { q, sMin: sMin0, sMax: sMax0, warnings, } = validateLookback(input, strikeType, functionName);
|
|
547
|
+
const { spot: S, timeToExpiryYears: T, riskFreeRate: r, volatility: sigma } = input;
|
|
548
|
+
const K = input.strike ?? 0;
|
|
549
|
+
const steps = options.steps ?? 150;
|
|
550
|
+
const timeStepYears = T / steps;
|
|
551
|
+
const df = Math.exp(-r * T);
|
|
552
|
+
// BGK shift: the continuous extreme is the discrete one extrapolated by exp(±βσ√dt).
|
|
553
|
+
const upShift = Math.exp(BGK_BETA * sigma * Math.sqrt(timeStepYears));
|
|
554
|
+
const downShift = 1 / upShift;
|
|
555
|
+
const payoff = (z) => {
|
|
556
|
+
const path = gbmPathUnchecked({
|
|
557
|
+
spot: S,
|
|
558
|
+
riskFreeRate: r,
|
|
559
|
+
dividendYield: q,
|
|
560
|
+
volatility: sigma,
|
|
561
|
+
timeToExpiryYears: T,
|
|
562
|
+
shocks: z,
|
|
563
|
+
});
|
|
564
|
+
let mn = sMin0;
|
|
565
|
+
let mx = sMax0;
|
|
566
|
+
for (let i = 1; i <= steps; i++) {
|
|
567
|
+
const p = path[i];
|
|
568
|
+
if (p < mn)
|
|
569
|
+
mn = p;
|
|
570
|
+
if (p > mx)
|
|
571
|
+
mx = p;
|
|
572
|
+
}
|
|
573
|
+
const ST = path[steps];
|
|
574
|
+
const minC = mn * downShift;
|
|
575
|
+
const maxC = mx * upShift;
|
|
576
|
+
let intrinsic;
|
|
577
|
+
if (strikeType === 'floating') {
|
|
578
|
+
intrinsic = type === 'call' ? ST - minC : maxC - ST;
|
|
579
|
+
}
|
|
580
|
+
else {
|
|
581
|
+
intrinsic = type === 'call' ? Math.max(maxC - K, 0) : Math.max(K - minC, 0);
|
|
582
|
+
}
|
|
583
|
+
return df * Math.max(0, intrinsic);
|
|
584
|
+
};
|
|
585
|
+
const est = monteCarloEstimate({
|
|
586
|
+
dimensions: steps,
|
|
587
|
+
payoff,
|
|
588
|
+
options,
|
|
589
|
+
controlVariate: undefined,
|
|
590
|
+
label: functionName,
|
|
591
|
+
});
|
|
592
|
+
const diagnostics = {
|
|
593
|
+
engine: `lookback-${strikeType}`,
|
|
594
|
+
method: est.method === 'pseudo' ? 'monte-carlo-bgk' : `monte-carlo-${est.method}-bgk`,
|
|
595
|
+
converged: est.converged,
|
|
596
|
+
iterations: est.paths,
|
|
597
|
+
warnings: [...warnings, ...est.warnings],
|
|
598
|
+
};
|
|
599
|
+
return {
|
|
600
|
+
value: est.value,
|
|
601
|
+
assumptions: assumptions(input.timeToExpiryYears, q, `lookback-${strikeType}`, `lookback-${strikeType}-mc`),
|
|
602
|
+
diagnostics,
|
|
603
|
+
monteCarlo: monteCarloStatistics(est),
|
|
604
|
+
};
|
|
605
|
+
},
|
|
606
|
+
};
|
|
607
|
+
// ────────────────────────────────────────────────────────────────────────────
|
|
608
|
+
// shared input validation
|
|
609
|
+
// ────────────────────────────────────────────────────────────────────────────
|
|
610
|
+
function requireSigma(input, functionName) {
|
|
611
|
+
if (typeof input.volatility !== 'number') {
|
|
612
|
+
throw new InputError(`${functionName}: volatility (a number) is required.`, {
|
|
613
|
+
code: ErrorCode.InputMissingField,
|
|
614
|
+
context: { field: 'volatility' },
|
|
615
|
+
});
|
|
616
|
+
}
|
|
617
|
+
ensurePositive(input.volatility, 'volatility', functionName);
|
|
618
|
+
return input.volatility;
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* The most averaging fixings one Asian contract accepts (2026-08-23 review, P0 "unbounded work"):
|
|
622
|
+
* `Number.isInteger(1e308)` is `true`, so the old check let an absurd fixing count through — the
|
|
623
|
+
* Monte-Carlo pricer draws one normal and one path point PER fixing on every path (averagingPoints
|
|
624
|
+
* becomes the estimator's dimension count), so the count is a workload control, not a label.
|
|
625
|
+
* 100,000 fixings is daily averaging for ~400 years; real Asian contracts fix daily-to-monthly over
|
|
626
|
+
* months-to-years (tens to hundreds).
|
|
627
|
+
*/
|
|
628
|
+
const MAX_AVERAGING_POINTS = 100_000;
|
|
629
|
+
function requirePoints(m, functionName) {
|
|
630
|
+
if (!Number.isSafeInteger(m) || m < 1 || m > MAX_AVERAGING_POINTS) {
|
|
631
|
+
throw new InputError(`${functionName}: averagingPoints must be an integer in [1, ${MAX_AVERAGING_POINTS.toLocaleString('en-US')}] — each fixing is one path point per Monte-Carlo path (the cap is daily fixings for ~400 years; real contracts fix tens to hundreds of times). Received ${m}.\n e.g. { averagingPoints: 252 }`, {
|
|
632
|
+
code: ErrorCode.InputOutOfRange,
|
|
633
|
+
context: { averagingPoints: m, max: MAX_AVERAGING_POINTS },
|
|
634
|
+
});
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
// ────────────────────────────────────────────────────────────────────────────
|
|
638
|
+
// §9.3 multi-asset & structured exotics: spread, quanto, basket, rainbow,
|
|
639
|
+
// autocallable, and variance/volatility swaps. Each closed form is corroborated by
|
|
640
|
+
// (or, where no closed form exists, replaced with) a Monte-Carlo engine.
|
|
641
|
+
// ────────────────────────────────────────────────────────────────────────────
|
|
642
|
+
/** Map independent normals `z` to correlated normals via a Cholesky factor `L` (lower-triangular). */
|
|
643
|
+
function correlatedDraw(L, z) {
|
|
644
|
+
const n = L.length;
|
|
645
|
+
const w = new Array(n).fill(0);
|
|
646
|
+
for (let i = 0; i < n; i++) {
|
|
647
|
+
let s = 0;
|
|
648
|
+
for (let k = 0; k <= i; k++)
|
|
649
|
+
s += L[i][k] * z[k];
|
|
650
|
+
w[i] = s;
|
|
651
|
+
}
|
|
652
|
+
return w;
|
|
653
|
+
}
|
|
654
|
+
function requireCorrelation(rho, functionName) {
|
|
655
|
+
ensureFinite(rho, 'correlation', functionName);
|
|
656
|
+
if (rho < -1 || rho > 1) {
|
|
657
|
+
throw new InputError(`${functionName}: correlation must be in [-1, 1], got ${rho}.`, {
|
|
658
|
+
code: ErrorCode.InputOutOfRange,
|
|
659
|
+
context: { correlation: rho },
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
function validateSpread(input, functionName) {
|
|
664
|
+
requireArgumentObject(functionName, 'input', input);
|
|
665
|
+
ensurePositive(input.spot1, 'spot1', functionName);
|
|
666
|
+
ensurePositive(input.spot2, 'spot2', functionName);
|
|
667
|
+
ensureFinite(input.strike, 'strike', functionName);
|
|
668
|
+
ensurePositive(input.timeToExpiryYears, 'timeToExpiryYears', functionName);
|
|
669
|
+
ensurePositive(input.volatility1, 'volatility1', functionName);
|
|
670
|
+
ensurePositive(input.volatility2, 'volatility2', functionName);
|
|
671
|
+
ensureFinite(input.riskFreeRate, 'riskFreeRate', functionName);
|
|
672
|
+
requireCorrelation(input.correlation, functionName);
|
|
673
|
+
const q1 = input.dividendYield1 ?? 0;
|
|
674
|
+
const q2 = input.dividendYield2 ?? 0;
|
|
675
|
+
ensureFinite(q1, 'dividendYield1', functionName);
|
|
676
|
+
ensureFinite(q2, 'dividendYield2', functionName);
|
|
677
|
+
return { q1, q2 };
|
|
678
|
+
}
|
|
679
|
+
/** Kirk's approximation for a spread call/put (exact Margrabe when `K = 0`). */
|
|
680
|
+
function kirkSpread(input) {
|
|
681
|
+
const { type, spot1: S1, spot2: S2, strike: K, timeToExpiryYears: T, riskFreeRate: r, dividendYield1: q1, dividendYield2: q2, volatility1: v1, volatility2: v2, correlation: rho, } = input;
|
|
682
|
+
const F1 = S1 * Math.exp((r - q1) * T);
|
|
683
|
+
const F2 = S2 * Math.exp((r - q2) * T);
|
|
684
|
+
if (F2 + K <= 0) {
|
|
685
|
+
throw new InputError(`spread: Kirk's approximation requires F2 + K > 0 (got ${F2 + K}).`, {
|
|
686
|
+
code: ErrorCode.InputOutOfRange,
|
|
687
|
+
context: { forward2: F2, strike: K },
|
|
688
|
+
});
|
|
689
|
+
}
|
|
690
|
+
const disc = Math.exp(-r * T);
|
|
691
|
+
const a = F2 / (F2 + K);
|
|
692
|
+
const sk = Math.sqrt(Math.max(0, v1 * v1 - 2 * rho * v1 * v2 * a + v2 * v2 * a * a));
|
|
693
|
+
const sd = sk * Math.sqrt(T);
|
|
694
|
+
let call;
|
|
695
|
+
if (sd <= 0) {
|
|
696
|
+
call = disc * Math.max(F1 - (F2 + K), 0);
|
|
697
|
+
}
|
|
698
|
+
else {
|
|
699
|
+
const d1 = (Math.log(F1 / (F2 + K)) + 0.5 * sd * sd) / sd;
|
|
700
|
+
const d2 = d1 - sd;
|
|
701
|
+
call = disc * (F1 * N(d1) - (F2 + K) * N(d2));
|
|
702
|
+
}
|
|
703
|
+
// Spread put–call parity: C − P = disc·(F1 − F2 − K).
|
|
704
|
+
return type === 'call' ? call : call - disc * (F1 - F2 - K);
|
|
705
|
+
}
|
|
706
|
+
const SPREAD_PRICE_SPEC = specOf('spread.price#0');
|
|
707
|
+
const SPREAD_MC_INPUT_SPEC = specOf('spread.monteCarloPrice#0');
|
|
708
|
+
const SPREAD_MC_OPTIONS_SPEC = specOf('spread.monteCarloPrice#1');
|
|
709
|
+
const SPREAD_EXAMPLE = () => "spread.price({ type: 'call', spot1: 100, spot2: 95, strike: 5, timeToExpiryYears: 0.25, riskFreeRate: 0.04, volatility1: 0.2, volatility2: 0.25, correlation: 0.5 })";
|
|
710
|
+
export const spread = {
|
|
711
|
+
/** Kirk's-approximation analytic price of an option on `S1 − S2`. */
|
|
712
|
+
price(input) {
|
|
713
|
+
const functionName = 'spread.price';
|
|
714
|
+
validateClosedRequest(functionName, input, SPREAD_PRICE_SPEC, {
|
|
715
|
+
exampleCall: SPREAD_EXAMPLE,
|
|
716
|
+
});
|
|
717
|
+
const { type } = input;
|
|
718
|
+
const { q1, q2 } = validateSpread(input, functionName);
|
|
719
|
+
const value = kirkSpread({
|
|
720
|
+
type,
|
|
721
|
+
spot1: input.spot1,
|
|
722
|
+
spot2: input.spot2,
|
|
723
|
+
strike: input.strike,
|
|
724
|
+
timeToExpiryYears: input.timeToExpiryYears,
|
|
725
|
+
riskFreeRate: input.riskFreeRate,
|
|
726
|
+
dividendYield1: q1,
|
|
727
|
+
dividendYield2: q2,
|
|
728
|
+
volatility1: input.volatility1,
|
|
729
|
+
volatility2: input.volatility2,
|
|
730
|
+
correlation: input.correlation,
|
|
731
|
+
});
|
|
732
|
+
return {
|
|
733
|
+
value,
|
|
734
|
+
assumptions: assumptions(input.timeToExpiryYears, q1, 'spread-kirk', 'spread-kirk'),
|
|
735
|
+
diagnostics: {
|
|
736
|
+
engine: 'spread-kirk',
|
|
737
|
+
method: 'closed-form',
|
|
738
|
+
converged: Number.isFinite(value),
|
|
739
|
+
warnings: [],
|
|
740
|
+
},
|
|
741
|
+
};
|
|
742
|
+
},
|
|
743
|
+
/** Monte-Carlo price of the spread option (validator for, and generalization of, Kirk). */
|
|
744
|
+
monteCarloPrice(input, options) {
|
|
745
|
+
const functionName = 'spread.monteCarloPrice';
|
|
746
|
+
validateClosedRequest(functionName, input, SPREAD_MC_INPUT_SPEC, {
|
|
747
|
+
exampleCall: SPREAD_EXAMPLE,
|
|
748
|
+
});
|
|
749
|
+
validateClosedRequest(functionName, options, SPREAD_MC_OPTIONS_SPEC, {
|
|
750
|
+
exampleCall: SPREAD_EXAMPLE,
|
|
751
|
+
argumentName: 'options',
|
|
752
|
+
});
|
|
753
|
+
const { type } = input;
|
|
754
|
+
const { q1, q2 } = validateSpread(input, functionName);
|
|
755
|
+
const { spot1: S1, spot2: S2, strike: K, timeToExpiryYears: T, riskFreeRate: r, volatility1: v1, volatility2: v2, correlation: rho, } = input;
|
|
756
|
+
const df = Math.exp(-r * T);
|
|
757
|
+
const drift1 = (r - q1 - 0.5 * v1 * v1) * T;
|
|
758
|
+
const drift2 = (r - q2 - 0.5 * v2 * v2) * T;
|
|
759
|
+
const sq = Math.sqrt(T);
|
|
760
|
+
const payoff = (z) => {
|
|
761
|
+
const w1 = z[0];
|
|
762
|
+
const w2 = rho * z[0] + Math.sqrt(1 - rho * rho) * z[1];
|
|
763
|
+
const s1 = S1 * Math.exp(drift1 + v1 * sq * w1);
|
|
764
|
+
const s2 = S2 * Math.exp(drift2 + v2 * sq * w2);
|
|
765
|
+
const intrinsic = type === 'call' ? Math.max(s1 - s2 - K, 0) : Math.max(K - (s1 - s2), 0);
|
|
766
|
+
return df * intrinsic;
|
|
767
|
+
};
|
|
768
|
+
const est = monteCarloEstimate({
|
|
769
|
+
dimensions: 2,
|
|
770
|
+
payoff,
|
|
771
|
+
options,
|
|
772
|
+
controlVariate: undefined,
|
|
773
|
+
label: functionName,
|
|
774
|
+
});
|
|
775
|
+
return {
|
|
776
|
+
value: est.value,
|
|
777
|
+
assumptions: assumptions(T, q1, 'spread', 'spread-mc'),
|
|
778
|
+
diagnostics: {
|
|
779
|
+
engine: 'spread-mc',
|
|
780
|
+
method: `monte-carlo-${est.method}`,
|
|
781
|
+
converged: est.converged,
|
|
782
|
+
iterations: est.paths,
|
|
783
|
+
warnings: est.warnings,
|
|
784
|
+
},
|
|
785
|
+
monteCarlo: monteCarloStatistics(est),
|
|
786
|
+
};
|
|
787
|
+
},
|
|
788
|
+
};
|
|
789
|
+
const QUANTO_PRICE_SPEC = specOf('quanto.price#0');
|
|
790
|
+
const QUANTO_EXAMPLE = () => "quanto.price({ type: 'call', spot: 100, strike: 105, timeToExpiryYears: 0.25, domesticRate: 0.04, foreignRate: 0.02, volatility: 0.2, fxVolatility: 0.1, correlation: 0.5 })";
|
|
791
|
+
export const quanto = {
|
|
792
|
+
/**
|
|
793
|
+
* Quanto option paying `(S_foreign(T) − K)⁺` in domestic currency at a fixed FX rate. The asset's
|
|
794
|
+
* drift is adjusted by `−ρ·σ_S·σ_FX` (the quanto correction) and discounting is domestic.
|
|
795
|
+
*/
|
|
796
|
+
price(input) {
|
|
797
|
+
const functionName = 'quanto.price';
|
|
798
|
+
validateClosedRequest(functionName, input, QUANTO_PRICE_SPEC, {
|
|
799
|
+
exampleCall: QUANTO_EXAMPLE,
|
|
800
|
+
});
|
|
801
|
+
const { type } = input;
|
|
802
|
+
ensurePositive(input.spot, 'spot', functionName);
|
|
803
|
+
ensurePositive(input.strike, 'strike', functionName);
|
|
804
|
+
ensurePositive(input.timeToExpiryYears, 'timeToExpiryYears', functionName);
|
|
805
|
+
ensurePositive(input.volatility, 'volatility', functionName);
|
|
806
|
+
ensureNonNegativeVolatility(input.fxVolatility, 'fxVolatility', functionName);
|
|
807
|
+
ensureFinite(input.domesticRate, 'domesticRate', functionName);
|
|
808
|
+
ensureFinite(input.foreignRate, 'foreignRate', functionName);
|
|
809
|
+
requireCorrelation(input.correlation, functionName);
|
|
810
|
+
const q = input.dividendYield ?? 0;
|
|
811
|
+
ensureFinite(q, 'dividendYield', functionName);
|
|
812
|
+
const { spot: S, strike: K, timeToExpiryYears: T, volatility: sigma } = input;
|
|
813
|
+
const muQ = input.foreignRate - q - input.correlation * sigma * input.fxVolatility;
|
|
814
|
+
const F = S * Math.exp(muQ * T);
|
|
815
|
+
const sd = sigma * Math.sqrt(T);
|
|
816
|
+
const disc = Math.exp(-input.domesticRate * T);
|
|
817
|
+
const d1 = (Math.log(F / K) + 0.5 * sd * sd) / sd;
|
|
818
|
+
const d2 = d1 - sd;
|
|
819
|
+
const value = type === 'call' ? disc * (F * N(d1) - K * N(d2)) : disc * (K * N(-d2) - F * N(-d1));
|
|
820
|
+
return {
|
|
821
|
+
value,
|
|
822
|
+
assumptions: assumptions(T, q, 'quanto', 'quanto'),
|
|
823
|
+
diagnostics: {
|
|
824
|
+
engine: 'quanto',
|
|
825
|
+
method: 'closed-form',
|
|
826
|
+
converged: Number.isFinite(value),
|
|
827
|
+
warnings: [],
|
|
828
|
+
},
|
|
829
|
+
};
|
|
830
|
+
},
|
|
831
|
+
};
|
|
832
|
+
function ensureNonNegativeVolatility(v, field, functionName) {
|
|
833
|
+
ensureFinite(v, field, functionName);
|
|
834
|
+
if (v < 0) {
|
|
835
|
+
throw new InputError(`${functionName}: ${field} must be ≥ 0, got ${v}.`, {
|
|
836
|
+
code: ErrorCode.InputOutOfRange,
|
|
837
|
+
context: { [field]: v },
|
|
838
|
+
});
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* Validate a correlation matrix: square, symmetric, unit diagonal, entries in [−1, 1], and positive
|
|
843
|
+
* definite.
|
|
844
|
+
*
|
|
845
|
+
* The Monte-Carlo branch got this for free — `cholesky` refuses a non-PD matrix — while the analytic
|
|
846
|
+
* (Levy moment-matched) branch only ever READ the entries, so `ρ = 1.8` produced a confident price
|
|
847
|
+
* from an impossible market, and an asymmetric or non-PSD matrix priced a covariance no asset pair
|
|
848
|
+
* could have. One validator now runs on every multi-asset entry point.
|
|
849
|
+
*/
|
|
850
|
+
function requireCorrelationMatrix(matrix, size, functionName) {
|
|
851
|
+
const bad = (message, context) => {
|
|
852
|
+
throw new InputError(`${functionName}: ${message}`, {
|
|
853
|
+
code: ErrorCode.InputOutOfRange,
|
|
854
|
+
context,
|
|
855
|
+
});
|
|
856
|
+
};
|
|
857
|
+
for (let i = 0; i < size; i++) {
|
|
858
|
+
for (let j = 0; j < size; j++) {
|
|
859
|
+
const value = matrix[i][j];
|
|
860
|
+
ensureFinite(value, `correlation[${i}][${j}]`, functionName);
|
|
861
|
+
if (i === j && Math.abs(value - 1) > 1e-12) {
|
|
862
|
+
bad(`correlation[${i}][${i}] must be exactly 1 (an asset correlates perfectly with itself), got ${value}.`, {
|
|
863
|
+
row: i,
|
|
864
|
+
value,
|
|
865
|
+
});
|
|
866
|
+
}
|
|
867
|
+
if (value < -1 || value > 1) {
|
|
868
|
+
bad(`correlation[${i}][${j}] = ${value} is outside [−1, 1] — a correlation is a normalized covariance; ` +
|
|
869
|
+
'did you pass a covariance matrix?', { row: i, column: j, value });
|
|
870
|
+
}
|
|
871
|
+
const mirrored = matrix[j][i];
|
|
872
|
+
if (i !== j && Math.abs(value - mirrored) > 1e-12) {
|
|
873
|
+
bad(`correlation is not symmetric: [${i}][${j}] = ${value} but [${j}][${i}] = ${mirrored}.`, { row: i, column: j, value, mirrored });
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
try {
|
|
878
|
+
// The same positive-definiteness test the simulation path applies, so both branches accept
|
|
879
|
+
// exactly the same matrices (and reject the same ones with the same code).
|
|
880
|
+
cholesky(matrix);
|
|
881
|
+
}
|
|
882
|
+
catch (error) {
|
|
883
|
+
throw new InputError(`${functionName}: correlation is not positive definite, so it describes no possible joint ` +
|
|
884
|
+
'distribution (some portfolio of these assets would have negative variance). Repair it with ' +
|
|
885
|
+
'nearestCorrelation / nearestPsd from @insiderfinance/totalfinance/math, or reduce the number of assets.', {
|
|
886
|
+
code: ErrorCode.LinalgNotPositiveDefinite,
|
|
887
|
+
context: { function: functionName, size },
|
|
888
|
+
cause: error,
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
}
|
|
892
|
+
function validateMultiAsset(input, functionName) {
|
|
893
|
+
requireArgumentObject(functionName, 'input', input);
|
|
894
|
+
// Container-shape first: a wrong key (`volatilities: [...]`, `sigma: [...]`) must teach the real slot
|
|
895
|
+
// names by echoing what the caller DID pass, not crash on `undefined.length`.
|
|
896
|
+
if (!Array.isArray(input.spots) ||
|
|
897
|
+
!Array.isArray(input.volatilities) ||
|
|
898
|
+
!Array.isArray(input.correlation)) {
|
|
899
|
+
throw wrongShapeError(functionName, 'input with spots: number[], volatilities: number[], and correlation: number[][] (plus strike, t, rate)', input);
|
|
900
|
+
}
|
|
901
|
+
const n = input.spots.length;
|
|
902
|
+
if (n < 2 || input.volatilities.length !== n || input.correlation.length !== n) {
|
|
903
|
+
throw new InputError(`${functionName}: need ≥ 2 assets with matching volatilities and an n×n correlation.`, {
|
|
904
|
+
code: ErrorCode.InputOutOfRange,
|
|
905
|
+
context: {
|
|
906
|
+
spots: n,
|
|
907
|
+
volatilities: input.volatilities.length,
|
|
908
|
+
correlation: input.correlation.length,
|
|
909
|
+
},
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
ensurePositive(input.strike, 'strike', functionName);
|
|
913
|
+
ensurePositive(input.timeToExpiryYears, 'timeToExpiryYears', functionName);
|
|
914
|
+
ensureFinite(input.riskFreeRate, 'riskFreeRate', functionName);
|
|
915
|
+
for (let i = 0; i < n; i++) {
|
|
916
|
+
ensurePositive(input.spots[i], `spots[${i}]`, functionName);
|
|
917
|
+
ensurePositive(input.volatilities[i], `volatilities[${i}]`, functionName);
|
|
918
|
+
if (!Array.isArray(input.correlation[i]) || input.correlation[i].length !== n) {
|
|
919
|
+
throw new InputError(`${functionName}: correlation row ${i} must have length ${n}.`, {
|
|
920
|
+
code: ErrorCode.InputOutOfRange,
|
|
921
|
+
context: { row: i },
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
requireCorrelationMatrix(input.correlation, n, functionName);
|
|
926
|
+
const q = input.dividendYields ?? new Array(n).fill(0);
|
|
927
|
+
if (q.length !== n) {
|
|
928
|
+
throw new InputError(`${functionName}: dividendYields must have length ${n}.`, {
|
|
929
|
+
code: ErrorCode.InputOutOfRange,
|
|
930
|
+
context: { got: q.length, expected: n },
|
|
931
|
+
});
|
|
932
|
+
}
|
|
933
|
+
for (let i = 0; i < n; i++)
|
|
934
|
+
ensureFinite(q[i], `dividendYields[${i}]`, functionName);
|
|
935
|
+
return q;
|
|
936
|
+
}
|
|
937
|
+
const BASKET_APPROXIMATE_SPEC = specOf('basket.approximatePrice#0');
|
|
938
|
+
const BASKET_MC_INPUT_SPEC = specOf('basket.monteCarloPrice#0');
|
|
939
|
+
const BASKET_MC_OPTIONS_SPEC = specOf('basket.monteCarloPrice#1');
|
|
940
|
+
const BASKET_EXAMPLE = () => "basket.approximatePrice({ type: 'call', spots: [100, 95], weights: [0.5, 0.5], strike: 100, timeToExpiryYears: 0.25, riskFreeRate: 0.04, volatilities: [0.2, 0.25], correlation: [[1, 0.5], [0.5, 1]] })";
|
|
941
|
+
export const basket = {
|
|
942
|
+
/** Levy moment-matched lognormal approximation (closed form) for a weighted-basket option. */
|
|
943
|
+
approximatePrice(input) {
|
|
944
|
+
const functionName = 'basket.approximatePrice';
|
|
945
|
+
validateClosedRequest(functionName, input, BASKET_APPROXIMATE_SPEC, {
|
|
946
|
+
exampleCall: BASKET_EXAMPLE,
|
|
947
|
+
});
|
|
948
|
+
const { type } = input;
|
|
949
|
+
const q = validateMultiAsset(input, functionName);
|
|
950
|
+
const n = input.spots.length;
|
|
951
|
+
// A missing/mistyped weights slot must teach its name, not crash on `.length`.
|
|
952
|
+
requireArgumentArray(functionName, 'input.weights', input.weights);
|
|
953
|
+
if (input.weights.length !== n) {
|
|
954
|
+
throw new InputError(`${functionName}: weights must have length ${n}.`, {
|
|
955
|
+
code: ErrorCode.InputOutOfRange,
|
|
956
|
+
context: { got: input.weights.length, expected: n },
|
|
957
|
+
});
|
|
958
|
+
}
|
|
959
|
+
const { timeToExpiryYears: T, riskFreeRate: r, strike: K } = input;
|
|
960
|
+
const F = input.spots.map((s, i) => s * Math.exp((r - q[i]) * T));
|
|
961
|
+
let M1 = 0;
|
|
962
|
+
for (let i = 0; i < n; i++)
|
|
963
|
+
M1 += input.weights[i] * F[i];
|
|
964
|
+
let M2 = 0;
|
|
965
|
+
for (let i = 0; i < n; i++) {
|
|
966
|
+
for (let j = 0; j < n; j++) {
|
|
967
|
+
const covariance = Math.exp(input.correlation[i][j] * input.volatilities[i] * input.volatilities[j] * T);
|
|
968
|
+
M2 += input.weights[i] * input.weights[j] * F[i] * F[j] * covariance;
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
if (M1 <= 0) {
|
|
972
|
+
throw new InputError(`${functionName}: the moment-matched forward basket must be positive (got ${M1}).`, {
|
|
973
|
+
code: ErrorCode.InputOutOfRange,
|
|
974
|
+
context: { forwardBasket: M1 },
|
|
975
|
+
});
|
|
976
|
+
}
|
|
977
|
+
const sigmaB = Math.sqrt(Math.log(M2 / (M1 * M1)) / T);
|
|
978
|
+
const sd = sigmaB * Math.sqrt(T);
|
|
979
|
+
const disc = Math.exp(-r * T);
|
|
980
|
+
let call;
|
|
981
|
+
if (sd <= 0) {
|
|
982
|
+
call = disc * Math.max(M1 - K, 0);
|
|
983
|
+
}
|
|
984
|
+
else {
|
|
985
|
+
const d1 = (Math.log(M1 / K) + 0.5 * sd * sd) / sd;
|
|
986
|
+
call = disc * (M1 * N(d1) - K * N(d1 - sd));
|
|
987
|
+
}
|
|
988
|
+
const value = type === 'call' ? call : call - disc * (M1 - K);
|
|
989
|
+
return {
|
|
990
|
+
value,
|
|
991
|
+
assumptions: assumptions(T, 0, 'basket-levy', 'basket-levy'),
|
|
992
|
+
diagnostics: {
|
|
993
|
+
engine: 'basket-levy',
|
|
994
|
+
method: 'closed-form',
|
|
995
|
+
converged: Number.isFinite(value),
|
|
996
|
+
warnings: [],
|
|
997
|
+
},
|
|
998
|
+
};
|
|
999
|
+
},
|
|
1000
|
+
/** Monte-Carlo price of a weighted-basket option (exact; corroborates the Levy approximation). */
|
|
1001
|
+
monteCarloPrice(input, options) {
|
|
1002
|
+
const functionName = 'basket.monteCarloPrice';
|
|
1003
|
+
validateClosedRequest(functionName, input, BASKET_MC_INPUT_SPEC, {
|
|
1004
|
+
exampleCall: BASKET_EXAMPLE,
|
|
1005
|
+
});
|
|
1006
|
+
validateClosedRequest(functionName, options, BASKET_MC_OPTIONS_SPEC, {
|
|
1007
|
+
exampleCall: BASKET_EXAMPLE,
|
|
1008
|
+
argumentName: 'options',
|
|
1009
|
+
});
|
|
1010
|
+
const { type } = input;
|
|
1011
|
+
const q = validateMultiAsset(input, functionName);
|
|
1012
|
+
const n = input.spots.length;
|
|
1013
|
+
requireArgumentArray(functionName, 'input.weights', input.weights);
|
|
1014
|
+
if (input.weights.length !== n) {
|
|
1015
|
+
throw new InputError(`${functionName}: weights must have length ${n}.`, {
|
|
1016
|
+
code: ErrorCode.InputOutOfRange,
|
|
1017
|
+
context: { got: input.weights.length, expected: n },
|
|
1018
|
+
});
|
|
1019
|
+
}
|
|
1020
|
+
const { timeToExpiryYears: T, riskFreeRate: r, strike: K } = input;
|
|
1021
|
+
const L = cholesky(input.correlation);
|
|
1022
|
+
const df = Math.exp(-r * T);
|
|
1023
|
+
const sq = Math.sqrt(T);
|
|
1024
|
+
const drift = input.spots.map((_, i) => (r - q[i] - 0.5 * input.volatilities[i] * input.volatilities[i]) * T);
|
|
1025
|
+
const payoff = (z) => {
|
|
1026
|
+
const w = correlatedDraw(L, z);
|
|
1027
|
+
let b = 0;
|
|
1028
|
+
for (let i = 0; i < n; i++) {
|
|
1029
|
+
b +=
|
|
1030
|
+
input.weights[i] *
|
|
1031
|
+
input.spots[i] *
|
|
1032
|
+
Math.exp(drift[i] + input.volatilities[i] * sq * w[i]);
|
|
1033
|
+
}
|
|
1034
|
+
return df * (type === 'call' ? Math.max(b - K, 0) : Math.max(K - b, 0));
|
|
1035
|
+
};
|
|
1036
|
+
const est = monteCarloEstimate({
|
|
1037
|
+
dimensions: n,
|
|
1038
|
+
payoff,
|
|
1039
|
+
options,
|
|
1040
|
+
controlVariate: undefined,
|
|
1041
|
+
label: functionName,
|
|
1042
|
+
});
|
|
1043
|
+
return {
|
|
1044
|
+
value: est.value,
|
|
1045
|
+
assumptions: assumptions(T, 0, 'basket', 'basket-mc'),
|
|
1046
|
+
diagnostics: {
|
|
1047
|
+
engine: 'basket-mc',
|
|
1048
|
+
method: `monte-carlo-${est.method}`,
|
|
1049
|
+
converged: est.converged,
|
|
1050
|
+
iterations: est.paths,
|
|
1051
|
+
warnings: est.warnings,
|
|
1052
|
+
},
|
|
1053
|
+
monteCarlo: monteCarloStatistics(est),
|
|
1054
|
+
};
|
|
1055
|
+
},
|
|
1056
|
+
};
|
|
1057
|
+
const RAINBOW_MC_INPUT_SPEC = specOf('rainbow.monteCarloPrice#0');
|
|
1058
|
+
const RAINBOW_MC_OPTIONS_SPEC = specOf('rainbow.monteCarloPrice#1');
|
|
1059
|
+
const RAINBOW_EXAMPLE = () => "rainbow.monteCarloPrice({ type: 'call', kind: 'max', spots: [100, 95], strike: 100, timeToExpiryYears: 0.25, riskFreeRate: 0.04, volatilities: [0.2, 0.25], correlation: [[1, 0.5], [0.5, 1]] }, { paths: 20000, seed: 42 })";
|
|
1060
|
+
export const rainbow = {
|
|
1061
|
+
/** Monte-Carlo price of a rainbow option on the max or min of several assets. */
|
|
1062
|
+
monteCarloPrice(input, options) {
|
|
1063
|
+
const functionName = 'rainbow.monteCarloPrice';
|
|
1064
|
+
validateClosedRequest(functionName, input, RAINBOW_MC_INPUT_SPEC, {
|
|
1065
|
+
exampleCall: RAINBOW_EXAMPLE,
|
|
1066
|
+
});
|
|
1067
|
+
validateClosedRequest(functionName, options, RAINBOW_MC_OPTIONS_SPEC, {
|
|
1068
|
+
exampleCall: RAINBOW_EXAMPLE,
|
|
1069
|
+
argumentName: 'options',
|
|
1070
|
+
});
|
|
1071
|
+
const { type, kind } = input;
|
|
1072
|
+
const q = validateMultiAsset(input, functionName);
|
|
1073
|
+
const n = input.spots.length;
|
|
1074
|
+
const { timeToExpiryYears: T, riskFreeRate: r, strike: K } = input;
|
|
1075
|
+
const L = cholesky(input.correlation);
|
|
1076
|
+
const df = Math.exp(-r * T);
|
|
1077
|
+
const sq = Math.sqrt(T);
|
|
1078
|
+
const drift = input.spots.map((_, i) => (r - q[i] - 0.5 * input.volatilities[i] * input.volatilities[i]) * T);
|
|
1079
|
+
const payoff = (z) => {
|
|
1080
|
+
const w = correlatedDraw(L, z);
|
|
1081
|
+
let best = kind === 'max' ? -Infinity : Infinity;
|
|
1082
|
+
for (let i = 0; i < n; i++) {
|
|
1083
|
+
const si = input.spots[i] * Math.exp(drift[i] + input.volatilities[i] * sq * w[i]);
|
|
1084
|
+
best = kind === 'max' ? Math.max(best, si) : Math.min(best, si);
|
|
1085
|
+
}
|
|
1086
|
+
return df * (type === 'call' ? Math.max(best - K, 0) : Math.max(K - best, 0));
|
|
1087
|
+
};
|
|
1088
|
+
const est = monteCarloEstimate({
|
|
1089
|
+
dimensions: n,
|
|
1090
|
+
payoff,
|
|
1091
|
+
options,
|
|
1092
|
+
controlVariate: undefined,
|
|
1093
|
+
label: functionName,
|
|
1094
|
+
});
|
|
1095
|
+
return {
|
|
1096
|
+
value: est.value,
|
|
1097
|
+
assumptions: assumptions(T, 0, `rainbow-${kind}`, `rainbow-${kind}-mc`),
|
|
1098
|
+
diagnostics: {
|
|
1099
|
+
engine: `rainbow-${kind}-mc`,
|
|
1100
|
+
method: `monte-carlo-${est.method}`,
|
|
1101
|
+
converged: est.converged,
|
|
1102
|
+
iterations: est.paths,
|
|
1103
|
+
warnings: est.warnings,
|
|
1104
|
+
},
|
|
1105
|
+
monteCarlo: monteCarloStatistics(est),
|
|
1106
|
+
};
|
|
1107
|
+
},
|
|
1108
|
+
};
|
|
1109
|
+
const AUTOCALLABLE_MC_INPUT_SPEC = specOf('autocallable.monteCarloPrice#0');
|
|
1110
|
+
const AUTOCALLABLE_MC_OPTIONS_SPEC = specOf('autocallable.monteCarloPrice#1');
|
|
1111
|
+
const AUTOCALLABLE_EXAMPLE = () => 'autocallable.monteCarloPrice({ spot: 100, observationTimes: [0.5, 1], riskFreeRate: 0.04, volatility: 0.2, autocallBarrier: 105, couponRate: 0.03, knockInBarrier: 70 }, { paths: 20000, seed: 42 })';
|
|
1112
|
+
export const autocallable = {
|
|
1113
|
+
/**
|
|
1114
|
+
* Monte-Carlo price of a canonical autocallable note: on each observation date the note redeems at
|
|
1115
|
+
* `notional·(1 + couponRate·periods)` if the spot is at or above `autocallBarrier`; if it never does,
|
|
1116
|
+
* at maturity it returns the notional when `S(T) ≥ knockInBarrier`, else the loss-bearing
|
|
1117
|
+
* `notional·S(T)/S(0)`. The payoff is discounted at the per-path redemption time.
|
|
1118
|
+
*/
|
|
1119
|
+
monteCarloPrice(input, options) {
|
|
1120
|
+
const functionName = 'autocallable.monteCarloPrice';
|
|
1121
|
+
validateClosedRequest(functionName, input, AUTOCALLABLE_MC_INPUT_SPEC, {
|
|
1122
|
+
exampleCall: AUTOCALLABLE_EXAMPLE,
|
|
1123
|
+
});
|
|
1124
|
+
validateClosedRequest(functionName, options, AUTOCALLABLE_MC_OPTIONS_SPEC, {
|
|
1125
|
+
exampleCall: AUTOCALLABLE_EXAMPLE,
|
|
1126
|
+
argumentName: 'options',
|
|
1127
|
+
});
|
|
1128
|
+
ensurePositive(input.spot, 'spot', functionName);
|
|
1129
|
+
ensurePositive(input.volatility, 'volatility', functionName);
|
|
1130
|
+
ensureFinite(input.riskFreeRate, 'riskFreeRate', functionName);
|
|
1131
|
+
ensurePositive(input.autocallBarrier, 'autocallBarrier', functionName);
|
|
1132
|
+
ensurePositive(input.knockInBarrier, 'knockInBarrier', functionName);
|
|
1133
|
+
ensureFinite(input.couponRate, 'couponRate', functionName);
|
|
1134
|
+
const q = input.dividendYield ?? 0;
|
|
1135
|
+
ensureFinite(q, 'dividendYield', functionName);
|
|
1136
|
+
// A missing/mistyped schedule slot must teach its name, not crash on `.length`.
|
|
1137
|
+
requireArgumentArray(functionName, 'input.observationTimes', input.observationTimes);
|
|
1138
|
+
const obs = input.observationTimes;
|
|
1139
|
+
const n = obs.length;
|
|
1140
|
+
if (n < 1) {
|
|
1141
|
+
throw new InputError(`${functionName}: at least one observation time is required.`, {
|
|
1142
|
+
code: ErrorCode.InputOutOfRange,
|
|
1143
|
+
context: { observations: n },
|
|
1144
|
+
});
|
|
1145
|
+
}
|
|
1146
|
+
for (let i = 0; i < n; i++) {
|
|
1147
|
+
ensurePositive(obs[i], `observationTimes[${i}]`, functionName);
|
|
1148
|
+
if (i > 0 && obs[i] <= obs[i - 1]) {
|
|
1149
|
+
throw new InputError(`${functionName}: observationTimes must be strictly increasing.`, {
|
|
1150
|
+
code: ErrorCode.InputOutOfRange,
|
|
1151
|
+
context: { index: i },
|
|
1152
|
+
});
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
const notional = input.notional ?? 100;
|
|
1156
|
+
const { spot: S0, riskFreeRate: r, volatility: sigma } = input;
|
|
1157
|
+
const timeStepYears = obs.map((t, i) => t - (i === 0 ? 0 : obs[i - 1]));
|
|
1158
|
+
const sqdt = timeStepYears.map((d) => Math.sqrt(d));
|
|
1159
|
+
const drift = timeStepYears.map((d) => (r - q - 0.5 * sigma * sigma) * d);
|
|
1160
|
+
const T = obs[n - 1];
|
|
1161
|
+
const payoff = (z) => {
|
|
1162
|
+
let logS = Math.log(S0);
|
|
1163
|
+
for (let i = 0; i < n; i++) {
|
|
1164
|
+
logS += drift[i] + sigma * sqdt[i] * z[i];
|
|
1165
|
+
const s = Math.exp(logS);
|
|
1166
|
+
if (s >= input.autocallBarrier) {
|
|
1167
|
+
return notional * (1 + input.couponRate * (i + 1)) * Math.exp(-r * obs[i]);
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
const sT = Math.exp(logS);
|
|
1171
|
+
const redemption = sT >= input.knockInBarrier ? notional : notional * (sT / S0);
|
|
1172
|
+
return redemption * Math.exp(-r * T);
|
|
1173
|
+
};
|
|
1174
|
+
const est = monteCarloEstimate({
|
|
1175
|
+
dimensions: n,
|
|
1176
|
+
payoff,
|
|
1177
|
+
options,
|
|
1178
|
+
controlVariate: undefined,
|
|
1179
|
+
label: functionName,
|
|
1180
|
+
});
|
|
1181
|
+
return {
|
|
1182
|
+
value: est.value,
|
|
1183
|
+
assumptions: assumptions(T, q, 'autocallable', 'autocallable-mc'),
|
|
1184
|
+
diagnostics: {
|
|
1185
|
+
engine: 'autocallable-mc',
|
|
1186
|
+
method: `monte-carlo-${est.method}`,
|
|
1187
|
+
converged: est.converged,
|
|
1188
|
+
iterations: est.paths,
|
|
1189
|
+
warnings: est.warnings,
|
|
1190
|
+
},
|
|
1191
|
+
monteCarlo: monteCarloStatistics(est),
|
|
1192
|
+
};
|
|
1193
|
+
},
|
|
1194
|
+
};
|
|
1195
|
+
// ───────────────────────── variance & volatility swaps ─────────────────────────
|
|
1196
|
+
const VARIANCE_SWAP_HESTON_SPEC = specOf('varianceSwap.hestonFairVariance#0');
|
|
1197
|
+
const VARIANCE_SWAP_VALUE_SPEC = specOf('varianceSwap.value#0');
|
|
1198
|
+
const VARIANCE_SWAP_HESTON_EXAMPLE = () => 'varianceSwap.hestonFairVariance({ v0: 0.04, kappa: 2, theta: 0.05 }, 0.25)';
|
|
1199
|
+
const VARIANCE_SWAP_VALUE_EXAMPLE = () => 'varianceSwap.value({ realizedVariance: 0.05, strikeVariance: 0.04, riskFreeRate: 0.04, timeToExpiryYears: 0.25 })';
|
|
1200
|
+
export const varianceSwap = {
|
|
1201
|
+
/**
|
|
1202
|
+
* Fair variance strike under Heston: `θ + (v₀ − θ)·(1 − e^{−κT})/(κT)`. Depends only on the
|
|
1203
|
+
* mean-reversion `κ`, long-run variance `θ`, and initial variance `v₀` (not on vol-of-vol/ρ).
|
|
1204
|
+
*/
|
|
1205
|
+
hestonFairVariance(parameters, timeToExpiryYears) {
|
|
1206
|
+
const functionName = 'varianceSwap.hestonFairVariance';
|
|
1207
|
+
validateClosedRequest(functionName, parameters, VARIANCE_SWAP_HESTON_SPEC, {
|
|
1208
|
+
exampleCall: VARIANCE_SWAP_HESTON_EXAMPLE,
|
|
1209
|
+
argumentName: 'parameters',
|
|
1210
|
+
});
|
|
1211
|
+
ensureNonNegativeVolatility(parameters.v0, 'v0', functionName);
|
|
1212
|
+
ensurePositive(parameters.kappa, 'kappa', functionName);
|
|
1213
|
+
ensureNonNegativeVolatility(parameters.theta, 'theta', functionName);
|
|
1214
|
+
ensurePositive(timeToExpiryYears, 'timeToExpiryYears', functionName);
|
|
1215
|
+
return (parameters.theta +
|
|
1216
|
+
((parameters.v0 - parameters.theta) * (1 - Math.exp(-parameters.kappa * timeToExpiryYears))) /
|
|
1217
|
+
(parameters.kappa * timeToExpiryYears));
|
|
1218
|
+
},
|
|
1219
|
+
/** Present value of a variance swap: `e^{−rT}·varianceNotional·(realizedVariance − strikeVariance)`. */
|
|
1220
|
+
value(input) {
|
|
1221
|
+
const functionName = 'varianceSwap.value';
|
|
1222
|
+
validateClosedRequest(functionName, input, VARIANCE_SWAP_VALUE_SPEC, {
|
|
1223
|
+
exampleCall: VARIANCE_SWAP_VALUE_EXAMPLE,
|
|
1224
|
+
});
|
|
1225
|
+
ensureNonNegativeVolatility(input.realizedVariance, 'realizedVariance', functionName);
|
|
1226
|
+
ensureNonNegativeVolatility(input.strikeVariance, 'strikeVariance', functionName);
|
|
1227
|
+
ensureFinite(input.riskFreeRate, 'riskFreeRate', functionName);
|
|
1228
|
+
ensurePositive(input.timeToExpiryYears, 'timeToExpiryYears', functionName);
|
|
1229
|
+
const notional = input.varianceNotional ?? 1;
|
|
1230
|
+
// `?? 1` only substitutes for null/undefined, so an explicit NaN would flow straight through.
|
|
1231
|
+
ensureFinite(notional, 'varianceNotional', functionName);
|
|
1232
|
+
return (Math.exp(-input.riskFreeRate * input.timeToExpiryYears) *
|
|
1233
|
+
notional *
|
|
1234
|
+
(input.realizedVariance - input.strikeVariance));
|
|
1235
|
+
},
|
|
1236
|
+
};
|
|
1237
|
+
const VOLATILITY_SWAP_FAIR_VOLATILITY_SPEC = specOf('volatilitySwap.approximateFairVolatility#0');
|
|
1238
|
+
const VOLATILITY_SWAP_EXAMPLE = () => 'volatilitySwap.approximateFairVolatility({ fairVariance: 0.04 })';
|
|
1239
|
+
export const volatilitySwap = {
|
|
1240
|
+
/**
|
|
1241
|
+
* Brockhaus–Long convexity-adjusted fair vol:
|
|
1242
|
+
* `K_vol ≈ √K_var·(1 − Var[realized variance]/(8·K_var²))`. With no variance-of-variance it reduces
|
|
1243
|
+
* to `√K_var`; the adjustment captures the (downward) Jensen gap between √E[var] and E[√var].
|
|
1244
|
+
*/
|
|
1245
|
+
approximateFairVolatility(input) {
|
|
1246
|
+
const functionName = 'volatilitySwap.approximateFairVolatility';
|
|
1247
|
+
validateClosedRequest(functionName, input, VOLATILITY_SWAP_FAIR_VOLATILITY_SPEC, {
|
|
1248
|
+
exampleCall: VOLATILITY_SWAP_EXAMPLE,
|
|
1249
|
+
});
|
|
1250
|
+
ensurePositive(input.fairVariance, 'fairVariance', functionName);
|
|
1251
|
+
const varVar = input.varianceOfVariance ?? 0;
|
|
1252
|
+
ensureNonNegativeVolatility(varVar, 'varianceOfVariance', functionName);
|
|
1253
|
+
// The Brockhaus–Long convexity term `varVar/(8·K_var²)` is a *small* second-order correction; once
|
|
1254
|
+
// it reaches 1 the formula would return a ≤0 "fair vol", which is meaningless. Refuse rather than
|
|
1255
|
+
// emit a negative volatility — the caller must supply a smaller varVar or price the swap directly.
|
|
1256
|
+
const secondOrder = varVar / (8 * input.fairVariance * input.fairVariance);
|
|
1257
|
+
if (secondOrder >= 1) {
|
|
1258
|
+
throw new InputError(`${functionName}: varianceOfVariance ${varVar} is too large relative to fairVariance² — the Brockhaus–Long approximation leaves its valid region (convexity correction ${1 - secondOrder} ≤ 0).`, {
|
|
1259
|
+
code: ErrorCode.InputOutOfRange,
|
|
1260
|
+
context: {
|
|
1261
|
+
fairVariance: input.fairVariance,
|
|
1262
|
+
varianceOfVariance: varVar,
|
|
1263
|
+
correction: 1 - secondOrder,
|
|
1264
|
+
},
|
|
1265
|
+
});
|
|
1266
|
+
}
|
|
1267
|
+
return Math.sqrt(input.fairVariance) * (1 - secondOrder);
|
|
1268
|
+
},
|
|
1269
|
+
};
|
|
1270
|
+
function validateDigital(input, functionName) {
|
|
1271
|
+
requireArgumentObject(functionName, 'input', input);
|
|
1272
|
+
ensurePositive(input.spot, 'spot', functionName);
|
|
1273
|
+
ensurePositive(input.strike, 'strike', functionName);
|
|
1274
|
+
ensurePositive(input.timeToExpiryYears, 'timeToExpiryYears', functionName);
|
|
1275
|
+
ensurePositive(input.volatility, 'volatility', functionName);
|
|
1276
|
+
ensureFinite(input.riskFreeRate, 'riskFreeRate', functionName);
|
|
1277
|
+
const q = input.dividendYield ?? 0;
|
|
1278
|
+
ensureFinite(q, 'dividendYield', functionName);
|
|
1279
|
+
const cash = input.cash ?? 1;
|
|
1280
|
+
ensureFinite(cash, 'cash', functionName);
|
|
1281
|
+
return { q, cash };
|
|
1282
|
+
}
|
|
1283
|
+
/** Cash-or-nothing (`Q·e^{−rT}·N(±d₂)`) / asset-or-nothing (`S·e^{−qT}·N(±d₁)`) European binary. */
|
|
1284
|
+
function digitalAnalytic(input) {
|
|
1285
|
+
const { type, kind, spot: S, strike: K, timeToExpiryYears: T, riskFreeRate: r, dividendYield: q, volatility: sigma, cash, } = input;
|
|
1286
|
+
const b = r - q;
|
|
1287
|
+
const vol = sigma * Math.sqrt(T);
|
|
1288
|
+
const d1 = (Math.log(S / K) + (b + 0.5 * sigma * sigma) * T) / vol;
|
|
1289
|
+
const d2 = d1 - vol;
|
|
1290
|
+
const phi = type === 'call' ? 1 : -1;
|
|
1291
|
+
return kind === 'cash-or-nothing'
|
|
1292
|
+
? cash * Math.exp(-r * T) * N(phi * d2)
|
|
1293
|
+
: S * Math.exp(-q * T) * N(phi * d1);
|
|
1294
|
+
}
|
|
1295
|
+
const DIGITAL_PRICE_SPEC = specOf('digital.price#0');
|
|
1296
|
+
const DIGITAL_MC_INPUT_SPEC = specOf('digital.monteCarloPrice#0');
|
|
1297
|
+
const DIGITAL_MC_OPTIONS_SPEC = specOf('digital.monteCarloPrice#1');
|
|
1298
|
+
const DIGITAL_GREEKS_SPEC = specOf('digital.greeks#0');
|
|
1299
|
+
const DIGITAL_EXTENDED_GREEKS_SPEC = specOf('digital.extendedGreeks#0');
|
|
1300
|
+
const DIGITAL_EXAMPLE = () => "digital.price({ type: 'call', kind: 'cash-or-nothing', spot: 100, strike: 105, timeToExpiryYears: 0.25, riskFreeRate: 0.04, volatility: 0.2 })";
|
|
1301
|
+
export const digital = {
|
|
1302
|
+
/** European binary price (closed form). A vanilla call ≡ asset-or-nothing call − K·cash-or-nothing call. */
|
|
1303
|
+
price(input) {
|
|
1304
|
+
const functionName = 'digital.price';
|
|
1305
|
+
validateClosedRequest(functionName, input, DIGITAL_PRICE_SPEC, {
|
|
1306
|
+
exampleCall: DIGITAL_EXAMPLE,
|
|
1307
|
+
});
|
|
1308
|
+
const { type, kind } = input;
|
|
1309
|
+
const { q, cash } = validateDigital(input, functionName);
|
|
1310
|
+
const value = digitalAnalytic({
|
|
1311
|
+
type,
|
|
1312
|
+
kind,
|
|
1313
|
+
spot: input.spot,
|
|
1314
|
+
strike: input.strike,
|
|
1315
|
+
timeToExpiryYears: input.timeToExpiryYears,
|
|
1316
|
+
riskFreeRate: input.riskFreeRate,
|
|
1317
|
+
dividendYield: q,
|
|
1318
|
+
volatility: input.volatility,
|
|
1319
|
+
cash,
|
|
1320
|
+
});
|
|
1321
|
+
return {
|
|
1322
|
+
value,
|
|
1323
|
+
assumptions: assumptions(input.timeToExpiryYears, q, 'digital', `digital-${kind}`),
|
|
1324
|
+
diagnostics: {
|
|
1325
|
+
engine: `digital-${kind}`,
|
|
1326
|
+
method: 'closed-form',
|
|
1327
|
+
converged: Number.isFinite(value),
|
|
1328
|
+
warnings: [],
|
|
1329
|
+
},
|
|
1330
|
+
};
|
|
1331
|
+
},
|
|
1332
|
+
/** Monte-Carlo binary price (discount the terminal indicator payoff); converges to the analytic. */
|
|
1333
|
+
monteCarloPrice(input, options) {
|
|
1334
|
+
const functionName = 'digital.monteCarloPrice';
|
|
1335
|
+
validateClosedRequest(functionName, input, DIGITAL_MC_INPUT_SPEC, {
|
|
1336
|
+
exampleCall: DIGITAL_EXAMPLE,
|
|
1337
|
+
});
|
|
1338
|
+
validateClosedRequest(functionName, options, DIGITAL_MC_OPTIONS_SPEC, {
|
|
1339
|
+
exampleCall: DIGITAL_EXAMPLE,
|
|
1340
|
+
argumentName: 'options',
|
|
1341
|
+
});
|
|
1342
|
+
const { type, kind } = input;
|
|
1343
|
+
const { q, cash } = validateDigital(input, functionName);
|
|
1344
|
+
const { spot: S, strike: K, timeToExpiryYears: T, riskFreeRate: r, volatility: sigma } = input;
|
|
1345
|
+
const df = Math.exp(-r * T);
|
|
1346
|
+
const payoff = (z) => {
|
|
1347
|
+
const ST = gbmTerminal({
|
|
1348
|
+
spot: S,
|
|
1349
|
+
riskFreeRate: r,
|
|
1350
|
+
dividendYield: q,
|
|
1351
|
+
volatility: sigma,
|
|
1352
|
+
timeToExpiryYears: T,
|
|
1353
|
+
shock: z[0],
|
|
1354
|
+
});
|
|
1355
|
+
const inMoney = type === 'call' ? ST > K : ST < K;
|
|
1356
|
+
if (!inMoney)
|
|
1357
|
+
return 0;
|
|
1358
|
+
return df * (kind === 'cash-or-nothing' ? cash : ST);
|
|
1359
|
+
};
|
|
1360
|
+
const est = monteCarloEstimate({
|
|
1361
|
+
dimensions: 1,
|
|
1362
|
+
payoff,
|
|
1363
|
+
options,
|
|
1364
|
+
controlVariate: undefined,
|
|
1365
|
+
label: functionName,
|
|
1366
|
+
});
|
|
1367
|
+
return {
|
|
1368
|
+
value: est.value,
|
|
1369
|
+
assumptions: assumptions(input.timeToExpiryYears, q, 'digital', `digital-${kind}-mc`),
|
|
1370
|
+
diagnostics: {
|
|
1371
|
+
engine: `digital-${kind}`,
|
|
1372
|
+
method: `monte-carlo-${est.method}`,
|
|
1373
|
+
converged: est.converged,
|
|
1374
|
+
iterations: est.paths,
|
|
1375
|
+
warnings: est.warnings,
|
|
1376
|
+
},
|
|
1377
|
+
monteCarlo: monteCarloStatistics(est),
|
|
1378
|
+
};
|
|
1379
|
+
},
|
|
1380
|
+
/**
|
|
1381
|
+
* Closed-form greeks (delta, gamma, vega, theta, rho) for the European binary. Every greek is an exact
|
|
1382
|
+
* derivative of the `digital.price` closed form — pinned to a finite-difference bump in the tests. Units
|
|
1383
|
+
* match the package: `vega` per vol point, `theta` per calendar day, `rho` per 1% (echoed in
|
|
1384
|
+
* `assumptions.units`). A cash-or-nothing's delta spikes and gamma flips sign across the strike (pin
|
|
1385
|
+
* risk); the asset-or-nothing's gamma/vega are exactly `0` at `d₂ = 0`. See `docs/specs/digital-greeks.md`.
|
|
1386
|
+
*/
|
|
1387
|
+
greeks(input) {
|
|
1388
|
+
const functionName = 'digital.greeks';
|
|
1389
|
+
validateClosedRequest(functionName, input, DIGITAL_GREEKS_SPEC, {
|
|
1390
|
+
exampleCall: DIGITAL_EXAMPLE,
|
|
1391
|
+
});
|
|
1392
|
+
const { type, kind } = input;
|
|
1393
|
+
const { q, cash } = validateDigital(input, functionName);
|
|
1394
|
+
const { spot: S, strike: K, timeToExpiryYears: T, riskFreeRate: r, volatility: sigma } = input;
|
|
1395
|
+
const sqrtT = Math.sqrt(T);
|
|
1396
|
+
const vol = sigma * sqrtT;
|
|
1397
|
+
const v2 = sigma * sigma * T; // vol²
|
|
1398
|
+
const d1 = (Math.log(S / K) + (r - q + 0.5 * sigma * sigma) * T) / vol;
|
|
1399
|
+
const d2 = d1 - vol;
|
|
1400
|
+
const phi = type === 'call' ? 1 : -1;
|
|
1401
|
+
const df = Math.exp(-r * T);
|
|
1402
|
+
const dq = Math.exp(-q * T);
|
|
1403
|
+
const pd1 = npdf(d1);
|
|
1404
|
+
const pd2 = npdf(d2);
|
|
1405
|
+
const Aterm = Math.log(S / K) / sigma;
|
|
1406
|
+
const dd2dT = ((r - q - 0.5 * sigma * sigma) / sigma - Aterm / T) / (2 * sqrtT);
|
|
1407
|
+
const dd1dT = ((r - q + 0.5 * sigma * sigma) / sigma - Aterm / T) / (2 * sqrtT);
|
|
1408
|
+
let delta;
|
|
1409
|
+
let gamma;
|
|
1410
|
+
let vegaRaw; // ∂V/∂σ
|
|
1411
|
+
let rhoRaw; // ∂V/∂r
|
|
1412
|
+
let thetaPerYear; // −∂V/∂T
|
|
1413
|
+
if (kind === 'cash-or-nothing') {
|
|
1414
|
+
const nCdf = N(phi * d2);
|
|
1415
|
+
delta = (phi * cash * df * pd2) / (S * vol);
|
|
1416
|
+
gamma = (-phi * cash * df * pd2 * d1) / (S * S * v2);
|
|
1417
|
+
vegaRaw = (-phi * cash * df * pd2 * d1) / sigma;
|
|
1418
|
+
rhoRaw = cash * df * (-T * nCdf + (phi * pd2 * sqrtT) / sigma);
|
|
1419
|
+
thetaPerYear = cash * df * (r * nCdf - phi * pd2 * dd2dT);
|
|
1420
|
+
}
|
|
1421
|
+
else {
|
|
1422
|
+
const nCdf = N(phi * d1);
|
|
1423
|
+
delta = dq * nCdf + (phi * dq * pd1) / vol;
|
|
1424
|
+
gamma = (-phi * dq * pd1 * d2) / (S * v2);
|
|
1425
|
+
vegaRaw = (-phi * S * dq * pd1 * d2) / sigma;
|
|
1426
|
+
rhoRaw = (phi * S * dq * pd1 * sqrtT) / sigma;
|
|
1427
|
+
thetaPerYear = S * dq * (q * nCdf - phi * pd1 * dd1dT);
|
|
1428
|
+
}
|
|
1429
|
+
const greeks = {
|
|
1430
|
+
delta,
|
|
1431
|
+
gamma,
|
|
1432
|
+
theta: thetaPerYear / DAYS_PER_YEAR,
|
|
1433
|
+
vega: vegaRaw / 100,
|
|
1434
|
+
rho: rhoRaw / 100,
|
|
1435
|
+
};
|
|
1436
|
+
return {
|
|
1437
|
+
value: greeks,
|
|
1438
|
+
assumptions: {
|
|
1439
|
+
...assumptions(input.timeToExpiryYears, q, 'digital', `digital-${kind}`),
|
|
1440
|
+
units: DEFAULT_GREEK_UNITS,
|
|
1441
|
+
},
|
|
1442
|
+
diagnostics: {
|
|
1443
|
+
engine: `digital-${kind}`,
|
|
1444
|
+
method: 'closed-form-greeks',
|
|
1445
|
+
converged: Object.values(greeks).every((x) => Number.isFinite(x)),
|
|
1446
|
+
warnings: [],
|
|
1447
|
+
},
|
|
1448
|
+
};
|
|
1449
|
+
},
|
|
1450
|
+
/**
|
|
1451
|
+
* The full higher-order (extended) Greek set for the European binary — completing {@link digital.greeks}
|
|
1452
|
+
* with vanna, charm, vomma, speed, color, phi, zomma, veta, vera, ultima, and lambda. The binary price is
|
|
1453
|
+
* a smooth function of `(S, σ, r, q, T)` for `T > 0`, so the higher-order Greeks are taken by central
|
|
1454
|
+
* finite differences of the exact `digital.price` closed form (the shared `finiteDifferenceExtendedGreeks`
|
|
1455
|
+
* helper); the first-order fields are the exact analytic Greeks of {@link digital.greeks}. Units match the
|
|
1456
|
+
* package (higher-order raw; `phi` per 1% dividend yield; `lambda` dimensionless). Near the strike a
|
|
1457
|
+
* binary's Greeks spike (pin risk) — they stay finite for `T > 0`, but very close to expiry-at-the-pin the
|
|
1458
|
+
* higher-order finite differences lose precision; widen `t` or read the sign/scale rather than the digit.
|
|
1459
|
+
* See `docs/specs/digital-extended-greeks.md`.
|
|
1460
|
+
*/
|
|
1461
|
+
extendedGreeks(input) {
|
|
1462
|
+
const functionName = 'digital.extendedGreeks';
|
|
1463
|
+
validateClosedRequest(functionName, input, DIGITAL_EXTENDED_GREEKS_SPEC, {
|
|
1464
|
+
exampleCall: DIGITAL_EXAMPLE,
|
|
1465
|
+
});
|
|
1466
|
+
const { type, kind } = input;
|
|
1467
|
+
const { q, cash } = validateDigital(input, functionName);
|
|
1468
|
+
const { spot: S, strike: K, timeToExpiryYears: T, riskFreeRate: r, volatility: sigma } = input;
|
|
1469
|
+
// Higher-order set: central differences of the exact analytic binary price.
|
|
1470
|
+
const price = ({ spot, volatility, timeToExpiryYears, riskFreeRate, dividendYield, }) => digitalAnalytic({
|
|
1471
|
+
type,
|
|
1472
|
+
kind,
|
|
1473
|
+
spot,
|
|
1474
|
+
strike: K,
|
|
1475
|
+
timeToExpiryYears,
|
|
1476
|
+
riskFreeRate,
|
|
1477
|
+
dividendYield,
|
|
1478
|
+
volatility,
|
|
1479
|
+
cash,
|
|
1480
|
+
});
|
|
1481
|
+
const fd = finiteDifferenceExtendedGreeks({
|
|
1482
|
+
price,
|
|
1483
|
+
spotAt: () => S,
|
|
1484
|
+
state: { spot: S, T, r, q, sigma },
|
|
1485
|
+
});
|
|
1486
|
+
// Override the FD first-order with the exact analytic Greeks (they agree to ~1e-5), and re-derive the
|
|
1487
|
+
// elasticity `lambda = Δ·S/V` from the analytic delta so it stays consistent with the overridden delta.
|
|
1488
|
+
const first = digital.greeks(input).value;
|
|
1489
|
+
const value = {
|
|
1490
|
+
...fd,
|
|
1491
|
+
...first,
|
|
1492
|
+
lambda: finiteOrNull((first.delta * S) /
|
|
1493
|
+
digitalAnalytic({
|
|
1494
|
+
type,
|
|
1495
|
+
kind,
|
|
1496
|
+
spot: S,
|
|
1497
|
+
strike: K,
|
|
1498
|
+
timeToExpiryYears: T,
|
|
1499
|
+
riskFreeRate: r,
|
|
1500
|
+
dividendYield: q,
|
|
1501
|
+
volatility: sigma,
|
|
1502
|
+
cash,
|
|
1503
|
+
})),
|
|
1504
|
+
};
|
|
1505
|
+
return {
|
|
1506
|
+
value,
|
|
1507
|
+
assumptions: {
|
|
1508
|
+
...assumptions(input.timeToExpiryYears, q, 'digital', `digital-${kind}`),
|
|
1509
|
+
units: DEFAULT_GREEK_UNITS,
|
|
1510
|
+
},
|
|
1511
|
+
diagnostics: {
|
|
1512
|
+
engine: `digital-${kind}`,
|
|
1513
|
+
method: 'analytic-first-order + fd-higher-order',
|
|
1514
|
+
// A disclosed-null lambda is an undefined-by-design quantity, not a convergence failure.
|
|
1515
|
+
converged: Object.values(value).every((x) => x === null || Number.isFinite(x)),
|
|
1516
|
+
warnings: value.lambda === null
|
|
1517
|
+
? [
|
|
1518
|
+
{
|
|
1519
|
+
code: WarningCode.LambdaUndefined,
|
|
1520
|
+
message: 'lambda (elasticity Δ·S/V) is undefined — the binary price underflowed to zero; reported as null, never NaN/Infinity.',
|
|
1521
|
+
severity: 'info',
|
|
1522
|
+
},
|
|
1523
|
+
]
|
|
1524
|
+
: [],
|
|
1525
|
+
},
|
|
1526
|
+
};
|
|
1527
|
+
},
|
|
1528
|
+
};
|
|
1529
|
+
function validateTouch(input, functionName) {
|
|
1530
|
+
requireArgumentObject(functionName, 'input', input);
|
|
1531
|
+
ensurePositive(input.spot, 'spot', functionName);
|
|
1532
|
+
ensurePositive(input.barrier, 'barrier', functionName);
|
|
1533
|
+
ensurePositive(input.timeToExpiryYears, 'timeToExpiryYears', functionName);
|
|
1534
|
+
ensurePositive(input.volatility, 'volatility', functionName);
|
|
1535
|
+
ensureFinite(input.riskFreeRate, 'riskFreeRate', functionName);
|
|
1536
|
+
const q = input.dividendYield ?? 0;
|
|
1537
|
+
ensureFinite(q, 'dividendYield', functionName);
|
|
1538
|
+
const cash = input.cash ?? 1;
|
|
1539
|
+
ensureFinite(cash, 'cash', functionName);
|
|
1540
|
+
return { q, cash };
|
|
1541
|
+
}
|
|
1542
|
+
function touchProbability(input) {
|
|
1543
|
+
const { spot: S, barrier: H, timeToExpiryYears: T, riskFreeRate: r, dividendYield: q, volatility: sigma, } = input;
|
|
1544
|
+
const nu = r - q - 0.5 * sigma * sigma;
|
|
1545
|
+
const sT = sigma * Math.sqrt(T);
|
|
1546
|
+
const L = Math.log(H / S);
|
|
1547
|
+
const p = H < S
|
|
1548
|
+
? N((L - nu * T) / sT) + Math.exp((2 * nu * L) / (sigma * sigma)) * N((L + nu * T) / sT)
|
|
1549
|
+
: N((-L + nu * T) / sT) + Math.exp((2 * nu * L) / (sigma * sigma)) * N((-L - nu * T) / sT);
|
|
1550
|
+
return Math.min(1, Math.max(0, p));
|
|
1551
|
+
}
|
|
1552
|
+
/** Reiner–Rubinstein one-touch value with the rebate paid AT the hit (assumes `S ≠ H`). */
|
|
1553
|
+
function oneTouchAtHit(input) {
|
|
1554
|
+
const { spot: S, barrier: H, timeToExpiryYears: T, riskFreeRate: r, dividendYield: q, volatility: sigma, cash, } = input;
|
|
1555
|
+
const b = r - q;
|
|
1556
|
+
const mu = (b - 0.5 * sigma * sigma) / (sigma * sigma);
|
|
1557
|
+
// λ is the exponent of the first-passage Laplace transform E[e^{−rτ}]. Its discriminant goes
|
|
1558
|
+
// negative when a negative rate outruns the drift (r < 0 with a negative carry), and λ — with the
|
|
1559
|
+
// whole value — becomes NaN: the discounted rebate has no finite expectation, because discounting
|
|
1560
|
+
// at a negative rate GROWS the payoff faster than the hitting-time density decays.
|
|
1561
|
+
const discriminant = mu * mu + (2 * r) / (sigma * sigma);
|
|
1562
|
+
if (!(discriminant >= 0)) {
|
|
1563
|
+
throw new UnsupportedError(`touch.price: the pay-at-hit one-touch has no finite value at riskFreeRate=${r} with carry ` +
|
|
1564
|
+
`riskFreeRate − dividendYield=${b} — the first-passage discount exponent needs ` +
|
|
1565
|
+
`μ² + 2r/σ² ≥ 0 and here it is ${discriminant.toPrecision(6)} (μ=${mu.toPrecision(6)}, σ=${sigma}). ` +
|
|
1566
|
+
'Discounting at a negative rate grows the rebate faster than the hitting time can arrive, so ' +
|
|
1567
|
+
"E[e^{−rτ}·cash] diverges. Price the expiry-settled form instead (payAt: 'expiry', which is " +
|
|
1568
|
+
'bounded by cash·e^{−rT}), or use a non-negative riskFreeRate.', {
|
|
1569
|
+
code: ErrorCode.EngineUnsupportedContract,
|
|
1570
|
+
context: {
|
|
1571
|
+
engine: 'touch-one-touch',
|
|
1572
|
+
payAt: 'hit',
|
|
1573
|
+
riskFreeRate: r,
|
|
1574
|
+
dividendYield: q,
|
|
1575
|
+
carry: b,
|
|
1576
|
+
volatility: sigma,
|
|
1577
|
+
discriminant,
|
|
1578
|
+
},
|
|
1579
|
+
});
|
|
1580
|
+
}
|
|
1581
|
+
const lambda = Math.sqrt(discriminant);
|
|
1582
|
+
const sT = sigma * Math.sqrt(T);
|
|
1583
|
+
const z = Math.log(H / S) / sT + lambda * sT;
|
|
1584
|
+
const eta = H < S ? 1 : -1;
|
|
1585
|
+
const value = Math.pow(H / S, mu + lambda) * N(eta * z) +
|
|
1586
|
+
Math.pow(H / S, mu - lambda) * N(eta * (z - 2 * lambda * sT));
|
|
1587
|
+
return cash * value;
|
|
1588
|
+
}
|
|
1589
|
+
/** Pure one-touch / no-touch value (shared by `touch.price` and the finite-difference `touch.greeks`). */
|
|
1590
|
+
function touchValue(input) {
|
|
1591
|
+
const { kind, payAt, spot: S, barrier: H, timeToExpiryYears: T, riskFreeRate: r, cash } = input;
|
|
1592
|
+
const df = Math.exp(-r * T);
|
|
1593
|
+
if (S === H)
|
|
1594
|
+
return kind === 'no-touch' ? 0 : payAt === 'hit' ? cash : cash * df;
|
|
1595
|
+
if (kind === 'one-touch') {
|
|
1596
|
+
return payAt === 'hit' ? oneTouchAtHit(input) : cash * df * touchProbability(input);
|
|
1597
|
+
}
|
|
1598
|
+
return cash * df * (1 - touchProbability(input));
|
|
1599
|
+
}
|
|
1600
|
+
function fdBarrierGreeks(input) {
|
|
1601
|
+
const { price: v, state, spotBump: spotStep } = input;
|
|
1602
|
+
const { spot: S, volatility: sigma, timeToExpiryYears: T, riskFreeRate: r } = state;
|
|
1603
|
+
const hVolatility = Math.min(1e-4, sigma * 0.5);
|
|
1604
|
+
const timeStepYears = Math.min(1e-4, T * 0.5);
|
|
1605
|
+
const rateStep = 1e-5;
|
|
1606
|
+
const p0 = v(state);
|
|
1607
|
+
const delta = (v({ ...state, spot: S + spotStep }) - v({ ...state, spot: S - spotStep })) / (2 * spotStep);
|
|
1608
|
+
const gamma = (v({ ...state, spot: S + spotStep }) - 2 * p0 + v({ ...state, spot: S - spotStep })) /
|
|
1609
|
+
(spotStep * spotStep);
|
|
1610
|
+
const vegaRaw = (v({ ...state, volatility: sigma + hVolatility }) -
|
|
1611
|
+
v({ ...state, volatility: sigma - hVolatility })) /
|
|
1612
|
+
(2 * hVolatility);
|
|
1613
|
+
const thetaPerYear = -(v({ ...state, timeToExpiryYears: T + timeStepYears }) -
|
|
1614
|
+
v({ ...state, timeToExpiryYears: T - timeStepYears })) /
|
|
1615
|
+
(2 * timeStepYears);
|
|
1616
|
+
const rhoRaw = (v({ ...state, riskFreeRate: r + rateStep }) - v({ ...state, riskFreeRate: r - rateStep })) /
|
|
1617
|
+
(2 * rateStep);
|
|
1618
|
+
return {
|
|
1619
|
+
delta,
|
|
1620
|
+
gamma,
|
|
1621
|
+
theta: thetaPerYear / DAYS_PER_YEAR,
|
|
1622
|
+
vega: vegaRaw / 100,
|
|
1623
|
+
rho: rhoRaw / 100,
|
|
1624
|
+
};
|
|
1625
|
+
}
|
|
1626
|
+
const TOUCH_PRICE_SPEC = specOf('touch.price#0');
|
|
1627
|
+
const TOUCH_GREEKS_SPEC = specOf('touch.greeks#0');
|
|
1628
|
+
const TOUCH_MC_INPUT_SPEC = specOf('touch.monteCarloPrice#0');
|
|
1629
|
+
const TOUCH_MC_OPTIONS_SPEC = specOf('touch.monteCarloPrice#1');
|
|
1630
|
+
const TOUCH_EXAMPLE = () => "touch.price({ kind: 'one-touch', spot: 100, barrier: 110, timeToExpiryYears: 0.25, riskFreeRate: 0.04, volatility: 0.2 })";
|
|
1631
|
+
export const touch = {
|
|
1632
|
+
/**
|
|
1633
|
+
* One-touch (pays if `H` is ever touched) / no-touch (pays if it never is), continuous monitoring.
|
|
1634
|
+
* `one-touch` settles at expiry by default or at the hit (`payAt: 'hit'`, Reiner–Rubinstein);
|
|
1635
|
+
* `no-touch` is always expiry-settled. An already-touched spot (`S = H`) short-circuits to the
|
|
1636
|
+
* certain payoff. See `docs/specs/digital-touch.md`.
|
|
1637
|
+
*/
|
|
1638
|
+
price(input) {
|
|
1639
|
+
const functionName = 'touch.price';
|
|
1640
|
+
validateClosedRequest(functionName, input, TOUCH_PRICE_SPEC, {
|
|
1641
|
+
exampleCall: TOUCH_EXAMPLE,
|
|
1642
|
+
});
|
|
1643
|
+
const { kind } = input;
|
|
1644
|
+
const { q, cash } = validateTouch(input, functionName);
|
|
1645
|
+
const payAt = input.payAt ?? 'expiry';
|
|
1646
|
+
if (kind === 'no-touch' && input.payAt === 'hit') {
|
|
1647
|
+
throw new InputError(`${functionName}: a no-touch settles at expiry — payAt: 'hit' is not applicable (there is no hit to pay on).`, { code: ErrorCode.InputInvalidEnum, context: { kind, payAt } });
|
|
1648
|
+
}
|
|
1649
|
+
const { spot: S, barrier: H, timeToExpiryYears: T, riskFreeRate: r, volatility: sigma } = input;
|
|
1650
|
+
const value = touchValue({
|
|
1651
|
+
kind,
|
|
1652
|
+
payAt,
|
|
1653
|
+
spot: S,
|
|
1654
|
+
barrier: H,
|
|
1655
|
+
timeToExpiryYears: T,
|
|
1656
|
+
riskFreeRate: r,
|
|
1657
|
+
dividendYield: q,
|
|
1658
|
+
volatility: sigma,
|
|
1659
|
+
cash,
|
|
1660
|
+
});
|
|
1661
|
+
return {
|
|
1662
|
+
value,
|
|
1663
|
+
assumptions: assumptions(input.timeToExpiryYears, q, 'touch', `touch-${kind}-${payAt}`),
|
|
1664
|
+
diagnostics: {
|
|
1665
|
+
engine: `touch-${kind}`,
|
|
1666
|
+
method: payAt === 'hit' ? 'reiner-rubinstein' : 'first-passage',
|
|
1667
|
+
converged: Number.isFinite(value),
|
|
1668
|
+
warnings: [],
|
|
1669
|
+
},
|
|
1670
|
+
};
|
|
1671
|
+
},
|
|
1672
|
+
/**
|
|
1673
|
+
* First-order greeks (delta, gamma, vega, theta, rho) for the one-touch / no-touch binary, by central
|
|
1674
|
+
* finite-difference of the exact `touch.price` (the analytic greeks are a research-grade first-passage
|
|
1675
|
+
* series). Units match the package (vega/1%, theta/day, rho/1%; echoed in `assumptions.units`). The spot
|
|
1676
|
+
* bump is shrunk near the barrier so it never straddles it. Pinned to the exact identity that a one-touch
|
|
1677
|
+
* (pay-at-expiry) and a no-touch greek sum to the `cash·e^{−rT}` greeks. See `docs/specs/touch-greeks.md`.
|
|
1678
|
+
*/
|
|
1679
|
+
greeks(input) {
|
|
1680
|
+
const functionName = 'touch.greeks';
|
|
1681
|
+
validateClosedRequest(functionName, input, TOUCH_GREEKS_SPEC, {
|
|
1682
|
+
exampleCall: TOUCH_EXAMPLE,
|
|
1683
|
+
});
|
|
1684
|
+
const { kind } = input;
|
|
1685
|
+
const { q, cash } = validateTouch(input, functionName);
|
|
1686
|
+
const payAt = input.payAt ?? 'expiry';
|
|
1687
|
+
if (kind === 'no-touch' && input.payAt === 'hit') {
|
|
1688
|
+
throw new InputError(`${functionName}: a no-touch settles at expiry — payAt: 'hit' is not applicable.`, { code: ErrorCode.InputInvalidEnum, context: { kind, payAt } });
|
|
1689
|
+
}
|
|
1690
|
+
const { spot: S, barrier: H, timeToExpiryYears: T, riskFreeRate: r, volatility: sigma } = input;
|
|
1691
|
+
// Keep the spot bump from straddling the barrier (the price is discontinuous in regime across H).
|
|
1692
|
+
const spotStep = Math.min(S * 1e-4, Math.abs(S - H) * 0.25) || S * 1e-6;
|
|
1693
|
+
const greeks = fdBarrierGreeks({
|
|
1694
|
+
price: ({ spot, volatility, timeToExpiryYears, riskFreeRate }) => touchValue({
|
|
1695
|
+
kind,
|
|
1696
|
+
payAt,
|
|
1697
|
+
spot,
|
|
1698
|
+
barrier: H,
|
|
1699
|
+
timeToExpiryYears,
|
|
1700
|
+
riskFreeRate,
|
|
1701
|
+
dividendYield: q,
|
|
1702
|
+
volatility,
|
|
1703
|
+
cash,
|
|
1704
|
+
}),
|
|
1705
|
+
state: { spot: S, volatility: sigma, timeToExpiryYears: T, riskFreeRate: r },
|
|
1706
|
+
spotBump: spotStep,
|
|
1707
|
+
});
|
|
1708
|
+
return {
|
|
1709
|
+
value: greeks,
|
|
1710
|
+
assumptions: {
|
|
1711
|
+
...assumptions(input.timeToExpiryYears, q, 'touch', `touch-${kind}-${payAt}`),
|
|
1712
|
+
units: DEFAULT_GREEK_UNITS,
|
|
1713
|
+
},
|
|
1714
|
+
diagnostics: {
|
|
1715
|
+
engine: `touch-${kind}`,
|
|
1716
|
+
method: 'finite-difference',
|
|
1717
|
+
converged: Object.values(greeks).every((x) => Number.isFinite(x)),
|
|
1718
|
+
warnings: [],
|
|
1719
|
+
},
|
|
1720
|
+
};
|
|
1721
|
+
},
|
|
1722
|
+
/**
|
|
1723
|
+
* Monte-Carlo one-touch / no-touch. Pay-at-expiry reuses the Brownian-bridge survival so discrete
|
|
1724
|
+
* monitoring converges to the continuous analytic; pay-at-hit detects the first crossing on the grid
|
|
1725
|
+
* and discounts at the hit time.
|
|
1726
|
+
*/
|
|
1727
|
+
monteCarloPrice(input, options) {
|
|
1728
|
+
const functionName = 'touch.monteCarloPrice';
|
|
1729
|
+
validateClosedRequest(functionName, input, TOUCH_MC_INPUT_SPEC, {
|
|
1730
|
+
exampleCall: TOUCH_EXAMPLE,
|
|
1731
|
+
});
|
|
1732
|
+
validateClosedRequest(functionName, options, TOUCH_MC_OPTIONS_SPEC, {
|
|
1733
|
+
exampleCall: TOUCH_EXAMPLE,
|
|
1734
|
+
argumentName: 'options',
|
|
1735
|
+
});
|
|
1736
|
+
const { kind } = input;
|
|
1737
|
+
const { q, cash } = validateTouch(input, functionName);
|
|
1738
|
+
const payAt = input.payAt ?? 'expiry';
|
|
1739
|
+
if (kind === 'no-touch' && input.payAt === 'hit') {
|
|
1740
|
+
throw new InputError(`${functionName}: a no-touch settles at expiry — payAt: 'hit' is not applicable.`, { code: ErrorCode.InputInvalidEnum, context: { kind, payAt } });
|
|
1741
|
+
}
|
|
1742
|
+
const { spot: S, barrier: H, timeToExpiryYears: T, riskFreeRate: r, volatility: sigma } = input;
|
|
1743
|
+
const steps = options.steps ?? 100;
|
|
1744
|
+
const timeStepYears = T / steps;
|
|
1745
|
+
const df = Math.exp(-r * T);
|
|
1746
|
+
const isDown = H < S;
|
|
1747
|
+
// Broadie–Glasserman–Kou continuity correction, β₁ = −ζ(1/2)/√(2π) = 0.5826: a barrier monitored
|
|
1748
|
+
// on a Δt grid behaves like a continuous barrier that is 0.5826·σ√Δt further away in log-space,
|
|
1749
|
+
// so the grid barrier is moved that far TOWARD the spot to reproduce the continuous price.
|
|
1750
|
+
const correctedBarrier = H * Math.exp((isDown ? 1 : -1) * 0.5826 * sigma * Math.sqrt(timeStepYears));
|
|
1751
|
+
const payoff = (z) => {
|
|
1752
|
+
const path = gbmPathUnchecked({
|
|
1753
|
+
spot: S,
|
|
1754
|
+
riskFreeRate: r,
|
|
1755
|
+
dividendYield: q,
|
|
1756
|
+
volatility: sigma,
|
|
1757
|
+
timeToExpiryYears: T,
|
|
1758
|
+
shocks: z,
|
|
1759
|
+
});
|
|
1760
|
+
if (payAt === 'hit') {
|
|
1761
|
+
// one-touch only (no-touch@hit rejected above): discount the rebate at the first crossing.
|
|
1762
|
+
// The grid only SEES the barrier at monitoring dates, so it misses every excursion that
|
|
1763
|
+
// crosses and returns between them and under-prices the touch (>8 SE low at 500 steps). The
|
|
1764
|
+
// Broadie–Glasserman–Kou continuity correction is applied the same way the barrier engines
|
|
1765
|
+
// apply it: the tested barrier is shifted TOWARD the path by e^{±0.5826·σ√Δt}, which makes a
|
|
1766
|
+
// discretely-monitored crossing match the continuous first-passage probability.
|
|
1767
|
+
for (let k = 0; k <= steps; k++) {
|
|
1768
|
+
const x = path[k];
|
|
1769
|
+
if (isDown ? x <= correctedBarrier : x >= correctedBarrier)
|
|
1770
|
+
return cash * Math.exp(-r * k * timeStepYears);
|
|
1771
|
+
}
|
|
1772
|
+
return 0;
|
|
1773
|
+
}
|
|
1774
|
+
const surv = barrierSurvival({
|
|
1775
|
+
path,
|
|
1776
|
+
barrier: H,
|
|
1777
|
+
isDown,
|
|
1778
|
+
volatility: sigma,
|
|
1779
|
+
timeStepYears,
|
|
1780
|
+
});
|
|
1781
|
+
return df * cash * (kind === 'one-touch' ? 1 - surv : surv);
|
|
1782
|
+
};
|
|
1783
|
+
const est = monteCarloEstimate({
|
|
1784
|
+
dimensions: steps,
|
|
1785
|
+
payoff,
|
|
1786
|
+
options,
|
|
1787
|
+
controlVariate: undefined,
|
|
1788
|
+
label: functionName,
|
|
1789
|
+
});
|
|
1790
|
+
return {
|
|
1791
|
+
value: est.value,
|
|
1792
|
+
assumptions: assumptions(input.timeToExpiryYears, q, 'touch', `touch-${kind}-${payAt}-mc`),
|
|
1793
|
+
diagnostics: {
|
|
1794
|
+
engine: `touch-${kind}`,
|
|
1795
|
+
method: payAt === 'hit'
|
|
1796
|
+
? `monte-carlo-${est.method}-first-crossing`
|
|
1797
|
+
: `monte-carlo-${est.method}-brownian-bridge`,
|
|
1798
|
+
converged: est.converged,
|
|
1799
|
+
iterations: est.paths,
|
|
1800
|
+
warnings: est.warnings,
|
|
1801
|
+
},
|
|
1802
|
+
monteCarlo: monteCarloStatistics(est),
|
|
1803
|
+
};
|
|
1804
|
+
},
|
|
1805
|
+
};
|
|
1806
|
+
function validateForwardStart(input, functionName) {
|
|
1807
|
+
requireArgumentObject(functionName, 'input', input);
|
|
1808
|
+
ensurePositive(input.spot, 'spot', functionName);
|
|
1809
|
+
ensurePositive(input.timeToExpiryYears, 'timeToExpiryYears', functionName);
|
|
1810
|
+
ensurePositive(input.volatility, 'volatility', functionName);
|
|
1811
|
+
ensureFinite(input.riskFreeRate, 'riskFreeRate', functionName);
|
|
1812
|
+
if (!(input.resetTime > 0 && input.resetTime < input.timeToExpiryYears)) {
|
|
1813
|
+
throw new InputError(`${functionName}: resetTime must be in (0, t); got resetTime=${input.resetTime}, t=${input.timeToExpiryYears}.`, {
|
|
1814
|
+
code: ErrorCode.InputOutOfRange,
|
|
1815
|
+
context: { resetTime: input.resetTime, timeToExpiryYears: input.timeToExpiryYears },
|
|
1816
|
+
});
|
|
1817
|
+
}
|
|
1818
|
+
const q = input.dividendYield ?? 0;
|
|
1819
|
+
ensureFinite(q, 'dividendYield', functionName);
|
|
1820
|
+
const alpha = input.strikeMultiplier ?? 1;
|
|
1821
|
+
ensurePositive(alpha, 'strikeMultiplier', functionName);
|
|
1822
|
+
return { q, alpha };
|
|
1823
|
+
}
|
|
1824
|
+
/** Rubinstein (1991) forward-start price: `V = S·e^{−q·t₁}·φ`, with `φ` the fixed-moneyness BSM shape. */
|
|
1825
|
+
function forwardStartAnalytic(input) {
|
|
1826
|
+
const { type, spot: S, strikeMultiplier: alpha, resetTime: t1, timeToExpiryYears: T, riskFreeRate: r, dividendYield: q, volatility: sigma, } = input;
|
|
1827
|
+
const b = r - q;
|
|
1828
|
+
const tau = T - t1;
|
|
1829
|
+
const vol = sigma * Math.sqrt(tau);
|
|
1830
|
+
const d1 = (-Math.log(alpha) + (b + 0.5 * sigma * sigma) * tau) / vol;
|
|
1831
|
+
const d2 = d1 - vol;
|
|
1832
|
+
const phi = type === 'call'
|
|
1833
|
+
? Math.exp(-q * tau) * N(d1) - alpha * Math.exp(-r * tau) * N(d2)
|
|
1834
|
+
: alpha * Math.exp(-r * tau) * N(-d2) - Math.exp(-q * tau) * N(-d1);
|
|
1835
|
+
return S * Math.exp(-q * t1) * phi;
|
|
1836
|
+
}
|
|
1837
|
+
const FORWARD_START_PRICE_SPEC = specOf('forwardStart.price#0');
|
|
1838
|
+
const FORWARD_START_MC_INPUT_SPEC = specOf('forwardStart.monteCarloPrice#0');
|
|
1839
|
+
const FORWARD_START_MC_OPTIONS_SPEC = specOf('forwardStart.monteCarloPrice#1');
|
|
1840
|
+
const FORWARD_START_EXAMPLE = () => "forwardStart.price({ type: 'call', spot: 100, resetTime: 0.1, timeToExpiryYears: 0.25, riskFreeRate: 0.04, volatility: 0.2 })";
|
|
1841
|
+
export const forwardStart = {
|
|
1842
|
+
/** Closed-form forward-start price (Rubinstein 1991); the value scales with today's spot. */
|
|
1843
|
+
price(input) {
|
|
1844
|
+
const functionName = 'forwardStart.price';
|
|
1845
|
+
validateClosedRequest(functionName, input, FORWARD_START_PRICE_SPEC, {
|
|
1846
|
+
exampleCall: FORWARD_START_EXAMPLE,
|
|
1847
|
+
});
|
|
1848
|
+
const { type } = input;
|
|
1849
|
+
const { q, alpha } = validateForwardStart(input, functionName);
|
|
1850
|
+
const value = forwardStartAnalytic({
|
|
1851
|
+
type,
|
|
1852
|
+
spot: input.spot,
|
|
1853
|
+
strikeMultiplier: alpha,
|
|
1854
|
+
resetTime: input.resetTime,
|
|
1855
|
+
timeToExpiryYears: input.timeToExpiryYears,
|
|
1856
|
+
riskFreeRate: input.riskFreeRate,
|
|
1857
|
+
dividendYield: q,
|
|
1858
|
+
volatility: input.volatility,
|
|
1859
|
+
});
|
|
1860
|
+
return {
|
|
1861
|
+
value,
|
|
1862
|
+
assumptions: assumptions(input.timeToExpiryYears, q, 'forward-start', 'forward-start'),
|
|
1863
|
+
diagnostics: {
|
|
1864
|
+
engine: 'forward-start',
|
|
1865
|
+
method: 'rubinstein',
|
|
1866
|
+
converged: Number.isFinite(value),
|
|
1867
|
+
warnings: [],
|
|
1868
|
+
},
|
|
1869
|
+
};
|
|
1870
|
+
},
|
|
1871
|
+
/** Two-step-GBM Monte-Carlo forward-start price (converges to the analytic). */
|
|
1872
|
+
monteCarloPrice(input, options) {
|
|
1873
|
+
const functionName = 'forwardStart.monteCarloPrice';
|
|
1874
|
+
validateClosedRequest(functionName, input, FORWARD_START_MC_INPUT_SPEC, {
|
|
1875
|
+
exampleCall: FORWARD_START_EXAMPLE,
|
|
1876
|
+
});
|
|
1877
|
+
validateClosedRequest(functionName, options, FORWARD_START_MC_OPTIONS_SPEC, {
|
|
1878
|
+
exampleCall: FORWARD_START_EXAMPLE,
|
|
1879
|
+
argumentName: 'options',
|
|
1880
|
+
});
|
|
1881
|
+
const { type } = input;
|
|
1882
|
+
const { q, alpha } = validateForwardStart(input, functionName);
|
|
1883
|
+
const { spot: S, resetTime: t1, timeToExpiryYears: T, riskFreeRate: r, volatility: sigma, } = input;
|
|
1884
|
+
const tau = T - t1;
|
|
1885
|
+
const df = Math.exp(-r * T);
|
|
1886
|
+
const payoff = (z) => {
|
|
1887
|
+
const St1 = gbmTerminal({
|
|
1888
|
+
spot: S,
|
|
1889
|
+
riskFreeRate: r,
|
|
1890
|
+
dividendYield: q,
|
|
1891
|
+
volatility: sigma,
|
|
1892
|
+
timeToExpiryYears: t1,
|
|
1893
|
+
shock: z[0],
|
|
1894
|
+
});
|
|
1895
|
+
const ST = gbmTerminal({
|
|
1896
|
+
spot: St1,
|
|
1897
|
+
riskFreeRate: r,
|
|
1898
|
+
dividendYield: q,
|
|
1899
|
+
volatility: sigma,
|
|
1900
|
+
timeToExpiryYears: tau,
|
|
1901
|
+
shock: z[1],
|
|
1902
|
+
});
|
|
1903
|
+
const K = alpha * St1;
|
|
1904
|
+
const intrinsic = type === 'call' ? Math.max(ST - K, 0) : Math.max(K - ST, 0);
|
|
1905
|
+
return df * intrinsic;
|
|
1906
|
+
};
|
|
1907
|
+
const est = monteCarloEstimate({
|
|
1908
|
+
dimensions: 2,
|
|
1909
|
+
payoff,
|
|
1910
|
+
options,
|
|
1911
|
+
controlVariate: undefined,
|
|
1912
|
+
label: functionName,
|
|
1913
|
+
});
|
|
1914
|
+
return {
|
|
1915
|
+
value: est.value,
|
|
1916
|
+
assumptions: assumptions(input.timeToExpiryYears, q, 'forward-start', 'forward-start-mc'),
|
|
1917
|
+
diagnostics: {
|
|
1918
|
+
engine: 'forward-start',
|
|
1919
|
+
method: `monte-carlo-${est.method}`,
|
|
1920
|
+
converged: est.converged,
|
|
1921
|
+
iterations: est.paths,
|
|
1922
|
+
warnings: est.warnings,
|
|
1923
|
+
},
|
|
1924
|
+
monteCarlo: monteCarloStatistics(est),
|
|
1925
|
+
};
|
|
1926
|
+
},
|
|
1927
|
+
};
|
|
1928
|
+
function validateCliquet(input, functionName) {
|
|
1929
|
+
requireArgumentObject(functionName, 'input', input);
|
|
1930
|
+
ensurePositive(input.spot, 'spot', functionName);
|
|
1931
|
+
ensurePositive(input.volatility, 'volatility', functionName);
|
|
1932
|
+
ensureFinite(input.riskFreeRate, 'riskFreeRate', functionName);
|
|
1933
|
+
requireArgumentArray(functionName, 'resetTimes', input.resetTimes);
|
|
1934
|
+
const rt = input.resetTimes;
|
|
1935
|
+
if (rt.length < 1) {
|
|
1936
|
+
throw new InputError(`${functionName}: at least one reset time is required.`, {
|
|
1937
|
+
code: ErrorCode.InputOutOfRange,
|
|
1938
|
+
context: { resets: rt.length },
|
|
1939
|
+
});
|
|
1940
|
+
}
|
|
1941
|
+
const periods = [];
|
|
1942
|
+
let prev = 0;
|
|
1943
|
+
for (let i = 0; i < rt.length; i++) {
|
|
1944
|
+
ensureFinite(rt[i], `resetTimes[${i}]`, functionName);
|
|
1945
|
+
if (!(rt[i] > prev)) {
|
|
1946
|
+
throw new InputError(`${functionName}: resetTimes must be strictly increasing and > 0; resetTimes[${i}] = ${rt[i]} ≤ ${prev}.`, { code: ErrorCode.InputOutOfRange, context: { index: i, value: rt[i], previous: prev } });
|
|
1947
|
+
}
|
|
1948
|
+
periods.push(rt[i] - prev);
|
|
1949
|
+
prev = rt[i];
|
|
1950
|
+
}
|
|
1951
|
+
const q = input.dividendYield ?? 0;
|
|
1952
|
+
ensureFinite(q, 'dividendYield', functionName);
|
|
1953
|
+
const localFloor = input.localFloor ?? 0;
|
|
1954
|
+
const localCap = input.localCap ?? Infinity;
|
|
1955
|
+
ensureFinite(localFloor, 'localFloor', functionName);
|
|
1956
|
+
if (!(localFloor >= -1)) {
|
|
1957
|
+
throw new InputError(`${functionName}: localFloor must be ≥ −1 (a return can't fall below −100%); got ${localFloor}.`, {
|
|
1958
|
+
code: ErrorCode.InputOutOfRange,
|
|
1959
|
+
context: { localFloor },
|
|
1960
|
+
});
|
|
1961
|
+
}
|
|
1962
|
+
if (!(localCap > localFloor)) {
|
|
1963
|
+
throw new InputError(`${functionName}: localCap must exceed localFloor; got cap ${localCap}, floor ${localFloor}.`, {
|
|
1964
|
+
code: ErrorCode.InputOutOfRange,
|
|
1965
|
+
context: { localCap, localFloor },
|
|
1966
|
+
});
|
|
1967
|
+
}
|
|
1968
|
+
const globalFloor = input.globalFloor ?? -Infinity;
|
|
1969
|
+
const globalCap = input.globalCap ?? Infinity;
|
|
1970
|
+
if (!(globalCap > globalFloor)) {
|
|
1971
|
+
throw new InputError(`${functionName}: globalCap must exceed globalFloor; got cap ${globalCap}, floor ${globalFloor}.`, {
|
|
1972
|
+
code: ErrorCode.InputOutOfRange,
|
|
1973
|
+
context: { globalCap, globalFloor },
|
|
1974
|
+
});
|
|
1975
|
+
}
|
|
1976
|
+
const notional = input.notional ?? 1;
|
|
1977
|
+
ensureFinite(notional, 'notional', functionName);
|
|
1978
|
+
return {
|
|
1979
|
+
q,
|
|
1980
|
+
localFloor,
|
|
1981
|
+
localCap,
|
|
1982
|
+
globalFloor,
|
|
1983
|
+
globalCap,
|
|
1984
|
+
notional,
|
|
1985
|
+
periods,
|
|
1986
|
+
maturity: prev,
|
|
1987
|
+
};
|
|
1988
|
+
}
|
|
1989
|
+
/** `E[max(R − K′, 0)]` for the period return `R` (Black-76 on the forward return `e^{b·τ}`). */
|
|
1990
|
+
function returnCaplet(input) {
|
|
1991
|
+
const { strike, period: tau, carryRate: b, volatility: sigma } = input;
|
|
1992
|
+
if (!Number.isFinite(strike))
|
|
1993
|
+
return 0; // an infinite (uncapped) strike contributes nothing
|
|
1994
|
+
const forward = Math.exp(b * tau);
|
|
1995
|
+
const vol = sigma * Math.sqrt(tau);
|
|
1996
|
+
const d1 = (Math.log(forward / strike) + 0.5 * sigma * sigma * tau) / vol;
|
|
1997
|
+
const d2 = d1 - vol;
|
|
1998
|
+
return forward * N(d1) - strike * N(d2);
|
|
1999
|
+
}
|
|
2000
|
+
const CLIQUET_PRICE_SPEC = specOf('cliquet.price#0');
|
|
2001
|
+
const CLIQUET_MC_INPUT_SPEC = specOf('cliquet.monteCarloPrice#0');
|
|
2002
|
+
const CLIQUET_MC_OPTIONS_SPEC = specOf('cliquet.monteCarloPrice#1');
|
|
2003
|
+
const CLIQUET_EXAMPLE = () => 'cliquet.price({ spot: 100, resetTimes: [0.25, 0.5, 0.75, 1], riskFreeRate: 0.04, volatility: 0.2 })';
|
|
2004
|
+
export const cliquet = {
|
|
2005
|
+
/**
|
|
2006
|
+
* Closed-form cliquet (a strip of forward-start caplets), valid when there is NO global cap/floor —
|
|
2007
|
+
* the value is then the discounted sum of the per-period expected clipped returns (Black-76 on each
|
|
2008
|
+
* period return). A global cap/floor makes the total path-dependent; this throws and points to
|
|
2009
|
+
* `monteCarloPrice`. See `docs/specs/cliquet.md`.
|
|
2010
|
+
*/
|
|
2011
|
+
price(input) {
|
|
2012
|
+
const functionName = 'cliquet.price';
|
|
2013
|
+
validateClosedRequest(functionName, input, CLIQUET_PRICE_SPEC, {
|
|
2014
|
+
exampleCall: CLIQUET_EXAMPLE,
|
|
2015
|
+
});
|
|
2016
|
+
const c = validateCliquet(input, functionName);
|
|
2017
|
+
if (Number.isFinite(c.globalFloor) || Number.isFinite(c.globalCap)) {
|
|
2018
|
+
throw new UnsupportedError(`${functionName}: a globalFloor/globalCap makes the summed payoff path-dependent — the closed form does not apply. Use cliquet.monteCarloPrice.`, {
|
|
2019
|
+
code: ErrorCode.EngineUnsupportedContract,
|
|
2020
|
+
context: { globalFloor: c.globalFloor, globalCap: c.globalCap },
|
|
2021
|
+
});
|
|
2022
|
+
}
|
|
2023
|
+
const b = input.riskFreeRate - c.q;
|
|
2024
|
+
let sumExpected = 0;
|
|
2025
|
+
for (const tau of c.periods) {
|
|
2026
|
+
// E[clip(rᵢ, lf, lc)] = lf + caplet(1+lf) − caplet(1+lc).
|
|
2027
|
+
sumExpected +=
|
|
2028
|
+
c.localFloor +
|
|
2029
|
+
returnCaplet({
|
|
2030
|
+
strike: 1 + c.localFloor,
|
|
2031
|
+
period: tau,
|
|
2032
|
+
carryRate: b,
|
|
2033
|
+
volatility: input.volatility,
|
|
2034
|
+
}) -
|
|
2035
|
+
returnCaplet({
|
|
2036
|
+
strike: 1 + c.localCap,
|
|
2037
|
+
period: tau,
|
|
2038
|
+
carryRate: b,
|
|
2039
|
+
volatility: input.volatility,
|
|
2040
|
+
});
|
|
2041
|
+
}
|
|
2042
|
+
const value = Math.exp(-input.riskFreeRate * c.maturity) * c.notional * sumExpected;
|
|
2043
|
+
return {
|
|
2044
|
+
value,
|
|
2045
|
+
assumptions: assumptions(c.maturity, c.q, 'cliquet', 'cliquet'),
|
|
2046
|
+
diagnostics: {
|
|
2047
|
+
engine: 'cliquet',
|
|
2048
|
+
method: 'black76-caplet-strip',
|
|
2049
|
+
converged: Number.isFinite(value),
|
|
2050
|
+
warnings: [],
|
|
2051
|
+
},
|
|
2052
|
+
};
|
|
2053
|
+
},
|
|
2054
|
+
/** General Monte-Carlo cliquet (local + global caps/floors); converges to the analytic in the no-global case. */
|
|
2055
|
+
monteCarloPrice(input, options) {
|
|
2056
|
+
const functionName = 'cliquet.monteCarloPrice';
|
|
2057
|
+
validateClosedRequest(functionName, input, CLIQUET_MC_INPUT_SPEC, {
|
|
2058
|
+
exampleCall: CLIQUET_EXAMPLE,
|
|
2059
|
+
});
|
|
2060
|
+
validateClosedRequest(functionName, options, CLIQUET_MC_OPTIONS_SPEC, {
|
|
2061
|
+
exampleCall: CLIQUET_EXAMPLE,
|
|
2062
|
+
argumentName: 'options',
|
|
2063
|
+
});
|
|
2064
|
+
const c = validateCliquet(input, functionName);
|
|
2065
|
+
const { spot: S, riskFreeRate: r, volatility: sigma } = input;
|
|
2066
|
+
const df = Math.exp(-r * c.maturity);
|
|
2067
|
+
const payoff = (z) => {
|
|
2068
|
+
let acc = 0;
|
|
2069
|
+
let prevSpot = S;
|
|
2070
|
+
for (let i = 0; i < c.periods.length; i++) {
|
|
2071
|
+
const next = gbmTerminal({
|
|
2072
|
+
spot: prevSpot,
|
|
2073
|
+
riskFreeRate: r,
|
|
2074
|
+
dividendYield: c.q,
|
|
2075
|
+
volatility: sigma,
|
|
2076
|
+
timeToExpiryYears: c.periods[i],
|
|
2077
|
+
shock: z[i],
|
|
2078
|
+
});
|
|
2079
|
+
const ret = next / prevSpot - 1;
|
|
2080
|
+
acc += Math.min(c.localCap, Math.max(c.localFloor, ret));
|
|
2081
|
+
prevSpot = next;
|
|
2082
|
+
}
|
|
2083
|
+
const total = Math.min(c.globalCap, Math.max(c.globalFloor, acc));
|
|
2084
|
+
return df * c.notional * total;
|
|
2085
|
+
};
|
|
2086
|
+
const est = monteCarloEstimate({
|
|
2087
|
+
dimensions: c.periods.length,
|
|
2088
|
+
payoff,
|
|
2089
|
+
options,
|
|
2090
|
+
controlVariate: undefined,
|
|
2091
|
+
label: functionName,
|
|
2092
|
+
});
|
|
2093
|
+
return {
|
|
2094
|
+
value: est.value,
|
|
2095
|
+
assumptions: assumptions(c.maturity, c.q, 'cliquet', 'cliquet-mc'),
|
|
2096
|
+
diagnostics: {
|
|
2097
|
+
engine: 'cliquet',
|
|
2098
|
+
method: `monte-carlo-${est.method}`,
|
|
2099
|
+
converged: est.converged,
|
|
2100
|
+
iterations: est.paths,
|
|
2101
|
+
warnings: est.warnings,
|
|
2102
|
+
},
|
|
2103
|
+
monteCarlo: monteCarloStatistics(est),
|
|
2104
|
+
};
|
|
2105
|
+
},
|
|
2106
|
+
};
|
|
2107
|
+
function validateNapoleon(input, functionName) {
|
|
2108
|
+
requireArgumentObject(functionName, 'input', input);
|
|
2109
|
+
ensurePositive(input.spot, 'spot', functionName);
|
|
2110
|
+
ensurePositive(input.volatility, 'volatility', functionName);
|
|
2111
|
+
ensureFinite(input.riskFreeRate, 'riskFreeRate', functionName);
|
|
2112
|
+
ensureFinite(input.coupon, 'coupon', functionName);
|
|
2113
|
+
requireArgumentArray(functionName, 'resetTimes', input.resetTimes);
|
|
2114
|
+
const rt = input.resetTimes;
|
|
2115
|
+
if (rt.length < 1) {
|
|
2116
|
+
throw new InputError(`${functionName}: at least one reset time is required.`, {
|
|
2117
|
+
code: ErrorCode.InputOutOfRange,
|
|
2118
|
+
context: { resets: rt.length },
|
|
2119
|
+
});
|
|
2120
|
+
}
|
|
2121
|
+
const periods = [];
|
|
2122
|
+
let prev = 0;
|
|
2123
|
+
for (let i = 0; i < rt.length; i++) {
|
|
2124
|
+
ensureFinite(rt[i], `resetTimes[${i}]`, functionName);
|
|
2125
|
+
if (!(rt[i] > prev)) {
|
|
2126
|
+
throw new InputError(`${functionName}: resetTimes must be strictly increasing and > 0; resetTimes[${i}] = ${rt[i]} ≤ ${prev}.`, { code: ErrorCode.InputOutOfRange, context: { index: i, value: rt[i], previous: prev } });
|
|
2127
|
+
}
|
|
2128
|
+
periods.push(rt[i] - prev);
|
|
2129
|
+
prev = rt[i];
|
|
2130
|
+
}
|
|
2131
|
+
const q = input.dividendYield ?? 0;
|
|
2132
|
+
ensureFinite(q, 'dividendYield', functionName);
|
|
2133
|
+
const globalFloor = input.globalFloor ?? 0;
|
|
2134
|
+
// −Infinity is the "unfloored" note (the closed-form floorlessValue case); reject +Infinity / NaN.
|
|
2135
|
+
if (globalFloor !== -Infinity)
|
|
2136
|
+
ensureFinite(globalFloor, 'globalFloor', functionName);
|
|
2137
|
+
const notional = input.notional ?? 1;
|
|
2138
|
+
ensureFinite(notional, 'notional', functionName);
|
|
2139
|
+
return { q, coupon: input.coupon, globalFloor, notional, periods, maturity: prev };
|
|
2140
|
+
}
|
|
2141
|
+
const NAPOLEON_MC_INPUT_SPEC = specOf('napoleon.monteCarloPrice#0');
|
|
2142
|
+
const NAPOLEON_MC_OPTIONS_SPEC = specOf('napoleon.monteCarloPrice#1');
|
|
2143
|
+
const NAPOLEON_EXAMPLE = () => 'napoleon.monteCarloPrice({ spot: 100, resetTimes: [0.25, 0.5, 0.75, 1], riskFreeRate: 0.04, volatility: 0.2, coupon: 0.08 }, { paths: 20000, seed: 42 })';
|
|
2144
|
+
export const napoleon = {
|
|
2145
|
+
/**
|
|
2146
|
+
* Napoleon option: pays the coupon plus the **single worst** period return, `max(floor, C + minᵢ rᵢ)`.
|
|
2147
|
+
* The investor is SHORT the volatility of the minimum return — a higher `volatility` LOWERS the value. No clean
|
|
2148
|
+
* closed form (the minimum of `n` dependent lognormals), so Monte-Carlo only. See
|
|
2149
|
+
* `docs/specs/napoleon-reverse-cliquet.md`.
|
|
2150
|
+
*/
|
|
2151
|
+
monteCarloPrice(input, options) {
|
|
2152
|
+
const functionName = 'napoleon.monteCarloPrice';
|
|
2153
|
+
validateClosedRequest(functionName, input, NAPOLEON_MC_INPUT_SPEC, {
|
|
2154
|
+
exampleCall: NAPOLEON_EXAMPLE,
|
|
2155
|
+
});
|
|
2156
|
+
validateClosedRequest(functionName, options, NAPOLEON_MC_OPTIONS_SPEC, {
|
|
2157
|
+
exampleCall: NAPOLEON_EXAMPLE,
|
|
2158
|
+
argumentName: 'options',
|
|
2159
|
+
});
|
|
2160
|
+
const c = validateNapoleon(input, functionName);
|
|
2161
|
+
const { spot: S, riskFreeRate: r, volatility: sigma } = input;
|
|
2162
|
+
const df = Math.exp(-r * c.maturity);
|
|
2163
|
+
const payoff = (z) => {
|
|
2164
|
+
let prevSpot = S;
|
|
2165
|
+
let worst = Infinity;
|
|
2166
|
+
for (let i = 0; i < c.periods.length; i++) {
|
|
2167
|
+
const next = gbmTerminal({
|
|
2168
|
+
spot: prevSpot,
|
|
2169
|
+
riskFreeRate: r,
|
|
2170
|
+
dividendYield: c.q,
|
|
2171
|
+
volatility: sigma,
|
|
2172
|
+
timeToExpiryYears: c.periods[i],
|
|
2173
|
+
shock: z[i],
|
|
2174
|
+
});
|
|
2175
|
+
worst = Math.min(worst, next / prevSpot - 1);
|
|
2176
|
+
prevSpot = next;
|
|
2177
|
+
}
|
|
2178
|
+
return df * c.notional * Math.max(c.globalFloor, c.coupon + worst);
|
|
2179
|
+
};
|
|
2180
|
+
const est = monteCarloEstimate({
|
|
2181
|
+
dimensions: c.periods.length,
|
|
2182
|
+
payoff,
|
|
2183
|
+
options,
|
|
2184
|
+
controlVariate: undefined,
|
|
2185
|
+
label: functionName,
|
|
2186
|
+
});
|
|
2187
|
+
return {
|
|
2188
|
+
value: est.value,
|
|
2189
|
+
assumptions: assumptions(c.maturity, c.q, 'napoleon', 'napoleon-mc'),
|
|
2190
|
+
diagnostics: {
|
|
2191
|
+
engine: 'napoleon',
|
|
2192
|
+
method: `monte-carlo-${est.method}-short-worst-return-vol`,
|
|
2193
|
+
converged: est.converged,
|
|
2194
|
+
iterations: est.paths,
|
|
2195
|
+
warnings: est.warnings,
|
|
2196
|
+
},
|
|
2197
|
+
monteCarlo: monteCarloStatistics(est),
|
|
2198
|
+
};
|
|
2199
|
+
},
|
|
2200
|
+
};
|
|
2201
|
+
const REVERSE_CLIQUET_MC_INPUT_SPEC = specOf('reverseCliquet.monteCarloPrice#0');
|
|
2202
|
+
const REVERSE_CLIQUET_MC_OPTIONS_SPEC = specOf('reverseCliquet.monteCarloPrice#1');
|
|
2203
|
+
const REVERSE_CLIQUET_FLOORLESS_SPEC = specOf('reverseCliquet.floorlessValue#0');
|
|
2204
|
+
const REVERSE_CLIQUET_EXAMPLE = () => 'reverseCliquet.floorlessValue({ spot: 100, resetTimes: [0.25, 0.5, 0.75, 1], riskFreeRate: 0.04, volatility: 0.2, coupon: 0.08 })';
|
|
2205
|
+
export const reverseCliquet = {
|
|
2206
|
+
/**
|
|
2207
|
+
* Reverse cliquet: pays the coupon eroded by the **sum of the negative** period returns,
|
|
2208
|
+
* `max(floor, C + Σᵢ min(rᵢ, 0))`. Up-periods don't help, down-periods subtract — the investor is short
|
|
2209
|
+
* downside vol, so a higher `volatility` LOWERS the value. Path-dependent (the floored sum) ⇒ Monte-Carlo. See
|
|
2210
|
+
* `docs/specs/napoleon-reverse-cliquet.md`.
|
|
2211
|
+
*/
|
|
2212
|
+
monteCarloPrice(input, options) {
|
|
2213
|
+
const functionName = 'reverseCliquet.monteCarloPrice';
|
|
2214
|
+
validateClosedRequest(functionName, input, REVERSE_CLIQUET_MC_INPUT_SPEC, {
|
|
2215
|
+
exampleCall: REVERSE_CLIQUET_EXAMPLE,
|
|
2216
|
+
});
|
|
2217
|
+
validateClosedRequest(functionName, options, REVERSE_CLIQUET_MC_OPTIONS_SPEC, {
|
|
2218
|
+
exampleCall: REVERSE_CLIQUET_EXAMPLE,
|
|
2219
|
+
argumentName: 'options',
|
|
2220
|
+
});
|
|
2221
|
+
const c = validateNapoleon(input, functionName);
|
|
2222
|
+
const { spot: S, riskFreeRate: r, volatility: sigma } = input;
|
|
2223
|
+
const df = Math.exp(-r * c.maturity);
|
|
2224
|
+
const payoff = (z) => {
|
|
2225
|
+
let prevSpot = S;
|
|
2226
|
+
let acc = 0;
|
|
2227
|
+
for (let i = 0; i < c.periods.length; i++) {
|
|
2228
|
+
const next = gbmTerminal({
|
|
2229
|
+
spot: prevSpot,
|
|
2230
|
+
riskFreeRate: r,
|
|
2231
|
+
dividendYield: c.q,
|
|
2232
|
+
volatility: sigma,
|
|
2233
|
+
timeToExpiryYears: c.periods[i],
|
|
2234
|
+
shock: z[i],
|
|
2235
|
+
});
|
|
2236
|
+
acc += Math.min(next / prevSpot - 1, 0);
|
|
2237
|
+
prevSpot = next;
|
|
2238
|
+
}
|
|
2239
|
+
return df * c.notional * Math.max(c.globalFloor, c.coupon + acc);
|
|
2240
|
+
};
|
|
2241
|
+
const est = monteCarloEstimate({
|
|
2242
|
+
dimensions: c.periods.length,
|
|
2243
|
+
payoff,
|
|
2244
|
+
options,
|
|
2245
|
+
controlVariate: undefined,
|
|
2246
|
+
label: functionName,
|
|
2247
|
+
});
|
|
2248
|
+
return {
|
|
2249
|
+
value: est.value,
|
|
2250
|
+
assumptions: assumptions(c.maturity, c.q, 'reverse-cliquet', 'reverse-cliquet-mc'),
|
|
2251
|
+
diagnostics: {
|
|
2252
|
+
engine: 'reverse-cliquet',
|
|
2253
|
+
method: `monte-carlo-${est.method}-short-downside-vol`,
|
|
2254
|
+
converged: est.converged,
|
|
2255
|
+
iterations: est.paths,
|
|
2256
|
+
warnings: est.warnings,
|
|
2257
|
+
},
|
|
2258
|
+
monteCarlo: monteCarloStatistics(est),
|
|
2259
|
+
};
|
|
2260
|
+
},
|
|
2261
|
+
/**
|
|
2262
|
+
* Closed-form reverse-cliquet value **ignoring the global floor**: `df·notional·(C + Σᵢ E[min(rᵢ, 0)])`,
|
|
2263
|
+
* with `E[min(rᵢ, 0)] = (e^{b·τᵢ} − 1) − returnCaplet(1, τᵢ, b, σ)` (reusing the cliquet caplet). Exact for
|
|
2264
|
+
* an unfloored note (`globalFloor = −∞`) and a fast lower bound for the floored one (large coupon ⇒ the
|
|
2265
|
+
* floor rarely binds ⇒ this ≈ the MC price). See `docs/specs/napoleon-reverse-cliquet.md`.
|
|
2266
|
+
*/
|
|
2267
|
+
floorlessValue(input) {
|
|
2268
|
+
const functionName = 'reverseCliquet.floorlessValue';
|
|
2269
|
+
validateClosedRequest(functionName, input, REVERSE_CLIQUET_FLOORLESS_SPEC, {
|
|
2270
|
+
exampleCall: REVERSE_CLIQUET_EXAMPLE,
|
|
2271
|
+
});
|
|
2272
|
+
const c = validateNapoleon(input, functionName);
|
|
2273
|
+
const b = input.riskFreeRate - c.q;
|
|
2274
|
+
let expectedNeg = 0;
|
|
2275
|
+
for (const tau of c.periods) {
|
|
2276
|
+
// E[min(r,0)] = E[r] − E[max(r,0)] = (e^{bτ} − 1) − returnCaplet(1, τ, b, σ).
|
|
2277
|
+
expectedNeg +=
|
|
2278
|
+
Math.exp(b * tau) -
|
|
2279
|
+
1 -
|
|
2280
|
+
returnCaplet({ strike: 1, period: tau, carryRate: b, volatility: input.volatility });
|
|
2281
|
+
}
|
|
2282
|
+
const value = Math.exp(-input.riskFreeRate * c.maturity) * c.notional * (c.coupon + expectedNeg);
|
|
2283
|
+
return {
|
|
2284
|
+
value,
|
|
2285
|
+
assumptions: assumptions(c.maturity, c.q, 'reverse-cliquet', 'reverse-cliquet-floorless'),
|
|
2286
|
+
diagnostics: {
|
|
2287
|
+
engine: 'reverse-cliquet',
|
|
2288
|
+
method: 'closed-form-floorless-caplet-strip',
|
|
2289
|
+
converged: Number.isFinite(value),
|
|
2290
|
+
warnings: [],
|
|
2291
|
+
},
|
|
2292
|
+
};
|
|
2293
|
+
},
|
|
2294
|
+
};
|
|
2295
|
+
function validateDoubleTouch(input, functionName) {
|
|
2296
|
+
requireArgumentObject(functionName, 'input', input);
|
|
2297
|
+
ensurePositive(input.spot, 'spot', functionName);
|
|
2298
|
+
ensurePositive(input.lower, 'lower', functionName);
|
|
2299
|
+
ensurePositive(input.upper, 'upper', functionName);
|
|
2300
|
+
ensurePositive(input.timeToExpiryYears, 'timeToExpiryYears', functionName);
|
|
2301
|
+
ensurePositive(input.volatility, 'volatility', functionName);
|
|
2302
|
+
ensureFinite(input.riskFreeRate, 'riskFreeRate', functionName);
|
|
2303
|
+
if (!(input.lower < input.upper)) {
|
|
2304
|
+
throw new InputError(`${functionName}: require lower < upper (got lower=${input.lower}, upper=${input.upper}).`, { code: ErrorCode.InputOutOfRange, context: { lower: input.lower, upper: input.upper } });
|
|
2305
|
+
}
|
|
2306
|
+
const q = input.dividendYield ?? 0;
|
|
2307
|
+
ensureFinite(q, 'dividendYield', functionName);
|
|
2308
|
+
const cash = input.cash ?? 1;
|
|
2309
|
+
ensureFinite(cash, 'cash', functionName);
|
|
2310
|
+
return { q, cash };
|
|
2311
|
+
}
|
|
2312
|
+
function doubleBarrierSurvival(input) {
|
|
2313
|
+
const { spot: S, lower: L, upper: U, timeToExpiryYears: T, riskFreeRate: r, dividendYield: q, volatility: sigma, } = input;
|
|
2314
|
+
const a = Math.log(L / S);
|
|
2315
|
+
const b = Math.log(U / S);
|
|
2316
|
+
const nu = r - q - 0.5 * sigma * sigma;
|
|
2317
|
+
const sT = sigma * Math.sqrt(T);
|
|
2318
|
+
const d = b - a;
|
|
2319
|
+
const v2 = sigma * sigma;
|
|
2320
|
+
const term = (c) => Math.exp((nu * c) / v2) * (N((b - c - nu * T) / sT) - N((a - c - nu * T) / sT));
|
|
2321
|
+
let p = 0;
|
|
2322
|
+
for (let n = -25; n <= 25; n++)
|
|
2323
|
+
p += term(2 * n * d) - term(2 * b + 2 * n * d);
|
|
2324
|
+
return Math.min(1, Math.max(0, p));
|
|
2325
|
+
}
|
|
2326
|
+
/** Pure double-no-touch / double-one-touch value (shared by `doubleTouch.price` and `doubleTouch.greeks`). */
|
|
2327
|
+
function doubleTouchValue(input) {
|
|
2328
|
+
const { kind, spot: S, lower: L, upper: U, timeToExpiryYears: T, riskFreeRate: r, cash } = input;
|
|
2329
|
+
const df = Math.exp(-r * T);
|
|
2330
|
+
const survival = S <= L || S >= U ? 0 : doubleBarrierSurvival(input);
|
|
2331
|
+
return cash * df * (kind === 'double-no-touch' ? survival : 1 - survival);
|
|
2332
|
+
}
|
|
2333
|
+
const DOUBLE_TOUCH_PRICE_SPEC = specOf('doubleTouch.price#0');
|
|
2334
|
+
const DOUBLE_TOUCH_GREEKS_SPEC = specOf('doubleTouch.greeks#0');
|
|
2335
|
+
const DOUBLE_TOUCH_MC_INPUT_SPEC = specOf('doubleTouch.monteCarloPrice#0');
|
|
2336
|
+
const DOUBLE_TOUCH_MC_OPTIONS_SPEC = specOf('doubleTouch.monteCarloPrice#1');
|
|
2337
|
+
const DOUBLE_TOUCH_EXAMPLE = () => "doubleTouch.price({ kind: 'double-no-touch', spot: 100, lower: 90, upper: 115, timeToExpiryYears: 0.25, riskFreeRate: 0.04, volatility: 0.2 })";
|
|
2338
|
+
export const doubleTouch = {
|
|
2339
|
+
/**
|
|
2340
|
+
* Double no-touch (pays if `S` stays in `(L, U)` the whole life) / double one-touch (pays if it ever
|
|
2341
|
+
* leaves), continuous monitoring, settled at expiry. The image-series survival `P_stay` drives both:
|
|
2342
|
+
* `DNT = cash·e^{−rT}·P_stay`, `DOT = cash·e^{−rT}·(1 − P_stay)`, so `DNT + DOT = cash·e^{−rT}`. A spot
|
|
2343
|
+
* already outside the corridor short-circuits (DNT = 0, DOT = cash·e^{−rT}). See
|
|
2344
|
+
* `docs/specs/double-touch.md`.
|
|
2345
|
+
*/
|
|
2346
|
+
price(input) {
|
|
2347
|
+
const functionName = 'doubleTouch.price';
|
|
2348
|
+
validateClosedRequest(functionName, input, DOUBLE_TOUCH_PRICE_SPEC, {
|
|
2349
|
+
exampleCall: DOUBLE_TOUCH_EXAMPLE,
|
|
2350
|
+
});
|
|
2351
|
+
const { kind } = input;
|
|
2352
|
+
const { q, cash } = validateDoubleTouch(input, functionName);
|
|
2353
|
+
const { spot: S, lower: L, upper: U, timeToExpiryYears: T, riskFreeRate: r, volatility: sigma, } = input;
|
|
2354
|
+
const breached = S <= L || S >= U;
|
|
2355
|
+
const value = doubleTouchValue({
|
|
2356
|
+
kind,
|
|
2357
|
+
spot: S,
|
|
2358
|
+
lower: L,
|
|
2359
|
+
upper: U,
|
|
2360
|
+
timeToExpiryYears: T,
|
|
2361
|
+
riskFreeRate: r,
|
|
2362
|
+
dividendYield: q,
|
|
2363
|
+
volatility: sigma,
|
|
2364
|
+
cash,
|
|
2365
|
+
});
|
|
2366
|
+
return {
|
|
2367
|
+
value,
|
|
2368
|
+
assumptions: assumptions(input.timeToExpiryYears, q, 'double-touch', `double-touch-${kind}`),
|
|
2369
|
+
diagnostics: {
|
|
2370
|
+
engine: `double-touch-${kind}`,
|
|
2371
|
+
method: breached ? 'already-breached' : 'method-of-images',
|
|
2372
|
+
converged: Number.isFinite(value),
|
|
2373
|
+
warnings: [],
|
|
2374
|
+
},
|
|
2375
|
+
};
|
|
2376
|
+
},
|
|
2377
|
+
/**
|
|
2378
|
+
* First-order greeks (delta, gamma, vega, theta, rho) for the double-no-touch / double-one-touch corridor
|
|
2379
|
+
* binary, by central finite-difference of the exact `doubleTouch.price` (the image-series precludes clean
|
|
2380
|
+
* analytic greeks). Units match the package (vega/1%, theta/day, rho/1%; echoed in `assumptions.units`).
|
|
2381
|
+
* The spot bump is shrunk near either barrier so it never straddles the corridor edge. Pinned to the exact
|
|
2382
|
+
* `DNT + DOT = cash·e^{−rT}` greek identity. See `docs/specs/touch-greeks.md`.
|
|
2383
|
+
*/
|
|
2384
|
+
greeks(input) {
|
|
2385
|
+
const functionName = 'doubleTouch.greeks';
|
|
2386
|
+
validateClosedRequest(functionName, input, DOUBLE_TOUCH_GREEKS_SPEC, {
|
|
2387
|
+
exampleCall: DOUBLE_TOUCH_EXAMPLE,
|
|
2388
|
+
});
|
|
2389
|
+
const { kind } = input;
|
|
2390
|
+
const { q, cash } = validateDoubleTouch(input, functionName);
|
|
2391
|
+
const { spot: S, lower: L, upper: U, timeToExpiryYears: T, riskFreeRate: r, volatility: sigma, } = input;
|
|
2392
|
+
// Keep the spot bump inside the corridor (the value is discontinuous in regime across L and U); floor it
|
|
2393
|
+
// positive so a breached spot (S ≤ L or S ≥ U, where the distances go non-positive) still bumps validly.
|
|
2394
|
+
const spotStep = Math.max(S * 1e-6, Math.min(S * 1e-4, (S - L) * 0.25, (U - S) * 0.25));
|
|
2395
|
+
const greeks = fdBarrierGreeks({
|
|
2396
|
+
price: ({ spot, volatility, timeToExpiryYears, riskFreeRate }) => doubleTouchValue({
|
|
2397
|
+
kind,
|
|
2398
|
+
spot,
|
|
2399
|
+
lower: L,
|
|
2400
|
+
upper: U,
|
|
2401
|
+
timeToExpiryYears,
|
|
2402
|
+
riskFreeRate,
|
|
2403
|
+
dividendYield: q,
|
|
2404
|
+
volatility,
|
|
2405
|
+
cash,
|
|
2406
|
+
}),
|
|
2407
|
+
state: { spot: S, volatility: sigma, timeToExpiryYears: T, riskFreeRate: r },
|
|
2408
|
+
spotBump: spotStep,
|
|
2409
|
+
});
|
|
2410
|
+
return {
|
|
2411
|
+
value: greeks,
|
|
2412
|
+
assumptions: {
|
|
2413
|
+
...assumptions(input.timeToExpiryYears, q, 'double-touch', `double-touch-${kind}`),
|
|
2414
|
+
units: DEFAULT_GREEK_UNITS,
|
|
2415
|
+
},
|
|
2416
|
+
diagnostics: {
|
|
2417
|
+
engine: `double-touch-${kind}`,
|
|
2418
|
+
method: 'finite-difference',
|
|
2419
|
+
converged: Object.values(greeks).every((x) => Number.isFinite(x)),
|
|
2420
|
+
warnings: [],
|
|
2421
|
+
},
|
|
2422
|
+
};
|
|
2423
|
+
},
|
|
2424
|
+
/**
|
|
2425
|
+
* Monte-Carlo double-no-touch / double-one-touch. The corridor survival per path is the product of the
|
|
2426
|
+
* two single-barrier Brownian-bridge survivals (lower down × upper up), so discrete monitoring converges
|
|
2427
|
+
* to the continuous analytic.
|
|
2428
|
+
*/
|
|
2429
|
+
monteCarloPrice(input, options) {
|
|
2430
|
+
const functionName = 'doubleTouch.monteCarloPrice';
|
|
2431
|
+
validateClosedRequest(functionName, input, DOUBLE_TOUCH_MC_INPUT_SPEC, {
|
|
2432
|
+
exampleCall: DOUBLE_TOUCH_EXAMPLE,
|
|
2433
|
+
});
|
|
2434
|
+
validateClosedRequest(functionName, options, DOUBLE_TOUCH_MC_OPTIONS_SPEC, {
|
|
2435
|
+
exampleCall: DOUBLE_TOUCH_EXAMPLE,
|
|
2436
|
+
argumentName: 'options',
|
|
2437
|
+
});
|
|
2438
|
+
const { kind } = input;
|
|
2439
|
+
const { q, cash } = validateDoubleTouch(input, functionName);
|
|
2440
|
+
const { spot: S, lower: L, upper: U, timeToExpiryYears: T, riskFreeRate: r, volatility: sigma, } = input;
|
|
2441
|
+
const steps = options.steps ?? 100;
|
|
2442
|
+
const timeStepYears = T / steps;
|
|
2443
|
+
const df = Math.exp(-r * T);
|
|
2444
|
+
const payoff = (z) => {
|
|
2445
|
+
const path = gbmPathUnchecked({
|
|
2446
|
+
spot: S,
|
|
2447
|
+
riskFreeRate: r,
|
|
2448
|
+
dividendYield: q,
|
|
2449
|
+
volatility: sigma,
|
|
2450
|
+
timeToExpiryYears: T,
|
|
2451
|
+
shocks: z,
|
|
2452
|
+
});
|
|
2453
|
+
const surv = barrierSurvival({
|
|
2454
|
+
path,
|
|
2455
|
+
barrier: L,
|
|
2456
|
+
isDown: true,
|
|
2457
|
+
volatility: sigma,
|
|
2458
|
+
timeStepYears,
|
|
2459
|
+
}) *
|
|
2460
|
+
barrierSurvival({
|
|
2461
|
+
path,
|
|
2462
|
+
barrier: U,
|
|
2463
|
+
isDown: false,
|
|
2464
|
+
volatility: sigma,
|
|
2465
|
+
timeStepYears,
|
|
2466
|
+
});
|
|
2467
|
+
return df * cash * (kind === 'double-no-touch' ? surv : 1 - surv);
|
|
2468
|
+
};
|
|
2469
|
+
const est = monteCarloEstimate({
|
|
2470
|
+
dimensions: steps,
|
|
2471
|
+
payoff,
|
|
2472
|
+
options,
|
|
2473
|
+
controlVariate: undefined,
|
|
2474
|
+
label: functionName,
|
|
2475
|
+
});
|
|
2476
|
+
return {
|
|
2477
|
+
value: est.value,
|
|
2478
|
+
assumptions: assumptions(input.timeToExpiryYears, q, 'double-touch', `double-touch-${kind}-mc`),
|
|
2479
|
+
diagnostics: {
|
|
2480
|
+
engine: `double-touch-${kind}`,
|
|
2481
|
+
method: `monte-carlo-${est.method}-brownian-bridge`,
|
|
2482
|
+
converged: est.converged,
|
|
2483
|
+
iterations: est.paths,
|
|
2484
|
+
warnings: est.warnings,
|
|
2485
|
+
},
|
|
2486
|
+
monteCarlo: monteCarloStatistics(est),
|
|
2487
|
+
};
|
|
2488
|
+
},
|
|
2489
|
+
};
|
|
2490
|
+
/** Validate a compo input and return the composite spot `A₀`, composite vol `σ_A`, and yield `q`. */
|
|
2491
|
+
function resolveCompo(input, functionName) {
|
|
2492
|
+
requireArgumentObject(functionName, 'input', input);
|
|
2493
|
+
ensurePositive(input.spot, 'spot', functionName);
|
|
2494
|
+
ensurePositive(input.fxSpot, 'fxSpot', functionName);
|
|
2495
|
+
ensurePositive(input.strike, 'strike', functionName);
|
|
2496
|
+
ensurePositive(input.timeToExpiryYears, 'timeToExpiryYears', functionName);
|
|
2497
|
+
ensurePositive(input.volatility, 'volatility', functionName);
|
|
2498
|
+
ensureNonNegativeVolatility(input.fxVolatility, 'fxVolatility', functionName);
|
|
2499
|
+
ensureFinite(input.domesticRate, 'domesticRate', functionName);
|
|
2500
|
+
requireCorrelation(input.correlation, functionName);
|
|
2501
|
+
const q = input.dividendYield ?? 0;
|
|
2502
|
+
ensureFinite(q, 'dividendYield', functionName);
|
|
2503
|
+
const { volatility: sigS, fxVolatility: sigX, correlation: rho } = input;
|
|
2504
|
+
const varA = sigS * sigS + sigX * sigX + 2 * rho * sigS * sigX;
|
|
2505
|
+
const sigA = Math.sqrt(Math.max(0, varA));
|
|
2506
|
+
if (!(sigA > 0)) {
|
|
2507
|
+
throw new InputError(`${functionName}: the composite volatility is zero (the asset and FX perfectly offset: ρ = ${rho}, σ_S = ${sigS}, σ_X = ${sigX}) — the composite is riskless, price it as a domestic forward.`, {
|
|
2508
|
+
code: ErrorCode.InputOutOfRange,
|
|
2509
|
+
context: { correlation: rho, assetVolatility: sigS, fxVolatility: sigX },
|
|
2510
|
+
});
|
|
2511
|
+
}
|
|
2512
|
+
return { A0: input.spot * input.fxSpot, sigA, q };
|
|
2513
|
+
}
|
|
2514
|
+
const COMPO_PRICE_SPEC = specOf('compo.price#0');
|
|
2515
|
+
const COMPO_GREEKS_SPEC = specOf('compo.greeks#0');
|
|
2516
|
+
const COMPO_MC_INPUT_SPEC = specOf('compo.monteCarloPrice#0');
|
|
2517
|
+
const COMPO_MC_OPTIONS_SPEC = specOf('compo.monteCarloPrice#1');
|
|
2518
|
+
const COMPO_EXAMPLE = () => "compo.price({ type: 'call', spot: 50, fxSpot: 1.1, strike: 60, timeToExpiryYears: 0.25, domesticRate: 0.04, volatility: 0.2, fxVolatility: 0.1, correlation: 0.3 })";
|
|
2519
|
+
export const compo = {
|
|
2520
|
+
/**
|
|
2521
|
+
* Composite option paying `(S_f(T)·X(T) − K_d)⁺` in domestic currency — the foreign asset at the
|
|
2522
|
+
* FLOATING FX rate against a domestic strike. The domestic value `A = S_f·X` is a domestic asset
|
|
2523
|
+
* drifting at `r_d − q`, so this is exactly `BSM(A₀ = S_f·X, K_d, T, r_d, q, σ_A)` with the composite
|
|
2524
|
+
* vol `σ_A = √(σ_S² + σ_X² + 2ρσ_Sσ_X)`. The foreign rate drops out. See `docs/specs/compo-option.md`.
|
|
2525
|
+
*/
|
|
2526
|
+
price(input) {
|
|
2527
|
+
const functionName = 'compo.price';
|
|
2528
|
+
validateClosedRequest(functionName, input, COMPO_PRICE_SPEC, { exampleCall: COMPO_EXAMPLE });
|
|
2529
|
+
const { type } = input;
|
|
2530
|
+
const { A0, sigA, q } = resolveCompo(input, functionName);
|
|
2531
|
+
const value = blackScholesPrice({
|
|
2532
|
+
type,
|
|
2533
|
+
spot: A0,
|
|
2534
|
+
strike: input.strike,
|
|
2535
|
+
timeToExpiryYears: input.timeToExpiryYears,
|
|
2536
|
+
riskFreeRate: input.domesticRate,
|
|
2537
|
+
dividendYield: q,
|
|
2538
|
+
volatility: sigA,
|
|
2539
|
+
});
|
|
2540
|
+
return {
|
|
2541
|
+
value,
|
|
2542
|
+
assumptions: assumptions(input.timeToExpiryYears, q, 'compo', 'compo'),
|
|
2543
|
+
diagnostics: {
|
|
2544
|
+
engine: 'compo',
|
|
2545
|
+
method: 'closed-form',
|
|
2546
|
+
converged: Number.isFinite(value),
|
|
2547
|
+
warnings: [],
|
|
2548
|
+
},
|
|
2549
|
+
};
|
|
2550
|
+
},
|
|
2551
|
+
/**
|
|
2552
|
+
* The compo's multi-factor risk: foreign-asset and FX deltas, foreign-asset gamma, the asset and FX
|
|
2553
|
+
* vegas, the **correlation vega** (a compo is long correlation), plus theta and domestic rho — all
|
|
2554
|
+
* exact chain-rule derivatives of the composite BSM greeks through `A₀ = S_f·X` and `σ_A`.
|
|
2555
|
+
*/
|
|
2556
|
+
greeks(input) {
|
|
2557
|
+
const functionName = 'compo.greeks';
|
|
2558
|
+
validateClosedRequest(functionName, input, COMPO_GREEKS_SPEC, { exampleCall: COMPO_EXAMPLE });
|
|
2559
|
+
const { type } = input;
|
|
2560
|
+
const { A0, sigA, q } = resolveCompo(input, functionName);
|
|
2561
|
+
const { spot: S, fxSpot: X, volatility: sigS, fxVolatility: sigX, correlation: rho } = input;
|
|
2562
|
+
const bg = blackScholesGreeks({
|
|
2563
|
+
type,
|
|
2564
|
+
spot: A0,
|
|
2565
|
+
strike: input.strike,
|
|
2566
|
+
timeToExpiryYears: input.timeToExpiryYears,
|
|
2567
|
+
riskFreeRate: input.domesticRate,
|
|
2568
|
+
dividendYield: q,
|
|
2569
|
+
volatility: sigA,
|
|
2570
|
+
});
|
|
2571
|
+
const greeks = {
|
|
2572
|
+
assetDelta: bg.delta * X,
|
|
2573
|
+
fxDelta: bg.delta * S,
|
|
2574
|
+
assetGamma: bg.gamma * X * X,
|
|
2575
|
+
assetVega: bg.vega * ((sigS + rho * sigX) / sigA),
|
|
2576
|
+
fxVega: bg.vega * ((sigX + rho * sigS) / sigA),
|
|
2577
|
+
correlationVega: bg.vega * ((sigS * sigX) / sigA),
|
|
2578
|
+
theta: bg.theta,
|
|
2579
|
+
rho: bg.rho,
|
|
2580
|
+
};
|
|
2581
|
+
return {
|
|
2582
|
+
value: greeks,
|
|
2583
|
+
assumptions: {
|
|
2584
|
+
...assumptions(input.timeToExpiryYears, q, 'compo', 'compo'),
|
|
2585
|
+
units: DEFAULT_GREEK_UNITS,
|
|
2586
|
+
},
|
|
2587
|
+
diagnostics: {
|
|
2588
|
+
engine: 'compo',
|
|
2589
|
+
method: 'closed-form-greeks',
|
|
2590
|
+
converged: Object.values(greeks).every((x) => Number.isFinite(x)),
|
|
2591
|
+
warnings: [],
|
|
2592
|
+
},
|
|
2593
|
+
};
|
|
2594
|
+
},
|
|
2595
|
+
/**
|
|
2596
|
+
* Two-factor Monte-Carlo: simulate `S_f` and `X` as correlated GBMs under the domestic measure and
|
|
2597
|
+
* price `(S_f(T)·X(T) − K)⁺` discounted at `r_d`. Converges to the closed form, corroborating the `σ_A`
|
|
2598
|
+
* combination. `options.foreignRate` (default `domesticRate`) only splits the two drifts — the price is
|
|
2599
|
+
* invariant to it.
|
|
2600
|
+
*/
|
|
2601
|
+
monteCarloPrice(input, options) {
|
|
2602
|
+
const functionName = 'compo.monteCarloPrice';
|
|
2603
|
+
validateClosedRequest(functionName, input, COMPO_MC_INPUT_SPEC, {
|
|
2604
|
+
exampleCall: COMPO_EXAMPLE,
|
|
2605
|
+
});
|
|
2606
|
+
validateClosedRequest(functionName, options, COMPO_MC_OPTIONS_SPEC, {
|
|
2607
|
+
exampleCall: COMPO_EXAMPLE,
|
|
2608
|
+
argumentName: 'options',
|
|
2609
|
+
});
|
|
2610
|
+
const { type } = input;
|
|
2611
|
+
const { q } = resolveCompo(input, functionName);
|
|
2612
|
+
const { spot: S, fxSpot: X, strike: K, timeToExpiryYears: T, domesticRate: rd, volatility: sigS, fxVolatility: sigX, correlation: rho, } = input;
|
|
2613
|
+
const rf = options.foreignRate ?? rd;
|
|
2614
|
+
ensureFinite(rf, 'foreignRate', functionName);
|
|
2615
|
+
const sq = Math.sqrt(T);
|
|
2616
|
+
const df = Math.exp(-rd * T);
|
|
2617
|
+
// Q_d drifts: S_f at (r_f − q − ρσ_Sσ_X), X at (r_d − r_f).
|
|
2618
|
+
const drift1 = (rf - q - rho * sigS * sigX - 0.5 * sigS * sigS) * T;
|
|
2619
|
+
const drift2 = (rd - rf - 0.5 * sigX * sigX) * T;
|
|
2620
|
+
const payoff = (z) => {
|
|
2621
|
+
const w1 = z[0];
|
|
2622
|
+
const w2 = rho * z[0] + Math.sqrt(1 - rho * rho) * z[1];
|
|
2623
|
+
const sT = S * Math.exp(drift1 + sigS * sq * w1);
|
|
2624
|
+
const xT = X * Math.exp(drift2 + sigX * sq * w2);
|
|
2625
|
+
const composite = sT * xT;
|
|
2626
|
+
const intrinsic = type === 'call' ? Math.max(composite - K, 0) : Math.max(K - composite, 0);
|
|
2627
|
+
return df * intrinsic;
|
|
2628
|
+
};
|
|
2629
|
+
const est = monteCarloEstimate({
|
|
2630
|
+
dimensions: 2,
|
|
2631
|
+
payoff,
|
|
2632
|
+
options,
|
|
2633
|
+
controlVariate: undefined,
|
|
2634
|
+
label: functionName,
|
|
2635
|
+
});
|
|
2636
|
+
return {
|
|
2637
|
+
value: est.value,
|
|
2638
|
+
assumptions: assumptions(T, q, 'compo', 'compo-mc'),
|
|
2639
|
+
diagnostics: {
|
|
2640
|
+
engine: 'compo',
|
|
2641
|
+
method: `monte-carlo-${est.method}-two-factor`,
|
|
2642
|
+
converged: est.converged,
|
|
2643
|
+
iterations: est.paths,
|
|
2644
|
+
warnings: est.warnings,
|
|
2645
|
+
},
|
|
2646
|
+
monteCarlo: monteCarloStatistics(est),
|
|
2647
|
+
};
|
|
2648
|
+
},
|
|
2649
|
+
};
|
|
2650
|
+
/** Validate an inverse-option input and return the resolved coin yield. */
|
|
2651
|
+
function resolveInverse(input, functionName) {
|
|
2652
|
+
requireArgumentObject(functionName, 'input', input);
|
|
2653
|
+
ensurePositive(input.spot, 'spot', functionName);
|
|
2654
|
+
ensurePositive(input.strike, 'strike', functionName);
|
|
2655
|
+
ensurePositive(input.timeToExpiryYears, 'timeToExpiryYears', functionName);
|
|
2656
|
+
ensurePositive(input.volatility, 'volatility', functionName);
|
|
2657
|
+
ensureFinite(input.riskFreeRate, 'riskFreeRate', functionName);
|
|
2658
|
+
const q = input.coinYield ?? 0;
|
|
2659
|
+
ensureFinite(q, 'coinYield', functionName);
|
|
2660
|
+
return { q };
|
|
2661
|
+
}
|
|
2662
|
+
const INVERSE_PRICE_SPEC = specOf('inverseOption.price#0');
|
|
2663
|
+
const INVERSE_GREEKS_SPEC = specOf('inverseOption.greeks#0');
|
|
2664
|
+
const INVERSE_MC_INPUT_SPEC = specOf('inverseOption.monteCarloPrice#0');
|
|
2665
|
+
const INVERSE_MC_OPTIONS_SPEC = specOf('inverseOption.monteCarloPrice#1');
|
|
2666
|
+
const INVERSE_DIGITAL_SPEC = specOf('inverseOption.digital#0');
|
|
2667
|
+
const INVERSE_BARRIER_SPEC = specOf('inverseOption.barrier#0');
|
|
2668
|
+
const INVERSE_EXAMPLE = () => "inverseOption.price({ type: 'call', spot: 60000, strike: 65000, timeToExpiryYears: 0.25, riskFreeRate: 0.04, volatility: 0.6 })";
|
|
2669
|
+
export const inverseOption = {
|
|
2670
|
+
/**
|
|
2671
|
+
* The **coin (base-currency) premium** of a Deribit-style inverse option, settling `(±(S_T−K))⁺/S_T` in
|
|
2672
|
+
* the coin. The USD payoff is a vanilla's, so the coin premium is exactly `blackScholesPrice/spot`. `value·spot`
|
|
2673
|
+
* recovers the USD premium. `rate` is the USD/quote rate; `coinYield` the coin lending/staking yield.
|
|
2674
|
+
* See `docs/specs/inverse-option.md`.
|
|
2675
|
+
*/
|
|
2676
|
+
price(input) {
|
|
2677
|
+
const functionName = 'inverseOption.price';
|
|
2678
|
+
validateClosedRequest(functionName, input, INVERSE_PRICE_SPEC, {
|
|
2679
|
+
exampleCall: INVERSE_EXAMPLE,
|
|
2680
|
+
});
|
|
2681
|
+
const { type } = input;
|
|
2682
|
+
const { q } = resolveInverse(input, functionName);
|
|
2683
|
+
const vUsd = blackScholesPrice({
|
|
2684
|
+
type,
|
|
2685
|
+
spot: input.spot,
|
|
2686
|
+
strike: input.strike,
|
|
2687
|
+
timeToExpiryYears: input.timeToExpiryYears,
|
|
2688
|
+
riskFreeRate: input.riskFreeRate,
|
|
2689
|
+
dividendYield: q,
|
|
2690
|
+
volatility: input.volatility,
|
|
2691
|
+
});
|
|
2692
|
+
const value = vUsd / input.spot;
|
|
2693
|
+
return {
|
|
2694
|
+
value,
|
|
2695
|
+
assumptions: assumptions(input.timeToExpiryYears, q, 'inverse', 'inverse'),
|
|
2696
|
+
diagnostics: {
|
|
2697
|
+
engine: 'inverse',
|
|
2698
|
+
method: 'closed-form-coin-premium',
|
|
2699
|
+
converged: Number.isFinite(value),
|
|
2700
|
+
warnings: [],
|
|
2701
|
+
},
|
|
2702
|
+
};
|
|
2703
|
+
},
|
|
2704
|
+
/**
|
|
2705
|
+
* The inverse option's risk in **both** denominations. The `coin` greeks are the exact derivatives of
|
|
2706
|
+
* the coin premium `V_usd/S`: delta and gamma carry the numeraire corrections (`Δ_coin = Δ_usd/S −
|
|
2707
|
+
* V_usd/S²`, `Γ_coin = Γ_usd/S − 2Δ_usd/S² + 2V_usd/S³`), while vega/theta/rho scale by `1/S`. The `usd`
|
|
2708
|
+
* greeks equal the vanilla BSM greeks. The `−V_coin/S` delta term is the embedded short-coin from the
|
|
2709
|
+
* coin-denominated premium — an inverse option is NOT hedged at its Black–Scholes delta.
|
|
2710
|
+
*/
|
|
2711
|
+
greeks(input) {
|
|
2712
|
+
const functionName = 'inverseOption.greeks';
|
|
2713
|
+
validateClosedRequest(functionName, input, INVERSE_GREEKS_SPEC, {
|
|
2714
|
+
exampleCall: INVERSE_EXAMPLE,
|
|
2715
|
+
});
|
|
2716
|
+
const { type } = input;
|
|
2717
|
+
const { q } = resolveInverse(input, functionName);
|
|
2718
|
+
const { spot: S, strike: K, timeToExpiryYears: T, riskFreeRate: r, volatility } = input;
|
|
2719
|
+
const usd = blackScholesGreeks({
|
|
2720
|
+
type,
|
|
2721
|
+
spot: S,
|
|
2722
|
+
strike: K,
|
|
2723
|
+
timeToExpiryYears: T,
|
|
2724
|
+
riskFreeRate: r,
|
|
2725
|
+
dividendYield: q,
|
|
2726
|
+
volatility,
|
|
2727
|
+
});
|
|
2728
|
+
const vUsd = blackScholesPrice({
|
|
2729
|
+
type,
|
|
2730
|
+
spot: S,
|
|
2731
|
+
strike: K,
|
|
2732
|
+
timeToExpiryYears: T,
|
|
2733
|
+
riskFreeRate: r,
|
|
2734
|
+
dividendYield: q,
|
|
2735
|
+
volatility,
|
|
2736
|
+
});
|
|
2737
|
+
const coin = {
|
|
2738
|
+
delta: usd.delta / S - vUsd / (S * S),
|
|
2739
|
+
gamma: usd.gamma / S - (2 * usd.delta) / (S * S) + (2 * vUsd) / (S * S * S),
|
|
2740
|
+
vega: usd.vega / S,
|
|
2741
|
+
theta: usd.theta / S,
|
|
2742
|
+
rho: usd.rho / S,
|
|
2743
|
+
};
|
|
2744
|
+
const finite = (g) => Object.values(g).every((x) => Number.isFinite(x));
|
|
2745
|
+
return {
|
|
2746
|
+
value: { coin, usd },
|
|
2747
|
+
assumptions: { ...assumptions(T, q, 'inverse', 'inverse'), units: DEFAULT_GREEK_UNITS },
|
|
2748
|
+
diagnostics: {
|
|
2749
|
+
engine: 'inverse',
|
|
2750
|
+
method: 'closed-form-greeks',
|
|
2751
|
+
converged: finite(coin) && finite(usd),
|
|
2752
|
+
warnings: [],
|
|
2753
|
+
},
|
|
2754
|
+
};
|
|
2755
|
+
},
|
|
2756
|
+
/**
|
|
2757
|
+
* One-factor **coin-numeraire** Monte-Carlo: under the coin money-market numeraire the spot drifts at the
|
|
2758
|
+
* self-quanto rate `r − q + σ²`, and the coin premium is `E[e^{−qT}·(±(S_T−K))⁺/S_T]`. Converges to the
|
|
2759
|
+
* closed-form coin premium, corroborating the `V_usd/S` identity from the other measure.
|
|
2760
|
+
*/
|
|
2761
|
+
monteCarloPrice(input, options) {
|
|
2762
|
+
const functionName = 'inverseOption.monteCarloPrice';
|
|
2763
|
+
validateClosedRequest(functionName, input, INVERSE_MC_INPUT_SPEC, {
|
|
2764
|
+
exampleCall: INVERSE_EXAMPLE,
|
|
2765
|
+
});
|
|
2766
|
+
validateClosedRequest(functionName, options, INVERSE_MC_OPTIONS_SPEC, {
|
|
2767
|
+
exampleCall: INVERSE_EXAMPLE,
|
|
2768
|
+
argumentName: 'options',
|
|
2769
|
+
});
|
|
2770
|
+
const { type } = input;
|
|
2771
|
+
const { q } = resolveInverse(input, functionName);
|
|
2772
|
+
const { spot: S, strike: K, timeToExpiryYears: T, riskFreeRate: r, volatility } = input;
|
|
2773
|
+
const dq = Math.exp(-q * T);
|
|
2774
|
+
// Coin-measure drift r − q + σ²: fold the +σ² into gbmTerminal's rate argument.
|
|
2775
|
+
const payoff = (z) => {
|
|
2776
|
+
const sT = gbmTerminal({
|
|
2777
|
+
spot: S,
|
|
2778
|
+
riskFreeRate: r + volatility * volatility,
|
|
2779
|
+
dividendYield: q,
|
|
2780
|
+
volatility,
|
|
2781
|
+
timeToExpiryYears: T,
|
|
2782
|
+
shock: z[0],
|
|
2783
|
+
});
|
|
2784
|
+
const intrinsic = type === 'call' ? Math.max(sT - K, 0) : Math.max(K - sT, 0);
|
|
2785
|
+
return (dq * intrinsic) / sT;
|
|
2786
|
+
};
|
|
2787
|
+
const est = monteCarloEstimate({
|
|
2788
|
+
dimensions: 1,
|
|
2789
|
+
payoff,
|
|
2790
|
+
options,
|
|
2791
|
+
controlVariate: undefined,
|
|
2792
|
+
label: functionName,
|
|
2793
|
+
});
|
|
2794
|
+
return {
|
|
2795
|
+
value: est.value,
|
|
2796
|
+
assumptions: assumptions(T, q, 'inverse', 'inverse-mc'),
|
|
2797
|
+
diagnostics: {
|
|
2798
|
+
engine: 'inverse',
|
|
2799
|
+
method: `monte-carlo-${est.method}-coin-numeraire`,
|
|
2800
|
+
converged: est.converged,
|
|
2801
|
+
iterations: est.paths,
|
|
2802
|
+
warnings: est.warnings,
|
|
2803
|
+
},
|
|
2804
|
+
monteCarlo: monteCarloStatistics(est),
|
|
2805
|
+
};
|
|
2806
|
+
},
|
|
2807
|
+
/**
|
|
2808
|
+
* The **coin premium** of a coin-settled (inverse) **binary**. Every coin-settled exotic obeys the same
|
|
2809
|
+
* universal identity as the vanilla: a coin payoff `H(S_T)/S_T` is worth `H(S_T)` USD at expiry (1 coin =
|
|
2810
|
+
* `S_T` USD then), so its USD price is the vanilla's and its coin premium is exactly `vanillaUsd/spot`.
|
|
2811
|
+
* A `cash-or-nothing` therefore settles its `cash` USD-equivalent in the coin, an `asset-or-nothing`
|
|
2812
|
+
* settles 1 coin if in-the-money. `value·spot` recovers the USD premium. See `docs/specs/inverse-option.md`.
|
|
2813
|
+
*/
|
|
2814
|
+
digital(input) {
|
|
2815
|
+
const functionName = 'inverseOption.digital';
|
|
2816
|
+
validateClosedRequest(functionName, input, INVERSE_DIGITAL_SPEC, {
|
|
2817
|
+
exampleCall: INVERSE_EXAMPLE,
|
|
2818
|
+
});
|
|
2819
|
+
const { type, kind } = input;
|
|
2820
|
+
const { q } = resolveInverse(input, functionName);
|
|
2821
|
+
const usd = digital.price({
|
|
2822
|
+
type,
|
|
2823
|
+
kind,
|
|
2824
|
+
spot: input.spot,
|
|
2825
|
+
strike: input.strike,
|
|
2826
|
+
timeToExpiryYears: input.timeToExpiryYears,
|
|
2827
|
+
riskFreeRate: input.riskFreeRate,
|
|
2828
|
+
volatility: input.volatility,
|
|
2829
|
+
dividendYield: q,
|
|
2830
|
+
...(input.cash !== undefined ? { cash: input.cash } : {}),
|
|
2831
|
+
}).value;
|
|
2832
|
+
const value = usd / input.spot;
|
|
2833
|
+
return {
|
|
2834
|
+
value,
|
|
2835
|
+
assumptions: assumptions(input.timeToExpiryYears, q, 'inverse', 'inverse-digital'),
|
|
2836
|
+
diagnostics: {
|
|
2837
|
+
engine: 'inverse-digital',
|
|
2838
|
+
method: 'closed-form-coin-premium',
|
|
2839
|
+
converged: Number.isFinite(value),
|
|
2840
|
+
warnings: [],
|
|
2841
|
+
},
|
|
2842
|
+
};
|
|
2843
|
+
},
|
|
2844
|
+
/**
|
|
2845
|
+
* The **coin premium** of a coin-settled (inverse) **barrier** (continuous monitoring, zero rebate). By the
|
|
2846
|
+
* same universal identity, the coin premium is the vanilla barrier's USD price divided by spot. `value·spot`
|
|
2847
|
+
* recovers the USD premium. See `docs/specs/inverse-option.md`.
|
|
2848
|
+
*/
|
|
2849
|
+
barrier(input) {
|
|
2850
|
+
const functionName = 'inverseOption.barrier';
|
|
2851
|
+
validateClosedRequest(functionName, input, INVERSE_BARRIER_SPEC, {
|
|
2852
|
+
exampleCall: INVERSE_EXAMPLE,
|
|
2853
|
+
});
|
|
2854
|
+
const { type, barrierType } = input;
|
|
2855
|
+
const { q } = resolveInverse(input, functionName);
|
|
2856
|
+
const usd = barrier.price({
|
|
2857
|
+
type,
|
|
2858
|
+
barrierType,
|
|
2859
|
+
spot: input.spot,
|
|
2860
|
+
strike: input.strike,
|
|
2861
|
+
barrier: input.barrier,
|
|
2862
|
+
timeToExpiryYears: input.timeToExpiryYears,
|
|
2863
|
+
riskFreeRate: input.riskFreeRate,
|
|
2864
|
+
volatility: input.volatility,
|
|
2865
|
+
dividendYield: q,
|
|
2866
|
+
}).value;
|
|
2867
|
+
const value = usd / input.spot;
|
|
2868
|
+
return {
|
|
2869
|
+
value,
|
|
2870
|
+
assumptions: assumptions(input.timeToExpiryYears, q, 'inverse', 'inverse-barrier'),
|
|
2871
|
+
diagnostics: {
|
|
2872
|
+
engine: 'inverse-barrier',
|
|
2873
|
+
method: 'closed-form-coin-premium',
|
|
2874
|
+
converged: Number.isFinite(value),
|
|
2875
|
+
warnings: [],
|
|
2876
|
+
},
|
|
2877
|
+
};
|
|
2878
|
+
},
|
|
2879
|
+
};
|
|
2880
|
+
//# sourceMappingURL=exotics.js.map
|