【策略】Dual Thrust 交易策略策略介绍Dual Thrust是一个趋势跟踪系统,由Michael Chalek在20世纪80年代开发,曾被Future Thruth杂志评为最赚钱的策略之一。Dual Thrust系统具有简单易用、适用度广的特点,其思路简单、参数很少,配合不同的参数、止盈止损和仓位管理,可以为投资者带来长期稳定的收益,被投资者广泛应用于股票、货币、贵金属、债券、能源及股指期货市场等。 当然由于A股没有做空机制,所以,效果肯定受影响。 ![](http://image109.360doc.com/DownloadImg/2023/10/1215/273692321_1_20231012033807601_wm.jpeg)
本策略的核心思路1.当股票突破上界(Buyline),则认为该股票今天有较大行情,买入该股票。 2.当股价两天内下跌6%,或者三天内下跌8%则卖出股票。 3.根据大盘止损,如果大盘下跌超过3%则空仓。 from aiquant.engine.strategy import Strategy import pandas as pd
class DualThrust(Strategy): def __init__(self,context): Strategy.__init__(self,context)
self.bars = context['bars'] self.events = context['events'] self.porfolio = context['portfolio']
def check_sell_signal(self,df): hist = df['close'] case1 = (1 - hist[2] / hist[0]) >= 0.06 case2 = hist[1] / hist[0] <= 0.92 if case1 or case2: self.order_target_percent(s, 0)
def check_buy_signal(self,df):
high = df['high'] close = df['close'] low = df['low'] open = df['open']
HH = max(high[:2]) LC = min(close[:2]) HC = max(close[:2]) LL = min(low[:2]) open_price = open[2] current_price = close[2]
Range = max((HH - LC), (HC - LL)) K1 = 0.9 BuyLine = open_price + K1 * Range # print(BuyLine,'buyline') if current_price > BuyLine: return True
return False
def onbar(self): ''' A股只有LONG,EXIT,就是买入或平仓。 作为一个策略模板: 1,看账户里还有多少钱。 2,一次要交易多少支股票。 3,分配资金:这里先平均分配。 4,计算交易信号。 5,产生交易行为。 '''
#简化起见,这里只交易000001,平安银行
cash = self.get_available_cash() universe = self.get_universe()
# 分配资金,这里平均分配 cash_per_symbol = cash / len(universe)
for s in universe: latest_bars = self.bars.get_latest_bars(s, N=3) # 取最近三天的bars df = pd.DataFrame(latest_bars)
b_holded = self.check_is_holding(s) if b_holded: b_sell = self.check_sell_signal(df) if b_sell: pass else: # 买入cash_per_symbol b_buy = self.check_buy_signal(df) if b_buy: self.order_value(s, cash_per_symbol)
关于作者:魏佳斌,互联网产品/技术总监,北京大学光华管理学院(MBA),特许金融分析师(CFA),资深产品经理/码农。偏爱python,深度关注互联网趋势,人工智能,AI金融量化。致力于使用最前沿的认知技术去理解这个复杂的世界。
|