参数估计

https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86
Buy Me a Coffee at ko-fi.com

这个模块有一些功能,允许我们用几种方法估计均值向量、协方差矩阵和谷值平方矩阵:

  • 历史估计。

  • 使用指数加权移动平均数(EWMA)进行估计。

  • 协方差矩阵的稳健估计,如Ledoit and Wolf, Oracle, Shrinkage and Graphical Lasso, j-LoGo [B1] , Gerber statistic [B2] 和 Denoise [B3] 估计器。

  • 因子模型来估计平均值和协方差矩阵的向量。

  • Black Litterman模型,允许在均值向量和协方差矩阵的估计中纳入分析师对收益的看法 [B4] [B5]

  • 增强的Black Litterman模型允许将分析师对风险因素的看法纳入均值向量和协方差矩阵的估计中 [B6] .

  • Black Litterman贝叶斯模型,允许在均值向量和协方差矩阵的估计中纳入分析家对风险因素的看法:cite:b-LB

  • 用Bootstrapping方法估计最坏情况优化模型的均值向量和协方差矩阵的不确定性集的输入参数。

模块函数

ParamsEstimation.mean_vector(X, method='hist', d=0.94, target='b1')[源代码]

Calculate the expected returns vector using the selected method.

参数:
  • X (DataFrame of shape (n_samples, n_features)) – Features matrix, where n_samples is the number of samples and n_features is the number of features.

  • method (str, optional) –

    The method used to estimate the expected returns. The default value is ‘hist’. Possible values are:

    • ’hist’: use historical estimator.

    • ’ewma1’: use ewma with adjust=True. For more information see EWM.

    • ’ewma2’: use ewma with adjust=False. For more information see EWM.

    • ’JS’: James-Stein estimator. For more information see [B7] and [B8].

    • ’BS’: Bayes-Stein estimator. For more information see [B9].

    • ’BOP’: BOP estimator. For more information see [B10].

  • d (scalar) – The smoothing factor of ewma methods. The default is 0.94.

  • target (str, optional) –

    The target mean vector. The default value is ‘b1’. Possible values are:

    • ’b1’: grand mean.

    • ’b2’: volatility weighted grand mean.

    • ’b3’: mean square error of sample mean.

返回:

mu – The estimation of expected returns.

返回类型:

1d-array

抛出:

ValueError – When the value cannot be calculated.

ParamsEstimation.covar_matrix(X, method='hist', d=0.94, **kwargs)[源代码]

Calculate the covariance matrix using the selected method.

参数:
  • X (DataFrame of shape (n_samples, n_features)) – Features matrix, where n_samples is the number of samples and n_features is the number of features.

  • method (str, optional) –

    The method used to estimate the covariance matrix: The default is ‘hist’. Possible values are:

    • ’hist’: use historical estimates.

    • ’semi’: use semi lower covariance matrix.

    • ’ewma1’: use ewma with adjust=True. For more information see EWM.

    • ’ewma2’: use ewma with adjust=False. For more information see EWM.

    • ’ledoit’: use the Ledoit and Wolf Shrinkage method.

    • ’oas’: use the Oracle Approximation Shrinkage method.

    • ’shrunk’: use the basic Shrunk Covariance method.

    • ’gl’: use the basic Graphical Lasso Covariance method.

    • ’jlogo’: use the j-LoGo Covariance method. For more information see: [B1].

    • ’fixed’: denoise using fixed method. For more information see chapter 2 of [B3].

    • ’spectral’: denoise using spectral method. For more information see chapter 2 of [B3].

    • ’shrink’: denoise using shrink method. For more information see chapter 2 of [B3].

    • ’gerber1’: use the Gerber statistic 1. For more information see: [B2].

    • ’gerber2’: use the Gerber statistic 2. For more information see: [B2].

  • d (scalar) – The smoothing factor of ewma methods. The default is 0.94.

  • **kwargs – Other variables related to covariance estimation. See Scikit Learn and chapter 2 of [B3] for more details.

返回:

cov – The estimation of covariance matrix.

返回类型:

nd-array

抛出:

ValueError – When the value cannot be calculated.

ParamsEstimation.cokurt_matrix(X, method='hist', **kwargs)[源代码]

Calculate the cokurtosis square matrix using the selected method.

