量化交易机器人系统开发详细及策略丨量化合约/合约量化系统开发成熟及技术丨源码案例
The two main uses of quantitative trading robots are to make markets through arbitrage;When the market is relatively cold,act as the corresponding seller or buyer,and activate trading volume in the market;After initializing the setting parameters,the quantitative trading robot will trade according to the strategy,automatically buying or selling when the set conditions are met,without the need for long-term trading;Strictly implement trading strategies based on the new market situation;Real time viewing of transaction conditions to ensure real-time execution of transactions;Try to avoid adverse effects caused by human subjective factors as much as possible.
量化策略是指使用计算机作为工具,通过一套固定的逻辑来分析、判断和决策。量
化策略既可以自动执行,也可以人工执行;开发策略及详情唯:MrsFu123,从本质上说,交易机器人是一种软件程序,它直接与金融交易所进行交互(通常使用API获取和解释相关信息),并根据市场数据的解释发出买卖订单。
这是一个PPQ量化的入口脚本,将你的模型和数据按要求进行打包:
This file will show you how to quantize your network with PPQ
You should prepare your model and calibration dataset as follow:
~/working/model.onnx<--your model
~/working/data/*.npy or~/working/data/*.bin<--your dataset
if you are using caffe model:
~/working/model.caffemdoel<--your model
~/working/model.prototext<--your model
###MAKE SURE YOUR INPUT LAYOUT IS[N,C,H,W]or[C,H,W]###
quantized model will be generated at:~/working/quantized.onnx
"""
from ppq import*
from ppq.api import*
import os
#modify configuration below:
WORKING_DIRECTORY='working'#choose your working directory
TARGET_PLATFORM=TargetPlatform.PPL_CUDA_INT8#choose your target platform
MODEL_TYPE=NetworkFramework.ONNX#or NetworkFramework.CAFFE
INPUT_LAYOUT='chw'#input data layout,chw or hwc
NETWORK_INPUTSHAPE=[1,3,224,224]#input shape of your network
CALIBRATION_BATCHSIZE=16#batchsize of calibration dataset
EXECUTING_DEVICE='cuda'#'cuda'or'cpu'.
REQUIRE_ANALYSE=False
DUMP_RESULT=False#是否需要Finetuning一下你的网络
#SETTING对象用于控制PPQ的量化逻辑
#当你的网络量化误差过高时,你需要修改SETTING对象中的参数进行特定的优化
SETTING=UnbelievableUserFriendlyQuantizationSetting(
platform=TARGET_PLATFORM,finetune_steps=2500,
finetune_lr=1e-3,calibration='kl',#【改】量化算法可选'kl','pecentile','mse'
equalization=True,non_quantable_op=None)
SETTING=SETTING.convert_to_daddy_setting()
print('正准备量化你的网络,检查下列设置:')
print(f'WORKING DIRECTORY:{WORKING_DIRECTORY}')
print(f'TARGET PLATFORM:{TARGET_PLATFORM.name}')
print(f'NETWORK INPUTSHAPE:{NETWORK_INPUTSHAPE}')
print(f'CALIBRATION BATCHSIZE:{CALIBRATION_BATCHSIZE}')
#此脚本针对单输入模型,输入数据必须是图像数据layout:[n,c,h,w]
#如果你的模型具有更复杂的输入格式,你可以重写下面的load_calibration_dataset函数
#请注意,任何可遍历对象都可以作为PPQ的数据集作为输入
dataloader=load_calibration_dataset(
directory=WORKING_DIRECTORY,
input_shape=NETWORK_INPUTSHAPE,
batchsize=CALIBRATION_BATCHSIZE,
input_format=INPUT_LAYOUT)
print('网络正量化中,根据你的量化配置,这将需要一段时间:')
quantized=quantize(
working_directory=WORKING_DIRECTORY,setting=SETTING,
model_type=MODEL_TYPE,executing_device=EXECUTING_DEVICE,
input_shape=NETWORK_INPUTSHAPE,target_platform=TARGET_PLATFORM,
dataloader=dataloader,calib_steps=32)