Génération de nombres aléatoires
Lorsque j'utilise
randomize
unif= Rnd
La variable aléatoire renvoie des nombre pseudos aléatoires et celà toujours dans le même ordre.
Comment faire pour la lier au timer interne de l'ordi (l'équivalent de SRANDTIME=NULL du C++)
Appuyer sur le bouton CUI MC pour constater via le graf du dessous que la génération de nombres aléatoires n'est pas liée à la seed variable qui compte le nombre de secondes depuis les années 1960
Merci d'avance pour votre aide.
Cdt.
Ludovic
Salut, c'est pourtant sans paramètre que j'utiliser cette fonction, mon switch CUI à un comportement bizarre et le graph donne la même courbe à chaque click
Sub CUIPRICE()
Dim Barrierefranchise As Integer
GetData
Dim Stinit As Double
Stinit = St
Dim moyenneCUI As Double
Dim unif As Double
moyenneCUI = 0
Dim Stplusdt As Double
Dim i As Long
Dim j As Long
Dim tincr As Double
Dim RNG As Range
If t = 0 Then
tincr = 1 / 260
End If
Dim counter As Long
counter = 0
If St < L Then
For i = 1 To N
counter = counter + 1
Barrierefranchise = 0
For j = partieentiere(tincr * 260) To partieentiere((M * 260))
Randomize
unif = Rnd
z = WorksheetFunction.Norm_Inv(unif, 0, 1)
Stplusdt = St * (1 + z * sigma * WorksheetFunction.Power((M - t) / 260, 0.5) + (r - div) * ((M - t) / 260))
St = Stplusdt
If Stplusdt > L Then
Barrierefranchise = 1
End If
If counter = 1 Then
Worksheets("Feuil3").Cells(j, 1) = St
End If
Next
If counter = 1 Then
Worksheets("Feuil3").Select
Range("A1:A780").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Shapes.AddChart2(227, xlLineMarkers).Select
ActiveChart.SetSourceData Source:=Range("A1:A780")
ActiveChart.ChartTitle.Select
ActiveChart.ChartTitle.Text = "Euler Scheme Sample Graph"
Selection.Format.TextFrame2.TextRange.Characters.Text = _
"Euler Scheme Sample Graph"
With Selection.Format.TextFrame2.TextRange.Characters(1, 4).Font
.BaselineOffset = 0
.Bold = msoFalse
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(89, 89, 89)
.Fill.Transparency = 0
.Fill.Solid
.Size = 14
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Spacing = 0
.Strike = msoNoStrike
End With
With Selection.Format.TextFrame2.TextRange.Characters(5, 21).Font
.BaselineOffset = 0
.Bold = msoFalse
.NameComplexScript = "+mn-cs"
.NameFarEast = "+mn-ea"
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(89, 89, 89)
.Fill.Transparency = 0
.Fill.Solid
.Size = 14
.Italic = msoFalse
.Kerning = 12
.Name = "+mn-lt"
.UnderlineStyle = msoNoUnderline
.Spacing = 0
.Strike = msoNoStrike
End With
ActiveChart.PlotArea.Select
ActiveChart.ClearToMatchStyle
ActiveChart.ChartStyle = 233
ActiveChart.FullSeriesCollection(1).Select
ActiveChart.ChartTitle.Select
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(192, 0, 0)
.Transparency = 0
End With
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.RGB = RGB(192, 0, 0)
.Transparency = 0
End With
With Selection.Format.Line
.Visible = msoTrue
.ForeColor.ObjectThemeColor = msoThemeColorBackground1
.ForeColor.TintAndShade = 0
.ForeColor.Brightness = 0
.Transparency = 0
End With
Selection.Format.Line.Visible = msoFalse
ActiveChart.ChartArea.Select
With Selection.Format.TextFrame2.TextRange.Font.Fill
.Visible = msoTrue
.ForeColor.RGB = RGB(0, 176, 80)
.Transparency = 0
.Solid
End With
ActiveChart.Parent.Cut
Sheets("Feuil1").Select
Range("A28").Select
ActiveSheet.Paste
End If
If Barrierefranchise = 1 Then
moyenneCUI = moyenneCUI + Barrierefranchise * partiepositive(St - K)
End If
St = Stinit
Next
ElseIf St > L Then
moyenneCUI = 0
End If
Worksheets("Feuil1").Cells(17, 4) = Exp(-r * (M - t)) * moyenneCUI / N
End Sub
Sub CDIPRICE()
Dim Barrierefranchise As Integer
Dim moyenneCDI As Double
Dim Stinit As Double
moyenneCDI = 0
GetData
Stinit = St
Dim Stplusdt As Double
Dim i As Long
Dim j As Long
If St > L Then
For i = 1 To N
Barrierefranchise = 0
For j = partieentiere(t * 260) To partieentiere((M * 260))
Randomize
unif = Rnd
z = WorksheetFunction.Norm_Inv(unif, 0, 1)
Stplusdt = St * (1 + z * sigma * WorksheetFunction.Power((M - t) / 260, 0.5) + (r - div) * ((M - t) / 260))
St = Stplusdt
If Stplusdt < L Then
Barrierefranchise = 1
End If
Next
If Barrierefranchise = 1 Then
moyenneCDI = moyenneCDI + Barrierefranchise * partiepositive(St * Exp((r - div - 0.5 * WorksheetFunction.Power(sigma, 2)) * (M - t) + sigma * WorksheetFunction.Power(M - t, 0.5) * z) - K)
End If
St = Stinit
Next
ElseIf St < L Then
moyenneCDI = 0
End If
Worksheets("Feuil1").Cells(18, 4) = Exp(-r * (M - t)) * moyenneCDI / N
End Sub
Bonjour,
Avant d'utiliser RND pour ne pas avoir une suite identique il faut ajouter une ligne plus haut RANDOMIZE afin de lancer RND avec une référence différente à chaque tirage, me semble-t-il...
@ bientôt
LouReeD
Autant pour moi, c'était la maturité qui avait été modifiée et mon graphe n'est pas dynamique.
Merci pour votre aide.