3 分钟快速生成代码
输入想法,AI 即刻生成可运行代码
在PTrade量化交易平台中,fq参数主要用于历史行情获取函数(如get_history和get_price)中,用来指定数据复权选项。复权(Price Adjustment)是为了消除由于股票分红、送股、配股等除权除息事件导致的价格跳空缺口,从而保持价格走势的连续性。
根据PTrade API文档,fq参数支持以下几种选项:
'pre':前复权'post':后复权'dypre':动态前复权None:不复权(默认值)在编写策略时,可以根据需求灵活选择复权方式:
def initialize(context):
g.security = '600570.SS'
set_universe(g.security)
def handle_data(context, data):
# 1. 获取不复权数据(默认)
# 适用于查看历史真实成交价
history_none = get_history(5, '1d', 'close', security_list=g.security, fq=None)
log.info('不复权收盘价:\n%s' % history_none)
# 2. 获取前复权数据
# 适用于计算均线等技术指标
history_pre = get_history(5, '1d', 'close', security_list=g.security, fq='pre')
log.info('前复权收盘价:\n%s' % history_pre)
# 计算5日均线(必须使用复权数据)
ma5 = history_pre['close'].mean()
log.info('5日均线价格:%s' % ma5)
在绝大多数基于量价关系的技术分析策略(如双均线策略、突破策略)中,强烈建议将fq参数设置为'pre'(前复权)或'dypre'(动态前复权),以保证信号的准确性。而在需要核对历史真实账单或进行特定财务分析时,才使用None(不复权)。