Public
Edited
Mar 25, 2023
Paused
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
noiseFunction = d3.randomNormal(0, Math.sqrt(dt))
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
simulatedTrajectories = {
// Initialise an array of trajectories
const data = []
// For each trajectory…
for( let r = 0; r < numberOfTrajectories; r++){
// Determine the starting point of the run in the data array so each run is added consecutively in the array.
const startingArrayPos = r * steps
// Initialise the start of each run with the initialValue and reset the timeStep to 0
data[startingArrayPos] = {timeStep: 0, value: initialValue, run: r, time: 0}
// Step through each timeStep
for(let t = 1; t < steps; t++){
// Determine the previous value
const previousValue = data[startingArrayPos+t-1]['value']
// Calculate the new value, by applying the formula above.
//const newValue = previousValue * Math.exp((mu * dt) + (sigma * noiseFunction()))
const newValue = previousValue * Math.exp(((mu - (sigma ** 2)/2) * dt) + (sigma * noiseFunction()))
data[startingArrayPos+t] = {timeStep: t, value: newValue, run: r, time: dt * t}
}
}
return data
}

Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more