功率方法 - 非会聚系统

时间:2013-05-11 16:14:41

标签: excel vba math iteration linear-algebra

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

目标是找到您准备投资的eaach资产的权重。

为了意识到我需要实现一种功率方法,所以我猜每种资产的重量,我看是否满足当前条件:

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

其中sqr是平方根 N资产数量 Xi每个资产的重量 Betai每个资产的测试版 epsilon是我决定的门槛

Beta可以找到

Covariance i with P / variance of P

我是资产i和P投资组合

当我的病情没有得到尊重时,我将我的测试重新分配为我的新体重,直到我的病情得到尊重。

问题是系统不会收敛但会爆炸。我认为我完全尊重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

任何想法为什么系统不会收敛而是爆炸?

1 个答案:

答案 0 :(得分:1)

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

    Condition = 0
    seuil = 0.57

While Condition < seuil

     tempSumBeta = 0
     Condition = 0