#qmt# qmt量化策略开发

志扬工作室

共 4118字,需浏览 9分钟

 · 2023-09-18

 文章所涉及内容更多来自网络,在此声明,并感谢知识的贡献者!

QMT简介

QMT简介

QMT 系统与其他普通股票软件最大的不同点就是其提供历史数据下载、模型编辑、模型回测、模型交易、算法交易及交易风控等完整量化交易功能。通过 QMT 系统,用户可以快速的将自己的转化为计算机代码,形成自己的交易策略,让计算机帮助用户实现策略的回测检验并实现无人值守自动化交易。

QMT资源


QMT资源

下载地址:

https://download.gjzq.com.cn/temp/organ/gjzqqmt_ceshi.rar

官方文档:

http://docs.thinktrader.net/


QMT教程

QMT教程

-简单策略示例

-- 新建策略

--策略框架

--运行说明

运行过程:

QMT策略必须实现 两个接口:init()与 handlebar() 。系统首先调用 init() 方法,随后在每根 K 线上调用一次 handlebar() 。

QMT 系统的模型是根据行情驱动,逐K 线运行,每根 K 线调用一次 Python 模型中的 handlebar(ContextInfo) 函数。

根据选择的运行周期不同,handlebar(ContextInfo) 函数的运行次数也不同。如选择在日线上运行策略,则 handlebar(ContextInfo) 函数每天被调用一次(盘中虽会每个tick 调用一次,但只有最后一个 tick 才会判定交易函数是否被调用)。

运行机制:

当用户在 Python平台编写好自己的策略后,可以点击【运行】按钮来运行脚本。界面层在向下层请求数据的过程中,会首先创建一个 Python 模型,这个模型关联当前界面运行的产品。模型创建完毕后,加载用户编写的Python 脚本,并调用 init() 初始化函数。模型运行所需的数据也在此时向下层发出请求。下层在接收到请求后,会向服务器请求行情数据,并组织好数据格式。Python 模型根据返回的数据,运行 handlebar() ,用户可以用 paint() 方法将希望显示的计算结果输出到界面上,界面会将输出结果展示出来。


QMT概念


相关概念:

-数据 Tick 和 Bar

把单根 K 线称之为 Bar,每根 Bar 由 tick(分笔)组成。

-Init函数

init是一个Python模型的初始化方法。在模型加载的时候,系统会调用init方法,做一些必要的初始化,比如初始化股票池、初始化资金账号、初始化全局变量等。如果用户的模型无需做初始化,可以在方法体中写pass,但方法的定义必须存在,否则模型的运行会报错。

-handlebar函数

handlebar 是整个Python 模型中的核心执行函数。当模型从数据层获取到运行所需要的数据之后,会对数据集上的每一根 bar,调用一次 handlebar 函数,处理当前这根 bar 上的数据。也就是说,用户模型的核心逻辑都是写在该函数中的,如获取数据,设置下单条件等。在 handlebar 中处理完数据后,用户可以通过 paint 方法将需要绘图输出的结果返回给界面。界面会将输出结果如实的展示出来。

-ContextINfo

ContextInfo 是整个Python 框架中的一个核心对象。它包含了各种与 Python 底层框架交互的 API 方法,也是一个全局的上下文环境,可以在 init 以及 handlebar 这两个函数中自由地传递用户创建的各种自定义数据。

ContextINfo的属性

['__class__', '__deepcopy__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'barpos', 'benchmark', 'bsm_iv', 'bsm_price', 'capital', 'context', 'create_sector', 'current_bar', 'data_info_level', 'dividend_type', 'do_back_test', 'draw_icon', 'draw_number', 'draw_text', 'draw_vertline', 'end', 'get_ETF_list', 'get_all_subscription', 'get_back_test_index', 'get_bar_timetag', 'get_bvol', 'get_close_price', 'get_commission', 'get_contract_expire_date', 'get_contract_multiplier', 'get_date_location', 'get_divid_factors', 'get_factor_data', 'get_finance', 'get_financial_data', 'get_float_caps', 'get_full_tick', 'get_function_line', 'get_his_contract_list', 'get_his_index_data', 'get_his_st_data', 'get_history_data', 'get_hkt_details', 'get_hkt_statistics', 'get_holder_num', 'get_industry', 'get_instrumentdetail', 'get_largecap', 'get_last_close', 'get_last_volume', 'get_local_data', 'get_longhubang', 'get_main_contract', 'get_market_data', 'get_market_data_ex', 'get_market_data_ex_ori', 'get_midcap', 'get_net_value', 'get_north_finance_change', 'get_open_date', 'get_option_detail_data', 'get_option_iv', 'get_option_list', 'get_option_undl', 'get_option_undl_data', 'get_product_asset_value', 'get_product_init_share', 'get_product_share', 'get_raw_financial_data', 'get_risk_free_rate', 'get_scale_and_rank', 'get_scale_and_stock', 'get_sector', 'get_slippage', 'get_smallcap', 'get_stock_list_in_sector', 'get_stock_name', 'get_stock_type', 'get_svol', 'get_tick_timetag', 'get_top10_share_holder', 'get_total_share', 'get_tradedatafromerds', 'get_trading_dates', 'get_turn_over_rate', 'get_turnover_rate', 'get_universe', 'get_weight_in_index', 'in_pythonworker', 'is_fund', 'is_future', 'is_last_bar', 'is_new_bar', 'is_stock', 'is_suspended_stock', 'load_stk_list', 'load_stk_vol_list', 'market', 'paint', 'period', 'refresh_rate', 'request_id', 'run_time', 'set_account', 'set_commission', 'set_slippage', 'set_universe', 'start', 'stockcode', 'stockcode_in_rzrk', 'subMap', 'subscribe_quote', 'subscribe_whole_quote', 'time_tick_size', 'unsubscribe_quote', 'z8sglma_last_barpos', 'z8sglma_last_version']

主要函数

Paint

用户可以通过 paint 方法将需要绘图输出的结果返回给界面。界面会将输出结果如实的展示出来。


浏览 318
点赞
评论
收藏
分享

手机扫一扫分享

举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

举报