a
    cOj:                     @   s   d Z ddlZdd ZdS )u#   
收入现金含量信号计算。
    Nc                 C   s2   d}t j|| dtid}|d dd |d< |S )u3   计算所有股票最新年报收入现金含量。u  
    SELECT cf.code, cf.value::double precision / pl.value::double precision AS cash_to_revenue_ratio
    FROM (
        SELECT DISTINCT ON (code) code, value
        FROM financial_reports
        WHERE statement_type='cashflow' AND item_name='销售商品、提供劳务收到的现金' AND report_date LIKE '%1231'
          AND value IS NOT NULL
        ORDER BY code, report_date DESC
    ) cf
    JOIN (
        SELECT DISTINCT ON (code) code, value
        FROM financial_reports
        WHERE statement_type='profit' AND item_name='营业收入' AND report_date LIKE '%1231'
          AND value IS NOT NULL AND value::numeric != 0
        ORDER BY code, report_date DESC
    ) pl ON cf.code = pl.code
    code)dtypecash_to_revenue_ratioc                 S   s   t | r| dk rdS dS )Ngffffff?   r   )pdnotna)x r	   2/Users/admin/quant_ocf/ocf/signals/cash_revenue.py<lambda>       z$fetch_cash_revenue.<locals>.<lambda>cash_to_revenue_flag)r   read_sqlstrapply)connsqldfr	   r	   r
   fetch_cash_revenue   s    r   )__doc__pandasr   r   r	   r	   r	   r
   <module>   s   