参数:
  • X (DataFrame of shape (n_samples, n_features)) – Features matrix, where n_samples is the number of samples and n_features is the number of features.

  • method (str, optional) –

    The method used to estimate the cokurtosis square matrix: The default is ‘hist’. Possible values are:

    • ’hist’: use historical estimates.

    • ’semi’: use semi lower cokurtosis square matrix.

    • ’fixed’: denoise using fixed method. For more information see chapter 2 of [B3].

    • ’spectral’: denoise using spectral method. For more information see chapter 2 of [B3].

    • ’shrink’: denoise using shrink method. For more information see chapter 2 of [B3].

  • **kwargs – Other variables related to covariance estimation. See chapter 2 of [B3] for more details.

返回:

kurt – The estimation of cokurtosis square matrix.

返回类型:

nd-array

抛出:

ValueError – When the value cannot be calculated.

ParamsEstimation.forward_regression(X, y, criterion='pvalue', threshold=0.05, verbose=False)[源代码]

Select the variables that estimate the best model using stepwise forward regression. In case none of the variables has a p-value lower than threshold, the algorithm will select the variable with lowest p-value.

参数:
  • X (DataFrame of shape (n_samples, n_features)) – Features matrix, where n_samples is the number of samples and n_features is the number of features.

  • y (Series of shape (n_samples, 1)) – Target vector, where n_samples in the number of samples.

  • criterion (str, optional) –

    The default is ‘pvalue’. Possible values of the criterion used to select the best features are:

    • ’pvalue’: select the features based on p-values.

    • ’AIC’: select the features based on lowest Akaike Information Criterion.

    • ’SIC’: select the features based on lowest Schwarz Information Criterion.

    • ’R2’: select the features based on highest R Squared.

    • ’R2_A’: select the features based on highest Adjusted R Squared.

  • thresholdt (scalar, optional) – Is the maximum p-value for each variable that will be accepted in the model. The default is 0.05.

  • verbose (bool, optional) – Enable verbose output. The default is False.

返回:

value – A list of the variables that produce the best model.

返回类型:

list

抛出:

ValueError – When the value cannot be calculated.

ParamsEstimation.backward_regression(X, y, criterion='pvalue', threshold=0.05, verbose=False)[源代码]

Select the variables that estimate the best model using stepwise backward regression. In case none of the variables has a p-value lower than threshold, the algorithm will select the variable with lowest p-value.

参数:
  • X (DataFrame of shape (n_samples, n_features)) – Features matrix, where n_samples is the number of samples and n_features is the number of features.

  • y (Series of shape (n_samples, 1)) – Target vector, where n_samples in the number of samples.

  • criterion (str, optional) –

    The default is ‘pvalue’. Possible values of the criterion used to select the best features are:

    • ’pvalue’: select the features based on p-values.

    • ’AIC’: select the features based on lowest Akaike Information Criterion.

    • ’SIC’: select the features based on lowest Schwarz Information Criterion.

    • ’R2’: select the features based on highest R Squared.

    • ’R2_A’: select the features based on highest Adjusted R Squared.

  • threshold (scalar, optional) – Is the maximum p-value for each variable that will be accepted in the model. The default is 0.05.

  • verbose (bool, optional) – Enable verbose output. The default is False.

返回:

value – A list of the variables that produce the best model.

返回类型:

list

抛出:

ValueError – When the value cannot be calculated.

ParamsEstimation.PCR(X, y, n_components=0.95)[源代码]

Estimate the coefficients using Principal Components Regression (PCR).

参数:
  • X (DataFrame of shape (n_samples, n_features)) – Features matrix, where n_samples is the number of samples and n_features is the number of features.

  • y (Series of shape (n_samples, 1)) – Target vector, where n_samples in the number of samples.

  • n_components (int, float, None or str, optional) – if 1 < n_components (int), it represents the number of components that will be keep. if 0 < n_components < 1 (float), it represents the percentage of variance that the is explained by the components kept. See PCA for more details. The default is 0.95.

返回:

value – An array with the coefficients of the model calculated using PCR.

返回类型:

nd-array

抛出:

ValueError – When the value cannot be calculated.

ParamsEstimation.loadings_matrix(X, Y, feature_selection='stepwise', stepwise='Forward', criterion='pvalue', threshold=0.05, n_components=0.95, verbose=False)[源代码]

Estimate the loadings matrix using stepwise regression.

