gpt4 book ai didi

excel - 幂法 - 非收敛系统

转载 作者:行者123 更新时间:2023-12-04 20:46:05 24 4
gpt4 key购买 nike

我正在创建一个风险平价过程,我需要使用 Power 方法,它是一个迭代过程来查找系统的特征值。

目的是确定您准备投资的每种 Assets 的权重。

为了实现我需要实现一个幂方法,所以我猜测每个 Assets 的权重,我正在查看是否满足当前条件:

sqr((1/(N-1))Sum((Xi*Betai - 1/N)^2) < epsilon

其中 sqr 是平方根
N Assets 数量
Xi 每项 Assets 的权重
Beta 每个 Assets 的 beta
epsilon 一个我决定的阈值

Beta可以找到
Covariance i with P / variance of P

i 是 Assets i,P 是投资组合

当我的条件没有得到遵守时,我会重新分配我的 beta 作为我的新体重,直到我的条件得到遵守。

问题是系统不收敛而是爆炸。我认为我完全尊重 Denis B Chaves Jason C. Hsu Feifei Li 和 Omid Shakernia 的文章:

Efficient Algorithms for Computing Risk Parity Portfolio Weights

我试图在第 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

知道为什么系统不收敛而是爆炸吗?

最佳答案

最后,如果我初始化变量条件和 tempSumBeta,我的系统会通过 0,57 收敛:

    Condition = 0
seuil = 0.57

While Condition < seuil

tempSumBeta = 0
Condition = 0

关于excel - 幂法 - 非收敛系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16499206/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com