Skip to content
プロジェクト

chenditc/investment_data

GitHubで見る

概要

https://www.dolthub.com/repositories/chenditc/investment_data 用のスクリプトとドキュメント

その他のプロジェクト

この数値の測り方

計測したスター増加

24時間
+1
7日間
+8
15日間
+17
1か月
+33

期間ごとの純増数です。期間は重複しており、日別の値ではありません。未計測の値は空欄です。スター数は注目度の指標であり、品質の保証ではありません。

中文 README: ch

Chinese blog about this project: 量化系列2 - 众包数据集

Table of contents generated with markdown-toc

Special thanks

To: dmnsn7 Who provided tushare token and make daily update possible.

Sponsor

To continue maintain the CI/CD pipeline for this project, we need VPS with 30G+ memory, 4 core+ CPU and good connection to dolthub and github.

If you are willing to sponsor the running environment, please contact me directly.

If you are willing to sponsor the VPS fee, you can donate in this page: https://mp.weixin.qq.com/s/Athd5hsiN_hIKKgxIiO_ow

Thanks for everyone's help.

How to use it

  1. Download the canonical archive and its provenance manifest from the same GitHub release.
  2. Validate the completed archive bytes and date-bearing members.
  3. Extract the canonical archive to the default qlib directory.
wget "https://github.com/chenditc/investment_data/releases/download/<release-tag>/qlib_bin.tar.gz"
wget "https://github.com/chenditc/investment_data/releases/download/<release-tag>/qlib_bin.manifest.json"
python3 qlib/validate_archive.py \
  --archive qlib_bin.tar.gz \
  --manifest qlib_bin.manifest.json \
  --expected-tag "<release-tag>" \
  --require-publishable
tar -zxvf qlib_bin.tar.gz -C ~/.qlib/qlib_data/cn_data --strip-components=1

Optional community tool: qlib-sync automates downloading and updating this dataset. It is maintained independently of investment_data.

Index instruments files contain symbol, inclusive start date, and inclusive end date. Continuous membership is stored as one interval; a symbol can have multiple rows if it leaves the index and later returns. Historical members remain in the file even when they are absent from the latest index snapshot.

Developement Setup

If you want to contribute to the set of scripts or the data, here is what you should do to set up a dev environment.

Install dolt

Follow https://github.com/dolthub/dolt

Clone data

Raw data hosted on dolt: https://www.dolthub.com/repositories/chenditc/investment_data

To download as dolt database:

dolt clone chenditc/investment_data

Export to qlib format

docker run \
  -v /<some output directory>:/output \
  -it --rm chenditc/investment_data bash dump_qlib_bin.sh

To build a validated package after a source-data repair without replacing an existing dated release, dispatch upload_release.yml on main with operation=build. The workflow uses the verified immutable image and publisher preflight, selects the current Dolt snapshot, and uploads both canonical files as a qlib-source-repair-<run-id> Actions artifact. Its manifest records the image digest and source commits. The artifact is retained for 14 days; normal scheduled publication continues to create dated releases.

The standalone diagnostic grammar is bash dump_qlib_bin.sh [WORKING_DIR [QLIB_REPOSITORY]]. It always creates and validates qlib_bin.tar.gz together with qlib_bin.manifest.json. A standalone manifest has image_digest:null, so it is suitable for local inspection but cannot be published as a release asset.

You can use the following parameter to mount an existing dolt chenditc/investment_data folder to the container.

  -v /<dolt directory>:/dolt 

Run Daily Update

You will need tushare token to use tushare api. Get tushare token from https://tushare.pro/

export TUSHARE=<Token>
bash daily_update.sh

The stock collector uses Asia/Shanghai dates and waits until 17:00 before collecting the current trading day's closing prices. Failed requests, missing expected trading days, and incomplete price/adjustment-factor pairs stop the update before it can commit or advance past a missing day.

Daily update and output

