Follow ______ on twitter.

3.1.5 Stochastic Differential Equations

Code

Vega-Lite Chart

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "description": "Illustration of a simple SDE dXt=μXtdt+σXtdWt with μ=0.05 * Δt and σ=0.07 * √Δt.",
  "data": {
    "sequence": {
      "start": 0,
      "stop": 2,
      "step": 0.125,
      "as": "t"
    }
  },
  "transform": [
    {
      "calculate": "0.05 / 12",
      "as": "mu"
    },
    {
      "calculate": "0.07 * sqrt(0.125)",
      "as": "sigma"
    },
    {
      "calculate": "sampleNormal(0, 1)",
      "as": "randNorm"
    },
    {
      "window": [
        {
          "op": "sum",
          "field": "randNorm",
          "as": "cumulative_wiener_process"
        }
      ],
      "frame": [
        null,
        0
      ]
    },
    {
      "calculate": "datum.sigma * datum.cumulative_wiener_process",
      "as": "stochastic_component"
    },
    {
      "calculate": "(datum.mu - 0.5 * pow(datum.sigma, 2)) * datum.t",
      "as": "deterministic_component"
    },
    {
      "calculate": "0.05 * exp(datum.deterministic_component + datum.stochastic_component)",
      "as": "sde_outcome"
    },
    {
      "fold": [
        "stochastic_component",
        "deterministic_component"
      ],
      "as": [
        "component",
        "value"
      ]
    },
    {
      "window": [
        {
          "op": "min",
          "field": "sde_outcome",
          "as": "min_sde_outcome"
        },
        {
          "op": "max",
          "field": "sde_outcome",
          "as": "max_sde_outcome"
        }
      ],
      "frame": [
        null,
        null
      ]
    },
    {
      "calculate": "datum.max_sde_outcome * 1.15",
      "as": "max_y"
    },
    {
      "calculate": "datum.min_sde_outcome * 0.90",
      "as": "min_y"
    }
  ],
  "hconcat": [
    {
      "title": "Full SDE Outcome: μ=0.05 * Δt, σ=0.07 * √Δt",
      "width": 250,
      "height": 250,
      "mark": "line",
      "encoding": {
        "x": {
          "field": "t",
          "type": "quantitative",
          "title": "Time (t)"
        },
        "y": {
          "field": "sde_outcome",
          "type": "quantitative",
          "title": "SDE Outcome",
          "scale": {
            "domain": [
              {
                "expr": "0.04"
              },
              {
                "expr": "0.06"
              }
            ]
          }
        },
        "color": {
          "value": "blue"
        }
      }
    },
    {
      "title": "Components of the Stochastic Differential Equation",
      "width": 250,
      "height": 250,
      "layer": [
        {
          "mark": "line",
          "encoding": {
            "x": {
              "field": "t",
              "type": "quantitative",
              "title": "Time (t)"
            },
            "y": {
              "field": "value",
              "type": "quantitative",
              "title": "Value"
            },
            "color": {
              "field": "component",
              "type": "nominal",
              "legend": {
                "title": "Components"
              }
            }
          }
        }
      ]
    }
  ]
}