本文共 1881 字,大约阅读时间需要 6 分钟。
菲阿里四价策略
菲阿里四价策略是一种比较简单的趋势型日内交易策略。昨天高点、昨天低点、昨日收盘价、今天开盘价,可并称为菲阿里四价。它由日本期货冠军菲阿里实盘采用的主要突破交易参照系。菲阿里四价是日内突破策略,所以每日收盘之前都需要进行平仓。该策略的上下轨以及用法如下所示:
上轨=昨日高点;
下轨=昨日低点;
当价格突破上轨,买入开仓;
当价格跌穿下轨,卖出开仓。
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 StandardScalerdef init(context): context.feature_id = "IH88" subscribe(context.feature_id) context.per_qty = 10def before_trading(context): passdef handle_bar(context, bar_dict): if context.now.strftime('%H:%M') < '14:59': yest_high = history_bars(context.feature_id, 1, '1d', 'high')[-1] yest_low = history_bars(context.feature_id, 1, '1d', 'low')[-1] last_open = history_bars(context.feature_id, 1, '1m', 'open') last_close = history_bars(context.feature_id, 1, '1m', 'close') if last_open <= yest_high < last_close: buy_open(context.feature_id, context.per_qty) elif last_open >= yest_low > last_close: sell_open(context.feature_id, context.per_qty) else: buy_qty = context.portfolio.positions[context.feature_id].buy_quantity sell_qty = context.portfolio.positions[context.feature_id].sell_quantity if buy_qty > 0: sell_close(context.feature_id, buy_qty) if sell_qty > 0: buy_close(context.feature_id, sell_qty)
看起来还是不错的,原始裸策略,未做任何优化的,跑出这样的成绩还是意外的.
参考:
转载地址:http://bhyws.baihongyu.com/