0% found this document useful (0 votes)
46 views3 pages

' ' Handle Entire Column Reference '

The document describes a function that calculates a moving average for a range of data in Excel. The function takes in a range and the number of data points to average over. It iterates through the range from the last row to the first, skipping empty cells. It sums the numeric values and counts the number of values. It returns the sum divided by the count if the count meets or exceeds the number of points specified.

Uploaded by

Edith Moreno
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views3 pages

' ' Handle Entire Column Reference '

The document describes a function that calculates a moving average for a range of data in Excel. The function takes in a range and the number of data points to average over. It iterates through the range from the last row to the first, skipping empty cells. It sums the numeric values and counts the number of values. It returns the sum divided by the count if the count meets or exceeds the number of points specified.

Uploaded by

Edith Moreno
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Function MovingAverage(theRange As Range, LastN As Long) As Variant

Dim vArr As Variant

Dim j As Long
Dim nFound As Long
Dim dSum As Double

On Error GoTo Fail


MovingAverage = CVErr(xlErrNA)
'
' handle entire column reference
'
vArr = Intersect(Application.Caller.Parent.UsedRange, theRange).Value2

If IsArray(vArr) And LastN > 0 Then


For j = UBound(vArr) To 1 Step -1
' skip empty/uncalculated
If Not IsEmpty(vArr(j, 1)) Then
' look for valid numbers
If IsNumeric(vArr(j, 1)) Then
If Len(Trim(CStr(vArr(j, 1)))) > 0 Then
nFound = nFound + 1
If nFound <= LastN Then
dSum = dSum + CDbl(vArr(j, 1))
Else
Exit For
End If
End If
End If
End If
Next j

If nFound >= LastN Then MovingAverage = dSum / LastN

End If
Exit Function
Fail:
MovingAverage = CVErr(xlErrNA)
End Function

http://stackoverflow.com/questions/5283466/calculate-moving-average-in-excel
Public Function SMA_EOD(Commodity, TrdDay, period As Integer)

Dim rst As DAO.Recordset


Dim sql As String
Dim ma As Double
Dim n As Integer

sql = "SELECT [COMM_SYMB], [TRD_DAY], [CLOSE] FROM fct_EOD" & _


" WHERE [fct_EOD]![COMM_SYMB] ='" & Commodity & "'" & _
" AND [fct_EOD]![TRD_DAY] <= #" & TrdDay & "#" & _
" ORDER BY [fct_EOD]![TRD_DAY];"

Set rst = CurrentDb.OpenRecordset(sql)


rst.MoveLast
For n = 0 To period - 1
If rst.BOF Then
SMA_EOD = 0
Exit Function
Else
ma = ma + rst.Fields("CLOSE")
End If
rst.MovePrevious
Next n
rst.Close
SMA_EOD = ma / period

Public Function SMA_EOD(Commodity, TrdDay, period As Integer)

Dim rst As DAO.Recordset


Dim sql As String
Dim ma As Double
Dim n As Integer

sql = "SELECT [COMM_SYMB], [TRD_DAY], [CLOSE] FROM fct_EOD" & _


" WHERE [fct_EOD]![COMM_SYMB] ='" & Commodity & "'" & _
" AND [fct_EOD]![TRD_DAY] <= #" & TrdDay & "#" & _
" ORDER BY [fct_EOD]![TRD_DAY];"

Set rst = CurrentDb.OpenRecordset(sql)


rst.MoveLast
For n = 0 To period - 1
If rst.BOF Then
SMA_EOD = 0
Exit Function
Else
ma = ma + rst.Fields("CLOSE")
End If
rst.MovePrevious
Next n
rst.Close
SMA_EOD = ma / period

End Function
http://stackoverflow.com/questions/16561444/pass-sas-macro-variables-to-vb-script-as-parameters

http://www.stat.pitt.edu/stoffer/tsa2/Rissues.htm

>#plot data
>latihan3$World_Oil_Prices <- ts(latihan3$World_Oil_Prices,start=c(1996,1),
freq=12) # data diubah menjadi bertipe time series
>ts.plot(latihan3$World_Oil_Prices,col="blue",main="Time Series Plot")
> adf.test(latihan3$World_Oil_Prices) # uji stasioneritas
> win.graph()
> par(mfrow=c(2,1))
> acf(latihan3$World_Oil_Prices,na.action=na.pass) #plot ACF/PACF
> pacf(latihan3$World_Oil_Prices,na.action=na.pass) #plot ACF/PACF
> # transformasi difference dan plot
>latihan3$World_Oil_Prices.Diff1 <- diff(latihan3$World_Oil_Prices,
differences=1)

You might also like