我正在创建一个风险平价过程,我需要使用 Power 方法,它是一个查找系统特征值的迭代过程。
目的是确定您准备投资的每种资产的权重。
为了实现我需要实现一个幂方法,所以我猜测每个资产的权重,我正在查看是否满足当前条件:
sqr((1/(N-1))Sum((Xi*Betai - 1/N)^2) < epsilon
其中 sqr 是平方根 N 资产数量 Xi 每个资产的权重 Betai 每个资产的 beta epsilon 我决定的阈值
Beta可以找到
Covariance i with P / variance of P
i 是资产 i,P 是投资组合
当我的条件没有得到遵守时,我会重新分配我的 beta 作为我的新体重,直到我的条件得到遵守。
问题是系统不收敛而是爆炸。我认为我完全尊重 Denis B Chaves Jason C. Hsu Feifei Li 和 Omid Shakernia 的文章:
我试图在第 7 页实现算法 2
这是我的代码:
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
知道为什么系统不收敛而是爆炸吗?