我正在创建一个风险奇偶过程,其中我需要使用Power方法,这是一个迭代过程,以找到系统的特征值。
目的是找出你准备投资的每项资产的权重。
为了实现这一点,我需要实现一个幂方法,所以我猜测每个资产的权重,我正在寻找是否满足当前条件:
sqr((1/(N-1))Sum((Xi*Betai - 1/N)^2) < epsilon
其中sqr为平方根N资产的数量每项资产的一个我决定的阈值
Beta可以找到
Covariance i with P / variance of P
i是资产i, p是投资组合
当我的条件不被尊重时,我重新分配我的β作为我的新体重,直到我的条件被尊重。
问题是系统不是收敛而是爆炸。我认为我非常尊重Denis B Chaves Jason C. Hsu菲菲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
你知道为什么这个系统不是收敛而是爆炸吗?
最后,如果我初始化变量condition和tempSumBeta,我的系统收敛到0,57:
Condition = 0
seuil = 0.57
While Condition < seuil
tempSumBeta = 0
Condition = 0