03-高频策略类型

预计学习时间:1.5 小时

难度:⭐⭐⭐

核心问题:比普通人快一步能赚钱吗?高频交易者在做什么?


从一个直觉出发

假设某只股票即将发布利好财报。你知道这个消息比别人早 0.1 秒。

在这 0.1 秒内:

  1. 你发出一个市价买单
  2. 订单到达交易所,以当前卖一价格成交
  3. 其他投资者看到消息后也开始买入,推高价格
  4. 你卖出,赚取差价

这就是”延迟套利”的基本逻辑——利用信息传播的时间差赚钱。

但现实比这复杂得多。这一章我们来看高频交易者到底在用什么策略,以及这些策略的边界在哪里。


一、做市策略(Market Making)

1.1 原理

做市是最经典的高频策略:同时在买卖两侧挂单,赚取买卖价差

  卖一  10.02  ← 你的卖单挂在这里
  ═════════════  ← 价差 = 0.02 = 你的利润
  买一  10.00  ← 你的买单挂在这里

  当一个买家来了,你的卖单以 10.02 成交
  当一个卖家来了,你的买单以 10.00 成交
  你赚了 0.02 的价差

1.2 库存管理

做市不是”永远挂单不动”。核心难题是库存风险

  • 不断被成交买方,你的持仓越来越多 → 价格下跌你就亏
  • 需要通过调整报价来控制库存
import numpy as np
import matplotlib.pyplot as plt
 
np.random.seed(42)
 
# ============================================================
# 简化做市策略模拟
# ============================================================
T = 1.0
dt = 0.001
n_steps = int(T / dt)
sigma = 0.3
base_half_spread = 0.01  # 基础半价差
 
mid_price = 100.0
inventory = 0
cash = 0.0
 
pnl_list = []
inv_list = []
 
for step in range(n_steps):
    # 根据库存调整报价
    inventory_adj = 0.002 * inventory  # 库存越多,卖价越低、买价越低
 
    ask = mid_price + base_half_spread + inventory_adj
    bid = mid_price - base_half_spread + inventory_adj
 
    # 模拟订单到达
    if np.random.random() < 0.3:
        if np.random.random() < 0.5:
            # 对手方买入(我们卖出)
            inventory -= 1
            cash += ask
        else:
            # 对手方卖出(我们买入)
            inventory += 1
            cash -= bid
 
    # 中间价变动
    mid_price *= np.exp(-0.5 * sigma**2 * dt + sigma * np.sqrt(dt) * np.random.normal())
 
    # PnL = 现金 + 库存市值
    pnl = cash + inventory * mid_price
    pnl_list.append(pnl)
    inv_list.append(inventory)
 
fig, axes = plt.subplots(3, 1, figsize=(14, 10))
axes[0].plot(pnl_list)
axes[0].set_title('做市策略 PnL')
 
axes[1].plot(inv_list)
axes[1].set_title('库存变化')
 
axes[2].hist(inv_list, bins=50, edgecolor='black')
axes[2].set_title('库存分布')
 
plt.tight_layout()
plt.show()

1.3 做市的核心风险

风险描述应对
存货风险持仓累积,价格反向变动库存管理,动态调整报价
逆向选择对手方是知情交易者,你被”薅羊毛”监控 PIN/VPIN,动态调整价差
毒性订单流大量同方向订单预示价格将大幅变动暂停做市,等待信息消化
闪崩风险市场极端波动导致巨额亏损设置止损、最大持仓限制

二、延迟套利(Latency Arbitrage)

2.1 原理

延迟套利利用同一信息在不同市场或不同参与者之间的传播速度差来获利。

时间线:
  t=0ms    利好消息发布
  t=0.1ms  你的系统收到消息
  t=0.5ms  你的订单到达交易所
  t=2ms    其他慢速交易者的系统收到消息
  t=5ms    他们的订单到达交易所

  你的订单先成交,价格上涨后你再卖出

2.2 延迟的来源

