liquidity_proxy.py 文件源码

python
阅读 30 收藏 0 点赞 0 评论 0

项目:MarketMakingProfitability 作者: MiesJansen 项目源码 文件源码
def Calculate_Liquidity_Coeff(df_list):
    #list of lists of liq coeff per bond
    liq_arr_list = []

    #print 'df_list size: ', len(df_list)
    for df in df_list:
        if df.empty:
            continue

        # A temporary array for holding liquidity beta for each month
        liq_arr = [np.nan] * num_months_CONST
        #print df['cusip_id'][0]

        # Group dataframe on index by month
        for date, df_group in df.groupby(pd.TimeGrouper("M")):
            month = ''.join([str(date.month),str(date.year)])
            month_key = month_keys[month]

            # When there are some data in current month,
            if df_group.shape[0] > 0:
                # Run regression (as equation (2)) to get liquidity measure
                y,X = dmatrices('excess_return_1 ~ yld_pt + volume_and_sign', 
                                data=df_group, return_type='dataframe')
                #print date, X.shape
                mod = sm.OLS(y,X)
                res = mod.fit()

                #set specific months with liquidity factors
                #res.params(2) = liquidity coefficient
                liq_arr[month_key] = res.params[2]

        liq_arr_list.append(liq_arr)    #store all liq coeff for each month per bond

    return liq_arr_list
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号