参数:
  • X (DataFrame of shape (n_samples, n_features)) – Features matrix, where n_samples is the number of samples and n_features is the number of features.

  • Y (DataFrame of shape (n_samples, n_assets)) – Target matrix, where n_samples in the number of samples and n_assets is the number of assets.

  • feature_selection (str 'stepwise' or 'PCR', optional) – Indicate the method used to estimate the loadings matrix. The default is ‘stepwise’.

  • stepwise (str 'Forward' or 'Backward', optional) – Indicate the method used for stepwise regression. The default is ‘Forward’.

  • criterion (str, optional) –

    The default is ‘pvalue’. Possible values of the criterion used to select the best features are:

    • ’pvalue’: select the features based on p-values.

    • ’AIC’: select the features based on lowest Akaike Information Criterion.

    • ’SIC’: select the features based on lowest Schwarz Information Criterion.

    • ’R2’: select the features based on highest R Squared.

    • ’R2_A’: select the features based on highest Adjusted R Squared.

  • threshold (scalar, optional) – Is the maximum p-value for each variable that will be accepted in the model. The default is 0.05.

  • n_components (int, float, None or str, optional) –

    if 1 < n_components (int), it represents the number of components that will be keep. if 0 < n_components < 1 (float), it represents the percentage of variance that the is explained by the components kept. See PCA for more details. The default is 0.95.

  • verbose (bool, optional) – Enable verbose output. The default is False.

返回:

loadings – A DataFrame with the loadings matrix.

返回类型:

DataFrame

抛出:

ValueError – When the value cannot be calculated.

ParamsEstimation.risk_factors(X, Y, B=None, const=False, method_mu='hist', method_cov='hist', feature_selection='stepwise', stepwise='Forward', criterion='pvalue', threshold=0.05, n_components=0.95, error=True, **kwargs)[源代码]

Estimate the expected returns vector and covariance matrix based on risk factors models [B11] [B12].

\[\begin{split}\begin{aligned} R & = \alpha + B F + \epsilon \\ \mu_{f} & = \alpha +BE(F) \\ \Sigma_{f} & = B \Sigma_{F} B^{T} + \Sigma_{\epsilon} \\ \end{aligned}\end{split}\]

where:

\(R\) is the series returns.

\(\alpha\) is the intercept.

\(B\) is the loadings matrix.

\(F\) is the expected returns vector of the risk factors.

\(\Sigma_{F}\) is the covariance matrix of the risk factors.

\(\Sigma_{\epsilon}\) is the covariance matrix of error terms.

\(\mu_{f}\) is the expected returns vector obtained with the risk factor model.

\(\Sigma_{f}\) is the covariance matrix obtained with the risk factor model.

参数:
  • X (DataFrame of shape (n_samples, n_features)) – Features matrix, where n_samples is the number of samples and n_features is the number of features.

  • Y (DataFrame of shape (n_samples, n_assets)) – Target matrix, where n_samples in the number of samples and n_assets is the number of assets.

  • B (DataFrame of shape (n_assets, n_features), optional) – Loadings matrix. If is not specified, is estimated using stepwise regression. The default is None.

  • const (bool, optional) – Indicate if the loadings matrix has a constant. The default is False.

  • method_mu (str, optional) –

    The method used to estimate the expected returns of factors. The default value is ‘hist’. Possible values are:

    • ’hist’: use historical estimates.

    • ’ewma1’’: use ewma with adjust=True, see EWM for more details.

    • ’ewma2’: use ewma with adjust=False, see EWM for more details.

    • ’JS’: James-Stein estimator. For more information see [B7] and [B8].

    • ’BS’: Bayes-Stein estimator. For more information see [B9].

    • ’BOP’: BOP estimator. For more information see [B10].

  • method_cov (str, optional) –

    The method used to estimate the covariance matrix of factors. The default is ‘hist’. Possible values are:

    • ’hist’: use historical estimates.

    • ’ewma1’’: use ewma with adjust=True, see EWM for more details.

    • ’ewma2’: use ewma with adjust=False, see EWM for more details.

    • ’ledoit’: use the Ledoit and Wolf Shrinkage method.

    • ’oas’: use the Oracle Approximation Shrinkage method.

    • ’shrunk’: use the basic Shrunk Covariance method.

    • ’gl’: use the basic Graphical Lasso Covariance method.

    • ’jlogo’: use the j-LoGo Covariance method. For more information see: [B1].

    • ’fixed’: denoise using fixed method. For more information see chapter 2 of [B3].

    • ’spectral’: denoise using spectral method. For more information see chapter 2 of [B3].

    • ’shrink’: denoise using shrink method. For more information see chapter 2 of [B3].

    • ’gerber1’: use the Gerber statistic 1. For more information see: [B2].

    • ’gerber2’: use the Gerber statistic 2. For more information see: [B2].

  • feature_selection (str, 'stepwise' or 'PCR', optional) – Indicate the method used to estimate the loadings matrix. The default is ‘stepwise’.

  • stepwise (str, 'Forward' or 'Backward') – Indicate the method used for stepwise regression. The default is ‘Forward’.

  • criterion (str, optional) –

    The default is ‘pvalue’. Possible values of the criterion used to select the best features are:

    • ’pvalue’: select the features based on p-values.

    • ’AIC’: select the features based on lowest Akaike Information Criterion.

    • ’SIC’: select the features based on lowest Schwarz Information Criterion.

    • ’R2’: select the features based on highest R Squared.

    • ’R2_A’: select the features based on highest Adjusted R Squared.

  • threshold (scalar, optional) – Is the maximum p-value for each variable that will be accepted in the model. The default is 0.05.

  • n_components (int, float, None or str, optional) –

    if 1 < n_components (int), it represents the number of components that will be keep. if 0 < n_components < 1 (float), it represents the percentage of variance that the is explained by the components kept. See PCA for more details. The default is 0.95.

  • error (bool) – Indicate if diagonal covariance matrix of errors is included (only when B is estimated through a regression).

  • **kwargs (dict) – Other variables related to the expected returns and covariance estimation.

