Home > Software engineering >  The algorithm of weighted average of the code
The algorithm of weighted average of the code

Time:10-06

Y=sma (x, n, m)
X + y=[m * (n - m) * y `]/n
Among them: x=(x1, x2, x3,... X100), n=9, m=1
According to the above formula, its calculate go wrong?
Beg people!

CodePudding user response:

 Public Function CaclSMA (ByVal Cycle As Long, dData () As Currency, SMA () As Currency) As Long 

'creation date: 2014-07-05
'the last modification: 2014-07-05

Formula:
''y=sma (x, n, m)
X + y='[m * * y (n, m)]/n

The Dim u As Long
Dim As Long I

U=UBound (dData)
ReDim Preserve SMA (u)
SMA (0)=dData (0)

For I=1 To u
SMA (I)=((1 * dData (I) + (Cycle 1) * SMA (I - 1)))/Cycle
Next I

'great wisdom this function for 0.
SMA (0)=0

End the Function


Self-reliance, share happiness!

CodePudding user response:

Didn't do the shares the experience of the software, also not familiar with this formula, is really to say, generally calculate the weighted average is calculated amount first, then remove it,

CodePudding user response:

For n=9, m=1, theoretically to from 9 to

 SMA (9)=dData (9) 

For I=9 To u
SMA (I)=((1 * dData (I) + (Cycle 1) * SMA (I - 1)))/Cycle
Next I


That is to say, the first value is calculated with previous values, rather than the dData (0)
  • Related