Spaces:
Build error
Build error
| """ | |
| config.py — 全局常量、特征定义、路径、API Key | |
| ================================================= | |
| 所有模块共享的配置集中在此。 | |
| """ | |
| import os | |
| # ── 工作目录 ── | |
| BASE_DIR = os.environ.get('OILVERSE_BASE_DIR', os.path.dirname(os.path.abspath(__file__))) | |
| OUTPUT_DIR = os.path.join(BASE_DIR, 'output') | |
| DATA_DIR = os.path.join(BASE_DIR, 'data', 'csv_raw') | |
| # ── API Keys ── | |
| FRED_API_KEY = 'fc02a6e6a359a4cc16f0f1752d258011' | |
| EIA_API_KEY = '9Nv5PhLREMmmKeo0zJ2U3Zu21Bntf8DfhEKBpi55' | |
| SILICONFLOW_API_KEY = 'sk-cgllfrsuchzzwerkxcegkhbroboqcnpuubhreyrfudfstqjv' | |
| SILICONFLOW_BASE_URL = 'https://api.siliconflow.cn/v1' | |
| SILICONFLOW_MODEL = 'Qwen/Qwen2.5-7B-Instruct' | |
| # ── 价格列 ── | |
| PRICE_COLS = { | |
| 'WTI': 'WTI_spot', | |
| 'Brent': 'Brent_spot', | |
| } | |
| PRICE_COL = 'WTI_spot' # backward compat | |
| # ── 特征列表 (20个,含GPR + 新闻情绪) ── | |
| FEATURES = [ | |
| 'Brent_spot', 'natgas_spot_henry', 'iron_ore_spot', # Price | |
| 'rig_count_us_new', 'supply_saudi', 'us_oil_inventory_total', # Supply | |
| 'pmi_us_mfg', 'usd_index', 'nonfarm_us', 'ipi_us', # Demand | |
| 'vix_lag1', 'vix_lag2', 'geo_shock_count', 'geo_active_events', # Risk+Geo | |
| 'mom1m_lag1', 'hist_vol_12m', 'rsi12m', # Technical | |
| 'news_oil_sentiment', 'news_geo_tone', 'news_article_volume', # Alternative (GDELT) | |
| ] | |
| # ── 因子分组 ── | |
| FACTOR_GROUPS = { | |
| 'Price': ['Brent_spot', 'natgas_spot_henry', 'iron_ore_spot'], | |
| 'Supply': ['rig_count_us_new', 'supply_saudi', 'us_oil_inventory_total'], | |
| 'Demand': ['pmi_us_mfg', 'usd_index', 'nonfarm_us', 'ipi_us'], | |
| 'Risk_Geo': ['vix_lag1', 'vix_lag2', 'geo_shock_count', 'geo_active_events'], | |
| 'Technical': ['mom1m_lag1', 'hist_vol_12m', 'rsi12m'], | |
| 'Alternative': ['news_oil_sentiment', 'news_geo_tone', 'news_article_volume'], | |
| } | |
| # ── Walk-Forward 参数 ── | |
| TRAIN_WINDOW = 120 | |
| MAX_FEATURES = 10 | |
| MIN_TRAIN_SAMPLES = 20 | |
| # ── Regime 签名 (历史时期特征向量) ── | |
| REGIME_SIGNATURES = { | |
| '2008 金融危机': {'supply_stress': 0.1, 'demand_stress': 0.6, 'geopolitical_stress': 0.1, 'price_momentum': 0.15, 'vol_level': 0.25}, | |
| '2014 页岩油冲击': {'supply_stress': 0.5, 'demand_stress': 0.2, 'geopolitical_stress': 0.05, 'price_momentum': 0.2, 'vol_level': 0.12}, | |
| '2020 COVID': {'supply_stress': 0.3, 'demand_stress': 0.5, 'geopolitical_stress': 0.05, 'price_momentum': 0.1, 'vol_level': 0.30}, | |
| '2022 俄乌冲突': {'supply_stress': 0.3, 'demand_stress': 0.1, 'geopolitical_stress': 0.5, 'price_momentum': 0.05, 'vol_level': 0.15}, | |
| '2023 OPEC减产': {'supply_stress': 0.5, 'demand_stress': 0.15, 'geopolitical_stress': 0.15, 'price_momentum': 0.1, 'vol_level': 0.08}, | |
| '常态/低波动': {'supply_stress': 0.15, 'demand_stress': 0.15, 'geopolitical_stress': 0.1, 'price_momentum': 0.1, 'vol_level': 0.04}, | |
| } | |
| REGIME_TYPE_MAP = { | |
| '2008 金融危机': 'demand_collapse', | |
| '2014 页岩油冲击': 'supply_glut', | |
| '2020 COVID': 'demand_collapse', | |
| '2022 俄乌冲突': 'geopolitical', | |
| '2023 OPEC减产': 'supply_cut', | |
| '常态/低波动': 'normal', | |
| } | |
| # ── 行业映射 ── | |
| INDUSTRIES = ['Aviation', 'Logistics', 'Chemicals', 'Manufacturing', 'Upstream_OG'] | |
| INDUSTRY_ZH = { | |
| 'Aviation': '航空', 'Logistics': '物流', 'Chemicals': '化工', | |
| 'Manufacturing': '制造', 'Upstream_OG': '上游油气', | |
| } | |
| # ── 输出文件路径 ── | |
| OUTPUT_FILES = { | |
| 'results': os.path.join(OUTPUT_DIR, 'v2_championship_results.csv'), | |
| 'shap': os.path.join(OUTPUT_DIR, 'v2_shap_records.json'), | |
| 'nlg': os.path.join(OUTPUT_DIR, 'v2_nlg_reports.json'), | |
| 'scenarios': os.path.join(OUTPUT_DIR, 'v2_scenarios.json'), | |
| 'regime': os.path.join(OUTPUT_DIR, 'v2_regime_data.json'), | |
| 'ablation': os.path.join(OUTPUT_DIR, 'v2_ablation.json'), | |
| 'hedging': os.path.join(OUTPUT_DIR, 'v2_hedging.json'), | |
| 'backtest': os.path.join(OUTPUT_DIR, 'v2_hedge_backtest.json'), | |
| 'feat_sel': os.path.join(OUTPUT_DIR, 'v2_feature_selection.json'), | |
| 'dashboard': os.path.join(OUTPUT_DIR, 'risk_dashboard.html'), | |
| 'panel_live': os.path.join(OUTPUT_DIR, 'panel_monthly_live.csv'), | |
| 'lineage': os.path.join(OUTPUT_DIR, 'data_lineage.json'), | |
| 'quality': os.path.join(OUTPUT_DIR, 'data_quality.json'), | |
| 'causal': os.path.join(OUTPUT_DIR, 'causal_analysis.json'), | |
| 'events': os.path.join(OUTPUT_DIR, 'event_timeline.json'), | |
| } | |