# Normal Distribution Function • ### Question

• Unable to find a normal distribution function for VB8

Found the others I needed ...   Math.Log,  Math.Sqrt, Math.Exp but no Math.ND

To give an example of the problem that the code needs to do.

P = S*NORMSDIST(D1)-K*e(-Rf*T)*NORMSDIST(D2)

Friday, December 25, 2009 8:17 AM

• Public Function NormDist(ByVal x As Double) As Double

Dim t As Double
Const b1 = 0.31938153
Const b2 = -0.356563782
Const b3 = 1.781477937
Const b4 = -1.821255978
Const b5 = 1.330274429
Const p = 0.2316419
Const c = 0.39894228

If x >=0 Then
t = 1.0# / (1.0# + p * x)
NormDist = (1.0# - c * Math.Exp(-x * x / 2.0#) * t * (t * (t * (t *  (t * b5 +b4) + b3) + b2) + b1))
Else
t = 1.0# / (1.0# - p * x)
NormDist = (c * Math.Exp(-x * x / 2.0#) * t * (t * (t * (t *  (t * b5 +b4) + b3) + b2) + b1))
End If
End Function

'All one needs to do then Is

ValueNeeded = NormDist(Value)

• Marked as answer by Tuesday, January 5, 2010 5:16 AM
Tuesday, January 5, 2010 5:15 AM

### All replies

• • Proposed as answer by Saturday, December 26, 2009 10:21 AM
• Marked as answer by Thursday, December 31, 2009 4:43 AM
• Unmarked as answer by Tuesday, January 5, 2010 5:16 AM
Friday, December 25, 2009 11:43 AM
• Hello sunspot9393,

You may want to try the below freeware libraries :
http://www.codeplex.com/dnAnalytics
http://numerics.mathdotnet.com/

Cheers
Waleed El-Badry ,Teaching Assistant, Faculty of Engineering , Misr University for Science & Technology
• Proposed as answer by Saturday, December 26, 2009 10:21 AM
• Marked as answer by Thursday, December 31, 2009 4:43 AM
• Unmarked as answer by Tuesday, January 5, 2010 5:15 AM
Friday, December 25, 2009 11:58 PM
• Public Function NormDist(ByVal x As Double) As Double

Dim t As Double
Const b1 = 0.31938153
Const b2 = -0.356563782
Const b3 = 1.781477937
Const b4 = -1.821255978
Const b5 = 1.330274429
Const p = 0.2316419
Const c = 0.39894228

If x >=0 Then
t = 1.0# / (1.0# + p * x)
NormDist = (1.0# - c * Math.Exp(-x * x / 2.0#) * t * (t * (t * (t *  (t * b5 +b4) + b3) + b2) + b1))
Else
t = 1.0# / (1.0# - p * x)
NormDist = (c * Math.Exp(-x * x / 2.0#) * t * (t * (t * (t *  (t * b5 +b4) + b3) + b2) + b1))
End If
End Function

'All one needs to do then Is

ValueNeeded = NormDist(Value)

• Marked as answer by Tuesday, January 5, 2010 5:16 AM
Tuesday, January 5, 2010 5:15 AM
• Calculation of "cumulative Distribution Function" and "Normal Distribution Function" in vb.net:
```Imports System.Math
Module Module1
Sub Main()
Dim cumulative_distribution, Normal_distribution As Double
'CDF(x, mean, standard_dev,True/False)
cumulative_distribution = CDF(42, 40, 1.5, True) 'Example,  Excel command for checking: =NORM.DIST(4,10,4,TRUE)
Console.WriteLine("cumulative distribution: {0}", cumulative_distribution)
Normal_distribution = CDF(42, 40, 1.5, False) 'Example,  Excel command for checking: =NORM.DIST(4,10,4,FALSE)
Console.WriteLine("Normal distribution: {0}", Normal_distribution)
End Sub
Private Function CDF(ByVal x As Double, ByVal mean As Double, ByVal standard_dev As Double, ByVal cumulative As Boolean)
Dim result, b, a, n, k, sigma As Double
a = 0
b = x
n = 100
sigma = 0
For k = 1 To n - 1
sigma = sigma + f_func(a + k * (b - a) / n, mean, standard_dev)
Next
result = ((b - a) / n) * ((f_func(a, mean, standard_dev) / 2) + sigma + (f_func(b, mean, standard_dev) / 2))
If cumulative = False Then
Return (f_func(x, mean, standard_dev))
Else
Return (result)
End If
End Function
Private Function f_func(ByVal u As Double, ByVal mean As Double, ByVal standard_dev As Double)
Return ((1 / (standard_dev * Sqrt(2 * PI))) * Exp(-((u - mean) ^ 2) / (2 * (standard_dev ^ 2))))
End Function
End Module
```

• Proposed as answer by Tuesday, September 10, 2019 9:44 PM
• Unproposed as answer by Tuesday, September 10, 2019 9:46 PM
• Proposed as answer by Tuesday, September 10, 2019 9:46 PM
Tuesday, September 10, 2019 9:43 PM
• Hi

I wonder if the OP has remained a user of this forum after 8 years?

Regards Les, Livingston, Scotland

Tuesday, September 10, 2019 10:12 PM