🚀 AI 一键生成 qmt 策略代码

QMT 平台 get_full_tick() 函数:lastPrice 和 lastClose 有什么区别?

qmt | 发布时间: 2026/5/27
以下内容由 EasyQuant 生成。

问题描述

get_full_tick()中,lastPrice和lastClose有啥区别,lastClose是指?

get_full_tick()中,lastPrice 和 lastClose 有啥区别,lastClose 是指上一分钟的收盘价?

解决方案

在 QMT 平台的 ContextInfo.get_full_tick() 函数返回的分笔(Tick)数据字典中,lastPricelastClose 代表着完全不同的价格概念。lastClose 并不是指上一分钟的收盘价

它们的具体区别如下:

1. lastPrice (最新价)

  • 含义:指的是该标的在当前 Tick 瞬间的最新一笔成交价格
  • 动态性:在盘中交易时间,随着行情的不断推送,这个价格是实时变动的。

2. lastClose (昨收价/前收盘价)

  • 含义:指的是该标的在前一个交易日的最终收盘价(昨收价)。
  • 动态性:在整个当前的交易日内,这个数值是固定不变的。它通常被用来作为计算当日涨跌幅的基准价格。

总结与误区纠正

  • 误区:很多初学者会误以为 lastClose 是上一根 K 线(比如上一分钟)的收盘价。
  • 正解:在 Tick 级别的数据快照中,lastClose 永远代表昨收价。如果您需要获取上一分钟的收盘价,应该使用 ContextInfo.get_market_data()ContextInfo.get_history_data() 获取 1m 周期的 K 线数据,然后取倒数第二根 Bar 的 close 值。

代码示例

以下是如何在策略中获取并打印这两个值的示例:

#coding:gbk
def init(ContextInfo):
    # 设置股票池为平安银行
    ContextInfo.set_universe(['000001.SZ'])

def handlebar(ContextInfo):
    # 确保在最新行情下运行
    if not ContextInfo.is_last_bar():
        return
        
    # 获取最新分笔数据
    tick_data = ContextInfo.get_full_tick(['000001.SZ'])
    
    if '000001.SZ' in tick_data:
        stock_tick = tick_data['000001.SZ']
        last_price = stock_tick['lastPrice']
        last_close = stock_tick['lastClose']
        
        print(f"平安银行 最新价(lastPrice): {last_price}")
        print(f"平安银行 昨收价(lastClose): {last_close}")
        
        # 计算实时涨跌幅
        if last_close > 0:
            pct_change = (last_price - last_close) / last_close * 100
            print(f"当前涨跌幅: {pct_change:.2f}%")