liquidity_proxy.py 文件源码

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

项目:MarketMakingProfitability 作者: MiesJansen 项目源码 文件源码
def Run_Regression(liq_month_list):
    df = pd.DataFrame(index = month_list)    #set dates as index

    # Liquidity pi_t
    df['liq_month_list_1'] = liq_month_list
    # Liquidity pi_t-1
    df['liq_month_list'] = df['liq_month_list_1'].shift(1)
    # After shift, the first row is not longer valid data
    df = df.drop(df.index[0], inplace = False)

    ## FIX A scaling factor to delta_pi_t is dropped here because we do not
    ##  having historical amount outstanding of the bonds in the portfolio.
    ##  The scaling factor is (M_t-1 - M_1), where M_t is total dollar value at
    ##  end of month t-1, representing the total dollar value of the bonds
    ##  in month t
    # delta_pi_t = pi_t - pi_t-1
    df['liq_delta_1'] = df['liq_month_list_1'] - df['liq_month_list']
    # delta_pi_t-1
    df['liq_delta'] = df['liq_delta_1'].shift(1)
    # After shift, the first row is not longer valid data
    df = df.drop(df.index[0], inplace = False)

    # Run linear regression using equation (4)
    y,X = dmatrices('liq_delta_1 ~ liq_delta + liq_month_list', 
                    data = df, return_type = 'dataframe')
    mod = sm.OLS(y,X)
    res = mod.fit()

    # Calculate the predicted change in liquidty values
    df['liq_proxy_values'] = \
        res.params[0] + res.params[1] * df['liq_delta'] + \
        res.params[2] * df['liq_month_list']

    # Calculate the actual - predicted change in liquidity --> the residual term
    #  --> the liquidity risk
    df['residual_term'] = df['liq_delta_1'] - df['liq_proxy_values']

    # Scale the magnitude of the liquidity risk for convenient use in later steps
    df['residual_term'] = df['residual_term'] * 10000

    return df
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号