我也曾问过Quant Finance,但我认为有人也可以在这里提供帮助:
https://quant.stackexchange.com/questions/49099/why-dont-these-betas-match

我希望我的投资组合beta相对于市场回归时,能匹配我的各个成分beta乘以投资组合权重。我在下面创建了一个简单的示例。在解释我哪里出了问题方面的任何帮助将不胜感激。

import pandas as pd
    import numpy as np
    import statsmodels.api as sm
    from statsmodels import regression

    def beta(x, y):
        x = sm.add_constant(x)
        model = regression.linear_model.OLS(y, x).fit()
        # Remove the constant now that we're done
        x = x[:, 1]
        return model.params[1]


    bond_one = [100, 96, 102, 88, 96, 101, 120, 110, 105, 107, 106]
    bond_two = [98, 102, 88, 95, 105, 100, 101, 99, 104, 108, 112]
    mkt = [1000, 1004, 1000, 1010, 1020, 1000, 990, 995, 1005, 1025, 1035]

    df_mkt = pd.DataFrame(mkt, columns = ['mkt'])
    df_mkt = df_mkt.pct_change().dropna()
    df = pd.DataFrame(bond_one, columns = ['bond_one'])
    df['bond_two'] = bond_two

    df_price = df.copy()
    df = df.pct_change().dropna()

    notionals = {'bond_one': 2500000,
                    'bond_two': 6500000}

    mkt_values = {key: value*(df_price[key].iloc[-1]/100)
                  for (key, value) in notionals.items()}

    #create portfolio market value
    tot_port = sum(list(mkt_values.values()))
    #generate weights
    wts = {key: value/tot_port for (key, value) in mkt_values.items()}

    #create portfolio returns
    df_port = df.copy()*0
    df_port = df.mul(list(wts.values()), axis=1)
    df_port['port'] = df_port.sum(axis=1)

    #add port and market into original dataframe
    df['port'] = df_port['port'].copy()
    df['mkt'] = df_mkt['mkt'].copy()

    #run OLS on individuals and portfolio
    b1_beta = regression.linear_model.OLS(x = df['bond_one'].values, y=df['mkt'].values).fit()
    b2_beta = beta(x=df['bond_two'].values, y=df['mkt'].values)
    port_beta = beta(x=df['port'].values, y=df['mkt'].values)

    calc_beta = wts['bond_one']*b1_beta + wts['bond_two']*b2_beta
    ###why don't calc_beta and port_beta match?

最佳答案

差异与回归中投资组合权重的存在(或缺乏)有关。由于投资组合成分的价值每天都会变化,因此权重也会变化。 port_beta是您投资组合价值相对于market的时间的beta,而calc_beta是投资组合成分之间的beta的加权总和。产生差异的主要原因是,使用当前权重计算calc_beta,而使用历史权重计算port_beta

08-24 23:40