宏观数据与预测市场相匹配的地方
预测市场已经从好奇心转向基础设施. 卡尔希 美国首家由CFTC监管的预测交易所, 允许您交易"will 美国CPI 超过3.5%在4月份?"或"将 美国联邦储备 Polymarket 在 Polygon 区块链上运行,提供类似的二进制结果市场,在全球开放式访问下进行宏观事件. 美元/日元没有人知道. 欧元/美元其他外汇公司.
如果您已经使用FXMacroData来跟踪央行日历,监控CPI惊喜,并抽取政策利率历史,您有必要的原材料来建立这些市场的系统优势.本指南将向您展示如何连接点:从FXMacrodata抽取结构化宏观数据,将其映射到开放预测市场合约,并在Python中构建可重复的决策工作流.
通过FXMacroData将即将到来的宏观公告与Kalshi和Polymarket的相关预测市场合约匹配,并从历史惊喜数据计算方向信号,以帮助您了解位置.
预先要求
- 一个FXMacroData API 键 在这里订阅 免费试用.
- 通过Python 3.10或更高版本
requests已经安装 (pip install requests) 没有. - 卡尔希账户启用API访问,或者是Polymarket钱包进行手动交叉引用.
- 基本熟悉CPI的内容, 农业以外的工资没有 政策利率 决策是这样的.
步骤1 拉下一个发布日历
首先,您需要清楚地了解什么发布会和何时发布.FXMacroData的发布日历终点返回货币的所有预定宏观事件,以及预期日期和发布时间.
import requests
API_KEY = "YOUR_API_KEY"
BASE = "https://fxmacrodata.com/api/v1"
def get_upcoming_releases(currency: str) -> list[dict]:
url = f"{BASE}/calendar/{currency}?api_key={API_KEY}"
resp = requests.get(url, timeout=10)
resp.raise_for_status()
return resp.json().get("data", [])
usd_calendar = get_upcoming_releases("usd")
for event in usd_calendar[:5]:
print(event["indicator"], event.get("announcement_datetime"), event.get("next_release_date"))
每个条目都带有一个 indicator (例如: inflation没有人知道. non_farm_payrolls没有人知道. policy_rate,作为Unix时间的预定公告时间,以及下一个预期发布日期.这是您过开放预测市场合约的主要输入.
步骤2 获取历史公告数据并计算惊喜序列
预测市场价格概率基于可用信息. 如果您可以计算给定指标的近期惊喜指数,实际打印的共识是多少次,以及您有多少的基线来校准您的位置. 从公告终点从过去十二个月的实际与预测数据中提取:
def get_announcement_history(currency: str, indicator: str, limit: int = 24) -> list[dict]:
url = f"{BASE}/announcements/{currency}/{indicator}?api_key={API_KEY}&limit={limit}"
resp = requests.get(url, timeout=10)
resp.raise_for_status()
return resp.json().get("data", [])
def compute_surprise_series(records: list[dict]) -> list[dict]:
surprises = []
for r in records:
actual = r.get("actual_value")
consensus = r.get("predicted_value")
if actual is not None and consensus is not None:
surprises.append({
"date": r["date"],
"actual": actual,
"consensus": consensus,
"surprise": actual - consensus,
"direction": "beat" if actual > consensus else "miss",
})
return surprises
cpi_history = get_announcement_history("usd", "inflation", limit=24)
cpi_surprises = compute_surprise_series(cpi_history)
beat_count = sum(1 for s in cpi_surprises if s["direction"] == "beat")
miss_count = len(cpi_surprises) - beat_count
print(f"CPI beat rate (last 24 releases): {beat_count}/{len(cpi_surprises)} = {beat_count/len(cpi_surprises):.0%}")
没有什么. predicted_value 每个公告记录上的字段存储了权威来源的市场共识 (费城联邦储备局对美元指标的专业预测者调查). 这也是同一个准预测市场定价的共识信号,因此您的惊喜系列将与卡尔希CPI合约中的隐含概率直接相比.
步骤3 预测市场合约的地图指标
卡尔希和波利马克特都将其宏观合约围绕特定指标值构建起来.一旦您了解FXMacroData指标的,映射就很简单.下面是一个最流动合约的参考表:
| 预测市场合约类型 | 汇率指标 | 货币 | 应用程序文件 |
|---|---|---|---|
| 价格指数会超过X%吗? | inflation |
美元 | 美国美元/通货膨胀 |
| 核心价格指数将超过X%? | core_inflation |
美元 | 美国美元/核心通货膨胀 |
| 否则,我们将会有更多的问题. | non_farm_payrolls |
美元 | 农业工资人数 |
| 美国联邦储备委员会是否会减持或维持? | policy_rate |
美元 | 美国美元/政策_利率 |
| 国内生产总值增长将超过X%吗? | gdp_quarterly |
美元 | 美国人民币/GDP_季度 |
| 失业率会下降到X%以下吗? | unemployment |
美元 | 美国美元/失业 |
| 欧洲央行是否会在下一次会议上降息? | policy_rate |
欧元 | 欧元/政策_利率 |
没有什么. 发布日程 查看所有这些指标表单一视图. 当卡尔希合约列出解决日期时,与 next_release_date 根据FXMacroData日历确认他们根据相同的基本公告解决.不匹配,即合同根据预估和最终修订解决是误价的常见来源.
步骤4 查询共识定预测终点
汇丰MacroData的预测终点提供了来自官方调查数据的前性共识值,这些调查是预测市场参与者用来固他们的先验的. 抽取下一次CPI发布的当前共识,并将其与开放卡尔希合约的门进行比较:
def get_predictions(currency: str, indicator: str) -> list[dict]:
url = f"{BASE}/predictions/{currency}/{indicator}?api_key={API_KEY}"
resp = requests.get(url, timeout=10)
resp.raise_for_status()
return resp.json().get("data", [])
cpi_predictions = get_predictions("usd", "inflation")
# Most recent upcoming prediction
if cpi_predictions:
next_pred = cpi_predictions[0]
for p in next_pred.get("predictions", []):
print(f"Source: {p['prediction_source_label']}")
print(f"Consensus: {p['predicted_value']}%")
print(f"For release date: {next_pred['date']}")
样本反应的形状:
{
"currency": "USD",
"indicator": "inflation",
"count": 1,
"prediction_count": 1,
"data": [
{
"announcement_id": "usd_inflation_2026-05-14",
"currency": "usd",
"indicator": "inflation",
"date": "2026-05-14",
"announcement_datetime": 1747216200,
"predictions": [
{
"predicted_value": 2.8,
"prediction_type": "market_consensus",
"prediction_source": "philly_fed_spf",
"prediction_source_label": "Philadelphia Fed Survey of Professional Forecasters"
}
]
}
]
}
如果卡尔希合约问"4月CPI将会超过2.9%吗?"而SPF共识为2.8%,你现在有一个量化起点:共识表示没有,并且有0.1个百分点缓冲.从第二步的历史惊喜系列告诉你CPI有多少次超过了共识0.1百分點,给你一个实证的基率,可以与合同的隐含概率进行比较.
步骤5 建立完整的决策信号
将三个输入组合成一个单一的决策函数.逻辑是故意简单的目标是可重复的,数据基础的信号,而不是一个黑盒:
def prediction_market_signal(
currency: str,
indicator: str,
contract_threshold: float,
contract_direction: str, # "above" or "below"
lookback: int = 24,
) -> dict:
"""
Returns a signal dict for a prediction market contract.
contract_threshold: the numeric threshold in the contract question
(e.g. 2.9 for "Will CPI exceed 2.9%?")
contract_direction: "above" means YES if actual > threshold
"""
history = get_announcement_history(currency, indicator, limit=lookback)
surprises = compute_surprise_series(history)
predictions = get_predictions(currency, indicator)
consensus = None
release_date = None
if predictions:
latest_preds = predictions[0].get("predictions", [])
if latest_preds:
consensus = latest_preds[0]["predicted_value"]
release_date = predictions[0]["date"]
# Base rate: how often did actual exceed the threshold historically?
actuals_above = sum(1 for r in history if r.get("actual_value") is not None
and r["actual_value"] > contract_threshold)
base_rate = actuals_above / len(history) if history else None
# Surprise bias: mean surprise (positive = beat)
mean_surprise = (sum(s["surprise"] for s in surprises) / len(surprises)
if surprises else None)
# Directional signal
if consensus is not None:
buffer = consensus - contract_threshold # positive = consensus above threshold
signal = "NO" if (contract_direction == "above" and buffer > 0) else "YES"
else:
signal = "NEUTRAL"
return {
"currency": currency.upper(),
"indicator": indicator,
"contract_threshold": contract_threshold,
"contract_direction": contract_direction,
"consensus": consensus,
"release_date": release_date,
"historical_base_rate_above_threshold": base_rate,
"mean_surprise_last_n": mean_surprise,
"lookback": lookback,
"signal": signal,
}
result = prediction_market_signal(
currency="usd",
indicator="inflation",
contract_threshold=2.9,
contract_direction="above",
lookback=24,
)
import json
print(json.dumps(result, indent=2))
输出示例:
{
"currency": "USD",
"indicator": "inflation",
"contract_threshold": 2.9,
"contract_direction": "above",
"consensus": 2.8,
"release_date": "2026-05-14",
"historical_base_rate_above_threshold": 0.33,
"mean_surprise_last_n": 0.04,
"lookback": 24,
"signal": "NO"
}
阅读:共识为2.8% (低于2.9%的门),CPI打印超过2.9%24次发布的历史基率为33%,平均惊喜是温和的0.04ppt上升偏差.原始信号是NO,但基率和惊喜偏差的组合告诉你,这不是一个高信念的瘦调整位置大小.
步骤6 扩展到非美元和跨市场合同
预测市场越来越多地列出非美元宏观事件的合约:欧洲央行决定,英国CPI,日本银行政策和澳大利亚就业.FXMacroData通过相同的终点结构覆盖所有这些.
# ECB rate decision signal
ecb_signal = prediction_market_signal(
currency="eur",
indicator="policy_rate",
contract_threshold=3.15, # "Will ECB rate fall below 3.15%?"
contract_direction="below",
lookback=12,
)
# UK inflation signal
uk_cpi_signal = prediction_market_signal(
currency="gbp",
indicator="inflation",
contract_threshold=2.5,
contract_direction="above",
lookback=18,
)
# Australian employment signal
aus_employment_signal = prediction_market_signal(
currency="aud",
indicator="employment",
contract_threshold=30.0, # thousands, "Will employment add 30K+?"
contract_direction="above",
lookback=18,
)
没有什么. 欧元/美元 现在我 汇率汇率 仪表板显示每个货币对的政策利率历史和CPI趋势,在承诺之前给您视觉上下文检查. 欧洲央行 根据过去四次会议的持续降息情况,一个合同问"欧洲央行将在6月降息吗?"
步骤7 监控COT定位作为确认层
期货投机往往反映了相同的方向观点. 机器人机器人的仪表板 对于美元来说,指数显示大投机者是否是净长或短美元,即将进入CPI打印.如果规格是大量净长美元,CPI信号为NO (低于门),则有可能出现双边:预测市场合约可能值得消退,外汇仓位也可能容易受到挤压.
通过程序来提取COT数据,将其纳入您的信号框架:
def get_cot(currency: str) -> list[dict]:
url = f"{BASE}/cot/{currency}?api_key={API_KEY}&limit=4"
resp = requests.get(url, timeout=10)
resp.raise_for_status()
return resp.json().get("data", [])
usd_cot = get_cot("usd")
if usd_cot:
latest = usd_cot[0]
net_position = latest.get("net_position")
print(f"USD spec net position (latest week): {net_position:+,.0f} contracts")
让我们一起做
整个工作流程看起来是这样:
- 拉起这个 发布日程 确定即将到来的公告和预定时间.
- 赛事公告日期为 开放预测市场合同 在卡尔希或聚市场上.
- 拿来一个 预测终点 对于当前的共识值.
- 计算一个 历史惊喜系列 为了测量方向偏差和基率.
- 产生一个 方向信号 通过将共识与合同值进行比较.
- 选择性地加上 机器人位置 作为确认信号.
- 根据合同中暗示的概率与实证基准利率估计之间的差距,
提供第二级的FXMacroData
announcement_datetime 每个发布的时间对于预测市场至关重要,预测在官方打印后几秒内解决.始终确保合同的声明解决源 (例如"2026年3月的BLS CPI,首次发布") 与您查询的FXMacroData指标和修订标志完全匹配.预估和最终修订将作为单独的数据点存储.
开始吧
本指南中使用的所有终点均可免费试用,不需要信用卡.包括CPI,NFP,GDP,失业率,核心PCE和政策利率在内的美元指标均可在免费层面上访问.非美元指数和COT数据需要专业计划.