|
Question : Brownian Motion Charted in VBA
|
|
How can I make this vba script work ... after the user enters in the answers, VBA should generate chart using the record source of activecells and calculates a figure which plots the values in the B column against the values in the A column?
Sub Simulating_Brownian_Motion() Dim T, dt, Sqrdt, BrownianMotion, i, N T = InputBox("Enter the length of the time period (T)") N = InputBox("Enter the number of periods (N)") dt = T / N Sqrdt = Sqr(dt) Range("A1").Activate ActiveCell.Value = "Time" ActiveCell.Offset(0, 1) = "Brownian Motion" ActiveCell.Offset(1, 0) = 0 ' beginning time ActiveCell.Offset(1, 1) = 0 ' beginning value of Brownian motion BrownianMotion = 0 For i = 1 To N ActiveCell.Offset(i + 1, 0) = i * dt ' next time BrownianMotion = BrownianMotion + Sqrdt * RandN() ActiveCell.Offset(i + 1, 1) = BrownianMotion ' next value Next i End Sub
|
|
Answer : Brownian Motion Charted in VBA
|
|
Hi Rachael, You can alter the chart bit to:
With cht .ChartType = xlXYScatterLines .SetSourceData Range("A1:B" & i + 1) .Axes(xlCategory).MaximumScale = T End With
and that should do it. Regards, Rory
|
|
|
|