Provider factor-base conversions are stored in Dolt's ts_provider_factor_scale with their reference dates and captured factor values. Collection aligns both anchor checks and new adjusted closes to the registered canonical basis; the existing restatement tolerance remains unchanged. Existing securities without a registered scale must pass a separate historical anchor check before import. For the audited 2026-11-23 incident, manually dispatch data_update.yml on main with operation=install-provider-scale-2026-11-23. The pinned installer checks its source commit and reference values, records the plan in Dolt, and corrects one unpublished raw adjustment cell without changing canonical prices. It refuses a changed source base and supports verified repeated execution.

For the unpublished 2026-11-24 rows written by an older external collector, operation=repair-provider-rows-2026-11-24 applies the pinned, reviewed conversion plan to that day's adjustment cells only. Run the normal collector after the repair and before publishing. Historical prices and raw OHLC/volume/amount are preserved. Other Dolt writers must upgrade to the current collector and apply the registered factor basis; an older cached image can reintroduce this error.

After successful collection, ts_collection_verification records Dolt hashes of the price, link, index-weight and factor-metadata tables. Publication of data from 2026-11-24 onward requires these exact hashes to match before export. An external write invalidates verification until the normal collector checks the updated snapshot successfully. Earlier snapshots retain their legacy path.

The normal main collector can reconcile legacy-basis stock appends after the latest published trade date. It verifies the formal release manifest digest, requires that source commit to be an available ancestor, and rejects changes to published price history, existing link ratios, factor metadata or financial schemas. Only complete, provider-matching unpublished days can be converted, with at most three days per run. Both provider-identity and already-aligned values are recognized; unknown factor changes stop the update. The original restatement tolerance is unchanged. Plans and provider-input digests are stored in Dolt's ts_provider_reconciliation, which is included in source verification when present. Source pushes still reject a concurrent remote update.

