R-Breaker策略

2024-04-24 22:08
文章标签 策略 breaker

本文主要是介绍R-Breaker策略,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

R-Breaker 是一种短线日内交易策略,它结合了趋势和反转两种交易方式。该策略也长期被Future Thruth 杂志评为最赚钱的策略之一,尤其在标普500 股指期货上效果最佳。该策略的主要特点如下:

第一、根据前一个交易日的收盘价、最高价和最低价数据通过一定方式计算出六个价位,从大到小依次为突破买入价、观察卖出价、反转卖出价、反转买入价、观察买入价和突破卖出价,以此来形成当前交易日盘中交易的触发条件。通过对计算方式的调整,可以调节六个价格间的距离,进一步改变触发条件。

第二、根据盘中价格走势,实时判断触发条件,具体条件如下: 1) 当日内最高价超过观察卖出价后,盘中价格出现回落,且进一步跌破反转卖出价构成的支撑线时,采取反转策略,即在该点位(反手、开仓)做空; 2) 当日内最低价低于观察买入价后,盘中价格出现反弹,且进一步超过反转买入价构成的阻力线时,采取反转策略,即在该点位(反手、开仓)做多; 3) 在空仓的情况下,如果盘中价格超过突破买入价,则采取趋势策略,即在该点位开仓做多; 4) 在空仓的情况下,如果盘中价格跌破突破卖出价,则采取趋势策略,即在该点位开仓做空。

第三、设定止损以及止盈条件;

第四、设定过滤条件;

第五、在每日收盘前,对所持合约进行平仓。

具体来看,这六个价位形成的阻力和支撑位计算过程如下:

观察卖出价 = High + 0.35 * (Close – Low)
观察买入价 = Low – 0.35 * (High – Close)
反转卖出价 = 1.07 / 2 * (High + Low) – 0.07 * Low
反转买入价 = 1.07 / 2 * (High + Low) – 0.07 * High
突破买入价 = 观察卖出价 + 0.25 * (观察卖出价 – 观察买入价)
突破卖出价 = 观察买入价 – 0.25 * (观察卖出价 – 观察买入价)
其中,High、Close、Low 分别为昨日最高价、昨日收盘价和昨日最低价。这六个价位从大到小一次是,突破买入价、观察爱出价、反转卖出价、反转买入价、观察买入价和突破卖出价。

