电源方法 – 非收敛系统
我正在创build一个风险平价过程,在这里我需要使用Power方法,这是一个迭代过程来find系统的特征值。
目标是find你准备投资的资产。
为了实现我需要实现一个权力的方法,所以我猜每个资产的权重,我看是否确实满足现状:
sqr((1/(N-1))Sum((Xi*Betai - 1/N)^2) < epsilon
其中sqr是平方根N资产数量Xi每个资产的重量Betai每个资产的beta值ε是我决定的一个阈值
Beta可以被find
Covariance i with P / variance of P
我是资产我和P的投资组合
当我的状况不受尊重,我重新分配我的testing作为我的新重量,直到我的条件得到尊重。
问题是系统不会收敛而是爆炸。 我认为我完全尊重丹尼斯B查韦斯贾森C.许菲菲和奥米德Shakernia的文章:
计算风险平价投资组合权重的高效algorithm
我试图在第7页上实现algorithm2
这是我的代码:
Sub RiskParityPowerMethod() 'prendre des poids equiponderes Dim lastColumnReturn As Long Dim lastRowReturn As Long Dim tempReturnPtf As Double lastRowReturn = Cells(Rows.Count, 1).End(xlUp).Row lastColumnReturn = Cells(1, Columns.Count).End(xlToLeft).Column 'calcul du rendement du portefeuille pour les 90 premieres dates Sheets("Return").Select For k = 3 To 92 tempReturnPtf = 0 For j = 3 To lastColumnReturn tempReturnPtf = tempReturnPtf + (1 / (lastColumnReturn - 2) * Cells(k, j)) Next j Sheets("Portfolio").Cells(k, 2).Value = tempReturnPtf Cells(k, 2).Value = tempReturnPtf Next k ReDim vecteurPoids(3 To lastColumnReturn) ReDim covarIP(3 To lastColumnReturn) ReDim matrixVarCovar(92 To lastRowReturn, 3 To lastColumnReturn, 3 To lastColumnReturn) ReDim matrixVarCovarFinal(3 To lastColumnReturn, 3 To lastColumnReturn) ReDim beta(3 To lastColumnReturn) For k = 92 To lastRowReturn 'initialisation des poids For i = 3 To lastColumnReturn vecteurPoids(i) = 1 / (lastColumnReturn - 2) Next i Condition = 1 seuil = 0.05 While Condition > seuil 'calcul du return du portefeuille tempReturnPtf = 0 For i = 3 To lastColumnReturn tempReturnPtf = tempReturnPtf + vecteurPoids(i) * Sheets("Return").Cells(k, i).Value Next i Sheets("Portfolio").Cells(k, 2).Value = tempReturnPtf Cells(k, 2).Value = tempReturnPtf 'calcul de la covariance de l'actif i avec le portefeuille For i = 3 To lastColumnReturn covarIP(i) = Application.WorksheetFunction.Covar(Range(Cells(k - 90, i), Cells(k, i)), Range(Cells(k - 90, 2), Cells(k, 2))) Next i 'i is the asset i For i = 3 To lastColumnReturn 'j is the asset j For j = 3 To lastColumnReturn 'Sheets("Return").Select matrixVarCovar(k, i, j) = Application.WorksheetFunction.Covar(Range(Cells(k - 90, i), Cells(k, i)), Range(Cells(k - 90, j), Cells(k, j))) matrixVarCovarFinal(i, j) = matrixVarCovar(k, i, j) Next j Next i 'calcul de la volatilite du portefeuille tempVolPtf = 0 For i = 3 To lastColumnReturn For j = 3 To lastColumnReturn tempVolPtf = tempVolPtf + (matrixVarCovar(k, i, j)) * vecteurPoids(i) * vecteurPoids(j) Next j Next i volPtfCarre = tempVolPtf 'calcul du beta pour chaque actif For i = 3 To lastColumnReturn beta(i) = covarIP(i) / volPtfCarre Next i 'condition d'iteration For i = 3 To lastColumnReturn tempCondition = tempCondition + (vecteurPoids(i) * beta(i) - (1 / (lastColumnReturn - 2))) ^ (2) 'MsgBox tempCondition Next i tempCondition = (1 / (lastColumnReturn - 2 - 1)) * tempCondition 'MsgBox tempCondition Condition = Sqr(tempCondition) MsgBox Condition If Condition > seuil Then 'changement des poids tempSumBeta = 0 For i = 3 To lastColumnReturn tempSumBeta = tempSumBeta + (1 / beta(i)) Next i sumBeta = tempSumBeta For i = 3 To lastColumnReturn vecteurPoids(i) = (1 / beta(i)) / (1 / sumBeta) 'MsgBox vecteurPoids(i) Next i End If Wend Next k End Sub
任何想法为什么系统不会收敛,而是爆炸?
最后,如果我初始化variables条件和tempSumBeta,我的系统通过0,57收敛:
Condition = 0 seuil = 0.57 While Condition < seuil tempSumBeta = 0 Condition = 0