🚀 AI 一键生成 ptrade 策略代码
立即体验

PTrade 平台如何编写公募 REITs 折溢价套利策略?(附 Python 源码)

ptrade | 发布时间: 2026/8/4
以下内容由 EasyQuant 生成。

问题描述



Title: PTrade REITs 策略:利用折溢价进行套利交易

Question: 如何编写一个基于公募 REITs 折溢价的套利策略?

解决方案

什么是公募 REITs 折溢价套利?

公募 REITs(基础设施公募基金)兼具股性和债性。由于其在二级市场的交易价格由市场供求关系决定,而其基金份额净值(NAV)由底层资产评估决定,因此二级市场交易价格经常会偏离基金净值,产生折价(Discount)溢价(Premium)

当折价率过大时(二级市场价格显著低于净值),REITs 具备较高的安全边际与套利空间,投资者可以买入等待价值回归;反之,当溢价率过高时,则可以卖出避险。在 PTrade 平台中,我们可以通过 get_reits_list() 接口动态获取全市场 REITs 标的,并结合行情数据实现自动化套利。


PTrade REITs 套利策略核心步骤

  1. 获取 REITs 标的池:在 initialize 阶段,使用 get_reits_list() 动态获取沪深两市所有的公募 REITs 代码,并使用 set_universe() 设定股票池。
  2. 获取历史与实时行情:在 handle_data 阶段,通过 get_history() 获取历史价格,计算均值作为价值中枢。
  3. 执行套利交易
    • 折价买入:当最新价格低于价值中枢一定比例(如 3%)时,判定为折价低估,执行买入。
    • 溢价卖出:当最新价格高于价值中枢一定比例(如 3%)时,判定为溢价高估,执行卖出平仓。

PTrade 策略源码实现

以下是基于 PTrade 规范编写的公募 REITs 均值回归(折溢价模拟)套利策略源码:

# -*- coding: utf-8 -*-

def initialize(context):
    # 1. 获取沪深市场所有的公募 REITs 基金代码列表
    g.reits_pool = get_reits_list()
    log.info("获取到全市场公募 REITs 数量: %d" % len(g.reits_pool))
    
    # 2. 设置策略操作的股票池
    set_universe(g.reits_pool)
    
    # 设定套利阈值
    g.buy_threshold = 0.97   # 低于均价 3% 买入
    g.sell_threshold = 1.03  # 高于均价 3% 卖出

def handle_data(context, data):
    # 遍历 REITs 标的池
    for reit in g.reits_pool:
        # 确保标的在当前行情数据中
        if reit not in data:
            continue
            
        # 3. 获取过去 10 个交易日的历史收盘价
        df = get_history(10, '1d', 'close', reit, fq=None, include=False)
        if df is None or len(df) < 10:
            continue
            
        # 计算 10 日价格均值作为价值中枢
        mean_price = df['close'].mean()
        # 获取当前最新价格
        current_price = data[reit]['close']
        
        # 获取当前持仓信息
        position = get_position(reit)
        
        # 4. 交易逻辑判断
        # 情况 A:无持仓,且价格显著低于均值(折价),买入
        if position.amount == 0 and current_price < mean_price * g.buy_threshold:
            cash = context.portfolio.cash
            # 每次分配可用资金的 10% 买入单只 REIT
            invest_value = cash * 0.1
            if invest_value > 1000:
                order_value(reit, invest_value)
                log.info("REITs [%s] 出现折价机会,当前价: %.3f, 均价: %.3f,执行买入。" % (reit, current_price, mean_price))
                
        # 情况 B:持有仓位,且价格显著高于均值(溢价),卖出平仓
        elif position.amount > 0 and current_price > mean_price * g.sell_threshold:
            order_target(reit, 0)
            log.info("REITs [%s] 出现溢价高估,当前价: %.3f, 均价: %.3f,执行卖出平仓。" % (reit, current_price, mean_price))

注意事项

  1. 流动性风险:部分公募 REITs 二级市场日内成交量较低,实盘交易时建议配合 set_volume_ratio() 限制成交比例,避免冲击成本过大。
  2. 价格精度:公募 REITs 的价格精度为小数点后三位,在手动指定 limit_price 时需注意精度处理,避免委托失败。