返回:

  • mu (DataFrame) – The mean vector of risk factors model.

  • cov (DataFrame) – The covariance matrix of risk factors model.

  • returns (DataFrame) – The returns based on a risk factor model.

  • nav (DataFrame) – The cumulated uncompounded returns based on a risk factor model.

抛出:

ValueError – When the value cannot be calculated.

ParamsEstimation.black_litterman(X, w, P, Q, delta=1, rf=0, eq=True, method_mu='hist', method_cov='hist', **kwargs)[源代码]

Estimate the expected returns vector and covariance matrix based on the Black Litterman model [B4] [B5].

\[\begin{split}\begin{aligned} \Pi & = \delta \Sigma w \\ \Pi_{BL} & = \left [ (\tau\Sigma)^{-1}+ P^{T} \Omega^{-1}P \right]^{-1} \left[(\tau\Sigma)^{-1} \Pi + P^{T} \Omega^{-1} Q \right] \\ M & = \left((\tau\Sigma)^{-1} + P^{T}\Omega^{-1} P \right)^{-1} \\ \mu_{BL} & = \Pi_{BL} + r_{f} \\ \Sigma_{BL} & = \Sigma + M \\ \end{aligned}\end{split}\]

where:

\(r_{f}\) is the risk free rate.

\(\delta\) is the risk aversion factor.

\(\Pi\) is the equilibrium excess returns.

\(\Sigma\) is the covariance matrix.

\(P\) is the views matrix.

\(Q\) is the views returns matrix.

\(\Omega\) is the covariance matrix of the error views.

\(\mu_{BL}\) is the mean vector obtained with the black litterman model.

\(\Sigma_{BL}\) is the covariance matrix obtained with the black litterman model.

参数:
  • X (DataFrame of shape (n_samples, n_assets)) – Assets matrix, where n_samples is the number of samples and n_assets is the number of assets.

  • w (DataFrame of shape (n_assets, 1)) – Weights matrix, where n_assets is the number of assets.

  • P (DataFrame of shape (n_views, n_assets)) – Analyst’s views matrix, can be relative or absolute.

  • Q (DataFrame of shape (n_views, 1)) – Expected returns of analyst’s views.

  • delta (float, optional) – Risk aversion factor. The default value is 1.

  • rf (scalar, optional) – Risk free rate. The default is 0.

  • eq (bool, optional) – Indicate if use equilibrium or historical excess returns. The default is True.

  • method_mu (str, optional) –

    The method used to estimate the expected returns. The default value is ‘hist’.

    • ’hist’: use historical estimates.

    • ’ewma1’: use ewma with adjust=True. For more information see EWM.

    • ’ewma2’: use ewma with adjust=False. For more information see EWM.

    • ’JS’: James-Stein estimator. For more information see [B7] and [B8].

    • ’BS’: Bayes-Stein estimator. For more information see [B9].

    • ’BOP’: BOP estimator. For more information see [B10].

  • method_cov (str, optional) –

    The method used to estimate the covariance matrix: The default is ‘hist’. Possible values are:

    • ’hist’: use historical estimates.

    • ’ewma1’: use ewma with adjust=True. For more information see EWM.

    • ’ewma2’: use ewma with adjust=False. For more information see EWM.

    • ’ledoit’: use the Ledoit and Wolf Shrinkage method.

    • ’oas’: use the Oracle Approximation Shrinkage method.

    • ’shrunk’: use the basic Shrunk Covariance method.

    • ’gl’: use the basic Graphical Lasso Covariance method.

    • ’jlogo’: use the j-LoGo Covariance method. For more information see: [B1].

    • ’fixed’: denoise using fixed method. For more information see chapter 2 of [B3].

    • ’spectral’: denoise using spectral method. For more information see chapter 2 of [B3].

    • ’shrink’: denoise using shrink method. For more information see chapter 2 of [B3].

    • ’gerber1’: use the Gerber statistic 1. For more information see: [B2].

    • ’gerber2’: use the Gerber statistic 2. For more information see: [B2].

  • **kwargs (dict) – Other variables related to the expected returns and covariance estimation.

