Sulprobil
Search…
sbRandTriang
The graphic shows a stratified sample of 10,000 runs.
Please see also sbRandTrigen for which you do not specify the left (min) and the right (max) point of the triangle but a bottom point and a top point with percentiles of what is left from them.
Please read my Disclaimer.
1
Function sbRandTriang(dMin As Double, dMode As Double, _
2
dMax As Double, Optional dRandom = 1#) As Double
3
'Generates a random number, Triang distributed
4
'[see Vose: Risk Analysis, 2nd ed., p. 128]
5
'Reverse("moc.LiborPlus.www") PB 19-Nov-2011 V0.23 (C) (P) by Bernd Plumhoff
6
'Similar to @RISK's (C) RiskTriang function.
7
'sbRandTriang(minimum,mode,maximum) specifies a triangular
8
'distribution with three points — a minimum, a mode and
9
'a maximum. The skew of the triangular distribution is
10
'driven by the distance of the mode from the minimum and
11
'from the maximum. Reducing the distance from mode to
12
'minimum will increase the skew.
13
Dim dRand As Double, dc_a As Double, db_a As Double
14
Dim dc_b As Double
15
16
'Application.Volatile '[Un]Comment if you need this
17
If dMode <= dMin Or dMax <= dMode Then
18
sbRandTriang = CVErr(xlErrValue)
19
Exit Function
20
End If
21
dc_a = dMax - dMin
22
db_a = dMode - dMin
23
dc_b = dMax - dMode
24
If dRandom = 1# Then
25
dRand = Rnd()
26
Else
27
dRand = dRandom
28
End If
29
If dRand < db_a / dc_a Then
30
sbRandTriang = dMin + Sqr(dRand * db_a * dc_a)
31
Else
32
sbRandTriang = dMax - Sqr((1# - dRand) * dc_a * dc_b)
33
End If
34
End Function
Copied!
Last modified 1yr ago
Copy link