'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.これは、この問題の別の改善されたコードです。リターンはまだ#NAMEです。 @Cominternからの回答に感謝します。 @ Cominternのアドバイスによると、コードを改訂しました。ネーム・マネージャーでは、「Yr」は年の列(H3:H3696)、「M」は月の列(I3:I3696)、「C_10」は中国の10年の元のデータ財務省債券。Excel VBAで月間ボラティリティを計算する方法列時系列シリーズ
今、私は利回りの毎月のボラティリティを求めています。
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
あなたの質問は正確ですか?あなたは#Nameに解決する理由を尋ねていますか? –
はい、コードの問題を知りたいのですが。私は、債券利回りデータの年を示すために「年」を使用し、債券利回りデータの月を参照するために「月」を使用しました。「C_10」は、債券利回りの元のデータです。 –