返回:

  • mu (DataFrame) – The mean vector of Black Litterman model.

  • cov (DataFrame) – The covariance matrix of Black Litterman model.

  • w (DataFrame) – The equilibrium weights of Black Litterman model, without constraints.

抛出:

ValueError – When the value cannot be calculated.

ParamsEstimation.augmented_black_litterman(X, w, F=None, B=None, P=None, Q=None, P_f=None, Q_f=None, delta=1, rf=0, eq=True, const=True, method_mu='hist', method_cov='hist', **kwargs)[源代码]

Estimate the expected returns vector and covariance matrix based on the Augmented Black Litterman model [B6].

\[\begin{split}\begin{aligned} \Pi^{a} & = \delta \left [ \begin{array}{c} \Sigma \\ \Sigma_{F} B^{T} \\ \end{array} \right ] w \\ P^{a} & = \left [ \begin{array}{cc} P & 0 \\ 0 & P_{F} \\ \end{array} \right ] \\ Q^{a} & = \left [ \begin{array}{c} Q \\ Q_{F} \\ \end{array} \right ] \\ \Sigma^{a} & = \left [ \begin{array}{cc} \Sigma & B \Sigma_{F}\\ \Sigma_{F} B^{T} & \Sigma_{F} \\ \end{array} \right ] \\ \Omega^{a} & = \left [ \begin{array}{cc} \Omega & 0 \\ 0 & \Omega_{F} \\ \end{array} \right ] \\ \Pi^{a}_{BL} & = \left [ (\tau \Sigma^{a})^{-1} + (P^{a})^{T} (\Omega^{a})^{-1} P^{a} \right ]^{-1} \left [ (\tau\Sigma^{a})^{-1} \Pi^{a} + (P^{a})^{T} (\Omega^{a})^{-1} Q^{a} \right ] \\ M^{a} & = \left ( (\tau\Sigma^{a})^{-1} + (P^{a})^{T} (\Omega^{a})^{-1} P^{a} \right )^{-1} \\ \mu^{a}_{BL} & = \Pi^{a}_{BL} + r_{f} \\ \Sigma^{a}_{BL} & = \Sigma^{a} + M^{a} \\ \end{aligned}\end{split}\]

where:

\(r_{f}\) is the risk free rate.

\(\delta\) is the risk aversion factor.

\(B\) is the loadings matrix.

\(\Sigma\) is the covariance matrix of assets.

\(\Sigma_{F}\) is the covariance matrix of factors.

\(\Sigma^{a}\) is the augmented covariance matrix.

\(P\) is the assets views matrix.

\(Q\) is the assets views returns matrix.

\(P_{F}\) is the factors views matrix.

\(Q_{F}\) is the factors views returns matrix.

\(P^{a}\) is the augmented views matrix.

\(Q^{a}\) is the augmented views returns matrix.

\(\Pi^{a}\) is the augmented equilibrium excess returns.

\(\Omega\) is the covariance matrix of errors of assets views.

\(\Omega_{F}\) is the covariance matrix of errors of factors views.

\(\Omega^{a}\) is the covariance matrix of errors of augmented views.

\(\mu^{a}_{BL}\) is the mean vector obtained with the Augmented Black Litterman model.

\(\Sigma^{a}_{BL}\) is the covariance matrix obtained with the Augmented Black Litterman model.

