美文网首页
统计市场总体表现

统计市场总体表现

作者: 夏弘毅 | 来源:发表于2019-07-16 13:28 被阅读0次
    import numpy as np
    import pandas as pd
    import pandas.io.sql as sql
    import cx_Oracle as co
    # <editor-fold desc="数据提取">
    # 取用数据
    dsn = co.makedsn('220.248.233.27', 1521, 'zywinddb')
    conn = co.connect('wind', 'w1i2n3d4a5', dsn)
    c = conn.cursor()
    s_a = (
        """select  trade_dt,s_info_windcode,s_dq_adjclose 
        from ashareeodprices where trade_dt=20181228 order by s_info_windcode""")
    s_b = (
        """select  trade_dt,s_info_windcode,s_dq_adjclose 
        from ashareeodprices where trade_dt=20190628 order by s_info_windcode""")
    data_a = sql.read_sql(s_a, conn)
    data_b = sql.read_sql(s_b, conn)
    c.close()
    conn.close()
    # </editor-fold>
    pl = []
    for i in range(len(data_b)):
        try:
            loc = data_a[data_a.S_INFO_WINDCODE ==
                         data_b.S_INFO_WINDCODE[i]].index.tolist()[-1]
            pl.append(data_b.S_DQ_ADJCLOSE[i] / data_a.S_DQ_ADJCLOSE[loc] - 1)
        except BaseException:
            pass
        continue
    pl = np.array(pl)
    result = pd.DataFrame([{'项目': '内容',
                            '平均数': np.mean(pl),
                            '中位数': np.median(pl),
                            '25%分位点': np.percentile(pl,
                                                    75),
                            '股票数量': len(pl),
                            '正收益数量': sum(i > 0 for i in pl)}],
                          columns=['项目',
                                   '平均数',
                                   '中位数',
                                   '25%分位点',
                                   '股票数量',
                                   '正收益数量'])
    
    

    相关文章

      网友评论

          本文标题:统计市场总体表现

          本文链接:https://www.haomeiwen.com/subject/zzgzkctx.html