计算Access VBA中的指数移动平均线

时间:2015-12-22 15:20:01

标签: excel vba excel-vba ms-access access-vba

在Excel VBA中,我有一个工作函数来计算指数http://www.value-at-risk.net/exponentially-weighted-moving-average-ewma/后的指数加权移动平均线

我想将此功能转换为Access VBA以与Access中的某些数据一起使用。

我有以下表格的数据:

BucketDate     InterpRate
8/17/2015      5.56992228328638E-03 
8/18/2015      5.64693660341032E-03 
8/19/2015      5.72395092353427E-03 
8/20/2015      5.80096524365821E-03 
8/21/2015      5.87797956378215E-03 
8/22/2015      5.9549938839061E-03 
8/23/2015      6.03200820403004E-03 
8/24/2015      6.10902252415399E-03 
  ...              ...

76个数据点。 VBA子程序如下:

Function EWMA(InterpRate As Range, Lambda As Double, _
                 MarkDate As Date, MaturityDate As Date) As Double

    Dim vZeros() As Variant
    Dim Price1 As Double, Price2 As Double
    Dim SumWtdRtn As Double
    Dim I As Long
    Dim m As Double

    Dim LogRtn As Double, RtnSQ As Double, WT As Double, WtdRtn As Double

vZeros = InterpRate

m = Month(MaturityDate) - Month(MarkAsOfDate)

For I = 2 To UBound(vZeros, 1)

    Price1 = Exp(-vZeros(I - 1, 1) * (m / 12))

    Price2 = Exp(-vZeros(I, 1) * (m / 12))

    LogRtn = Log(Price1 / Price2)

    RtnSQ = LogRtn ^ 2

    WT = (1 - Lambda) * Lambda ^ (I - 2)

    WtdRtn = WT * RtnSQ

    SumWtdRtn = SumWtdRtn + WtdRtn

Next I

EWMA = SumWtdRtn ^ (1 / 2)

End Function

但是,我无法将InterpRate传递给用于计算指数加权移动平均值的数组。如何更改此值以计算指数移动平均线?

0 个答案:

没有答案