参数:
  • X (DataFrame of shape (n_samples, n_assets)) – Assets matrix, where n_samples is the number of samples and n_assets is the number of features.

  • w (DataFrame of shape (n_assets, 1)) – Weights matrix, where n_assets is the number of assets.

  • F (DataFrame of shape (n_samples, n_features)) – Features matrix, where n_samples is the number of samples and n_features is the number of features.

  • B (DataFrame of shape (n_assets, n_features), optional) – Loadings matrix. The default is None.

  • P (DataFrame of shape (n_views, n_assets)) – Analyst’s views matrix, can be relative or absolute.

  • Q (DataFrame of shape (n_views, 1)) – Expected returns of analyst’s views.

  • P_f (DataFrame of shape (n_views, n_features)) – Analyst’s factors views matrix, can be relative or absolute.

  • Q_f (DataFrame of shape (n_views, 1)) – Expected returns of analyst’s factors views.

  • delta (float, optional) – Risk aversion factor. The default value is 1.

  • rf (scalar, optional) – Risk free rate. The default is 0.

  • eq (bool, optional) – Indicate if use equilibrium or historical excess returns. The default is True.

  • const (bool, optional) – Indicate if use equilibrium or historical excess returns. The default is True.

  • method_mu (str, optional) –

    The method used to estimate the expected returns. The default value is ‘hist’.

    • ’hist’: use historical estimates.

    • ’ewma1’: use ewma with adjust=True. For more information see EWM.

    • ’ewma2’: use ewma with adjust=False. For more information see EWM.

    • ’JS’: James-Stein estimator. For more information see [B7] and [B8].

    • ’BS’: Bayes-Stein estimator. For more information see [B9].

    • ’BOP’: BOP estimator. For more information see [B10].

  • method_cov (str, optional) –

    The method used to estimate the covariance matrix. The default is ‘hist’. Possible values are:

    • ’hist’: use historical estimates.

    • ’ewma1’: use ewma with adjust=True. For more information see EWM.

    • ’ewma2’: use ewma with adjust=False. For more information see EWM.

    • ’ledoit’: use the Ledoit and Wolf Shrinkage method.

    • ’oas’: use the Oracle Approximation Shrinkage method.

    • ’shrunk’: use the basic Shrunk Covariance method.

    • ’gl’: use the basic Graphical Lasso Covariance method.

    • ’jlogo’: use the j-LoGo Covariance method. For more information see: [B1].

    • ’fixed’: denoise using fixed method. For more information see chapter 2 of [B3].

    • ’spectral’: denoise using spectral method. For more information see chapter 2 of [B3].

    • ’shrink’: denoise using shrink method. For more information see chapter 2 of [B3].

    • ’gerber1’: use the Gerber statistic 1. For more information see: [B2].

    • ’gerber2’: use the Gerber statistic 2. For more information see: [B2].

  • **kwargs (dict) – Other variables related to the expected returns and covariance estimation.

返回:

  • mu (DataFrame) – The mean vector of Augmented Black Litterman model.

  • cov (DataFrame) – The covariance matrix of Augmented Black Litterman model.

  • w (DataFrame) – The equilibrium weights of Augmented Black Litterman model, without constraints.

抛出:

ValueError – When the value cannot be calculated.

ParamsEstimation.black_litterman_bayesian(X, F, B, P_f, Q_f, delta=1, rf=0, eq=True, const=True, diag=True, method_mu='hist', method_cov='hist', **kwargs)[源代码]

Estimate the expected returns vector and covariance matrix based on the black litterman model [B13].

\[\begin{split}\begin{aligned} \Sigma_{F} & = B \Sigma_{F} B^{T} + D \\ \overline{\Pi}_{F} & = \left ( \Sigma_{F}^{-1} + P_{F}^{T}\Omega_{F}^{-1}P_{F} \right )^{-1} \left ( \Sigma_{F}^{-1}\Pi_{F} + P_{F}^{T}\Omega_{F}^{-1}Q_{F} \right) \\ \overline{\Sigma}_{F} & = \left ( \Sigma_{F}^{-1} + P_{F}^{T}\Omega_{F}^{-1}P_{F} \right )^{-1} \\ \Sigma_{BLB} & = \left( \Sigma^{-1} - \Sigma^{-1} B \left( \overline{\Sigma}_{F}^{-1} + B^{T}\Sigma^{-1}B \right)^{-1} B^{T}\Sigma^{-1} \right )^{-1} \\ \mu_{BLB} & = \Sigma_{BLB} \left ( \Sigma^{-1} B \left( \overline{\Sigma}_{F}^{-1} +B^{T}\Sigma^{-1}B \right)^{-1} \overline{\Sigma}_{F}^{-1} \overline{\Pi}_{F} \right ) + r_{f} \\ \end{aligned}\end{split}\]

where:

\(r_{f}\) is the risk free rate.

\(B\) is the loadings matrix.

\(D\) is a diagonal matrix of variance of errors of a factor model.

