qteasy


Nameqteasy JSON
Version 1.2.6 PyPI version JSON
download
home_pagehttps://github.com/shepherdpp/qteasy
SummaryA fast quantitative investment tool kit
upload_time2024-05-07 01:42:24
maintainerJackie PENG
docs_urlNone
authorJackie PENG
requires_python<3.13,>=3.6
licenseCopyright <2019> <JACKIE PENG> Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
keywords quantitative investment quantitative trading stock finance investment
VCS
bugtrack_url
requirements pandas numpy numba tushare mplfinance rich pytz matplotlib requests setuptools textual
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # `qteasy` -- 一个本地化、灵活易用的高效量化投资工具包

![PyPI](https://img.shields.io/pypi/v/qteasy)
![PyPI - Wheel](https://img.shields.io/pypi/wheel/qteasy)
[![Build Status](https://app.travis-ci.com/shepherdpp/qteasy.svg?branch=master)](https://app.travis-ci.com/shepherdpp/qteasy)
[![Documentation Status](https://readthedocs.org/projects/qteasy/badge/?version=latest)](https://qteasy.readthedocs.io/zh/latest/?badge=latest)
![GitHub](https://img.shields.io/github/license/shepherdpp/qteasy)
![GitHub repo size](https://img.shields.io/github/repo-size/shepherdpp/qteasy)
![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/shepherdpp/qteasy)
![GitHub top language](https://img.shields.io/github/languages/top/shepherdpp/qteasy)
![PyPI - Implementation](https://img.shields.io/pypi/implementation/qteasy)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/qteasy)
![GitHub branch checks state](https://img.shields.io/github/checks-status/shepherdpp/qteasy/master)
![GitHub commit activity](https://img.shields.io/github/commit-activity/m/shepherdpp/qteasy)
![GitHub issues](https://img.shields.io/github/issues/shepherdpp/qteasy)
![GitHub last commit](https://img.shields.io/github/last-commit/shepherdpp/qteasy)
![GitHub contributors](https://img.shields.io/github/contributors/shepherdpp/qteasy)
![PyPI - Downloads](https://img.shields.io/pypi/dm/qteasy)
![PyPI - Downloads](https://img.shields.io/pypi/dw/qteasy)
![GitHub Repo stars](https://img.shields.io/github/stars/shepherdpp/qteasy?style=social)
![GitHub forks](https://img.shields.io/github/forks/shepherdpp/qteasy?style=social)
![GitHub watchers](https://img.shields.io/github/watchers/shepherdpp/qteasy?style=social)
![GitHub followers](https://img.shields.io/github/followers/shepherdpp?style=social)
![GitHub Sponsors](https://img.shields.io/github/sponsors/shepherdpp?style=social)


- [`qteasy`能做什么](#qteasy能做什么?)
- [安装](#安装)
- [QTEASY文档](#文档)
- [10分钟了解Qteasy的功能](#10分钟了解QTEASY的功能)
  - [初始配置——本地数据源](#配置本地数据源)
  - [下载股票价格并可视化](#下载金融历史数据)
  - [创建投资策略](#创建一个投资策略)
  - [投资策略的回测和评价](#回测并评价交易策略的性能表现)
  - [投资策略的优化](#交易策略的参数调优)
  - [投资策略的实盘运行](#部署并开始交易策略的实盘运行)

> Note:
> 
> 目前`qteays`正处于密集开发测试阶段,软件中不免存在一些漏洞和bug,如果大家使用中出现问题,欢迎[Issue-报告bug](https://github.com/shepherdpp/qteasy/issues/new?assignees=&labels=&projects=&template=bug-report---bug报告.md&title=)或者[提交新功能需求](https://github.com/shepherdpp/qteasy/issues/new?assignees=&labels=&projects=&template=feature-request---新功能需求.md&title=)给我,也可以进入[讨论区](https://github.com/shepherdpp/qteasy/discussions)参与讨论。也欢迎各位贡献代码!
>
> 我会尽快修复问题并回复大家的问题。

## 关于`qteasy`

- 作者: **Jackie PENG**
- email: *jackie_pengzhao@163.com*
- Created: 2019, July, 16
- Latest Version: `1.2.6`
- License: BSD 3-Clause License

`qteasy`是为量化交易人员开发的一套量化交易工具包,特点如下:

1. **全流程覆盖** 从金融数据获取、存储,到交易策略的开发、回测、优化、实盘运行
2. **完全本地化** 所有的金融数据、策略运算和优化过程完全本地化,不依赖于任何云端服务
3. **使用简单** 提供大量内置交易策略,用户可以搭积木式地创建自己的交易策略
4. **灵活多变** 使用`qteasy`提供的策略类,用户可以自行创建自己的交易策略,灵活设置可调参数

## `qteasy`能做什么?


### **金融历史数据**: 

- 获取、清洗、本地存储大量金融历史数据
- 检索、处理、调用本地数据
- 本地金融数据可视化

![png](docs/source/img/output_5_2.png)

### **创建交易策略**

- 提供几十种内置交易策略,可以直接搭积木式使用
- 快速创建自定义交易策略,灵活设置可调参数
- 交易策略的回测、优化、评价,可视化输出回测结果

![png](docs/source/img/output_14_3.png)

### **实盘交易模拟**
- 读取实时市场数据,实盘运行交易策略
- 生成交易信号,模拟交易结果
- 跟踪记录交易日志、股票持仓、账户资金变化等信息
- 随时查看交易过程,检查盈亏情况
- 手动控制交易进程、调整交易参数,手动下单

![png](docs/source/examples/img/trader_app_1.png)  
![png](docs/source/examples/img/trader_app_2.png)  
![png](docs/source/examples/img/trader_app_light_theme.png) 

## 安装

```bash
$ pip install qteasy
```

## 文档

关于`QTEASY`系统的更多详细解释和使用方法,请参阅[QTEASY文档](https://qteasy.readthedocs.io):


### python 版本
- *`python` version >= 3.6, < 3.13* 

### 安装可选依赖包

`qteasy`所有必要的依赖包都可以在`pip`安装的同时安装好,但某些特殊情况下,您需要在安装时指定可选依赖包,以便在安装`qteasy`时同时安装,或者手动安装依赖包:

- **`pymysql`**, 用于连接`MySQL`数据库,将本地数据存储到`MySQL`数据库(`qteasy`默认使用`csv`文件作为本地数据源,但数据量大时推荐使用`mysql`数据库,详情参见[qteasy使用教程](https://qteasy.readthedocs.io))
`pymysql`可以在安装`qteasy`时自动安装,也可以手动安装:
    ```bash
    $ pip install 'qteasy[database]'  # 安装qteasy时自动安装pymysql
    $ pip install pymysql  # 手动安装pymysql
    ```
- **`pyarrow`**, 用于操作`feather`文件,将本地数据存储为`feather`文件,`pyarrow`可以在安装`qteasy`时自动安装,也可以手动安装:
    ```bash
    $ pip install 'qteasy[feather]'  # 安装qteasy时自动安装pyarrow
    $ pip install pyarrow  # 手动安装pyarrow
    ```
- **`pytables`**, 用于操作`HDF`文件,将本地数据存储到`HDF`文件,`pytables`不能自动安装,需要使用`conda`手动安装`pytables`:
    ```bash
    $ conda install pytables  # 安装pytables
    ```
- **`ta-lib`**, 以便使用所有的内置交易策略,下面的方法可以安装`ta-lib API`,但它还依赖C语言的`TA-Lib`包,安装方法请参考[FAQ](https://qteasy.readthedocs.io/zh/latest/faq.html#id2)
    ```bash
    $ pip install 'qteasy[talib]'  # 安装qteasy时自动安装ta-lib
    $ pip install ta-lib  # 手动安装ta-lib
    ```

##  10分钟了解qteasy的功能

### 导入`qteasy`
基本的模块导入方法如下

```python
import qteasy as qt
qt.__version__
```

### 配置本地数据源

为了使用`qteasy`,需要大量的金融历史数据,所有的历史数据都必须首先保存在本地,如果本地没有历史数据,那么`qteasy`的许多功能就无法执行。

`qteasy`默认通过`tushare`金融数据包来获取大量的金融数据,用户需要自行申请API Token,获取相应的权限和积分(详情参考:https://tushare.pro/document/2)

因此,在使用`qteasy`之前需要对本地数据源和`tushare`进行必要的配置。在`QT_ROOT_PATH/qteasy/`路径下打开配置文件`qteasy.cfg`,可以看到下面内容:

```
# qteasy configuration file
# following configurations will be loaded when initialize qteasy

# example:
# local_data_source = database
```
#### 配置`tushare token`

将你获得的tushare API token添加到配置文件中,如下所示:


``` commandline
tushare_token = <你的tushare API Token> 
```
#### 配置本地数据源 —— 用MySQL数据库作为本地数据源
默认情况下`qteasy`使用存储在`data/`路径下的`.csv`文件作为数据源,不需要特殊设置。
如果设置使用`mysql`数据库作为本地数据源,在配置文件中添加以下配置:

```text
local_data_source = database  

local_db_host = <host name>
local_db_port = <port number>
local_db_user = <user name>
local_db_password = <password>
local_db_name = <database name>
```

关闭并保存好配置文件后,重新导入`qteasy`,就完成了数据源的配置,可以开始下载数据到本地了。

### 下载金融历史数据 

要下载金融价格数据,使用`qt.refill_data_source()`函数。下面的代码下载2021及2022两年内所有股票、所有指数的日K线数据,同时下载所有的股票和基金的基本信息数据。
(根据网络速度,下载数据可能需要十分钟左右的时间,如果存储为csv文件,将占用大约200MB的磁盘空间):

```python
qt.refill_data_source(
        tables=['stock_daily',   # 股票的日线价格
                'index_daily',   # 指数的日线价格
                'basics'],       # 股票和基金的基本信息
        start_date='20210101',  # 下载数据的起止时间
        end_date='20221231',  
)
```

数据下载到本地后,可以使用`qt.get_history_data()`来获取数据,如果同时获取多个股票的历史数据,每个股票的历史数据会被分别保存到一个`dict`中。

```python
qt.get_history_data(htypes='open, high, low, close', 
                    shares='000001.SZ, 000300.SH',
                    start='20210101',
                    end='20210115')
```
运行上述代码会得到一个`Dict`对象,包含两个股票"000001.SZ"以及"000005.SZ"的K线数据(数据存储为`DataFrame`):
```
{'000001.SZ':
              open   high    low  close
 2021-01-04  19.10  19.10  18.44  18.60
 2021-01-05  18.40  18.48  17.80  18.17
 2021-01-06  18.08  19.56  18.00  19.56
 ... 
 2021-01-13  21.00  21.01  20.40  20.70
 2021-01-14  20.68  20.89  19.95  20.17
 2021-01-15  21.00  21.95  20.82  21.00,
 
 '000300.SH':
                  open       high        low      close
 2021-01-04  5212.9313  5284.4343  5190.9372  5267.7181
 2021-01-05  5245.8355  5368.5049  5234.3775  5368.5049
 2021-01-06  5386.5144  5433.4694  5341.4304  5417.6677
 ...
 2021-01-13  5609.2637  5644.7195  5535.1435  5577.9711
 2021-01-14  5556.2125  5568.0179  5458.6818  5470.4563
 2021-01-15  5471.3910  5500.6348  5390.2737  5458.0812}
```
除了价格数据以外,`qteasy`还可以下载并管理包括财务报表、技术指标、基本面数据等在内的大量金融数据,详情请参见[qteasy文档](https://qteasy.readthedocs.io)

股票的数据下载后,使用`qt.candle()`可以显示股票数据K线图。

```python
import qteasy as qt
data = qt.candle('000300.SH', start='2021-06-01', end='2021-8-01', asset_type='IDX')
```

![png](docs/source/img/output_5_2.png)
    
`qteasy`的K线图函数`candle`支持通过六位数股票/指数代码查询准确的证券代码,也支持通过股票、指数名称显示K线图
`qt.candle()`支持功能如下:
- 显示股票、基金、期货的K线
- 显示复权价格
- 显示分钟、 周或月K线 
- 显示不同移动均线以及MACD/KDJ等指标

详细的用法请参考文档,示例如下(请先使用`qt.refill_data_source()`下载相应的历史数据):


```python
import qteasy as qt
# 场内基金的小时K线图
qt.candle('159601', start = '20220121', freq='h')
# 沪深300指数的日K线图
qt.candle('000300', start = '20200121')
# 股票的30分钟K线,复权价格
qt.candle('中国电信', start = '20211021', freq='30min', adj='b')
# 期货K线,三条移动均线分别为9天、12天、26天
qt.candle('沪铜主力', start = '20211021', mav=[9, 12, 26])
# 场外基金净值曲线图,复权净值,不显示移动均线
qt.candle('000001.OF', start='20200101', asset_type='FD', adj='b', mav=[])
```

![png](docs/source/img/output_3_1.png)

![png](docs/source/img/output_7_2.png)

![png](docs/source/img/output_8_3.png)

![png](docs/source/img/output_3_4.png)

![png](docs/source/img/output_3_5.png)
    

生成的K线图可以是一个交互式动态K线图(请注意,K线图基于`matplotlib`绘制,在使用不同的终端时,显示功能有所区别,某些终端并不支持
动态图表,详情请参阅 [matplotlib文档](https://matplotlib.org/stable/users/explain/backends.html)


在使用动态K线图时,用户可以用鼠标和键盘控制K线图的显示范围:

- 鼠标在图表上左右拖动:可以移动K线图显示更早或更晚的K线
- 鼠标滚轮在图表上滚动,可以缩小或放大K线图的显示范围
- 通过键盘左右方向键,可以移动K线图的显示范围显示更早或更晚的K线
- 通过键盘上下键,可以缩小或放大K线图的显示范围
- 在K线图上双击鼠标,可以切换不同的均线类型
- 在K线图的指标区域双击,可以切换不同的指标类型:MACD,RSI,DEMA

![gif](docs/source/img/output_dyna_plot.gif)

关于`DataSource`对象的更多详细介绍,请参见[qteasy文档](https://qteasy.readthedocs.io)


###  创建一个投资策略

`qteasy`中的所有交易策略都是由`qteast.Operator`(交易员)对象来实现回测和运行的,`Operator`对象是一个策略容器,一个交易员可以同时
管理多个不同的交易策略。

`queasy`提供了两种方式创建交易策略,详细的说明请参见使用教程:

- **使用内置交易策略组合**
- **通过策略类自行创建策略**

#### 生成一个DMA均线择时交易策略
在这里,我们将使用一个内置的`DMA`均线择时策略来生成一个最简单的大盘择时交易系统。所有内置交易策略的清单和详细说明请参见文档。

创建`Operator`对象时传入参数:`strategies='DMA'`,可以新建一个`DMA`双均线择时交易策略。
创建好`Operator`对象后,可以用`op.info()`来查看它的信息。

```python
import qteasy as qt

op = qt.Operator(strategies='dma')
op.info()
```
现在可以看到`op`中有一个交易策略,ID是`dma`,我们在`Operator`层面设置或修改策略的参数
时,都需要引用这个`ID`。

`DMA`是一个内置的均线择时策略,它通过计算股票每日收盘价的快、慢两根移动均线的差值`DMA`与其移动平均值`AMA`之间的交叉情况来确定多空或买卖点。:

使用qt.built_ins()函数可以查看DMA策略的详情,例如:
```python
import qteasy as qt
qt.built_ins('dma')
```
得到:

```
 DMA择时策略

    策略参数:
        s, int, 短均线周期
        l, int, 长均线周期
        d, int, DMA周期
    信号类型:
        PS型:百分比买卖交易信号
    信号规则:
        在下面情况下产生买入信号:
        1, DMA在AMA上方时,多头区间,即DMA线自下而上穿越AMA线后,输出为1
        2, DMA在AMA下方时,空头区间,即DMA线自上而下穿越AMA线后,输出为0
        3, DMA与股价发生背离时的交叉信号,可信度较高

    策略属性缺省值:
    默认参数:(12, 26, 9)
    数据类型:close 收盘价,单数据输入
    采样频率:天
    窗口长度:270
    参数范围:[(10, 250), (10, 250), (8, 250)]
    策略不支持参考数据,不支持交易数据
```
在默认情况下,策略有三个**可调参数**:`(12,26,9)`, 但我们可以给出任意大于2小于250的三个整数作为策略的参数,以适应不同交易活跃度的股票、或者适应
不同的策略运行周期。


### 回测并评价交易策略的性能表现
queasy可以使用历史数据回测策略表现并输出图表如下:
![png](https://raw.githubusercontent.com/shepherdpp/qteasy/master/docs/source/img/output_14_3.png)

使用默认参数回测刚才建立的DMA策略在历史数据上的表现,可以使用`op.run()`。

```python
import qteasy as qt

op = qt.Operator(strategies='dma')
res = op.run(
        mode=1,                         # 历史回测模式
        asset_pool='000300.SH',         # 投资资产池,即允许投资的股票或指数,此处为沪深300指数
        asset_type='IDX',               # 投资资产类型,IDX表示指数,E表示股票
        invest_cash_amounts=[100000],   # 初始投资资金,此处为10万元
        invest_start='20220501',        # 投资回测开始日期
        invest_end='20221231',          # 投资回测结束日期
        cost_rate_buy=0.0003,           # 买入费率,此处为0.03%
        cost_rate_sell=0.0001,          # 卖出费率,此处为0.01%
        visual=True,                    # 打印可视化回测图表
        trade_log=True                  # 打印交易日志
)
```
输出结果如下:
```
     ====================================
     |                                  |
     |       BACK TESTING RESULT        |
     |                                  |
     ====================================

qteasy running mode: 1 - History back testing
time consumption for operate signal creation: 4.4 ms
time consumption for operation back looping:  82.5 ms

investment starts on      2022-05-05 00:00:00
ends on                   2022-12-30 00:00:00
Total looped periods:     0.7 years.

-------------operation summary:------------
Only non-empty shares are displayed, call 
"loop_result["oper_count"]" for complete operation summary

          Sell Cnt Buy Cnt Total Long pct Short pct Empty pct
000300.SH    6        6      12   56.4%      0.0%     43.6%   

Total operation fee:     ¥      257.15
total investment amount: ¥  100,000.00
final value:              ¥  105,773.09
Total return:                     5.77% 
Avg Yearly return:                8.95%
Skewness:                          0.58
Kurtosis:                          3.54
Benchmark return:                -3.46% 
Benchmark Yearly return:         -5.23%

------strategy loop_results indicators------ 
alpha:                            0.142
Beta:                             1.003
Sharp ratio:                      0.637
Info ratio:                       0.132
250 day volatility:               0.138
Max drawdown:                    11.92% 
    peak / valley:        2022-08-17 / 2022-10-31
    recovered on:         Not recovered!

===========END OF REPORT=============
```
![png](docs/source/img/output_21_1.png)

### 交易策略的参数调优

交易策略的表现与参数有关,如果输入不同的参数,策略回报相差会非常大。`qteasy`可以用多种不同的优化算法,帮助搜索最优的策略参数,

要使用策略优化功能,需要设置交易策略的优化标记`opt_tag=1`,并配置环境变量`mode=2`即可:

```python
import qteasy as qt

op = qt.Operator(strategies='dma')
op.set_parameter('dma', opt_tag=1)
res = op.run(mode=2,                    # 优化模式
             opti_start='20220501',     # 优化区间开始日期
             opti_end='20221231',       # 优化区间结束日期
             test_start='20220501',     # 测试区间开始日期
             test_end='20221231',       # 测试区间结束日期
             opti_sample_count=1000,    # 优化样本数量
             visual=True,               # 打印优化结果图表
             parallel=False)            # 不使用并行计算
```

`qteasy`将在同一段历史数据(优化区间)上反复回测,找到结果最好的30组参数,并把这30组参数在另一段历史数据(测试区间)上进行独立测试,并显
示独立测试的结果:
```commandline
==================================== 
|                                  |
|       OPTIMIZATION RESULT        |
|                                  |
====================================

qteasy running mode: 2 - Strategy Parameter Optimization

... # 省略部分输出

# 以下是30组优化的策略参数及其结果(部分结果省略)
    Strategy items Sell-outs Buy-ins ttl-fee     FV      ROI  Benchmark rtn MDD 
0     (35, 69, 60)     1.0      2.0    71.45 106,828.20  6.8%     -3.5%     9.5%
1   (124, 104, 18)     3.0      2.0   124.86 106,900.59  6.9%     -3.5%     7.4%
2   (126, 120, 56)     1.0      1.0    72.38 107,465.86  7.5%     -3.5%     7.5%
...
27   (103, 84, 70)     1.0      1.0    74.84 114,731.44 14.7%     -3.5%     8.8%
28  (143, 103, 49)     1.0      1.0    74.33 116,453.26 16.5%     -3.5%     4.3%
29   (129, 92, 56)     1.0      1.0    74.55 118,811.58 18.8%     -3.5%     4.3%

===========END OF REPORT=============
```

![png](docs/source/img/output_24_1.png)   
将优化后的参数应用到策略中,并再次回测,可以看到结果明显提升:

```python
op.set_parameter('dma', pars=(143, 99, 32))
res = op.run(
        mode=1,                         # 历史回测模式
        asset_pool='000300.SH',         # 投资资产池
        asset_type='IDX',               # 投资资产类型
        invest_cash_amounts=[100000],   # 投资资金
        invest_start='20220501',        # 投资回测开始日期
        invest_end='20221231',          # 投资回测结束日期
        cost_rate_buy=0.0003,           # 买入费率
        cost_rate_sell=0.0001,          # 卖出费率
        visual=True,                    # 打印可视化回测图表
        trade_log=True,                 # 打印交易日志
)
```
结果如下:

![png](docs/source/img/output_26_1.png)   


关于策略优化结果的更多解读、以及更多优化参数的介绍,请参见详细文档

### 部署并开始交易策略的实盘运行

在配置好Operator对象并设置好策略后,`qteasy`可以自动定期运行、自动盯盘、自动下载实时数据并根据策略结果生成交易指令,模拟交易过程并记录交易结果。

在`Operator`中设置好交易策略,并配置好交易参数后,可以直接启动实盘交易:

```python
import qteasy as qt

# 创建一个交易策略alpha
alpha = qt.get_built_in_strategy('ndayrate')  # 创建一个N日股价涨幅交易策略

# 设置策略的运行参数
alpha.strategy_run_freq = 'd'  # 每日运行
alpha.data_freq = 'd' # 策略使用日频数据
alpha.window_length = 20  # 数据窗口长度
alpha.sort_ascending = False  # 优先选择涨幅最大的股票
alpha.condition = 'greater'  # 筛选出涨幅大于某一个值的股票
alpha.ubound = 0.005  # 筛选出涨幅大于0.5%的股票
alpha.sel_count = 7  # 每次选出7支股票

# 创建一个交易员对象,运行alpha策略
op = qt.Operator(alpha, signal_type='PT', op_type='step')

# 设置策略运行参数
# 交易股票池包括所有的银行股和家用电器股
asset_pool = qt.filter_stock_codes(industry='银行, 家用电器', exchange='SSE, SZSE')

qt.configure(
        mode=0,  # 交易模式为实盘运行
        asset_type='E',  # 交易的标的类型为股票
        asset_pool=asset_pool,  # 交易股票池为所有银行股和家用电器股
        trade_batch_size=100,  # 交易批量为100股的整数倍
        sell_batch_size=1,  # 卖出数量为1股的整数倍
        live_trade_account_id=1,  # 实盘交易账户ID
        live_trade_account='user name',  # 实盘交易用户名
        live_trade_ui_type='tui',  # 使用TUI界面监控实盘交易,默认使用CLI界面
)

qt.run(op)
```
`qteasy`的实盘运行程序实际上是一个定时任务触发器,它能定时触发运行交易策略,提交策略到模拟交易Broker,并读取实时价格,模拟成交并自动记录交易过程。

为了对策略运行过程进行监控,同时与`qteasy`进行互动,`qteasy`提供了两种不同的交互界面:

- **`TraderShell`** 交互式命令行界面,可以在命令行中输入命令,查看交易日志、查看持仓、查看账户资金变化等信息:
![png](docs/source/img/output_27_1.png)  
![png](docs/source/img/output_27_3.png) 
- **`TraderApp`** (v1.2.0新增) 交互式图形界面,可以在图形界面中查看交易日志、查看持仓、查看账户资金变化等信息
![png](docs/source/examples/img/trader_app_light_theme.png) 
![png](docs/source/examples/img/trader_app_2.png) 

上面两种方式都可以在实盘运行时使用,根据qteasy的配置参数进入不同的交互界,关于更多实盘运行的介绍,请参见[`QTEASY`文档](https://qteasy.readthedocs.io)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/shepherdpp/qteasy",
    "name": "qteasy",
    "maintainer": "Jackie PENG",
    "docs_url": null,
    "requires_python": "<3.13,>=3.6",
    "maintainer_email": "jackie PENG <jackie.pengzhao@gmail.com>",
    "keywords": "quantitative investment, quantitative trading, stock, finance, investment",
    "author": "Jackie PENG",
    "author_email": "jackie PENG <jackie.pengzhao@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/6a/dc/61472d34e27f3acf09c39b57d4eab894e28eb8bfbabb963a664bb9b668fe/qteasy-1.2.6.tar.gz",
    "platform": null,
    "description": "# `qteasy` -- \u4e00\u4e2a\u672c\u5730\u5316\u3001\u7075\u6d3b\u6613\u7528\u7684\u9ad8\u6548\u91cf\u5316\u6295\u8d44\u5de5\u5177\u5305\n\n![PyPI](https://img.shields.io/pypi/v/qteasy)\n![PyPI - Wheel](https://img.shields.io/pypi/wheel/qteasy)\n[![Build Status](https://app.travis-ci.com/shepherdpp/qteasy.svg?branch=master)](https://app.travis-ci.com/shepherdpp/qteasy)\n[![Documentation Status](https://readthedocs.org/projects/qteasy/badge/?version=latest)](https://qteasy.readthedocs.io/zh/latest/?badge=latest)\n![GitHub](https://img.shields.io/github/license/shepherdpp/qteasy)\n![GitHub repo size](https://img.shields.io/github/repo-size/shepherdpp/qteasy)\n![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/shepherdpp/qteasy)\n![GitHub top language](https://img.shields.io/github/languages/top/shepherdpp/qteasy)\n![PyPI - Implementation](https://img.shields.io/pypi/implementation/qteasy)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/qteasy)\n![GitHub branch checks state](https://img.shields.io/github/checks-status/shepherdpp/qteasy/master)\n![GitHub commit activity](https://img.shields.io/github/commit-activity/m/shepherdpp/qteasy)\n![GitHub issues](https://img.shields.io/github/issues/shepherdpp/qteasy)\n![GitHub last commit](https://img.shields.io/github/last-commit/shepherdpp/qteasy)\n![GitHub contributors](https://img.shields.io/github/contributors/shepherdpp/qteasy)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/qteasy)\n![PyPI - Downloads](https://img.shields.io/pypi/dw/qteasy)\n![GitHub Repo stars](https://img.shields.io/github/stars/shepherdpp/qteasy?style=social)\n![GitHub forks](https://img.shields.io/github/forks/shepherdpp/qteasy?style=social)\n![GitHub watchers](https://img.shields.io/github/watchers/shepherdpp/qteasy?style=social)\n![GitHub followers](https://img.shields.io/github/followers/shepherdpp?style=social)\n![GitHub Sponsors](https://img.shields.io/github/sponsors/shepherdpp?style=social)\n\n\n- [`qteasy`\u80fd\u505a\u4ec0\u4e48](#qteasy\u80fd\u505a\u4ec0\u4e48\uff1f)\n- [\u5b89\u88c5](#\u5b89\u88c5)\n- [QTEASY\u6587\u6863](#\u6587\u6863)\n- [10\u5206\u949f\u4e86\u89e3Qteasy\u7684\u529f\u80fd](#10\u5206\u949f\u4e86\u89e3QTEASY\u7684\u529f\u80fd)\n  - [\u521d\u59cb\u914d\u7f6e\u2014\u2014\u672c\u5730\u6570\u636e\u6e90](#\u914d\u7f6e\u672c\u5730\u6570\u636e\u6e90)\n  - [\u4e0b\u8f7d\u80a1\u7968\u4ef7\u683c\u5e76\u53ef\u89c6\u5316](#\u4e0b\u8f7d\u91d1\u878d\u5386\u53f2\u6570\u636e)\n  - [\u521b\u5efa\u6295\u8d44\u7b56\u7565](#\u521b\u5efa\u4e00\u4e2a\u6295\u8d44\u7b56\u7565)\n  - [\u6295\u8d44\u7b56\u7565\u7684\u56de\u6d4b\u548c\u8bc4\u4ef7](#\u56de\u6d4b\u5e76\u8bc4\u4ef7\u4ea4\u6613\u7b56\u7565\u7684\u6027\u80fd\u8868\u73b0)\n  - [\u6295\u8d44\u7b56\u7565\u7684\u4f18\u5316](#\u4ea4\u6613\u7b56\u7565\u7684\u53c2\u6570\u8c03\u4f18)\n  - [\u6295\u8d44\u7b56\u7565\u7684\u5b9e\u76d8\u8fd0\u884c](#\u90e8\u7f72\u5e76\u5f00\u59cb\u4ea4\u6613\u7b56\u7565\u7684\u5b9e\u76d8\u8fd0\u884c)\n\n> Note:\n> \n> \u76ee\u524d`qteays`\u6b63\u5904\u4e8e\u5bc6\u96c6\u5f00\u53d1\u6d4b\u8bd5\u9636\u6bb5\uff0c\u8f6f\u4ef6\u4e2d\u4e0d\u514d\u5b58\u5728\u4e00\u4e9b\u6f0f\u6d1e\u548cbug\uff0c\u5982\u679c\u5927\u5bb6\u4f7f\u7528\u4e2d\u51fa\u73b0\u95ee\u9898\uff0c\u6b22\u8fce[Issue-\u62a5\u544abug](https://github.com/shepherdpp/qteasy/issues/new?assignees=&labels=&projects=&template=bug-report---bug\u62a5\u544a.md&title=)\u6216\u8005[\u63d0\u4ea4\u65b0\u529f\u80fd\u9700\u6c42](https://github.com/shepherdpp/qteasy/issues/new?assignees=&labels=&projects=&template=feature-request---\u65b0\u529f\u80fd\u9700\u6c42.md&title=)\u7ed9\u6211\uff0c\u4e5f\u53ef\u4ee5\u8fdb\u5165[\u8ba8\u8bba\u533a](https://github.com/shepherdpp/qteasy/discussions)\u53c2\u4e0e\u8ba8\u8bba\u3002\u4e5f\u6b22\u8fce\u5404\u4f4d\u8d21\u732e\u4ee3\u7801\uff01\n>\n> \u6211\u4f1a\u5c3d\u5feb\u4fee\u590d\u95ee\u9898\u5e76\u56de\u590d\u5927\u5bb6\u7684\u95ee\u9898\u3002\n\n## \u5173\u4e8e`qteasy`\n\n- \u4f5c\u8005: **Jackie PENG**\n- email: *jackie_pengzhao@163.com*\n- Created: 2019, July, 16\n- Latest Version: `1.2.6`\n- License: BSD 3-Clause License\n\n`qteasy`\u662f\u4e3a\u91cf\u5316\u4ea4\u6613\u4eba\u5458\u5f00\u53d1\u7684\u4e00\u5957\u91cf\u5316\u4ea4\u6613\u5de5\u5177\u5305\uff0c\u7279\u70b9\u5982\u4e0b\uff1a\n\n1. **\u5168\u6d41\u7a0b\u8986\u76d6** \u4ece\u91d1\u878d\u6570\u636e\u83b7\u53d6\u3001\u5b58\u50a8\uff0c\u5230\u4ea4\u6613\u7b56\u7565\u7684\u5f00\u53d1\u3001\u56de\u6d4b\u3001\u4f18\u5316\u3001\u5b9e\u76d8\u8fd0\u884c\n2. **\u5b8c\u5168\u672c\u5730\u5316** \u6240\u6709\u7684\u91d1\u878d\u6570\u636e\u3001\u7b56\u7565\u8fd0\u7b97\u548c\u4f18\u5316\u8fc7\u7a0b\u5b8c\u5168\u672c\u5730\u5316\uff0c\u4e0d\u4f9d\u8d56\u4e8e\u4efb\u4f55\u4e91\u7aef\u670d\u52a1\n3. **\u4f7f\u7528\u7b80\u5355** \u63d0\u4f9b\u5927\u91cf\u5185\u7f6e\u4ea4\u6613\u7b56\u7565\uff0c\u7528\u6237\u53ef\u4ee5\u642d\u79ef\u6728\u5f0f\u5730\u521b\u5efa\u81ea\u5df1\u7684\u4ea4\u6613\u7b56\u7565\n4. **\u7075\u6d3b\u591a\u53d8** \u4f7f\u7528`qteasy`\u63d0\u4f9b\u7684\u7b56\u7565\u7c7b\uff0c\u7528\u6237\u53ef\u4ee5\u81ea\u884c\u521b\u5efa\u81ea\u5df1\u7684\u4ea4\u6613\u7b56\u7565\uff0c\u7075\u6d3b\u8bbe\u7f6e\u53ef\u8c03\u53c2\u6570\n\n## `qteasy`\u80fd\u505a\u4ec0\u4e48\uff1f\n\n\n### **\u91d1\u878d\u5386\u53f2\u6570\u636e**: \n\n- \u83b7\u53d6\u3001\u6e05\u6d17\u3001\u672c\u5730\u5b58\u50a8\u5927\u91cf\u91d1\u878d\u5386\u53f2\u6570\u636e\n- \u68c0\u7d22\u3001\u5904\u7406\u3001\u8c03\u7528\u672c\u5730\u6570\u636e\n- \u672c\u5730\u91d1\u878d\u6570\u636e\u53ef\u89c6\u5316\n\n![png](docs/source/img/output_5_2.png)\n\n### **\u521b\u5efa\u4ea4\u6613\u7b56\u7565**\n\n- \u63d0\u4f9b\u51e0\u5341\u79cd\u5185\u7f6e\u4ea4\u6613\u7b56\u7565\uff0c\u53ef\u4ee5\u76f4\u63a5\u642d\u79ef\u6728\u5f0f\u4f7f\u7528\n- \u5feb\u901f\u521b\u5efa\u81ea\u5b9a\u4e49\u4ea4\u6613\u7b56\u7565\uff0c\u7075\u6d3b\u8bbe\u7f6e\u53ef\u8c03\u53c2\u6570\n- \u4ea4\u6613\u7b56\u7565\u7684\u56de\u6d4b\u3001\u4f18\u5316\u3001\u8bc4\u4ef7\uff0c\u53ef\u89c6\u5316\u8f93\u51fa\u56de\u6d4b\u7ed3\u679c\n\n![png](docs/source/img/output_14_3.png)\n\n### **\u5b9e\u76d8\u4ea4\u6613\u6a21\u62df**\n- \u8bfb\u53d6\u5b9e\u65f6\u5e02\u573a\u6570\u636e\uff0c\u5b9e\u76d8\u8fd0\u884c\u4ea4\u6613\u7b56\u7565\n- \u751f\u6210\u4ea4\u6613\u4fe1\u53f7\uff0c\u6a21\u62df\u4ea4\u6613\u7ed3\u679c\n- \u8ddf\u8e2a\u8bb0\u5f55\u4ea4\u6613\u65e5\u5fd7\u3001\u80a1\u7968\u6301\u4ed3\u3001\u8d26\u6237\u8d44\u91d1\u53d8\u5316\u7b49\u4fe1\u606f\n- \u968f\u65f6\u67e5\u770b\u4ea4\u6613\u8fc7\u7a0b\uff0c\u68c0\u67e5\u76c8\u4e8f\u60c5\u51b5\n- \u624b\u52a8\u63a7\u5236\u4ea4\u6613\u8fdb\u7a0b\u3001\u8c03\u6574\u4ea4\u6613\u53c2\u6570\uff0c\u624b\u52a8\u4e0b\u5355\n\n![png](docs/source/examples/img/trader_app_1.png)  \n![png](docs/source/examples/img/trader_app_2.png)  \n![png](docs/source/examples/img/trader_app_light_theme.png) \n\n## \u5b89\u88c5\n\n```bash\n$ pip install qteasy\n```\n\n## \u6587\u6863\n\n\u5173\u4e8e`QTEASY`\u7cfb\u7edf\u7684\u66f4\u591a\u8be6\u7ec6\u89e3\u91ca\u548c\u4f7f\u7528\u65b9\u6cd5\uff0c\u8bf7\u53c2\u9605[QTEASY\u6587\u6863](https://qteasy.readthedocs.io)\uff1a\n\n\n### python \u7248\u672c\n- *`python` version >= 3.6, < 3.13* \n\n### \u5b89\u88c5\u53ef\u9009\u4f9d\u8d56\u5305\n\n`qteasy`\u6240\u6709\u5fc5\u8981\u7684\u4f9d\u8d56\u5305\u90fd\u53ef\u4ee5\u5728`pip`\u5b89\u88c5\u7684\u540c\u65f6\u5b89\u88c5\u597d\uff0c\u4f46\u67d0\u4e9b\u7279\u6b8a\u60c5\u51b5\u4e0b\uff0c\u60a8\u9700\u8981\u5728\u5b89\u88c5\u65f6\u6307\u5b9a\u53ef\u9009\u4f9d\u8d56\u5305\uff0c\u4ee5\u4fbf\u5728\u5b89\u88c5`qteasy`\u65f6\u540c\u65f6\u5b89\u88c5\uff0c\u6216\u8005\u624b\u52a8\u5b89\u88c5\u4f9d\u8d56\u5305\uff1a\n\n- **`pymysql`**, \u7528\u4e8e\u8fde\u63a5`MySQL`\u6570\u636e\u5e93,\u5c06\u672c\u5730\u6570\u636e\u5b58\u50a8\u5230`MySQL`\u6570\u636e\u5e93\uff08`qteasy`\u9ed8\u8ba4\u4f7f\u7528`csv`\u6587\u4ef6\u4f5c\u4e3a\u672c\u5730\u6570\u636e\u6e90\uff0c\u4f46\u6570\u636e\u91cf\u5927\u65f6\u63a8\u8350\u4f7f\u7528`mysql`\u6570\u636e\u5e93\uff0c\u8be6\u60c5\u53c2\u89c1[qteasy\u4f7f\u7528\u6559\u7a0b](https://qteasy.readthedocs.io)\uff09\n`pymysql`\u53ef\u4ee5\u5728\u5b89\u88c5`qteasy`\u65f6\u81ea\u52a8\u5b89\u88c5\uff0c\u4e5f\u53ef\u4ee5\u624b\u52a8\u5b89\u88c5\uff1a\n    ```bash\n    $ pip install 'qteasy[database]'  # \u5b89\u88c5qteasy\u65f6\u81ea\u52a8\u5b89\u88c5pymysql\n    $ pip install pymysql  # \u624b\u52a8\u5b89\u88c5pymysql\n    ```\n- **`pyarrow`**, \u7528\u4e8e\u64cd\u4f5c`feather`\u6587\u4ef6\uff0c\u5c06\u672c\u5730\u6570\u636e\u5b58\u50a8\u4e3a`feather`\u6587\u4ef6\uff0c`pyarrow`\u53ef\u4ee5\u5728\u5b89\u88c5`qteasy`\u65f6\u81ea\u52a8\u5b89\u88c5\uff0c\u4e5f\u53ef\u4ee5\u624b\u52a8\u5b89\u88c5\uff1a\n    ```bash\n    $ pip install 'qteasy[feather]'  # \u5b89\u88c5qteasy\u65f6\u81ea\u52a8\u5b89\u88c5pyarrow\n    $ pip install pyarrow  # \u624b\u52a8\u5b89\u88c5pyarrow\n    ```\n- **`pytables`**, \u7528\u4e8e\u64cd\u4f5c`HDF`\u6587\u4ef6\uff0c\u5c06\u672c\u5730\u6570\u636e\u5b58\u50a8\u5230`HDF`\u6587\u4ef6\uff0c`pytables`\u4e0d\u80fd\u81ea\u52a8\u5b89\u88c5\uff0c\u9700\u8981\u4f7f\u7528`conda`\u624b\u52a8\u5b89\u88c5`pytables`\uff1a\n    ```bash\n    $ conda install pytables  # \u5b89\u88c5pytables\n    ```\n- **`ta-lib`**, \u4ee5\u4fbf\u4f7f\u7528\u6240\u6709\u7684\u5185\u7f6e\u4ea4\u6613\u7b56\u7565\uff0c\u4e0b\u9762\u7684\u65b9\u6cd5\u53ef\u4ee5\u5b89\u88c5`ta-lib API`\uff0c\u4f46\u5b83\u8fd8\u4f9d\u8d56C\u8bed\u8a00\u7684`TA-Lib`\u5305\uff0c\u5b89\u88c5\u65b9\u6cd5\u8bf7\u53c2\u8003[FAQ](https://qteasy.readthedocs.io/zh/latest/faq.html#id2)\n    ```bash\n    $ pip install 'qteasy[talib]'  # \u5b89\u88c5qteasy\u65f6\u81ea\u52a8\u5b89\u88c5ta-lib\n    $ pip install ta-lib  # \u624b\u52a8\u5b89\u88c5ta-lib\n    ```\n\n##  10\u5206\u949f\u4e86\u89e3qteasy\u7684\u529f\u80fd\n\n### \u5bfc\u5165`qteasy`\n\u57fa\u672c\u7684\u6a21\u5757\u5bfc\u5165\u65b9\u6cd5\u5982\u4e0b\n\n```python\nimport qteasy as qt\nqt.__version__\n```\n\n### \u914d\u7f6e\u672c\u5730\u6570\u636e\u6e90\n\n\u4e3a\u4e86\u4f7f\u7528`qteasy`\uff0c\u9700\u8981\u5927\u91cf\u7684\u91d1\u878d\u5386\u53f2\u6570\u636e\uff0c\u6240\u6709\u7684\u5386\u53f2\u6570\u636e\u90fd\u5fc5\u987b\u9996\u5148\u4fdd\u5b58\u5728\u672c\u5730\uff0c\u5982\u679c\u672c\u5730\u6ca1\u6709\u5386\u53f2\u6570\u636e\uff0c\u90a3\u4e48`qteasy`\u7684\u8bb8\u591a\u529f\u80fd\u5c31\u65e0\u6cd5\u6267\u884c\u3002\n\n`qteasy`\u9ed8\u8ba4\u901a\u8fc7`tushare`\u91d1\u878d\u6570\u636e\u5305\u6765\u83b7\u53d6\u5927\u91cf\u7684\u91d1\u878d\u6570\u636e\uff0c\u7528\u6237\u9700\u8981\u81ea\u884c\u7533\u8bf7API Token\uff0c\u83b7\u53d6\u76f8\u5e94\u7684\u6743\u9650\u548c\u79ef\u5206\uff08\u8be6\u60c5\u53c2\u8003\uff1ahttps://tushare.pro/document/2\uff09\n\n\u56e0\u6b64\uff0c\u5728\u4f7f\u7528`qteasy`\u4e4b\u524d\u9700\u8981\u5bf9\u672c\u5730\u6570\u636e\u6e90\u548c`tushare`\u8fdb\u884c\u5fc5\u8981\u7684\u914d\u7f6e\u3002\u5728`QT_ROOT_PATH/qteasy/`\u8def\u5f84\u4e0b\u6253\u5f00\u914d\u7f6e\u6587\u4ef6`qteasy.cfg`\uff0c\u53ef\u4ee5\u770b\u5230\u4e0b\u9762\u5185\u5bb9\uff1a\n\n```\n# qteasy configuration file\n# following configurations will be loaded when initialize qteasy\n\n# example:\n# local_data_source = database\n```\n#### \u914d\u7f6e`tushare token`\n\n\u5c06\u4f60\u83b7\u5f97\u7684tushare API token\u6dfb\u52a0\u5230\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u5982\u4e0b\u6240\u793a\uff1a\n\n\n``` commandline\ntushare_token = <\u4f60\u7684tushare API Token> \n```\n#### \u914d\u7f6e\u672c\u5730\u6570\u636e\u6e90 \u2014\u2014 \u7528MySQL\u6570\u636e\u5e93\u4f5c\u4e3a\u672c\u5730\u6570\u636e\u6e90\n\u9ed8\u8ba4\u60c5\u51b5\u4e0b`qteasy`\u4f7f\u7528\u5b58\u50a8\u5728`data/`\u8def\u5f84\u4e0b\u7684`.csv`\u6587\u4ef6\u4f5c\u4e3a\u6570\u636e\u6e90\uff0c\u4e0d\u9700\u8981\u7279\u6b8a\u8bbe\u7f6e\u3002\n\u5982\u679c\u8bbe\u7f6e\u4f7f\u7528`mysql`\u6570\u636e\u5e93\u4f5c\u4e3a\u672c\u5730\u6570\u636e\u6e90\uff0c\u5728\u914d\u7f6e\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\uff1a\n\n```text\nlocal_data_source = database  \n\nlocal_db_host = <host name>\nlocal_db_port = <port number>\nlocal_db_user = <user name>\nlocal_db_password = <password>\nlocal_db_name = <database name>\n```\n\n\u5173\u95ed\u5e76\u4fdd\u5b58\u597d\u914d\u7f6e\u6587\u4ef6\u540e\uff0c\u91cd\u65b0\u5bfc\u5165`qteasy`\uff0c\u5c31\u5b8c\u6210\u4e86\u6570\u636e\u6e90\u7684\u914d\u7f6e\uff0c\u53ef\u4ee5\u5f00\u59cb\u4e0b\u8f7d\u6570\u636e\u5230\u672c\u5730\u4e86\u3002\n\n### \u4e0b\u8f7d\u91d1\u878d\u5386\u53f2\u6570\u636e \n\n\u8981\u4e0b\u8f7d\u91d1\u878d\u4ef7\u683c\u6570\u636e\uff0c\u4f7f\u7528`qt.refill_data_source()`\u51fd\u6570\u3002\u4e0b\u9762\u7684\u4ee3\u7801\u4e0b\u8f7d2021\u53ca2022\u4e24\u5e74\u5185\u6240\u6709\u80a1\u7968\u3001\u6240\u6709\u6307\u6570\u7684\u65e5K\u7ebf\u6570\u636e\uff0c\u540c\u65f6\u4e0b\u8f7d\u6240\u6709\u7684\u80a1\u7968\u548c\u57fa\u91d1\u7684\u57fa\u672c\u4fe1\u606f\u6570\u636e\u3002\n\uff08\u6839\u636e\u7f51\u7edc\u901f\u5ea6\uff0c\u4e0b\u8f7d\u6570\u636e\u53ef\u80fd\u9700\u8981\u5341\u5206\u949f\u5de6\u53f3\u7684\u65f6\u95f4\uff0c\u5982\u679c\u5b58\u50a8\u4e3acsv\u6587\u4ef6\uff0c\u5c06\u5360\u7528\u5927\u7ea6200MB\u7684\u78c1\u76d8\u7a7a\u95f4\uff09\uff1a\n\n```python\nqt.refill_data_source(\n        tables=['stock_daily',   # \u80a1\u7968\u7684\u65e5\u7ebf\u4ef7\u683c\n                'index_daily',   # \u6307\u6570\u7684\u65e5\u7ebf\u4ef7\u683c\n                'basics'],       # \u80a1\u7968\u548c\u57fa\u91d1\u7684\u57fa\u672c\u4fe1\u606f\n        start_date='20210101',  # \u4e0b\u8f7d\u6570\u636e\u7684\u8d77\u6b62\u65f6\u95f4\n        end_date='20221231',  \n)\n```\n\n\u6570\u636e\u4e0b\u8f7d\u5230\u672c\u5730\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528`qt.get_history_data()`\u6765\u83b7\u53d6\u6570\u636e\uff0c\u5982\u679c\u540c\u65f6\u83b7\u53d6\u591a\u4e2a\u80a1\u7968\u7684\u5386\u53f2\u6570\u636e\uff0c\u6bcf\u4e2a\u80a1\u7968\u7684\u5386\u53f2\u6570\u636e\u4f1a\u88ab\u5206\u522b\u4fdd\u5b58\u5230\u4e00\u4e2a`dict`\u4e2d\u3002\n\n```python\nqt.get_history_data(htypes='open, high, low, close', \n                    shares='000001.SZ, 000300.SH',\n                    start='20210101',\n                    end='20210115')\n```\n\u8fd0\u884c\u4e0a\u8ff0\u4ee3\u7801\u4f1a\u5f97\u5230\u4e00\u4e2a`Dict`\u5bf9\u8c61\uff0c\u5305\u542b\u4e24\u4e2a\u80a1\u7968\"000001.SZ\"\u4ee5\u53ca\"000005.SZ\"\u7684K\u7ebf\u6570\u636e\uff08\u6570\u636e\u5b58\u50a8\u4e3a`DataFrame`\uff09\uff1a\n```\n{'000001.SZ':\n              open   high    low  close\n 2021-01-04  19.10  19.10  18.44  18.60\n 2021-01-05  18.40  18.48  17.80  18.17\n 2021-01-06  18.08  19.56  18.00  19.56\n ... \n 2021-01-13  21.00  21.01  20.40  20.70\n 2021-01-14  20.68  20.89  19.95  20.17\n 2021-01-15  21.00  21.95  20.82  21.00,\n \n '000300.SH':\n                  open       high        low      close\n 2021-01-04  5212.9313  5284.4343  5190.9372  5267.7181\n 2021-01-05  5245.8355  5368.5049  5234.3775  5368.5049\n 2021-01-06  5386.5144  5433.4694  5341.4304  5417.6677\n ...\n 2021-01-13  5609.2637  5644.7195  5535.1435  5577.9711\n 2021-01-14  5556.2125  5568.0179  5458.6818  5470.4563\n 2021-01-15  5471.3910  5500.6348  5390.2737  5458.0812}\n```\n\u9664\u4e86\u4ef7\u683c\u6570\u636e\u4ee5\u5916\uff0c`qteasy`\u8fd8\u53ef\u4ee5\u4e0b\u8f7d\u5e76\u7ba1\u7406\u5305\u62ec\u8d22\u52a1\u62a5\u8868\u3001\u6280\u672f\u6307\u6807\u3001\u57fa\u672c\u9762\u6570\u636e\u7b49\u5728\u5185\u7684\u5927\u91cf\u91d1\u878d\u6570\u636e\uff0c\u8be6\u60c5\u8bf7\u53c2\u89c1[qteasy\u6587\u6863](https://qteasy.readthedocs.io)\n\n\u80a1\u7968\u7684\u6570\u636e\u4e0b\u8f7d\u540e\uff0c\u4f7f\u7528`qt.candle()`\u53ef\u4ee5\u663e\u793a\u80a1\u7968\u6570\u636eK\u7ebf\u56fe\u3002\n\n```python\nimport qteasy as qt\ndata = qt.candle('000300.SH', start='2021-06-01', end='2021-8-01', asset_type='IDX')\n```\n\n![png](docs/source/img/output_5_2.png)\n    \n`qteasy`\u7684K\u7ebf\u56fe\u51fd\u6570`candle`\u652f\u6301\u901a\u8fc7\u516d\u4f4d\u6570\u80a1\u7968/\u6307\u6570\u4ee3\u7801\u67e5\u8be2\u51c6\u786e\u7684\u8bc1\u5238\u4ee3\u7801\uff0c\u4e5f\u652f\u6301\u901a\u8fc7\u80a1\u7968\u3001\u6307\u6570\u540d\u79f0\u663e\u793aK\u7ebf\u56fe\n`qt.candle()`\u652f\u6301\u529f\u80fd\u5982\u4e0b\uff1a\n- \u663e\u793a\u80a1\u7968\u3001\u57fa\u91d1\u3001\u671f\u8d27\u7684K\u7ebf\n- \u663e\u793a\u590d\u6743\u4ef7\u683c\n- \u663e\u793a\u5206\u949f\u3001 \u5468\u6216\u6708K\u7ebf \n- \u663e\u793a\u4e0d\u540c\u79fb\u52a8\u5747\u7ebf\u4ee5\u53caMACD/KDJ\u7b49\u6307\u6807\n\n\u8be6\u7ec6\u7684\u7528\u6cd5\u8bf7\u53c2\u8003\u6587\u6863\uff0c\u793a\u4f8b\u5982\u4e0b(\u8bf7\u5148\u4f7f\u7528`qt.refill_data_source()`\u4e0b\u8f7d\u76f8\u5e94\u7684\u5386\u53f2\u6570\u636e)\uff1a\n\n\n```python\nimport qteasy as qt\n# \u573a\u5185\u57fa\u91d1\u7684\u5c0f\u65f6K\u7ebf\u56fe\nqt.candle('159601', start = '20220121', freq='h')\n# \u6caa\u6df1300\u6307\u6570\u7684\u65e5K\u7ebf\u56fe\nqt.candle('000300', start = '20200121')\n# \u80a1\u7968\u768430\u5206\u949fK\u7ebf\uff0c\u590d\u6743\u4ef7\u683c\nqt.candle('\u4e2d\u56fd\u7535\u4fe1', start = '20211021', freq='30min', adj='b')\n# \u671f\u8d27K\u7ebf\uff0c\u4e09\u6761\u79fb\u52a8\u5747\u7ebf\u5206\u522b\u4e3a9\u5929\u300112\u5929\u300126\u5929\nqt.candle('\u6caa\u94dc\u4e3b\u529b', start = '20211021', mav=[9, 12, 26])\n# \u573a\u5916\u57fa\u91d1\u51c0\u503c\u66f2\u7ebf\u56fe\uff0c\u590d\u6743\u51c0\u503c\uff0c\u4e0d\u663e\u793a\u79fb\u52a8\u5747\u7ebf\nqt.candle('000001.OF', start='20200101', asset_type='FD', adj='b', mav=[])\n```\n\n![png](docs/source/img/output_3_1.png)\n\n![png](docs/source/img/output_7_2.png)\n\n![png](docs/source/img/output_8_3.png)\n\n![png](docs/source/img/output_3_4.png)\n\n![png](docs/source/img/output_3_5.png)\n    \n\n\u751f\u6210\u7684K\u7ebf\u56fe\u53ef\u4ee5\u662f\u4e00\u4e2a\u4ea4\u4e92\u5f0f\u52a8\u6001K\u7ebf\u56fe\uff08\u8bf7\u6ce8\u610f\uff0cK\u7ebf\u56fe\u57fa\u4e8e`matplotlib`\u7ed8\u5236\uff0c\u5728\u4f7f\u7528\u4e0d\u540c\u7684\u7ec8\u7aef\u65f6\uff0c\u663e\u793a\u529f\u80fd\u6709\u6240\u533a\u522b\uff0c\u67d0\u4e9b\u7ec8\u7aef\u5e76\u4e0d\u652f\u6301\n\u52a8\u6001\u56fe\u8868\uff0c\u8be6\u60c5\u8bf7\u53c2\u9605 [matplotlib\u6587\u6863](https://matplotlib.org/stable/users/explain/backends.html)\n\n\n\u5728\u4f7f\u7528\u52a8\u6001K\u7ebf\u56fe\u65f6\uff0c\u7528\u6237\u53ef\u4ee5\u7528\u9f20\u6807\u548c\u952e\u76d8\u63a7\u5236K\u7ebf\u56fe\u7684\u663e\u793a\u8303\u56f4\uff1a\n\n- \u9f20\u6807\u5728\u56fe\u8868\u4e0a\u5de6\u53f3\u62d6\u52a8\uff1a\u53ef\u4ee5\u79fb\u52a8K\u7ebf\u56fe\u663e\u793a\u66f4\u65e9\u6216\u66f4\u665a\u7684K\u7ebf\n- \u9f20\u6807\u6eda\u8f6e\u5728\u56fe\u8868\u4e0a\u6eda\u52a8\uff0c\u53ef\u4ee5\u7f29\u5c0f\u6216\u653e\u5927K\u7ebf\u56fe\u7684\u663e\u793a\u8303\u56f4\n- \u901a\u8fc7\u952e\u76d8\u5de6\u53f3\u65b9\u5411\u952e\uff0c\u53ef\u4ee5\u79fb\u52a8K\u7ebf\u56fe\u7684\u663e\u793a\u8303\u56f4\u663e\u793a\u66f4\u65e9\u6216\u66f4\u665a\u7684K\u7ebf\n- \u901a\u8fc7\u952e\u76d8\u4e0a\u4e0b\u952e\uff0c\u53ef\u4ee5\u7f29\u5c0f\u6216\u653e\u5927K\u7ebf\u56fe\u7684\u663e\u793a\u8303\u56f4\n- \u5728K\u7ebf\u56fe\u4e0a\u53cc\u51fb\u9f20\u6807\uff0c\u53ef\u4ee5\u5207\u6362\u4e0d\u540c\u7684\u5747\u7ebf\u7c7b\u578b\n- \u5728K\u7ebf\u56fe\u7684\u6307\u6807\u533a\u57df\u53cc\u51fb\uff0c\u53ef\u4ee5\u5207\u6362\u4e0d\u540c\u7684\u6307\u6807\u7c7b\u578b\uff1aMACD\uff0cRSI\uff0cDEMA\n\n![gif](docs/source/img/output_dyna_plot.gif)\n\n\u5173\u4e8e`DataSource`\u5bf9\u8c61\u7684\u66f4\u591a\u8be6\u7ec6\u4ecb\u7ecd\uff0c\u8bf7\u53c2\u89c1[qteasy\u6587\u6863](https://qteasy.readthedocs.io)\n\n\n###  \u521b\u5efa\u4e00\u4e2a\u6295\u8d44\u7b56\u7565\n\n`qteasy`\u4e2d\u7684\u6240\u6709\u4ea4\u6613\u7b56\u7565\u90fd\u662f\u7531`qteast.Operator`\uff08\u4ea4\u6613\u5458\uff09\u5bf9\u8c61\u6765\u5b9e\u73b0\u56de\u6d4b\u548c\u8fd0\u884c\u7684\uff0c`Operator`\u5bf9\u8c61\u662f\u4e00\u4e2a\u7b56\u7565\u5bb9\u5668\uff0c\u4e00\u4e2a\u4ea4\u6613\u5458\u53ef\u4ee5\u540c\u65f6\n\u7ba1\u7406\u591a\u4e2a\u4e0d\u540c\u7684\u4ea4\u6613\u7b56\u7565\u3002\n\n`queasy`\u63d0\u4f9b\u4e86\u4e24\u79cd\u65b9\u5f0f\u521b\u5efa\u4ea4\u6613\u7b56\u7565\uff0c\u8be6\u7ec6\u7684\u8bf4\u660e\u8bf7\u53c2\u89c1\u4f7f\u7528\u6559\u7a0b\uff1a\n\n- **\u4f7f\u7528\u5185\u7f6e\u4ea4\u6613\u7b56\u7565\u7ec4\u5408**\n- **\u901a\u8fc7\u7b56\u7565\u7c7b\u81ea\u884c\u521b\u5efa\u7b56\u7565**\n\n#### \u751f\u6210\u4e00\u4e2aDMA\u5747\u7ebf\u62e9\u65f6\u4ea4\u6613\u7b56\u7565\n\u5728\u8fd9\u91cc\uff0c\u6211\u4eec\u5c06\u4f7f\u7528\u4e00\u4e2a\u5185\u7f6e\u7684`DMA`\u5747\u7ebf\u62e9\u65f6\u7b56\u7565\u6765\u751f\u6210\u4e00\u4e2a\u6700\u7b80\u5355\u7684\u5927\u76d8\u62e9\u65f6\u4ea4\u6613\u7cfb\u7edf\u3002\u6240\u6709\u5185\u7f6e\u4ea4\u6613\u7b56\u7565\u7684\u6e05\u5355\u548c\u8be6\u7ec6\u8bf4\u660e\u8bf7\u53c2\u89c1\u6587\u6863\u3002\n\n\u521b\u5efa`Operator`\u5bf9\u8c61\u65f6\u4f20\u5165\u53c2\u6570\uff1a`strategies='DMA'`\uff0c\u53ef\u4ee5\u65b0\u5efa\u4e00\u4e2a`DMA`\u53cc\u5747\u7ebf\u62e9\u65f6\u4ea4\u6613\u7b56\u7565\u3002\n\u521b\u5efa\u597d`Operator`\u5bf9\u8c61\u540e\uff0c\u53ef\u4ee5\u7528`op.info()`\u6765\u67e5\u770b\u5b83\u7684\u4fe1\u606f\u3002\n\n```python\nimport qteasy as qt\n\nop = qt.Operator(strategies='dma')\nop.info()\n```\n\u73b0\u5728\u53ef\u4ee5\u770b\u5230`op`\u4e2d\u6709\u4e00\u4e2a\u4ea4\u6613\u7b56\u7565\uff0cID\u662f`dma`\uff0c\u6211\u4eec\u5728`Operator`\u5c42\u9762\u8bbe\u7f6e\u6216\u4fee\u6539\u7b56\u7565\u7684\u53c2\u6570\n\u65f6\uff0c\u90fd\u9700\u8981\u5f15\u7528\u8fd9\u4e2a`ID`\u3002\n\n`DMA`\u662f\u4e00\u4e2a\u5185\u7f6e\u7684\u5747\u7ebf\u62e9\u65f6\u7b56\u7565\uff0c\u5b83\u901a\u8fc7\u8ba1\u7b97\u80a1\u7968\u6bcf\u65e5\u6536\u76d8\u4ef7\u7684\u5feb\u3001\u6162\u4e24\u6839\u79fb\u52a8\u5747\u7ebf\u7684\u5dee\u503c`DMA`\u4e0e\u5176\u79fb\u52a8\u5e73\u5747\u503c`AMA`\u4e4b\u95f4\u7684\u4ea4\u53c9\u60c5\u51b5\u6765\u786e\u5b9a\u591a\u7a7a\u6216\u4e70\u5356\u70b9\u3002\uff1a\n\n\u4f7f\u7528qt.built_ins()\u51fd\u6570\u53ef\u4ee5\u67e5\u770bDMA\u7b56\u7565\u7684\u8be6\u60c5\uff0c\u4f8b\u5982\uff1a\n```python\nimport qteasy as qt\nqt.built_ins('dma')\n```\n\u5f97\u5230\uff1a\n\n```\n DMA\u62e9\u65f6\u7b56\u7565\n\n    \u7b56\u7565\u53c2\u6570\uff1a\n        s, int, \u77ed\u5747\u7ebf\u5468\u671f\n        l, int, \u957f\u5747\u7ebf\u5468\u671f\n        d, int, DMA\u5468\u671f\n    \u4fe1\u53f7\u7c7b\u578b\uff1a\n        PS\u578b\uff1a\u767e\u5206\u6bd4\u4e70\u5356\u4ea4\u6613\u4fe1\u53f7\n    \u4fe1\u53f7\u89c4\u5219\uff1a\n        \u5728\u4e0b\u9762\u60c5\u51b5\u4e0b\u4ea7\u751f\u4e70\u5165\u4fe1\u53f7\uff1a\n        1\uff0c DMA\u5728AMA\u4e0a\u65b9\u65f6\uff0c\u591a\u5934\u533a\u95f4\uff0c\u5373DMA\u7ebf\u81ea\u4e0b\u800c\u4e0a\u7a7f\u8d8aAMA\u7ebf\u540e\uff0c\u8f93\u51fa\u4e3a1\n        2\uff0c DMA\u5728AMA\u4e0b\u65b9\u65f6\uff0c\u7a7a\u5934\u533a\u95f4\uff0c\u5373DMA\u7ebf\u81ea\u4e0a\u800c\u4e0b\u7a7f\u8d8aAMA\u7ebf\u540e\uff0c\u8f93\u51fa\u4e3a0\n        3\uff0c DMA\u4e0e\u80a1\u4ef7\u53d1\u751f\u80cc\u79bb\u65f6\u7684\u4ea4\u53c9\u4fe1\u53f7\uff0c\u53ef\u4fe1\u5ea6\u8f83\u9ad8\n\n    \u7b56\u7565\u5c5e\u6027\u7f3a\u7701\u503c\uff1a\n    \u9ed8\u8ba4\u53c2\u6570\uff1a(12, 26, 9)\n    \u6570\u636e\u7c7b\u578b\uff1aclose \u6536\u76d8\u4ef7\uff0c\u5355\u6570\u636e\u8f93\u5165\n    \u91c7\u6837\u9891\u7387\uff1a\u5929\n    \u7a97\u53e3\u957f\u5ea6\uff1a270\n    \u53c2\u6570\u8303\u56f4\uff1a[(10, 250), (10, 250), (8, 250)]\n    \u7b56\u7565\u4e0d\u652f\u6301\u53c2\u8003\u6570\u636e\uff0c\u4e0d\u652f\u6301\u4ea4\u6613\u6570\u636e\n```\n\u5728\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u7b56\u7565\u6709\u4e09\u4e2a**\u53ef\u8c03\u53c2\u6570**\uff1a`(12,26,9)`, \u4f46\u6211\u4eec\u53ef\u4ee5\u7ed9\u51fa\u4efb\u610f\u5927\u4e8e2\u5c0f\u4e8e250\u7684\u4e09\u4e2a\u6574\u6570\u4f5c\u4e3a\u7b56\u7565\u7684\u53c2\u6570\uff0c\u4ee5\u9002\u5e94\u4e0d\u540c\u4ea4\u6613\u6d3b\u8dc3\u5ea6\u7684\u80a1\u7968\u3001\u6216\u8005\u9002\u5e94\n\u4e0d\u540c\u7684\u7b56\u7565\u8fd0\u884c\u5468\u671f\u3002\n\n\n### \u56de\u6d4b\u5e76\u8bc4\u4ef7\u4ea4\u6613\u7b56\u7565\u7684\u6027\u80fd\u8868\u73b0\nqueasy\u53ef\u4ee5\u4f7f\u7528\u5386\u53f2\u6570\u636e\u56de\u6d4b\u7b56\u7565\u8868\u73b0\u5e76\u8f93\u51fa\u56fe\u8868\u5982\u4e0b\uff1a\n![png](https://raw.githubusercontent.com/shepherdpp/qteasy/master/docs/source/img/output_14_3.png)\n\n\u4f7f\u7528\u9ed8\u8ba4\u53c2\u6570\u56de\u6d4b\u521a\u624d\u5efa\u7acb\u7684DMA\u7b56\u7565\u5728\u5386\u53f2\u6570\u636e\u4e0a\u7684\u8868\u73b0\uff0c\u53ef\u4ee5\u4f7f\u7528`op.run()`\u3002\n\n```python\nimport qteasy as qt\n\nop = qt.Operator(strategies='dma')\nres = op.run(\n        mode=1,                         # \u5386\u53f2\u56de\u6d4b\u6a21\u5f0f\n        asset_pool='000300.SH',         # \u6295\u8d44\u8d44\u4ea7\u6c60\uff0c\u5373\u5141\u8bb8\u6295\u8d44\u7684\u80a1\u7968\u6216\u6307\u6570\uff0c\u6b64\u5904\u4e3a\u6caa\u6df1300\u6307\u6570\n        asset_type='IDX',               # \u6295\u8d44\u8d44\u4ea7\u7c7b\u578b\uff0cIDX\u8868\u793a\u6307\u6570\uff0cE\u8868\u793a\u80a1\u7968\n        invest_cash_amounts=[100000],   # \u521d\u59cb\u6295\u8d44\u8d44\u91d1\uff0c\u6b64\u5904\u4e3a10\u4e07\u5143\n        invest_start='20220501',        # \u6295\u8d44\u56de\u6d4b\u5f00\u59cb\u65e5\u671f\n        invest_end='20221231',          # \u6295\u8d44\u56de\u6d4b\u7ed3\u675f\u65e5\u671f\n        cost_rate_buy=0.0003,           # \u4e70\u5165\u8d39\u7387\uff0c\u6b64\u5904\u4e3a0.03%\n        cost_rate_sell=0.0001,          # \u5356\u51fa\u8d39\u7387\uff0c\u6b64\u5904\u4e3a0.01%\n        visual=True,                    # \u6253\u5370\u53ef\u89c6\u5316\u56de\u6d4b\u56fe\u8868\n        trade_log=True                  # \u6253\u5370\u4ea4\u6613\u65e5\u5fd7\n)\n```\n\u8f93\u51fa\u7ed3\u679c\u5982\u4e0b\uff1a\n```\n     ====================================\n     |                                  |\n     |       BACK TESTING RESULT        |\n     |                                  |\n     ====================================\n\nqteasy running mode: 1 - History back testing\ntime consumption for operate signal creation: 4.4 ms\ntime consumption for operation back looping:  82.5 ms\n\ninvestment starts on      2022-05-05 00:00:00\nends on                   2022-12-30 00:00:00\nTotal looped periods:     0.7 years.\n\n-------------operation summary:------------\nOnly non-empty shares are displayed, call \n\"loop_result[\"oper_count\"]\" for complete operation summary\n\n          Sell Cnt Buy Cnt Total Long pct Short pct Empty pct\n000300.SH    6        6      12   56.4%      0.0%     43.6%   \n\nTotal operation fee:     \u00a5      257.15\ntotal investment amount: \u00a5  100,000.00\nfinal value:              \u00a5  105,773.09\nTotal return:                     5.77% \nAvg Yearly return:                8.95%\nSkewness:                          0.58\nKurtosis:                          3.54\nBenchmark return:                -3.46% \nBenchmark Yearly return:         -5.23%\n\n------strategy loop_results indicators------ \nalpha:                            0.142\nBeta:                             1.003\nSharp ratio:                      0.637\nInfo ratio:                       0.132\n250 day volatility:               0.138\nMax drawdown:                    11.92% \n    peak / valley:        2022-08-17 / 2022-10-31\n    recovered on:         Not recovered!\n\n===========END OF REPORT=============\n```\n![png](docs/source/img/output_21_1.png)\n\n### \u4ea4\u6613\u7b56\u7565\u7684\u53c2\u6570\u8c03\u4f18\n\n\u4ea4\u6613\u7b56\u7565\u7684\u8868\u73b0\u4e0e\u53c2\u6570\u6709\u5173\uff0c\u5982\u679c\u8f93\u5165\u4e0d\u540c\u7684\u53c2\u6570\uff0c\u7b56\u7565\u56de\u62a5\u76f8\u5dee\u4f1a\u975e\u5e38\u5927\u3002`qteasy`\u53ef\u4ee5\u7528\u591a\u79cd\u4e0d\u540c\u7684\u4f18\u5316\u7b97\u6cd5\uff0c\u5e2e\u52a9\u641c\u7d22\u6700\u4f18\u7684\u7b56\u7565\u53c2\u6570\uff0c\n\n\u8981\u4f7f\u7528\u7b56\u7565\u4f18\u5316\u529f\u80fd\uff0c\u9700\u8981\u8bbe\u7f6e\u4ea4\u6613\u7b56\u7565\u7684\u4f18\u5316\u6807\u8bb0`opt_tag=1`\uff0c\u5e76\u914d\u7f6e\u73af\u5883\u53d8\u91cf`mode=2`\u5373\u53ef:\n\n```python\nimport qteasy as qt\n\nop = qt.Operator(strategies='dma')\nop.set_parameter('dma', opt_tag=1)\nres = op.run(mode=2,                    # \u4f18\u5316\u6a21\u5f0f\n             opti_start='20220501',     # \u4f18\u5316\u533a\u95f4\u5f00\u59cb\u65e5\u671f\n             opti_end='20221231',       # \u4f18\u5316\u533a\u95f4\u7ed3\u675f\u65e5\u671f\n             test_start='20220501',     # \u6d4b\u8bd5\u533a\u95f4\u5f00\u59cb\u65e5\u671f\n             test_end='20221231',       # \u6d4b\u8bd5\u533a\u95f4\u7ed3\u675f\u65e5\u671f\n             opti_sample_count=1000,    # \u4f18\u5316\u6837\u672c\u6570\u91cf\n             visual=True,               # \u6253\u5370\u4f18\u5316\u7ed3\u679c\u56fe\u8868\n             parallel=False)            # \u4e0d\u4f7f\u7528\u5e76\u884c\u8ba1\u7b97\n```\n\n`qteasy`\u5c06\u5728\u540c\u4e00\u6bb5\u5386\u53f2\u6570\u636e\uff08\u4f18\u5316\u533a\u95f4\uff09\u4e0a\u53cd\u590d\u56de\u6d4b\uff0c\u627e\u5230\u7ed3\u679c\u6700\u597d\u768430\u7ec4\u53c2\u6570\uff0c\u5e76\u628a\u8fd930\u7ec4\u53c2\u6570\u5728\u53e6\u4e00\u6bb5\u5386\u53f2\u6570\u636e\uff08\u6d4b\u8bd5\u533a\u95f4\uff09\u4e0a\u8fdb\u884c\u72ec\u7acb\u6d4b\u8bd5\uff0c\u5e76\u663e\n\u793a\u72ec\u7acb\u6d4b\u8bd5\u7684\u7ed3\u679c\uff1a\n```commandline\n==================================== \n|                                  |\n|       OPTIMIZATION RESULT        |\n|                                  |\n====================================\n\nqteasy running mode: 2 - Strategy Parameter Optimization\n\n... # \u7701\u7565\u90e8\u5206\u8f93\u51fa\n\n# \u4ee5\u4e0b\u662f30\u7ec4\u4f18\u5316\u7684\u7b56\u7565\u53c2\u6570\u53ca\u5176\u7ed3\u679c\uff08\u90e8\u5206\u7ed3\u679c\u7701\u7565\uff09\n    Strategy items Sell-outs Buy-ins ttl-fee     FV      ROI  Benchmark rtn MDD \n0     (35, 69, 60)     1.0      2.0    71.45 106,828.20  6.8%     -3.5%     9.5%\n1   (124, 104, 18)     3.0      2.0   124.86 106,900.59  6.9%     -3.5%     7.4%\n2   (126, 120, 56)     1.0      1.0    72.38 107,465.86  7.5%     -3.5%     7.5%\n...\n27   (103, 84, 70)     1.0      1.0    74.84 114,731.44 14.7%     -3.5%     8.8%\n28  (143, 103, 49)     1.0      1.0    74.33 116,453.26 16.5%     -3.5%     4.3%\n29   (129, 92, 56)     1.0      1.0    74.55 118,811.58 18.8%     -3.5%     4.3%\n\n===========END OF REPORT=============\n```\n\n![png](docs/source/img/output_24_1.png)   \n\u5c06\u4f18\u5316\u540e\u7684\u53c2\u6570\u5e94\u7528\u5230\u7b56\u7565\u4e2d\uff0c\u5e76\u518d\u6b21\u56de\u6d4b\uff0c\u53ef\u4ee5\u770b\u5230\u7ed3\u679c\u660e\u663e\u63d0\u5347\uff1a\n\n```python\nop.set_parameter('dma', pars=(143, 99, 32))\nres = op.run(\n        mode=1,                         # \u5386\u53f2\u56de\u6d4b\u6a21\u5f0f\n        asset_pool='000300.SH',         # \u6295\u8d44\u8d44\u4ea7\u6c60\n        asset_type='IDX',               # \u6295\u8d44\u8d44\u4ea7\u7c7b\u578b\n        invest_cash_amounts=[100000],   # \u6295\u8d44\u8d44\u91d1\n        invest_start='20220501',        # \u6295\u8d44\u56de\u6d4b\u5f00\u59cb\u65e5\u671f\n        invest_end='20221231',          # \u6295\u8d44\u56de\u6d4b\u7ed3\u675f\u65e5\u671f\n        cost_rate_buy=0.0003,           # \u4e70\u5165\u8d39\u7387\n        cost_rate_sell=0.0001,          # \u5356\u51fa\u8d39\u7387\n        visual=True,                    # \u6253\u5370\u53ef\u89c6\u5316\u56de\u6d4b\u56fe\u8868\n        trade_log=True,                 # \u6253\u5370\u4ea4\u6613\u65e5\u5fd7\n)\n```\n\u7ed3\u679c\u5982\u4e0b\uff1a\n\n![png](docs/source/img/output_26_1.png)   \n\n\n\u5173\u4e8e\u7b56\u7565\u4f18\u5316\u7ed3\u679c\u7684\u66f4\u591a\u89e3\u8bfb\u3001\u4ee5\u53ca\u66f4\u591a\u4f18\u5316\u53c2\u6570\u7684\u4ecb\u7ecd\uff0c\u8bf7\u53c2\u89c1\u8be6\u7ec6\u6587\u6863\n\n### \u90e8\u7f72\u5e76\u5f00\u59cb\u4ea4\u6613\u7b56\u7565\u7684\u5b9e\u76d8\u8fd0\u884c\n\n\u5728\u914d\u7f6e\u597dOperator\u5bf9\u8c61\u5e76\u8bbe\u7f6e\u597d\u7b56\u7565\u540e\uff0c`qteasy`\u53ef\u4ee5\u81ea\u52a8\u5b9a\u671f\u8fd0\u884c\u3001\u81ea\u52a8\u76ef\u76d8\u3001\u81ea\u52a8\u4e0b\u8f7d\u5b9e\u65f6\u6570\u636e\u5e76\u6839\u636e\u7b56\u7565\u7ed3\u679c\u751f\u6210\u4ea4\u6613\u6307\u4ee4\uff0c\u6a21\u62df\u4ea4\u6613\u8fc7\u7a0b\u5e76\u8bb0\u5f55\u4ea4\u6613\u7ed3\u679c\u3002\n\n\u5728`Operator`\u4e2d\u8bbe\u7f6e\u597d\u4ea4\u6613\u7b56\u7565\uff0c\u5e76\u914d\u7f6e\u597d\u4ea4\u6613\u53c2\u6570\u540e\uff0c\u53ef\u4ee5\u76f4\u63a5\u542f\u52a8\u5b9e\u76d8\u4ea4\u6613\uff1a\n\n```python\nimport qteasy as qt\n\n# \u521b\u5efa\u4e00\u4e2a\u4ea4\u6613\u7b56\u7565alpha\nalpha = qt.get_built_in_strategy('ndayrate')  # \u521b\u5efa\u4e00\u4e2aN\u65e5\u80a1\u4ef7\u6da8\u5e45\u4ea4\u6613\u7b56\u7565\n\n# \u8bbe\u7f6e\u7b56\u7565\u7684\u8fd0\u884c\u53c2\u6570\nalpha.strategy_run_freq = 'd'  # \u6bcf\u65e5\u8fd0\u884c\nalpha.data_freq = 'd' # \u7b56\u7565\u4f7f\u7528\u65e5\u9891\u6570\u636e\nalpha.window_length = 20  # \u6570\u636e\u7a97\u53e3\u957f\u5ea6\nalpha.sort_ascending = False  # \u4f18\u5148\u9009\u62e9\u6da8\u5e45\u6700\u5927\u7684\u80a1\u7968\nalpha.condition = 'greater'  # \u7b5b\u9009\u51fa\u6da8\u5e45\u5927\u4e8e\u67d0\u4e00\u4e2a\u503c\u7684\u80a1\u7968\nalpha.ubound = 0.005  # \u7b5b\u9009\u51fa\u6da8\u5e45\u5927\u4e8e0.5%\u7684\u80a1\u7968\nalpha.sel_count = 7  # \u6bcf\u6b21\u9009\u51fa7\u652f\u80a1\u7968\n\n# \u521b\u5efa\u4e00\u4e2a\u4ea4\u6613\u5458\u5bf9\u8c61\uff0c\u8fd0\u884calpha\u7b56\u7565\nop = qt.Operator(alpha, signal_type='PT', op_type='step')\n\n# \u8bbe\u7f6e\u7b56\u7565\u8fd0\u884c\u53c2\u6570\n# \u4ea4\u6613\u80a1\u7968\u6c60\u5305\u62ec\u6240\u6709\u7684\u94f6\u884c\u80a1\u548c\u5bb6\u7528\u7535\u5668\u80a1\nasset_pool = qt.filter_stock_codes(industry='\u94f6\u884c, \u5bb6\u7528\u7535\u5668', exchange='SSE, SZSE')\n\nqt.configure(\n        mode=0,  # \u4ea4\u6613\u6a21\u5f0f\u4e3a\u5b9e\u76d8\u8fd0\u884c\n        asset_type='E',  # \u4ea4\u6613\u7684\u6807\u7684\u7c7b\u578b\u4e3a\u80a1\u7968\n        asset_pool=asset_pool,  # \u4ea4\u6613\u80a1\u7968\u6c60\u4e3a\u6240\u6709\u94f6\u884c\u80a1\u548c\u5bb6\u7528\u7535\u5668\u80a1\n        trade_batch_size=100,  # \u4ea4\u6613\u6279\u91cf\u4e3a100\u80a1\u7684\u6574\u6570\u500d\n        sell_batch_size=1,  # \u5356\u51fa\u6570\u91cf\u4e3a1\u80a1\u7684\u6574\u6570\u500d\n        live_trade_account_id=1,  # \u5b9e\u76d8\u4ea4\u6613\u8d26\u6237ID\n        live_trade_account='user name',  # \u5b9e\u76d8\u4ea4\u6613\u7528\u6237\u540d\n        live_trade_ui_type='tui',  # \u4f7f\u7528TUI\u754c\u9762\u76d1\u63a7\u5b9e\u76d8\u4ea4\u6613\uff0c\u9ed8\u8ba4\u4f7f\u7528CLI\u754c\u9762\n)\n\nqt.run(op)\n```\n`qteasy`\u7684\u5b9e\u76d8\u8fd0\u884c\u7a0b\u5e8f\u5b9e\u9645\u4e0a\u662f\u4e00\u4e2a\u5b9a\u65f6\u4efb\u52a1\u89e6\u53d1\u5668\uff0c\u5b83\u80fd\u5b9a\u65f6\u89e6\u53d1\u8fd0\u884c\u4ea4\u6613\u7b56\u7565\uff0c\u63d0\u4ea4\u7b56\u7565\u5230\u6a21\u62df\u4ea4\u6613Broker\uff0c\u5e76\u8bfb\u53d6\u5b9e\u65f6\u4ef7\u683c\uff0c\u6a21\u62df\u6210\u4ea4\u5e76\u81ea\u52a8\u8bb0\u5f55\u4ea4\u6613\u8fc7\u7a0b\u3002\n\n\u4e3a\u4e86\u5bf9\u7b56\u7565\u8fd0\u884c\u8fc7\u7a0b\u8fdb\u884c\u76d1\u63a7\uff0c\u540c\u65f6\u4e0e`qteasy`\u8fdb\u884c\u4e92\u52a8\uff0c`qteasy`\u63d0\u4f9b\u4e86\u4e24\u79cd\u4e0d\u540c\u7684\u4ea4\u4e92\u754c\u9762\uff1a\n\n- **`TraderShell`** \u4ea4\u4e92\u5f0f\u547d\u4ee4\u884c\u754c\u9762\uff0c\u53ef\u4ee5\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u547d\u4ee4\uff0c\u67e5\u770b\u4ea4\u6613\u65e5\u5fd7\u3001\u67e5\u770b\u6301\u4ed3\u3001\u67e5\u770b\u8d26\u6237\u8d44\u91d1\u53d8\u5316\u7b49\u4fe1\u606f\uff1a\n![png](docs/source/img/output_27_1.png)  \n![png](docs/source/img/output_27_3.png) \n- **`TraderApp`** (v1.2.0\u65b0\u589e) \u4ea4\u4e92\u5f0f\u56fe\u5f62\u754c\u9762\uff0c\u53ef\u4ee5\u5728\u56fe\u5f62\u754c\u9762\u4e2d\u67e5\u770b\u4ea4\u6613\u65e5\u5fd7\u3001\u67e5\u770b\u6301\u4ed3\u3001\u67e5\u770b\u8d26\u6237\u8d44\u91d1\u53d8\u5316\u7b49\u4fe1\u606f\n![png](docs/source/examples/img/trader_app_light_theme.png) \n![png](docs/source/examples/img/trader_app_2.png) \n\n\u4e0a\u9762\u4e24\u79cd\u65b9\u5f0f\u90fd\u53ef\u4ee5\u5728\u5b9e\u76d8\u8fd0\u884c\u65f6\u4f7f\u7528\uff0c\u6839\u636eqteasy\u7684\u914d\u7f6e\u53c2\u6570\u8fdb\u5165\u4e0d\u540c\u7684\u4ea4\u4e92\u754c\uff0c\u5173\u4e8e\u66f4\u591a\u5b9e\u76d8\u8fd0\u884c\u7684\u4ecb\u7ecd\uff0c\u8bf7\u53c2\u89c1[`QTEASY`\u6587\u6863](https://qteasy.readthedocs.io)\n",
    "bugtrack_url": null,
    "license": "Copyright <2019> <JACKIE PENG>  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \u201cAS IS\u201d AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.",
    "summary": "A fast quantitative investment tool kit",
    "version": "1.2.6",
    "project_urls": {
        "Documentation": "https://qteasy.readthedocs.io/zh/latest/",
        "Homepage": "https://github.com/shepherdpp/qteasy",
        "Issues": "https://github.com/shepherdpp/qteasy/issues"
    },
    "split_keywords": [
        "quantitative investment",
        " quantitative trading",
        " stock",
        " finance",
        " investment"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "50126ca43da882a9a9251d9223a9c8c0373b52143113873ecb73087f0e67e3c0",
                "md5": "0c3f629e67a890fc6a47fac950ac9d96",
                "sha256": "6917c9070f3ef6be552db028722b77f23df16e5f6bbe6e80129611e3e61098dc"
            },
            "downloads": -1,
            "filename": "qteasy-1.2.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0c3f629e67a890fc6a47fac950ac9d96",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<3.13,>=3.6",
            "size": 470566,
            "upload_time": "2024-05-07T01:42:21",
            "upload_time_iso_8601": "2024-05-07T01:42:21.302128Z",
            "url": "https://files.pythonhosted.org/packages/50/12/6ca43da882a9a9251d9223a9c8c0373b52143113873ecb73087f0e67e3c0/qteasy-1.2.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6adc61472d34e27f3acf09c39b57d4eab894e28eb8bfbabb963a664bb9b668fe",
                "md5": "b7a8e9c42b5b4d90e07d7c05926fc2ce",
                "sha256": "32a251c4d20d42237f027eae9c992aa8ef6a6e0bb0837c65b08e0c24f38da7a3"
            },
            "downloads": -1,
            "filename": "qteasy-1.2.6.tar.gz",
            "has_sig": false,
            "md5_digest": "b7a8e9c42b5b4d90e07d7c05926fc2ce",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<3.13,>=3.6",
            "size": 617169,
            "upload_time": "2024-05-07T01:42:24",
            "upload_time_iso_8601": "2024-05-07T01:42:24.226935Z",
            "url": "https://files.pythonhosted.org/packages/6a/dc/61472d34e27f3acf09c39b57d4eab894e28eb8bfbabb963a664bb9b668fe/qteasy-1.2.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-07 01:42:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "shepherdpp",
    "github_project": "qteasy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "pandas",
            "specs": []
        },
        {
            "name": "numpy",
            "specs": []
        },
        {
            "name": "numba",
            "specs": []
        },
        {
            "name": "tushare",
            "specs": []
        },
        {
            "name": "mplfinance",
            "specs": []
        },
        {
            "name": "rich",
            "specs": []
        },
        {
            "name": "pytz",
            "specs": []
        },
        {
            "name": "matplotlib",
            "specs": []
        },
        {
            "name": "requests",
            "specs": []
        },
        {
            "name": "setuptools",
            "specs": []
        },
        {
            "name": "textual",
            "specs": []
        }
    ],
    "lcname": "qteasy"
}
        
Elapsed time: 0.27751s