博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Dual Thrust策略
阅读量:4294 次
发布时间:2019-05-27

本文共 2925 字,大约阅读时间需要 9 分钟。

介绍参考:

:

要点:

日High的最高价HH, N日Close的最低价LC

N日Close的最高价HC,N日Low的最低价LL
Range = Max(HH-LC,HC-LL)
BuyLine = Open + K1*Range
SellLine = Open - K2*Range

当价格向上突破上轨时,如果当时持有空仓,则先平仓,再开多仓;如果没有仓位,则直接开多仓;

当价格向下突破下轨时,如果当时持有多仓,则先平仓,再开空仓;如果没有仓位,则直接开空仓;

当K1时,多头相对容易被触发,当K1>K2时,空头相对容易被触发。因此,投资者在使用该策略时,一方面可以参考历史数据测试的最优参数,另一方面,则可以根据自己对后势的判断,或从其他大周期的技术指标入手,阶段性地动态调整K1和K2的值。

代码:

import talibfrom rqalpha.api import *import numpyimport pandas as pdfrom pandas import Seriesfrom rqalpha import run_funcfrom rqalpha.api import industry, update_universe, order_target_valuefrom rqalpha.utils import schedulerimport numpy as npimport pandas as pdimport loggingimport warningsfrom math import ceilimport numpy as npimport pandas as pdimport matplotlib.pyplot as pltfrom rqalpha.api import *import scipy.optimize as scoimport seaborn as snsimport talibfrom sklearn.metrics import mean_squared_errorfrom sklearn.model_selection import TimeSeriesSplitfrom sklearn.preprocessing import StandardScaler# 在这个方法中编写任何的初始化逻辑。context对象将会在你的算法策略的任何方法之间做传递。def init(context):    context.future_id = "IH88"    context.max_length = 10    subscribe(context.future_id)    context.fired = False    context.k1 = 0.5    context.k2 = 0.5    context.qty = 5# before_day_trading此函数会在每天日盘交易开始前被调用,当天只会被调用一次def before_day_trading(context):    pass# 你选择的期货数据更新将会触发此段逻辑,例如日线或分钟线更新def handle_bar(context, bar_dict):    if context.now.strftime('%H:%M') < '14:59':        hist_close = history_bars(context.future_id, context.max_length, '1d', 'close')        hist_high = history_bars(context.future_id, context.max_length, '1d', 'high')        hist_low = history_bars(context.future_id, context.max_length, '1d', 'low')        price_open = history_bars(context.future_id, 1, '1d', 'open')[0]        range = max(max(hist_high) - min(hist_close), max(hist_close) - min(hist_low))        up = price_open + context.k1 * range        down = price_open - context.k2 * range        price_now = bar_dict[context.future_id].close        if price_now > up:            sell_qty = context.portfolio.positions[context.future_id].sell_quantity            if sell_qty > 0:                buy_close(context.future_id, sell_qty)            buy_open(context.future_id, context.qty)        if price_now < down:            buy_qty = context.portfolio.positions[context.future_id].buy_quantity            if buy_qty > 0:                sell_close(context.future_id, buy_qty)            sell_open(context.future_id, context.qty)    else:        buy_qty = context.portfolio.positions[context.future_id].buy_quantity        sell_qty = context.portfolio.positions[context.future_id].sell_quantity        if buy_qty > 0:            sell_close(context.future_id, buy_qty)        if sell_qty > 0:            buy_close(context.future_id, sell_qty)# before_night_trading此函数会在每天夜盘交易开始前被调用,当天只会被调用一次def before_night_trading(context):    pass

这是个裸策略,未做任何优化,结果也不佳,也在意料之中的. 

经典策略还是得依靠调优等方式改造后才能使用,要是拿来就用那历史上就出来无数的大富翁了.

 

参考:

转载地址:http://dhyws.baihongyu.com/

你可能感兴趣的文章
功率与dbm关系
查看>>
CC1101调试入门
查看>>
SPI时序分析
查看>>
MSP430FR5969内存分配的问题
查看>>
C语言在程序中内存
查看>>
CCS中CMD文件解析
查看>>
volatile关键字作用
查看>>
联合体union的使用
查看>>
MFC中CArray类原理及其应用
查看>>
CArray的用法
查看>>
什么是动态链接库
查看>>
如何创建与调用动态链接库
查看>>
CString LPCTSTR区别联系
查看>>
LPSTR、LPCSTR、LPTSTR和LPCTSTR的意义及区别
查看>>
C语言文件操作详解
查看>>
C++虚函数定义
查看>>
C语言 unlink函数
查看>>
对SendMessage与PostMessage的理解
查看>>
共享内存
查看>>
CRecordset类
查看>>