\(\Sigma\) is the covariance matrix obtained with a factor model.

\(\Pi_{F}\) is the equilibrium excess returns of factors.

\(\overline{\Pi}_{F}\) is the posterior excess returns of factors.

\(\Sigma_{F}\) is the covariance matrix of factors.

\(\overline{\Sigma}_{F}\) is the posterior covariance matrix of factors.

\(P_{F}\) is the factors views matrix.

\(Q_{F}\) is the factors views returns matrix.

\(\Omega_{F}\) is the covariance matrix of errors of factors views.

\(\mu_{BLB}\) is the mean vector obtained with the Black Litterman Bayesian model or posterior predictive mean.

\(\Sigma_{BLB}\) is the covariance matrix obtained with the Black Litterman Bayesian model or posterior predictive covariance.

参数:
  • X (DataFrame of shape (n_samples, n_assets)) – Assets matrix, where n_samples is the number of samples and n_assets is the number of assets.

  • F (DataFrame of shape (n_samples, n_features)) – Features matrix, where n_samples is the number of samples and n_features is the number of features.

  • B (DataFrame of shape (n_assets, n_features), optional) – Loadings matrix. The default is None.

  • P_f (DataFrame of shape (n_views, n_features)) – Analyst’s factors views matrix, can be relative or absolute.

  • Q_f (DataFrame of shape (n_views, 1)) – Expected returns of analyst’s factors views.

  • delta (float, optional) – Risk aversion factor. The default value is 1.

  • rf (scalar, optional) – Risk free rate. The default is 0.

  • eq (bool, optional) – Indicate if use equilibrium or historical excess returns. The default is True.

  • const (bool, optional) – Indicate if the loadings matrix has a constant. The default is True.

  • diag (bool, optional) – Indicate if we use the diagonal matrix to calculate covariance matrix of factor model, only useful when we work with a factor model based on a regresion model (only equity portfolio). The default is True.

  • method_mu (str, optional) –

    The method used to estimate the expected returns. The default value is ‘hist’.

    • ’hist’: use historical estimates.

    • ’ewma1’: use ewma with adjust=True. For more information see EWM.

    • ’ewma2’: use ewma with adjust=False, For more information see EWM.

    • ’JS’: James-Stein estimator. For more information see [B7] and [B8].

    • ’BS’: Bayes-Stein estimator. For more information see [B9].

    • ’BOP’: BOP estimator. For more information see [B10].

  • method_cov (str, optional) –

    The method used to estimate the covariance matrix: The default is ‘hist’. Possible values are:

    • ’hist’: use historical estimates.

    • ’ewma1’: use ewma with adjust=True. For more information see EWM.

    • ’ewma2’: use ewma with adjust=False. For more information see EWM.

    • ’ledoit’: use the Ledoit and Wolf Shrinkage method.

    • ’oas’: use the Oracle Approximation Shrinkage method.

    • ’shrunk’: use the basic Shrunk Covariance method.

    • ’gl’: use the basic Graphical Lasso Covariance method.

    • ’jlogo’: use the j-LoGo Covariance method. For more information see: [B1].

    • ’fixed’: denoise using fixed method. For more information see chapter 2 of [B3].

    • ’spectral’: denoise using spectral method. For more information see chapter 2 of [B3].

    • ’shrink’: denoise using shrink method. For more information see chapter 2 of [B3].

    • ’gerber1’: use the Gerber statistic 1. For more information see: [B2].

    • ’gerber2’: use the Gerber statistic 2. For more information see: [B2].

  • **kwargs (dict) – Other variables related to the expected returns and covariance estimation.

返回:

  • mu (DataFrame) – The mean vector of Black Litterman model.

  • cov (DataFrame) – The covariance matrix of Black Litterman model.

  • w (DataFrame) – The equilibrium weights of Black Litterman model, without constraints.

抛出:

ValueError – When the value cannot be calculated.

ParamsEstimation.bootstrapping(X, kind='stationary', q=0.05, n_sim=3000, window=3, seed=0)[源代码]

Estimates the uncertainty sets of mean and covariance matrix through the selected bootstrapping method.

参数:
  • X (DataFrame of shape (n_samples, n_features)) – Features matrix, where n_samples is the number of samples and n_features is the number of features.

  • kind (str) –

    The bootstrapping method. The default value is ‘stationary’. Possible values are:

  • q (scalar) – Significance level of the selected bootstrapping method. The default is 0.05.

  • n_sim (scalar) – Number of simulations of the bootstrapping method. The default is 3000.

  • window – Block size of the bootstrapping method. Must be greather than 1 and lower than the n_samples - n_features + 1 The default is 3.

  • seed – Seed used to generate random numbers for bootstrapping method. The default is 0.