Automatic reconciliation writes require the verified main workflow/image. Cold clones retain 32 commits so the published reference is normally available; an unavailable or divergent reference stops reconciliation. The external writer should still upgrade its own image/code (tracked in #173).

docker run -v /<some output directory>:/output -it --rm chenditc/investment_data \
  bash -lc 'bash daily_update.sh && bash dump_qlib_bin.sh'

Upload to GitHub release

Release publication is authorized only by the digest-pinned workflow on main. Dispatch the normal publisher with:

gh workflow run upload_release.yml --repo chenditc/investment_data --ref main -f operation=publish

If a day's publication was missed and collection finishes after midnight, dispatch operation=publish-previous-day after the collector succeeds. This manual-only operation derives yesterday's calendar date in Asia/Shanghai and uses the same publisher, immutable source selection, archive validation and remote download checks as normal publication. The source must exactly reach the trading day for that date and contain more than 1,000 price rows; an older, newer or index-only snapshot is rejected before any release is created. It accepts no custom date or source override and preserves existing assets.

upload_release.sh is workflow-internal and rejects direct/local/container publication. The workflow validates the ten-field manifest and the complete archive before any release mutation, then redownloads and validates both canonical assets.

The release gate uses a bounded, read-only DoltHub GraphQL query to avoid unnecessary builds while data is still stale. If that online check is unavailable, it defers to the publisher's mandatory local snapshot freshness and archive validation; a failed local check still prevents release creation and uploads. The target trading day must also contain more than 1,000 price rows, matching the collector's existing completion floor, so index-only updates cannot make an otherwise stale stock snapshot publishable.

On a trading day after 17:00 Asia/Shanghai, a successful freshness query that finds missing current-day data asks the normal main collector to run. The publisher skips its Docker build in this case. Requests require the current main revision and reuse the existing workflow token; an active or queued main collector is not duplicated. Shared concurrency starts collection after the publisher exits. The collector's existing factor checks, source certification and successful-update publication trigger still apply. Before close, on non-trading days, or when freshness cannot be established, the existing gate behavior is preserved. Recovery needs a delivered publisher event; this fallback does not guarantee delivery of GitHub's schedules.

After close, a current-day source also gets a bounded, read-only certificate check. An outdated certified date, invalid collector revision or mismatched protected table hash requests the same normal collector, rather than repeatedly failing publication on a fresh but uncertified external append. If this web check is unavailable or its response is ambiguous, publication retains the mandatory immutable local verification; online checks never certify a source or bypass the publisher's existing data guards.

The build pins the Dolt binary checksum. If the GitHub asset API download fails (including anonymous rate limits), retries use the same version's official tagged release URL and enforce that same checksum. No build token is required.

The fixed historical operation repair-2026-11-08 repairs issue #163 using the pinned corrected Dolt commit. It runs only through a manual main workflow, verifies the captured original release/asset identities, preserves and redownloads both originals in a separate backup prerelease, stages and validates the new pair, then replaces the canonical names and validates the downloaded result. Prepared and accepted receipts remain in the backup release.

Fail-safe repository rollback

A full repository revert is ordered and fail-closed:

  1. Run gh workflow disable upload_release.yml --repo chenditc/investment_data.
  2. Query gh workflow view upload_release.yml --repo chenditc/investment_data --json state --jq .state and require the exact result disabled_manually.
  3. Query both upload_release.yml and data_update.yml runs and wait until every queued or in-progress job using the shared Dolt volume has drained.
  4. Perform the full repository revert.
  5. Run gh workflow view upload_release.yml --repo chenditc/investment_data --json state --jq .state again and require disabled_manually.
  6. Do not re-enable publication until validator-backed digest pinning, workflow authority, and shared concurrency/filesystem locking are restored and verified end to end.

The revert may move the convenience latest image and therefore affect data update, but it cannot publish while the upload workflow is disabled. Draining is mandatory because a full revert may remove the shared lock and concurrency group. Already accepted release assets are untouched. An interrupted historical repair may complete only through the fixed repair-2026-07-20 operation, and the stale backup is never auto-restored. The deployed monitor is separate external state; roll it back only with the tracked ops/investment-data-project-monitor/deploy.sh rollback, never as part of the repository revert.

Extract tar file to qlib directory

tar -zxvf qlib_bin.tar.gz -C ~/.qlib/qlib_data/cn_data --strip-components=1

Initiative

  1. Try to fill in missing data by combining data from multiple data source. For example, delist company's data.
  2. Try to correct data by cross validate against multiple data source.

Project Detail

Data Source

The database table on dolthub is named with prefix of data source, for example ts_a_stock_eod_price. The meaning of the prefix:

Initial loading and Validation logic for each table

Dolt Table Explanation

ts_link_table

The initial date for each stock might be different, when we calculate the adjusted price, we are using the first date price as adjust factor = 1.0.

In order to merge different data sources, we need to rescale the adjust factor, so that each data source will have the same adjusted price.

Each data source will have a dedicated link table, which is generated by:

  1. If the final_a_stock_eod_price already has this stock, adjust_ratio = final_a_stock_eod_price.adjust_price / current_data_source.adjust_price
  2. If the stock is new to final_a_stock_eod_price, adjust_ratio = 1.

Data validation needs to run to verify if the adjust factor match between each data source:

  • data_source_1.adjust_ratio * data_source_1.adjust_price = final_a_stock_eod_price.adjust_price

Contribution Guide

Add more stock index

To add a new stock index, we need to change:

  1. Add index weight download script. Change tushare/dump_index_eod_price.py script to dump the index info. If the index is not available in tushare, write a new script and add to the daily_update.sh script. Example commit
  2. Add price download script. Change tushare/dump_index_eod_price.py to add the index price. Eg. Example Commit
  3. Modify export script. Change the qlib dump script qlib/dump_index_weight.py#L13, so that index will be dump and renamed to a txt file for use. Example commit

Add more data source or fields

Please raise an issue to discuss the plan, example issue: https://github.com/chenditc/investment_data/issues/11

It should includes:

  1. Why do we want this data?
  2. How do we do regular update?
    • Which data source would we use?
    • When should we trigger update?
    • How do we validate regular update complete correctly?
  3. Which data source should we get historical data?
  4. How do we plan to validate the historical data?
    • Is the data source complete? How did we verify this?
    • Is the data source accurate? How did we verify this?
    • If we see error in validation, how will we deal with them?
  5. Are we changing exisiting table or adding new table?

If the data is not clean, we might try hard to dig insight from it and find incorrect insight. So we want high quality data instead of just data.

関連プロジェクトを探す

読み込み中…