Skip to main content

Data engine for stockA quant

Project description

one-quant-data

one_quant_data是A股量化数据引擎,用于为量化工具提供数据支撑

目前,本库的数据来源是基于tushare.pro接口,可以认为是tushare的数据接口封装

由于tushare的数据访问有一定的频率限制,为避免tushare的访问限制,将数据缓存到自己的数据库中 同时,由于数据在指定数据库中,因此又可以提供一些新的使用数据的角度

安装方法

    $ pip install one_quant_data 

使用方法

  1. 先建立配置文件config.json
{
    "data_engine":{
        "api":{
            "name":"tushare_pro",
            "token":"your_tusharepro_token"
        },
        "cache":{
            "db":"mysql",
            "host":"yourdbhost",
            "port":3306,
            "user":"yourusername",
            "password":"yourpasswd",
            "schema":"yourdbname"
            "start_date":"20190101"  #需要缓存数据的起始日期
        }
    }
}

说明:

  • api的name可选tushare_pro或者offline,offline表示只使用数据库里的数据
  1. 引用数据包
    from one_quant_data import DataEngine
  1. 初始化类DataEngine
    engine = DataEngine('../config.json')
  1. 同步数据,可以启动定时任务进行调用,第一次运行会建立数据库并缓存从起始日期到今天的所有数据,以后再调用时只会增量添加数据。同步数据时必须使用tushare_pro接口 同步数据的接口有两个: sync_data_iterate_date是按日期同步,适合每天运行同步交易数据 sync_data_iterate_stock是按股票同步,用于更新不频繁的数据,可以隔一段时间再调用一次
    engine.sync_data_iterate_date()
  1. 使用数据,使用接口与tushare.pro保持一致,区别在于只会返回缓存的数据
    df = engine.stock_basic()
    df = engine.pro_bar('000651.SZ',adj='qfq')
    df = engine.daily_basic(trade_date='20190926')
    df = engine.daily_basic('000651.SZ')
    df = engine.index_dailybasic(trade_date='20190926')
    df = engine.index_dailybasic('000001.SH')
    df = engine.index_daily('000001.SH')
    df = engine.fina_mainbz(ts_code='000627.SZ', type='P')
    df = engine.fina_mainbz_vip(period='20190630', type='P')
  1. 需要使用tushare接口时,使用DataEngine的pro字段来访问tushare
    pro = engine.pro
    df = pro.query()
  1. 自定义的接口

    接口 功能 输入参数 输出格式 说明
    index_codes 返回缓存的指数代码 list
    cached_range 返回缓存的数据的开始,结束时间 (cached_start,cached_end) 输出格式为tuple
    attach_stock_name 根据一个dataframe的ts_code,添加股票名称 df 带name列的dataframe 必须有ts_code字段
    get_cached_trade_dates 获得所有缓存的数据日期 list

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

one_quant_data-0.1.9.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

one_quant_data-0.1.9-py3.7.egg (19.3 kB view details)

Uploaded Egg

File details

Details for the file one_quant_data-0.1.9.tar.gz.

File metadata

  • Download URL: one_quant_data-0.1.9.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for one_quant_data-0.1.9.tar.gz
Algorithm Hash digest
SHA256 2ee735344b99fbdcdd8a958b2f78d4d149399349af384096977f1658b629689b
MD5 0adcfede262d6948ae2cf57b41a1662e
BLAKE2b-256 cc3002a7da4df9198f434247492c64c706a41c6ae39bc34824c6f98f12d2f191

See more details on using hashes here.

File details

Details for the file one_quant_data-0.1.9-py3.7.egg.

File metadata

  • Download URL: one_quant_data-0.1.9-py3.7.egg
  • Upload date:
  • Size: 19.3 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.4.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for one_quant_data-0.1.9-py3.7.egg
Algorithm Hash digest
SHA256 0b66194c78b079485c392c5b6a967327c4631bca6dbfe65f38590bed7055e117
MD5 7c37e735455155564ddf5d7170706bcd
BLAKE2b-256 be03f9afecdde7c06d914b74aa59253efeb3ceeed2d7657acc6018c3cfdfe3aa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page