Note

价格动量分析策略

· Views 1,538

动量效应是由Jegadeesh和Titman(1993)提出的,是指股票的收益率有延续原来的运动方向的趋势,即过去一段时间收益率较高的股票在未来获得的收益率仍会高于过去收益率较低的股票。

 

价格动量的计算公式

AR = [N天所有(High-Open)的和/ N天所有(Open—Low)的和] * 100

这其中:

  • N: 日时间周期的统计窗口,默认一般为7天
  • High: 单日的最高价
  • Open: 单日的开盘价
  • Low: 单日的最低价
  • 我们假设这个值为100左右,超过100,则多头力量开始增加,小于100,则空头力量开始聚集。
  • AR值升高时表示行情活跃,人气旺盛,多头一路高歌猛进,但是过高则表示价格进入超买区域,应选择时机平仓。AR值的高度没有具体标准,一般情况下,AR值上升至150左右时,价格很有可能会回调下挫。
  • AR值下降时表示行情衰退,空头气势正盛,需要多头努力,过低则暗示价格可能已经跌入超卖区域,可考虑伺机做多或平仓。一般AR值跌至50以下时,价格随时止跌反涨。

 

#!/usr/bin/env python
#  -*- coding: utf-8 -*-
__author__ = "Ringo"
from tqsdk import TqAccount, TqApi,TargetPosTask,TqBacktest,TqSim
from datetime import date
# 设置指定合约,获取N条K线计算价格动量
SYMBOL ="SHFE.au2012"
N = 15
api = TqApi(TqSim(init_balance=1000000),web_gui=True,backtest=TqBacktest(start_dt=date(2020, 1, 1), end_dt=date(2020, 7, 15)))
klines = api.get_kline_serial(SYMBOL,60*60*24,N)
quote = api.get_quote(SYMBOL)
target_pos = TargetPosTask(api, SYMBOL)
position = api.get_position(SYMBOL)
# 编写价格动量函数AR,以前N-1日K线计算价格动量ar
def AR(kline1):
    spread_ho = sum(kline1.high[:-1] - kline1.open[:-1]) 
    spread_oc = sum(kline1.open[:-1] - kline1.low[:-1])
    # spread_oc 为0时,设置为最小价格跳动值
    if spread_oc == 0:
        spread_oc = quote.price_tick
    ar = (spread_ho/spread_oc)*100
    return ar
ar = AR(klines)
print("策略开始启动")
while True:
    api.wait_update()
    # 生成新K线时,重新计算价格动量值ar
    if api.is_changing(klines.iloc[-1],"datetime"):
        ar = AR(klines)
        print("价格动量是:", ar)
    # 每次最新价发生变动时,重新进行判断
    if api.is_changing(quote,"last_price"):
        # 开仓策略
        if position.pos_long == 0 and position.pos_short == 0:
            # 如果ar大于110并且小于150,开多仓
            if 110 < ar < 150:
                print("价值动量超过110,小于150,做多")
                target_pos.set_target_volume(10) 
            # 如果ar大于50,小于90,开空仓   
            elif  50 < ar < 90:
                print("价值动量大于50,小于90,做空")
                target_pos.set_target_volume(-10) 
        # 止损策略,多头下当前ar值小于90则平仓止损,空头下当前ar值大于110则平仓止损
        elif (position.pos_long > 0 and ar < 90) or (position.pos_short > 0 and ar > 110):
            print("止损平仓")
            target_pos.set_target_volume(0)
价格动量分析策略
回测收益情况
价格动量分析策略
回撤指标

评价:虽然回测了今年的收益是正的,但是回测和上涨过于不稳定,在很多情况下行情趋向于横盘整理,总体不算非常满意。

Disclaimer: The content above represents only the views of the author or guest. It does not represent any views or positions of FOLLOWME and does not mean that FOLLOWME agrees with its statement or description, nor does it constitute any investment advice. For all actions taken by visitors based on information provided by the FOLLOWME community, the community does not assume any form of liability unless otherwise expressly promised in writing.

FOLLOWME Trading Community Website: https://www.followme.com

If you like, reward to support.
avatar

Hot

No comment on record. Start new comment.