Cr量化交易:

 

所谓cr指标指的就是能量指标,又叫中间意愿指标,它和arbr指标又很多相似之处,如计算公式和研判法则等,又有自己独特的研判功能,是分析多空双方力量对比、把握买卖股/票时机的一种中长期技术分析工具。仿cr量化交易系统app开发,仿cr量化交易平台搭建,合/肥艾数大数/据仿cr量化交易软件开发,仿cr量化系统源码搭建。

 

所谓量化交易,是指以先进的数学模型替代人为的主观判断,利用计算机技术从庞大的历史数据中海选能带来超额收益的多种大概率事件以制定策略,减少投资者情绪波动的影响,避免在市场极度狂热或悲观的情况下作出非理性的投资决策。量化交易策略中包含了鳄鱼法则交易系统。

 

何为鳄鱼法则交易系统:

 

鳄鱼法则交易系统结合了控制论、信息理论、分形几何学和全息理论等理论。鳄鱼组线都能让用户保持适当的交易方向。

 

 1.鳄鱼线

 

鳄鱼线是运用分形几何学和非线性动力学的一组平均线,相当于交易中的方向盘角色,并且结合了非线性动力学和不规则碎形几何学的平均线。主要分为蓝、红、绿三条,蓝色被称为鳄鱼的鄂部,红色被称为鳄鱼的牙齿,绿色被称为鳄鱼的唇吻。它们的构造方法如下;

 

鄂部—13根价格线的平滑移动均线,并将数值向未来方向移动8根价格线;

牙齿—8根价格线的平滑移动平均线,并将数值向未来方向移动5根价格线;

唇吻—5根价格线的平滑移动平均线,并将数值向未来方向移动3根价格线;

 

 

2.鳄鱼线公式

 

    Var1:=(H+L)/2;

 

上唇:  REF(SMA(Var1,5,1),3),

牙齿:  REF(SMA(Var1,8,1),5),

下颚:  REF(SMA(Var1,13,1),8),

 

碎形:

 

碎形原理:是利用简单的多空原理而形成。市场上涨时,买方追高价的意愿很高,价格就会不断上升,买方意愿将随价格的不断上升而逐渐减少,价格最终回跌。交易者意愿被市场新入的信息(混沌)所影响,此时市场处于低价值区,虽然目前的价值区买卖双方都同意,但对于价格有着不同看法,当买方意愿再度大于卖方意愿时价格就会上涨;

量化策略分析/cr量化交易-LMLPHP 

 

(碎形结构图示)

 

(1)最典型的碎形结构如图中A型态。由连续5根的线条所组成,中间的高点一定最高(向下碎形则中间低点一定最低),中间线的左边有两根较低的高点,右边也有两根较低的高点(向下碎形则为左右各有两根较高的低点),你现在看自己的五根手指结构,就是典型的向上碎形。 分辨向上碎形时,我们只在乎高点的位置,向下碎形时,则只在乎低点的位置。

(2)B向上与向下碎形共享外围bar

(3)C向上、向下碎形由一根bar完成

(4)D如今天高点与之前高点相同,今天的bar不算在5bar之内。

 

3. 鳄鱼线的作用:

 

1)把握快速上涨行情,判断当前行情是否可操作;

2)确定止损位置;

3)提供安全的买卖点;

 

 

鳄鱼法则交易系统源码分析,大致内容如下:

 

import numpy as np

def initialize(context):

    g.up_price = 0 #向上碎形最高价

    g.low_price = 0 #向下碎形最低价

    g.up_fractal_exists = False #判断有效向上碎形

    g.down_fractal_exists = False #判断有效向下碎形

    g.AO_index = [0] #存放连续的AO指标数据

    g.cal_AC_index = [] #计算AC指标中转存储

    g.AC_index = [0] #存放连续的AC指标数据

    g.amount = 0 #满仓仓位

    g.stock = ['160119.XSHE']

   set_benchmark('160119.XSHE')

 

#判断 向上 或 向下 碎形

def is_fractal(stock,direction):

    hist = history(5,'1d',direction,[stock],df = False)

    if direction == 'high'\

    and hist[stock][2] > hist[stock][0]\

    and hist[stock][2] > hist[stock][1]\

    and hist[stock][2] > hist[stock][3]\

    and hist[stock][2] > hist[stock][4]:

       g.up_price = hist[stock][2]

       return True

    elif direction == 'low'\

    and hist[stock][2] < hist[stock][0]\

    and hist[stock][2] < hist[stock][1]\

    and hist[stock][2] < hist[stock][3]\

    and hist[stock][2] < hist[stock][4]:

       g.low_price = hist[stock][2]

       return True

    return False

 

#通过比较碎形与红线位置,判断碎形是否有效

