@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,2240 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The chain-driven options-strategy backtest engine over a position BOOK (Stage 4.6, FC8 Decision 5).
|
|
3
|
+
*
|
|
4
|
+
* Composes proven primitives — `strategyFromChain` and the calendar/diagonal constructors (entry),
|
|
5
|
+
* `Position.value()` (marking + per-leg greeks), `optionsMargin` / `aggregateGreeks` / `scenarioGrid`
|
|
6
|
+
* (sizing and the pre-trade limits) — over a time series of `ChainSnapshot`s. Several rules may hold
|
|
7
|
+
* several trades at once; every fill, settlement, and adjustment is a portfolio-ledger event and the
|
|
8
|
+
* reported equity reconciles to the ledger's NAV. No look-ahead (each snapshot sees only its own
|
|
9
|
+
* chain), no silent degradation (an unbuildable entry discloses and skips; a rejected entry is a row),
|
|
10
|
+
* and every result carries the `assumptions` + `diagnostics` envelope. With one rule and the default
|
|
11
|
+
* book of one, the engine is exactly the shipped single-position backtester.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
validateClosedRequest,
|
|
16
|
+
CONVENTIONS_VERSION,
|
|
17
|
+
ErrorCode,
|
|
18
|
+
InputError,
|
|
19
|
+
type EpochMs,
|
|
20
|
+
type PriceSource,
|
|
21
|
+
type QuantWarning,
|
|
22
|
+
formatOccSymbol,
|
|
23
|
+
isQuantError,
|
|
24
|
+
isoDateToEpochMs,
|
|
25
|
+
optionExpiryToMs,
|
|
26
|
+
yearFraction,
|
|
27
|
+
sideOf,
|
|
28
|
+
type OrderSide,
|
|
29
|
+
WarningCode,
|
|
30
|
+
} from '@totalfinance/core';
|
|
31
|
+
import type { ClosedRequestSpecification, OptionQuote } from '@totalfinance/core';
|
|
32
|
+
import { contentHash, createMarketSnapshot } from '@totalfinance/core/artifacts';
|
|
33
|
+
import { VALIDATION_SPECS } from '../generated/validation-specs.js';
|
|
34
|
+
import { selectQuotePrice } from '@totalfinance/options';
|
|
35
|
+
import { blackScholesImpliedVolatility } from '@totalfinance/options/black-scholes';
|
|
36
|
+
import { Position, type Leg } from '@totalfinance/strategy';
|
|
37
|
+
import {
|
|
38
|
+
aggregateGreeks,
|
|
39
|
+
explainPositionPnl,
|
|
40
|
+
optionsMargin,
|
|
41
|
+
scenarioGrid,
|
|
42
|
+
type OptionMarginLeg,
|
|
43
|
+
type PnlMarket,
|
|
44
|
+
} from '@totalfinance/risk';
|
|
45
|
+
import { analyze } from '@totalfinance/performance';
|
|
46
|
+
import {
|
|
47
|
+
PORTFOLIO_EVENT_SCHEMA_VERSION,
|
|
48
|
+
applyPortfolioEvents,
|
|
49
|
+
createPortfolioLedger,
|
|
50
|
+
portfolioEventsFromFill,
|
|
51
|
+
portfolioSnapshot,
|
|
52
|
+
portfolioTimeline,
|
|
53
|
+
type NormalizedFill,
|
|
54
|
+
type PortfolioEventEnvelope,
|
|
55
|
+
type PortfolioState,
|
|
56
|
+
type PortfolioTimelineResult,
|
|
57
|
+
type PortfolioValuationMark,
|
|
58
|
+
} from '@totalfinance/portfolio';
|
|
59
|
+
import { type CostModel, type SlippageModel, fees, slippage as slippageModels } from '../costs.js';
|
|
60
|
+
import { toEquityPoints, type EquityPoint, type OptionSettlement } from '../types.js';
|
|
61
|
+
import { buildEntryPosition, daysToExpiry, requireSnapshot, snapshotAsOf } from './chain.js';
|
|
62
|
+
import type {
|
|
63
|
+
AppliedMarkingPolicy,
|
|
64
|
+
ChainSnapshot,
|
|
65
|
+
DividendRiskRow,
|
|
66
|
+
EntryContext,
|
|
67
|
+
EntryRule,
|
|
68
|
+
ExitContext,
|
|
69
|
+
ExitReason,
|
|
70
|
+
ExitRule,
|
|
71
|
+
FillRejection,
|
|
72
|
+
LegAttribution,
|
|
73
|
+
LimitRejection,
|
|
74
|
+
MarkSource,
|
|
75
|
+
MissingMarkCause,
|
|
76
|
+
OpenTradeView,
|
|
77
|
+
OptionsBacktestConfig,
|
|
78
|
+
OptionsBacktestResult,
|
|
79
|
+
OptionsTrade,
|
|
80
|
+
PortfolioLimits,
|
|
81
|
+
SurfaceRow,
|
|
82
|
+
TradeLineage,
|
|
83
|
+
TradeMarkCounts,
|
|
84
|
+
TradePnlExplain,
|
|
85
|
+
UnfilledLeg,
|
|
86
|
+
} from './types.js';
|
|
87
|
+
|
|
88
|
+
const FN = 'optionsBacktest';
|
|
89
|
+
const ACCOUNT_ID = 'main';
|
|
90
|
+
const DAY_MS = 86_400_000;
|
|
91
|
+
const RECONCILIATION_TOLERANCE = 1e-9;
|
|
92
|
+
|
|
93
|
+
/** A quote's identity for order-invariant hashing: the contract it prices and its print time. */
|
|
94
|
+
const quoteIdentityKey = (q: OptionQuote): string =>
|
|
95
|
+
`${q.contract.expiry}|${q.contract.strike}|${q.contract.type}|${q.contract.underlying ?? ''}|${q.timestampMs ?? ''}`;
|
|
96
|
+
/** Decision 9: open positions one book may hold. */
|
|
97
|
+
export const OPTIONS_BOOK_CEILING = 10_000;
|
|
98
|
+
|
|
99
|
+
/** Generated closed-request spec (3B.1b): the allowlist tree projected from the declaration. */
|
|
100
|
+
function specOf(key: string): ClosedRequestSpecification {
|
|
101
|
+
const spec = VALIDATION_SPECS[key];
|
|
102
|
+
if (spec === undefined) {
|
|
103
|
+
throw new Error(
|
|
104
|
+
`optionsBacktest: no generated validation spec for '${key}' — run \`pnpm validation:update\``,
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
return spec;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const OPTIONS_BACKTEST_SPEC = specOf('optionsBacktest#0');
|
|
111
|
+
|
|
112
|
+
/** One leg of an open trade with its ledger identity and mark memory. */
|
|
113
|
+
interface TradeLeg {
|
|
114
|
+
leg: Leg;
|
|
115
|
+
/** Index in the trade's ORIGINAL leg list (the `legs` a trade row reports). */
|
|
116
|
+
originalIndex: number;
|
|
117
|
+
instrumentId: string;
|
|
118
|
+
entryVolatility: number | undefined;
|
|
119
|
+
lastVolatility: number | undefined;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
interface OpenTrade {
|
|
123
|
+
tradeId: number;
|
|
124
|
+
ruleId: string;
|
|
125
|
+
ruleIndex: number;
|
|
126
|
+
underlying: string;
|
|
127
|
+
structure: string;
|
|
128
|
+
/** The live position — the legs not yet settled. */
|
|
129
|
+
position: Position;
|
|
130
|
+
/** The live legs, aligned to `position.legs`. */
|
|
131
|
+
live: TradeLeg[];
|
|
132
|
+
/** Every leg the trade ever held, in original order. */
|
|
133
|
+
originalLegs: Leg[];
|
|
134
|
+
originalInstrumentIds: string[];
|
|
135
|
+
entryAsOf: EpochMs;
|
|
136
|
+
/** Signed net premium at entry (positive debit / negative credit), account currency. */
|
|
137
|
+
entryPremium: number;
|
|
138
|
+
contracts: number;
|
|
139
|
+
entryCosts: number;
|
|
140
|
+
/** Underlying spot at entry — the anchor for the trade's greek P&L explain (entry → exit). */
|
|
141
|
+
entrySpot: number;
|
|
142
|
+
/** Position-level ATM vol at entry (fallback for legs without their own IV); `undefined` when the
|
|
143
|
+
* entry chain carried no IV and every leg priced off its own. */
|
|
144
|
+
entryVolatility: number | undefined;
|
|
145
|
+
/** The current-snapshot marks of this trade, computed once per snapshot (Preview P1). */
|
|
146
|
+
markCache: { snap: ChainSnapshot; legVolatilities: (number | undefined)[] } | null;
|
|
147
|
+
marks: TradeMarkCounts;
|
|
148
|
+
/** Fallback leg-snapshots per cause, for the one-warning-per-cause disclosure at close. */
|
|
149
|
+
fallbacks: Map<MissingMarkCause, number>;
|
|
150
|
+
/** P&L already realized by legs that settled before the close (cash at intrinsic, basis relieved). */
|
|
151
|
+
settledPnl: number;
|
|
152
|
+
legSettlements: Array<{ legIndex: number; settlement: OptionSettlement }>;
|
|
153
|
+
lineage: TradeLineage[];
|
|
154
|
+
partial: boolean;
|
|
155
|
+
unfilledLegs: UnfilledLeg[];
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** One leg's current-snapshot mark resolution (Preview P1). */
|
|
159
|
+
type LegMark =
|
|
160
|
+
| { volatility: number; source: MarkSource }
|
|
161
|
+
| { cause: MissingMarkCause }
|
|
162
|
+
| { intrinsic: true };
|
|
163
|
+
|
|
164
|
+
const MISSING_MARK_TEACHING: Record<MissingMarkCause, string> = {
|
|
165
|
+
missing: 'the snapshot carries no quote for this contract',
|
|
166
|
+
ambiguous: 'the snapshot carries more than one quote for this contract',
|
|
167
|
+
stale: "the contract's quote is older than marking.maximumQuoteAgeMs",
|
|
168
|
+
unpriceable:
|
|
169
|
+
'the quote states no usable implied volatility and its price cannot be inverted (no price under the request priceSource, or a price below intrinsic)',
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
// ── module-level pure helpers ─────────────────────────────────────────────────────────────────────
|
|
173
|
+
|
|
174
|
+
/** Per-contract dollar price from a per-share premium and the multiplier. */
|
|
175
|
+
function perContract(premiumPerShare: number, multiplier: number): number {
|
|
176
|
+
return Math.abs(premiumPerShare) * multiplier;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
interface CostPieces {
|
|
180
|
+
commission: number;
|
|
181
|
+
slippageAdjustment: number;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** Commission + slippage for one leg at contract granularity, kept apart for the ledger's cost rows. */
|
|
185
|
+
function legCost(
|
|
186
|
+
contracts: number,
|
|
187
|
+
perContractPrice: number,
|
|
188
|
+
side: OrderSide,
|
|
189
|
+
commission: CostModel,
|
|
190
|
+
slippage: SlippageModel,
|
|
191
|
+
): CostPieces {
|
|
192
|
+
if (contracts === 0) return { commission: 0, slippageAdjustment: 0 };
|
|
193
|
+
return {
|
|
194
|
+
commission: commission.commission({ quantity: contracts, price: perContractPrice }),
|
|
195
|
+
slippageAdjustment:
|
|
196
|
+
Math.abs(
|
|
197
|
+
slippage.fill({ referencePrice: perContractPrice, side, quantity: contracts }) -
|
|
198
|
+
perContractPrice,
|
|
199
|
+
) * contracts,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const totalCost = (pieces: readonly CostPieces[]): number =>
|
|
204
|
+
pieces.reduce((sum, p) => sum + p.commission + p.slippageAdjustment, 0);
|
|
205
|
+
|
|
206
|
+
function positionExpiries(position: Position): string[] {
|
|
207
|
+
const set = new Set<string>();
|
|
208
|
+
for (const l of position.legs) if (l.expiry !== undefined) set.add(l.expiry);
|
|
209
|
+
return [...set];
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/** Days to the NEAREST leg expiry (the first to settle). */
|
|
213
|
+
function minDaysToExpiry(position: Position, asOfMs: EpochMs): number {
|
|
214
|
+
const expiries = positionExpiries(position);
|
|
215
|
+
if (expiries.length === 0) return Number.POSITIVE_INFINITY;
|
|
216
|
+
return Math.min(...expiries.map((e) => daysToExpiry(asOfMs, e)));
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/** Evaluate one exit rule against the current mark; return the firing reason or null. */
|
|
220
|
+
function evaluateExit(rule: ExitRule, context: ExitContext): ExitReason | null {
|
|
221
|
+
if (rule.profitTarget !== undefined && context.pnlFraction >= rule.profitTarget)
|
|
222
|
+
return 'profit-target';
|
|
223
|
+
if (rule.stopLoss !== undefined && context.pnlFraction <= -rule.stopLoss) return 'stop-loss';
|
|
224
|
+
if (rule.daysToExpiry !== undefined && context.daysToExpiry <= rule.daysToExpiry)
|
|
225
|
+
return 'daysToExpiry';
|
|
226
|
+
if (rule.when !== undefined && rule.when(context)) return 'signal';
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/** The guarded fallback: book the whole gross P&L to the residual so the attribution still sums. */
|
|
231
|
+
function unexplainedTradeExplain(grossPnl: number): TradePnlExplain {
|
|
232
|
+
return {
|
|
233
|
+
total: grossPnl,
|
|
234
|
+
delta: 0,
|
|
235
|
+
gamma: 0,
|
|
236
|
+
vega: 0,
|
|
237
|
+
theta: 0,
|
|
238
|
+
rho: 0,
|
|
239
|
+
vanna: 0,
|
|
240
|
+
vomma: 0,
|
|
241
|
+
charm: 0,
|
|
242
|
+
veta: 0,
|
|
243
|
+
vera: 0,
|
|
244
|
+
deltaRate: 0,
|
|
245
|
+
thetaRate: 0,
|
|
246
|
+
rhoConvexity: 0,
|
|
247
|
+
thetaConvexity: 0,
|
|
248
|
+
phi: 0,
|
|
249
|
+
unexplained: grossPnl,
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* The trade's greek P&L explain (entry → exit) via `explainPositionPnl` over the LIVE legs. `total` is
|
|
255
|
+
* anchored to the trade's ACTUAL gross (pre-cost) P&L, so the entry edge and any P&L realized by legs
|
|
256
|
+
* that settled earlier are folded into `unexplained` — model/data and settlement effects, not
|
|
257
|
+
* market-move greeks; the sums stay invariant (`Σterms + unexplained === total`).
|
|
258
|
+
*/
|
|
259
|
+
function tradePnlExplain(input: {
|
|
260
|
+
position: Position;
|
|
261
|
+
entry: {
|
|
262
|
+
asOf: EpochMs;
|
|
263
|
+
spot: number;
|
|
264
|
+
volatility: number | undefined;
|
|
265
|
+
legVolatilities?: readonly (number | undefined)[];
|
|
266
|
+
};
|
|
267
|
+
exit: {
|
|
268
|
+
asOf: EpochMs;
|
|
269
|
+
spot: number;
|
|
270
|
+
volatility: number | undefined;
|
|
271
|
+
legVolatilities?: readonly (number | undefined)[];
|
|
272
|
+
};
|
|
273
|
+
riskFreeRate: number;
|
|
274
|
+
dividendYield: number;
|
|
275
|
+
grossPnl: number;
|
|
276
|
+
}): TradePnlExplain {
|
|
277
|
+
const { position, entry, exit, riskFreeRate, dividendYield, grossPnl } = input;
|
|
278
|
+
const market = (m: {
|
|
279
|
+
asOf: EpochMs;
|
|
280
|
+
spot: number;
|
|
281
|
+
volatility: number | undefined;
|
|
282
|
+
legVolatilities?: readonly (number | undefined)[];
|
|
283
|
+
}): PnlMarket => ({
|
|
284
|
+
spot: m.spot,
|
|
285
|
+
riskFreeRate,
|
|
286
|
+
asOf: m.asOf,
|
|
287
|
+
dividendYield,
|
|
288
|
+
...(m.volatility !== undefined ? { volatility: m.volatility } : {}),
|
|
289
|
+
...(m.legVolatilities !== undefined ? { legVolatilities: m.legVolatilities } : {}),
|
|
290
|
+
});
|
|
291
|
+
try {
|
|
292
|
+
if (position.legs.length === 0) return unexplainedTradeExplain(grossPnl);
|
|
293
|
+
const {
|
|
294
|
+
assumptions: _assumptions,
|
|
295
|
+
diagnostics: _diagnostics,
|
|
296
|
+
perLeg: _perLeg,
|
|
297
|
+
...terms
|
|
298
|
+
} = explainPositionPnl({ position, from: market(entry), to: market(exit) });
|
|
299
|
+
const edge = grossPnl - terms.total;
|
|
300
|
+
return { ...terms, total: grossPnl, unexplained: terms.unexplained + edge };
|
|
301
|
+
} catch {
|
|
302
|
+
return unexplainedTradeExplain(grossPnl);
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/** Reg-T initial margin of a position's option legs (share-scaled by the risk package). */
|
|
307
|
+
function optionMargin(position: Position, spot: number): number {
|
|
308
|
+
const optionLegs: OptionMarginLeg[] = position.legs
|
|
309
|
+
.filter((l): l is Leg & { kind: 'call' | 'put' } => l.kind === 'call' || l.kind === 'put')
|
|
310
|
+
.map((l) => ({ type: l.kind, quantity: l.quantity, strike: l.strike, premium: l.premium }));
|
|
311
|
+
if (optionLegs.length === 0) return 0;
|
|
312
|
+
const hasStock = position.legs.some((l) => l.kind === 'stock');
|
|
313
|
+
const expiries = new Set(
|
|
314
|
+
position.legs.filter((l) => l.kind !== 'stock' && l.expiry !== undefined).map((l) => l.expiry),
|
|
315
|
+
);
|
|
316
|
+
if (hasStock && expiries.size <= 1) {
|
|
317
|
+
const maxLoss = position.metrics().maxLoss;
|
|
318
|
+
if (maxLoss !== null) return Math.max(0, -maxLoss);
|
|
319
|
+
}
|
|
320
|
+
return optionsMargin(optionLegs, { spot, multiplier: position.multiplier }).initialMargin;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* The instant to mark a settling position: the latest **expired** leg's expiry moment (≥ `asOf`), so
|
|
325
|
+
* those legs price at true intrinsic (t ≤ 0) while any not-yet-expired (calendar/diagonal) leg keeps
|
|
326
|
+
* its remaining time value.
|
|
327
|
+
*/
|
|
328
|
+
function settlementInstant(position: Position, asOfMs: EpochMs): EpochMs {
|
|
329
|
+
let instant = asOfMs;
|
|
330
|
+
for (const leg of position.legs) {
|
|
331
|
+
if (leg.kind === 'stock' || leg.expiry === undefined) continue;
|
|
332
|
+
if (daysToExpiry(asOfMs, leg.expiry) > 0) continue;
|
|
333
|
+
const legInstant = optionExpiryToMs(leg.expiry);
|
|
334
|
+
if (legInstant > instant) instant = legInstant;
|
|
335
|
+
}
|
|
336
|
+
return instant;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/** A proxy "lot count" for a custom-built position: the largest per-leg option contract count. */
|
|
340
|
+
function maxLotOf(position: Position): number {
|
|
341
|
+
let max = 1;
|
|
342
|
+
for (const l of position.legs) if (l.kind !== 'stock') max = Math.max(max, Math.abs(l.quantity));
|
|
343
|
+
return max;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
/** Simple per-period returns from an equity curve (length n+1 → n returns). */
|
|
347
|
+
function simpleReturns(equity: number[]): number[] {
|
|
348
|
+
const out: number[] = [];
|
|
349
|
+
for (let i = 1; i < equity.length; i++) {
|
|
350
|
+
const prev = equity[i - 1]!;
|
|
351
|
+
out.push(prev === 0 ? 0 : equity[i]! / prev - 1);
|
|
352
|
+
}
|
|
353
|
+
return out;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function intrinsicOf(kind: 'call' | 'put', spot: number, strike: number): number {
|
|
357
|
+
return kind === 'call' ? Math.max(spot - strike, 0) : Math.max(strike - spot, 0);
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
/** The calendar date (`YYYY-MM-DD`, UTC) of an instant. */
|
|
361
|
+
function dateOf(ms: EpochMs): string {
|
|
362
|
+
return new Date(Math.floor(ms / DAY_MS) * DAY_MS).toISOString().slice(0, 10);
|
|
363
|
+
}
|
|
364
|
+
function nextCalendarDate(date: string): string {
|
|
365
|
+
return new Date(isoDateToEpochMs(date) + DAY_MS).toISOString().slice(0, 10);
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/** An OCC-style instrument id for an option leg (the ledger's key), or the underlying for stock. */
|
|
369
|
+
function legInstrumentId(underlying: string, leg: Leg, expiry: string | undefined): string {
|
|
370
|
+
if (leg.kind === 'stock') return underlying;
|
|
371
|
+
// A `build` leg without an expiry never settles and cannot carry option terms; it still needs an
|
|
372
|
+
// id of its own so the ledger never confuses it with the underlying.
|
|
373
|
+
if (expiry === undefined) return `${underlying}:${leg.kind}:${leg.strike}`;
|
|
374
|
+
return formatOccSymbol({ root: underlying, expiry, type: leg.kind, strike: leg.strike });
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/** The rules of a request: one rule, or the book's rules in order. */
|
|
378
|
+
function rulesOf(config: OptionsBacktestConfig): readonly EntryRule[] {
|
|
379
|
+
return config.rules ?? (config.entry === undefined ? [] : [config.entry]);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/** The identity of the request: every declarative member; callbacks recorded as such. */
|
|
383
|
+
function identityOf(
|
|
384
|
+
config: OptionsBacktestConfig,
|
|
385
|
+
rules: readonly EntryRule[],
|
|
386
|
+
): Record<string, unknown> {
|
|
387
|
+
const rule = (r: EntryRule): unknown =>
|
|
388
|
+
'build' in r
|
|
389
|
+
? { build: 'callback', when: typeof r.when === 'function' ? 'callback' : (r.when ?? 'flat') }
|
|
390
|
+
: { ...r, when: typeof r.when === 'function' ? 'callback' : (r.when ?? 'flat') };
|
|
391
|
+
return {
|
|
392
|
+
rules: rules.map(rule),
|
|
393
|
+
entryForm: config.rules === undefined ? 'entry' : 'rules',
|
|
394
|
+
exit: { ...config.exit, when: config.exit.when === undefined ? undefined : 'callback' },
|
|
395
|
+
roll:
|
|
396
|
+
config.roll === undefined
|
|
397
|
+
? null
|
|
398
|
+
: {
|
|
399
|
+
when:
|
|
400
|
+
config.roll.when === undefined
|
|
401
|
+
? null
|
|
402
|
+
: {
|
|
403
|
+
...config.roll.when,
|
|
404
|
+
when: config.roll.when.when === undefined ? undefined : 'callback',
|
|
405
|
+
},
|
|
406
|
+
},
|
|
407
|
+
hedge:
|
|
408
|
+
config.hedge === undefined
|
|
409
|
+
? null
|
|
410
|
+
: {
|
|
411
|
+
deltaBand: config.hedge.deltaBand,
|
|
412
|
+
commission: config.hedge.commission?.label ?? null,
|
|
413
|
+
slippage: config.hedge.slippage?.label ?? null,
|
|
414
|
+
},
|
|
415
|
+
marking: config.marking ?? null,
|
|
416
|
+
initialCapital: config.initialCapital ?? 100_000,
|
|
417
|
+
riskFreeRate: config.riskFreeRate,
|
|
418
|
+
dividendYield: config.dividendYield ?? 0,
|
|
419
|
+
commission: config.commission?.label ?? 'none',
|
|
420
|
+
slippage: config.slippage?.label ?? 'none',
|
|
421
|
+
assignment: config.assignment ?? 'none',
|
|
422
|
+
periodsPerYear: config.periodsPerYear ?? 252,
|
|
423
|
+
book: config.book ?? null,
|
|
424
|
+
limits: config.limits ?? null,
|
|
425
|
+
fillPolicy: config.fillPolicy ?? null,
|
|
426
|
+
quoteFreshness: config.quoteFreshness ?? null,
|
|
427
|
+
corporateActions: config.corporateActions ?? [],
|
|
428
|
+
dividends: config.dividends ?? [],
|
|
429
|
+
baseCurrency: config.baseCurrency ?? 'USD',
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// ── the engine ──────────────────────────────────────────────────────────────────────────────────
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Run a chain-driven options-strategy backtest over a position book. See
|
|
437
|
+
* `docs/specs/options-backtest.md` and `docs/specs/portfolio-scale-backtesting.md` (Decision 5).
|
|
438
|
+
*/
|
|
439
|
+
/**
|
|
440
|
+
* The closed guard for `optionsBacktest` (Stage 4.6): the generated closed-request spec over the
|
|
441
|
+
* whole declaration, then the hand laws — the iterable `chains`, the rules and their unique ids, the
|
|
442
|
+
* book's bounds, the limits, the fill and freshness policies, the corporate actions, the dividends.
|
|
443
|
+
* `optionsBacktest` calls it first; the run artifacts call it before storing a request.
|
|
444
|
+
*/
|
|
445
|
+
export function requireOptionsBacktestConfig(
|
|
446
|
+
functionName: string,
|
|
447
|
+
label: string,
|
|
448
|
+
value: unknown,
|
|
449
|
+
): void {
|
|
450
|
+
validateClosedRequest(functionName, value as OptionsBacktestConfig, OPTIONS_BACKTEST_SPEC, {
|
|
451
|
+
argumentName: label,
|
|
452
|
+
exampleCall:
|
|
453
|
+
"optionsBacktest({ chains, entry: { structure: 'bullPutSpread', daysToExpiry: { target: 45, min: 30, max: 60 }, select: { shortDelta: 0.3, width: 5 } }, exit: { profitTarget: 0.5, daysToExpiry: 21 } })",
|
|
454
|
+
});
|
|
455
|
+
const config = value as OptionsBacktestConfig;
|
|
456
|
+
const refuse = (
|
|
457
|
+
field: string,
|
|
458
|
+
message: string,
|
|
459
|
+
code: string = ErrorCode.InputOutOfRange,
|
|
460
|
+
): never => {
|
|
461
|
+
throw new InputError(`${functionName}: ${label}.${field} ${message}`, {
|
|
462
|
+
code,
|
|
463
|
+
context: { function: functionName, field: `${label}.${field}` },
|
|
464
|
+
});
|
|
465
|
+
};
|
|
466
|
+
if (
|
|
467
|
+
config.chains === null ||
|
|
468
|
+
typeof config.chains !== 'object' ||
|
|
469
|
+
typeof (config.chains as Iterable<unknown>)[Symbol.iterator] !== 'function'
|
|
470
|
+
) {
|
|
471
|
+
refuse('chains', 'must be an iterable of ChainSnapshot.', ErrorCode.InputWrongType);
|
|
472
|
+
}
|
|
473
|
+
if (config.riskFreeRate === undefined || config.riskFreeRate === null) {
|
|
474
|
+
refuse(
|
|
475
|
+
'riskFreeRate',
|
|
476
|
+
'is required — the continuously-compounded rate (decimal, e.g. 0.045) that prices every mark and the assignment carry. The engine never assumes a rate.',
|
|
477
|
+
ErrorCode.InputMissingField,
|
|
478
|
+
);
|
|
479
|
+
}
|
|
480
|
+
if (typeof config.riskFreeRate !== 'number' || !Number.isFinite(config.riskFreeRate)) {
|
|
481
|
+
refuse('riskFreeRate', 'must be a finite decimal rate.', ErrorCode.InputWrongType);
|
|
482
|
+
}
|
|
483
|
+
const maximumQuoteAgeMs = config.marking?.maximumQuoteAgeMs ?? null;
|
|
484
|
+
if (
|
|
485
|
+
maximumQuoteAgeMs !== null &&
|
|
486
|
+
(!Number.isFinite(maximumQuoteAgeMs) || maximumQuoteAgeMs < 0)
|
|
487
|
+
) {
|
|
488
|
+
refuse(
|
|
489
|
+
'marking.maximumQuoteAgeMs',
|
|
490
|
+
`must be a finite number of milliseconds ≥ 0 (omit it to treat every quote a snapshot carries as current). Received ${String(maximumQuoteAgeMs)}.`,
|
|
491
|
+
);
|
|
492
|
+
}
|
|
493
|
+
const hasEntry = config.entry !== undefined;
|
|
494
|
+
const hasRules = config.rules !== undefined;
|
|
495
|
+
if (hasEntry === hasRules) {
|
|
496
|
+
refuse(
|
|
497
|
+
hasEntry ? 'rules' : 'entry',
|
|
498
|
+
hasEntry
|
|
499
|
+
? 'and entry were both given — one rule goes in entry, several in rules, never both.'
|
|
500
|
+
: 'or rules must be given — one rule in entry, several in rules.',
|
|
501
|
+
hasEntry ? ErrorCode.InputUnknownField : ErrorCode.InputMissingField,
|
|
502
|
+
);
|
|
503
|
+
}
|
|
504
|
+
const rules: readonly EntryRule[] = rulesOf(config);
|
|
505
|
+
if (rules.length === 0) refuse('rules', 'must name at least one rule.');
|
|
506
|
+
const ids = rules.map((rule, index) => rule.id ?? `rule-${index}`);
|
|
507
|
+
ids.forEach((id, index) => {
|
|
508
|
+
if (ids.indexOf(id) !== index)
|
|
509
|
+
refuse(`entry[${index}].id`, `repeats '${id}' — ids are unique.`);
|
|
510
|
+
});
|
|
511
|
+
const maximumOpenPositions = config.book?.maximumOpenPositions ?? 1;
|
|
512
|
+
if (!Number.isSafeInteger(maximumOpenPositions) || maximumOpenPositions < 1) {
|
|
513
|
+
refuse(
|
|
514
|
+
'book.maximumOpenPositions',
|
|
515
|
+
`must be a positive integer. Received ${String(maximumOpenPositions)}.`,
|
|
516
|
+
);
|
|
517
|
+
}
|
|
518
|
+
if (maximumOpenPositions > OPTIONS_BOOK_CEILING) {
|
|
519
|
+
refuse(
|
|
520
|
+
'book.maximumOpenPositions',
|
|
521
|
+
`is ${maximumOpenPositions}, above the ${OPTIONS_BOOK_CEILING} open positions one synchronous book may hold.`,
|
|
522
|
+
ErrorCode.BacktestBookTooLarge,
|
|
523
|
+
);
|
|
524
|
+
}
|
|
525
|
+
const maximumPerUnderlying = config.book?.maximumPerUnderlying;
|
|
526
|
+
if (
|
|
527
|
+
maximumPerUnderlying !== undefined &&
|
|
528
|
+
(!Number.isSafeInteger(maximumPerUnderlying) || maximumPerUnderlying < 1)
|
|
529
|
+
) {
|
|
530
|
+
refuse(
|
|
531
|
+
'book.maximumPerUnderlying',
|
|
532
|
+
`must be a positive integer. Received ${String(maximumPerUnderlying)}.`,
|
|
533
|
+
);
|
|
534
|
+
}
|
|
535
|
+
const limits = config.limits ?? {};
|
|
536
|
+
for (const key of ['maximumMarginFraction', 'maximumConcentration'] as const) {
|
|
537
|
+
const v = limits[key];
|
|
538
|
+
if (v !== undefined && !(Number.isFinite(v) && v > 0 && v <= 1))
|
|
539
|
+
refuse(`limits.${key}`, `must be a fraction in (0, 1]. Received ${String(v)}.`);
|
|
540
|
+
}
|
|
541
|
+
for (const key of ['maximumNetDelta', 'maximumNetVega'] as const) {
|
|
542
|
+
const v = limits[key];
|
|
543
|
+
if (v !== undefined && !(Number.isFinite(v) && v >= 0))
|
|
544
|
+
refuse(`limits.${key}`, `must be a finite number ≥ 0. Received ${String(v)}.`);
|
|
545
|
+
}
|
|
546
|
+
if (limits.scenarioLoss !== undefined) {
|
|
547
|
+
const sl = limits.scenarioLoss;
|
|
548
|
+
if (
|
|
549
|
+
!(
|
|
550
|
+
Number.isFinite(sl.maximumLossFraction) &&
|
|
551
|
+
sl.maximumLossFraction > 0 &&
|
|
552
|
+
sl.maximumLossFraction <= 1
|
|
553
|
+
)
|
|
554
|
+
) {
|
|
555
|
+
refuse('limits.scenarioLoss.maximumLossFraction', 'must be a fraction in (0, 1].');
|
|
556
|
+
}
|
|
557
|
+
for (const [name, values] of [
|
|
558
|
+
['spotShocks', sl.spotShocks],
|
|
559
|
+
['volatilityShocks', sl.volatilityShocks],
|
|
560
|
+
] as const) {
|
|
561
|
+
if (
|
|
562
|
+
!Array.isArray(values) ||
|
|
563
|
+
values.length === 0 ||
|
|
564
|
+
values.length > 64 ||
|
|
565
|
+
values.some((v) => !Number.isFinite(v))
|
|
566
|
+
) {
|
|
567
|
+
refuse(`limits.scenarioLoss.${name}`, 'must be 1–64 finite shocks.');
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
const fillAge = config.quoteFreshness?.maximumQuoteAgeMs;
|
|
572
|
+
if (fillAge !== undefined && !(Number.isFinite(fillAge) && fillAge >= 0)) {
|
|
573
|
+
refuse('quoteFreshness.maximumQuoteAgeMs', 'must be a finite number of milliseconds ≥ 0.');
|
|
574
|
+
}
|
|
575
|
+
(config.corporateActions ?? []).forEach((action, index) => {
|
|
576
|
+
if (
|
|
577
|
+
(action.type === 'split' || action.type === 'reverseSplit') &&
|
|
578
|
+
!(typeof action.ratio === 'number' && Number.isFinite(action.ratio) && action.ratio > 0)
|
|
579
|
+
) {
|
|
580
|
+
refuse(
|
|
581
|
+
`corporateActions[${index}].ratio`,
|
|
582
|
+
`is needed by a ${action.type} on ${action.symbol} (a positive ratio).`,
|
|
583
|
+
);
|
|
584
|
+
}
|
|
585
|
+
if (
|
|
586
|
+
action.type === 'symbolChange' &&
|
|
587
|
+
!(typeof action.newSymbol === 'string' && action.newSymbol.length > 0)
|
|
588
|
+
) {
|
|
589
|
+
refuse(
|
|
590
|
+
`corporateActions[${index}].newSymbol`,
|
|
591
|
+
`is needed by a symbolChange on ${action.symbol}.`,
|
|
592
|
+
ErrorCode.InputMissingField,
|
|
593
|
+
);
|
|
594
|
+
}
|
|
595
|
+
});
|
|
596
|
+
(config.dividends ?? []).forEach((d, index) => {
|
|
597
|
+
if (!(typeof d.amount === 'number' && Number.isFinite(d.amount) && d.amount > 0)) {
|
|
598
|
+
refuse(`dividends[${index}].amount`, 'must be a positive per-share amount.');
|
|
599
|
+
}
|
|
600
|
+
});
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
export function optionsBacktest(config: OptionsBacktestConfig): OptionsBacktestResult {
|
|
604
|
+
requireOptionsBacktestConfig(FN, 'config', config);
|
|
605
|
+
const initialCapital = config.initialCapital ?? 100_000;
|
|
606
|
+
const rate = config.riskFreeRate;
|
|
607
|
+
const dividendYield = config.dividendYield ?? 0;
|
|
608
|
+
const commission = config.commission ?? fees.none();
|
|
609
|
+
const slippage = config.slippage ?? slippageModels.none();
|
|
610
|
+
const assignment = config.assignment ?? 'none';
|
|
611
|
+
const periodsPerYear = config.periodsPerYear ?? 252;
|
|
612
|
+
const baseCurrency = config.baseCurrency ?? 'USD';
|
|
613
|
+
const marking: AppliedMarkingPolicy = {
|
|
614
|
+
volatility: config.marking?.volatility ?? 'current-quote',
|
|
615
|
+
missingMark: config.marking?.missingMark ?? 'refuse',
|
|
616
|
+
maximumQuoteAgeMs: config.marking?.maximumQuoteAgeMs ?? null,
|
|
617
|
+
};
|
|
618
|
+
const { exit, roll, hedge } = config;
|
|
619
|
+
const hedgeCommission = hedge?.commission ?? commission;
|
|
620
|
+
const hedgeSlippage = hedge?.slippage ?? slippage;
|
|
621
|
+
|
|
622
|
+
// ---- Stage 4.6: the rules, the book, the limits, the fill and freshness policies ------------------
|
|
623
|
+
const rules: readonly EntryRule[] = rulesOf(config);
|
|
624
|
+
const ruleIds = rules.map((rule, index) => rule.id ?? `rule-${index}`);
|
|
625
|
+
const priceSource: PriceSource = rules[0]!.price ?? 'mid';
|
|
626
|
+
const maximumOpenPositions = config.book?.maximumOpenPositions ?? 1;
|
|
627
|
+
const maximumPerUnderlying = config.book?.maximumPerUnderlying ?? null;
|
|
628
|
+
const limits: PortfolioLimits = config.limits ?? {};
|
|
629
|
+
const fillMode = config.fillPolicy?.mode ?? 'combo';
|
|
630
|
+
const partialFill = config.fillPolicy?.partialFill ?? 'reject';
|
|
631
|
+
const fillPrice: PriceSource = config.fillPolicy?.price ?? priceSource;
|
|
632
|
+
const maximumFillQuoteAgeMs = config.quoteFreshness?.maximumQuoteAgeMs ?? null;
|
|
633
|
+
const corporateActions = [...(config.corporateActions ?? [])].sort((a, b) =>
|
|
634
|
+
a.effectiveDate < b.effectiveDate ? -1 : a.effectiveDate > b.effectiveDate ? 1 : 0,
|
|
635
|
+
);
|
|
636
|
+
const dividends = [...(config.dividends ?? [])].sort((a, b) =>
|
|
637
|
+
a.exDate < b.exDate ? -1 : a.exDate > b.exDate ? 1 : 0,
|
|
638
|
+
);
|
|
639
|
+
const replayable =
|
|
640
|
+
rules.every((r) => !('build' in r) && typeof r.when !== 'function') &&
|
|
641
|
+
exit.when === undefined &&
|
|
642
|
+
roll?.when?.when === undefined;
|
|
643
|
+
|
|
644
|
+
const snapshots = [...config.chains];
|
|
645
|
+
snapshots.forEach((s, i) => requireSnapshot(s, i, FN));
|
|
646
|
+
const ordered = snapshots
|
|
647
|
+
.map((snap, i) => ({ snap, asOfMs: snapshotAsOf(snap, FN), i }))
|
|
648
|
+
.sort((a, b) => a.asOfMs - b.asOfMs || a.i - b.i);
|
|
649
|
+
const runId = contentHash({
|
|
650
|
+
...identityOf(config, rules),
|
|
651
|
+
// Identity is order-invariant where the engine is: a snapshot's quotes are matched by contract,
|
|
652
|
+
// so two requests that differ only in quote order are the same run (FC8 ordering invariance).
|
|
653
|
+
chains: contentHash(
|
|
654
|
+
ordered.map(({ snap }) => ({
|
|
655
|
+
...snap,
|
|
656
|
+
quotes: [...snap.quotes].sort((a, b) =>
|
|
657
|
+
quoteIdentityKey(a) < quoteIdentityKey(b)
|
|
658
|
+
? -1
|
|
659
|
+
: quoteIdentityKey(a) > quoteIdentityKey(b)
|
|
660
|
+
? 1
|
|
661
|
+
: 0,
|
|
662
|
+
),
|
|
663
|
+
})),
|
|
664
|
+
),
|
|
665
|
+
});
|
|
666
|
+
const sourceId = `backtest:options:${runId}`;
|
|
667
|
+
|
|
668
|
+
// ---- state ----------------------------------------------------------------------------------------
|
|
669
|
+
const book: OpenTrade[] = [];
|
|
670
|
+
let nextTradeId = 1;
|
|
671
|
+
let cash = initialCapital;
|
|
672
|
+
let hedgeShares = 0;
|
|
673
|
+
let hedgeUnderlying: string | null = null;
|
|
674
|
+
let sizingMode: 'fixed-quantity' | 'margin-aware' = 'fixed-quantity';
|
|
675
|
+
const trades: OptionsTrade[] = [];
|
|
676
|
+
const settlements: OptionSettlement[] = [];
|
|
677
|
+
/** Every fill the book placed, in booking order — the same NormalizedFills the ledger folded. */
|
|
678
|
+
const fills: NormalizedFill[] = [];
|
|
679
|
+
const limitRejections: LimitRejection[] = [];
|
|
680
|
+
const fillRejections: FillRejection[] = [];
|
|
681
|
+
const surface: SurfaceRow[] = [];
|
|
682
|
+
const warnings: QuantWarning[] = [];
|
|
683
|
+
let earlyAssignmentCount = 0;
|
|
684
|
+
let corporateActionsApplied = 0;
|
|
685
|
+
const equityCurve: number[] = [initialCapital];
|
|
686
|
+
const timestamps: EpochMs[] = [];
|
|
687
|
+
|
|
688
|
+
// ---- the ledger -----------------------------------------------------------------------------------
|
|
689
|
+
const events: PortfolioEventEnvelope[] = [];
|
|
690
|
+
let state: PortfolioState | undefined;
|
|
691
|
+
let eventSequence = 0;
|
|
692
|
+
/**
|
|
693
|
+
* The instant the ledger records this snapshot's events at. A snapshot's events fold in order, so
|
|
694
|
+
* once an expiry settlement moves the clock to the contract's expiry instant (16:00 ET on a
|
|
695
|
+
* date-only snapshot), every later event of the same snapshot carries that instant too.
|
|
696
|
+
*/
|
|
697
|
+
let eventClock = 0;
|
|
698
|
+
const stamp = (asOfMs: EpochMs): EpochMs => {
|
|
699
|
+
if (asOfMs > eventClock) eventClock = asOfMs;
|
|
700
|
+
return eventClock;
|
|
701
|
+
};
|
|
702
|
+
const fold = (batch: PortfolioEventEnvelope[]): void => {
|
|
703
|
+
if (batch.length === 0) return;
|
|
704
|
+
state =
|
|
705
|
+
state === undefined
|
|
706
|
+
? applyPortfolioEvents({ portfolio: { baseCurrency }, events: batch })
|
|
707
|
+
: applyPortfolioEvents({ previousState: state, events: batch });
|
|
708
|
+
events.push(...batch);
|
|
709
|
+
};
|
|
710
|
+
const envelope = (
|
|
711
|
+
asOfMs: EpochMs,
|
|
712
|
+
event: PortfolioEventEnvelope['event'],
|
|
713
|
+
correlationId?: string,
|
|
714
|
+
): PortfolioEventEnvelope => {
|
|
715
|
+
eventSequence += 1;
|
|
716
|
+
return {
|
|
717
|
+
...((): Record<string, never> => {
|
|
718
|
+
void stamp(asOfMs);
|
|
719
|
+
return {} as Record<string, never>;
|
|
720
|
+
})(),
|
|
721
|
+
eventId: `${runId}:e${eventSequence}`,
|
|
722
|
+
schemaVersion: PORTFOLIO_EVENT_SCHEMA_VERSION,
|
|
723
|
+
eventType: event.eventType,
|
|
724
|
+
sourceId,
|
|
725
|
+
accountId: ACCOUNT_ID,
|
|
726
|
+
effectiveTimestampMs: eventClock,
|
|
727
|
+
recordedTimestampMs: eventClock,
|
|
728
|
+
...(correlationId !== undefined ? { correlationId } : {}),
|
|
729
|
+
event,
|
|
730
|
+
provenance: {},
|
|
731
|
+
};
|
|
732
|
+
};
|
|
733
|
+
const bookFill = (input: {
|
|
734
|
+
asOfMs: EpochMs;
|
|
735
|
+
instrumentId: string;
|
|
736
|
+
side: OrderSide;
|
|
737
|
+
quantity: number;
|
|
738
|
+
pricePerUnit: number;
|
|
739
|
+
contractMultiplier: number;
|
|
740
|
+
contract?: NormalizedFill['contract'];
|
|
741
|
+
costs: CostPieces;
|
|
742
|
+
orderId: string;
|
|
743
|
+
}): void => {
|
|
744
|
+
if (input.quantity <= 0) return;
|
|
745
|
+
eventSequence += 1;
|
|
746
|
+
const fill: NormalizedFill = {
|
|
747
|
+
fillId: `${runId}:f${eventSequence}`,
|
|
748
|
+
accountId: ACCOUNT_ID,
|
|
749
|
+
instrumentId: input.instrumentId,
|
|
750
|
+
side: input.side,
|
|
751
|
+
quantity: input.quantity,
|
|
752
|
+
pricePerUnit: input.pricePerUnit,
|
|
753
|
+
currency: baseCurrency,
|
|
754
|
+
filledTimestampMs: stamp(input.asOfMs),
|
|
755
|
+
contractMultiplier: input.contractMultiplier,
|
|
756
|
+
settlementStyle: 'cash-on-trade',
|
|
757
|
+
...(input.contract !== undefined ? { contract: input.contract } : {}),
|
|
758
|
+
costs: {
|
|
759
|
+
...(input.costs.commission > 0 ? { commission: input.costs.commission } : {}),
|
|
760
|
+
...(input.costs.slippageAdjustment > 0
|
|
761
|
+
? { slippageAdjustment: input.costs.slippageAdjustment }
|
|
762
|
+
: {}),
|
|
763
|
+
},
|
|
764
|
+
orderId: input.orderId,
|
|
765
|
+
};
|
|
766
|
+
fills.push(fill);
|
|
767
|
+
fold(portfolioEventsFromFill({ fill, sourceId, recordedTimestampMs: fill.filledTimestampMs }));
|
|
768
|
+
};
|
|
769
|
+
const optionTerms = (
|
|
770
|
+
underlying: string,
|
|
771
|
+
leg: Leg,
|
|
772
|
+
expiry: string | undefined,
|
|
773
|
+
): NormalizedFill['contract'] =>
|
|
774
|
+
leg.kind === 'stock' || expiry === undefined || expiry === ''
|
|
775
|
+
? undefined
|
|
776
|
+
: {
|
|
777
|
+
kind: 'option',
|
|
778
|
+
underlyingInstrumentId: underlying,
|
|
779
|
+
type: leg.kind,
|
|
780
|
+
strikePricePerUnit: leg.strike,
|
|
781
|
+
expiryTimestampMs: optionExpiryToMs(expiry),
|
|
782
|
+
};
|
|
783
|
+
|
|
784
|
+
if (ordered.length > 0) {
|
|
785
|
+
fold([
|
|
786
|
+
envelope(ordered[0]!.asOfMs, {
|
|
787
|
+
eventType: 'cash.deposit',
|
|
788
|
+
amount: initialCapital,
|
|
789
|
+
currency: baseCurrency,
|
|
790
|
+
}),
|
|
791
|
+
]);
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
// ---- the implied-volatility enrichment (unchanged from P1) ---------------------------------------
|
|
795
|
+
const impliedVolatilityCache = new Map<ChainSnapshot, ChainSnapshot>();
|
|
796
|
+
const enrichedQuotes = new WeakSet<OptionQuote>();
|
|
797
|
+
const enrichSnapshot = (snap: ChainSnapshot, asOfMs: EpochMs): ChainSnapshot => {
|
|
798
|
+
const hit = impliedVolatilityCache.get(snap);
|
|
799
|
+
if (hit) return hit;
|
|
800
|
+
const hasImpliedVolatility = snap.quotes.some(
|
|
801
|
+
(q) => typeof q.impliedVolatility === 'number' && q.impliedVolatility > 0,
|
|
802
|
+
);
|
|
803
|
+
if (hasImpliedVolatility) {
|
|
804
|
+
impliedVolatilityCache.set(snap, snap);
|
|
805
|
+
return snap;
|
|
806
|
+
}
|
|
807
|
+
const quotes = snap.quotes.map((q) => {
|
|
808
|
+
if (typeof q.impliedVolatility === 'number' && q.impliedVolatility > 0) return q;
|
|
809
|
+
const price = selectQuotePrice(q, priceSource);
|
|
810
|
+
if (price === undefined || !Number.isFinite(price)) return q;
|
|
811
|
+
const t = yearFraction(asOfMs, optionExpiryToMs(q.contract.expiry), 'ACT/365F');
|
|
812
|
+
if (!(t > 0)) return q;
|
|
813
|
+
const impliedVolatility = blackScholesImpliedVolatility({
|
|
814
|
+
type: q.contract.type,
|
|
815
|
+
price,
|
|
816
|
+
spot: snap.underlyingPrice,
|
|
817
|
+
strike: q.contract.strike,
|
|
818
|
+
timeToExpiryYears: t,
|
|
819
|
+
riskFreeRate: rate,
|
|
820
|
+
dividendYield,
|
|
821
|
+
});
|
|
822
|
+
if (!(impliedVolatility.converged && impliedVolatility.value > 0)) return q;
|
|
823
|
+
const enriched = { ...q, impliedVolatility: impliedVolatility.value };
|
|
824
|
+
enrichedQuotes.add(enriched);
|
|
825
|
+
return enriched;
|
|
826
|
+
});
|
|
827
|
+
const enriched: ChainSnapshot = { ...snap, quotes };
|
|
828
|
+
impliedVolatilityCache.set(snap, enriched);
|
|
829
|
+
return enriched;
|
|
830
|
+
};
|
|
831
|
+
|
|
832
|
+
const atmVolatility = (snap: ChainSnapshot): number | undefined => {
|
|
833
|
+
let best: number | undefined;
|
|
834
|
+
let bestDist = Infinity;
|
|
835
|
+
for (const q of snap.quotes) {
|
|
836
|
+
if (q.impliedVolatility === undefined) continue;
|
|
837
|
+
const dist = Math.abs(q.contract.strike - snap.underlyingPrice);
|
|
838
|
+
if (dist < bestDist) {
|
|
839
|
+
bestDist = dist;
|
|
840
|
+
best = q.impliedVolatility;
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
return best;
|
|
844
|
+
};
|
|
845
|
+
|
|
846
|
+
// ---- Preview P1: the current-quote mark (per trade, unchanged law) --------------------------------
|
|
847
|
+
const quoteIndexCache = new Map<ChainSnapshot, Map<string, OptionQuote[]>>();
|
|
848
|
+
const quoteKey = (type: string, strike: number, expiry: string): string =>
|
|
849
|
+
`${type}:${strike}:${expiry}`;
|
|
850
|
+
const quoteIndex = (snap: ChainSnapshot): Map<string, OptionQuote[]> => {
|
|
851
|
+
const hit = quoteIndexCache.get(snap);
|
|
852
|
+
if (hit) return hit;
|
|
853
|
+
const index = new Map<string, OptionQuote[]>();
|
|
854
|
+
for (const q of snap.quotes) {
|
|
855
|
+
const key = quoteKey(q.contract.type, q.contract.strike, q.contract.expiry);
|
|
856
|
+
const list = index.get(key);
|
|
857
|
+
if (list) list.push(q);
|
|
858
|
+
else index.set(key, [q]);
|
|
859
|
+
}
|
|
860
|
+
quoteIndexCache.set(snap, index);
|
|
861
|
+
return index;
|
|
862
|
+
};
|
|
863
|
+
const positionExpiryOf = (position: Position): string | undefined => {
|
|
864
|
+
const expiries = new Set(position.legs.map((l) => l.expiry).filter((e) => e !== undefined));
|
|
865
|
+
return expiries.size === 1 ? [...expiries][0] : undefined;
|
|
866
|
+
};
|
|
867
|
+
const currentLegMark = (
|
|
868
|
+
leg: Leg,
|
|
869
|
+
expiry: string | undefined,
|
|
870
|
+
snap: ChainSnapshot,
|
|
871
|
+
asOfMs: EpochMs,
|
|
872
|
+
): LegMark => {
|
|
873
|
+
if (leg.kind === 'stock' || expiry === undefined) return { intrinsic: true };
|
|
874
|
+
if (daysToExpiry(asOfMs, expiry) <= 0) return { intrinsic: true };
|
|
875
|
+
const t = yearFraction(asOfMs, optionExpiryToMs(expiry), 'ACT/365F');
|
|
876
|
+
if (!(t > 0)) return { intrinsic: true };
|
|
877
|
+
const matches = quoteIndex(snap).get(quoteKey(leg.kind, leg.strike, expiry)) ?? [];
|
|
878
|
+
if (matches.length === 0) return { cause: 'missing' };
|
|
879
|
+
if (matches.length > 1) return { cause: 'ambiguous' };
|
|
880
|
+
const q = matches[0]!;
|
|
881
|
+
if (
|
|
882
|
+
marking.maximumQuoteAgeMs !== null &&
|
|
883
|
+
typeof q.timestampMs === 'number' &&
|
|
884
|
+
asOfMs - q.timestampMs > marking.maximumQuoteAgeMs
|
|
885
|
+
) {
|
|
886
|
+
return { cause: 'stale' };
|
|
887
|
+
}
|
|
888
|
+
if (
|
|
889
|
+
typeof q.impliedVolatility === 'number' &&
|
|
890
|
+
Number.isFinite(q.impliedVolatility) &&
|
|
891
|
+
q.impliedVolatility > 0
|
|
892
|
+
) {
|
|
893
|
+
return {
|
|
894
|
+
volatility: q.impliedVolatility,
|
|
895
|
+
source: enrichedQuotes.has(q) ? 'implied-from-price' : 'current-quote',
|
|
896
|
+
};
|
|
897
|
+
}
|
|
898
|
+
const price = selectQuotePrice(q, priceSource);
|
|
899
|
+
if (price === undefined || !Number.isFinite(price)) return { cause: 'unpriceable' };
|
|
900
|
+
const implied = blackScholesImpliedVolatility({
|
|
901
|
+
type: leg.kind,
|
|
902
|
+
price,
|
|
903
|
+
spot: snap.underlyingPrice,
|
|
904
|
+
strike: leg.strike,
|
|
905
|
+
timeToExpiryYears: t,
|
|
906
|
+
riskFreeRate: rate,
|
|
907
|
+
dividendYield,
|
|
908
|
+
});
|
|
909
|
+
return implied.converged && implied.value > 0
|
|
910
|
+
? { volatility: implied.value, source: 'implied-from-price' }
|
|
911
|
+
: { cause: 'unpriceable' };
|
|
912
|
+
};
|
|
913
|
+
/** This snapshot's mark sources across every trade (the surface row's evidence). */
|
|
914
|
+
let snapshotMarkSources: TradeMarkCounts = {
|
|
915
|
+
snapshots: 0,
|
|
916
|
+
currentQuote: 0,
|
|
917
|
+
impliedFromPrice: 0,
|
|
918
|
+
entryVolatility: 0,
|
|
919
|
+
carried: 0,
|
|
920
|
+
};
|
|
921
|
+
const snapshotLegVolatilities = (
|
|
922
|
+
t: OpenTrade,
|
|
923
|
+
snap: ChainSnapshot,
|
|
924
|
+
asOfMs: EpochMs,
|
|
925
|
+
): (number | undefined)[] | null => {
|
|
926
|
+
if (marking.volatility === 'entry') return null;
|
|
927
|
+
if (t.markCache !== null && t.markCache.snap === snap) return t.markCache.legVolatilities;
|
|
928
|
+
const positionExpiry = positionExpiryOf(t.position);
|
|
929
|
+
const legVolatilities: (number | undefined)[] = [];
|
|
930
|
+
t.marks.snapshots += 1;
|
|
931
|
+
snapshotMarkSources.snapshots += 1;
|
|
932
|
+
t.position.legs.forEach((leg, index) => {
|
|
933
|
+
const live = t.live[index]!;
|
|
934
|
+
const resolved = currentLegMark(leg, leg.expiry ?? positionExpiry, snap, asOfMs);
|
|
935
|
+
if ('intrinsic' in resolved) {
|
|
936
|
+
legVolatilities.push(undefined);
|
|
937
|
+
return;
|
|
938
|
+
}
|
|
939
|
+
if ('volatility' in resolved) {
|
|
940
|
+
legVolatilities.push(resolved.volatility);
|
|
941
|
+
live.lastVolatility = resolved.volatility;
|
|
942
|
+
if (resolved.source === 'current-quote') {
|
|
943
|
+
t.marks.currentQuote += 1;
|
|
944
|
+
snapshotMarkSources.currentQuote += 1;
|
|
945
|
+
} else {
|
|
946
|
+
t.marks.impliedFromPrice += 1;
|
|
947
|
+
snapshotMarkSources.impliedFromPrice += 1;
|
|
948
|
+
}
|
|
949
|
+
return;
|
|
950
|
+
}
|
|
951
|
+
const fallback =
|
|
952
|
+
marking.missingMark === 'entry-volatility'
|
|
953
|
+
? live.entryVolatility
|
|
954
|
+
: marking.missingMark === 'carry-last-volatility'
|
|
955
|
+
? live.lastVolatility
|
|
956
|
+
: undefined;
|
|
957
|
+
if (marking.missingMark === 'refuse' || fallback === undefined) {
|
|
958
|
+
throw new InputError(
|
|
959
|
+
`${FN}: leg ${live.originalIndex} (${leg.kind} ${leg.strike} ${leg.expiry ?? positionExpiry}) has no usable mark at snapshot ${asOfMs}: ${MISSING_MARK_TEACHING[resolved.cause]}${marking.missingMark === 'refuse' ? '' : ` — and the '${marking.missingMark}' fallback has no volatility to fall back to for this leg`}. Supply the contract's current quote, choose a named fallback (marking.missingMark: 'entry-volatility' | 'carry-last-volatility'), or mark at entry volatility explicitly (marking.volatility: 'entry').`,
|
|
960
|
+
{
|
|
961
|
+
code: ErrorCode.BacktestMarkUnavailable,
|
|
962
|
+
context: {
|
|
963
|
+
function: FN,
|
|
964
|
+
leg: live.originalIndex,
|
|
965
|
+
contract: {
|
|
966
|
+
type: leg.kind,
|
|
967
|
+
strike: leg.strike,
|
|
968
|
+
expiry: leg.expiry ?? positionExpiry,
|
|
969
|
+
},
|
|
970
|
+
asOf: asOfMs,
|
|
971
|
+
cause: resolved.cause,
|
|
972
|
+
missingMark: marking.missingMark,
|
|
973
|
+
},
|
|
974
|
+
},
|
|
975
|
+
);
|
|
976
|
+
}
|
|
977
|
+
legVolatilities.push(fallback);
|
|
978
|
+
live.lastVolatility = fallback;
|
|
979
|
+
if (marking.missingMark === 'entry-volatility') {
|
|
980
|
+
t.marks.entryVolatility += 1;
|
|
981
|
+
snapshotMarkSources.entryVolatility += 1;
|
|
982
|
+
} else {
|
|
983
|
+
t.marks.carried += 1;
|
|
984
|
+
snapshotMarkSources.carried += 1;
|
|
985
|
+
}
|
|
986
|
+
t.fallbacks.set(resolved.cause, (t.fallbacks.get(resolved.cause) ?? 0) + 1);
|
|
987
|
+
});
|
|
988
|
+
t.markCache = { snap, legVolatilities };
|
|
989
|
+
return legVolatilities;
|
|
990
|
+
};
|
|
991
|
+
|
|
992
|
+
const mark = (
|
|
993
|
+
position: Position,
|
|
994
|
+
snap: ChainSnapshot,
|
|
995
|
+
asOfMs: EpochMs,
|
|
996
|
+
legVolatilities?: readonly (number | undefined)[] | null,
|
|
997
|
+
) => {
|
|
998
|
+
const input = { spot: snap.underlyingPrice, asOf: asOfMs, riskFreeRate: rate, dividendYield };
|
|
999
|
+
const volatility = atmVolatility(snap);
|
|
1000
|
+
if (legVolatilities !== undefined && legVolatilities !== null) {
|
|
1001
|
+
return volatility === undefined
|
|
1002
|
+
? position.value({ ...input, legVolatilities })
|
|
1003
|
+
: position.value({ ...input, legVolatilities, volatility });
|
|
1004
|
+
}
|
|
1005
|
+
return volatility === undefined
|
|
1006
|
+
? position.value(input)
|
|
1007
|
+
: position.value({ ...input, volatility });
|
|
1008
|
+
};
|
|
1009
|
+
const markTrade = (t: OpenTrade, snap: ChainSnapshot, asOfMs: EpochMs, markAsOf = asOfMs) =>
|
|
1010
|
+
mark(t.position, snap, markAsOf, snapshotLegVolatilities(t, snap, asOfMs));
|
|
1011
|
+
|
|
1012
|
+
/** Current dollar value of one open trade's live legs (entry basis + running P&L of the live legs). */
|
|
1013
|
+
const tradeValue = (t: OpenTrade, snap: ChainSnapshot, asOfMs: EpochMs): number =>
|
|
1014
|
+
t.position.legs.length === 0
|
|
1015
|
+
? 0
|
|
1016
|
+
: markTrade(t, snap, asOfMs).perLeg.reduce((sum, p) => sum + p.value, 0);
|
|
1017
|
+
const openOptionValue = (snap: ChainSnapshot, asOfMs: EpochMs): number =>
|
|
1018
|
+
book.reduce((sum, t) => sum + tradeValue(t, snap, asOfMs), 0);
|
|
1019
|
+
|
|
1020
|
+
const skip = (asOfMs: EpochMs, ruleId: string, reason: string): void => {
|
|
1021
|
+
warnings.push({
|
|
1022
|
+
code: WarningCode.BacktestEntrySkipped,
|
|
1023
|
+
message: `No entry for ${ruleId} at ${asOfMs}: ${reason}.`,
|
|
1024
|
+
severity: 'info',
|
|
1025
|
+
});
|
|
1026
|
+
};
|
|
1027
|
+
|
|
1028
|
+
// ---- the underlying hedge (book-level) -------------------------------------------------------------
|
|
1029
|
+
const tradeUnderlying = (hedgeTrade: {
|
|
1030
|
+
deltaShares: number;
|
|
1031
|
+
spot: number;
|
|
1032
|
+
asOfMs: EpochMs;
|
|
1033
|
+
underlying: string;
|
|
1034
|
+
}): void => {
|
|
1035
|
+
const { deltaShares, spot, asOfMs, underlying } = hedgeTrade;
|
|
1036
|
+
if (deltaShares === 0) return;
|
|
1037
|
+
const side: OrderSide = sideOf(deltaShares);
|
|
1038
|
+
const shares = Math.abs(deltaShares);
|
|
1039
|
+
const pieces: CostPieces = {
|
|
1040
|
+
commission: hedgeCommission.commission({ quantity: shares, price: spot }),
|
|
1041
|
+
slippageAdjustment:
|
|
1042
|
+
Math.abs(hedgeSlippage.fill({ referencePrice: spot, side, quantity: shares }) - spot) *
|
|
1043
|
+
shares,
|
|
1044
|
+
};
|
|
1045
|
+
cash -= deltaShares * spot + pieces.commission + pieces.slippageAdjustment;
|
|
1046
|
+
hedgeShares += deltaShares;
|
|
1047
|
+
hedgeUnderlying = underlying;
|
|
1048
|
+
bookFill({
|
|
1049
|
+
asOfMs,
|
|
1050
|
+
instrumentId: underlying,
|
|
1051
|
+
side,
|
|
1052
|
+
quantity: shares,
|
|
1053
|
+
pricePerUnit: spot,
|
|
1054
|
+
contractMultiplier: 1,
|
|
1055
|
+
costs: pieces,
|
|
1056
|
+
orderId: `${runId}:hedge:${asOfMs}`,
|
|
1057
|
+
});
|
|
1058
|
+
};
|
|
1059
|
+
const rehedge = (snap: ChainSnapshot, asOfMs: EpochMs): void => {
|
|
1060
|
+
if (!hedge) return;
|
|
1061
|
+
if (book.length === 0) {
|
|
1062
|
+
if (hedgeShares !== 0 && hedgeUnderlying !== null)
|
|
1063
|
+
tradeUnderlying({
|
|
1064
|
+
deltaShares: -hedgeShares,
|
|
1065
|
+
spot: snap.underlyingPrice,
|
|
1066
|
+
asOfMs,
|
|
1067
|
+
underlying: hedgeUnderlying,
|
|
1068
|
+
});
|
|
1069
|
+
return;
|
|
1070
|
+
}
|
|
1071
|
+
let optionDelta = 0;
|
|
1072
|
+
for (const t of book)
|
|
1073
|
+
optionDelta += t.position.legs.length === 0 ? 0 : markTrade(t, snap, asOfMs).greeks.delta;
|
|
1074
|
+
if (Math.abs(optionDelta + hedgeShares) <= hedge.deltaBand) return;
|
|
1075
|
+
tradeUnderlying({
|
|
1076
|
+
deltaShares: -optionDelta - hedgeShares,
|
|
1077
|
+
spot: snap.underlyingPrice,
|
|
1078
|
+
asOfMs,
|
|
1079
|
+
underlying: book[0]!.underlying,
|
|
1080
|
+
});
|
|
1081
|
+
};
|
|
1082
|
+
|
|
1083
|
+
// ---- settlement of individual legs (expiry, early assignment) -------------------------------------
|
|
1084
|
+
/** Settle the given live legs at intrinsic (cash) and rebuild the trade's position from the rest. */
|
|
1085
|
+
const settleLegs = (
|
|
1086
|
+
t: OpenTrade,
|
|
1087
|
+
snap: ChainSnapshot,
|
|
1088
|
+
asOfMs: EpochMs,
|
|
1089
|
+
which: (leg: Leg, index: number) => boolean,
|
|
1090
|
+
early: { reason: 'dividend' | 'deep-itm' } | null,
|
|
1091
|
+
): { settled: number; assigned: boolean } => {
|
|
1092
|
+
const S = snap.underlyingPrice;
|
|
1093
|
+
const remaining: TradeLeg[] = [];
|
|
1094
|
+
let settled = 0;
|
|
1095
|
+
let assigned = false;
|
|
1096
|
+
const mult = t.position.multiplier;
|
|
1097
|
+
t.position.legs.forEach((leg, index) => {
|
|
1098
|
+
const live = t.live[index]!;
|
|
1099
|
+
if (leg.kind === 'stock' || leg.expiry === undefined || !which(leg, index)) {
|
|
1100
|
+
remaining.push(live);
|
|
1101
|
+
return;
|
|
1102
|
+
}
|
|
1103
|
+
const intrinsic = intrinsicOf(leg.kind, S, leg.strike);
|
|
1104
|
+
const action = intrinsic <= 0 ? 'expired' : leg.quantity > 0 ? 'exercised' : 'assigned';
|
|
1105
|
+
const cashFlow = leg.quantity * mult * intrinsic;
|
|
1106
|
+
cash += cashFlow;
|
|
1107
|
+
t.settledPnl += leg.quantity * mult * (intrinsic - leg.premium);
|
|
1108
|
+
const settlement: OptionSettlement = {
|
|
1109
|
+
symbol: live.instrumentId,
|
|
1110
|
+
underlying: t.underlying,
|
|
1111
|
+
timestampMs: asOfMs,
|
|
1112
|
+
type: leg.kind,
|
|
1113
|
+
strike: leg.strike,
|
|
1114
|
+
multiplier: mult,
|
|
1115
|
+
contracts: leg.quantity,
|
|
1116
|
+
underlierPrice: S,
|
|
1117
|
+
intrinsic,
|
|
1118
|
+
action,
|
|
1119
|
+
settlement: 'cash',
|
|
1120
|
+
cashFlow,
|
|
1121
|
+
shares: 0,
|
|
1122
|
+
...(early !== null ? { early: true, reason: early.reason } : {}),
|
|
1123
|
+
};
|
|
1124
|
+
settlements.push(settlement);
|
|
1125
|
+
t.legSettlements.push({ legIndex: live.originalIndex, settlement });
|
|
1126
|
+
if (action === 'assigned') {
|
|
1127
|
+
assigned = true;
|
|
1128
|
+
warnings.push({
|
|
1129
|
+
code: WarningCode.BacktestAssignment,
|
|
1130
|
+
message:
|
|
1131
|
+
early === null
|
|
1132
|
+
? `A short ${leg.kind} at ${leg.strike} was ITM at expiry and assigned.`
|
|
1133
|
+
: `A short ${leg.kind} at ${leg.strike} was assigned early (${early.reason}) at ${asOfMs}.`,
|
|
1134
|
+
severity: 'info',
|
|
1135
|
+
});
|
|
1136
|
+
}
|
|
1137
|
+
const quantity = Math.abs(leg.quantity);
|
|
1138
|
+
if (early === null) stamp(optionExpiryToMs(leg.expiry));
|
|
1139
|
+
const event: PortfolioEventEnvelope['event'] =
|
|
1140
|
+
action === 'expired'
|
|
1141
|
+
? { eventType: 'derivative.expiration', instrumentId: live.instrumentId, quantity }
|
|
1142
|
+
: action === 'exercised'
|
|
1143
|
+
? {
|
|
1144
|
+
eventType: 'derivative.exercise',
|
|
1145
|
+
instrumentId: live.instrumentId,
|
|
1146
|
+
quantity,
|
|
1147
|
+
settlement: { kind: 'cash', settlementPricePerUnit: S },
|
|
1148
|
+
premiumTreatment: 'realize',
|
|
1149
|
+
}
|
|
1150
|
+
: {
|
|
1151
|
+
eventType: 'derivative.assignment',
|
|
1152
|
+
instrumentId: live.instrumentId,
|
|
1153
|
+
quantity,
|
|
1154
|
+
settlement: { kind: 'cash', settlementPricePerUnit: S },
|
|
1155
|
+
premiumTreatment: 'realize',
|
|
1156
|
+
};
|
|
1157
|
+
fold([envelope(asOfMs, event, `${runId}:t${t.tradeId}`)]);
|
|
1158
|
+
settled += 1;
|
|
1159
|
+
});
|
|
1160
|
+
if (settled > 0) {
|
|
1161
|
+
t.live = remaining;
|
|
1162
|
+
t.position = new Position(
|
|
1163
|
+
remaining.map((r) => ({ ...r.leg })),
|
|
1164
|
+
{
|
|
1165
|
+
multiplier: mult,
|
|
1166
|
+
...(positionExpiryOf(t.position) !== undefined
|
|
1167
|
+
? { expiry: positionExpiryOf(t.position)! }
|
|
1168
|
+
: {}),
|
|
1169
|
+
},
|
|
1170
|
+
);
|
|
1171
|
+
t.markCache = null;
|
|
1172
|
+
}
|
|
1173
|
+
return { settled, assigned };
|
|
1174
|
+
};
|
|
1175
|
+
|
|
1176
|
+
const discloseFallbacks = (t: OpenTrade): void => {
|
|
1177
|
+
for (const [cause, count] of [...t.fallbacks.entries()].sort()) {
|
|
1178
|
+
warnings.push({
|
|
1179
|
+
code: WarningCode.BacktestMarkFallback,
|
|
1180
|
+
message: `${FN}: the trade entered at ${t.entryAsOf} marked ${count} leg-snapshot${count === 1 ? '' : 's'} by the '${marking.missingMark}' fallback because ${MISSING_MARK_TEACHING[cause]} (cause '${cause}') — its P&L over those marks is not quote-driven.`,
|
|
1181
|
+
severity: 'warn',
|
|
1182
|
+
context: {
|
|
1183
|
+
entryAsOf: t.entryAsOf,
|
|
1184
|
+
cause,
|
|
1185
|
+
legSnapshots: count,
|
|
1186
|
+
missingMark: marking.missingMark,
|
|
1187
|
+
},
|
|
1188
|
+
});
|
|
1189
|
+
}
|
|
1190
|
+
};
|
|
1191
|
+
|
|
1192
|
+
const tradeRow = (input: {
|
|
1193
|
+
t: OpenTrade;
|
|
1194
|
+
/** The position and live legs the row describes — captured BEFORE a settlement removed legs. */
|
|
1195
|
+
position: Position;
|
|
1196
|
+
live: readonly TradeLeg[];
|
|
1197
|
+
snap: ChainSnapshot;
|
|
1198
|
+
exitAsOf: EpochMs | null;
|
|
1199
|
+
reason: ExitReason;
|
|
1200
|
+
exitCosts: number;
|
|
1201
|
+
m: ReturnType<typeof markTrade> | null;
|
|
1202
|
+
markAsOf: EpochMs;
|
|
1203
|
+
grossPnl: number;
|
|
1204
|
+
}): OptionsTrade => {
|
|
1205
|
+
const { t, position, live, snap, exitAsOf, reason, exitCosts, m, markAsOf, grossPnl } = input;
|
|
1206
|
+
const perLeg = m === null ? [] : m.perLeg;
|
|
1207
|
+
const exitVolatilities: (number | null)[] = t.originalLegs.map(() => null);
|
|
1208
|
+
const attribution: LegAttribution[] = t.originalLegs.map((leg) => ({ leg, realizedPnl: 0 }));
|
|
1209
|
+
for (const { legIndex, settlement } of t.legSettlements) {
|
|
1210
|
+
const leg = t.originalLegs[legIndex]!;
|
|
1211
|
+
attribution[legIndex] = {
|
|
1212
|
+
leg,
|
|
1213
|
+
realizedPnl:
|
|
1214
|
+
leg.quantity *
|
|
1215
|
+
settlement.multiplier *
|
|
1216
|
+
(settlement.intrinsic - (leg.kind === 'stock' ? leg.price : leg.premium)),
|
|
1217
|
+
};
|
|
1218
|
+
}
|
|
1219
|
+
live.forEach((l, index) => {
|
|
1220
|
+
const valuation = perLeg[index];
|
|
1221
|
+
if (valuation === undefined) return;
|
|
1222
|
+
attribution[l.originalIndex] = { leg: l.leg, realizedPnl: valuation.pnl };
|
|
1223
|
+
exitVolatilities[l.originalIndex] =
|
|
1224
|
+
l.leg.kind === 'stock' || valuation.greeks.vega === 0 ? null : (l.lastVolatility ?? null);
|
|
1225
|
+
});
|
|
1226
|
+
return {
|
|
1227
|
+
structure: t.structure,
|
|
1228
|
+
entryAsOf: t.entryAsOf,
|
|
1229
|
+
exitAsOf,
|
|
1230
|
+
expiry: positionExpiriesOfLegs(t.originalLegs)[0] ?? '',
|
|
1231
|
+
contracts: t.contracts,
|
|
1232
|
+
entryPremium: t.entryPremium,
|
|
1233
|
+
realizedPnl: grossPnl - t.entryCosts - exitCosts,
|
|
1234
|
+
costs: t.entryCosts + exitCosts,
|
|
1235
|
+
exitReason: reason,
|
|
1236
|
+
perLeg: attribution,
|
|
1237
|
+
legs: t.originalLegs,
|
|
1238
|
+
pnlExplain: tradePnlExplain({
|
|
1239
|
+
position,
|
|
1240
|
+
entry: {
|
|
1241
|
+
asOf: t.entryAsOf,
|
|
1242
|
+
spot: t.entrySpot,
|
|
1243
|
+
volatility: t.entryVolatility,
|
|
1244
|
+
...(marking.volatility === 'current-quote'
|
|
1245
|
+
? { legVolatilities: live.map((l) => l.entryVolatility) }
|
|
1246
|
+
: {}),
|
|
1247
|
+
},
|
|
1248
|
+
exit: {
|
|
1249
|
+
asOf: markAsOf,
|
|
1250
|
+
spot: snap.underlyingPrice,
|
|
1251
|
+
volatility: atmVolatility(snap),
|
|
1252
|
+
...(marking.volatility === 'current-quote' && m !== null
|
|
1253
|
+
? {
|
|
1254
|
+
legVolatilities: live.map((l, index) =>
|
|
1255
|
+
l.leg.kind === 'stock' || perLeg[index]?.greeks.vega === 0
|
|
1256
|
+
? undefined
|
|
1257
|
+
: l.lastVolatility,
|
|
1258
|
+
),
|
|
1259
|
+
}
|
|
1260
|
+
: {}),
|
|
1261
|
+
},
|
|
1262
|
+
riskFreeRate: rate,
|
|
1263
|
+
dividendYield,
|
|
1264
|
+
grossPnl,
|
|
1265
|
+
}),
|
|
1266
|
+
marks: { ...t.marks },
|
|
1267
|
+
exitVolatilities,
|
|
1268
|
+
tradeId: t.tradeId,
|
|
1269
|
+
ruleId: t.ruleId,
|
|
1270
|
+
underlying: t.underlying,
|
|
1271
|
+
legInstrumentIds: [...t.originalInstrumentIds],
|
|
1272
|
+
lineage: [...t.lineage],
|
|
1273
|
+
partial: t.partial,
|
|
1274
|
+
unfilledLegs: [...t.unfilledLegs],
|
|
1275
|
+
legSettlements: [...t.legSettlements],
|
|
1276
|
+
};
|
|
1277
|
+
};
|
|
1278
|
+
const positionExpiriesOfLegs = (legs: readonly Leg[]): string[] => {
|
|
1279
|
+
const set = new Set<string>();
|
|
1280
|
+
for (const l of legs) if (l.expiry !== undefined) set.add(l.expiry);
|
|
1281
|
+
return [...set];
|
|
1282
|
+
};
|
|
1283
|
+
|
|
1284
|
+
const removeFromBook = (t: OpenTrade): void => {
|
|
1285
|
+
const index = book.indexOf(t);
|
|
1286
|
+
if (index >= 0) book.splice(index, 1);
|
|
1287
|
+
};
|
|
1288
|
+
|
|
1289
|
+
/** Close a trade: settle any expired legs, sell the live legs at their marks, record the row. */
|
|
1290
|
+
/**
|
|
1291
|
+
* Close a trade. A settlement marks the WHOLE position at the settlement instant first (expired
|
|
1292
|
+
* legs at intrinsic — the explain and the attribution see every leg), settles the expired legs
|
|
1293
|
+
* (cash and ledger events), then closes whatever remains at that same mark.
|
|
1294
|
+
*/
|
|
1295
|
+
const closeTrade = (
|
|
1296
|
+
t: OpenTrade,
|
|
1297
|
+
snap: ChainSnapshot,
|
|
1298
|
+
asOfMs: EpochMs,
|
|
1299
|
+
reason: ExitReason,
|
|
1300
|
+
isSettlement: boolean,
|
|
1301
|
+
): void => {
|
|
1302
|
+
const position = t.position;
|
|
1303
|
+
const live = [...t.live];
|
|
1304
|
+
let m: ReturnType<typeof markTrade> | null = null;
|
|
1305
|
+
let exitCosts = 0;
|
|
1306
|
+
let markAsOf = asOfMs;
|
|
1307
|
+
let grossPnl = t.settledPnl;
|
|
1308
|
+
if (position.legs.length > 0) {
|
|
1309
|
+
markAsOf = isSettlement ? settlementInstant(position, asOfMs) : asOfMs;
|
|
1310
|
+
m = markTrade(t, snap, asOfMs, markAsOf);
|
|
1311
|
+
grossPnl = m.pnl + t.settledPnl;
|
|
1312
|
+
const settledBefore = t.legSettlements.length;
|
|
1313
|
+
if (isSettlement) {
|
|
1314
|
+
settleLegs(
|
|
1315
|
+
t,
|
|
1316
|
+
snap,
|
|
1317
|
+
asOfMs,
|
|
1318
|
+
(leg) => leg.expiry !== undefined && daysToExpiry(asOfMs, leg.expiry) <= 0,
|
|
1319
|
+
null,
|
|
1320
|
+
);
|
|
1321
|
+
}
|
|
1322
|
+
const settledNow = new Set(t.legSettlements.slice(settledBefore).map((x) => x.legIndex));
|
|
1323
|
+
const mult = position.multiplier;
|
|
1324
|
+
const pieces: CostPieces[] = [];
|
|
1325
|
+
let closingValue = 0;
|
|
1326
|
+
m.perLeg.forEach((p, index) => {
|
|
1327
|
+
const l = live[index]!;
|
|
1328
|
+
if (settledNow.has(l.originalIndex)) return;
|
|
1329
|
+
closingValue += p.value;
|
|
1330
|
+
const units = Math.abs(p.leg.quantity);
|
|
1331
|
+
if (units === 0) return;
|
|
1332
|
+
const side: OrderSide = sideOf(-p.leg.quantity); // closing: the opposite of the held sign
|
|
1333
|
+
if (p.leg.kind === 'stock') {
|
|
1334
|
+
const shares = units;
|
|
1335
|
+
bookFill({
|
|
1336
|
+
asOfMs,
|
|
1337
|
+
instrumentId: l.instrumentId,
|
|
1338
|
+
side,
|
|
1339
|
+
quantity: shares,
|
|
1340
|
+
pricePerUnit: Math.abs(p.value) / shares,
|
|
1341
|
+
contractMultiplier: 1,
|
|
1342
|
+
costs: { commission: 0, slippageAdjustment: 0 },
|
|
1343
|
+
orderId: `${runId}:t${t.tradeId}:close`,
|
|
1344
|
+
});
|
|
1345
|
+
return;
|
|
1346
|
+
}
|
|
1347
|
+
const perContractPrice = Math.abs(p.value / p.leg.quantity);
|
|
1348
|
+
const piece = isSettlement
|
|
1349
|
+
? { commission: 0, slippageAdjustment: 0 }
|
|
1350
|
+
: legCost(units, perContractPrice, side, commission, slippage);
|
|
1351
|
+
pieces.push(piece);
|
|
1352
|
+
bookFill({
|
|
1353
|
+
asOfMs,
|
|
1354
|
+
instrumentId: l.instrumentId,
|
|
1355
|
+
side,
|
|
1356
|
+
quantity: units,
|
|
1357
|
+
pricePerUnit: perContractPrice / mult,
|
|
1358
|
+
contractMultiplier: mult,
|
|
1359
|
+
contract: optionTerms(t.underlying, p.leg, p.leg.expiry ?? positionExpiryOf(position)),
|
|
1360
|
+
costs: piece,
|
|
1361
|
+
orderId: `${runId}:t${t.tradeId}:close`,
|
|
1362
|
+
});
|
|
1363
|
+
});
|
|
1364
|
+
exitCosts = totalCost(pieces);
|
|
1365
|
+
cash += closingValue - exitCosts;
|
|
1366
|
+
}
|
|
1367
|
+
discloseFallbacks(t);
|
|
1368
|
+
trades.push(
|
|
1369
|
+
tradeRow({
|
|
1370
|
+
t,
|
|
1371
|
+
position,
|
|
1372
|
+
live,
|
|
1373
|
+
snap,
|
|
1374
|
+
exitAsOf: asOfMs,
|
|
1375
|
+
reason,
|
|
1376
|
+
exitCosts,
|
|
1377
|
+
m,
|
|
1378
|
+
markAsOf,
|
|
1379
|
+
grossPnl,
|
|
1380
|
+
}),
|
|
1381
|
+
);
|
|
1382
|
+
removeFromBook(t);
|
|
1383
|
+
};
|
|
1384
|
+
|
|
1385
|
+
// ---- the pre-trade limits, on the post-trade book ---------------------------------------------------
|
|
1386
|
+
const limitCheck = (
|
|
1387
|
+
candidate: OpenTrade,
|
|
1388
|
+
candidateMark: ReturnType<typeof markTrade>,
|
|
1389
|
+
snap: ChainSnapshot,
|
|
1390
|
+
asOfMs: EpochMs,
|
|
1391
|
+
equityNow: number,
|
|
1392
|
+
): LimitRejection | null => {
|
|
1393
|
+
const rejection = (
|
|
1394
|
+
limit: keyof PortfolioLimits,
|
|
1395
|
+
value: number,
|
|
1396
|
+
bound: number,
|
|
1397
|
+
): LimitRejection => ({
|
|
1398
|
+
asOf: asOfMs,
|
|
1399
|
+
ruleId: candidate.ruleId,
|
|
1400
|
+
structure: candidate.structure,
|
|
1401
|
+
limit,
|
|
1402
|
+
value,
|
|
1403
|
+
bound,
|
|
1404
|
+
code: WarningCode.BacktestLimitRejected,
|
|
1405
|
+
});
|
|
1406
|
+
const spot = snap.underlyingPrice;
|
|
1407
|
+
const all = [...book, candidate];
|
|
1408
|
+
const marks = all.map((t) => (t === candidate ? candidateMark : markTrade(t, snap, asOfMs)));
|
|
1409
|
+
if (limits.maximumMarginFraction !== undefined) {
|
|
1410
|
+
const margin = all.reduce((sum, t) => sum + optionMargin(t.position, spot), 0);
|
|
1411
|
+
const bound = limits.maximumMarginFraction * equityNow;
|
|
1412
|
+
if (margin > bound) return rejection('maximumMarginFraction', margin, bound);
|
|
1413
|
+
}
|
|
1414
|
+
const sameUnderlying = all
|
|
1415
|
+
.map((t, i) => [t, marks[i]!] as const)
|
|
1416
|
+
.filter(([t]) => t.underlying === candidate.underlying);
|
|
1417
|
+
if (limits.maximumNetDelta !== undefined) {
|
|
1418
|
+
const delta =
|
|
1419
|
+
sameUnderlying.reduce((sum, [, mk]) => sum + mk.greeks.delta, 0) +
|
|
1420
|
+
(hedgeUnderlying === candidate.underlying ? hedgeShares : 0);
|
|
1421
|
+
if (Math.abs(delta) > limits.maximumNetDelta)
|
|
1422
|
+
return rejection('maximumNetDelta', Math.abs(delta), limits.maximumNetDelta);
|
|
1423
|
+
}
|
|
1424
|
+
if (limits.maximumNetVega !== undefined) {
|
|
1425
|
+
const vega = sameUnderlying.reduce((sum, [, mk]) => sum + mk.greeks.vega, 0);
|
|
1426
|
+
if (Math.abs(vega) > limits.maximumNetVega)
|
|
1427
|
+
return rejection('maximumNetVega', Math.abs(vega), limits.maximumNetVega);
|
|
1428
|
+
}
|
|
1429
|
+
if (limits.maximumConcentration !== undefined) {
|
|
1430
|
+
const atRisk = sameUnderlying.reduce((sum, [t]) => sum + Math.abs(t.entryPremium), 0);
|
|
1431
|
+
const bound = limits.maximumConcentration * equityNow;
|
|
1432
|
+
if (atRisk > bound) return rejection('maximumConcentration', atRisk, bound);
|
|
1433
|
+
}
|
|
1434
|
+
if (limits.scenarioLoss !== undefined) {
|
|
1435
|
+
const aggregate = aggregateGreeks(
|
|
1436
|
+
marks.map((mk, i) => ({
|
|
1437
|
+
id: `t${all[i]!.tradeId}`,
|
|
1438
|
+
quantity: 1,
|
|
1439
|
+
greeks: {
|
|
1440
|
+
value: mk.perLeg.reduce((s, p) => s + p.value, 0),
|
|
1441
|
+
spot,
|
|
1442
|
+
delta: mk.greeks.delta,
|
|
1443
|
+
gamma: mk.greeks.gamma,
|
|
1444
|
+
vega: mk.greeks.vega,
|
|
1445
|
+
theta: mk.greeks.theta,
|
|
1446
|
+
rho: mk.greeks.rho,
|
|
1447
|
+
},
|
|
1448
|
+
})),
|
|
1449
|
+
);
|
|
1450
|
+
const greeks = aggregate.value;
|
|
1451
|
+
const grid = scenarioGrid({
|
|
1452
|
+
greeks: {
|
|
1453
|
+
value: greeks.value,
|
|
1454
|
+
spot,
|
|
1455
|
+
delta: greeks.delta,
|
|
1456
|
+
gamma: greeks.gamma,
|
|
1457
|
+
vega: greeks.vega,
|
|
1458
|
+
theta: greeks.theta,
|
|
1459
|
+
rho: greeks.rho,
|
|
1460
|
+
},
|
|
1461
|
+
spotShocks: limits.scenarioLoss.spotShocks.map((value) => ({
|
|
1462
|
+
factor: 'spot',
|
|
1463
|
+
kind: 'percent',
|
|
1464
|
+
value,
|
|
1465
|
+
})),
|
|
1466
|
+
volatilityShocks: limits.scenarioLoss.volatilityShocks.map((value) => ({
|
|
1467
|
+
factor: 'volatility',
|
|
1468
|
+
kind: 'absolute',
|
|
1469
|
+
value,
|
|
1470
|
+
})),
|
|
1471
|
+
});
|
|
1472
|
+
let worst = 0;
|
|
1473
|
+
for (const row of grid.pnl) for (const pnl of row) if (pnl < worst) worst = pnl;
|
|
1474
|
+
const bound = limits.scenarioLoss.maximumLossFraction * equityNow;
|
|
1475
|
+
if (-worst > bound) return rejection('scenarioLoss', -worst, bound);
|
|
1476
|
+
}
|
|
1477
|
+
return null;
|
|
1478
|
+
};
|
|
1479
|
+
|
|
1480
|
+
// ---- the fill policy -------------------------------------------------------------------------------
|
|
1481
|
+
const usability = (
|
|
1482
|
+
quote: OptionQuote | undefined,
|
|
1483
|
+
asOfMs: EpochMs,
|
|
1484
|
+
): UnfilledLeg['cause'] | null => {
|
|
1485
|
+
if (quote === undefined) return 'missing';
|
|
1486
|
+
if (
|
|
1487
|
+
maximumFillQuoteAgeMs !== null &&
|
|
1488
|
+
typeof quote.timestampMs === 'number' &&
|
|
1489
|
+
asOfMs - quote.timestampMs > maximumFillQuoteAgeMs
|
|
1490
|
+
)
|
|
1491
|
+
return 'stale';
|
|
1492
|
+
const price = selectQuotePrice(quote, fillPrice);
|
|
1493
|
+
if (price === undefined || !Number.isFinite(price) || price < 0) return 'unpriceable';
|
|
1494
|
+
return null;
|
|
1495
|
+
};
|
|
1496
|
+
|
|
1497
|
+
// ---- entry -----------------------------------------------------------------------------------------
|
|
1498
|
+
const openTradeViews = (snap: ChainSnapshot, asOfMs: EpochMs): OpenTradeView[] =>
|
|
1499
|
+
book.map((t) => ({
|
|
1500
|
+
tradeId: t.tradeId,
|
|
1501
|
+
ruleId: t.ruleId,
|
|
1502
|
+
structure: t.structure,
|
|
1503
|
+
underlying: t.underlying,
|
|
1504
|
+
entryAsOf: t.entryAsOf,
|
|
1505
|
+
entryPremium: t.entryPremium,
|
|
1506
|
+
markToMarket: t.position.legs.length === 0 ? 0 : markTrade(t, snap, asOfMs).pnl,
|
|
1507
|
+
legs: t.originalLegs,
|
|
1508
|
+
}));
|
|
1509
|
+
const underlyingOf = (snap: ChainSnapshot, quotes: readonly (OptionQuote | null)[]): string =>
|
|
1510
|
+
quotes.find((q) => q !== null)?.contract.underlying ??
|
|
1511
|
+
snap.quotes[0]?.contract.underlying ??
|
|
1512
|
+
'UNDERLYING';
|
|
1513
|
+
|
|
1514
|
+
const tryEnter = (attempt: {
|
|
1515
|
+
ruleIndex: number;
|
|
1516
|
+
snap: ChainSnapshot;
|
|
1517
|
+
asOfMs: EpochMs;
|
|
1518
|
+
equityNow: number;
|
|
1519
|
+
}): void => {
|
|
1520
|
+
const { ruleIndex, snap, asOfMs, equityNow } = attempt;
|
|
1521
|
+
const rule = rules[ruleIndex]!;
|
|
1522
|
+
const ruleId = ruleIds[ruleIndex]!;
|
|
1523
|
+
if (book.length >= maximumOpenPositions) return;
|
|
1524
|
+
const flat = !book.some((t) => t.ruleIndex === ruleIndex);
|
|
1525
|
+
const context: EntryContext = {
|
|
1526
|
+
snapshot: snap,
|
|
1527
|
+
asOf: asOfMs,
|
|
1528
|
+
cash,
|
|
1529
|
+
equity: equityNow,
|
|
1530
|
+
flat,
|
|
1531
|
+
openTrades: openTradeViews(snap, asOfMs),
|
|
1532
|
+
};
|
|
1533
|
+
const gate = rule.when ?? 'flat';
|
|
1534
|
+
const gateOpen = gate === 'flat' ? flat : gate === 'always' ? true : gate(context);
|
|
1535
|
+
if (!gateOpen) return;
|
|
1536
|
+
|
|
1537
|
+
const isBuild = 'build' in rule;
|
|
1538
|
+
const buildFn = (): Position | null => (isBuild ? rule.build(context) : null);
|
|
1539
|
+
let quantity = 1;
|
|
1540
|
+
if (!isBuild && rule.sizing && 'quantity' in rule.sizing) {
|
|
1541
|
+
quantity = rule.sizing.quantity;
|
|
1542
|
+
} else if (!isBuild && rule.sizing && 'maxMarginFraction' in rule.sizing) {
|
|
1543
|
+
sizingMode = 'margin-aware';
|
|
1544
|
+
const probe = buildEntryPosition(rule, snap, asOfMs, 1, buildFn);
|
|
1545
|
+
if ('skip' in probe) return skip(asOfMs, ruleId, probe.skip);
|
|
1546
|
+
const perLot = optionMargin(probe.position, snap.underlyingPrice);
|
|
1547
|
+
const budget = Math.max(0, rule.sizing.maxMarginFraction * equityNow);
|
|
1548
|
+
quantity = perLot > 0 ? Math.floor(budget / perLot) : 0;
|
|
1549
|
+
if (quantity < 1) return skip(asOfMs, ruleId, 'margin budget affords < 1 contract');
|
|
1550
|
+
}
|
|
1551
|
+
const built = buildEntryPosition(rule, snap, asOfMs, quantity, buildFn);
|
|
1552
|
+
if ('skip' in built) return skip(asOfMs, ruleId, built.skip);
|
|
1553
|
+
let position = built.position;
|
|
1554
|
+
const structure = position.constructedAs ?? ('structure' in rule ? rule.structure : 'custom');
|
|
1555
|
+
const underlying = underlyingOf(snap, built.quotes);
|
|
1556
|
+
if (
|
|
1557
|
+
maximumPerUnderlying !== null &&
|
|
1558
|
+
book.filter((t) => t.underlying === underlying).length >= maximumPerUnderlying
|
|
1559
|
+
)
|
|
1560
|
+
return;
|
|
1561
|
+
|
|
1562
|
+
// The fill policy: every leg's quote must be usable (combo), or the sequence stops (legged).
|
|
1563
|
+
const unfilled: UnfilledLeg[] = [];
|
|
1564
|
+
if (!isBuild) {
|
|
1565
|
+
const keep: boolean[] = position.legs.map(() => true);
|
|
1566
|
+
let stopped = false;
|
|
1567
|
+
let optionLegs = 0;
|
|
1568
|
+
position.legs.forEach((leg, index) => {
|
|
1569
|
+
if (leg.kind === 'stock') return;
|
|
1570
|
+
optionLegs += 1;
|
|
1571
|
+
const cause = stopped ? 'missing' : usability(built.quotes[index] ?? undefined, asOfMs);
|
|
1572
|
+
if (cause === null && !stopped) return;
|
|
1573
|
+
if (fillMode === 'legged') stopped = true;
|
|
1574
|
+
unfilled.push({ leg, cause: cause ?? 'missing' });
|
|
1575
|
+
keep[index] = false;
|
|
1576
|
+
});
|
|
1577
|
+
if (unfilled.length > 0) {
|
|
1578
|
+
const kept = position.legs.filter((_, index) => keep[index]);
|
|
1579
|
+
if (
|
|
1580
|
+
fillMode === 'combo' ||
|
|
1581
|
+
partialFill === 'reject' ||
|
|
1582
|
+
kept.every((l) => l.kind === 'stock')
|
|
1583
|
+
) {
|
|
1584
|
+
fillRejections.push({
|
|
1585
|
+
asOf: asOfMs,
|
|
1586
|
+
ruleId,
|
|
1587
|
+
structure,
|
|
1588
|
+
mode: fillMode,
|
|
1589
|
+
unfilledLegs: unfilled,
|
|
1590
|
+
code: WarningCode.BacktestComboLegUnfilled,
|
|
1591
|
+
});
|
|
1592
|
+
warnings.push({
|
|
1593
|
+
code: WarningCode.BacktestComboLegUnfilled,
|
|
1594
|
+
message: `${FN}: ${ruleId} at ${asOfMs}: ${unfilled.length} of ${optionLegs} legs could not fill (${unfilled.map((u) => `${u.leg.kind} ${u.leg.strike}: ${u.cause}`).join('; ')}) — the entry was rejected under fillPolicy.mode '${fillMode}'.`,
|
|
1595
|
+
severity: 'info',
|
|
1596
|
+
});
|
|
1597
|
+
return;
|
|
1598
|
+
}
|
|
1599
|
+
position = new Position(
|
|
1600
|
+
kept.map((l) => ({ ...l })),
|
|
1601
|
+
{
|
|
1602
|
+
multiplier: position.multiplier,
|
|
1603
|
+
...(positionExpiryOf(position) !== undefined
|
|
1604
|
+
? { expiry: positionExpiryOf(position)! }
|
|
1605
|
+
: {}),
|
|
1606
|
+
},
|
|
1607
|
+
);
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1611
|
+
const positionExpiry = positionExpiryOf(position);
|
|
1612
|
+
const candidate: OpenTrade = {
|
|
1613
|
+
tradeId: nextTradeId,
|
|
1614
|
+
ruleId,
|
|
1615
|
+
ruleIndex,
|
|
1616
|
+
underlying,
|
|
1617
|
+
structure,
|
|
1618
|
+
position,
|
|
1619
|
+
live: position.legs.map((leg, index) => ({
|
|
1620
|
+
leg,
|
|
1621
|
+
originalIndex: index,
|
|
1622
|
+
instrumentId: legInstrumentId(underlying, leg, leg.expiry ?? positionExpiry),
|
|
1623
|
+
entryVolatility: leg.kind === 'stock' ? undefined : leg.impliedVolatility,
|
|
1624
|
+
lastVolatility: leg.kind === 'stock' ? undefined : leg.impliedVolatility,
|
|
1625
|
+
})),
|
|
1626
|
+
originalLegs: [...position.legs],
|
|
1627
|
+
originalInstrumentIds: position.legs.map((leg) =>
|
|
1628
|
+
legInstrumentId(underlying, leg, leg.expiry ?? positionExpiry),
|
|
1629
|
+
),
|
|
1630
|
+
entryAsOf: asOfMs,
|
|
1631
|
+
entryPremium: 0,
|
|
1632
|
+
contracts: isBuild ? maxLotOf(position) : quantity,
|
|
1633
|
+
entryCosts: 0,
|
|
1634
|
+
entrySpot: snap.underlyingPrice,
|
|
1635
|
+
entryVolatility: atmVolatility(snap),
|
|
1636
|
+
markCache: null,
|
|
1637
|
+
marks: { snapshots: 0, currentQuote: 0, impliedFromPrice: 0, entryVolatility: 0, carried: 0 },
|
|
1638
|
+
fallbacks: new Map(),
|
|
1639
|
+
settledPnl: 0,
|
|
1640
|
+
legSettlements: [],
|
|
1641
|
+
lineage: [],
|
|
1642
|
+
partial: unfilled.length > 0,
|
|
1643
|
+
unfilledLegs: unfilled,
|
|
1644
|
+
};
|
|
1645
|
+
let entryMark: ReturnType<typeof markTrade>;
|
|
1646
|
+
try {
|
|
1647
|
+
entryMark = markTrade(candidate, snap, asOfMs);
|
|
1648
|
+
candidate.live.forEach((l, index) => {
|
|
1649
|
+
if (entryMark.perLeg[index]!.leg.kind !== 'stock') l.entryVolatility = l.lastVolatility;
|
|
1650
|
+
});
|
|
1651
|
+
} catch (err) {
|
|
1652
|
+
if (isQuantError(err)) {
|
|
1653
|
+
return skip(
|
|
1654
|
+
asOfMs,
|
|
1655
|
+
ruleId,
|
|
1656
|
+
isQuantError(err, ErrorCode.BacktestMarkUnavailable)
|
|
1657
|
+
? `position not markable from the entry snapshot (${String((err.context as { cause?: unknown }).cause)})`
|
|
1658
|
+
: 'position not markable (no vol available)',
|
|
1659
|
+
);
|
|
1660
|
+
}
|
|
1661
|
+
throw err;
|
|
1662
|
+
}
|
|
1663
|
+
const entryPremium = position.netDebit();
|
|
1664
|
+
candidate.entryPremium = entryPremium;
|
|
1665
|
+
const rejected = limitCheck(candidate, entryMark, snap, asOfMs, equityNow);
|
|
1666
|
+
if (rejected !== null) {
|
|
1667
|
+
limitRejections.push(rejected);
|
|
1668
|
+
warnings.push({
|
|
1669
|
+
code: WarningCode.BacktestLimitRejected,
|
|
1670
|
+
message: `${FN}: ${ruleId} at ${asOfMs}: the post-trade book would carry ${rejected.limit} = ${rejected.value} against the bound ${rejected.bound} — the entry was rejected; nothing was scaled.`,
|
|
1671
|
+
severity: 'info',
|
|
1672
|
+
});
|
|
1673
|
+
return;
|
|
1674
|
+
}
|
|
1675
|
+
// Fills: one per option leg at the entry premium, with the ledger's cost rows.
|
|
1676
|
+
const mult = position.multiplier;
|
|
1677
|
+
const pieces: CostPieces[] = [];
|
|
1678
|
+
position.legs.forEach((leg, index) => {
|
|
1679
|
+
if (leg.kind === 'stock') {
|
|
1680
|
+
const shares = Math.abs(leg.quantity);
|
|
1681
|
+
const side: OrderSide = sideOf(leg.quantity);
|
|
1682
|
+
bookFill({
|
|
1683
|
+
asOfMs,
|
|
1684
|
+
instrumentId: underlying,
|
|
1685
|
+
side,
|
|
1686
|
+
quantity: shares,
|
|
1687
|
+
pricePerUnit: leg.price,
|
|
1688
|
+
contractMultiplier: 1,
|
|
1689
|
+
costs: { commission: 0, slippageAdjustment: 0 },
|
|
1690
|
+
orderId: `${runId}:t${candidate.tradeId}:open`,
|
|
1691
|
+
});
|
|
1692
|
+
return;
|
|
1693
|
+
}
|
|
1694
|
+
const contracts = Math.abs(leg.quantity);
|
|
1695
|
+
const side: OrderSide = sideOf(leg.quantity);
|
|
1696
|
+
const piece = legCost(contracts, perContract(leg.premium, mult), side, commission, slippage);
|
|
1697
|
+
pieces.push(piece);
|
|
1698
|
+
bookFill({
|
|
1699
|
+
asOfMs,
|
|
1700
|
+
instrumentId: candidate.live[index]!.instrumentId,
|
|
1701
|
+
side,
|
|
1702
|
+
quantity: contracts,
|
|
1703
|
+
pricePerUnit: leg.premium,
|
|
1704
|
+
contractMultiplier: mult,
|
|
1705
|
+
contract: optionTerms(underlying, leg, leg.expiry ?? positionExpiry),
|
|
1706
|
+
costs: piece,
|
|
1707
|
+
orderId: `${runId}:t${candidate.tradeId}:open`,
|
|
1708
|
+
});
|
|
1709
|
+
});
|
|
1710
|
+
const cost = totalCost(pieces);
|
|
1711
|
+
cash += -entryPremium - cost;
|
|
1712
|
+
candidate.entryCosts = cost;
|
|
1713
|
+
nextTradeId += 1;
|
|
1714
|
+
book.push(candidate);
|
|
1715
|
+
};
|
|
1716
|
+
|
|
1717
|
+
// ---- corporate actions and dividends ---------------------------------------------------------------
|
|
1718
|
+
let nextActionIndex = 0;
|
|
1719
|
+
const applyCorporateActions = (asOfMs: EpochMs): void => {
|
|
1720
|
+
const date = dateOf(asOfMs);
|
|
1721
|
+
while (
|
|
1722
|
+
nextActionIndex < corporateActions.length &&
|
|
1723
|
+
corporateActions[nextActionIndex]!.effectiveDate <= date
|
|
1724
|
+
) {
|
|
1725
|
+
const action = corporateActions[nextActionIndex]!;
|
|
1726
|
+
nextActionIndex += 1;
|
|
1727
|
+
const affected = book.filter((t) => t.underlying === action.symbol);
|
|
1728
|
+
if (action.type === 'dividend' || action.type === 'other') continue;
|
|
1729
|
+
if (affected.length === 0 && !(hedgeUnderlying === action.symbol && hedgeShares !== 0))
|
|
1730
|
+
continue;
|
|
1731
|
+
if (action.type === 'merger' || action.type === 'spinoff') {
|
|
1732
|
+
throw new InputError(
|
|
1733
|
+
`${FN}: a ${action.type} on ${action.symbol} effective ${action.effectiveDate} meets ${affected.length} open option trade${affected.length === 1 ? '' : 's'} — the deliverable of an open option leg cannot be adjusted for a ${action.type}; close the legs before the effective date or drop the action.`,
|
|
1734
|
+
{
|
|
1735
|
+
code: ErrorCode.BacktestUnsupportedCorporateAction,
|
|
1736
|
+
context: {
|
|
1737
|
+
function: FN,
|
|
1738
|
+
action: action.type,
|
|
1739
|
+
symbol: action.symbol,
|
|
1740
|
+
effectiveDate: action.effectiveDate,
|
|
1741
|
+
},
|
|
1742
|
+
},
|
|
1743
|
+
);
|
|
1744
|
+
}
|
|
1745
|
+
corporateActionsApplied += 1;
|
|
1746
|
+
const lineageId = `${runId}:ca${nextActionIndex}`;
|
|
1747
|
+
if (action.type === 'symbolChange') {
|
|
1748
|
+
const to = action.newSymbol!;
|
|
1749
|
+
for (const t of affected) {
|
|
1750
|
+
t.lineage.push({
|
|
1751
|
+
lineageId,
|
|
1752
|
+
action: action.type,
|
|
1753
|
+
effectiveDate: action.effectiveDate,
|
|
1754
|
+
asOf: asOfMs,
|
|
1755
|
+
previous: {
|
|
1756
|
+
underlying: t.underlying,
|
|
1757
|
+
strikes: t.position.legs.flatMap((l) => (l.kind === 'stock' ? [] : [l.strike])),
|
|
1758
|
+
multiplier: t.position.multiplier,
|
|
1759
|
+
},
|
|
1760
|
+
adjusted: {
|
|
1761
|
+
underlying: to,
|
|
1762
|
+
strikes: t.position.legs.flatMap((l) => (l.kind === 'stock' ? [] : [l.strike])),
|
|
1763
|
+
multiplier: t.position.multiplier,
|
|
1764
|
+
},
|
|
1765
|
+
});
|
|
1766
|
+
t.underlying = to;
|
|
1767
|
+
}
|
|
1768
|
+
if (hedgeUnderlying === action.symbol && hedgeShares !== 0) {
|
|
1769
|
+
fold([
|
|
1770
|
+
envelope(asOfMs, {
|
|
1771
|
+
eventType: 'corporate.symbol-change',
|
|
1772
|
+
fromInstrumentId: action.symbol,
|
|
1773
|
+
toInstrumentId: to,
|
|
1774
|
+
}),
|
|
1775
|
+
]);
|
|
1776
|
+
hedgeUnderlying = to;
|
|
1777
|
+
}
|
|
1778
|
+
continue;
|
|
1779
|
+
}
|
|
1780
|
+
// split / reverseSplit: strike ÷ ratio, multiplier × ratio; quantity and exposure unchanged.
|
|
1781
|
+
const ratio = action.ratio!;
|
|
1782
|
+
for (const t of affected) {
|
|
1783
|
+
const previous = {
|
|
1784
|
+
underlying: t.underlying,
|
|
1785
|
+
strikes: t.position.legs.flatMap((l) => (l.kind === 'stock' ? [] : [l.strike])),
|
|
1786
|
+
multiplier: t.position.multiplier,
|
|
1787
|
+
};
|
|
1788
|
+
const adjustedMultiplier = t.position.multiplier * ratio;
|
|
1789
|
+
const adjustedLegs = t.position.legs.map((l) =>
|
|
1790
|
+
l.kind === 'stock'
|
|
1791
|
+
? { ...l }
|
|
1792
|
+
: { ...l, strike: l.strike / ratio, premium: l.premium / ratio },
|
|
1793
|
+
);
|
|
1794
|
+
t.position = new Position(adjustedLegs, {
|
|
1795
|
+
multiplier: adjustedMultiplier,
|
|
1796
|
+
...(positionExpiryOf(t.position) !== undefined
|
|
1797
|
+
? { expiry: positionExpiryOf(t.position)! }
|
|
1798
|
+
: {}),
|
|
1799
|
+
});
|
|
1800
|
+
t.live = t.live.map((l, i) => ({ ...l, leg: t.position.legs[i]! }));
|
|
1801
|
+
t.markCache = null;
|
|
1802
|
+
t.lineage.push({
|
|
1803
|
+
lineageId,
|
|
1804
|
+
action: action.type,
|
|
1805
|
+
effectiveDate: action.effectiveDate,
|
|
1806
|
+
asOf: asOfMs,
|
|
1807
|
+
previous,
|
|
1808
|
+
adjusted: {
|
|
1809
|
+
underlying: t.underlying,
|
|
1810
|
+
strikes: t.position.legs.flatMap((l) => (l.kind === 'stock' ? [] : [l.strike])),
|
|
1811
|
+
multiplier: adjustedMultiplier,
|
|
1812
|
+
},
|
|
1813
|
+
});
|
|
1814
|
+
t.live.forEach((l) => {
|
|
1815
|
+
if (l.leg.kind === 'stock') return;
|
|
1816
|
+
fold([
|
|
1817
|
+
envelope(
|
|
1818
|
+
asOfMs,
|
|
1819
|
+
{
|
|
1820
|
+
eventType: 'derivative.multiplier-change',
|
|
1821
|
+
instrumentId: l.instrumentId,
|
|
1822
|
+
contractMultiplierAfter: adjustedMultiplier,
|
|
1823
|
+
strikePricePerUnitAfter: l.leg.strike,
|
|
1824
|
+
reason: `${action.type} ${ratio}:1 on ${action.symbol} (${lineageId})`,
|
|
1825
|
+
},
|
|
1826
|
+
lineageId,
|
|
1827
|
+
),
|
|
1828
|
+
]);
|
|
1829
|
+
});
|
|
1830
|
+
}
|
|
1831
|
+
if (hedgeUnderlying === action.symbol && hedgeShares !== 0) {
|
|
1832
|
+
const after = Math.round(ratio * 1_000_000);
|
|
1833
|
+
fold([
|
|
1834
|
+
envelope(asOfMs, {
|
|
1835
|
+
eventType: 'corporate.split',
|
|
1836
|
+
instrumentId: action.symbol,
|
|
1837
|
+
sharesAfterSplit: after,
|
|
1838
|
+
sharesBeforeSplit: 1_000_000,
|
|
1839
|
+
}),
|
|
1840
|
+
]);
|
|
1841
|
+
hedgeShares *= ratio;
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
};
|
|
1845
|
+
|
|
1846
|
+
/** Dividend evidence: every open short call before an ex-date; early assignment under 'model'. */
|
|
1847
|
+
const dividendEvidence = (
|
|
1848
|
+
snap: ChainSnapshot,
|
|
1849
|
+
asOfMs: EpochMs,
|
|
1850
|
+
nextAsOfMs: EpochMs | null,
|
|
1851
|
+
): DividendRiskRow[] => {
|
|
1852
|
+
const rows: DividendRiskRow[] = [];
|
|
1853
|
+
if (dividends.length === 0) return rows;
|
|
1854
|
+
const date = dateOf(asOfMs);
|
|
1855
|
+
const nextDate = nextAsOfMs === null ? null : dateOf(nextAsOfMs);
|
|
1856
|
+
for (const dividend of dividends) {
|
|
1857
|
+
// the last snapshot strictly before the ex-date: date < exDate ≤ next snapshot's date (or none follows)
|
|
1858
|
+
if (!(date < dividend.exDate && (nextDate === null || nextDate >= dividend.exDate))) continue;
|
|
1859
|
+
for (const t of [...book]) {
|
|
1860
|
+
if (t.underlying !== dividend.underlying || t.position.legs.length === 0) continue;
|
|
1861
|
+
const m = markTrade(t, snap, asOfMs);
|
|
1862
|
+
const atRiskLegs: number[] = [];
|
|
1863
|
+
t.position.legs.forEach((leg, index) => {
|
|
1864
|
+
if (leg.kind !== 'call' || leg.quantity >= 0 || leg.expiry === undefined) return;
|
|
1865
|
+
if (leg.expiry < dividend.exDate) return;
|
|
1866
|
+
const perShare =
|
|
1867
|
+
Math.abs(m.perLeg[index]!.value) / (Math.abs(leg.quantity) * t.position.multiplier);
|
|
1868
|
+
const extrinsic = Math.max(
|
|
1869
|
+
0,
|
|
1870
|
+
perShare - intrinsicOf('call', snap.underlyingPrice, leg.strike),
|
|
1871
|
+
);
|
|
1872
|
+
const atRisk = dividend.amount > extrinsic;
|
|
1873
|
+
rows.push({
|
|
1874
|
+
tradeId: t.tradeId,
|
|
1875
|
+
legIndex: t.live[index]!.originalIndex,
|
|
1876
|
+
underlying: t.underlying,
|
|
1877
|
+
exDate: dividend.exDate,
|
|
1878
|
+
dividend: dividend.amount,
|
|
1879
|
+
extrinsic,
|
|
1880
|
+
atRisk,
|
|
1881
|
+
});
|
|
1882
|
+
if (atRisk) atRiskLegs.push(index);
|
|
1883
|
+
});
|
|
1884
|
+
if (assignment === 'model' && atRiskLegs.length > 0) {
|
|
1885
|
+
const { settled } = settleLegs(
|
|
1886
|
+
t,
|
|
1887
|
+
snap,
|
|
1888
|
+
asOfMs,
|
|
1889
|
+
(_leg, index) => atRiskLegs.includes(index),
|
|
1890
|
+
{ reason: 'dividend' },
|
|
1891
|
+
);
|
|
1892
|
+
earlyAssignmentCount += settled;
|
|
1893
|
+
// an assigned structure whose only remaining legs are stock is closed at market
|
|
1894
|
+
if (t.position.legs.every((l) => l.kind === 'stock'))
|
|
1895
|
+
closeTrade(t, snap, asOfMs, 'assignment', false);
|
|
1896
|
+
}
|
|
1897
|
+
}
|
|
1898
|
+
}
|
|
1899
|
+
return rows;
|
|
1900
|
+
};
|
|
1901
|
+
|
|
1902
|
+
/** Deep-ITM short puts under 'model': assigned when the extrinsic value is below the carry. */
|
|
1903
|
+
const deepInTheMoneyAssignment = (snap: ChainSnapshot, asOfMs: EpochMs): void => {
|
|
1904
|
+
if (assignment !== 'model') return;
|
|
1905
|
+
for (const t of [...book]) {
|
|
1906
|
+
if (t.position.legs.length === 0) continue;
|
|
1907
|
+
const m = markTrade(t, snap, asOfMs);
|
|
1908
|
+
const targets: number[] = [];
|
|
1909
|
+
t.position.legs.forEach((leg, index) => {
|
|
1910
|
+
if (leg.kind !== 'put' || leg.quantity >= 0 || leg.expiry === undefined) return;
|
|
1911
|
+
const intrinsic = intrinsicOf('put', snap.underlyingPrice, leg.strike);
|
|
1912
|
+
if (intrinsic <= 0) return;
|
|
1913
|
+
const years = Math.max(0, yearFraction(asOfMs, optionExpiryToMs(leg.expiry), 'ACT/365F'));
|
|
1914
|
+
const carry = leg.strike * (1 - Math.exp(-rate * years));
|
|
1915
|
+
const perShare =
|
|
1916
|
+
Math.abs(m.perLeg[index]!.value) / (Math.abs(leg.quantity) * t.position.multiplier);
|
|
1917
|
+
const extrinsic = Math.max(0, perShare - intrinsic);
|
|
1918
|
+
if (extrinsic < carry) targets.push(index);
|
|
1919
|
+
});
|
|
1920
|
+
if (targets.length > 0) {
|
|
1921
|
+
const { settled } = settleLegs(t, snap, asOfMs, (_leg, index) => targets.includes(index), {
|
|
1922
|
+
reason: 'deep-itm',
|
|
1923
|
+
});
|
|
1924
|
+
earlyAssignmentCount += settled;
|
|
1925
|
+
if (t.position.legs.every((l) => l.kind === 'stock'))
|
|
1926
|
+
closeTrade(t, snap, asOfMs, 'assignment', false);
|
|
1927
|
+
}
|
|
1928
|
+
}
|
|
1929
|
+
};
|
|
1930
|
+
|
|
1931
|
+
// ---- the surface row --------------------------------------------------------------------------------
|
|
1932
|
+
const surfaceRow = (
|
|
1933
|
+
snap: ChainSnapshot,
|
|
1934
|
+
asOfMs: EpochMs,
|
|
1935
|
+
dividendRisk: DividendRiskRow[],
|
|
1936
|
+
): SurfaceRow => {
|
|
1937
|
+
const atm: Record<string, number> = {};
|
|
1938
|
+
const nearest: Record<string, number> = {};
|
|
1939
|
+
for (const q of snap.quotes) {
|
|
1940
|
+
if (typeof q.impliedVolatility !== 'number' || !(q.impliedVolatility > 0)) continue;
|
|
1941
|
+
const dist = Math.abs(q.contract.strike - snap.underlyingPrice);
|
|
1942
|
+
if (nearest[q.contract.expiry] === undefined || dist < nearest[q.contract.expiry]!) {
|
|
1943
|
+
nearest[q.contract.expiry] = dist;
|
|
1944
|
+
atm[q.contract.expiry] = q.impliedVolatility;
|
|
1945
|
+
}
|
|
1946
|
+
}
|
|
1947
|
+
let skew25Delta: number | null = null;
|
|
1948
|
+
const expiries = Object.keys(atm).sort();
|
|
1949
|
+
const first = expiries[0];
|
|
1950
|
+
if (first !== undefined) {
|
|
1951
|
+
const pick = (right: 'call' | 'put'): number | null => {
|
|
1952
|
+
let best: number | null = null;
|
|
1953
|
+
let bestDist = Number.POSITIVE_INFINITY;
|
|
1954
|
+
for (const q of snap.quotes) {
|
|
1955
|
+
if (q.contract.expiry !== first || q.contract.type !== right) continue;
|
|
1956
|
+
const delta = q.greeks?.delta;
|
|
1957
|
+
if (typeof delta !== 'number' || typeof q.impliedVolatility !== 'number') continue;
|
|
1958
|
+
const dist = Math.abs(Math.abs(delta) - 0.25);
|
|
1959
|
+
if (dist < bestDist) {
|
|
1960
|
+
bestDist = dist;
|
|
1961
|
+
best = q.impliedVolatility;
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1964
|
+
return best;
|
|
1965
|
+
};
|
|
1966
|
+
const put = pick('put');
|
|
1967
|
+
const call = pick('call');
|
|
1968
|
+
if (put !== null && call !== null) skew25Delta = put - call;
|
|
1969
|
+
}
|
|
1970
|
+
return {
|
|
1971
|
+
asOf: asOfMs,
|
|
1972
|
+
atTheMoneyVolatilityByExpiry: atm,
|
|
1973
|
+
skew25Delta,
|
|
1974
|
+
markSources: { ...snapshotMarkSources },
|
|
1975
|
+
dividendRisk,
|
|
1976
|
+
};
|
|
1977
|
+
};
|
|
1978
|
+
|
|
1979
|
+
// ---- the ledger's marks -----------------------------------------------------------------------------
|
|
1980
|
+
const marks: PortfolioValuationMark[] = [];
|
|
1981
|
+
const markEquity: number[] = [];
|
|
1982
|
+
let reconciliationResidual = 0;
|
|
1983
|
+
const recordMark = (snap: ChainSnapshot, asOfMs: EpochMs, equity: number): void => {
|
|
1984
|
+
const spots: Record<string, { price: number; currency: string }> = {};
|
|
1985
|
+
const anyUnderlying = book[0]?.underlying ?? hedgeUnderlying;
|
|
1986
|
+
if (anyUnderlying !== null && anyUnderlying !== undefined)
|
|
1987
|
+
spots[anyUnderlying] = { price: snap.underlyingPrice, currency: baseCurrency };
|
|
1988
|
+
for (const t of book) {
|
|
1989
|
+
spots[t.underlying] = { price: snap.underlyingPrice, currency: baseCurrency };
|
|
1990
|
+
if (t.position.legs.length === 0) continue;
|
|
1991
|
+
const m = markTrade(t, snap, asOfMs);
|
|
1992
|
+
m.perLeg.forEach((p, index) => {
|
|
1993
|
+
if (p.leg.kind === 'stock' || p.leg.quantity === 0) return;
|
|
1994
|
+
spots[t.live[index]!.instrumentId] = {
|
|
1995
|
+
price: Math.abs(p.value) / (Math.abs(p.leg.quantity) * t.position.multiplier),
|
|
1996
|
+
currency: baseCurrency,
|
|
1997
|
+
};
|
|
1998
|
+
});
|
|
1999
|
+
}
|
|
2000
|
+
const valuationDate = nextCalendarDate(dateOf(asOfMs));
|
|
2001
|
+
const market = createMarketSnapshot({
|
|
2002
|
+
asOf: isoDateToEpochMs(valuationDate),
|
|
2003
|
+
observations: { spots },
|
|
2004
|
+
});
|
|
2005
|
+
const nav =
|
|
2006
|
+
state === undefined
|
|
2007
|
+
? initialCapital
|
|
2008
|
+
: portfolioSnapshot({ portfolio: state, asOf: isoDateToEpochMs(valuationDate), market })
|
|
2009
|
+
.netAssetValue;
|
|
2010
|
+
const residual = nav - equity;
|
|
2011
|
+
if (Math.abs(residual) > Math.abs(reconciliationResidual)) reconciliationResidual = residual;
|
|
2012
|
+
const last = marks[marks.length - 1];
|
|
2013
|
+
if (last !== undefined && last.valuationDate === valuationDate) {
|
|
2014
|
+
marks[marks.length - 1] = { valuationDate, market };
|
|
2015
|
+
markEquity[markEquity.length - 1] = equity;
|
|
2016
|
+
} else {
|
|
2017
|
+
marks.push({ valuationDate, market });
|
|
2018
|
+
markEquity.push(equity);
|
|
2019
|
+
}
|
|
2020
|
+
};
|
|
2021
|
+
|
|
2022
|
+
// ---- the loop ----------------------------------------------------------------------------------------
|
|
2023
|
+
for (let step = 0; step < ordered.length; step += 1) {
|
|
2024
|
+
const { snap: rawSnap, asOfMs } = ordered[step]!;
|
|
2025
|
+
const nextAsOfMs = step + 1 < ordered.length ? ordered[step + 1]!.asOfMs : null;
|
|
2026
|
+
const snap = enrichSnapshot(rawSnap, asOfMs);
|
|
2027
|
+
const spot = snap.underlyingPrice;
|
|
2028
|
+
stamp(asOfMs);
|
|
2029
|
+
snapshotMarkSources = {
|
|
2030
|
+
snapshots: 0,
|
|
2031
|
+
currentQuote: 0,
|
|
2032
|
+
impliedFromPrice: 0,
|
|
2033
|
+
entryVolatility: 0,
|
|
2034
|
+
carried: 0,
|
|
2035
|
+
};
|
|
2036
|
+
|
|
2037
|
+
applyCorporateActions(asOfMs);
|
|
2038
|
+
|
|
2039
|
+
for (const t of [...book]) {
|
|
2040
|
+
if (!book.includes(t)) continue;
|
|
2041
|
+
const m = markTrade(t, snap, asOfMs);
|
|
2042
|
+
const dte = minDaysToExpiry(t.position, asOfMs);
|
|
2043
|
+
if (dte <= 0) {
|
|
2044
|
+
// Settle every expired leg; a multi-expiry trade keeps its far legs and stays open.
|
|
2045
|
+
const expiredAll = t.position.legs.every(
|
|
2046
|
+
(l) =>
|
|
2047
|
+
l.kind === 'stock' || l.expiry === undefined || daysToExpiry(asOfMs, l.expiry) <= 0,
|
|
2048
|
+
);
|
|
2049
|
+
if (expiredAll) {
|
|
2050
|
+
const anyAssigned = t.position.legs.some(
|
|
2051
|
+
(l) =>
|
|
2052
|
+
l.kind !== 'stock' &&
|
|
2053
|
+
l.quantity < 0 &&
|
|
2054
|
+
(l.kind === 'call' ? spot > l.strike : spot < l.strike),
|
|
2055
|
+
);
|
|
2056
|
+
closeTrade(t, snap, asOfMs, anyAssigned ? 'assignment' : 'expiry', true);
|
|
2057
|
+
continue;
|
|
2058
|
+
}
|
|
2059
|
+
settleLegs(
|
|
2060
|
+
t,
|
|
2061
|
+
snap,
|
|
2062
|
+
asOfMs,
|
|
2063
|
+
(leg) => leg.expiry !== undefined && daysToExpiry(asOfMs, leg.expiry) <= 0,
|
|
2064
|
+
null,
|
|
2065
|
+
);
|
|
2066
|
+
if (t.position.legs.every((l) => l.kind === 'stock')) {
|
|
2067
|
+
closeTrade(t, snap, asOfMs, 'expiry', false);
|
|
2068
|
+
continue;
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
const liveMark = t.position.legs.length === 0 ? m : markTrade(t, snap, asOfMs);
|
|
2072
|
+
const context: ExitContext = {
|
|
2073
|
+
snapshot: snap,
|
|
2074
|
+
asOf: asOfMs,
|
|
2075
|
+
position: t.position,
|
|
2076
|
+
entryPremium: t.entryPremium,
|
|
2077
|
+
markToMarket: liveMark.pnl + t.settledPnl,
|
|
2078
|
+
pnlFraction: (liveMark.pnl + t.settledPnl) / (Math.abs(t.entryPremium) || 1),
|
|
2079
|
+
daysToExpiry: minDaysToExpiry(t.position, asOfMs),
|
|
2080
|
+
netDelta: liveMark.greeks.delta,
|
|
2081
|
+
greeks: liveMark.greeks,
|
|
2082
|
+
};
|
|
2083
|
+
const rollTriggers = roll ? (roll.when ?? exit) : null;
|
|
2084
|
+
if (rollTriggers && evaluateExit(rollTriggers, context)) {
|
|
2085
|
+
const ruleIndex = t.ruleIndex;
|
|
2086
|
+
closeTrade(t, snap, asOfMs, 'roll', false);
|
|
2087
|
+
tryEnter({
|
|
2088
|
+
ruleIndex: ruleIndex,
|
|
2089
|
+
snap,
|
|
2090
|
+
asOfMs,
|
|
2091
|
+
equityNow: cash + openOptionValue(snap, asOfMs) + hedgeShares * spot,
|
|
2092
|
+
});
|
|
2093
|
+
} else {
|
|
2094
|
+
const reason = evaluateExit(exit, context);
|
|
2095
|
+
if (reason) closeTrade(t, snap, asOfMs, reason, false);
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
|
|
2099
|
+
deepInTheMoneyAssignment(snap, asOfMs);
|
|
2100
|
+
const dividendRisk = dividendEvidence(snap, asOfMs, nextAsOfMs);
|
|
2101
|
+
|
|
2102
|
+
for (let ruleIndex = 0; ruleIndex < rules.length; ruleIndex += 1) {
|
|
2103
|
+
const gate = rules[ruleIndex]!.when ?? 'flat';
|
|
2104
|
+
// `'always'` keeps entering while the book has room and the rule keeps building; every other
|
|
2105
|
+
// gate enters at most once per snapshot.
|
|
2106
|
+
for (;;) {
|
|
2107
|
+
const before = book.length;
|
|
2108
|
+
tryEnter({
|
|
2109
|
+
ruleIndex: ruleIndex,
|
|
2110
|
+
snap,
|
|
2111
|
+
asOfMs,
|
|
2112
|
+
equityNow: cash + openOptionValue(snap, asOfMs) + hedgeShares * spot,
|
|
2113
|
+
});
|
|
2114
|
+
if (gate !== 'always' || book.length === before || book.length >= maximumOpenPositions)
|
|
2115
|
+
break;
|
|
2116
|
+
}
|
|
2117
|
+
}
|
|
2118
|
+
rehedge(snap, asOfMs);
|
|
2119
|
+
|
|
2120
|
+
const equity = cash + openOptionValue(snap, asOfMs) + hedgeShares * spot;
|
|
2121
|
+
equityCurve.push(equity);
|
|
2122
|
+
timestamps.push(asOfMs);
|
|
2123
|
+
surface.push(surfaceRow(snap, asOfMs, dividendRisk));
|
|
2124
|
+
recordMark(snap, asOfMs, equity);
|
|
2125
|
+
}
|
|
2126
|
+
|
|
2127
|
+
// A still-open trade is recorded as an open-at-end trade (marked, not cash-settled).
|
|
2128
|
+
const openAtEnd = book.length;
|
|
2129
|
+
if (book.length > 0 && ordered.length > 0) {
|
|
2130
|
+
const last = ordered[ordered.length - 1]!;
|
|
2131
|
+
const lastSnap = enrichSnapshot(last.snap, last.asOfMs);
|
|
2132
|
+
for (const t of [...book]) {
|
|
2133
|
+
const m = t.position.legs.length === 0 ? null : markTrade(t, lastSnap, last.asOfMs);
|
|
2134
|
+
discloseFallbacks(t);
|
|
2135
|
+
trades.push(
|
|
2136
|
+
tradeRow({
|
|
2137
|
+
t,
|
|
2138
|
+
position: t.position,
|
|
2139
|
+
live: t.live,
|
|
2140
|
+
snap: lastSnap,
|
|
2141
|
+
exitAsOf: null,
|
|
2142
|
+
reason: 'open-at-end',
|
|
2143
|
+
exitCosts: 0,
|
|
2144
|
+
m,
|
|
2145
|
+
markAsOf: last.asOfMs,
|
|
2146
|
+
grossPnl: (m === null ? 0 : m.pnl) + t.settledPnl,
|
|
2147
|
+
}),
|
|
2148
|
+
);
|
|
2149
|
+
}
|
|
2150
|
+
}
|
|
2151
|
+
|
|
2152
|
+
// ---- the ledger's own reports and the reconciliation law ------------------------------------------
|
|
2153
|
+
const ledger = createPortfolioLedger({ portfolioId: runId, baseCurrency, events });
|
|
2154
|
+
let timeline: PortfolioTimelineResult | null = null;
|
|
2155
|
+
if (marks.length > 0 && state !== undefined) {
|
|
2156
|
+
if (!(Math.abs(reconciliationResidual) <= RECONCILIATION_TOLERANCE)) {
|
|
2157
|
+
throw new InputError(
|
|
2158
|
+
`${FN}: the ledger's net asset value differs from the engine's equity by ${reconciliationResidual} at a mark — an engine invariant failed; nothing was published.`,
|
|
2159
|
+
{
|
|
2160
|
+
code: ErrorCode.BacktestLedgerReconciliationFailed,
|
|
2161
|
+
context: { function: FN, residual: reconciliationResidual },
|
|
2162
|
+
},
|
|
2163
|
+
);
|
|
2164
|
+
}
|
|
2165
|
+
if (marks.length >= 2) timeline = portfolioTimeline({ ledger, valuationMarks: marks });
|
|
2166
|
+
}
|
|
2167
|
+
|
|
2168
|
+
const points: EquityPoint[] = toEquityPoints(equityCurve, timestamps);
|
|
2169
|
+
const performance = analyze({ equity: equityCurve }, { periodsPerYear, riskFreeRate: rate });
|
|
2170
|
+
|
|
2171
|
+
return {
|
|
2172
|
+
points,
|
|
2173
|
+
returns: simpleReturns(equityCurve),
|
|
2174
|
+
trades,
|
|
2175
|
+
settlements,
|
|
2176
|
+
fills,
|
|
2177
|
+
finalValue: equityCurve[equityCurve.length - 1]!,
|
|
2178
|
+
performance,
|
|
2179
|
+
limitRejections,
|
|
2180
|
+
fillRejections,
|
|
2181
|
+
surface,
|
|
2182
|
+
ledger: ledger.toJSON(),
|
|
2183
|
+
timeline: timeline as PortfolioTimelineResult,
|
|
2184
|
+
runId,
|
|
2185
|
+
assumptions: {
|
|
2186
|
+
conventionsVersion: CONVENTIONS_VERSION,
|
|
2187
|
+
initialCapital,
|
|
2188
|
+
riskFreeRate: rate,
|
|
2189
|
+
dividendYield,
|
|
2190
|
+
priceSource,
|
|
2191
|
+
sizing: sizingMode,
|
|
2192
|
+
commission: commission.label,
|
|
2193
|
+
slippage: slippage.label,
|
|
2194
|
+
assignment,
|
|
2195
|
+
hedge: hedge ? hedge.deltaBand : 'none',
|
|
2196
|
+
periodsPerYear,
|
|
2197
|
+
marking,
|
|
2198
|
+
book: { maximumOpenPositions, maximumPerUnderlying },
|
|
2199
|
+
limits: {
|
|
2200
|
+
maximumMarginFraction: limits.maximumMarginFraction ?? null,
|
|
2201
|
+
maximumNetDelta: limits.maximumNetDelta ?? null,
|
|
2202
|
+
maximumNetVega: limits.maximumNetVega ?? null,
|
|
2203
|
+
maximumConcentration: limits.maximumConcentration ?? null,
|
|
2204
|
+
scenarioLoss:
|
|
2205
|
+
limits.scenarioLoss === undefined
|
|
2206
|
+
? null
|
|
2207
|
+
: {
|
|
2208
|
+
spotShocks: [...limits.scenarioLoss.spotShocks],
|
|
2209
|
+
volatilityShocks: [...limits.scenarioLoss.volatilityShocks],
|
|
2210
|
+
maximumLossFraction: limits.scenarioLoss.maximumLossFraction,
|
|
2211
|
+
},
|
|
2212
|
+
},
|
|
2213
|
+
fillPolicy: { mode: fillMode, partialFill, price: fillPrice },
|
|
2214
|
+
quoteFreshness: { maximumQuoteAgeMs: maximumFillQuoteAgeMs },
|
|
2215
|
+
rules: rules.map((rule, index) => ({
|
|
2216
|
+
id: ruleIds[index]!,
|
|
2217
|
+
structure: 'build' in rule ? 'build' : rule.structure,
|
|
2218
|
+
})),
|
|
2219
|
+
corporateActions: corporateActions.length,
|
|
2220
|
+
dividends: dividends.length,
|
|
2221
|
+
baseCurrency,
|
|
2222
|
+
ledger: { sourceId, accountId: ACCOUNT_ID, lotRelief: ledger.lotRelief },
|
|
2223
|
+
replayable,
|
|
2224
|
+
},
|
|
2225
|
+
diagnostics: {
|
|
2226
|
+
engine: 'options-backtest',
|
|
2227
|
+
method: 'chain-snapshot-driven',
|
|
2228
|
+
converged: true,
|
|
2229
|
+
warnings,
|
|
2230
|
+
snapshotCount: ordered.length,
|
|
2231
|
+
tradeCount: trades.length,
|
|
2232
|
+
openAtEnd,
|
|
2233
|
+
limitRejectionCount: limitRejections.length,
|
|
2234
|
+
fillRejectionCount: fillRejections.length,
|
|
2235
|
+
earlyAssignmentCount,
|
|
2236
|
+
corporateActionsApplied,
|
|
2237
|
+
reconciliationResidual,
|
|
2238
|
+
},
|
|
2239
|
+
};
|
|
2240
|
+
}
|