【代码报错】m_product()函数计算结果为NaN值
由bqp8687s创建,最终由small_q 被浏览 16 用户
代码如下
import dai
st = ''
sql = f"""
select
date,
instrument,
sw2021_level2,
sw2021_level2_name,
r_ind,
r_mkt,
m_product(r_ind + 1,240)- 1 as r_ind_1y,
m_product(r_mkt + 1,240)- 1 as r_mkt_1y,
r_ind - r_mkt as r_std,
(r_ind_1y - r_mkt_1y) / r_std as IR
from(
SELECT
date,
instrument,
sw2021_level2,
sw2021_level2_name,
turn,
daily_return,
float_market_cap,
daily_return * float_market_cap AS df,
c_group_sum(sw2021_level2, df) / c_group_sum(sw2021_level2, float_market_cap) AS r_ind,
SUM(df) OVER () / SUM(float_market_cap) OVER () AS r_mkt
FROM
cn_stock_prefactors
WHERE
st_status = 0
AND
suspended = 0
AND
daily_return IS NOT NULL
AND
date BETWEEN '2024-08-01'::timestamp - INTERVAL '360 days' AND '2024-09-01'
) as subquery
QUALIFY
date BETWEEN '2024-08-01' AND '2024-09-01';
"""
df = dai.query(sql).df()
我检测了很多遍一级查询里的数据,没有NAN值了 但是r_ind 和r_mkt的数据还是计算出来为空值。
\