def is_effective_fractal(stock, direction):

    if is_fractal(stock,direction):

       hist = history(13,'1d','close',[stock],df = False)

       red_line = hist[stock][:-5].mean()

       close_price = hist[stock][-1]

       if direction == 'high':

           if close_price > red_line:

              g.up_fractal_exists = True

          else:

              g.up_fractal_exists = False

       elif direction == 'low':

           if close_price < red_line:

              g.down_fractal_exists = True

          else:

              g.down_fractal_exists = False

 

#N日内最高价格的N日线

def nday_high_point(stock,n):

    hist = history(2*n,'1d','high',[stock],df = False)[stock]

    high_point = []

    for i in range(n):

       high_point.append(max(hist[-5-i:-1-i]))

    return np.array(high_point).mean()

 

#N日内最低价格的N日线

def nday_low_point(stock,n):

    hist = history(2*n,'1d','low',[stock],df = False)[stock]

    low_point = []

    for i in range(n):

       low_point.append(max(hist[-5-i:-1-i]))

    return np.array(low_point).mean()

 

#AO=5日内(最高-最低)/25日移动平均-34日内(最高-最低)/234日移动平均

def AO_index(stock):

   g.AO_index.append(nday_high_point(stock,5)/2 + nday_low_point(stock,5)/2\

                   - nday_high_point(stock,34)/2 - nday_low_point(stock,34)/2)

    return g.AO_index[-1]

 

#AO-AO5日平均值的5日平均

def AC_index(stock):

    AO_index(stock)

    if len(g.AO_index) >= 5:

       g.cal_AC_index.append(g.AO_index[-1] - np.array(g.AO_index[-5:]).mean())

       if len(g.cal_AC_index) >=5:

          g.AC_index.append(np.array(g.cal_AC_index[-5:]).mean())

 

#判断序列n日上行

def is_up_going(alist,n):

    if len(alist) < n:

       return False

    for i in range(n-1):

       if alist[-(1+i)] <= alist[-(2+i)]:

           return False

    return True

 

#判断序列n日下行

def is_down_going(alist,n):

    if len(alist) < n:

       return False

    for i in range(n-1):

       if alist[-(1+i)] >= alist[-(2+i)]:

           return False

    return True

 

#碎形被突破

def active_fractal(stock,direction):

    close_price = history(1,'1d','close',[stock],df=False)[stock][0]

    if direction == 'up' and close_price > g.up_price:

       return True

    elif direction == 'down' and close_price < g.low_price:

       return True

 

#进场,初始仓位50%

def set_initial_position(stock,context):

    close_price = history(1,'1d','close',[stock],df=False)[stock][0]

    g.amount = context.portfolio.cash/close_price

    order(stock, g.amount*0.8)

    log.info("buying %s 股数为 %s"%(stock,g.amount*0.7))

    g.down_fractal_exists = False

 

#卖出

def sell_all_stock(stock,context):

   order_target(stock,0)

    log.info("selling %s"%stock)

    g.up_fractal_exists = False

 

#加仓

def adjust_position(stock,context,position):

   order(stock,g.amount*position)

    log.info("adjust position buying %s 股数为 %s"%(stock,g.amount*position))

 

def handle_data(context,data):

    stock = g.stock[0]

    #计算AOAC指标

    AC_index(stock)

    #止损

    #空仓时,寻找机会入场

    if context.portfolio.positions[stock].amount == 0:

       #计算向上碎形

       is_effective_fractal(stock,'high')

       #有效向上碎形存在,并被突破,买入

       if g.up_fractal_exists and active_fractal(stock,'up'):

          set_initial_position(stock,context)

    #有持仓时,加仓或离场

    else:

       close_price = history(13,'1d','close',[stock],df=False)

       red_line = close_price[stock][:-5].mean()

       #计算向下碎形

       is_effective_fractal(stock,'low')

       #出场条件1:有效向下碎形存在,并被突破,卖出

       if g.down_fractal_exists and active_fractal(stock,'down'):

          sell_all_stock(stock,context)

          return

       #出场条件2AC

       #加仓10%AOAC同时5日上行,且收盘价走高

       if is_up_going(g.AO_index,5)\

       and is_up_going(g.AC_index,3)\

       and is_up_going(close_price[stock],2):

          adjust_position(stock,context,0.1)

       #减仓10%AOAC同时3日下行,且收盘价走低

       if is_down_going(g.AO_index,5)\

       and is_down_going(g.AC_index,3)\

       and is_down_going(close_price[stock],2):

          adjust_position(stock,context,-0.1)

    record(AOindex = g.AO_index[-1])

record(ACindex = g.AC_index[-1])

 

鳄鱼法则交易系统,感兴趣的可以了解一下,仅供参考;cr量化交易系统软件开发技术,量化交易策略分析。

11-17 16:08