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如何通过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

Python 中 requests 与 aiohttp 在实际项目中的选择策略详解

《Python中requests与aiohttp在实际项目中的选择策略详解》本文主要介绍了Python爬虫开发中常用的两个库requests和aiohttp的使用方法及其区别,通过实际项目案... 目录一、requests 库二、aiohttp 库三、requests 和 aiohttp 的比较四、requ

Redis过期键删除策略解读

《Redis过期键删除策略解读》Redis通过惰性删除策略和定期删除策略来管理过期键,惰性删除策略在键被访问时检查是否过期并删除,节省CPU开销但可能导致过期键滞留,定期删除策略定期扫描并删除过期键,... 目录1.Redis使用两种不同的策略来删除过期键,分别是惰性删除策略和定期删除策略1.1惰性删除策略

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

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

缓存策略使用总结

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