'H' Column is the year data column, 'I' Column is the month data column, 'D' Column is the 10-year bond yield we want to calculate the monthly volatility. Dies ist ein weiterer verbesserter Code für diese Frage, bitte helfen Sie mir. Die Rückkehr ist immer noch #NAME. Danke der Antwort von @Comintern. Laut dem Rat von @Comintern habe ich den Code überarbeitet. Im Namensmanager bezieht sich "Yr" auf die Spalte des Jahres (H3: H3696), "M" bezieht sich auf die Spalte des Monats (I3: I3696), "C_10" bezieht sich auf die ursprünglichen Ertragsdaten von China 10 Year Schatzobligation.So berechnen Sie die monatliche Volatilität in Excel VBA unter Spalte Zeitreihe
Gerade jetzt möchte ich die monatliche Volatilität der Rendite erhalten.
Function Volatility(n As Variant) As Variant
'this function uses to calculate volatility of a bond yield
'"n" is the number of data/date we need to calculate
'please manage the data name in the name manager of formulas
Dim i As Integer, dnum As Integer, mnum As Integer, vectornum As Integer
'dnum count day number, mnum count month number
Dim Result(), TempSave() As Variant
Dim Yr, M As Range
vectornum = Int(n/20) + 1
ReDim Result(vectornum) As Variant
Yr = ActiveWorkbook.Names("Yr").Value
M = ActiveWorkbook.Names("M").Value
Bond = ActiveWorkbook.Names("C_10").Value
For i = 1 To n
If Yr(i) = Yr(i + 1) And M(i) = M(i + 1) Then
dnum = dnum + 1
ReDim Preserve TempSave(1 To dnum)
TempSave(dnum) = Bond(i)
'this is the temporary data container for the same month bond yield
Else
TempSave(dnum + 1) = Bond(i)
'because there is a gap between two month, so, we add the last 'same month bond yield' back
dnum = 0
mnum = mnum + 1
Result(mnum) = Application.WorksheetFunction.StDev_S(TempSave)
End If
Next i
Volatility = Result
End Function
Was ist Ihre Frage genau? Fragen Sie, warum es in #Name aufgelöst wird? –
Ja, ich möchte das Problem in den Codes kennen. Ich habe das "Jahr" verwendet, um das Jahr der Anleiherenditen zu referenzieren, und "Monat", um den Monat der Anleiherenditen zu referenzieren, "C_10" sind die ursprünglichen Daten der Anleiherenditen. –