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

相关文章

在JS中的设计模式的单例模式、策略模式、代理模式、原型模式浅讲

1. 单例模式(Singleton Pattern) 确保一个类只有一个实例,并提供一个全局访问点。 示例代码: class Singleton {constructor() {if (Singleton.instance) {return Singleton.instance;}Singleton.instance = this;this.data = [];}addData(value)

缓存策略使用总结

缓存是提高系统性能的最简单方法之一。相对而言,数据库(or NoSQL数据库)的速度比较慢,而速度却又是致胜的关键。 如果使用得当,缓存可以减少相应时间、减少数据库负载以及节省成本。本文罗列了几种缓存策略,选择正确的一种会有很大的不同。缓存策略取决于数据和数据访问模式。换句话说,数据是如何写和读的。例如: 系统是写多读少的吗?(例如基于时间的日志)数据是否是只写入一次并被读取多次?(例如用户配

Flink任务重启策略

概述 Flink支持不同的重启策略,以在故障发生时控制作业如何重启集群在启动时会伴随一个默认的重启策略,在没有定义具体重启策略时会使用该默认策略。如果在工作提交时指定了一个重启策略,该策略会覆盖集群的默认策略默认的重启策略可以通过 Flink 的配置文件 flink-conf.yaml 指定。配置参数 restart-strategy 定义了哪个策略被使用。常用的重启策略: 固定间隔 (Fixe

Java后端微服务架构下的API限流策略:Guava RateLimiter

Java后端微服务架构下的API限流策略:Guava RateLimiter 大家好,我是微赚淘客返利系统3.0的小编,是个冬天不穿秋裤,天冷也要风度的程序猿! 在微服务架构中,API限流是保护服务不受过度使用和拒绝服务攻击的重要手段。Guava RateLimiter是Google开源的Java库中的一个组件,提供了简单易用的限流功能。 API限流概述 API限流通过控制请求的速率来防止

未雨绸缪:环保专包二级资质续期工程师招聘时间策略

对于环保企业而言,在二级资质续期前启动工程师招聘的时间规划至关重要。考虑到招聘流程的复杂性、企业内部需求的变化以及政策标准的更新,建议环保企业在二级资质续期前至少提前6至12个月启动工程师招聘工作。这个时间规划可以细化为以下几个阶段: 一、前期准备阶段(提前6-12个月) 政策与标准研究: 深入研究国家和地方关于环保二级资质续期的最新政策、法规和标准,了解对工程师的具体要求。评估政策变化可

面对Redis数据量庞大时的应对策略

面对Redis数据量庞大时的应对策略,我们可以从多个维度出发,包括数据分片、内存优化、持久化策略、使用集群、硬件升级、数据淘汰策略、以及数据结构选择等。以下是对这些策略的详细探讨: 一、数据分片(Sharding) 当Redis数据量持续增长,单个实例的处理能力可能达到瓶颈。此时,可以通过数据分片将数据分散存储到多个Redis实例中,以实现水平扩展。分片的主要策略包括: 一致性哈希:使用一

集群环境下为雪花算法生成全局唯一机器ID策略

雪花算法是生成数据id非常好的一种方式,机器id是雪花算法不可分割的一部分。但是对于集群应用,让不同的机器自动产生不同的机器id传统做法就是针对每一个机器进行单独配置,但这样做不利于集群水平扩展,且操作过程非常复杂,所以每一个机器在集群环境下是一个头疼的问题。现在借助spring+redis,给出一种策略,支持随意水平扩展,肥肠好用。 大致策略分为4步: 1.对机器ip进行hash,对某一个(大于

数据库归档策略

数据库迁移策略 为备战双11,需要将数据库中的相关表(历史订单)进行归档,以便腾出更多的空间迎接订单的暴增。作者经过尝试,得出自认为最优的解决方案。下面给出数据库归档策略及示例代码。 现有条件: 1.现有两个数据库:db-A 以及 db-B; 2.两个库中有字段相同的表:tba(表中只有字段订单id–rx_id(long型) 有索引); 3.归档库的tba中还有17年整年的归档数据。 4.由于单

2024 年高教社杯全国大学生数学建模竞赛 C 题 农作物的种植策略 参考论文 无水印

持续更新中,2024年数学建模比赛思路代码论文都会发布到专栏内,只需订阅一次!  完整论文+代码+数据结果链接在文末!  订阅后可查看参考论文文件 第一问 1.1 问题重述 这个问题围绕的是华北山区的某乡村,在有限的耕地条件下,如何制定最优的农作物种植策略。乡村有 34 块露天耕地和 20 个大棚,种植条件包括粮食作物、蔬菜、水稻和食用菌。除了要考虑地块的面积、种植季节等,还要确保

【redis】数据量庞大时的应对策略

文章目录 为什么数据量多了主机会崩分布式系统应用数据分离架构应用服务集群架构负载均衡器数据库读写分离 引入缓存冷热分离架构 分库分表微服务是什么代价优势 为什么数据量多了主机会崩 一台主机的硬件资源是有上限的,包括但不限于一下几种: CPU内存硬盘网络… 服务器每次收到一个请求,都是需要消耗上述的一些资源的~~ 如果同一时刻处理的请求多了,此时就可能会导致某个硬件资源不够用了