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

计算前复权价格 #26

Open
zjp-CN opened this issue Jul 3, 2022 · 0 comments
Open

计算前复权价格 #26

zjp-CN opened this issue Jul 3, 2022 · 0 comments

Comments

@zjp-CN
Copy link
Owner

zjp-CN commented Jul 3, 2022

-- 计算复权数据
DROP TABLE IF EXISTS rustdx.qfq_x;
CREATE TABLE rustdx.qfq_x (
    -- 前复权系数
    code FixedString(6),
    x    Float64,
    PRIMARY KEY(code)
) ENGINE = MergeTree  AS
WITH
qfq AS (
    SELECT code, LAST_VALUE(close) / LAST_VALUE(factor) AS qfq_multi
    FROM rustdx.factor
    GROUP BY code
    ORDER BY code
)
SELECT * FROM qfq;
--  SELECT * FROM rustdx.qfq_x LIMIT 2;
DROP TABLE IF EXISTS rustdx.qfq;
CREATE TABLE rustdx.qfq (
    -- 前复权价格
    date  Date,
    code  FixedString(6),
    close Float64,
    open  Float64,
    high  Float64,
    low   Float64,
    PRIMARY KEY(date, code)
) ENGINE = MergeTree AS
WITH
qfq_x AS (SELECT * FROM rustdx.qfq_x),
fct AS (
    SELECT date, code, open/close AS open, high/close AS high, low/close AS low, factor
    FROM rustdx.factor
),
raw AS (
    SELECT *
    FROM fct
    LEFT JOIN qfq_x ON qfq_x.code = fct.code
)
SELECT date, code, factor*x AS close, open*close AS open, high*close AS high, low*close AS low
FROM raw
ORDER BY date, code

计算后的数据在 rustdx.qfq 表,并且每次运行此脚本时,将原表删除再重建。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant