RiceQuant和 JoinQuant合成月k线、周k线的极简公式

这篇博客介绍了如何在米筐(RiceQuant)和聚宽(JoinQuant)平台上通过编写简洁的函数来获取日、周、月k线数据,弥补了这两个平台直接获取周期k线数据的不足。
摘要由CSDN通过智能技术生成

米筐和聚宽没有直接可以获取月k线,周k线的函数,为此写了一个极简函数可以获取日k线,周k线,月k线,乃至分钟k线。如下:

聚宽:

def get_period_price_wjlec(stock, rule='W', start_date=None, end_date=None, frequency='daily', fields=None, \
                           skip_paused=True, fq='pre', count=None):
    '''
            极简方法获取真实的日线、周线、月线或其他周期数据,本函数考虑了假期情况,不会列出不交易的日期。
    参数:
        stock : 证券代码
        rule : K线类别,默认是周线'W',月线是'M',季度线是'Q',年线是'A'。期间代码也可以使用周K('W-FRI')、月K('BM')、
        年K('A-DEC')
        end_date : 默认None, 对应使用attribute_history; 否则使用get_price
        其他参数:同get_price
    返回:
        dataframe: index:时间序列 
    范例:
        df=get_period_price_wjlec('601668.XSHG', start_date='2017-1-1', end_date='2017-5-31')#获取周线
        df=get_period_price_wjlec('601668.XSHG', rule='W', count=120, end_date='2017-6-1')#获取周线
        df=get_period_price_wjlec('601668.XSHG', rule='M', start_date='2017-1-1', end_date='2017-5-31')#获取月线
        df=get_period_price_wjlec('601668.XSHG', rule='M', count=1000, end_date='2017-5-31')#获取月线
    '''
    #设定转换周期period_type  转换为周是'W',月'M',季度线'Q',五分钟'5min',12天'12D'
    period_type = rule
    if "attribute_history" not in dir() or end_date:
        stock_data = get_price(stock, start_date=start_date, end_date=end_date, frequency=frequency, fields=\
                       ['open','high','low'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值