zoukankan      html  css  js  c++  java
  • 数据分析--布林带策略(择时)

    布林带策略:原理是估计出一段时间(例如30日)的股价范围,超过上限会回落,低于下限会上涨。

    布林带/布林线/保利加通道(Bollinger Band):

      由三条轨道线组成,其中上下两条线分别可以看成是价格的压力线和支撑线,在两条线之间是一条价格平均线

      K线超过压力线,开始跌,跌破了支撑线,开始涨

    计算公式:

      中间线 = 20日均线

      up线 = 20日均线 + N*SD  (SD为20日收盘价标准差,N为可调参数)

      down线 = 20日均线 - N*SD   (SD为20日收盘价标准差,N为可调参数)

    布林带策略:择时

      当股价突破阻力线时,清仓

      当股价跌破支撑线时,全仓买入

    布林带策略研究:N的取值问题,布林带宽度等

    from jqdata import *
    
    def initialize(context):
        set_benchmark('000300.XSHG')
        set_option('use_real_price', True)
        set_order_cost(OrderCost(close_tax=0.001, open_commission=0.0003, close_commission=0.0003, min_commission=5), type='stock')
        
        g.security = '600036.XSHG'
        
        g.M = 20 # 20日均线
        g.k = 2 # 指数N
    
    def handle_data(context, data):
        sr = attribute_history(g.security, g.M)['close']
        ma = sr.mean()  #20日均线
        up = ma + g.k*sr.std()  #上限
        down = ma - g.k*sr.std()  #下限
        
        print(ma)
        
        p = get_current_data()[g.security].day_open  #开盘价
        cash = context.portfolio.available_cash
        if p < down and g.security not in context.portfolio.positions:
            order_value(g.security, cash) # 跌破,买入
        elif p > up and g.security in context.portfolio.positions:
            order_target(g.security, 0)  # 升破,卖出
    布林线策略

  • 相关阅读:
    Yield Usage Understanding
    Deadclock on calling async methond
    How to generate file name according to datetime in bat command
    Run Unit API Testing Which Was Distributed To Multiple Test Agents
    druid的关键参数+数据库连接池运行原理
    修改idea打开新窗口的默认配置
    spring boot -thymeleaf-url
    @pathvariable和@RequestParam的区别
    spring boot -thymeleaf-域对象操作
    spring boot -thymeleaf-遍历list和map
  • 原文地址:https://www.cnblogs.com/staff/p/10962507.html
Copyright © 2011-2022 走看看