来源延迟量级说明
数据中心到交易所0.1-1 msCo-location 可以最小化
光纤传输5 ms / 1000 km物理极限,无法突破
微波通信2-3 ms / 1000 km比光纤快,但带宽低、受天气影响
软件处理0.01-1 ms取决于代码效率
操作系统调度0.01-0.1 ms使用实时操作系统可以降低

2.3 现实中的可行性

延迟套利的门槛极高

# 延迟的经济价值模拟
def latency_value(price_impact_per_ms, latency_advantage_ms, daily_trades):
    """延迟优势的经济价值"""
    # 每笔交易多赚的价格差
    gain_per_trade = price_impact_per_ms * latency_advantage_ms
    daily_profit = gain_per_trade * daily_trades
    annual_profit = daily_profit * 252
    return annual_profit
 
# 假设:每毫秒延迟导致 0.0001 的价格变动
# 你比别人快 1ms,每天交易 1000 次
profit = latency_value(0.0001, 1, 1000)
print(f"年化延迟优势价值: {profit:.2f}(每股)")
 
# 但建设一个低延迟系统的成本:
# Co-location: ~$5000/月
# FPGA 开发: ~$200,000 初始
# 微波链路: ~$100,000/年
print("\n投入成本分析:")
print("Co-location 年费: $60,000")
print("如果用 1ms 优势交易 10000 股/天,年化利润 = $25,200")
print("结论:只有大资金量才能覆盖基础设施成本")

三、统计套利(毫秒级)

3.1 与中低频统计套利的区别

维度中低频统计套利毫秒级统计套利
频率日频、小时频毫秒、秒频
持仓时间数天到数周数秒到数分钟
数据日线、分钟线Tick、订单簿
成本敏感度中等极高
策略容量
技术门槛

3.2 毫秒级协整

import numpy as np
from statsmodels.tsa.stattools import coint
 
np.random.seed(42)
 
# 模拟两只毫秒级协整的资产
n = 100000
# 共同因子
common_factor = np.cumsum(np.random.normal(0, 0.0001, n))
# 资产 A
spread = np.cumsum(np.random.normal(0, 0.00005, n))
price_A = 100 + common_factor + spread
# 资产 B(与 A 协整)
price_B = 100 + 0.8 * common_factor + 0.5 * spread
 
# 协整检验(采样到秒频,否则数据太多)
sample_rate = 100
A_sampled = price_A[::sample_rate]
B_sampled = price_B[::sample_rate]
 
score, pvalue, _ = coint(A_sampled, B_sampled)
print(f"协整检验 p 值: {pvalue:.6f}")
print(f"是否协整(p<0.05): {pvalue < 0.05}")

四、订单流预测(短期价格方向)

4.1 核心思想

订单流(Order Flow)是带符号的交易量序列:买入为正,卖出为负。

短期价格变动可以被订单流预测——大量买入会推高价格,大量卖出会推低价格。

4.2 简化模型

import numpy as np
import matplotlib.pyplot as plt
 
np.random.seed(42)
 
# ============================================================
# 订单流预测短期价格变动
# ============================================================
n = 10000
sigma = 0.001
 
# 模拟订单流(带符号的交易量)
order_flow = np.random.choice([-1, 1], n) * np.random.exponential(100, n)
 
# 注入一些自相关(模拟大单拆分、趋势跟随)
for i in range(1, n):
    order_flow[i] = 0.3 * order_flow[i-1] + 0.7 * order_flow[i]
 
# 订单流对价格的冲击
lambda_impact = 0.00001  # 价格冲击系数
price_impact = lambda_impact * order_flow
price_changes = price_impact + np.random.normal(0, sigma, n)
 
# 用过去的订单流预测未来的价格变动
window = 50
predicted_returns = []
actual_returns = []
 
