dexbot 1.6.10 → 1.6.12
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/CHANGELOG.md +50 -3
- package/README.md +3 -1
- package/analysis/README.md +51 -11
- package/analysis/bot_fitting/README.md +12 -0
- package/analysis/tradingview/README.md +3 -3
- package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +11 -37
- package/analysis/trend_detection/README.md +31 -0
- package/claw/docs/DEXBOT2_TUNING_CHEAT_SHEET.md +4 -3
- package/claw/modules/chain_broadcast.ts +7 -1
- package/claw/modules/claw_launcher.ts +1 -1
- package/claw/modules/launcher_mode_detector.ts +9 -2
- package/claw/package.json +1 -1
- package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
- package/claw/runtimes/openclaw-plugin/package.json +1 -1
- package/dist/analysis/account_resolver.d.ts +1 -1
- package/dist/analysis/account_resolver.js +15 -2
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.js +3 -4
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +2 -7
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.js +4 -4
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +20 -4
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +9 -6
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js +16 -12
- package/dist/analysis/analyze_args.d.ts +31 -0
- package/dist/analysis/analyze_args.js +41 -0
- package/dist/analysis/analyze_dynamic_weight.js +7 -20
- package/dist/analysis/analyze_kalman.js +7 -17
- package/dist/analysis/analyze_regime.js +7 -17
- package/dist/analysis/analyze_regime_windows.js +8 -18
- package/dist/analysis/analyze_risk_profile.js +8 -18
- package/dist/analysis/analyze_trade_heatmap.js +7 -17
- package/dist/analysis/analyze_volatility.js +7 -17
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts +220 -12
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js +55 -10
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +34 -4
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js +72 -66
- package/dist/analysis/bot_fitting/backtest_lookback_drawdown.d.ts +21 -0
- package/dist/analysis/bot_fitting/backtest_lookback_drawdown.js +315 -0
- package/dist/analysis/bot_fitting/shared_utils.d.ts +7 -7
- package/dist/analysis/bot_fitting/shared_utils.js +2 -2
- package/dist/analysis/bot_key_utils.d.ts +18 -10
- package/dist/analysis/bot_key_utils.js +10 -17
- package/dist/analysis/bot_usage/discover_bot_accounts.js +44 -47
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts +1 -21
- package/dist/analysis/chain_pool.d.ts +3 -1
- package/dist/analysis/chart_ui.d.ts +5 -2
- package/dist/analysis/chart_ui.js +6 -3
- package/dist/analysis/chart_utils.d.ts +5 -5
- package/dist/analysis/chart_utils.js +9 -0
- package/dist/analysis/fills_cache.d.ts +64 -0
- package/dist/analysis/fills_cache.js +254 -0
- package/dist/analysis/fills_source.d.ts +2 -2
- package/dist/analysis/fills_source.js +19 -14
- package/dist/analysis/grid_correction_check.d.ts +1 -1
- package/dist/analysis/grid_correction_check.js +12 -11
- package/dist/analysis/math_utils.d.ts +7 -6
- package/dist/analysis/math_utils.js +5 -8
- package/dist/analysis/pnl_report.d.ts +39 -0
- package/dist/analysis/pnl_report.js +325 -0
- package/dist/analysis/price_sources.d.ts +8 -8
- package/dist/analysis/price_sources.js +5 -4
- package/dist/analysis/resolve_bot_accounts.js +2 -2
- package/dist/analysis/resolve_source.d.ts +1 -2
- package/dist/analysis/trade_profitability.d.ts +32 -2
- package/dist/analysis/trade_profitability.js +232 -106
- package/dist/analysis/tradingview/analyze_tradingview.d.ts +17 -6
- package/dist/analysis/tradingview/analyze_tradingview.js +9 -10
- package/dist/analysis/tradingview/grid_reset_config.d.ts +42 -31
- package/dist/analysis/tradingview/grid_reset_config.js +35 -6
- package/dist/analysis/tradingview/grid_reset_sim.d.ts +75 -8
- package/dist/analysis/tradingview/grid_reset_sim.js +42 -5
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +69 -4
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +20 -20
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.d.ts +102 -0
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.js +725 -0
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts +63 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +27 -112
- package/dist/analysis/trend_detection/huber_scale_variants.d.ts +40 -0
- package/dist/analysis/trend_detection/huber_scale_variants.js +176 -0
- package/dist/analysis/trend_detection/kalman_chart_generator.d.ts +30 -1
- package/dist/analysis/trend_detection/kalman_chart_generator.js +3 -3
- package/dist/analysis/trend_detection/regime_chart_generator.d.ts +31 -1
- package/dist/analysis/trend_detection/regime_chart_generator.js +2 -2
- package/dist/analysis/trend_detection/volatility_chart_generator.d.ts +33 -1
- package/dist/credential-daemon.js +34 -20
- package/dist/dexbot.js +17 -14
- package/dist/market_adapter/candle_utils.d.ts +22 -18
- package/dist/market_adapter/candle_utils.js +24 -20
- package/dist/market_adapter/core/asymmetric_bounds.d.ts +13 -4
- package/dist/market_adapter/core/config_normalizers.d.ts +3 -3
- package/dist/market_adapter/core/kibana_candles.d.ts +53 -18
- package/dist/market_adapter/core/kibana_candles.js +9 -7
- package/dist/market_adapter/core/kibana_client.d.ts +9 -1
- package/dist/market_adapter/core/kibana_client.js +8 -7
- package/dist/market_adapter/core/kibana_market_candles.d.ts +3 -2
- package/dist/market_adapter/core/market_adapter_service.d.ts +297 -115
- package/dist/market_adapter/core/market_adapter_service.js +184 -101
- package/dist/market_adapter/core/strategies/ama.d.ts +10 -2
- package/dist/market_adapter/core/strategies/ama.js +7 -32
- package/dist/market_adapter/core/strategies/ama_slope_model.d.ts +14 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.js +12 -34
- package/dist/market_adapter/core/strategies/atr/calculator.d.ts +7 -2
- package/dist/market_adapter/core/strategies/atr/calculator.js +2 -34
- package/dist/market_adapter/core/strategies/collateral_manager.d.ts +7 -1
- package/dist/market_adapter/core/strategies/collateral_manager.js +0 -22
- package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts +36 -8
- package/dist/market_adapter/core/strategies/dynamic_weight_series.js +9 -9
- package/dist/market_adapter/core/strategies/regime_gate.d.ts +24 -15
- package/dist/market_adapter/core/strategies/regime_gate.js +4 -31
- package/dist/market_adapter/core/strategies/regime_interp.d.ts +7 -1
- package/dist/market_adapter/core/strategies/regime_interp.js +14 -22
- package/dist/market_adapter/core/strategies/volatility_shift.d.ts +11 -1
- package/dist/market_adapter/core/strategies/volatility_shift.js +0 -13
- package/dist/market_adapter/inputs/cex_candle_parsing.d.ts +29 -0
- package/dist/market_adapter/inputs/cex_candle_parsing.js +52 -0
- package/dist/market_adapter/inputs/fetch_book_data.d.ts +20 -4
- package/dist/market_adapter/inputs/fetch_book_data.js +3 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +97 -226
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts +42 -7
- package/dist/market_adapter/inputs/fetch_lp_data.js +22 -15
- package/dist/market_adapter/inputs/kibana_feed_source.d.ts +74 -15
- package/dist/market_adapter/inputs/kibana_feed_source.js +29 -22
- package/dist/market_adapter/inputs/kibana_source.d.ts +25 -3
- package/dist/market_adapter/inputs/kibana_source.js +2 -2
- package/dist/market_adapter/inputs/window_cache.d.ts +99 -94
- package/dist/market_adapter/inputs/window_cache.js +8 -8
- package/dist/market_adapter/interval_utils.d.ts +4 -4
- package/dist/market_adapter/log_format.d.ts +6 -6
- package/dist/market_adapter/log_format.js +28 -22
- package/dist/market_adapter/lp_chart_core.d.ts +22 -1
- package/dist/market_adapter/lp_chart_core.js +26 -192
- package/dist/market_adapter/lp_chart_runner.d.ts +7 -7
- package/dist/market_adapter/lp_chart_strategy_loader.d.ts +41 -6
- package/dist/market_adapter/lp_chart_strategy_loader.js +8 -7
- package/dist/market_adapter/market_adapter.d.ts +94 -33
- package/dist/market_adapter/market_adapter.js +69 -75
- package/dist/market_adapter/utils/adapter_client.d.ts +3 -3
- package/dist/market_adapter/utils/adapter_client.js +2 -2
- package/dist/market_adapter/utils/atomic_write.d.ts +8 -1
- package/dist/market_adapter/utils/chain.d.ts +50 -41
- package/dist/market_adapter/utils/chain.js +40 -46
- package/dist/market_adapter/utils/data_discovery.d.ts +4 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts +12 -3
- package/dist/market_adapter/utils/file_json_cache.d.ts +2 -2
- package/dist/market_adapter/utils/file_lock.d.ts +28 -14
- package/dist/market_adapter/utils/file_lock.js +36 -32
- package/dist/market_adapter/utils/native_history.d.ts +9 -2
- package/dist/market_adapter/utils/native_history.js +35 -28
- package/dist/modules/account_bots.d.ts +577 -21
- package/dist/modules/account_bots.js +182 -158
- package/dist/modules/account_orders.d.ts +66 -30
- package/dist/modules/account_orders.js +22 -20
- package/dist/modules/authority_resolver.d.ts +12 -2
- package/dist/modules/authority_resolver.js +15 -8
- package/dist/modules/bitshares-native/chain_client.d.ts +38 -3
- package/dist/modules/bitshares-native/chain_client.js +45 -46
- package/dist/modules/bitshares-native/crypto/ecc.browser.js +11 -171
- package/dist/modules/bitshares-native/crypto/ecc.js +13 -176
- package/dist/modules/bitshares-native/crypto/ecc_core.d.ts +33 -0
- package/dist/modules/bitshares-native/crypto/ecc_core.js +213 -0
- package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts +2 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.js +1 -13
- package/dist/modules/bitshares-native/index.d.ts +1 -1
- package/dist/modules/bitshares-native/lru_cache.d.ts +7 -7
- package/dist/modules/bitshares-native/resolvers.d.ts +18 -6
- package/dist/modules/bitshares-native/serial/lazy_buffer.d.ts +4 -0
- package/dist/modules/bitshares-native/serial/lazy_buffer.js +21 -0
- package/dist/modules/bitshares-native/serial/operations.d.ts +1 -1
- package/dist/modules/bitshares-native/serial/serializer.d.ts +16 -12
- package/dist/modules/bitshares-native/serial/serializer.js +7 -13
- package/dist/modules/bitshares-native/serial/types.d.ts +25 -16
- package/dist/modules/bitshares-native/serial/types.js +55 -62
- package/dist/modules/bitshares-native/signing_client.d.ts +32 -2
- package/dist/modules/bitshares-native/signing_client.js +19 -14
- package/dist/modules/bitshares-native/subscriptions.d.ts +81 -1
- package/dist/modules/bitshares-native/subscriptions.js +12 -12
- package/dist/modules/bitshares-native/transport.d.ts +5 -4
- package/dist/modules/bitshares-native/transport.js +5 -4
- package/dist/modules/bitshares-native/tx/builder.d.ts +40 -5
- package/dist/modules/bitshares-native/tx/builder.js +4 -3
- package/dist/modules/bitshares-native/tx/tx_cache.d.ts +4 -4
- package/dist/modules/bitshares_client.d.ts +45 -13
- package/dist/modules/bitshares_client.js +28 -19
- package/dist/modules/bot_defaults.d.ts +6 -15
- package/dist/modules/bot_defaults.js +1 -5
- package/dist/modules/bot_settings.d.ts +44 -10
- package/dist/modules/bot_settings.js +11 -8
- package/dist/modules/bots_file_lock.d.ts +6 -6
- package/dist/modules/bots_file_lock.js +16 -12
- package/dist/modules/broadcast_failure.d.ts +2 -2
- package/dist/modules/broadcast_failure.js +5 -4
- package/dist/modules/chain_keys.d.ts +42 -40
- package/dist/modules/chain_keys.js +53 -45
- package/dist/modules/chain_orders.d.ts +93 -59
- package/dist/modules/chain_orders.js +31 -23
- package/dist/modules/constants.d.ts +530 -32
- package/dist/modules/constants.js +52 -60
- package/dist/modules/cr_planner.d.ts +40 -2
- package/dist/modules/credential_policy.d.ts +68 -8
- package/dist/modules/credential_policy.js +37 -31
- package/dist/modules/credential_session_cache.d.ts +2 -2
- package/dist/modules/credit_pricing.d.ts +42 -6
- package/dist/modules/credit_pricing.js +44 -30
- package/dist/modules/credit_runtime.d.ts +276 -118
- package/dist/modules/credit_runtime.js +462 -165
- package/dist/modules/crypto/browser_provider.js +6 -4
- package/dist/modules/crypto/node_provider.js +1 -1
- package/dist/modules/crypto/pure_scrypt.js +35 -4
- package/dist/modules/crypto/pure_secp256k1.js +72 -26
- package/dist/modules/crypto/sync.d.ts +9 -9
- package/dist/modules/crypto/sync.js +16 -9
- package/dist/modules/dexbot_class.d.ts +195 -139
- package/dist/modules/dexbot_class.js +78 -28
- package/dist/modules/dexbot_cow_runtime.d.ts +167 -87
- package/dist/modules/dexbot_cow_runtime.js +248 -206
- package/dist/modules/dexbot_credential_client.d.ts +19 -11
- package/dist/modules/dexbot_fill_runtime.d.ts +63 -48
- package/dist/modules/dexbot_fill_runtime.js +48 -41
- package/dist/modules/dexbot_maintenance_runtime.d.ts +109 -70
- package/dist/modules/dexbot_maintenance_runtime.js +117 -80
- package/dist/modules/dexbot_startup_runtime.d.ts +11 -10
- package/dist/modules/dexbot_startup_runtime.js +43 -43
- package/dist/modules/dexbot_state_recovery.d.ts +13 -12
- package/dist/modules/dexbot_state_recovery.js +18 -13
- package/dist/modules/fund_registry.d.ts +4 -2
- package/dist/modules/fund_registry.js +10 -10
- package/dist/modules/general_settings.d.ts +30 -4
- package/dist/modules/graceful_shutdown.d.ts +3 -3
- package/dist/modules/graceful_shutdown.js +2 -2
- package/dist/modules/grid_price_source.d.ts +1 -1
- package/dist/modules/key_store.d.ts +14 -8
- package/dist/modules/key_store.js +7 -6
- package/dist/modules/launcher/adapter_requirement.d.ts +11 -5
- package/dist/modules/launcher/adapter_requirement.js +5 -5
- package/dist/modules/launcher/bot_supervisor.d.ts +106 -24
- package/dist/modules/launcher/bot_supervisor.js +12 -11
- package/dist/modules/launcher/credential_bootstrap.d.ts +1 -1
- package/dist/modules/launcher/credential_bootstrap.js +1 -1
- package/dist/modules/launcher/credential_daemon.d.ts +4 -4
- package/dist/modules/launcher/credential_daemon.js +2 -2
- package/dist/modules/launcher/credential_secret.d.ts +1 -1
- package/dist/modules/launcher/foreign_cred_daemon.d.ts +2 -2
- package/dist/modules/launcher/market_adapter_runtime.d.ts +61 -6
- package/dist/modules/launcher/market_adapter_watchdog.d.ts +10 -2
- package/dist/modules/launcher/market_adapter_watchdog.js +4 -0
- package/dist/modules/launcher/monolithic_runtime.d.ts +18 -16
- package/dist/modules/launcher/status_reporting.d.ts +22 -14
- package/dist/modules/launcher/supervisor_control.d.ts +8 -1
- package/dist/modules/launcher/supervisor_control.js +4 -2
- package/dist/modules/market_adapter_whitelist.d.ts +9 -3
- package/dist/modules/market_adapter_whitelist.js +15 -3
- package/dist/modules/node_manager.d.ts +41 -11
- package/dist/modules/node_manager.js +5 -4
- package/dist/modules/order/accounting.d.ts +53 -24
- package/dist/modules/order/accounting.js +40 -14
- package/dist/modules/order/async_lock.d.ts +5 -2
- package/dist/modules/order/async_lock.js +1 -1
- package/dist/modules/order/export.d.ts +7 -6
- package/dist/modules/order/export.js +1 -7
- package/dist/modules/order/format.d.ts +39 -19
- package/dist/modules/order/format.js +62 -16
- package/dist/modules/order/genesis_policy.d.ts +21 -18
- package/dist/modules/order/genesis_policy.js +12 -8
- package/dist/modules/order/grid.d.ts +142 -36
- package/dist/modules/order/grid.js +148 -123
- package/dist/modules/order/grid_reconcile.d.ts +21 -20
- package/dist/modules/order/grid_reconcile.js +13 -12
- package/dist/modules/order/grid_reconcile_internal.d.ts +85 -72
- package/dist/modules/order/grid_reconcile_internal.js +28 -19
- package/dist/modules/order/index.d.ts +263 -1
- package/dist/modules/order/logger.d.ts +45 -11
- package/dist/modules/order/logger.js +38 -40
- package/dist/modules/order/logger_state.d.ts +4 -4
- package/dist/modules/order/manager.d.ts +226 -180
- package/dist/modules/order/manager.js +101 -83
- package/dist/modules/order/processed_fill_store.d.ts +18 -3
- package/dist/modules/order/processed_fill_store.js +16 -27
- package/dist/modules/order/strategy.d.ts +21 -13
- package/dist/modules/order/strategy.js +5 -6
- package/dist/modules/order/sync_engine.d.ts +91 -33
- package/dist/modules/order/sync_engine.js +99 -54
- package/dist/modules/order/utils/math.d.ts +157 -102
- package/dist/modules/order/utils/math.js +77 -38
- package/dist/modules/order/utils/order.d.ts +326 -106
- package/dist/modules/order/utils/order.js +200 -99
- package/dist/modules/order/utils/slot.d.ts +1 -1
- package/dist/modules/order/utils/system.d.ts +176 -26
- package/dist/modules/order/utils/system.js +86 -69
- package/dist/modules/order/utils/validate.d.ts +89 -41
- package/dist/modules/order/utils/validate.js +24 -22
- package/dist/modules/order/utils/withPoolRef.d.ts +4 -3
- package/dist/modules/order/utils/withPoolRef.js +18 -12
- package/dist/modules/order/working_grid.d.ts +14 -13
- package/dist/modules/paths.d.ts +3 -4
- package/dist/modules/paths.js +3 -27
- package/dist/modules/process_discovery.d.ts +1 -1
- package/dist/modules/process_discovery.js +2 -1
- package/dist/modules/runtime.d.ts +7 -3
- package/dist/modules/runtime.js +4 -3
- package/dist/modules/runtime_settings.d.ts +15 -10
- package/dist/modules/runtime_settings.js +30 -24
- package/dist/modules/settings_merge.d.ts +29 -3
- package/dist/modules/settings_merge.js +56 -78
- package/dist/modules/socket_json_client.d.ts +7 -4
- package/dist/modules/storage/browser_adapter.d.ts +38 -53
- package/dist/modules/storage/browser_adapter.js +7 -30
- package/dist/modules/storage/index.d.ts +1 -1
- package/dist/modules/storage/node_adapter.d.ts +45 -27
- package/dist/modules/storage/node_adapter.js +9 -9
- package/dist/modules/storage/types.d.ts +5 -4
- package/dist/modules/types.d.ts +1071 -2
- package/dist/modules/types.js +4 -1
- package/dist/modules/utils/asset_symbols.d.ts +2 -1
- package/dist/modules/utils/asset_symbols.js +2 -1
- package/dist/modules/utils/errors.d.ts +9 -0
- package/dist/modules/utils/errors.js +23 -1
- package/dist/modules/utils/time_range.d.ts +4 -0
- package/dist/modules/utils/time_range.js +18 -0
- package/dist/modules/validate_profiles.js +53 -43
- package/dist/modules/version_notice.d.ts +14 -3
- package/dist/modules/version_notice.js +6 -4
- package/dist/pm2.d.ts +29 -27
- package/dist/pm2.js +5 -5
- package/dist/scripts/analyze-credit.d.ts +2 -1
- package/dist/scripts/analyze-credit.js +23 -24
- package/dist/scripts/analyze-orders.d.ts +77 -9
- package/dist/scripts/analyze-orders.js +66 -84
- package/dist/scripts/chart_command.d.ts +27 -18
- package/dist/scripts/chart_command.js +16 -15
- package/dist/scripts/check_any.d.ts +18 -0
- package/dist/scripts/check_any.js +126 -0
- package/dist/scripts/diagnose-pool-history.js +12 -7
- package/dist/scripts/pnl.d.ts +3 -0
- package/dist/scripts/pnl.js +40 -0
- package/dist/scripts/print_grid.js +0 -1
- package/dist/scripts/run-tests.js +39 -7
- package/dist/scripts/runner.js +1 -1
- package/dist/scripts/test-credit-renewal.js +30 -21
- package/dist/scripts/update.d.ts +10 -5
- package/dist/scripts/update.js +168 -103
- package/dist/scripts/update_dist_freshness.js +1 -0
- package/dist/scripts/update_layout.d.ts +61 -0
- package/dist/scripts/update_layout.js +180 -0
- package/dist/scripts/validate_bots.js +2 -1
- package/dist/scripts/verify-browser-bundle.js +8 -0
- package/dist/unlock.d.ts +28 -3
- package/dist/unlock.js +72 -10
- package/docs/BITSHARES_ONBOARDING.md +2 -0
- package/docs/COPY_ON_WRITE_MASTER_PLAN.md +1 -1
- package/docs/COW_INVARIANTS.md +13 -6
- package/docs/DEXBOT_COMPARISON.md +8 -8
- package/docs/EVOLUTION.md +12 -10
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +5 -5
- package/docs/GRID_RECALCULATION.md +15 -16
- package/docs/GRID_RECONCILE.md +14 -3
- package/docs/LIFECYCLE.md +11 -11
- package/docs/MPA_CREDIT_USAGE.md +22 -3
- package/docs/README.md +15 -4
- package/docs/WORKFLOW.md +1 -0
- package/docs/architecture.md +12 -9
- package/docs/developer_guide.md +6 -6
- package/market_adapter/README.md +9 -26
- package/modules/README.md +4 -1
- package/package.json +4 -1
- package/scripts/README.md +14 -0
|
@@ -1,3 +1,65 @@
|
|
|
1
|
-
|
|
1
|
+
interface DynamicWeightRow {
|
|
2
|
+
timestamp: string | number;
|
|
3
|
+
price: number;
|
|
4
|
+
hurst?: number | null;
|
|
5
|
+
pe?: number | null;
|
|
6
|
+
hurstSegment?: number | null;
|
|
7
|
+
peSegment?: number | null;
|
|
8
|
+
amaSlopePct?: number | null;
|
|
9
|
+
velocityRawPct?: number | null;
|
|
10
|
+
velocityPct?: number | null;
|
|
11
|
+
displacementRawPct?: number | null;
|
|
12
|
+
displacementPct?: number | null;
|
|
13
|
+
isReady?: boolean;
|
|
14
|
+
signal?: string | null;
|
|
15
|
+
ama3Price?: number | null;
|
|
16
|
+
}
|
|
17
|
+
interface DynWeightCfg {
|
|
18
|
+
alpha?: number;
|
|
19
|
+
gain?: number;
|
|
20
|
+
dispWeight?: number;
|
|
21
|
+
neutralZonePct?: number;
|
|
22
|
+
amaNeutralZonePct?: number;
|
|
23
|
+
lookbackBars?: number;
|
|
24
|
+
amaLookbackBars?: number;
|
|
25
|
+
amaMaxSlopePct?: number;
|
|
26
|
+
kalmanMaxSlopePct?: number;
|
|
27
|
+
clipPercentile?: number;
|
|
28
|
+
minOutputThreshold?: number;
|
|
29
|
+
outputClamp?: number;
|
|
30
|
+
dispScaleMinPct?: number;
|
|
31
|
+
regimeSensitivity?: number;
|
|
32
|
+
absoluteThreshold?: number;
|
|
33
|
+
}
|
|
34
|
+
interface DynamicWeightChartInput {
|
|
35
|
+
allResults?: DynamicWeightRow[];
|
|
36
|
+
marketAdapter?: DynWeightCfg;
|
|
37
|
+
amaWeightConfig?: DynWeightCfg;
|
|
38
|
+
amaConfig?: {
|
|
39
|
+
erPeriod?: number;
|
|
40
|
+
fastPeriod?: number;
|
|
41
|
+
slowPeriod?: number;
|
|
42
|
+
};
|
|
43
|
+
alpha?: number;
|
|
44
|
+
gain?: number;
|
|
45
|
+
dispWeight?: number;
|
|
46
|
+
clipPct?: number;
|
|
47
|
+
minOutputThreshold?: number;
|
|
48
|
+
outputClamp?: number;
|
|
49
|
+
absoluteThreshold?: number;
|
|
50
|
+
lookbackBars?: number;
|
|
51
|
+
neutralZonePct?: number;
|
|
52
|
+
amaMaxSlopePct?: number;
|
|
53
|
+
kalmanMaxSlopePct?: number;
|
|
54
|
+
dispScaleMinPct?: number;
|
|
55
|
+
regimeSensitivity?: number;
|
|
56
|
+
signalConfirmBars?: number;
|
|
57
|
+
kalmanSmoothPct?: number;
|
|
58
|
+
kalmanDispScaleMult?: number;
|
|
59
|
+
kalmanDispThresholdMult?: number;
|
|
60
|
+
kalmanSmoothSpanPct?: number;
|
|
61
|
+
[key: string]: unknown;
|
|
62
|
+
}
|
|
63
|
+
declare function generateHTML(data: DynamicWeightChartInput, title?: string): string;
|
|
2
64
|
export { generateHTML };
|
|
3
65
|
//# sourceMappingURL=dynamic_weight_chart_generator.d.ts.map
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { DEFAULT_CONFIG, MARKET_ADAPTER } from '../../modules/constants.js';
|
|
3
3
|
import { getAmaWarmupBars } from '../../market_adapter/core/strategies/ama.js';
|
|
4
4
|
import { bilinearInterpolate } from '../../market_adapter/core/strategies/regime_interp.js';
|
|
5
|
-
import { computeDynamicWeightSeries,
|
|
5
|
+
import { computeDynamicWeightSeries, computeHuberWindowSlopePct, computeAmaSlopeClipThreshold, echoLatchSeries, roundToN } from '../../market_adapter/core/strategies/dynamic_weight_series.js';
|
|
6
6
|
import { buildKalmanVelocitySeries, computeAbsolutePercentileThreshold, resolveKalmanVelocitySmoothingConfig, smoothKalmanVelocityPoint, } from '../../market_adapter/core/signals/kalman_velocity_smoothing.js';
|
|
7
7
|
import { embedFunctionSources, escapeHtml, serializeJsonForScript, toEpochSeconds, UPLOT_SHARED_SCRIPT, uplotInlineTags } from '../chart_utils.js';
|
|
8
8
|
import { sharedChartCSS } from '../chart_css.js';
|
|
@@ -10,7 +10,6 @@ import { Y_AXIS_SIZE, makeCursorConfig, bindHoverStateFn, wireChartEvents, zoomR
|
|
|
10
10
|
// Browser-embedded shared functions — the interactive chart runs the exact same
|
|
11
11
|
// pure logic as the live market adapter service instead of a hand-copied copy.
|
|
12
12
|
const EMBEDDED_SHARED_FUNCS = embedFunctionSources([
|
|
13
|
-
computeAverageAmaSlopePct,
|
|
14
13
|
computeHuberWindowSlopePct,
|
|
15
14
|
computeAmaSlopeClipThreshold,
|
|
16
15
|
bilinearInterpolate,
|
|
@@ -28,12 +27,11 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
|
|
|
28
27
|
throw new Error('No analysis results in input');
|
|
29
28
|
// Slider ranges — single source of truth for HTML attrs, tooltips,
|
|
30
29
|
// payload transport, and client paste-clamp bounds.
|
|
31
|
-
const LB_MIN =
|
|
30
|
+
const LB_MIN = 4, LB_MAX = 32;
|
|
32
31
|
const GAIN_MIN = 0.5, GAIN_MAX = 2.0;
|
|
33
32
|
const AMA_MS_MIN = 0.06, AMA_MS_MAX = 0.12;
|
|
34
|
-
const KAL_MS_MIN = 0.
|
|
33
|
+
const KAL_MS_MIN = 0.75, KAL_MS_MAX = 1.5;
|
|
35
34
|
const CLIP_PCT_MAX = 20;
|
|
36
|
-
const EMA_MIN = 0, EMA_MAX = 32;
|
|
37
35
|
const TH_MIN = 0, TH_MAX = 0.5;
|
|
38
36
|
const KF_MIN = 0, KF_MAX = 200;
|
|
39
37
|
const KFD_MIN = 1.0, KFD_MAX = 3.0;
|
|
@@ -47,7 +45,6 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
|
|
|
47
45
|
dispWeight: [0, 1],
|
|
48
46
|
neutralZonePct: [0, 1],
|
|
49
47
|
lookbackBars: [LB_MIN, LB_MAX],
|
|
50
|
-
amaEmaSpan: [EMA_MIN, EMA_MAX],
|
|
51
48
|
amaMaxSlopePct: [AMA_MS_MIN, AMA_MS_MAX],
|
|
52
49
|
kalmanMaxSlopePct: [KAL_MS_MIN, KAL_MS_MAX],
|
|
53
50
|
clipPct: [0, CLIP_PCT_MAX],
|
|
@@ -107,10 +104,6 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
|
|
|
107
104
|
const defaultKalmanDispThresholdMult = data.kalmanDispThresholdMult ?? MARKET_ADAPTER.DYNAMIC_WEIGHT_KALMAN_DISP_THRESHOLD_MULT_DEFAULT;
|
|
108
105
|
const defaultKalmanSmoothSpanPct = data.kalmanSmoothSpanPct ?? MARKET_ADAPTER.DYNAMIC_WEIGHT_KALMAN_SMOOTH_SPAN_PCT_DEFAULT;
|
|
109
106
|
const defaultSignalConfirmBars = data.signalConfirmBars ?? MARKET_ADAPTER.DYNAMIC_WEIGHT_SIGNAL_CONFIRM_BARS_DEFAULT;
|
|
110
|
-
// Research-only `ema` knob: EMA span in bars over the AMA input before the
|
|
111
|
-
// slope is taken. 0 (default) = off, keeps the raw AMA input.
|
|
112
|
-
const defaultAmaEmaSpanRaw = data.amaEmaSpan ?? ma.amaEmaSpan ?? 0;
|
|
113
|
-
const defaultAmaEmaSpan = Math.round(Math.min(EMA_MAX, Math.max(EMA_MIN, Number.isFinite(defaultAmaEmaSpanRaw) ? defaultAmaEmaSpanRaw : EMA_MIN)));
|
|
114
107
|
const regimeInitSlider = Math.round(defaultRegimeSensitivity * 100);
|
|
115
108
|
const interval = results.length > 1 ?
|
|
116
109
|
(new Date(results[1].timestamp).getTime() - new Date(results[0].timestamp).getTime()) / 1000 : 3600;
|
|
@@ -137,8 +130,7 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
|
|
|
137
130
|
const amaErPeriod = data.amaConfig?.erPeriod ?? MARKET_ADAPTER.AMAS[defaultAmaKey].erPeriod;
|
|
138
131
|
const amaSlowPeriod = data.amaConfig?.slowPeriod ?? MARKET_ADAPTER.AMAS[defaultAmaKey].slowPeriod;
|
|
139
132
|
const amaFastPeriod = data.amaConfig?.fastPeriod ?? MARKET_ADAPTER.AMAS[defaultAmaKey].fastPeriod;
|
|
140
|
-
const
|
|
141
|
-
const amaWarmupBars = getAmaWarmupBars(amaErPeriod, amaSlowPeriod, lookbackBars, amaFastPeriod, amaErSmoothPeriod);
|
|
133
|
+
const amaWarmupBars = getAmaWarmupBars(amaErPeriod, amaSlowPeriod, lookbackBars, amaFastPeriod);
|
|
142
134
|
const amaSlopeReadyBars = Math.ceil(amaErPeriod) + lookbackBars;
|
|
143
135
|
const amaSeedSmaLine = new Array(results.length).fill(null);
|
|
144
136
|
const amaSeedWindowEnd = Math.min(results.length - 1, Math.ceil(amaErPeriod));
|
|
@@ -176,22 +168,13 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
|
|
|
176
168
|
amaSeedSmaLine.push(null);
|
|
177
169
|
}
|
|
178
170
|
const realBarCount = results.length;
|
|
179
|
-
function maxAbsPct(arr) {
|
|
180
|
-
let m = 0;
|
|
181
|
-
for (let i = 0; i < realBarCount; i++) {
|
|
182
|
-
if (arr[i] != null && Math.abs(arr[i]) > m)
|
|
183
|
-
m = Math.abs(arr[i]);
|
|
184
|
-
}
|
|
185
|
-
return m || 4;
|
|
186
|
-
}
|
|
187
|
-
const amaPctMax = Math.ceil(maxAbsPct(amaSlopePct) * 1.15) || 5;
|
|
188
|
-
const kalPctMax = Math.ceil(Math.max(maxAbsPct(kalmanVelocityPct), maxAbsPct(kalmanDisplacementPct)) * 1.15) || 5;
|
|
189
171
|
function buildPercentiles(arr, startIndex = 0) {
|
|
190
172
|
const safeStartIndex = Math.max(0, Math.min(realBarCount, Math.ceil(startIndex)));
|
|
191
173
|
const sorted = [];
|
|
192
174
|
for (let i = safeStartIndex; i < realBarCount; i++) {
|
|
193
|
-
|
|
194
|
-
|
|
175
|
+
const v = arr[i];
|
|
176
|
+
if (v != null)
|
|
177
|
+
sorted.push(Math.abs(v));
|
|
195
178
|
}
|
|
196
179
|
sorted.sort((a, b) => a - b);
|
|
197
180
|
// Empty pool → Infinity: the live percentile lookup treats an empty
|
|
@@ -208,7 +191,6 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
|
|
|
208
191
|
}
|
|
209
192
|
const amaPercentiles = buildPercentiles(amaSlopePct, amaSlopeReadyBars);
|
|
210
193
|
const kalPercentiles = buildPercentiles(kalmanVelocityPct);
|
|
211
|
-
const maxDispPct = Math.ceil(maxAbsPct(kalmanDisplacementPct) * 1.15) || 5;
|
|
212
194
|
return `<!DOCTYPE html>
|
|
213
195
|
<html lang="en">
|
|
214
196
|
<head>
|
|
@@ -225,7 +207,7 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
|
|
|
225
207
|
.legend-item { gap: 3px; }
|
|
226
208
|
.legend-val { font-family: monospace; display: inline-block; text-align: right; min-width: 45px; }
|
|
227
209
|
#l-price, #l-ama3 { min-width: 62px; }
|
|
228
|
-
#l-ama-slope, #l-
|
|
210
|
+
#l-ama-slope, #l-kal-vel, #l-kal-disp { min-width: 54px; }
|
|
229
211
|
#l-signal, #l-signal-latched { min-width: 70px; text-align: left; }
|
|
230
212
|
#l-combined-raw, #l-combined-echo { min-width: 42px; }
|
|
231
213
|
#l-mult { min-width: 38px; }
|
|
@@ -270,9 +252,6 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
|
|
|
270
252
|
.ctrl.lb label { min-width: 20px; }
|
|
271
253
|
.ctrl.lb input[type="range"] { accent-color: #39d0d8; width: 80px; }
|
|
272
254
|
.ctrl.lb .val { color: #39d0d8; }
|
|
273
|
-
.ctrl.ema label { min-width: 20px; }
|
|
274
|
-
.ctrl.ema input[type="range"] { accent-color: #f0a000; width: 80px; }
|
|
275
|
-
.ctrl.ema .val { color: #f0a000; }
|
|
276
255
|
.ctrl.off input[type="range"] { accent-color: #3fb950; }
|
|
277
256
|
.ctrl.off .val { color: #3fb950; }
|
|
278
257
|
.ctrl.nz input[type="range"] { accent-color: #8b949e; }
|
|
@@ -318,7 +297,6 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
|
|
|
318
297
|
<div class="section-label">AMA SLOPE INPUT</div>
|
|
319
298
|
<div class="legend">
|
|
320
299
|
<div class="legend-item"><div class="dot" style="background:#f0a000;"></div>Slope‰: <span id="l-ama-slope" class="legend-val" style="font-weight:bold;">-</span></div>
|
|
321
|
-
<div class="legend-item"><div class="dot" style="background:#8b949e;"></div>Raw‰: <span id="l-ama-slope-raw" class="legend-val">-</span></div>
|
|
322
300
|
</div>
|
|
323
301
|
<div id="ama-chart"></div>
|
|
324
302
|
</div>
|
|
@@ -349,7 +327,6 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
|
|
|
349
327
|
<div class="group-sep"></div>
|
|
350
328
|
<div class="ctrl nz"><label for="nz-slider">nz%</label><input type="range" id="nz-slider" min="0" max="100" value="${Math.round(defaultNeutralZone * 100)}" title="Neutral Zone %"><span class="val" id="nz-value">${defaultNeutralZone.toFixed(2)}</span></div>
|
|
351
329
|
<div class="ctrl lb"><label for="lb-slider">lb</label><input type="range" id="lb-slider" min="0" max="1000" value="${lbInitSlider}" title="Lookback Bars (${LB_MIN}-${LB_MAX})"><span class="val" id="lb-value">${lookbackBars}</span></div>
|
|
352
|
-
<div class="ctrl ema"><label for="ema-slider">ema</label><input type="range" id="ema-slider" min="${EMA_MIN}" max="${EMA_MAX}" value="${defaultAmaEmaSpan}" title="AMA input EMA span in bars (${EMA_MIN} = off; noise std ~ 1/sqrt(span), lag ~ (span-1)/2 bars; span ~ lb is the balance point)"><span class="val" id="ema-value">${defaultAmaEmaSpan}</span></div>
|
|
353
330
|
<div class="ctrl ms-ama"><label for="ama-ms-slider">amaS%</label><input type="range" id="ama-ms-slider" min="0" max="1000" value="${amaMsInitSlider}" title="AMA Max Slope % per bar (${AMA_MS_MIN}-${AMA_MS_MAX})"><span class="val" id="ama-ms-value">${defaultAmaMaxSlopePct.toFixed(4)}</span></div>
|
|
354
331
|
<div class="ctrl clip"><label for="clip-slider">clip%</label><input type="range" id="clip-slider" min="0" max="${CLIP_PCT_MAX}" value="${Math.min(defaultClipPct, CLIP_PCT_MAX)}" title="Outlier Clip %"><span class="val" id="clip-value">${Math.min(defaultClipPct, CLIP_PCT_MAX)}%</span></div>
|
|
355
332
|
|
|
@@ -383,7 +360,7 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
|
|
|
383
360
|
</div>
|
|
384
361
|
</div>
|
|
385
362
|
|
|
386
|
-
<script id="payload" type="application/json">${serializeJsonForScript({ dates, prices, hurstArr, peArr, hurstSegments, peSegments, ama3Prices, amaSeedSmaLine,
|
|
363
|
+
<script id="payload" type="application/json">${serializeJsonForScript({ dates, prices, hurstArr, peArr, hurstSegments, peSegments, ama3Prices, amaSeedSmaLine, kalmanVelocityPctRaw, kalmanVelocityPct, kalmanDisplacementPct, kalmanIsReady, signals, alpha: defaultAlpha, gain: defaultGain, kalmanSmoothPct: defaultKalmanSmoothPct, kalmanDispScaleMult: defaultKalmanDispScaleMult, kalmanDispThresholdMult: defaultKalmanDispThresholdMult, kalmanSmoothSpanPct: defaultKalmanSmoothSpanPct, signalConfirmBars: defaultSignalConfirmBars, neutralZonePct: defaultNeutralZone, dispWeight: defaultDispWeight, amaMaxSlopePct: defaultAmaMaxSlopePct, kalmanMaxSlopePct: defaultKalmanMaxSlopePct, clipPct: defaultClipPct, minOutputThreshold: defaultMinOutputThreshold, outputClamp: defaultOutputClamp, regimeSensitivity: defaultRegimeSensitivity, absoluteThreshold: defaultAbsoluteThreshold, lookbackBars, amaErPeriod, amaSlowPeriod, amaWarmupBars, amaSlopeReadyBars, realBarCount, amaPercentiles, kalPercentiles, amaSlopeLogMin: AMA_MS_LOG_MIN_N, amaSlopeLogMax: AMA_MS_LOG_MAX_N, kalSlopeLogMin: KAL_MS_LOG_MIN_N, kalSlopeLogMax: KAL_MS_LOG_MAX_N, lbLogMin: LB_LOG_MIN_N, lbLogMax: LB_LOG_MAX_N, gainLogMin: GAIN_LOG_MIN_N, gainLogMax: GAIN_LOG_MAX_N, sliderRanges: SLIDER_RANGES, dispScaleMinPct: defaultDispScaleMinPct, weightMin: MARKET_ADAPTER.DYNAMIC_WEIGHT_MIN_WEIGHT, weightMax: MARKET_ADAPTER.DYNAMIC_WEIGHT_MAX_WEIGHT, marketAdapter: ma, amaWeightConfig, hNodes: [0.5 + MARKET_ADAPTER.HURST_ZONE_BAND, 0.5, 0.5 - MARKET_ADAPTER.HURST_ZONE_BAND], pNodes: MARKET_ADAPTER.PE_NODES, regimeTable: MARKET_ADAPTER.REGIME_TABLE })}</script>
|
|
387
364
|
|
|
388
365
|
<script>
|
|
389
366
|
const data = JSON.parse(document.getElementById('payload').textContent);
|
|
@@ -429,8 +406,7 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
|
|
|
429
406
|
const kalMsSliderToVal = (pos) => Math.exp(KAL_MS_LOG_MIN + (pos / 1000) * (KAL_MS_LOG_MAX - KAL_MS_LOG_MIN));
|
|
430
407
|
|
|
431
408
|
let currentLookbackBars = data.lookbackBars ?? ${JSON.stringify(lookbackBars)};
|
|
432
|
-
|
|
433
|
-
let currentAmaSource = data.ama3Prices;
|
|
409
|
+
const currentAmaSource = data.ama3Prices;
|
|
434
410
|
const LB_LOG_MIN = data.lbLogMin;
|
|
435
411
|
const LB_LOG_MAX = data.lbLogMax;
|
|
436
412
|
const lbSliderToVal = (pos) => Math.round(Math.exp(LB_LOG_MIN + (pos / 1000) * (LB_LOG_MAX - LB_LOG_MIN)));
|
|
@@ -442,11 +418,10 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
|
|
|
442
418
|
const gainValToSlider = (val) => Math.round((Math.log(Math.max(Math.exp(GAIN_LOG_MIN), val)) - GAIN_LOG_MIN) / (GAIN_LOG_MAX - GAIN_LOG_MIN) * 1000);
|
|
443
419
|
|
|
444
420
|
let currentClipPct = data.clipPct ?? ${JSON.stringify(defaultClipPct)};
|
|
445
|
-
//
|
|
446
|
-
//
|
|
447
|
-
//
|
|
448
|
-
|
|
449
|
-
let currentAmaClipThreshold = currentClipPct === 0 ? maxAmaSlope : Infinity;
|
|
421
|
+
// The AMA clip threshold always comes from dynamicClipThreshold, which
|
|
422
|
+
// recalcInputs() recomputes via the canonical
|
|
423
|
+
// computeAmaSlopeClipThreshold (Infinity when clipping is disabled,
|
|
424
|
+
// matching the live adapter). No separate clipPct==0 branch is needed.
|
|
450
425
|
let currentKalClipThreshold = currentClipPct === 0 ? Infinity : data.kalPercentiles[100 - currentClipPct];
|
|
451
426
|
|
|
452
427
|
// Regime table and axis nodes from payload — sourced from MARKET_ADAPTER in constants.ts
|
|
@@ -460,7 +435,10 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
|
|
|
460
435
|
*/
|
|
461
436
|
function getRegimeMultiplier(H, PE) {
|
|
462
437
|
if (H == null || PE == null) return 1.0;
|
|
463
|
-
|
|
438
|
+
// NOTE: peNodes is the canonical option name read by
|
|
439
|
+
// bilinearInterpolate; a pNodes key silently falls back to the
|
|
440
|
+
// inline defaults.
|
|
441
|
+
return bilinearInterpolate(H, PE, REGIME_TABLE, { hNodes: H_NODES, peNodes: P_NODES });
|
|
464
442
|
}
|
|
465
443
|
|
|
466
444
|
let currentRegimeSensitivity = data.regimeSensitivity ?? ma.regimeSensitivity;
|
|
@@ -469,7 +447,6 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
|
|
|
469
447
|
const currentLatchedSignals = new Array(data.dates.length).fill(null);
|
|
470
448
|
const dynamicAmaOff = new Array(data.dates.length).fill(null);
|
|
471
449
|
const dynamicAmaSlopePct = new Array(data.dates.length).fill(null);
|
|
472
|
-
const dynamicAmaSlopePctRaw = new Array(data.dates.length).fill(null);
|
|
473
450
|
const dynamicKalOff = new Array(data.dates.length).fill(null);
|
|
474
451
|
const combinedOff = new Array(data.dates.length).fill(null);
|
|
475
452
|
const combinedSell = new Array(data.dates.length).fill(null);
|
|
@@ -584,37 +561,6 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
|
|
|
584
561
|
}
|
|
585
562
|
}
|
|
586
563
|
|
|
587
|
-
/**
|
|
588
|
-
* Research-only ema knob — EMA low-pass over the AMA input before the
|
|
589
|
-
* slope is taken (EMA-then-difference == difference-then-EMA, both are
|
|
590
|
-
* linear filters). span bars, alpha = 2/(span+1): noise std shrinks ~
|
|
591
|
-
* 1/sqrt(span), lag grows ~ (span-1)/2 bars. Seeded with an SMA over the
|
|
592
|
-
* first 'span' finite values (mirrors the AMA seed SMA) so the transient
|
|
593
|
-
* is gone before any slope bar can go ready. Nulls (warmup / trailing
|
|
594
|
-
* padding) stay null so no fabricated values reach the clip-percentile
|
|
595
|
-
* pool or the offset pipeline. span <= 0 returns the input untouched.
|
|
596
|
-
*/
|
|
597
|
-
function buildEmaSeries(values, span) {
|
|
598
|
-
if (!(span > 0) || !Array.isArray(values)) return values;
|
|
599
|
-
const n = values.length;
|
|
600
|
-
const out = new Array(n);
|
|
601
|
-
const alpha = 2 / (span + 1);
|
|
602
|
-
let seedSum = 0, seedCount = 0;
|
|
603
|
-
for (let i = 0; i < n && seedCount < span; i++) {
|
|
604
|
-
const v = values[i];
|
|
605
|
-
if (v == null || !Number.isFinite(v)) continue;
|
|
606
|
-
seedSum += v; seedCount++;
|
|
607
|
-
}
|
|
608
|
-
let prev = seedCount > 0 ? seedSum / seedCount : null;
|
|
609
|
-
for (let i = 0; i < n; i++) {
|
|
610
|
-
const v = values[i];
|
|
611
|
-
if (v == null || !Number.isFinite(v)) { out[i] = null; continue; }
|
|
612
|
-
prev = prev == null ? v : alpha * v + (1 - alpha) * prev;
|
|
613
|
-
out[i] = prev;
|
|
614
|
-
}
|
|
615
|
-
return out;
|
|
616
|
-
}
|
|
617
|
-
|
|
618
564
|
function computeSlopeAtIndex(idx, lb, values) {
|
|
619
565
|
// Canonical AMA slope % (computeHuberWindowSlopePct injected above).
|
|
620
566
|
const sp = computeHuberWindowSlopePct(values, idx, lb);
|
|
@@ -625,7 +571,6 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
|
|
|
625
571
|
recalcKalmanVelocity();
|
|
626
572
|
recalcKalmanClipThreshold();
|
|
627
573
|
recalcLatchedSignals();
|
|
628
|
-
currentAmaSource = buildEmaSeries(data.ama3Prices, currentAmaEmaSpan);
|
|
629
574
|
const lb = currentLookbackBars;
|
|
630
575
|
const amaErWarmup = Math.max(0, Number.isFinite(data.amaErPeriod) ? Math.ceil(data.amaErPeriod) : ${JSON.stringify(MARKET_ADAPTER.AMAS[MARKET_ADAPTER.DEFAULT_AMA_KEY].erPeriod)});
|
|
631
576
|
const amaReadyBar = Math.max(lb, amaErWarmup + lb);
|
|
@@ -634,20 +579,13 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
|
|
|
634
579
|
// implementation (computeAmaSlopeClipThreshold injected above),
|
|
635
580
|
// shared with the live market adapter service. Trailing padded
|
|
636
581
|
// nulls beyond realBarCount are skipped by its finiteness guards.
|
|
637
|
-
// Clip pool follows the (possibly EMA-filtered) AMA input so the
|
|
638
|
-
// percentile threshold matches the series the offsets derive from.
|
|
639
582
|
dynamicClipThreshold = computeAmaSlopeClipThreshold(currentAmaSource, amaErWarmup, lb, currentClipPct);
|
|
640
583
|
|
|
641
584
|
for (let i = 0; i < data.realBarCount; i++) {
|
|
642
|
-
|
|
643
|
-
// recalcWeights): the raw reference line from the unfiltered AMA
|
|
644
|
-
// input, the plotted series from the EMA-filtered input.
|
|
645
|
-
dynamicAmaSlopePctRaw[i] = i < amaReadyBar ? null : computeSlopeAtIndex(i, lb, data.ama3Prices);
|
|
646
|
-
dynamicAmaSlopePct[i] = i < amaReadyBar ? null : computeSlopeAtIndex(i, lb, currentAmaSource);
|
|
585
|
+
dynamicAmaSlopePct[i] = i < amaReadyBar ? null : computeSlopeAtIndex(i, lb, currentAmaSource);
|
|
647
586
|
}
|
|
648
587
|
for (let i = data.realBarCount; i < data.dates.length; i++) {
|
|
649
588
|
dynamicAmaSlopePct[i] = null;
|
|
650
|
-
dynamicAmaSlopePctRaw[i] = null;
|
|
651
589
|
}
|
|
652
590
|
}
|
|
653
591
|
|
|
@@ -655,7 +593,6 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
|
|
|
655
593
|
// Normalize each channel by the configured clamp so alpha remains a pure ratio knob.
|
|
656
594
|
// Gain then scales the blended output linearly after the dead-band decision.
|
|
657
595
|
currentOutputAxisMax = Math.max(0.5, OUTPUT_CLAMP);
|
|
658
|
-
const channelNorm = Math.max(Math.abs(OUTPUT_CLAMP), 1e-9);
|
|
659
596
|
const outputThreshold = currentMinOutputThreshold;
|
|
660
597
|
const n = data.realBarCount;
|
|
661
598
|
|
|
@@ -663,11 +600,11 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
|
|
|
663
600
|
for (let i = 0; i < data.dates.length; i++) {
|
|
664
601
|
if (i >= n) { currentMults[i] = null; continue; }
|
|
665
602
|
const baseMult = getRegimeMultiplier(data.hurstArr[i], data.peArr[i]);
|
|
666
|
-
//
|
|
667
|
-
|
|
668
|
-
//
|
|
669
|
-
|
|
670
|
-
currentMults[i] = Math.abs(rawMult - 1.0) >= ABSOLUTE_THRESHOLD ?
|
|
603
|
+
// Match the live regime gate exactly: apply the sensitivity
|
|
604
|
+
// exponent, clamp to 1.0 (dampen-only), round the per-bar series
|
|
605
|
+
// to 3 decimals, then apply the absolute-threshold dead-band.
|
|
606
|
+
const rawMult = roundToN(Math.min(Math.pow(baseMult, currentRegimeSensitivity), 1.0), 1000);
|
|
607
|
+
currentMults[i] = Math.abs(rawMult - 1.0) >= ABSOLUTE_THRESHOLD ? rawMult : 1.0;
|
|
671
608
|
}
|
|
672
609
|
|
|
673
610
|
// Per-bar offset pipeline — canonical implementation (computeDynamicWeightSeries
|
|
@@ -680,7 +617,7 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
|
|
|
680
617
|
regimeMultipliers: currentMults,
|
|
681
618
|
lookbackBars: currentLookbackBars,
|
|
682
619
|
amaErPeriod: data.amaErPeriod,
|
|
683
|
-
amaClipThreshold:
|
|
620
|
+
amaClipThreshold: dynamicClipThreshold,
|
|
684
621
|
kalClipThreshold: currentKalClipThreshold,
|
|
685
622
|
neutralZonePct: currentNz,
|
|
686
623
|
amaMaxSlopePct: currentAmaMaxSlopePct,
|
|
@@ -757,7 +694,7 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
|
|
|
757
694
|
max: Number.isFinite(xs.max) ? xs.max : xMax,
|
|
758
695
|
} : null;
|
|
759
696
|
|
|
760
|
-
amaChart.setData([data.dates,
|
|
697
|
+
amaChart.setData([data.dates, dynamicAmaSlopePct], false);
|
|
761
698
|
kalmanChart.setData([data.dates, currentKalmanVelocityPct, data.kalmanDisplacementPct], false);
|
|
762
699
|
outputChart.setData([data.dates, combinedOff, echoCombinedOff], false);
|
|
763
700
|
|
|
@@ -792,11 +729,6 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
|
|
|
792
729
|
if (sp == null) { spEl.textContent = '-'; spEl.style.color = '#8b949e'; }
|
|
793
730
|
else { spEl.textContent = (sp >= 0 ? '+' : '') + (sp * 10).toFixed(3) + '‰'; spEl.style.color = sp > 0.01 ? '#2ea043' : sp < -0.01 ? '#f85149' : '#8b949e'; }
|
|
794
731
|
|
|
795
|
-
const spRaw = dynamicAmaSlopePctRaw[idx];
|
|
796
|
-
const spRawEl = document.getElementById('l-ama-slope-raw');
|
|
797
|
-
if (spRaw == null) { spRawEl.textContent = '-'; spRawEl.style.color = '#8b949e'; }
|
|
798
|
-
else { spRawEl.textContent = (spRaw >= 0 ? '+' : '') + (spRaw * 10).toFixed(3) + '‰'; spRawEl.style.color = '#8b949e'; }
|
|
799
|
-
|
|
800
732
|
const vp = currentKalmanVelocityPct[idx];
|
|
801
733
|
const vpEl = document.getElementById('l-kal-vel');
|
|
802
734
|
if (vp == null) { vpEl.textContent = '-'; vpEl.style.color = '#8b949e'; }
|
|
@@ -1020,7 +952,6 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
|
|
|
1020
952
|
document.getElementById('clip-slider').value = currentClipPct;
|
|
1021
953
|
document.getElementById('nz-slider').value = Math.round(currentNz * 100);
|
|
1022
954
|
document.getElementById('lb-slider').value = lbValToSlider(currentLookbackBars);
|
|
1023
|
-
document.getElementById('ema-slider').value = currentAmaEmaSpan;
|
|
1024
955
|
|
|
1025
956
|
const priceEl = document.getElementById('price-panel');
|
|
1026
957
|
const amaEl = document.getElementById('ama-panel');
|
|
@@ -1056,7 +987,6 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
|
|
|
1056
987
|
scales: { x: { time: true }, p: { auto: true } },
|
|
1057
988
|
series: [
|
|
1058
989
|
{ label: 'Time' },
|
|
1059
|
-
{ label: 'Raw‰', stroke: '#8b949e', width: 1, dash: [3, 3], scale: 'p', points: { show: false } },
|
|
1060
990
|
{ label: 'Slope‰', stroke: '#f0a000', width: 2, scale: 'p', points: { show: false } },
|
|
1061
991
|
],
|
|
1062
992
|
axes: [
|
|
@@ -1066,7 +996,7 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
|
|
|
1066
996
|
],
|
|
1067
997
|
cursor: cursorCfg,
|
|
1068
998
|
hooks: { draw: [makePctFillHook(dynamicAmaSlopePct, 'p', 'rgba(46,160,67,0.20)', 'rgba(248,81,73,0.20)'), makeSignalBgHook('p')] }
|
|
1069
|
-
}, [data.dates,
|
|
999
|
+
}, [data.dates, dynamicAmaSlopePct], document.getElementById('ama-chart'));
|
|
1070
1000
|
|
|
1071
1001
|
kalmanChart = new uPlot({
|
|
1072
1002
|
width: kalmanEl.offsetWidth, height: kalmanEl.offsetHeight,
|
|
@@ -1203,7 +1133,6 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
|
|
|
1203
1133
|
document.getElementById('clip-slider').addEventListener('input', (e) => {
|
|
1204
1134
|
currentClipPct = parseInt(e.target.value, 10);
|
|
1205
1135
|
if (currentClipPct === 0) {
|
|
1206
|
-
currentAmaClipThreshold = data.amaPercentiles[data.amaPercentiles.length - 1];
|
|
1207
1136
|
currentKalClipThreshold = Infinity;
|
|
1208
1137
|
} else {
|
|
1209
1138
|
// AMA clip threshold for clipPct>0 comes from the canonical
|
|
@@ -1228,12 +1157,6 @@ function generateHTML(data, title = 'Dynamic Weight Research') {
|
|
|
1228
1157
|
onSliderChange();
|
|
1229
1158
|
});
|
|
1230
1159
|
|
|
1231
|
-
document.getElementById('ema-slider').addEventListener('input', (e) => {
|
|
1232
|
-
currentAmaEmaSpan = parseInt(e.target.value, 10);
|
|
1233
|
-
document.getElementById('ema-value').textContent = currentAmaEmaSpan;
|
|
1234
|
-
onSliderChange();
|
|
1235
|
-
});
|
|
1236
|
-
|
|
1237
1160
|
document.getElementById('regime-slider').addEventListener('input', (e) => {
|
|
1238
1161
|
currentRegimeSensitivity = parseInt(e.target.value, 10) / 100;
|
|
1239
1162
|
document.getElementById('regime-value').textContent = currentRegimeSensitivity.toFixed(2);
|
|
@@ -1308,7 +1231,6 @@ function applyParams(p, btn) {
|
|
|
1308
1231
|
document.getElementById('clip-slider').value = currentClipPct;
|
|
1309
1232
|
document.getElementById('clip-value').textContent = currentClipPct + '%';
|
|
1310
1233
|
if (currentClipPct === 0) {
|
|
1311
|
-
currentAmaClipThreshold = data.amaPercentiles[data.amaPercentiles.length - 1];
|
|
1312
1234
|
currentKalClipThreshold = Infinity;
|
|
1313
1235
|
} else {
|
|
1314
1236
|
recalcKalmanClipThreshold();
|
|
@@ -1329,11 +1251,6 @@ function applyParams(p, btn) {
|
|
|
1329
1251
|
document.getElementById('lb-slider').value = lbValToSlider(currentLookbackBars);
|
|
1330
1252
|
document.getElementById('lb-value').textContent = currentLookbackBars;
|
|
1331
1253
|
}
|
|
1332
|
-
if (p.amaEmaSpan != null) {
|
|
1333
|
-
currentAmaEmaSpan = Math.max(SR.amaEmaSpan[0], Math.min(SR.amaEmaSpan[1], Math.round(p.amaEmaSpan)));
|
|
1334
|
-
document.getElementById('ema-slider').value = currentAmaEmaSpan;
|
|
1335
|
-
document.getElementById('ema-value').textContent = currentAmaEmaSpan;
|
|
1336
|
-
}
|
|
1337
1254
|
recalcInputs();
|
|
1338
1255
|
recalcWeights();
|
|
1339
1256
|
refreshChartsPreservingZoom();
|
|
@@ -1360,7 +1277,6 @@ function applyParams(p, btn) {
|
|
|
1360
1277
|
regimeSensitivity: 'regime',
|
|
1361
1278
|
dispWeight: 'dw',
|
|
1362
1279
|
lookbackBars: 'lb',
|
|
1363
|
-
amaEmaSpan: 'ema',
|
|
1364
1280
|
};
|
|
1365
1281
|
document.getElementById('paste-confirm-vals').innerHTML = Object.entries(labels)
|
|
1366
1282
|
.filter(([k]) => p[k] != null)
|
|
@@ -1414,7 +1330,6 @@ function applyParams(p, btn) {
|
|
|
1414
1330
|
regimeSensitivity: +currentRegimeSensitivity.toFixed(2),
|
|
1415
1331
|
dispWeight: +currentDw.toFixed(2),
|
|
1416
1332
|
lookbackBars: currentLookbackBars,
|
|
1417
|
-
amaEmaSpan: currentAmaEmaSpan,
|
|
1418
1333
|
};
|
|
1419
1334
|
const json = JSON.stringify(params, null, 2);
|
|
1420
1335
|
localStorage.setItem(LS_KEY, json);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export type HuberScaleMode = 'none' | 'df' | 'mscale';
|
|
2
|
+
/** One-bar diagnostic snapshot returned alongside the slope. */
|
|
3
|
+
export interface HuberDiagnostics {
|
|
4
|
+
slopePct: number;
|
|
5
|
+
scale: number;
|
|
6
|
+
outlierFraction: number;
|
|
7
|
+
}
|
|
8
|
+
/** Accumulated stats attached to an estimator built by {@link createHuberEstimator}. */
|
|
9
|
+
export interface HuberEstimatorStats {
|
|
10
|
+
calls: number;
|
|
11
|
+
outlierFractionSum: number;
|
|
12
|
+
scaleSum: number;
|
|
13
|
+
}
|
|
14
|
+
/** Estimator function shape accepted by simulateGridResetSeries (cfg.slopeEstimator). */
|
|
15
|
+
export interface HuberConsts {
|
|
16
|
+
C?: number;
|
|
17
|
+
ITERATIONS?: number;
|
|
18
|
+
SCALE_FLOOR?: number;
|
|
19
|
+
ZERO_EPSILON?: number;
|
|
20
|
+
}
|
|
21
|
+
export type HuberEstimator = ((amaValues: unknown, index: number, lookbackBars: unknown) => number | null) & {
|
|
22
|
+
stats: HuberEstimatorStats;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* delta_C = E[rho_C(Z)] for Z ~ N(0,1), the proposal-2 consistency constant:
|
|
26
|
+
* delta_C = 2*Phi(c) - 1 + 2*c*phi(c) - 2*c^2*(1 - Phi(c)).
|
|
27
|
+
*/
|
|
28
|
+
export declare function huberConsistencyConstant(c: number): number;
|
|
29
|
+
/**
|
|
30
|
+
* Core fit. Reproduces `computeHuberWindowSlopePct` byte-for-byte for
|
|
31
|
+
* `mode='none'`; the other modes change only the scale estimate fed to the
|
|
32
|
+
* Huber weight `min(1, C*s/|r|)`.
|
|
33
|
+
*/
|
|
34
|
+
export declare function huberSlopeCore(amaValues: unknown, index: number, lookbackBars: unknown, mode?: HuberScaleMode, hub?: HuberConsts): HuberDiagnostics | null;
|
|
35
|
+
/**
|
|
36
|
+
* Build the `(series, index, lookbackBars)` estimator the reset replay expects,
|
|
37
|
+
* accumulating the mean outlier fraction and scale across calls in `.stats`.
|
|
38
|
+
*/
|
|
39
|
+
export declare function createHuberEstimator(mode?: HuberScaleMode, hub?: HuberConsts): HuberEstimator;
|
|
40
|
+
//# sourceMappingURL=huber_scale_variants.d.ts.map
|