问答交流

市值行业中性化代码,求帮忙更正

由bqkrin4q创建,最终由small_q 被浏览 26 用户

%%sql
SELECT
    log(total_market_cap) as f_market_cap,
    m_avg(turn,20) as f_trun,
    date,
    instrument,
    industry_level1_code,
    c_neutralize(f_trun,industry_level1_code,f_market_cap) as NEW_TURN

FROM cn_stock_factors 
JOIN cn_stock_industry_component 
USING(date,instrument)
WHERE  date >= '2022-01-01' and date <= '2022-12-31' and cn_stock_industry_component.industry = 'sw2021'
--QUALIFY COLUMNS(*) NOT NULL

\

标签

换手率市值管理
评论
  • 要把nan值过滤掉
  • import dai
  • xf = dai.query("""
  • WITH cte AS (
  •     SELECT
  •         log(total_market_cap) as f_market_cap,
  •         m_avg(turn,20) as f_trun,
  •         date,
  •         instrument,
  •         industry_level1_code,
  •     FROM cn_stock_factors
  •     JOIN cn_stock_industry_component
  •     USING(date,instrument)
  •     WHERE  date >= '2022-01-01' and date <= '2022-12-31' and cn_stock_industry_component.industry = 'sw2021'
  •     QUALIFY COLUMNS(*) NOT NULL
  • )
  • select *, c_neutralize(f_trun, industry_level1_code, f_market_cap) as NEW_TURN
  • from cte
  • """).df()
  • xf
  • 跑通了,感谢。
{link}