for i in range(window, n - 1):
    # 过去 window 笔的累计订单流
    past_of = np.sum(order_flow[i-window:i])
    # 预测:正订单流 → 价格上涨
    predicted_returns.append(lambda_impact * past_of)
    actual_returns.append(price_changes[i])
 
predicted_returns = np.array(predicted_returns)
actual_returns = np.array(actual_returns)
 
# 评估预测能力
correlation = np.corrcoef(predicted_returns, actual_returns)[0, 1]
direction_accuracy = np.mean(np.sign(predicted_returns) == np.sign(actual_returns))
 
print(f"预测方向准确率: {direction_accuracy:.4f}")
print(f"预测值与实际值相关性: {correlation:.4f}")

五、冰山单探测

5.1 什么是冰山单

冰山单(Iceberg Order)是一种隐藏大单的方式:只显示部分数量,成交后自动补充

你看到的订单簿:
  卖一  10.02  │  100 股  ← 只显示 100 股

实际情况:
  卖一  10.02  │  10000 股  ← 隐藏了 9900 股

  每次 100 股被吃掉后,又补充 100 股
  直到 10000 股全部成交或被撤单

5.2 探测方法

def detect_iceberg(execution_prices, execution_volumes, threshold=5):
    """简化的冰山单探测
    如果同一个价格反复被成交,可能是冰山单
    """
    # 统计每个价格的成交次数
    price_counts = {}
    for p, v in zip(execution_prices, execution_volumes):
        p_rounded = round(p, 2)  # 精确到分
        if p_rounded not in price_counts:
            price_counts[p_rounded] = {'count': 0, 'total_vol': 0}
        price_counts[p_rounded]['count'] += 1
        price_counts[p_rounded]['total_vol'] += v
 
    # 如果某个价格被成交超过 threshold 次,疑似冰山单
    iceberg_candidates = {
        p: data for p, data in price_counts.items()
        if data['count'] >= threshold
    }
 
    return iceberg_candidates
 
# 模拟
np.random.seed(42)
n_executions = 1000
prices = []
volumes = []
 
# 正常成交
for _ in range(800):
    prices.append(round(10.00 + np.random.normal(0, 0.01), 2))
    volumes.append(np.random.randint(50, 500))
 
# 冰山单:价格固定 10.05,每次成交 100 股,共 30 次
for _ in range(30):
    prices.append(10.05)
    volumes.append(100)
 
candidates = detect_iceberg(prices, volumes, threshold=10)
print(f"冰山单候选:")
for p, data in candidates.items():
    print(f"  价格 {p:.2f}: 成交 {data['count']} 次, 总量 {data['total_vol']}")

六、交易所间套利

6.1 原理

同一只股票可能在多个交易所同时交易(如 A 股同时在上海和深圳),或相关资产在不同交易所交易(如期货在 CFFEX,ETF 在 SSE)。

当两个交易所的价格出现不一致时,可以同时在一个交易所买入、另一个交易所卖出。

import numpy as np
import matplotlib.pyplot as plt
 
np.random.seed(42)
 
# ============================================================
# 模拟跨交易所价差套利
# ============================================================
n = 10000
dt = 1 / 390  # 分钟
 
# 两个交易所的价格(高度相关但有微小偏差)
common_factor = np.cumsum(np.random.normal(0, 0.001, n))
price_exchange_A = 100 + common_factor + np.random.normal(0, 0.0005, n)
price_exchange_B = 100 + common_factor + np.random.normal(0, 0.0005, n)
 
# 注入随机价差偏差(模拟两个交易所的暂时不一致)
spread_deviation = np.random.normal(0, 0.003, n)
price_exchange_B += spread_deviation
 
spread = price_exchange_A - price_exchange_B
 
# 套利策略:价差超过阈值时入场
threshold = 0.005  # 0.05%
positions = np.zeros(n)
pnl = np.zeros(n)
 
