dexbot 1.6.7 → 1.6.8
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 +49 -1
- package/README.md +3 -3
- package/analysis/README.md +2 -3
- package/analysis/tradingview/README.md +78 -1
- package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +1 -1
- 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/tradingview/analyze_tradingview.d.ts +4 -0
- package/dist/analysis/tradingview/analyze_tradingview.js +55 -0
- package/dist/analysis/tradingview/grid_reset_config.d.ts +61 -0
- package/dist/analysis/tradingview/grid_reset_config.js +235 -0
- package/dist/analysis/tradingview/grid_reset_sim.d.ts +67 -0
- package/dist/analysis/tradingview/grid_reset_sim.js +307 -0
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +419 -3
- package/dist/dexbot.js +22 -6
- package/dist/market_adapter/core/market_adapter_service.js +14 -2
- package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts +8 -1
- package/dist/market_adapter/core/strategies/dynamic_weight_series.js +5 -1
- package/dist/market_adapter/inputs/window_cache.d.ts +97 -19
- package/dist/market_adapter/inputs/window_cache.js +302 -48
- package/dist/market_adapter/market_adapter.d.ts +8 -1
- package/dist/market_adapter/market_adapter.js +22 -4
- package/dist/modules/account_bots.js +10 -0
- package/dist/modules/account_orders.d.ts +24 -2
- package/dist/modules/account_orders.js +41 -4
- package/dist/modules/bot_settings.js +10 -1
- package/dist/modules/config.d.ts +1 -0
- package/dist/modules/config.js +1 -0
- package/dist/modules/constants.d.ts +11 -3
- package/dist/modules/constants.js +116 -37
- package/dist/modules/dexbot_class.d.ts +6 -76
- package/dist/modules/dexbot_class.js +0 -32
- package/dist/modules/dexbot_cow_runtime.d.ts +3 -58
- package/dist/modules/dexbot_cow_runtime.js +4 -87
- package/dist/modules/dexbot_maintenance_runtime.d.ts +15 -1
- package/dist/modules/dexbot_maintenance_runtime.js +59 -11
- package/dist/modules/dexbot_startup_runtime.js +73 -20
- package/dist/modules/dexbot_state_recovery.d.ts +6 -0
- package/dist/modules/dexbot_state_recovery.js +21 -0
- package/dist/modules/order/async_lock.d.ts +8 -0
- package/dist/modules/order/async_lock.js +15 -0
- package/dist/modules/order/genesis_policy.d.ts +162 -0
- package/dist/modules/order/genesis_policy.js +267 -0
- package/dist/modules/order/grid.js +76 -134
- package/dist/modules/order/grid_reconcile.d.ts +9 -0
- package/dist/modules/order/grid_reconcile.js +13 -4
- package/dist/modules/order/grid_reconcile_internal.js +2 -2
- package/dist/modules/order/manager.d.ts +4 -0
- package/dist/modules/order/manager.js +14 -1
- package/dist/modules/order/sync_engine.d.ts +19 -0
- package/dist/modules/order/sync_engine.js +284 -344
- package/dist/modules/order/utils/math.d.ts +22 -1
- package/dist/modules/order/utils/math.js +64 -1
- package/dist/modules/order/utils/order.d.ts +43 -58
- package/dist/modules/order/utils/order.js +220 -197
- package/dist/modules/order/utils/system.js +8 -1
- package/dist/modules/paths.d.ts +1 -0
- package/dist/modules/paths.js +1 -0
- package/dist/modules/version_notice.d.ts +165 -0
- package/dist/modules/version_notice.js +364 -0
- package/dist/pm2.js +9 -0
- package/dist/unlock.js +28 -0
- package/docs/BITSHARES_ONBOARDING.md +8 -1
- package/docs/COW_INVARIANTS.md +3 -2
- package/docs/DEXBOT_COMPARISON.md +4 -4
- package/docs/EVOLUTION.md +20 -19
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
- package/docs/GRID_PRICE_INVARIANT.md +149 -31
- package/docs/GRID_RECALCULATION.md +12 -0
- package/docs/README.md +3 -1
- package/docs/WORKFLOW.md +16 -5
- package/market_adapter/README.md +1 -1
- package/modules/README.md +18 -1
- package/package.json +13 -5
- package/scripts/README.md +28 -2
- package/scripts/clear-all.sh +13 -4
- package/scripts/clear-logs.sh +13 -4
- package/scripts/clear-market-adapter.sh +6 -0
- package/scripts/clear-orders.sh +5 -0
- package/scripts/lib/dexbot-paths.sh +108 -0
- package/tests/README.md +11 -3
- package/analysis/account_resolver.ts +0 -161
- package/analysis/ama_fitting/analyze_ama_price_changes.ts +0 -155
- package/analysis/ama_fitting/analyze_lambda_vs_slow.ts +0 -404
- package/analysis/ama_fitting/calibrate_convergence_er.ts +0 -201
- package/analysis/ama_fitting/fetch_lp_candles.ts +0 -184
- package/analysis/ama_fitting/generate_unified_comparison_chart.ts +0 -232
- package/analysis/ama_fitting/optimizer_high_resolution.ts +0 -802
- package/analysis/analyze_dynamic_weight.ts +0 -243
- package/analysis/analyze_kalman.ts +0 -157
- package/analysis/analyze_regime.ts +0 -158
- package/analysis/analyze_regime_windows.ts +0 -470
- package/analysis/analyze_risk_profile.ts +0 -199
- package/analysis/analyze_trade_heatmap.ts +0 -362
- package/analysis/analyze_volatility.ts +0 -182
- package/analysis/bot_fitting/backtest_ama_sweep.ts +0 -934
- package/analysis/bot_fitting/backtest_bot_fitting.ts +0 -861
- package/analysis/bot_fitting/shared_utils.ts +0 -52
- package/analysis/bot_key_utils.ts +0 -426
- package/analysis/bot_usage/discover_bot_accounts.ts +0 -635
- package/analysis/bot_usage/kibana_bot_queries.ts +0 -211
- package/analysis/chain_pool.ts +0 -47
- package/analysis/chart_css.ts +0 -62
- package/analysis/chart_ui.ts +0 -105
- package/analysis/chart_utils.ts +0 -210
- package/analysis/fills_source.ts +0 -228
- package/analysis/grid_correction_check.ts +0 -786
- package/analysis/math_utils.ts +0 -53
- package/analysis/price_sources.ts +0 -136
- package/analysis/resolve_bot_accounts.ts +0 -199
- package/analysis/resolve_source.ts +0 -99
- package/analysis/results/ama_sweep_results_lp_pool_133_1h.json +0 -2455
- package/analysis/results/bot_fitting_results_lp_pool_133_1h.json +0 -218
- package/analysis/trade_profitability.ts +0 -1335
- package/analysis/tradingview/analyze_tradingview.ts +0 -280
- package/analysis/tradingview/h-bts_tradingview.html +0 -1570
- package/analysis/tradingview/t-bts_tradingview.html +0 -1570
- package/analysis/tradingview/tradingview_uplot_chart_generator.ts +0 -3268
- package/analysis/trend_detection/dynamic_weight_chart_generator.ts +0 -1481
- package/analysis/trend_detection/hurst_analyzer.ts +0 -7
- package/analysis/trend_detection/kalman_chart_generator.ts +0 -398
- package/analysis/trend_detection/kalman_trend_analyzer.ts +0 -9
- package/analysis/trend_detection/kalman_velocity_smoothing.ts +0 -7
- package/analysis/trend_detection/package.json +0 -23
- package/analysis/trend_detection/permutation_entropy_analyzer.ts +0 -7
- package/analysis/trend_detection/regime_chart_generator.ts +0 -338
- package/analysis/trend_detection/tests/test_kalman_trend.ts +0 -153
- package/analysis/trend_detection/tests/test_kalman_velocity_smoothing.ts +0 -64
- package/analysis/trend_detection/volatility_chart_generator.ts +0 -654
- package/analysis/tsconfig.json +0 -29
- package/claw/tests/package.json +0 -3
- package/claw/tests/test_claw_bridge.ts +0 -570
- package/claw/tests/test_claw_catalog_and_credentials.ts +0 -156
- package/claw/tests/test_claw_chain_layer.ts +0 -739
- package/claw/tests/test_claw_data_flow.ts +0 -525
- package/claw/tests/test_claw_domain_logic.ts +0 -471
- package/claw/tests/test_claw_manifest_and_matrix.ts +0 -222
- package/claw/tests/test_claw_mcp_transport.ts +0 -243
- package/claw/tests/test_claw_regressions.ts +0 -711
- package/claw/tests/test_claw_skill_generation.ts +0 -103
- package/claw/tests/test_claw_state_store.ts +0 -44
- package/claw/tests/test_dexbot_profiles.ts +0 -654
- package/claw/tests/test_memu_bridge.ts +0 -189
- package/claw/tests/test_nullclaw_tmp_integration.ts +0 -57
- package/claw/tests/test_position_health.ts +0 -343
- package/claw/tests/test_position_manager.ts +0 -429
- package/claw/tests/test_position_manager_watch_health.ts +0 -100
- package/claw/tests/test_short_mpa_strategy.ts +0 -232
- package/dist/analysis/account_resolver.d.ts.map +0 -1
- package/dist/analysis/account_resolver.js.map +0 -1
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.js.map +0 -1
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js.map +0 -1
- package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js.map +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.js.map +0 -1
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js.map +0 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts.map +0 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js.map +0 -1
- package/dist/analysis/analyze_dynamic_weight.d.ts.map +0 -1
- package/dist/analysis/analyze_dynamic_weight.js.map +0 -1
- package/dist/analysis/analyze_kalman.d.ts.map +0 -1
- package/dist/analysis/analyze_kalman.js.map +0 -1
- package/dist/analysis/analyze_regime.d.ts.map +0 -1
- package/dist/analysis/analyze_regime.js.map +0 -1
- package/dist/analysis/analyze_regime_windows.d.ts.map +0 -1
- package/dist/analysis/analyze_regime_windows.js.map +0 -1
- package/dist/analysis/analyze_risk_profile.d.ts.map +0 -1
- package/dist/analysis/analyze_risk_profile.js.map +0 -1
- package/dist/analysis/analyze_trade_heatmap.d.ts.map +0 -1
- package/dist/analysis/analyze_trade_heatmap.js.map +0 -1
- package/dist/analysis/analyze_volatility.d.ts.map +0 -1
- package/dist/analysis/analyze_volatility.js.map +0 -1
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js.map +0 -1
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js.map +0 -1
- package/dist/analysis/bot_fitting/shared_utils.d.ts.map +0 -1
- package/dist/analysis/bot_fitting/shared_utils.js.map +0 -1
- package/dist/analysis/bot_key_utils.d.ts.map +0 -1
- package/dist/analysis/bot_key_utils.js.map +0 -1
- package/dist/analysis/bot_usage/discover_bot_accounts.d.ts.map +0 -1
- package/dist/analysis/bot_usage/discover_bot_accounts.js.map +0 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +0 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.js.map +0 -1
- package/dist/analysis/chain_pool.d.ts.map +0 -1
- package/dist/analysis/chain_pool.js.map +0 -1
- package/dist/analysis/chart_css.d.ts.map +0 -1
- package/dist/analysis/chart_css.js.map +0 -1
- package/dist/analysis/chart_ui.d.ts.map +0 -1
- package/dist/analysis/chart_ui.js.map +0 -1
- package/dist/analysis/chart_utils.d.ts.map +0 -1
- package/dist/analysis/chart_utils.js.map +0 -1
- package/dist/analysis/fills_source.d.ts.map +0 -1
- package/dist/analysis/fills_source.js.map +0 -1
- package/dist/analysis/grid_correction_check.d.ts.map +0 -1
- package/dist/analysis/grid_correction_check.js.map +0 -1
- package/dist/analysis/math_utils.d.ts.map +0 -1
- package/dist/analysis/math_utils.js.map +0 -1
- package/dist/analysis/price_sources.d.ts.map +0 -1
- package/dist/analysis/price_sources.js.map +0 -1
- package/dist/analysis/resolve_bot_accounts.d.ts.map +0 -1
- package/dist/analysis/resolve_bot_accounts.js.map +0 -1
- package/dist/analysis/resolve_source.d.ts.map +0 -1
- package/dist/analysis/resolve_source.js.map +0 -1
- package/dist/analysis/trade_profitability.d.ts.map +0 -1
- package/dist/analysis/trade_profitability.js.map +0 -1
- package/dist/analysis/tradingview/analyze_tradingview.d.ts.map +0 -1
- package/dist/analysis/tradingview/analyze_tradingview.js.map +0 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +0 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/hurst_analyzer.d.ts.map +0 -1
- package/dist/analysis/trend_detection/hurst_analyzer.js.map +0 -1
- package/dist/analysis/trend_detection/kalman_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/kalman_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts.map +0 -1
- package/dist/analysis/trend_detection/kalman_trend_analyzer.js.map +0 -1
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts.map +0 -1
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.js.map +0 -1
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts.map +0 -1
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.js.map +0 -1
- package/dist/analysis/trend_detection/regime_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/regime_chart_generator.js.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts +0 -2
- package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_trend.js +0 -128
- package/dist/analysis/trend_detection/tests/test_kalman_trend.js.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts +0 -2
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts.map +0 -1
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js +0 -37
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js.map +0 -1
- package/dist/analysis/trend_detection/volatility_chart_generator.d.ts.map +0 -1
- package/dist/analysis/trend_detection/volatility_chart_generator.js.map +0 -1
- package/dist/bot.d.ts.map +0 -1
- package/dist/bot.js.map +0 -1
- package/dist/credential-daemon.d.ts.map +0 -1
- package/dist/credential-daemon.js.map +0 -1
- package/dist/dexbot.d.ts.map +0 -1
- package/dist/dexbot.js.map +0 -1
- package/dist/market_adapter/ama_signal_runner.d.ts.map +0 -1
- package/dist/market_adapter/ama_signal_runner.js.map +0 -1
- package/dist/market_adapter/candle_utils.d.ts.map +0 -1
- package/dist/market_adapter/candle_utils.js.map +0 -1
- package/dist/market_adapter/core/asymmetric_bounds.d.ts.map +0 -1
- package/dist/market_adapter/core/asymmetric_bounds.js.map +0 -1
- package/dist/market_adapter/core/config_normalizers.d.ts.map +0 -1
- package/dist/market_adapter/core/config_normalizers.js.map +0 -1
- package/dist/market_adapter/core/kibana_candles.d.ts.map +0 -1
- package/dist/market_adapter/core/kibana_candles.js.map +0 -1
- package/dist/market_adapter/core/kibana_client.d.ts.map +0 -1
- package/dist/market_adapter/core/kibana_client.js.map +0 -1
- package/dist/market_adapter/core/kibana_market_candles.d.ts.map +0 -1
- package/dist/market_adapter/core/kibana_market_candles.js.map +0 -1
- package/dist/market_adapter/core/market_adapter_service.d.ts.map +0 -1
- package/dist/market_adapter/core/market_adapter_service.js.map +0 -1
- package/dist/market_adapter/core/signals/hurst_analyzer.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/hurst_analyzer.js.map +0 -1
- package/dist/market_adapter/core/signals/kalman_trend_analyzer.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/kalman_trend_analyzer.js.map +0 -1
- package/dist/market_adapter/core/signals/kalman_velocity_smoothing.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/kalman_velocity_smoothing.js.map +0 -1
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts.map +0 -1
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js.map +0 -1
- package/dist/market_adapter/core/strategies/ama.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/ama.js.map +0 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.js.map +0 -1
- package/dist/market_adapter/core/strategies/atr/calculator.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/atr/calculator.js.map +0 -1
- package/dist/market_adapter/core/strategies/collateral_manager.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/collateral_manager.js.map +0 -1
- package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/dynamic_weight_series.js.map +0 -1
- package/dist/market_adapter/core/strategies/regime_gate.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/regime_gate.js.map +0 -1
- package/dist/market_adapter/core/strategies/regime_interp.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/regime_interp.js.map +0 -1
- package/dist/market_adapter/core/strategies/volatility_shift.d.ts.map +0 -1
- package/dist/market_adapter/core/strategies/volatility_shift.js.map +0 -1
- package/dist/market_adapter/inputs/fetch_book_data.d.ts.map +0 -1
- package/dist/market_adapter/inputs/fetch_book_data.js.map +0 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.d.ts.map +0 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +0 -1
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +0 -1
- package/dist/market_adapter/inputs/fetch_lp_data.js.map +0 -1
- package/dist/market_adapter/inputs/kibana_feed_source.d.ts.map +0 -1
- package/dist/market_adapter/inputs/kibana_feed_source.js.map +0 -1
- package/dist/market_adapter/inputs/kibana_source.d.ts.map +0 -1
- package/dist/market_adapter/inputs/kibana_source.js.map +0 -1
- package/dist/market_adapter/inputs/window_cache.d.ts.map +0 -1
- package/dist/market_adapter/inputs/window_cache.js.map +0 -1
- package/dist/market_adapter/interval_utils.d.ts.map +0 -1
- package/dist/market_adapter/interval_utils.js.map +0 -1
- package/dist/market_adapter/log_format.d.ts.map +0 -1
- package/dist/market_adapter/log_format.js.map +0 -1
- package/dist/market_adapter/lp_chart_core.d.ts.map +0 -1
- package/dist/market_adapter/lp_chart_core.js.map +0 -1
- package/dist/market_adapter/lp_chart_runner.d.ts.map +0 -1
- package/dist/market_adapter/lp_chart_runner.js.map +0 -1
- package/dist/market_adapter/lp_chart_strategy_loader.d.ts.map +0 -1
- package/dist/market_adapter/lp_chart_strategy_loader.js.map +0 -1
- package/dist/market_adapter/market_adapter.d.ts.map +0 -1
- package/dist/market_adapter/market_adapter.js.map +0 -1
- package/dist/market_adapter/test_helpers.d.ts.map +0 -1
- package/dist/market_adapter/test_helpers.js.map +0 -1
- package/dist/market_adapter/utils/adapter_client.d.ts.map +0 -1
- package/dist/market_adapter/utils/adapter_client.js.map +0 -1
- package/dist/market_adapter/utils/atomic_write.d.ts.map +0 -1
- package/dist/market_adapter/utils/atomic_write.js.map +0 -1
- package/dist/market_adapter/utils/chain.d.ts.map +0 -1
- package/dist/market_adapter/utils/chain.js.map +0 -1
- package/dist/market_adapter/utils/data_discovery.d.ts.map +0 -1
- package/dist/market_adapter/utils/data_discovery.js.map +0 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts.map +0 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.js.map +0 -1
- package/dist/market_adapter/utils/file_lock.d.ts.map +0 -1
- package/dist/market_adapter/utils/file_lock.js.map +0 -1
- package/dist/market_adapter/utils/native_history.d.ts.map +0 -1
- package/dist/market_adapter/utils/native_history.js.map +0 -1
- package/dist/modules/account_bots.d.ts.map +0 -1
- package/dist/modules/account_bots.js.map +0 -1
- package/dist/modules/account_orders.d.ts.map +0 -1
- package/dist/modules/account_orders.js.map +0 -1
- package/dist/modules/authority_resolver.d.ts.map +0 -1
- package/dist/modules/authority_resolver.js.map +0 -1
- package/dist/modules/bitshares-native/chain_client.d.ts.map +0 -1
- package/dist/modules/bitshares-native/chain_client.js.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.browser.js.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.d.ts.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc.js.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts.map +0 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.js.map +0 -1
- package/dist/modules/bitshares-native/index.d.ts.map +0 -1
- package/dist/modules/bitshares-native/index.js.map +0 -1
- package/dist/modules/bitshares-native/lru_cache.d.ts.map +0 -1
- package/dist/modules/bitshares-native/lru_cache.js.map +0 -1
- package/dist/modules/bitshares-native/resolvers.d.ts.map +0 -1
- package/dist/modules/bitshares-native/resolvers.js.map +0 -1
- package/dist/modules/bitshares-native/serial/chain_constants.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/chain_constants.js.map +0 -1
- package/dist/modules/bitshares-native/serial/index.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/index.js.map +0 -1
- package/dist/modules/bitshares-native/serial/operations.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/operations.js.map +0 -1
- package/dist/modules/bitshares-native/serial/serializer.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/serializer.js.map +0 -1
- package/dist/modules/bitshares-native/serial/types.d.ts.map +0 -1
- package/dist/modules/bitshares-native/serial/types.js.map +0 -1
- package/dist/modules/bitshares-native/signing_client.d.ts.map +0 -1
- package/dist/modules/bitshares-native/signing_client.js.map +0 -1
- package/dist/modules/bitshares-native/subscriptions.d.ts.map +0 -1
- package/dist/modules/bitshares-native/subscriptions.js.map +0 -1
- package/dist/modules/bitshares-native/transport.d.ts.map +0 -1
- package/dist/modules/bitshares-native/transport.js.map +0 -1
- package/dist/modules/bitshares-native/tx/builder.d.ts.map +0 -1
- package/dist/modules/bitshares-native/tx/builder.js.map +0 -1
- package/dist/modules/bitshares-native/tx/tx_cache.d.ts.map +0 -1
- package/dist/modules/bitshares-native/tx/tx_cache.js.map +0 -1
- package/dist/modules/bitshares_client.d.ts.map +0 -1
- package/dist/modules/bitshares_client.js.map +0 -1
- package/dist/modules/bot_defaults.d.ts.map +0 -1
- package/dist/modules/bot_defaults.js.map +0 -1
- package/dist/modules/bot_settings.d.ts.map +0 -1
- package/dist/modules/bot_settings.js.map +0 -1
- package/dist/modules/bots_file_lock.d.ts.map +0 -1
- package/dist/modules/bots_file_lock.js.map +0 -1
- package/dist/modules/broadcast_failure.d.ts.map +0 -1
- package/dist/modules/broadcast_failure.js.map +0 -1
- package/dist/modules/chain_keys.d.ts.map +0 -1
- package/dist/modules/chain_keys.js.map +0 -1
- package/dist/modules/chain_orders.d.ts.map +0 -1
- package/dist/modules/chain_orders.js.map +0 -1
- package/dist/modules/cli_colors.d.ts.map +0 -1
- package/dist/modules/cli_colors.js.map +0 -1
- package/dist/modules/cli_start_onboarding.d.ts.map +0 -1
- package/dist/modules/cli_start_onboarding.js.map +0 -1
- package/dist/modules/cli_start_output.d.ts.map +0 -1
- package/dist/modules/cli_start_output.js.map +0 -1
- package/dist/modules/config.d.ts.map +0 -1
- package/dist/modules/config.js.map +0 -1
- package/dist/modules/constants.d.ts.map +0 -1
- package/dist/modules/constants.js.map +0 -1
- package/dist/modules/cr_planner.d.ts.map +0 -1
- package/dist/modules/cr_planner.js.map +0 -1
- package/dist/modules/credential_policy.d.ts.map +0 -1
- package/dist/modules/credential_policy.js.map +0 -1
- package/dist/modules/credential_runtime.d.ts.map +0 -1
- package/dist/modules/credential_runtime.js.map +0 -1
- package/dist/modules/credential_session_cache.d.ts.map +0 -1
- package/dist/modules/credential_session_cache.js.map +0 -1
- package/dist/modules/credit_pricing.d.ts.map +0 -1
- package/dist/modules/credit_pricing.js.map +0 -1
- package/dist/modules/credit_runtime.d.ts.map +0 -1
- package/dist/modules/credit_runtime.js.map +0 -1
- package/dist/modules/crypto/browser_provider.d.ts.map +0 -1
- package/dist/modules/crypto/browser_provider.js.map +0 -1
- package/dist/modules/crypto/index.d.ts.map +0 -1
- package/dist/modules/crypto/index.js.map +0 -1
- package/dist/modules/crypto/node_provider.d.ts.map +0 -1
- package/dist/modules/crypto/node_provider.js.map +0 -1
- package/dist/modules/crypto/provider.d.ts.map +0 -1
- package/dist/modules/crypto/provider.js.map +0 -1
- package/dist/modules/crypto/pure_ripemd160.d.ts.map +0 -1
- package/dist/modules/crypto/pure_ripemd160.js.map +0 -1
- package/dist/modules/crypto/pure_scrypt.d.ts.map +0 -1
- package/dist/modules/crypto/pure_scrypt.js.map +0 -1
- package/dist/modules/crypto/pure_secp256k1.d.ts.map +0 -1
- package/dist/modules/crypto/pure_secp256k1.js.map +0 -1
- package/dist/modules/crypto/sync.d.ts.map +0 -1
- package/dist/modules/crypto/sync.js.map +0 -1
- package/dist/modules/daemon_node_health.d.ts.map +0 -1
- package/dist/modules/daemon_node_health.js.map +0 -1
- package/dist/modules/dexbot_class.d.ts.map +0 -1
- package/dist/modules/dexbot_class.js.map +0 -1
- package/dist/modules/dexbot_cow_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_cow_runtime.js.map +0 -1
- package/dist/modules/dexbot_credential_client.d.ts.map +0 -1
- package/dist/modules/dexbot_credential_client.js.map +0 -1
- package/dist/modules/dexbot_fill_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_fill_runtime.js.map +0 -1
- package/dist/modules/dexbot_maintenance_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_maintenance_runtime.js.map +0 -1
- package/dist/modules/dexbot_startup_runtime.d.ts.map +0 -1
- package/dist/modules/dexbot_startup_runtime.js.map +0 -1
- package/dist/modules/dexbot_state_recovery.d.ts.map +0 -1
- package/dist/modules/dexbot_state_recovery.js.map +0 -1
- package/dist/modules/env.d.ts.map +0 -1
- package/dist/modules/env.js.map +0 -1
- package/dist/modules/fund_registry.d.ts.map +0 -1
- package/dist/modules/fund_registry.js.map +0 -1
- package/dist/modules/general_settings.d.ts.map +0 -1
- package/dist/modules/general_settings.js.map +0 -1
- package/dist/modules/graceful_shutdown.d.ts.map +0 -1
- package/dist/modules/graceful_shutdown.js.map +0 -1
- package/dist/modules/grid_price_source.d.ts.map +0 -1
- package/dist/modules/grid_price_source.js.map +0 -1
- package/dist/modules/key_store.d.ts.map +0 -1
- package/dist/modules/key_store.js.map +0 -1
- package/dist/modules/launcher/adapter_requirement.d.ts.map +0 -1
- package/dist/modules/launcher/adapter_requirement.js.map +0 -1
- package/dist/modules/launcher/bot_supervisor.d.ts.map +0 -1
- package/dist/modules/launcher/bot_supervisor.js.map +0 -1
- package/dist/modules/launcher/child_env.d.ts.map +0 -1
- package/dist/modules/launcher/child_env.js.map +0 -1
- package/dist/modules/launcher/credential_bootstrap.d.ts.map +0 -1
- package/dist/modules/launcher/credential_bootstrap.js.map +0 -1
- package/dist/modules/launcher/credential_daemon.d.ts.map +0 -1
- package/dist/modules/launcher/credential_daemon.js.map +0 -1
- package/dist/modules/launcher/credential_secret.d.ts.map +0 -1
- package/dist/modules/launcher/credential_secret.js.map +0 -1
- package/dist/modules/launcher/foreign_cred_daemon.d.ts.map +0 -1
- package/dist/modules/launcher/foreign_cred_daemon.js.map +0 -1
- package/dist/modules/launcher/headless_password.d.ts.map +0 -1
- package/dist/modules/launcher/headless_password.js.map +0 -1
- package/dist/modules/launcher/launch_modes.d.ts.map +0 -1
- package/dist/modules/launcher/launch_modes.js.map +0 -1
- package/dist/modules/launcher/market_adapter_runtime.d.ts.map +0 -1
- package/dist/modules/launcher/market_adapter_runtime.js.map +0 -1
- package/dist/modules/launcher/market_adapter_watchdog.d.ts.map +0 -1
- package/dist/modules/launcher/market_adapter_watchdog.js.map +0 -1
- package/dist/modules/launcher/monolithic_runtime.d.ts.map +0 -1
- package/dist/modules/launcher/monolithic_runtime.js.map +0 -1
- package/dist/modules/launcher/runtime_entry.d.ts.map +0 -1
- package/dist/modules/launcher/runtime_entry.js.map +0 -1
- package/dist/modules/launcher/status_reporting.d.ts.map +0 -1
- package/dist/modules/launcher/status_reporting.js.map +0 -1
- package/dist/modules/launcher/supervisor_control.d.ts.map +0 -1
- package/dist/modules/launcher/supervisor_control.js.map +0 -1
- package/dist/modules/market_adapter_whitelist.d.ts.map +0 -1
- package/dist/modules/market_adapter_whitelist.js.map +0 -1
- package/dist/modules/node_connect_policy.d.ts.map +0 -1
- package/dist/modules/node_connect_policy.js.map +0 -1
- package/dist/modules/node_failure_ledger.d.ts.map +0 -1
- package/dist/modules/node_failure_ledger.js.map +0 -1
- package/dist/modules/node_health_cache.d.ts.map +0 -1
- package/dist/modules/node_health_cache.js.map +0 -1
- package/dist/modules/node_manager.d.ts.map +0 -1
- package/dist/modules/node_manager.js.map +0 -1
- package/dist/modules/order/accounting.d.ts.map +0 -1
- package/dist/modules/order/accounting.js.map +0 -1
- package/dist/modules/order/async_lock.d.ts.map +0 -1
- package/dist/modules/order/async_lock.js.map +0 -1
- package/dist/modules/order/export.d.ts.map +0 -1
- package/dist/modules/order/export.js.map +0 -1
- package/dist/modules/order/format.d.ts.map +0 -1
- package/dist/modules/order/format.js.map +0 -1
- package/dist/modules/order/grid.d.ts.map +0 -1
- package/dist/modules/order/grid.js.map +0 -1
- package/dist/modules/order/grid_reconcile.d.ts.map +0 -1
- package/dist/modules/order/grid_reconcile.js.map +0 -1
- package/dist/modules/order/grid_reconcile_internal.d.ts.map +0 -1
- package/dist/modules/order/grid_reconcile_internal.js.map +0 -1
- package/dist/modules/order/index.d.ts.map +0 -1
- package/dist/modules/order/index.js.map +0 -1
- package/dist/modules/order/logger.d.ts.map +0 -1
- package/dist/modules/order/logger.js.map +0 -1
- package/dist/modules/order/logger_state.d.ts.map +0 -1
- package/dist/modules/order/logger_state.js.map +0 -1
- package/dist/modules/order/manager.d.ts.map +0 -1
- package/dist/modules/order/manager.js.map +0 -1
- package/dist/modules/order/processed_fill_store.d.ts.map +0 -1
- package/dist/modules/order/processed_fill_store.js.map +0 -1
- package/dist/modules/order/strategy.d.ts.map +0 -1
- package/dist/modules/order/strategy.js.map +0 -1
- package/dist/modules/order/sync_engine.d.ts.map +0 -1
- package/dist/modules/order/sync_engine.js.map +0 -1
- package/dist/modules/order/utils/math.d.ts.map +0 -1
- package/dist/modules/order/utils/math.js.map +0 -1
- package/dist/modules/order/utils/order.d.ts.map +0 -1
- package/dist/modules/order/utils/order.js.map +0 -1
- package/dist/modules/order/utils/slot.d.ts.map +0 -1
- package/dist/modules/order/utils/slot.js.map +0 -1
- package/dist/modules/order/utils/system.d.ts.map +0 -1
- package/dist/modules/order/utils/system.js.map +0 -1
- package/dist/modules/order/utils/timeout.d.ts.map +0 -1
- package/dist/modules/order/utils/timeout.js.map +0 -1
- package/dist/modules/order/utils/validate.d.ts.map +0 -1
- package/dist/modules/order/utils/validate.js.map +0 -1
- package/dist/modules/order/utils/withPoolRef.d.ts.map +0 -1
- package/dist/modules/order/utils/withPoolRef.js.map +0 -1
- package/dist/modules/order/working_grid.d.ts.map +0 -1
- package/dist/modules/order/working_grid.js.map +0 -1
- package/dist/modules/path_api.d.ts.map +0 -1
- package/dist/modules/path_api.js.map +0 -1
- package/dist/modules/paths.d.ts.map +0 -1
- package/dist/modules/paths.js.map +0 -1
- package/dist/modules/process_discovery.d.ts.map +0 -1
- package/dist/modules/process_discovery.js.map +0 -1
- package/dist/modules/runtime.d.ts.map +0 -1
- package/dist/modules/runtime.js.map +0 -1
- package/dist/modules/runtime_settings.d.ts.map +0 -1
- package/dist/modules/runtime_settings.js.map +0 -1
- package/dist/modules/settings_merge.d.ts.map +0 -1
- package/dist/modules/settings_merge.js.map +0 -1
- package/dist/modules/socket_json_client.d.ts.map +0 -1
- package/dist/modules/socket_json_client.js.map +0 -1
- package/dist/modules/storage/browser_adapter.d.ts.map +0 -1
- package/dist/modules/storage/browser_adapter.js.map +0 -1
- package/dist/modules/storage/index.d.ts.map +0 -1
- package/dist/modules/storage/index.js.map +0 -1
- package/dist/modules/storage/node_adapter.d.ts.map +0 -1
- package/dist/modules/storage/node_adapter.js.map +0 -1
- package/dist/modules/storage/types.d.ts.map +0 -1
- package/dist/modules/storage/types.js.map +0 -1
- package/dist/modules/types.d.ts.map +0 -1
- package/dist/modules/types.js.map +0 -1
- package/dist/modules/utils/base58check.d.ts.map +0 -1
- package/dist/modules/utils/base58check.js.map +0 -1
- package/dist/modules/utils/build_dir.d.ts.map +0 -1
- package/dist/modules/utils/build_dir.js.map +0 -1
- package/dist/modules/utils/chain_logs.d.ts.map +0 -1
- package/dist/modules/utils/chain_logs.js.map +0 -1
- package/dist/modules/utils/errors.d.ts.map +0 -1
- package/dist/modules/utils/errors.js.map +0 -1
- package/dist/modules/utils/sanitize_key.d.ts.map +0 -1
- package/dist/modules/utils/sanitize_key.js.map +0 -1
- package/dist/modules/utils/text_width.d.ts.map +0 -1
- package/dist/modules/utils/text_width.js.map +0 -1
- package/dist/modules/validate_profiles.d.ts.map +0 -1
- package/dist/modules/validate_profiles.js.map +0 -1
- package/dist/pm2.d.ts.map +0 -1
- package/dist/pm2.js.map +0 -1
- package/dist/scripts/analyze-credit.d.ts.map +0 -1
- package/dist/scripts/analyze-credit.js.map +0 -1
- package/dist/scripts/analyze-git.d.ts.map +0 -1
- package/dist/scripts/analyze-git.js.map +0 -1
- package/dist/scripts/analyze-orders.d.ts.map +0 -1
- package/dist/scripts/analyze-orders.js.map +0 -1
- package/dist/scripts/chart_command.d.ts.map +0 -1
- package/dist/scripts/chart_command.js.map +0 -1
- package/dist/scripts/diagnose-kibana-candles.d.ts.map +0 -1
- package/dist/scripts/diagnose-kibana-candles.js.map +0 -1
- package/dist/scripts/diagnose-pool-history.d.ts.map +0 -1
- package/dist/scripts/diagnose-pool-history.js.map +0 -1
- package/dist/scripts/divergence-calc.d.ts.map +0 -1
- package/dist/scripts/divergence-calc.js.map +0 -1
- package/dist/scripts/dw.d.ts.map +0 -1
- package/dist/scripts/dw.js.map +0 -1
- package/dist/scripts/generate_lp_chart.d.ts.map +0 -1
- package/dist/scripts/generate_lp_chart.js.map +0 -1
- package/dist/scripts/generate_mainnet_corpus_report.d.ts.map +0 -1
- package/dist/scripts/generate_mainnet_corpus_report.js.map +0 -1
- package/dist/scripts/native_release_gates.d.ts.map +0 -1
- package/dist/scripts/native_release_gates.js.map +0 -1
- package/dist/scripts/print_grid.d.ts.map +0 -1
- package/dist/scripts/print_grid.js.map +0 -1
- package/dist/scripts/run-tests.d.ts.map +0 -1
- package/dist/scripts/run-tests.js.map +0 -1
- package/dist/scripts/runner.d.ts.map +0 -1
- package/dist/scripts/runner.js.map +0 -1
- package/dist/scripts/sync-version.d.ts.map +0 -1
- package/dist/scripts/sync-version.js.map +0 -1
- package/dist/scripts/test-credit-renewal.d.ts.map +0 -1
- package/dist/scripts/test-credit-renewal.js.map +0 -1
- package/dist/scripts/tv.d.ts.map +0 -1
- package/dist/scripts/tv.js.map +0 -1
- package/dist/scripts/update.d.ts.map +0 -1
- package/dist/scripts/update.js.map +0 -1
- package/dist/scripts/update_dist_freshness.d.ts.map +0 -1
- package/dist/scripts/update_dist_freshness.js.map +0 -1
- package/dist/scripts/validate_bots.d.ts.map +0 -1
- package/dist/scripts/validate_bots.js.map +0 -1
- package/dist/scripts/verify-browser-bundle.d.ts.map +0 -1
- package/dist/scripts/verify-browser-bundle.js.map +0 -1
- package/dist/unlock.d.ts.map +0 -1
- package/dist/unlock.js.map +0 -1
|
@@ -1,470 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* REGIME WINDOW OPTIMIZER
|
|
6
|
-
*
|
|
7
|
-
* Grid-searches optimal Hurst and Permutation Entropy window sizes to maximize
|
|
8
|
-
* regime quality — a composite score of stability, directional accuracy, and
|
|
9
|
-
* information content.
|
|
10
|
-
*
|
|
11
|
-
* Scoring:
|
|
12
|
-
* - regimeStability: mean duration (bars) before regime switches
|
|
13
|
-
* - entropyDefect: penalty for being stuck in the "random" band (H 0.45–0.55)
|
|
14
|
-
*
|
|
15
|
-
* Usage:
|
|
16
|
-
* node dist/analysis/analyze_regime_windows.js \
|
|
17
|
-
* --source json \
|
|
18
|
-
* --file market_adapter/data/lp/<path>/<to>/<lp-candles>.json
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
import path from 'node:path';
|
|
22
|
-
import { HurstAnalyzer, classifyHurst } from './trend_detection/hurst_analyzer.js';
|
|
23
|
-
import { PermutationEntropyAnalyzer } from './trend_detection/permutation_entropy_analyzer.js';
|
|
24
|
-
import { MARKET_ADAPTER } from '../modules/constants.js';
|
|
25
|
-
import { PATHS } from '../modules/paths.js';
|
|
26
|
-
import { writeChartFile } from './chart_utils.js';
|
|
27
|
-
import { getCandleClose } from './math_utils.js';
|
|
28
|
-
import { roundTo } from '../modules/order/utils/math.js';
|
|
29
|
-
import { resolveSource, listAvailableBots, type SourceConfig } from './resolve_source.js';
|
|
30
|
-
|
|
31
|
-
const HURST_CONFIG = MARKET_ADAPTER.HURST_CONFIG;
|
|
32
|
-
const PE_CONFIG = MARKET_ADAPTER.PE_CONFIG;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const HURST_CENTER = HURST_CONFIG.window;
|
|
36
|
-
const PE_CENTER = PE_CONFIG.window;
|
|
37
|
-
const RANGE_FACTOR = 2;
|
|
38
|
-
const N_POINTS = 20;
|
|
39
|
-
|
|
40
|
-
function geoRange(center: number, factor: number, n: number) {
|
|
41
|
-
const lo = center / factor;
|
|
42
|
-
const hi = center * factor;
|
|
43
|
-
const r = Math.pow(hi / lo, 1 / (n - 1));
|
|
44
|
-
const vals: number[] = [];
|
|
45
|
-
for (let i = 0; i < n; i++) vals.push(lo * Math.pow(r, i));
|
|
46
|
-
return vals;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const HURST_WINDOWS = geoRange(HURST_CENTER, RANGE_FACTOR, N_POINTS);
|
|
50
|
-
const PE_WINDOWS = geoRange(PE_CENTER, RANGE_FACTOR, N_POINTS);
|
|
51
|
-
const HURST_SCALES = HURST_CONFIG.scales;
|
|
52
|
-
const PE_M = PE_CONFIG.m;
|
|
53
|
-
const PE_DELAY = PE_CONFIG.delay;
|
|
54
|
-
|
|
55
|
-
function parseArgs() {
|
|
56
|
-
const args = process.argv.slice(2);
|
|
57
|
-
const config: {
|
|
58
|
-
source: { type: string; config: SourceConfig };
|
|
59
|
-
chartFile: string;
|
|
60
|
-
quiet: boolean;
|
|
61
|
-
listBots: boolean;
|
|
62
|
-
} = {
|
|
63
|
-
source: { type: 'market_adapter', config: { botKey: '' } },
|
|
64
|
-
chartFile: path.join(PATHS.ANALYSIS.CHARTS_DIR, 'regime_windows_heatmap.html'),
|
|
65
|
-
quiet: false,
|
|
66
|
-
listBots: false,
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
for (let i = 0; i < args.length; i++) {
|
|
70
|
-
const arg = args[i];
|
|
71
|
-
if (arg === '--source') config.source.type = args[++i];
|
|
72
|
-
else if (arg === '--bot-key') config.source.config.botKey = args[++i];
|
|
73
|
-
else if (arg === '--file') {
|
|
74
|
-
config.source.config.filePath = args[++i];
|
|
75
|
-
config.source.type = 'json';
|
|
76
|
-
}
|
|
77
|
-
else if (arg === '--chart') config.chartFile = args[++i];
|
|
78
|
-
else if (arg === '--list-bots') config.listBots = true;
|
|
79
|
-
else if (arg === '--quiet') config.quiet = true;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return config;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// Signal-quality bands from MARKET_ADAPTER.PE_NODES (structured / mixed / noise).
|
|
86
|
-
const PE_STRUCTURED = MARKET_ADAPTER.PE_NODES[0];
|
|
87
|
-
const PE_NOISE = MARKET_ADAPTER.PE_NODES[MARKET_ADAPTER.PE_NODES.length - 1];
|
|
88
|
-
|
|
89
|
-
// Hurst band classification delegates to the production classifyHurst
|
|
90
|
-
// (market_adapter/core/signals/hurst_analyzer.ts) so boundary semantics
|
|
91
|
-
// (inclusive >=/<=) and zone width stay on one logic path.
|
|
92
|
-
function regimeBand(H: number | null): string {
|
|
93
|
-
if (H === null) return 'RANDOM';
|
|
94
|
-
return classifyHurst(H).regime;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function rankNormalize(arr: number[]) {
|
|
98
|
-
const sorted = arr.slice().sort((a: number, b: number) => a - b);
|
|
99
|
-
return arr.map((v: number) => {
|
|
100
|
-
const idx = sorted.findIndex((x: number) => x === v);
|
|
101
|
-
return idx / (sorted.length - 1);
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function scoreWindowPair(prices: number[], hurstWindow: number, peWindow: number) {
|
|
106
|
-
const n = prices.length;
|
|
107
|
-
|
|
108
|
-
const hurstAnalyzer = new HurstAnalyzer({ window: hurstWindow, scales: HURST_SCALES });
|
|
109
|
-
const peAnalyzer = new PermutationEntropyAnalyzer({ m: PE_M, delay: PE_DELAY, window: peWindow });
|
|
110
|
-
|
|
111
|
-
const hArr: (number | null)[] = [];
|
|
112
|
-
const pArr: (number | null)[] = [];
|
|
113
|
-
|
|
114
|
-
for (let i = 0; i < n; i++) {
|
|
115
|
-
const h = hurstAnalyzer.update(prices[i]);
|
|
116
|
-
const p = peAnalyzer.update(prices[i]);
|
|
117
|
-
hArr.push(h.isReady ? h.hurst : null);
|
|
118
|
-
pArr.push(p.isReady ? p.normalizedEntropy : null);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const firstReady = hArr.findIndex(v => v !== null);
|
|
122
|
-
if (firstReady < 0) return null;
|
|
123
|
-
|
|
124
|
-
// ── Regime sequences ──────────────────────────────────────────────────
|
|
125
|
-
// Pair H and PE strictly per bar: both analyzers become ready on different
|
|
126
|
-
// schedules (PE window vs Hurst window), so slicing from Hurst readiness
|
|
127
|
-
// and independently null-filtering PE would index-shift the pairing.
|
|
128
|
-
const hBands: string[] = [];
|
|
129
|
-
const pBands: string[] = [];
|
|
130
|
-
for (let i = 0; i < n; i++) {
|
|
131
|
-
if (hArr[i] === null || pArr[i] === null) continue;
|
|
132
|
-
hBands.push(regimeBand(hArr[i]));
|
|
133
|
-
pBands.push(pArr[i]! < PE_STRUCTURED ? 'STRUCTURED' : pArr[i]! > PE_NOISE ? 'NOISE' : 'MIXED');
|
|
134
|
-
}
|
|
135
|
-
const m = hBands.length;
|
|
136
|
-
if (m < 50) return null;
|
|
137
|
-
|
|
138
|
-
const combined = hBands.map((h, i) => `${h}|${pBands[i]}`);
|
|
139
|
-
|
|
140
|
-
// ── Stability: mean run-length of combined regime ───────────────────
|
|
141
|
-
let stabilitySum = 0, stabilityCount = 0;
|
|
142
|
-
let runLen = 1;
|
|
143
|
-
for (let i = 1; i < combined.length; i++) {
|
|
144
|
-
if (combined[i] === combined[i - 1]) {
|
|
145
|
-
runLen++;
|
|
146
|
-
} else {
|
|
147
|
-
stabilitySum += runLen;
|
|
148
|
-
stabilityCount++;
|
|
149
|
-
runLen = 1;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
stabilitySum += runLen;
|
|
153
|
-
stabilityCount++;
|
|
154
|
-
const meanStability = stabilitySum / stabilityCount;
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
// ── Entropy defect: how often stuck in random band ───────────────────
|
|
159
|
-
const randomCount = hBands.filter(b => b === 'RANDOM').length;
|
|
160
|
-
const entropyDefect = randomCount / m;
|
|
161
|
-
|
|
162
|
-
// ── Structured fraction: how often PE is structured ───────────────────
|
|
163
|
-
const structuredCount = pBands.filter(b => b === 'STRUCTURED').length;
|
|
164
|
-
const structuredFrac = structuredCount / m;
|
|
165
|
-
|
|
166
|
-
// ── Lag score: inverse window size — smaller windows respond faster ─────
|
|
167
|
-
const minH = HURST_WINDOWS[0];
|
|
168
|
-
const minP = PE_WINDOWS[0];
|
|
169
|
-
const lagScore = 0.5 * (minH / hurstWindow) + 0.5 * (minP / peWindow);
|
|
170
|
-
|
|
171
|
-
return {
|
|
172
|
-
hurstWindow,
|
|
173
|
-
peWindow,
|
|
174
|
-
meanStability,
|
|
175
|
-
entropyDefect,
|
|
176
|
-
structuredFrac,
|
|
177
|
-
lagScore,
|
|
178
|
-
_stabilityRaw: meanStability,
|
|
179
|
-
_entropyRaw: 1 - entropyDefect,
|
|
180
|
-
_structuredRaw: structuredFrac,
|
|
181
|
-
_lagRaw: lagScore,
|
|
182
|
-
n: m,
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
function computeComposite(allResults: any[]) {
|
|
187
|
-
const n = allResults.length;
|
|
188
|
-
if (n === 0) return allResults;
|
|
189
|
-
|
|
190
|
-
const stabilityVals = allResults.map((r: any) => r._stabilityRaw);
|
|
191
|
-
const entropyVals = allResults.map((r: any) => r._entropyRaw);
|
|
192
|
-
const structuredVals = allResults.map((r: any) => r._structuredRaw);
|
|
193
|
-
const lagVals = allResults.map((r: any) => r._lagRaw);
|
|
194
|
-
|
|
195
|
-
const [rnStability, rnEntropy, rnStructured, rnLag] =
|
|
196
|
-
[stabilityVals, entropyVals, structuredVals, lagVals].map(rankNormalize);
|
|
197
|
-
|
|
198
|
-
// Weights: lag=30%, stability=30%, entropy=25%, structured=15%
|
|
199
|
-
const W = { lag: 0.30, stability: 0.30, entropy: 0.25, structured: 0.15 };
|
|
200
|
-
|
|
201
|
-
return allResults.map((r: any, i: number) => {
|
|
202
|
-
const composite =
|
|
203
|
-
W.lag * rnLag[i] +
|
|
204
|
-
W.stability * rnStability[i] +
|
|
205
|
-
W.entropy * rnEntropy[i] +
|
|
206
|
-
W.structured * rnStructured[i];
|
|
207
|
-
|
|
208
|
-
return {
|
|
209
|
-
...r,
|
|
210
|
-
stabilityScore: roundTo(rnStability[i], 1000),
|
|
211
|
-
entropyScore: roundTo(rnEntropy[i], 1000),
|
|
212
|
-
structuredScore: roundTo(rnStructured[i], 1000),
|
|
213
|
-
lagScore: roundTo(rnLag[i], 1000),
|
|
214
|
-
composite: roundTo(composite, 1000),
|
|
215
|
-
};
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
function generateHeatmapHTML(results: any[], hurstVals: number[], peVals: number[]) {
|
|
220
|
-
const maxComposite = Math.max(...results.map((r: any) => r.composite));
|
|
221
|
-
const minComposite = Math.min(...results.map((r: any) => r.composite));
|
|
222
|
-
const range = maxComposite - minComposite || 1;
|
|
223
|
-
|
|
224
|
-
const grid: Record<string, any> = {};
|
|
225
|
-
results.forEach((r: any) => { grid[`${r.hurstWindow},${r.peWindow}`] = r; });
|
|
226
|
-
|
|
227
|
-
const defaultH = HURST_CENTER;
|
|
228
|
-
const defaultP = PE_CENTER;
|
|
229
|
-
const geoRatio = Math.pow(RANGE_FACTOR, 1 / (N_POINTS - 1));
|
|
230
|
-
const epsH = Math.abs(HURST_WINDOWS[HURST_WINDOWS.length - 1] - HURST_WINDOWS[0]) / (N_POINTS - 1) * 0.6;
|
|
231
|
-
const epsP = Math.abs(PE_WINDOWS[PE_WINDOWS.length - 1] - PE_WINDOWS[0]) / (N_POINTS - 1) * 0.6;
|
|
232
|
-
|
|
233
|
-
const best = results.reduce((a: any, b: any) => a.composite > b.composite ? a : b);
|
|
234
|
-
const top10 = results.slice().sort((a: any, b: any) => b.composite - a.composite).slice(0, 10);
|
|
235
|
-
|
|
236
|
-
const currentResult = results.find((r: any) =>
|
|
237
|
-
Math.abs(r.hurstWindow - defaultH) < epsH && Math.abs(r.peWindow - defaultP) < epsP
|
|
238
|
-
);
|
|
239
|
-
|
|
240
|
-
function cell(r: any, h: number, p: number) {
|
|
241
|
-
if (!r) return '<td class="empty"></td>';
|
|
242
|
-
const norm = (r.composite - minComposite) / range; // 0 = worst, 1 = best
|
|
243
|
-
|
|
244
|
-
// Color ramp: red (worst) → orange → yellow → green (best)
|
|
245
|
-
// norm 0.0 → rgb(248,81,73) red
|
|
246
|
-
// norm 0.5 → rgb(240,140,0) orange
|
|
247
|
-
// norm 1.0 → rgb(46,160,67) green
|
|
248
|
-
const rr = norm < 0.5
|
|
249
|
-
? Math.round(248 - (248 - 240) * norm * 2)
|
|
250
|
-
: Math.round(240 - (240 - 46) * (norm - 0.5) * 2);
|
|
251
|
-
const rg = norm < 0.5
|
|
252
|
-
? Math.round(81 + (140 - 81) * norm * 2)
|
|
253
|
-
: Math.round(140 + (160 - 140) * (norm - 0.5) * 2);
|
|
254
|
-
const rb = norm < 0.5
|
|
255
|
-
? Math.round(73 + (0 - 73) * norm * 2)
|
|
256
|
-
: Math.round(0 + (67 - 0) * (norm - 0.5) * 2);
|
|
257
|
-
const bg = `rgb(${rr},${rg},${rb})`;
|
|
258
|
-
|
|
259
|
-
const isCenter = Math.abs(h - defaultH) < epsH && Math.abs(p - defaultP) < epsP;
|
|
260
|
-
const isBest = r === best;
|
|
261
|
-
let border = isBest ? '2px solid #fff' : isCenter ? '2px solid #58a6ff' : '1px solid #1c2128';
|
|
262
|
-
|
|
263
|
-
return `<td class="cell" style="background:${bg};${border}"
|
|
264
|
-
title="H=${Math.round(h)} PE=${Math.round(p)}
|
|
265
|
-
composite=${r.composite} (${(norm * 100).toFixed(1)}% of range)
|
|
266
|
-
stability=${r.meanStability.toFixed(1)}b lag=${r.lagScore.toFixed(3)}
|
|
267
|
-
noise=${(r.entropyDefect*100).toFixed(1)}%">
|
|
268
|
-
<span class="val" style="color:${norm > 0.7 ? '#fff' : norm > 0.35 ? '#0b0e14' : 'rgba(255,255,255,0.75)'}">${r.composite.toFixed(3)}</span>
|
|
269
|
-
</td>`;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
// PE on Y axis (rows), Hurst on X axis (columns)
|
|
273
|
-
const colHeaders = hurstVals.map((h: number) => `<th>${Math.round(h)}</th>`).join('');
|
|
274
|
-
const rows = peVals.map((p: number) =>
|
|
275
|
-
`<tr><td class="row-label">${Math.round(p)}</td>${hurstVals.map((h: number) => cell(grid[`${h},${p}`], h, p)).join('')}</tr>`
|
|
276
|
-
).join('\n');
|
|
277
|
-
|
|
278
|
-
const top10Bars = top10.map((r: any, i: number) => {
|
|
279
|
-
const isCenter = Math.abs(r.hurstWindow - defaultH) < epsH && Math.abs(r.peWindow - defaultP) < epsP;
|
|
280
|
-
const isBest = r === best;
|
|
281
|
-
const barNorm = (r.composite - minComposite) / range;
|
|
282
|
-
const rr = barNorm < 0.5
|
|
283
|
-
? Math.round(248 - (248 - 240) * barNorm * 2)
|
|
284
|
-
: Math.round(240 - (240 - 46) * (barNorm - 0.5) * 2);
|
|
285
|
-
const rg = barNorm < 0.5
|
|
286
|
-
? Math.round(81 + (140 - 81) * barNorm * 2)
|
|
287
|
-
: Math.round(140 + (160 - 140) * (barNorm - 0.5) * 2);
|
|
288
|
-
const rb = barNorm < 0.5
|
|
289
|
-
? Math.round(73 + (0 - 73) * barNorm * 2)
|
|
290
|
-
: Math.round(0 + (67 - 0) * (barNorm - 0.5) * 2);
|
|
291
|
-
const barColor = `rgb(${rr},${rg},${rb})`;
|
|
292
|
-
return `<div class="bar-row" title="H=${Math.round(r.hurstWindow)} PE=${Math.round(r.peWindow)} stability=${r.meanStability.toFixed(1)}b lag=${r.lagScore.toFixed(3)}">
|
|
293
|
-
<span class="bar-label" style="color:${isBest ? '#3fb950' : isCenter ? '#58a6ff' : '#8b949e'}">#${i+1} H=${Math.round(r.hurstWindow)} PE=${Math.round(r.peWindow)}</span>
|
|
294
|
-
<div class="bar-track"><div class="bar-fill" style="width:${(barNorm * 100).toFixed(1)}%;background:${barColor}"></div></div>
|
|
295
|
-
<span class="bar-score" style="color:${barColor}">${r.composite.toFixed(3)}</span>
|
|
296
|
-
<span class="bar-meta">${r.meanStability.toFixed(1)}b lag=${r.lagScore.toFixed(2)} ${(r.entropyDefect*100).toFixed(0)}%noise</span>
|
|
297
|
-
</div>`;
|
|
298
|
-
}).join('\n');
|
|
299
|
-
|
|
300
|
-
return `<!DOCTYPE html>
|
|
301
|
-
<html lang="en">
|
|
302
|
-
<head>
|
|
303
|
-
<meta charset="UTF-8">
|
|
304
|
-
<title>Regime Window Optimization</title>
|
|
305
|
-
<style>
|
|
306
|
-
* { box-sizing: border-box; }
|
|
307
|
-
body { background: #0b0e14; color: #d1d5db; font-family: 'Segoe UI', sans-serif; margin: 0; padding: 20px; }
|
|
308
|
-
h1 { color: #fff; font-size: 16px; margin: 0 0 4px 0; }
|
|
309
|
-
.subtitle { color: #8b949e; font-size: 11px; margin: 0 0 12px 0; }
|
|
310
|
-
.topline { display: flex; gap: 32px; margin-bottom: 14px; font-size: 12px; }
|
|
311
|
-
.topline span { color: #8b949e; }
|
|
312
|
-
.topline .highlight { color: #3fb950; font-weight: bold; }
|
|
313
|
-
.topline .current { color: #58a6ff; }
|
|
314
|
-
.layout { display: flex; gap: 24px; align-items: flex-start; flex-wrap: wrap; }
|
|
315
|
-
.col-label { font-size: 11px; color: #8b949e; margin-bottom: 4px; }
|
|
316
|
-
table { border-collapse: collapse; }
|
|
317
|
-
th, td { padding: 0; text-align: center; }
|
|
318
|
-
th { color: #8b949e; font-size: 10px; font-weight: normal; height: 20px; line-height: 20px; }
|
|
319
|
-
td.cell { width: 36px; height: 26px; cursor: default; }
|
|
320
|
-
td.cell .val { display: block; font-size: 9px; font-weight: bold; line-height: 26px; }
|
|
321
|
-
td.row-label { color: #8b949e; font-size: 10px; text-align: right; padding-right: 8px; width: 40px; }
|
|
322
|
-
td.empty { background: #161b22; }
|
|
323
|
-
.legend { display: flex; gap: 10px; align-items: center; font-size: 10px; color: #8b949e; margin-top: 8px; }
|
|
324
|
-
.legend-bar { width: 100px; height: 6px; border-radius: 2px; background: linear-gradient(to right, #f85149, #f08c00, #3fb950); }
|
|
325
|
-
.section-title { color: #8b949e; font-size: 10px; text-transform: uppercase; letter-spacing: 1px; margin: 0 0 10px 0; border-bottom: 1px solid #30363d; padding-bottom: 4px; }
|
|
326
|
-
.top10-chart { display: flex; flex-direction: column; gap: 6px; min-width: 380px; }
|
|
327
|
-
.bar-row { display: flex; align-items: center; gap: 10px; }
|
|
328
|
-
.bar-label { font-size: 10px; color: #8b949e; min-width: 100px; text-align: right; font-family: monospace; }
|
|
329
|
-
.bar-track { flex: 1; height: 18px; background: #161b22; border-radius: 2px; overflow: hidden; }
|
|
330
|
-
.bar-fill { height: 100%; border-radius: 2px; transition: width 0.3s ease; }
|
|
331
|
-
.bar-score { font-size: 11px; font-weight: bold; min-width: 44px; text-align: right; font-family: monospace; }
|
|
332
|
-
.bar-meta { font-size: 9px; color: #555; min-width: 140px; }
|
|
333
|
-
.bottom-row { display: flex; gap: 32px; align-items: flex-start; flex-wrap: wrap; margin-top: 24px; }
|
|
334
|
-
.score-breakdown { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
|
|
335
|
-
.score-card { background: #161b22; border: 1px solid #30363d; border-radius: 6px; padding: 10px 14px; }
|
|
336
|
-
.score-card h3 { color: #8b949e; font-size: 9px; text-transform: uppercase; letter-spacing: 1px; margin: 0 0 4px 0; font-weight: normal; }
|
|
337
|
-
.score-card .value { font-size: 18px; font-weight: bold; color: #3fb950; }
|
|
338
|
-
.score-card .desc { font-size: 10px; color: #8b949e; margin-top: 2px; }
|
|
339
|
-
.params-table { font-size: 11px; color: #8b949e; }
|
|
340
|
-
.params-table td { padding: 3px 0; }
|
|
341
|
-
.params-table td:first-child { color: #555; padding-right: 16px; }
|
|
342
|
-
</style>
|
|
343
|
-
</head>
|
|
344
|
-
<body>
|
|
345
|
-
<h1>Regime Window Optimization</h1>
|
|
346
|
-
<p class="subtitle">
|
|
347
|
-
Composite = 0.30×lag + 0.30×stability + 0.25×entropy + 0.15×structured
|
|
348
|
-
· ${hurstVals.length}×${peVals.length} grid (${hurstVals.length * peVals.length} combos)
|
|
349
|
-
· ${results[0]?.n ?? 0} usable bars
|
|
350
|
-
</p>
|
|
351
|
-
|
|
352
|
-
<div class="topline">
|
|
353
|
-
<span>Best: <span class="highlight">H=${Math.round(best.hurstWindow)} PE=${Math.round(best.peWindow)}</span> score=${best.composite}</span>
|
|
354
|
-
<span>Current: <span class="current">H=${defaultH} PE=${defaultP}</span> score=${currentResult ? currentResult.composite : '—'}</span>
|
|
355
|
-
<span>Ratio: <span class="highlight">${(best.composite / (currentResult?.composite || 1)).toFixed(3)}</span></span>
|
|
356
|
-
<span>Δ: <span class="highlight">+${((best.composite - (currentResult?.composite || 0)) * 100).toFixed(1)}%</span></span>
|
|
357
|
-
</div>
|
|
358
|
-
|
|
359
|
-
<div class="layout">
|
|
360
|
-
<div>
|
|
361
|
-
<div class="col-label">Hurst window →</div>
|
|
362
|
-
<table class="heatmap">
|
|
363
|
-
<thead><tr><th></th>${colHeaders}</tr></thead>
|
|
364
|
-
<tbody>${rows}</tbody>
|
|
365
|
-
</table>
|
|
366
|
-
<div class="legend">
|
|
367
|
-
<span style="color:#f85149">bad</span>
|
|
368
|
-
<div class="legend-bar"></div>
|
|
369
|
-
<span style="color:#3fb950">good</span>
|
|
370
|
-
<span style="margin-left:12px;border-left:2px solid #58a6ff;padding-left:6px;">current</span>
|
|
371
|
-
<span style="border-left:2px solid #fff;padding-left:6px;">best</span>
|
|
372
|
-
</div>
|
|
373
|
-
</div>
|
|
374
|
-
|
|
375
|
-
<div>
|
|
376
|
-
<p class="section-title">Top 10 — Best combinations</p>
|
|
377
|
-
<div class="top10-chart">${top10Bars}</div>
|
|
378
|
-
</div>
|
|
379
|
-
</div>
|
|
380
|
-
|
|
381
|
-
<div class="bottom-row">
|
|
382
|
-
<div class="score-breakdown">
|
|
383
|
-
<div class="score-card">
|
|
384
|
-
<h3>Lag</h3>
|
|
385
|
-
<div class="value">30%</div>
|
|
386
|
-
<div class="desc">Responsiveness (inverse window size)</div>
|
|
387
|
-
</div>
|
|
388
|
-
<div class="score-card">
|
|
389
|
-
<h3>Stability</h3>
|
|
390
|
-
<div class="value">30%</div>
|
|
391
|
-
<div class="desc">Mean regime run-length</div>
|
|
392
|
-
</div>
|
|
393
|
-
<div class="score-card">
|
|
394
|
-
<h3>Entropy</h3>
|
|
395
|
-
<div class="value">25%</div>
|
|
396
|
-
<div class="desc">1 − random-band fraction</div>
|
|
397
|
-
</div>
|
|
398
|
-
<div class="score-card">
|
|
399
|
-
<h3>Structured</h3>
|
|
400
|
-
<div class="value">15%</div>
|
|
401
|
-
<div class="desc">PE structured fraction</div>
|
|
402
|
-
</div>
|
|
403
|
-
</div>
|
|
404
|
-
|
|
405
|
-
<table class="params-table">
|
|
406
|
-
<tr><td>Hurst range</td><td>${Math.round(hurstVals[0])} – ${Math.round(hurstVals[hurstVals.length-1])} (center=${defaultH})</td></tr>
|
|
407
|
-
<tr><td>PE range</td><td>${Math.round(peVals[0])} – ${Math.round(peVals[peVals.length-1])} (center=${defaultP})</td></tr>
|
|
408
|
-
<tr><td>Hurst scales</td><td>[${HURST_SCALES.join(', ')}]</td></tr>
|
|
409
|
-
<tr><td>PE embedding</td><td>m=${PE_M}, delay=${PE_DELAY}</td></tr>
|
|
410
|
-
<tr><td>Spacing</td><td>geometric (ratio=${geoRatio.toFixed(3)})</td></tr>
|
|
411
|
-
</table>
|
|
412
|
-
</div>
|
|
413
|
-
</body>
|
|
414
|
-
</html>`;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
async function main() {
|
|
418
|
-
const config = parseArgs();
|
|
419
|
-
|
|
420
|
-
try {
|
|
421
|
-
if (config.listBots) {
|
|
422
|
-
listAvailableBots();
|
|
423
|
-
return;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
const { source } = resolveSource({ ...config.source.config, type: config.source.type }, { quiet: config.quiet });
|
|
427
|
-
if (!config.quiet) console.log(`[RegimeWindows] Loading candles from ${source.name}...`);
|
|
428
|
-
|
|
429
|
-
const candles = await source.fetchCandles();
|
|
430
|
-
if (!Array.isArray(candles) || candles.length === 0) {
|
|
431
|
-
throw new Error('No candles returned from source');
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
const prices = candles.map(c => getCandleClose(c) ?? 0);
|
|
435
|
-
|
|
436
|
-
if (!config.quiet) console.log(`[RegimeWindows] ${prices.length} candles — running grid search...`);
|
|
437
|
-
|
|
438
|
-
const rawResults: any[] = [];
|
|
439
|
-
for (const hW of HURST_WINDOWS) {
|
|
440
|
-
for (const pW of PE_WINDOWS) {
|
|
441
|
-
if (!config.quiet) process.stdout.write(` H=${hW.toFixed(1)} PE=${pW.toFixed(1)} ... `);
|
|
442
|
-
const r = scoreWindowPair(prices, hW, pW);
|
|
443
|
-
if (r) {
|
|
444
|
-
rawResults.push(r);
|
|
445
|
-
if (!config.quiet) console.log(`stab=${r._stabilityRaw.toFixed(1)}b entr=${(r._entropyRaw*100).toFixed(1)}% lag=${r._lagRaw.toFixed(3)}`);
|
|
446
|
-
} else {
|
|
447
|
-
if (!config.quiet) console.log('skip (not enough data)');
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
const results = computeComposite(rawResults);
|
|
453
|
-
|
|
454
|
-
if (!config.quiet) {
|
|
455
|
-
const best = results.reduce((a: any, b: any) => a.composite > b.composite ? a : b);
|
|
456
|
-
console.log(`\n[RegimeWindows] Best: H=${Math.round(best.hurstWindow)} PE=${Math.round(best.peWindow)} score=${best.composite} (stab=${best.stabilityScore} entr=${best.entropyScore} lag=${best.lagScore})`);
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
const html = generateHeatmapHTML(results, HURST_WINDOWS, PE_WINDOWS);
|
|
460
|
-
writeChartFile(config.chartFile, html);
|
|
461
|
-
|
|
462
|
-
if (!config.quiet) console.log(`[RegimeWindows] ✓ Chart saved to ${config.chartFile}`);
|
|
463
|
-
|
|
464
|
-
} catch (err: unknown) {
|
|
465
|
-
console.error(`[RegimeWindows] Error: ${(err as any)?.message ?? err}`);
|
|
466
|
-
process.exit(1);
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
|
|
470
|
-
main().catch((err: unknown) => { console.error(err); process.exit(1); });
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
'use strict';
|
|
3
|
-
/**
|
|
4
|
-
* RISK PROFILE ANALYZER
|
|
5
|
-
*
|
|
6
|
-
* Unified utility to measure historical inventory drift (divergence quantiles
|
|
7
|
-
* and max divergence) to characterize risk bounds and establish safe ranges.
|
|
8
|
-
*
|
|
9
|
-
* Also computes the empirical standard deviation of per-bar AMA movement
|
|
10
|
-
* (σ_ama_delta) for calibrating AMA_DELTA_THRESHOLD_PERCENT.
|
|
11
|
-
*
|
|
12
|
-
* Usage:
|
|
13
|
-
* node dist/analysis/analyze_risk_profile.js --source market_adapter --bot-key <key> [options]
|
|
14
|
-
* node dist/analysis/analyze_risk_profile.js --file <path_to_json> [options]
|
|
15
|
-
*/
|
|
16
|
-
import { calculateAMA } from '../market_adapter/core/strategies/ama.js';
|
|
17
|
-
import { MARKET_ADAPTER } from '../modules/constants.js';
|
|
18
|
-
import { generateHTML } from '../market_adapter/lp_chart_core.js';
|
|
19
|
-
import { calcStdDev, getCandleClose } from './math_utils.js';
|
|
20
|
-
import { writeChartFile } from './chart_utils.js';
|
|
21
|
-
import { resolveSource, listAvailableBots, type SourceConfig } from './resolve_source.js';
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
function normSInv(p: number) {
|
|
25
|
-
if (p <= 0 || p >= 1) return p <= 0 ? -Infinity : Infinity;
|
|
26
|
-
const a = [-3.969683028665376e1, 2.209460984245205e2, -2.759285104469687e2, 1.383577518672690e2, -3.066479806614716e1, 2.506628277459239];
|
|
27
|
-
const b = [-5.447609879822406e1, 1.615858368580409e2, -1.556989798598866e2, 6.680131188771972e1, -1.328068155288572e1];
|
|
28
|
-
const c = [-7.784894002430293e-3, -3.223964580411365e-1, -2.400758277161838e0, -2.549732539343734e0, 4.374664141464968e0, 2.938163982698783e0];
|
|
29
|
-
const d = [7.784695709041462e-3, 3.224671290700398e-1, 2.445134137142996e0, 3.754408661907416e0];
|
|
30
|
-
const p_low = 0.02425;
|
|
31
|
-
const p_high = 1 - p_low;
|
|
32
|
-
if (p < p_low) {
|
|
33
|
-
const q = Math.sqrt(-2 * Math.log(p));
|
|
34
|
-
return (((((c[0] * q + c[1]) * q + c[2]) * q + c[3]) * q + c[4]) * q + c[5]) / ((((d[0] * q + d[1]) * q + d[2]) * q + d[3]) * q + 1);
|
|
35
|
-
} else if (p <= p_high) {
|
|
36
|
-
const q = p - 0.5;
|
|
37
|
-
const r = q * q;
|
|
38
|
-
return (((((a[0] * r + a[1]) * r + a[2]) * r + a[3]) * r + a[4]) * r + a[5]) * q / (((((b[0] * r + b[1]) * r + b[2]) * r + b[3]) * r + b[4]) * r + 1);
|
|
39
|
-
} else {
|
|
40
|
-
const q = Math.sqrt(-2 * Math.log(1 - p));
|
|
41
|
-
return -((((((c[0] * q + c[1]) * q + c[2]) * q + c[3]) * q + c[4]) * q + c[5]) / ((((d[0] * q + d[1]) * q + d[2]) * q + d[3]) * q + 1));
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
function quantileToSigma(q: number) {
|
|
46
|
-
return normSInv((1 + q) / 2);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function getAmaDeltaStdDev(closes: number[], amaConfig: any, warmup: number) {
|
|
50
|
-
const amaValues = calculateAMA(closes, amaConfig);
|
|
51
|
-
const deltas: number[] = [];
|
|
52
|
-
for (let i = warmup + 1; i < closes.length; i++) {
|
|
53
|
-
const prev = amaValues[i - 1];
|
|
54
|
-
const cur = amaValues[i];
|
|
55
|
-
if (!prev || !cur) continue;
|
|
56
|
-
deltas.push((cur - prev) / prev);
|
|
57
|
-
}
|
|
58
|
-
return deltas.length ? calcStdDev(deltas) : null;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function getDivergenceDist(closes: number[], amaConfig: any) {
|
|
62
|
-
const amaValues = calculateAMA(closes, amaConfig);
|
|
63
|
-
const dists: number[] = [];
|
|
64
|
-
for (let i = 1600; i < closes.length; i++) {
|
|
65
|
-
const ama = amaValues[i];
|
|
66
|
-
if (!ama) continue;
|
|
67
|
-
dists.push(Math.abs(closes[i] - ama) / ama);
|
|
68
|
-
}
|
|
69
|
-
return dists.sort((a, b) => a - b);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
function parseArgs() {
|
|
73
|
-
const args = process.argv.slice(2);
|
|
74
|
-
const config: {
|
|
75
|
-
source: { type: string; config: SourceConfig };
|
|
76
|
-
ama: string;
|
|
77
|
-
output: string | null;
|
|
78
|
-
quiet: boolean;
|
|
79
|
-
listBots: boolean;
|
|
80
|
-
} = {
|
|
81
|
-
source: { type: 'market_adapter', config: { botKey: '' } },
|
|
82
|
-
ama: 'AMA3',
|
|
83
|
-
output: null,
|
|
84
|
-
quiet: false,
|
|
85
|
-
listBots: false,
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
for (let i = 0; i < args.length; i++) {
|
|
89
|
-
const arg = args[i];
|
|
90
|
-
if (arg === '--source') config.source.type = args[++i];
|
|
91
|
-
else if (arg === '--bot-key') config.source.config.botKey = args[++i];
|
|
92
|
-
else if (arg === '--file') {
|
|
93
|
-
config.source.config.filePath = args[++i];
|
|
94
|
-
config.source.type = 'json';
|
|
95
|
-
}
|
|
96
|
-
else if (arg === '--ama') config.ama = args[++i];
|
|
97
|
-
else if (arg === '--output') config.output = args[++i];
|
|
98
|
-
else if (arg === '--list-bots') config.listBots = true;
|
|
99
|
-
else if (arg === '--quiet') config.quiet = true;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return config;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async function main() {
|
|
106
|
-
try {
|
|
107
|
-
const config = parseArgs();
|
|
108
|
-
|
|
109
|
-
if (config.listBots) {
|
|
110
|
-
listAvailableBots();
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
const { source, botKey } = resolveSource({ ...config.source.config, type: config.source.type }, { quiet: config.quiet });
|
|
115
|
-
if (!config.quiet) console.log(`[RiskProfile] Loading candles from ${source.name}...`);
|
|
116
|
-
|
|
117
|
-
const candles = await source.fetchCandles();
|
|
118
|
-
if (!Array.isArray(candles) || candles.length === 0) {
|
|
119
|
-
throw new Error('No candles returned from source');
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const closes = candles.map(c => getCandleClose(c) ?? Number(c?.[4] ?? 0));
|
|
123
|
-
const warmup = 1600;
|
|
124
|
-
const presets = ['AMA1', 'AMA2', 'AMA3', 'AMA4'];
|
|
125
|
-
const quantiles = [0.999, 0.9999, 0.99999];
|
|
126
|
-
|
|
127
|
-
if (!config.quiet) console.log(`[RiskProfile] Analyzing ${closes.length} candles from ${source.name}`);
|
|
128
|
-
const sigmaLabels = quantiles.map(q => `${(q * 100).toFixed(3)}% — ${quantileToSigma(q).toFixed(2)}σ`);
|
|
129
|
-
console.log('Preset, Max_Divergence(x), ' + sigmaLabels.map((l, i) => `${l} (${['Soft','Hard','Emergency'][i]})`).join(', '));
|
|
130
|
-
|
|
131
|
-
presets.forEach(name => {
|
|
132
|
-
const cfg = MARKET_ADAPTER.AMAS[name as keyof typeof MARKET_ADAPTER.AMAS];
|
|
133
|
-
const allDists = getDivergenceDist(closes, cfg);
|
|
134
|
-
|
|
135
|
-
if (allDists.length === 0) {
|
|
136
|
-
console.log(`${name}, N/A, N/A, N/A, N/A`);
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
const maxDist = allDists[allDists.length - 1];
|
|
140
|
-
const meanDist = allDists.reduce((a, b) => a + b, 0) / allDists.length;
|
|
141
|
-
const stdDist = calcStdDev(allDists);
|
|
142
|
-
const amaDeltaSigma = getAmaDeltaStdDev(closes, cfg, warmup);
|
|
143
|
-
const quantileResults = quantiles.map(q => {
|
|
144
|
-
const val = allDists[Math.min(Math.floor(allDists.length * q), allDists.length - 1)];
|
|
145
|
-
const sigma = quantileToSigma(q);
|
|
146
|
-
const empSigma = (val - meanDist) / stdDist;
|
|
147
|
-
return `${(1 + val).toFixed(3)}x (${sigma.toFixed(2)}σt, ${empSigma.toFixed(2)}σe)`;
|
|
148
|
-
});
|
|
149
|
-
console.log(`${name}, ${(1 + maxDist).toFixed(3)}x, ${quantileResults.join(', ')}`);
|
|
150
|
-
console.log(` σ_div: ${(stdDist * 100).toFixed(3)}% | mean_div: ${(meanDist * 100).toFixed(3)}% | σ_ama_delta: ${amaDeltaSigma !== null ? (amaDeltaSigma * 100).toFixed(3) : 'N/A'}%`);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
if (config.output) {
|
|
154
|
-
if (!MARKET_ADAPTER.AMAS[config.ama as keyof typeof MARKET_ADAPTER.AMAS]) {
|
|
155
|
-
console.error(`Invalid AMA preset for output: ${config.ama}. Choose from: ${Object.keys(MARKET_ADAPTER.AMAS).join(', ')}`);
|
|
156
|
-
process.exit(1);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const amaCfg = MARKET_ADAPTER.AMAS[config.ama as keyof typeof MARKET_ADAPTER.AMAS];
|
|
160
|
-
const amaValues = calculateAMA(closes, amaCfg);
|
|
161
|
-
const candleArrays = candles.map(c => [c?.timestamp ?? c?.[0] ?? 0, c?.open ?? c?.[1] ?? 0, c?.high ?? c?.[2] ?? 0, c?.low ?? c?.[3] ?? 0, c?.close ?? c?.[4] ?? 0, c?.volume ?? c?.[5] ?? 0]);
|
|
162
|
-
|
|
163
|
-
const allDists = getDivergenceDist(closes, amaCfg);
|
|
164
|
-
const amaDeltaSigma = getAmaDeltaStdDev(closes, amaCfg, warmup);
|
|
165
|
-
const thresholds = quantiles.map(q => {
|
|
166
|
-
const val = allDists[Math.min(Math.floor(allDists.length * q), allDists.length - 1)];
|
|
167
|
-
return { quantile: q, multiplier: (1 + val).toFixed(3) };
|
|
168
|
-
});
|
|
169
|
-
const amaResult = {
|
|
170
|
-
name: config.ama,
|
|
171
|
-
values: amaValues,
|
|
172
|
-
color: '#e3b341',
|
|
173
|
-
lineWidth: 2,
|
|
174
|
-
erPeriod: amaCfg.erPeriod,
|
|
175
|
-
fastPeriod: amaCfg.fastPeriod,
|
|
176
|
-
slowPeriod: amaCfg.slowPeriod
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
const pairName = botKey || 'Market';
|
|
180
|
-
const meta = {
|
|
181
|
-
pool: `${pairName} ${config.ama} Risk Analysis`,
|
|
182
|
-
assetA: { symbol: 'Base' },
|
|
183
|
-
assetB: { symbol: 'Quote' },
|
|
184
|
-
intervalSeconds: candles.length > 1 ? ((candles[1]?.timestamp ?? candles[1]?.[0] ?? 0) - (candles[0]?.timestamp ?? candles[0]?.[0] ?? 0)) / 1000 : 3600,
|
|
185
|
-
thresholds: thresholds,
|
|
186
|
-
sigmaAmaDelta: amaDeltaSigma !== null ? +((amaDeltaSigma * 100).toFixed(3)) : null
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
const html = generateHTML(meta, candleArrays, [amaResult]);
|
|
190
|
-
writeChartFile(config.output, html);
|
|
191
|
-
console.log(`\n[RiskProfile] ✓ Risk report generated: ${config.output}`);
|
|
192
|
-
}
|
|
193
|
-
} catch (err: any) {
|
|
194
|
-
console.error(`[RiskProfile] Error: ${err?.message ?? err}`);
|
|
195
|
-
process.exit(1);
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
main().catch((err: unknown) => { console.error(err); process.exit(1); });
|