Giter Site home page Giter Site logo

cn_stock_holidays's Introduction

cn_stock_holidays

CI Status

数据文件 (File Path)

沪深市场

cn_stock_holidays/data.txt

香港市场

cn_stock_holidays/data_hk.txt

Fetch Data via URL :

wget https://raw.githubusercontent.com/rainx/cn_stock_holidays/main/cn_stock_holidays/data.txt

or

curl https://raw.githubusercontent.com/rainx/cn_stock_holidays/main/cn_stock_holidays/data.txt

文件内容 ( File Content)

保存除了周六日休市之外,其它休市信息,换行分割

store all (even upcoming) holiday for china stock exchange (without regular market close date on Saturday Day and Sun Day ) , one date per line

格式(File Format)

YYYYMMDD

Python version

pip install cn-stock-holidays

or

pip install git+https://github.com/rainx/cn_stock_holidays.git

导入

# 针对沪深
import cn_stock_holidays.data as shsz

# 针对香港
import cn_stock_holidays.data_hk as hkex

Functions

Help on module cn_stock_holidays.data in cn_stock_holidays:

NAME
    cn_stock_holidays.data - Help functions for python to get china stock exchange holidays

FILE
    /Users/rainx/dev/cn_stock_holidays/cn_stock_holidays/data.py

FUNCTIONS
    check_expired()
        check if local or cached data need update
        :return: true/false

    date_to_int(da)

    date_to_str(da)

    get_cache_path()

    get_cached()
        get from cache version , if it is not exising , use txt file in package data
        :return: a list contains all holiday data, element with datatime.date format

    get_local()
        read data from package data file
        :return: a list contains all holiday data, element with datatime.date format

    get_remote_and_cache()
        get newest data file from network and cache on local machine
        :return: a list contains all holiday data, element with datatime.date format

    int_to_date(d)

    str_to_int(s)

    sync_data()


    is_trading_day(dt)
        param dt: datetime.datetime or datetime.date.
        is a trading day or not
        :returns: Bool

    previous_trading_day(dt):
        param dt: datetime.datetime or datetime.date.
        get previous trading day
        :returns: datetime.date

    next_trading_day(dt):
        param dt: datetime.datetime or datetime.date.
        get next trading day
        :returns: datetime.date

    trading_days_between(start, end):

        param start, end: start and end time , datetime.datetime or datetime.date
        get calendar data range
        :returns: a generator for available dates for chinese market included start and end date

about function cache

from version 0.10 on, we used functools.lrucache on get_cached for getting more speech, if needed you can used the following syntax to clear cache.

get_cached.cache_clear()  

Keep it up-to-date

we had a script to check the expired of the data and fetch the data from web.

you could set it up on cron job

0 0 * * * /usr/local/bin/cn-stock-holiday-sync > /tmp/cn_stock_holiday_sync.log

You could get the absolute path of cn-stock-holiday-sync by which command

沪深

which cn-stock-holiday-sync

香港

which cn-stock-holiday-sync-hk

cn_stock_holidays's People

Contributors

jaysonalbert avatar rainx avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cn_stock_holidays's Issues

SHSZExchangeCalendar Error

zipline (1.1.1+258.gbd24e0de)
zipline-cn-databundle (0.5)

IndexError: index 246479 is out of bounds for axis 0 with size # 186582

您好,使用cn_stock_holidays过程中,zipline ingest bundle的时候,报错。 经查,发现是SHSZExchangeCalendar的问题。
@Property
def open_time(self):
return time(9, 30)
@Property
def close_time(self):
return time(15, 00)

将9:30 缩小。 将15:00放大后,186582 会相应变大,猜测是中间的时间差计算问题。不知道作者使用过程中是否遇到过此问题。

谢作者,提供这么好的开源项目。

Zipline AssertionError

您好,能否告知,一般如果出现这种错误,是数据源的问题还是日历的问题?
AssertionError: Got 382 rows for daily bars table with first day=2016-08-09, last day=2018-03-07, expected 383 rows.
Missing sessions: [Timestamp('2016-10-31 00:00:00+0000', tz='UTC'), Timestamp('2016-11-01 00:00:00+0000', tz='UTC')]
Extra sessions: [Timestamp('2017-02-02 00:00:00+0000', tz='UTC')]

pipeline data was delayed 1 trading day with this calendar

写一个最简单的使用pipeline的策略, 再使用一个最简单的返回收盘价的自定义因子,然后在策略中使用。
通过打印调试信息,并检查原始的行情数据,发现该股票SH600212 在2010.4.16处于停牌状态,但是策略中pipeline在2010.4.16仍有数据,而在2010-04-19才是NaN。
可能是使用该日历,pipeline的数据延迟了一个交易日。

原始行情数据:
20100415 6 6.01 5.81 5.86
20100419 5.79 5.82 5.51 5.52
Factor中打印的log:
today= 2010-04-16 00:00:00+00:00 ,out= [ ... 5.86 ...]
today= 2010-04-19 00:00:00+00:00 ,out= [ ... nan ...]
策略中打印的log:
2010-04-16 07:00:00+00:00,pipeline_data= MyFactor ... Equity(6 [SH600212]) 5.86 ...
2010-04-19 07:00:00+00:00,pipeline_data= MyFactor ... Equity(6 [SH600212]) NaN ...

zipline 1.3 error

from cn_stock_holidays.zipline.exchange_calendar_shsz import SHSZExchangeCalendar
../../.local/share/virtualenvs/stralib-Bozs3YP5/lib/python3.6/site-packages/cn_stock_holidays/zipline/init.py:1: in
from cn_stock_holidays.zipline.exchange_calendar_hkex import HKExchangeCalendar
../../.local/share/virtualenvs/stralib-Bozs3YP5/lib/python3.6/site-packages/cn_stock_holidays/zipline/exchange_calendar_hkex.py:9: in
from zipline.utils.calendars.trading_calendar import days_at_time, NANOS_IN_MINUTE
E ModuleNotFoundError: No module named 'zipline.utils.calendars.trading_calendar'; 'zipline.utils.calendars' is not a package

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.