### Minimal Backtest Example in QTEasy Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/back_testing/2. run_backtest.md This example shows the basic setup for running a backtest. Ensure your data source and Operator are configured before execution. ```python import qteasy as qt # 假设已配置数据源与 Operator op = qt.Operator(strategies='dma', signal_type='PT', run_freq='d') qt.configure(asset_pool='000001.SZ', invest_start='2020-01-01', invest_end='2023-12-31') result = qt.run(op, mode=1) ``` -------------------------------- ### Import QTEASY and check version Source: https://github.com/shepherdpp/qteasy/blob/master/README.md Import the QTEASY library and display its current version. This is a basic step to verify the installation and start using the library. ```python import qteasy as qt qt.__version__ ``` -------------------------------- ### QTEASY configuration file example Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/tutorials/1-get-started.md An example of a correctly configured `qteasy.cfg` file, including settings for tushare token and database connection. ```default tushare_token = xxxxxxxxxxxxxxxxxxxxx local_data_source = database local_db_host = localhost local_db_port = 3306 local_db_user = user_name local_db_password = pass_word local_db_name = qt_db ``` -------------------------------- ### Install qteasy with Pip Mirrors Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/faq.md Use a mirror source to speed up installation in regions with restricted network access. ```bash $ pip install -i https://pypi.tuna.tsinghua.edu.cn/simple qteasy ``` -------------------------------- ### Install QTEASY Source: https://github.com/shepherdpp/qteasy/wiki/1-‐-安装方法及初始配置 Install the qteasy package using pip within an activated virtual environment. ```bash pip install qteasy ``` -------------------------------- ### Install TA-Lib for QTEASY Source: https://github.com/shepherdpp/qteasy/blob/master/README.md Install the TA-Lib API for use with QTEASY, which enables all built-in trading strategies. Note that this also requires a C-language TA-Lib installation. ```bash pip install 'qteasy[talib]' ``` -------------------------------- ### Example of Correct qteasy.cfg Configuration Source: https://github.com/shepherdpp/qteasy/wiki/1-‐-安装方法及初始配置 This example shows the correct format for configuring Tushare token and MySQL database connection details in qteasy.cfg. Note that angle brackets should be omitted. ```ini tushare_token = 2dff3f034aa966479c81e4b4b0736fb081b740abb2xxxxxxxxxxxxxxxxxxxxx local_data_source = database local_db_host = localhost local_db_port = 3306 local_db_user = user_name local_db_password = pass_word local_db_name = qt_db ``` -------------------------------- ### Install QTEASY with Feather support Source: https://github.com/shepherdpp/qteasy/blob/master/README.md Install QTEASY along with the 'pyarrow' library for Feather file support. This is useful for efficient local data storage. ```bash pip install 'qteasy[feather]' ``` -------------------------------- ### Configure qteasy.cfg Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/faq.md Examples of correct configuration syntax for database connections in qteasy.cfg. ```default local_db_port = 3306 ``` ```default tushare_token = 2dff3f034aa966479c81e4b4b0736fb081b740abb2xxxxxxxxxxxxxxxxxxxxx local_data_source = database local_db_host = localhost local_db_port = 3306 local_db_user = user_name local_db_password = pass_word local_db_name = ts_db ``` -------------------------------- ### Manually install TA-Lib Source: https://github.com/shepherdpp/qteasy/blob/master/README.md Manually install the TA-Lib Python package. This is an alternative to using the QTEASY-specific installation command. ```bash pip install ta-lib ``` -------------------------------- ### Install pymysql Source: https://github.com/shepherdpp/qteasy/wiki/1-‐-安装方法及初始配置 Install the pymysql library, which is required for MySQL database support in QTEASY. ```bash pip install pymysql ``` -------------------------------- ### Get QTEASY Root Path Source: https://github.com/shepherdpp/qteasy/wiki/1-‐-安装方法及初始配置 Print the root directory path of the qteasy installation. ```python import qteasy as qt print(qt.QT_ROOT_PATH) ``` -------------------------------- ### Display Startup Settings Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/api/api_reference.md Prints the startup settings stored in QTEasy's configuration file. ```APIDOC ## GET /start_up_settings ### Description Prints the startup settings stored in QTEasy's configuration file. ### Method GET ### Endpoint /start_up_settings ### Response #### Success Response (200) - **None** - This function does not return any value, but prints settings to the console. ### Response Example ``` Start up settings: -------------------- local_data_source = file local_data_file_type = csv local_data_file_path = data/ ``` ``` -------------------------------- ### Get Historical Data with Specific Htypes Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/api/history_data.md Use special htypes to retrieve specific data, such as index weighting information. This example fetches the weight data for '000001.SZ' within the 'HS300' index. ```python >>> # 使用特殊的htypes,可以获取特定的数据,如指数权重数据,下面的代码获取000001.SZ在HS300指数重的权重数据,单位为百分比 >>> qt.get_history_data(htype_names='wt_id:000300.SH', shares='000001.SZ, 000002.SZ', start='20191225', end='20200105') {'000001.SZ': wt_idx:000300.SH 2020-01-02 1.1714 2020-01-03 1.1714, '000002.SZ': wt_idx:000300.SH 2020-01-02 1.3595 2020-01-03 1.3595 } ``` -------------------------------- ### Get HistoryPanel Segment Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/api/HistoryPanel.md Illustrates how to extract a specific date range segment from a HistoryPanel using the .isegment() method with start and end indices. The method returns a new HistoryPanel containing data only for the specified date range. ```python >>> hp = HistoryPanel(np.array([[[10, 20, 30, 40, 50]]*10]*3), ... levels=['000001', '000002', '000003'], ... rows=pd.date_range('2015-01-05', periods=10), ... columns=['open', 'high', 'low', 'close', 'volume']) >>> hp.isegment(2, 5) ``` -------------------------------- ### Get Adjusted Closing Price using DataType Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/manage_data/02. datatypes.md Demonstrates how to use a predefined DataType object ('close|b') to fetch the adjusted closing price for a specific stock within a date range. Ensure the qteasy library is installed and the QT_DATA_SOURCE is configured. ```python import qteasy from qteasy.datatypes import DataType # Get the adjusted closing price for Gree Electric Appliances from 2025-02-01 to 2025-02-27 close_b = DataType(name='close|b', asset_type='E', freq='D') close_b.get_data_from_source( datasource=qteasy.QT_DATA_SOURCE, symbols='000651.SZ', starts='2025-02-01', ends='2025-02-27', ) ``` -------------------------------- ### Import QTEASY and Print Version Source: https://github.com/shepherdpp/qteasy/wiki/1-‐-安装方法及初始配置 Import the qteasy library and print its version. This action also triggers the initial setup and creates a configuration file if it doesn't exist. ```python import qteasy as qt print(qt.__version__) ``` -------------------------------- ### View Current QTEasy Settings Source: https://github.com/shepherdpp/qteasy/blob/master/README.md Use `qt.start_up_settings()` to view the current configuration of QTEasy. This helps verify that your settings are correctly applied. ```python qt.start_up_settings() ``` -------------------------------- ### Install TA-Lib Python Wrapper Source: https://github.com/shepherdpp/qteasy/wiki/1-‐-安装方法及初始配置 After installing the C language TA-Lib, install its Python wrapper using pip. ```bash pip install TA-Lib ``` -------------------------------- ### qteasy.run() - Unified Entry Point Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/api/use_qteasy.md The `run` function serves as the unified entry point for QTEASY operations. It executes a given Operator based on the current configuration, supporting various modes like backtesting, optimization, or live trading. Temporary configuration overrides can be applied via keyword arguments. ```APIDOC ## POST /api/run ### Description Starts QTEASY configuration and runs a given Operator in different modes (backtesting, optimization, live trading). ### Method POST ### Endpoint /api/run ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **op** (Operator) - Required - An Operator object with configured strategy and running parameters. - **kwargs** (dict) - Optional - Temporary configuration items to override global settings, such as `mode`, `asset_pool`, `invest_start`, `invest_end`. ### Request Example ```json { "op": { "strategy_name": "dma" }, "mode": "BACKTEST_MODE", "invest_start": "2023-01-01", "invest_end": "2023-12-31" } ``` ### Response #### Success Response (200) - **result** (dict or list) - The structure of the returned data depends on the `mode`. - For `mode == 1` (backtesting), typically returns a dictionary with backtesting results. - For `mode == 2` (optimization), typically returns a list of results for multiple parameter sets. - For live trading and other modes, refer to `Operator.run()` documentation. #### Response Example ```json { "result": { "total_return": 0.15, "sharpe_ratio": 1.2, "drawdown": 0.05 } } ``` ``` -------------------------------- ### Install TA-Lib Dependency Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/faq.md Instructions for installing the C-based TA-Lib library on various operating systems before installing the Python wrapper. ```bash $ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" $ brew install ta-lib ``` ```bash $ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" $ arch -arm64 brew install ta-lib ``` ```bash $ tar -xzf ta-lib-0.4.0-src.tar.gz $ cd ta-lib/ $ ./configure --prefix=/usr $ make $ sudo make install ``` ```bash $ pip install ta-lib ``` ```bash $ arch -arm64 python -m pip install --no-cache-dir ta-lib ``` -------------------------------- ### Install PyArrow manually Source: https://github.com/shepherdpp/qteasy/blob/master/README.md Manually install the PyArrow library, which is used for Feather file operations. This can be done after QTEASY is installed. ```bash pip install pyarrow ``` -------------------------------- ### Install Plotly for Interactive Charts Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/getting_started.md Install Plotly for basic interactive chart functionality. For enhanced interactivity in Notebooks (FigureWidget), install ipywidgets and anywidget. ```bash pip install plotly ``` ```bash pip install ipywidgets anywidget ``` -------------------------------- ### Install PyTables with Conda Source: https://github.com/shepherdpp/qteasy/blob/master/README.md Install the PyTables library using Conda, which is required for HDF file operations. This library cannot be automatically installed via pip. ```bash conda install pytables ``` -------------------------------- ### Run Strategy Optimization with Grid Search Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/optimization/2. run_optimization.md This example demonstrates how to run strategy optimization using the 'grid' method. It initializes a 'dma' strategy operator, configures backtesting parameters, and then executes the optimization with specified sample and output counts. Ensure necessary parameters like asset pool and investment period are configured. ```python import qteasy as qt op = qt.Operator(strategies='dma', signal_type='PT', run_freq='d') # dma 策略带 short_period、long_period 等可调参数 qt.configure(asset_pool='000001.SZ', invest_start='2020-01-01', invest_end='2023-12-31') result = qt.run(op, mode=2, opti_method='grid', opti_sample_count=100, opti_output_count=10) ``` -------------------------------- ### Manage qteasy startup settings Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/api/api_reference.md Functions to view, update, and remove startup configuration settings. ```pycon >>> import qteasy as qt >>> qt.start_up_settings() Start up settings: -------------------- local_data_source = file local_data_file_type = csv local_data_file_path = data/ ``` ```pycon >>> import qteasy as qt >>> qt.start_up_settings() Start up settings: -------------------- local_data_source = file local_data_file_type = csv local_data_file_path = data/ ``` ```pycon >>> qt.update_start_up_setting(local_data_source='database', local_data_file_type='feather') Start up settings updated successfully! ``` ```pycon >>> qt.start_up_settings() Start up settings: -------------------- local_data_source = file local_data_file_type = feather local_data_file_path = data/ ``` ```pycon >>> import qteasy as qt >>> qt.start_up_settings() Start up settings: -------------------- local_data_source = file local_data_file_type = csv local_data_file_path = data/ ``` ```pycon >>> qt.remove_start_up_setting('local_data_source') Start up settings removed: ('local_data_source',) ``` ```pycon >>> qt.start_up_settings() Start up settings: -------------------- local_data_file_type = csv local_data_file_path = data/ ``` -------------------------------- ### Operator Strategy Management Example Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/references/3-back-test-strategy.md Demonstrates clearing existing strategies, adding a new strategy with specific parameters, and then printing the Operator's strategies and IDs. It also shows verbose operator information. ```python op.clear_strategies() op.add_strategy(stg, pars=(26, 35, 189), opt_tag=1) print(f'Operator strategies: {op.strategies}') print(f'Strategy IDs are: {op.strategy_ids}') op.info(verbose=True) ``` -------------------------------- ### get_history_data Example Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/api/HistoryPanel.md Example of how to use get_history_data with special htypes to retrieve specific data like index weights. ```APIDOC ## get_history_data Example ### Description This example demonstrates fetching index weight data for specific stocks within a given date range using the `get_history_data` function with the `htype_names` parameter. ### Method ```python qt.get_history_data(htype_names='wt_id:000300.SH', shares='000001.SZ, 000002.SZ', start='20191225', end='20200105') ``` ### Response Example ```json { "000001.SZ": { "wt_idx:000300.SH": { "2020-01-02": 1.1714, "2021-01-03": 1.1714 } }, "000002.SZ": { "wt_idx:000300.SH": { "2020-01-02": 1.3595, "2021-01-03": 1.3595 } } } ``` ``` -------------------------------- ### Run Backtest with Visualization and Trade Log Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/tutorials/3-start-first-strategy.md Execute the trading strategy using 'qt.run()' with visualization and trade log enabled to analyze performance. ```python res=qt.run(op, visual=True, trade_log=True) ``` -------------------------------- ### Blender Expression Example Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/references/4-build-in-strategy-blender.md A practical example demonstrating how to set up and use blender expressions with multiple trading strategies. ```APIDOC ## Blender Expression Example This example illustrates how to create an Operator with multiple identical strategies, set different parameters for each, and then combine their signals using a blender expression. ### Setup ```python # Initialize an Operator with five identical DMA strategies # Each strategy will generate different signals due to distinct parameters op = qt.Operator('dma, dma, dma, dma, dma') # Set unique parameters for each strategy instance op.set_parameter(stg_id=0, pars=(132, 200, 24)) op.set_parameter(stg_id=1, pars=(124, 187, 51)) op.set_parameter(stg_id=2, pars=(103, 81, 16)) op.set_parameter(stg_id=3, pars=(48, 111, 148)) op.set_parameter(stg_id=4, pars=(104, 127, 58)) ``` ### Weighted Average Combination One method to combine signals is through weighted averaging. Assign different weights to each strategy's output: - Strategy 0: Weight 0.8 - Strategy 1: Weight 1.2 - Strategy 2: Weight 2.0 - Strategy 3: Weight 0.5 - Strategy 4: Weight 1.5 To implement this, you would set the blender expression using `op.set_blender()` with a string representing the weighted sum, for example: ```python # Example of setting a weighted average blender expression # Note: The actual expression string would be constructed based on the weights and signal names (s0, s1, etc.) # op.set_blender("0.8*s0 + 1.2*s1 + 2.0*s2 + 0.5*s3 + 1.5*s4") ``` ``` -------------------------------- ### POST /qt/configure Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/references/3-back-test-strategy.md Configures the qteasy running environment variables, including backtesting parameters, asset pools, and investment settings. ```APIDOC ## POST /qt/configure ### Description Sets the environment variables for qteasy, such as backtesting dates, initial capital, asset pools, and trading rules. ### Method POST ### Parameters #### Request Body - **mode** (int) - Optional - 1 for backtesting mode - **benchmark_asset** (string) - Optional - Asset code for performance benchmarking - **asset_pool** (string) - Optional - Trading asset combination - **asset_type** (string) - Optional - Type of assets (e.g., 'IDX') - **trade_batch_size** (float) - Optional - Minimum trading batch size - **invest_start** (string) - Optional - Start date of investment (YYYYMMDD) - **invest_end** (string) - Optional - End date of investment (YYYYMMDD) - **invest_cash_amounts** (list) - Optional - Initial investment amounts - **visual** (boolean) - Optional - Whether to output visual charts ### Request Example { "mode": 1, "benchmark_asset": "000300.SH", "asset_pool": "000300.SH", "asset_type": "IDX", "trade_batch_size": 0.01, "invest_start": "20100105", "invest_end": "20201231", "invest_cash_amounts": [1000000], "visual": true } ``` -------------------------------- ### Initialize Operator and Run Backtest Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/examples/Example_02_Alpha选股策略.md Configures the strategy parameters and executes the backtest using the qt.run function. ```python >>> import numpy as np >>> alpha = AlphaPS(pars=[], ... name='AlphaPS', ... description='本策略每隔1个月定时触发计算SHSE.000300成份股的过去的EV/EBITDA并选取EV/EBITDA大于0的股票', ... data_types=[DataType('total_mv', asset_type='E'), ... DataType('total_liab'), ... DataType('c_cash_equ_end_period'), ... DataType('ebitda')], ... window_length=10) >>> op = qt.Operator(alpha, signal_type='PS') >>> qt.run(op=op, ... mode=1, ... asset_type='E', ... asset_pool=shares, ... invest_start='20160405', ... invest_end='20210201', ... trade_batch_size=100, ... sell_batch_size=1, ... trade_log=True) ``` -------------------------------- ### Install TA-Lib C library on Linux Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/tutorials/1-get-started.md Download, configure, compile, and install the TA-Lib C library from source on Linux systems. ```bash tar -xzf ta-lib-0.4.0-src.tar.gz cd ta-lib/ ./configure --prefix=/usr make sudo make install ``` -------------------------------- ### Configure for Path A: E + simulator Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/tutorials/8-live-trade-risk-and-broker-walkthrough.md Sets up the qteasy configuration for simulated live trading using asset type 'E' and a simulator broker. Ensure live trading parameters are correctly configured. ```python import qteasy as qt qt.configure( mode=0, asset_type='E', live_trade_broker_type='simulator', live_price_acquire_channel='eastmoney', live_price_acquire_freq='15MIN', ) ``` -------------------------------- ### Update QTEASY startup settings Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/tutorials/1-get-started.md Use `update_start_up_setting()` to modify QTEASY's startup configuration. Settings will take effect on the next import. ```python qt.update_start_up_setting(tushare_token='你的tushare token', local_data_source='database', local_db_host='localhost', local_db_port=3306, local_db_user='user_name', local_db_password='pass_word', local_db_name='qt_db') qt.start_up_settings() ``` -------------------------------- ### 查看qteasy配置 Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/references/2-get-history-data.md 使用qt.configuration查看当前配置变量,使用qt.QT_DATA_SOURCE查看当前数据源设置。 ```python qt.configuration(config_key='local_data_source, local_data_file_type, local_data_file_path', default=False) qt.QT_DATA_SOURCE ``` -------------------------------- ### Install TA-Lib C library on Mac OS Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/tutorials/1-get-started.md Use Homebrew to install the TA-Lib C library on macOS. For Apple Silicon chips, use the `arch -arm64` command. ```bash brew install ta-lib ``` ```bash arch -arm64 brew install ta-lib ``` -------------------------------- ### Backtesting Result Output with Custom Settings Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/examples/Example_04_多因子选股.md Example output from a QTEasy backtesting run using custom operator settings, demonstrating performance over a different investment period. ```bash ==================================== | | | BACK TESTING RESULT | | | ==================================== qteasy running mode: 1 - History back testing time consumption for operate signal creation: 0.0 ms time consumption for operation back looping: 8 sec 335.0 ms investment starts on 2016-04-05 00:00:00 ends on 2021-02-01 00:00:00 Total looped periods: 4.8 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 ``` -------------------------------- ### Configure and Run DMA Strategy Backtest Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/getting_started.md Set up QTEasy configuration parameters for backtesting, including asset pool, investment amounts, dates, costs, and visualization options. Then, create an Operator with the 'dma' strategy and run the backtest. ```python >>> # 设置qteasy的运行配置参数 >>> qt.configure( ... asset_pool='000300.SH', # 交易资产池包括沪深300指数 ... asset_type='IDX', # 投资资产类型为IDX-指数 ... invest_cash_amounts=[100000], # 回测初始投资金额为十万元 ... invest_start='20150101', # 回测投资初始日期 ... invest_end='20241231', # 回测投资结束日期 ... cost_rate_buy=0.0003, # 交易费率:买入手续费万分之三 ... cost_rate_sell=0.0001, # 交易费率:卖出手续费万分之一 ... visual=True, # 是否输出回测结果可视化图表:是 ... trade_log=True, # 是否输出回测记录:是 ... ) >>> op = qt.Operator(strategies='dma') # 创建一个交易员对象,执行一个DMA交易策略 >>> op.set_parameter('dma', par_values=(20, 60, 10)) # 设置交易策略的参数 >>> res = qt.run(op, mode=1) # 启动交易,运行模式为1(回测交易) ``` -------------------------------- ### GET /cashflow Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/manage_data/08. data_tables_40.md 获取上市公司的现金流量表数据,包含经营活动、投资活动及筹资活动等详细现金流指标。 ```APIDOC ## GET /cashflow ### Description 获取上市公司的现金流量表数据,包含经营活动、投资活动及筹资活动等详细现金流指标。 ### Method GET ### Endpoint /cashflow ### Parameters #### Query Parameters - **ts_code** (varchar) - Required - 证券代码 - **end_date** (date) - Required - 报告期 ### Response #### Success Response (200) - **ts_code** (varchar) - 证券代码 - **end_date** (date) - 报告期 - **ann_date** (date) - 公告日期 - **f_ann_date** (date) - 实际公告日期 - **comp_type** (varchar) - 公司类型 - **report_type** (varchar) - 报表类型 - **end_type** (varchar) - 报告期类型 - **net_profit** (double) - 净利润 - **finan_exp** (double) - 财务费用 - **c_fr_sale_sg** (double) - 销售商品、提供劳务收到的现金 - **recp_tax_rends** (double) - 收到的税费返还 - **n_depos_incr_fi** (double) - 客户存款和同业存放款项净增加额 - **n_incr_loans_cb** (double) - 向中央银行借款净增加额 - **n_inc_borr_oth_fi** (double) - 向其他金融机构拆入资金净增加额 - **prem_fr_orig_contr** (double) - 收到原保险合同保费取得的现金 - **n_incr_insured_dep** (double) - 保户储金净增加额 - **n_reinsur_prem** (double) - 收到再保业务现金净额 - **n_incr_disp_tfa** (double) - 处置交易性金融资产净增加额 - **ifc_cash_incr** (double) - 收取利息和手续费净增加额 - **n_incr_disp_faas** (double) - 处置可供出售金融资产净增加额 - **n_incr_loans_oth_bank** (double) - 拆入资金净增加额 - **n_cap_incr_repur** (double) - 回购业务资金净增加额 - **c_fr_oth_operate_a** (double) - 收到其他与经营活动有关的现金 - **c_inf_fr_operate_a** (double) - 经营活动现金流入小计 - **c_paid_goods_s** (double) - 购买商品、接受劳务支付的现金 - **c_paid_to_for_empl** (double) - 支付给职工以及为职工支付的现金 - **c_paid_for_taxes** (double) - 支付的各项税费 - **n_incr_clt_loan_adv** (double) - 客户贷款及垫款净增加额 - **n_incr_dep_cbob** (double) - 存放央行和同业款项净增加额 - **c_pay_claims_orig_inco** (double) - 支付原保险合同赔付款项的现金 - **pay_handling_chrg** (double) - 支付手续费的现金 - **pay_comm_insur_plcy** (double) - 支付保单红利的现金 - **oth_cash_pay_oper_act** (double) - 支付其他与经营活动有关的现金 - **st_cash_out_act** (double) - 经营活动现金流出小计 - **n_cashflow_act** (double) - 经营活动产生的现金流量净额 - **oth_recp_ral_inv_act** (double) - 收到其他与投资活动有关的现金 - **c_disp_withdrwl_invest** (double) - 收回投资收到的现金 - **c_recp_return_invest** (double) - 取得投资收益收到的现金 - **n_recp_disp_fiolta** (double) - 处置固定资产、无形资产和其他长期资产收回的现金净额 - **n_recp_disp_sobu** (double) - 处置子公司及其他营业单位收到的现金净额 - **stot_inflows_inv_act** (double) - 投资活动现金流入小计 - **c_pay_acq_const_fiolta** (double) - 购建固定资产、无形资产和其他长期资产支付的现金 - **c_paid_invest** (double) - 投资支付的现金 - **n_disp_subs_oth_biz** (double) - 取得子公司及其他营业单位支付的现金净额 - **oth_pay_ral_inv_act** (double) - 支付其他与投资活动有关的现金 - **n_incr_pledge_loan** (double) - 质押贷款净增加额 - **stot_out_inv_act** (double) - 投资活动现金流出小计 - **n_cashflow_inv_act** (double) - 投资活动产生的现金流量净额 ``` -------------------------------- ### DMA Strategy Backtest Report Example Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/getting_started.md Example output of a DMA strategy backtest, showing key performance indicators, operation summary, and investment details. This report is generated after running the backtest. ```default ==================================== | | | BACKTEST REPORT | | | ==================================== qteasy running mode: 1 - History back testing time consumption for operate signal creation: 81.3 ms time consumption for operation back testing: 4.9 ms investment starts on 2015-01-05 15:00:00 ends on 2024-12-30 15:00:00 Total looped periods: 10.0 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 340 41 381 44.7% -0.0% 55.3% Total operation fee: ¥ 3,261.19 total investment amount: ¥ 100,000.00 final value: ¥ 115,601.73 Total return: 15.60% Avg Yearly return: 1.46% Skewness: -1.16 Kurtosis: 16.95 Benchmark return: 1.67% Benchmark Yearly return: 0.17% ------strategy loop_results indicators------ alpha: 0.006 Beta: 0.975 Sharp ratio: 0.113 Info ratio: 0.001 250 day volatility: 0.130 Max drawdown: 36.85% peak / valley: 2015-04-27 / 2018-11-27 recovered on: Not recovered! ==================END OF REPORT=================== ``` -------------------------------- ### Configure QTEasy Backtesting Environment Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/references/3-back-test-strategy.md Set up essential backtesting environment variables such as benchmark, asset pool, dates, initial investment, and visualization preferences. These settings persist until changed. ```python qt.configure( mode=1, # 设置运行模式为:1-回测模式 benchmark_asset = '000300.SH', # 设置交易评价基准(类型由系统根据代码自动推断) asset_pool = '000300.SH', # 设置交易资产组合 asset_type = 'IDX', # 交易资产组合的资产类型 trade_batch_size = 0.01, # 设置允许最小交易批量(最小0.01) invest_start = '20100105', # 设置交易开始日期 invest_end = '20201231', # 设置交易终止日期 invest_cash_amounts = [1000000], # 设置初始交易投资金额为十万元 visual=True # 输出可视化交易结果图表 ) ``` -------------------------------- ### Get Data Source Overview Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/manage_data/03. datasource.md Use the `overview()` method to analyze all data tables in the data source and get a summary of their information. This process may take time depending on the size of the tables. ```python >>> overview = ds.overview() Analyzing local data source tables... depending on size of tables, it may take a few minutes [########################################]104/104-100.0% A...zing completed! Finished analyzing datasource: file://csv@qt_root/data/ 3 table(s) out of 104 contain local data as summary below, to view complete list, print returned DataFrame ===============================tables with local data=============================== Has_data Size_on_disk Record_count Record_start Record_end table trade_calendar True 1.8MB 70K CFFEX SZSE stock_basic True 852KB 5K None None stock_daily True 98.8MB 1.3M 20211112 20241231 ``` -------------------------------- ### Configure Live Trading Environment Source: https://github.com/shepherdpp/qteasy/blob/master/docs/source/live_trading/2-configuration-and-run.md Use these templates to set up the live trading environment for stocks or funds using the simulator broker. ```python import qteasy as qt qt.configure( mode=0, asset_type='E', live_trade_broker_type='simulator', live_price_acquire_channel='eastmoney', live_price_acquire_freq='15MIN', ) ``` ```python import qteasy as qt qt.configure( mode=0, asset_type='FD', live_trade_broker_type='simulator', live_price_acquire_channel='eastmoney', live_price_acquire_freq='15MIN', ) ```