for i in range(1, n):
    if spread[i] > threshold:
        # A 贵 B 便宜:做空 A,做多 B
        positions[i] = -1
        pnl[i] = pnl[i-1] - (spread[i] - spread[i-1])
    elif spread[i] < -threshold:
        # A 便宜 B 贵:做多 A,做空 B
        positions[i] = 1
        pnl[i] = pnl[i-1] + (spread[i] - spread[i-1])
    else:
        positions[i] = 0
        pnl[i] = pnl[i-1]
 
# 扣除交易成本(每边 0.001)
n_trades = np.sum(np.abs(np.diff(positions)) > 0)
total_cost = n_trades * 0.002
net_pnl = pnl - total_cost * np.arange(n) / n
 
fig, axes = plt.subplots(3, 1, figsize=(14, 10))
axes[0].plot(spread)
axes[0].axhline(threshold, color='r', linestyle='--')
axes[0].axhline(-threshold, color='r', linestyle='--')
axes[0].set_title('交易所间价差')
 
axes[1].plot(pnl, label='毛利润')
axes[1].plot(net_pnl, label='净利润')
axes[1].set_title('套利 PnL')
axes[1].legend()
 
axes[2].plot(positions)
axes[2].set_title('持仓状态')
 
plt.tight_layout()
plt.show()
 
print(f"总交易次数: {n_trades}")
print(f"总交易成本: {total_cost:.4f}")
print(f"最终毛利润: {pnl[-1]:.4f}")
print(f"最终净利润: {net_pnl[-1]:.4f}")

6.2 跨交易所套利的风险

风险描述
执行风险一边成交了另一边没成交
延迟风险两个交易所的延迟不同
制度风险涨跌停、停牌等导致一边无法交易
成本风险双边手续费可能吞噬价差

七、策略对比

策略频率容量技术门槛主要风险资金门槛
做市微秒-毫秒中等极高库存风险、逆向选择
延迟套利微秒极高竞速(军备竞赛)极高
统计套利(高频)毫秒-秒中等关系断裂中等
订单流预测毫秒-秒中等预测失效中等
冰山单探测秒-分钟误判
跨交易所套利毫秒中等执行风险中等

八、高频交易的现实挑战

8.1 延迟军备竞赛

2000 年:秒级延迟已经很快了
2005 年:毫秒级成为标配
2010 年:微秒级(10^-6 秒)是竞争前沿
2015 年:纳秒级(10^-9 秒)成为顶级机构的追求
2020 年:光速成为物理极限

顶级高频公司(如 Citadel Securities, Jump Trading, Virtu)在延迟优化上的投入:

  • Co-location:把服务器放在交易所机房里,节省光纤传输时间
  • FPGA:用硬件编程替代软件,延迟降低 10-100 倍
  • 自定义网络协议:绕过 TCP/IP 栈,直接发送裸数据包
  • 微波链路:在芝加哥和纽约之间架设微波塔(直线距离更短)

8.2 市场结构变化

  • IEX 的减速机制:故意增加 350 微秒的延迟,保护长期投资者
  • Maker-Taker 费率:不同交易所的费率结构影响策略选择
  • Tick Size 变化:最小价格变动单位影响价差和流动性
  • 暗池(Dark Pool):不在公开订单簿上显示的内部撮合平台

8.3 监管

  • 欧洲 MiFID II:要求高频交易者做市、限制无风险套利
  • 美国 SEC:对闪崩(Flash Crash)的调查和规则调整
  • 中国:程序化交易报备制度、撤单频率限制

九、本文件核心要点

策略一句话概括
做市双边挂单赚价差,核心风险是库存和逆向选择
延迟套利比别人快就能赚差价,门槛是基础设施
统计套利(高频)毫秒级协整关系,对成本极度敏感
订单流预测买卖力量对比预测短期价格方向
冰山单探测发现隐藏的大单,跟踪大资金的意图
跨交易所套利利用价差不一致,核心风险是执行

一句话总结:高频交易不是”程序化交易”的同义词,而是一系列依赖速度和技术基础设施的策略集合。对个人投资者来说,了解其原理比试图参与更重要。