Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

停牌结束后复权因子错误 #17

Closed
zjp-CN opened this issue Dec 1, 2021 · 2 comments
Closed

停牌结束后复权因子错误 #17

zjp-CN opened this issue Dec 1, 2021 · 2 comments
Labels
bug Something isn't working rustdx-cmd rustdx-cmd 相关

Comments

@zjp-CN
Copy link
Owner

zjp-CN commented Dec 1, 2021

301089 在 2021-11-13 至 2021-11-21 期间停牌,但是停牌结束后的 2021-11-22 从数据库没有获取到前一天的信息,自动被赋予因子 1。

┌───────date─┬─code───┬─open─┬──high─┬───low─┬─close─┬─────amount─┬────vol─┬─preclose─┬────────────factor─┐
│ 2021-11-11 │ 301089 │   71 │  79.4 │ 69.01 │ 75.99 │ 1049168640 │ 137989 │    66.17 │ 2.636710571423655 │
│ 2021-11-12 │ 301089 │   77 │ 91.19 │ 75.03 │ 91.19 │ 1057524600 │ 123778 │    75.99 │ 3.164122255621781 │
└────────────┴────────┴──────┴───────┴───────┴───────┴────────────┴────────┴──────────┴───────────────────┘
┌───────date─┬─code───┬──open─┬──high─┬───low─┬─close─┬────amount─┬────vol─┬─preclose─┬─────────────factor─┐
│ 2021-11-22 │ 301089 │    88 │ 91.18 │ 80.02 │ 87.58 │ 936002800 │ 108537 │    91.19 │ 0.9604123202796145 │
│ 2021-11-23 │ 301089 │ 86.61 │    94 │ 82.22 │ 88.48 │ 991503360 │ 113542 │    87.58 │ 0.9702818399833474 │
└────────────┴────────┴───────┴───────┴───────┴───────┴───────────┴────────┴──────────┴────────────────────┘

修复此 bug:
取每只股票最后一次(因为索引是日期升序排列的)的收盘价和因子作为数据库最新的信息

SELECT
    yesterday() AS date,
    code,
    last_value(close) AS close,
    last_value(factor) AS factor
FROM rustdx.factor
GROUP BY code

注意:此 date 只是一个标记,并不会对 date 做任何计算。

TODO: yesterday() AS date 也应改成 last_value(date) AS date (我忘了... 虽然暂时不改暂时没啥影响,改了可以更清楚知道哪些股票停牌)

@zjp-CN zjp-CN added bug Something isn't working rustdx-cmd rustdx-cmd 相关 labels Dec 1, 2021
@zjp-CN zjp-CN closed this as completed in 59d718a Dec 1, 2021
@zjp-CN
Copy link
Owner Author

zjp-CN commented Dec 1, 2021

SQL 语句有问题,需要重新发布

@zjp-CN zjp-CN reopened this Dec 1, 2021
@zjp-CN zjp-CN closed this as completed in 5709668 Dec 1, 2021
@zjp-CN
Copy link
Owner Author

zjp-CN commented Dec 1, 2021

修复结果:

┌───────date─┬─code───┬──open─┬──high─┬───low─┬─close─┬─────amount─┬───────vol─┬───────────preclose─┬─────────────factor─┐
│ 2021-11-11 │ 301089 │    71 │  79.4 │ 69.01 │ 75.99 │ 1049168640 │ 137988.98 │  66.16999816894531 │  2.636710571423655 │
│ 2021-11-12 │ 301089 │    77 │ 91.19 │ 75.03 │ 91.19 │ 1057524600 │ 123778.46 │  75.98999786376953 │  3.164122255621781 │
└────────────┴────────┴───────┴───────┴───────┴───────┴────────────┴───────────┴────────────────────┴────────────────────┘
┌───────date─┬─code───┬──open─┬──high─┬───low─┬─close─┬────amount─┬───────vol─┬──────────preclose─┬─────────────factor─┐
│ 2021-11-22 │ 301089 │    88 │ 91.18 │ 80.02 │ 87.58 │ 936002800 │ 108537.14 │ 91.19000244140625 │ 3.0388619971700823 │
│ 2021-11-23 │ 301089 │ 86.61 │    94 │ 82.22 │ 88.48 │ 991503360 │ 113542.41 │ 87.58000183105469 │  3.070090364116961 │
└────────────┴────────┴───────┴───────┴───────┴───────┴───────────┴───────────┴───────────────────┴────────────────────┘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working rustdx-cmd rustdx-cmd 相关
Projects
None yet
Development

No branches or pull requests

1 participant