请 [注册] 或 [登录]  | 返回主站

量化交易吧 /  量化平台 帖子:3365825 新帖:0

量化交易(JoinQuant数据)-日本蜡烛图算法-Python代码实现

技术性调整发表于:5 月 10 日 06:43回复(1)

memu https://www.joinquant.com/post/13955
'''
蜡烛图算法

parameter:以下参数均包含的有缺省值
security 聚宽格式股票代码,只支持['']单只股票格式
start_date 起始时间点
end_date 结束时间点

Note:
1.日本蜡烛图是最基础的数据整合形式,主要是包括了[开盘价/收盘价/日内最高/日内最低]
2.下面代码使用JoinQuant数据源做出蜡烛图算法的实现
3.图一蜡烛图,图二量比

author:aaron-clark-aic 20/07/2018
'''

 .股票跌成狗,代码慌得一批~
 .有问题可以留言,回不回复看心(大)情(盘)

Untitled.png

import talib
import datetime
import jqdata
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.finance as mpf
'''
默认股票代码格式(000915)转换为聚宽代码格式(000915.XSHG)
author:aaron-clark-aic 18/07/2018
'''
def standardStocks(stocks):
    _stocks = list(get_all_securities('stock').index)
    _standardStocks = []
    for i in stocks:
        _standardStocks =_standardStocks+[code for code in _stocks if code.upper().startswith(i)]
    return _standardStocks
'''
蜡烛图算法


parameter:以下参数均包含的有缺省值
    security 聚宽格式股票代码,只支持['']单只股票格式
    start_date 起始时间点
    end_date 结束时间点

Note:
    1.日本蜡烛图是最基础的数据整合形式,主要是包括了[开盘价/收盘价/日内最高/日内最低]
    2.下面代码使用JoinQuant数据源做出蜡烛图算法的实现
    3.图一蜡烛图,图二量比
    4. .股票跌成狗,代码慌得一批~
       .有问题可以留言,回不回复看大盘(心情)
    
author:aaron-clark-aic 20/07/2018
'''
def candlestick(security=standardStocks(['000915']),start_date=(datetime.date.today()-datetime.timedelta(days=120)),end_date=datetime.date.today()):
    data  = get_price(security,start_date=start_date,end_date=end_date,fields=['open','close','high','low','volume'])
    _base_days = jqdata.get_trade_days(start_date=start_date, end_date=end_date)#基础交易日list
    _open = np.hstack(data['open'].values)
    _close = np.hstack(data['close'].values)
    _high = np.hstack(data['high'].values)
    _low = np.hstack(data['low'].values)
    _volume = np.hstack(data['volume'].values)
    
    fig = plt.figure(figsize=(17, 10))
    ax_1 = fig.add_axes([0,0.2,1,0.5])
    ax_2 = fig.add_axes([0,0,1,0.2])

    mpf.candlestick2_ochl(ax = ax_1, opens = _open, closes = _close ,highs = _high, lows = _low ,width=0.5, colorup='r', colordown='g', alpha=0.81)
    ax_1.set_xticks(range(0, len(_base_days), 1))
    ax_1.grid(False)

    mpf.volume_overlay(ax = ax_2,opens = _open, closes = _close, volumes = _volume, colorup='r', colordown='g', width=0.5, alpha=0.81)
    ax_2.set_xticks(range(0, len(_base_days), 1))
    ax_2.set_xticklabels(_base_days, rotation=90)
    ax_2.grid(True)

    plt.show()
    
candlestick()

全部回复

0/140

量化课程

    移动端课程