import DataAPI import numpy as np import pandas as pd import talib as ta from collections import deque from itertools import product import datetime import matplotlib import matplotlib.pyplot as plt import matplotlib.cm as cm import seaborn as sns import quartz_futures as qf from quartz_futures.api import * from CAL import * cal = Calendar(‘China.SSE’) class DataCenter(): keys = [u’openPrice’, u’highPrice’, u’lowPrice’, u’closePrice’, u’tradeDate’, u’volume’] def init(self, refresh_rate, pipe_length): self.data = {key:deque([], maxlen=pipe_length) for key in self.keys}#用双向队列保存数据 self.refresh_rate = refresh_rate # 算法调用周期 self.pipe_length = pipe_length #队列长度 def update_data(self, symbol): if len(self.data[‘openPrice’]) < self.pipe_length: hist = get_symbol_history(symbol=symbol, field=self.keys, time_range=self.refresh_rate*self.pipe_length)[symbol] else: hist = get_symbol_history(symbol=symbol, field=self.keys, time_range=self.refresh_rate)[symbol] # hist.index = range(len(hist)) current_data = {key:[] for key in self.keys} for i in range(len(hist)/self.refresh_rate): current_bar = hist[self.refresh_rate*i:self.refresh_rate*(i+1)] current_data[‘closePrice’].append(current_bar.ix[len(current_bar)-1, ‘closePrice’]) current_data[‘openPrice’].append(current_bar.ix[0, ‘openPrice’]) current_data[‘highPrice’].append(current_bar[‘highPrice’].max()) current_data[‘lowPrice’].append(current_bar[‘lowPrice’].min()) current_data[‘volume’].append(current_bar[‘volume’].sum()) current_data[‘tradeDate’].append(current_bar.ix[len(current_bar)-1, ‘tradeDate’]) for i in self.keys: for j in current_data[i]: self.data[i].append(j) return self.data ### 策略初始化函数 universe = ‘RBM0’ # 策略交易的期货合约,此处选择IH1609 start = “2010-01-01” # 回测开始时间 end = “2016-12-28” # 回测结束时间 capital_base = 1e6 # 初始可用资金 refresh_rate = 5 # 算法调用周期 freq = ‘m’ # 算法调用频率:m-> 分钟;d-> 日; commissions = {‘RB’: (0.000025, ‘perValue’)} slippage = Slippage(0, ‘perValue’) amount = 20 def initialize(futures_account): global data_pool data_pool = DataCenter(refresh_rate, 2) futures_account.high = np.NAN futures_account.low = np.NAN futures_account.close = np.NAN futures_account.count1 = 0 futures_account.count2 = 0 def handle_data(futures_account): symbol = get_symbol(universe) long_position = futures_account.position.get(symbol, dict()).get(‘long_position’, 0) short_position = futures_account.position.get(symbol, dict()).get(‘short_position’, 0) if futures_account.current_time == ‘09:30:00’: yester_data = DataAPI.MktFutdGet(tradeDate=futures_account.previous_date, ticker=symbol, field=[u’closePrice’, u’highestPrice’,u’lowestPrice’], pandas=”1”) futures_account.high = yester_data[‘highestPrice’].iat[0] futures_account.low = yester_data[‘lowestPrice’].iat[0] futures_account.close = yester_data[‘closePrice’].iat[0] if futures_account.current_time > ‘09:30:00’ and futures_account.current_time < ‘14:55:00’: data = data_pool.update_data(symbol) before_2_close = data[‘closePrice’][-2] before_2_high = data[‘highPrice’][-2] before_1_close = data[‘closePrice’][-1] before_1_high = data[‘highPrice’][-1] before_1_low = data[‘lowPrice’][-1] before_1_open = data[‘openPrice’][-1] # 观察卖出价 ssetup=futures_account.high+0.35*(futures_account.close-futures_account.low) # 观察买入价 bsetup=futures_account.low-0.35*(futures_account.high-futures_account.close) # 反转卖出价 senter=(1+0.07)/2*(futures_account.high+futures_account.low)-0.07*futures_account.low # 反转买入价 benter = (1+0.07)/2*(futures_account.high+futures_account.low)-0.07*futures_account.high # 突破买入价 bbreak = ssetup+0.25*(ssetup-bsetup) # 突破卖出价 sbreak = bsetup-0.25*(ssetup-bsetup) ## 趋势 if before_2_close <= bbreak and before_1_close > bbreak: if long_position == 0: order(symbol, amount, ‘open’) if short_position != 0: order(symbol, short_position, ‘close’) if before_2_close >= sbreak and before_1_close < sbreak: if short_position == 0: order(symbol, -amount, ‘open’) if long_position != 0: order(symbol, -long_position, ‘close’) ## 反转 ### 多单反转,当日内最高价超过观察卖出价后,盘中价格出现回落,且进一步跌破反转卖出价构成的支撑线时,采取反转策略,即在该点位(反手、开仓)做空 if before_1_high > ssetup and before_1_close > senter: futures_account.count1 = 1 if futures_account.count1 == 1 and before_1_close < senter: if long_position > 0: order(symbol, -long_position, ‘close’) order(symbol, -amount, ‘open’) ### 空单反转,当日内最低价低于观察买入价后,盘中价格出现反弹,且进一步超过反转买入价构成的阻力线时,采取反转策略,即在该点位(反手、开仓)做多 if before_1_low < bsetup: futures_account.count2 = 1 if futures_account.count2 == 1 and before_1_close > benter: if short_position != 0: order(symbol, short_position, ‘close’) order(symbol, amount, ‘open’) elif futures_account.current_time >= ‘14:55:00’:#在每日收盘前,对所持合约进行平仓 if short_position > 0: order(symbol, short_position, ‘close’) if long_position > 0: order(symbol, -long_position, ‘close’) futures_account.high = np.NAN futures_account.low = np.NAN futures_account.close = np.NAN futures_account.count1 = 0 futures_account.count2 = 0

