-
Dec 4th, 2011, 04:45 AM
#1
Thread Starter
New Member
Don't understand what this subroutine is doing? Please Help?
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim d As Integer
Dim price(20) As Double ' Adjusted close price
Dim smm(20) As Double ' Simple moving median
For i As Integer = LBound(price) To UBound(price)
price(i) = CInt(Rnd() * 50)
Next
d = CInt(txtDay.Text)
SimpleMovingMedian(price, smm, d) ' calculate the SMM in each daily record
DisplayRecords(price, smm) ' display the array of DailyRecord in a message box
End Sub
________________________________________________________________
Public Sub SimpleMovingMedian(ByRef pri() As Double, ByRef sim() As Double, ByVal day As Integer)
' calculate the SMM for each daily record
' call MEDIAN function to calculate the median of an array
For i As Integer = LBound(pri) To UBound(pri)
sim(i) = 0
Next
For i As Integer = LBound(pri) To UBound(pri) - day + 1
sim(i) = Median(pri, i, i + day - 1)
Next
End Sub
What is the for ... next loops in the second subroutine doing? What is the sim() array meaning?
-
Dec 4th, 2011, 04:53 AM
#2
Re: Don't understand what this subroutine is doing? Please Help?
The second array, i.e. 'sim' would appear to contain the SMM for the first array, 'pri' around the value at the same index. The first loop resets each value in the array to zero and the second loop calculates the SMM around an element in the first array and places it at the same index in the second array.
-
Dec 4th, 2011, 05:03 AM
#3
Thread Starter
New Member
Re: Don't understand what this subroutine is doing? Please Help?
Thx a lot. Can I also ask why is there a - day + 1 in the second loop?
Do you know how I can write a code to sort the elements in an array using a loop?
-
Dec 4th, 2011, 08:22 AM
#4
Re: Don't understand what this subroutine is doing? Please Help?
The second and third arguments to Median specify the part of the array to use to calculate the median. I don't really understand how you can want to use this code without knowing what it's doing. Do you want to calculate the simple moving median or not, because that's what the code is doing. If you do then surely you must know what a simple moving median is and, therefore, how it's calculated. If you don't then what are you doing with this code in the first place? Also, have you actually stepped through the code and watched it in action?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|