Built-In Function for Variance?

R

ryguy7272

I am teaching myself VB.NET. I got this code from a book:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim dblReturns As Double() = New Double(9) {0.0203, -0.0136, 0.0012,
0.0266, -0.0063, -0.0601, 0.0307, 0.0123, 0.0055, 0.0441}
Label1.Text = Format(Average(dblReturns), "#.#####")
'Label2.Text = Format(Var(dblReturns), "#.#####")
End Sub

Public Function Average(ByRef InArray As Double()) As Double
Dim dblTotalReturn As Double
Dim x As Integer
Dim dblLength# = UBound(InArray, 1)
For x = 0 To dblLength
dblTotalReturn += InArray(x)
Next x
Return dblTotalReturn / (dblLength + 1)
End Function

The Average function works just fine, but I am wondering if there is an
easier way to do this. Also, I am trying to figure out how to calculate
Variance. Are there built-in functions for these types of calculations (and
others)? I’ve been using both Excel and Access for quite some time and these
functions are simply built into the apps. I find it hard to believe that
VB.NET would not offer the same type of courtesy to users, but after
searching online for a bit, I have come up with nothing.

Please help.


Thanks,
Ryan---
 
A

Armin Zingler

ryguy7272 said:
The Average function works just fine, but I am wondering if there is
an easier way to do this.
dblReturns.Average

Also, I am trying to figure out how to
calculate Variance.

I don't know a built-in function.


Armin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top