返回:

  • mu_l (DataFrame) – The q/2 percentile of mean vector obtained through the selected bootstrapping method.

  • mu_u (DataFrame) – The 1-q/2 percentile of mean vector obtained through the selected bootstrapping method.

  • cov_l (DataFrame) – The q/2 percentile of covariance matrix obtained through the selected bootstrapping method.

  • cov_u (DataFrame) – The 1-q/2 percentile of covariance matrix obtained through the selected bootstrapping method.

  • cov_mu (DataFrame) – The covariance matrix of estimation errors of mean vector obtained through the selected bootstrapping method. We take the diagonal of this matrix following [B14].

抛出:

ValueError – When the value cannot be calculated.

参考文献

[B1] (1,2,3,4,5,6)

Wolfram Barfuss, Guido Previde Massara, T. Di Matteo, and Tomaso Aste. Parsimonious modeling with information filtering networks. Physical Review E, Dec 2016. URL: http://dx.doi.org/10.1103/PhysRevE.94.062306, doi:10.1103/physreve.94.062306.

[B2] (1,2,3,4,5,6,7,8,9,10,11)

Sander Gerber, Harry Markowitz, Philip Ernst, Yinsen Miao, Babak Javid, and Paul Sargen. The gerber statistic: a robust co-movement measure for portfolio optimization. SSRN Electronic Journal, 2021. URL: https://doi.org/10.2139/ssrn.3880054, doi:10.2139/ssrn.3880054.

[B3] (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21)

Marcos M. López de Prado. Machine Learning for Asset Managers. Elements in Quantitative Finance. Cambridge University Press, 2020. doi:10.1017/9781108883658.

[B4] (1,2)

Fischer Black and Robert Litterman. Global portfolio optimization. Financial Analysts Journal, 48(5):28–43, 1992. URL: http://www.jstor.org/stable/4479577.

[B5] (1,2)

Jay Walters. The black-litterman model in detail. SSRN Electronic Journal, pages, 07 2011. doi:10.2139/ssrn.1314585.

[B6] (1,2)

Wing Cheung. The augmented black-litterman model: a ranking-free approach to factor-based portfolio construction and beyond. Quantitative Finance, 13:, 08 2007. doi:10.2139/ssrn.1347648.

[B7] (1,2,3,4,5)

Attilio Meucci. Risk and Asset Allocation. Springer Berlin Heidelberg, 2005. URL: https://doi.org/10.1007/978-3-540-27904-4, doi:10.1007/978-3-540-27904-4.

[B8] (1,2,3,4,5)

Yiyong Feng and Daniel P. Palomar. A signal processing perspective of financial engineering. Foundations and Trends® in Signal Processing, 9(1-2):1–231, 2016. URL: https://doi.org/10.1561/2000000072, doi:10.1561/2000000072.

[B9] (1,2,3,4,5)

Philippe Jorion. Bayes-stein estimation for portfolio analysis. The Journal of Financial and Quantitative Analysis, 21(3):279, September 1986. URL: https://doi.org/10.2307/2331042, doi:10.2307/2331042.

[B10] (1,2,3,4,5)

Taras Bodnar, Ostap Okhrin, and Nestor Parolya. Optimal shrinkage estimator for high-dimensional mean vector. Journal of Multivariate Analysis, 170:63–79, mar 2019. URL: https://doi.org/10.1016\%2Fj.jmva.2018.07.004, doi:10.1016/j.jmva.2018.07.004.

[B11]

Stephen A. Ross. The arbitrage theory of capital asset pricing. Journal of Economic Theory, 13(3):341–360, December 1976. URL: https://ideas.repec.org/a/eee/jetheo/v13y1976i3p341-360.html, doi:.

[B12]

Jianqing Fan, Yingying Fan, and Jinchi Lv. High dimensional covariance matrix estimation using a factor model. Journal of Econometrics, 147(1):186–197, November 2008. URL: https://ideas.repec.org/a/eee/econom/v147y2008i1p186-197.html, doi:.

[B13]

Petter Kolm and Gordon Ritter. On the bayesian interpretation of black-litterman. European Journal of Operational Research, 258:, 10 2016. doi:10.1016/j.ejor.2016.10.027.

[B14]

Frank Fabozzi. Robust portfolio optimization and management. John Wiley, Hoboken, N.J, 2007. ISBN 978-0-471-92122-6.