这篇关于R-Breaker策略的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/932963

相关文章

SpringBoot基于配置实现短信服务策略的动态切换

《SpringBoot基于配置实现短信服务策略的动态切换》这篇文章主要为大家详细介绍了SpringBoot在接入多个短信服务商(如阿里云、腾讯云、华为云)后,如何根据配置或环境切换使用不同的服务商,需... 目录目标功能示例配置(application.yml)配置类绑定短信发送策略接口示例:阿里云 & 腾

redis过期key的删除策略介绍

《redis过期key的删除策略介绍》:本文主要介绍redis过期key的删除策略,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录第一种策略:被动删除第二种策略:定期删除第三种策略:强制删除关于big key的清理UNLINK命令FLUSHALL/FLUSHDB命

SpringRetry重试机制之@Retryable注解与重试策略详解

《SpringRetry重试机制之@Retryable注解与重试策略详解》本文将详细介绍SpringRetry的重试机制,特别是@Retryable注解的使用及各种重试策略的配置,帮助开发者构建更加健... 目录引言一、SpringRetry基础知识二、启用SpringRetry三、@Retryable注解

MySQL 分区与分库分表策略应用小结

《MySQL分区与分库分表策略应用小结》在大数据量、复杂查询和高并发的应用场景下,单一数据库往往难以满足性能和扩展性的要求,本文将详细介绍这两种策略的基本概念、实现方法及优缺点,并通过实际案例展示如... 目录mysql 分区与分库分表策略1. 数据库水平拆分的背景2. MySQL 分区策略2.1 分区概念

SpringBoot如何通过Map实现策略模式

《SpringBoot如何通过Map实现策略模式》策略模式是一种行为设计模式,它允许在运行时选择算法的行为,在Spring框架中,我们可以利用@Resource注解和Map集合来优雅地实现策略模式,这... 目录前言底层机制解析Spring的集合类型自动装配@Resource注解的行为实现原理使用直接使用M

Redis 内存淘汰策略深度解析(最新推荐)

《Redis内存淘汰策略深度解析(最新推荐)》本文详细探讨了Redis的内存淘汰策略、实现原理、适用场景及最佳实践,介绍了八种内存淘汰策略,包括noeviction、LRU、LFU、TTL、Rand... 目录一、 内存淘汰策略概述二、内存淘汰策略详解2.1 ​noeviction(不淘汰)​2.2 ​LR

Deepseek使用指南与提问优化策略方式

《Deepseek使用指南与提问优化策略方式》本文介绍了DeepSeek语义搜索引擎的核心功能、集成方法及优化提问策略,通过自然语言处理和机器学习提供精准搜索结果,适用于智能客服、知识库检索等领域... 目录序言1. DeepSeek 概述2. DeepSeek 的集成与使用2.1 DeepSeek API

Redis的数据过期策略和数据淘汰策略

《Redis的数据过期策略和数据淘汰策略》本文主要介绍了Redis的数据过期策略和数据淘汰策略,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一... 目录一、数据过期策略1、惰性删除2、定期删除二、数据淘汰策略1、数据淘汰策略概念2、8种数据淘汰策略

SpringBoot中的404错误:原因、影响及解决策略

《SpringBoot中的404错误:原因、影响及解决策略》本文详细介绍了SpringBoot中404错误的出现原因、影响以及处理策略,404错误常见于URL路径错误、控制器配置问题、静态资源配置错误... 目录Spring Boot中的404错误:原因、影响及处理策略404错误的出现原因1. URL路径错

Redis多种内存淘汰策略及配置技巧分享

《Redis多种内存淘汰策略及配置技巧分享》本文介绍了Redis内存满时的淘汰机制,包括内存淘汰机制的概念,Redis提供的8种淘汰策略(如noeviction、volatile-lru等)及其适用场... 目录前言一、什么是 Redis 的内存淘汰机制?二、Redis 内存淘汰策略1. pythonnoe