Follow ______ on twitter.

3.1.3 Appplications in Risk Assessment

Code

Vega-Lite Chart

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "config": {
    "view": {
      "continuousWidth": 400,
      "continuousHeight": 300
    }
  },
  "data": {
    "sequence": {
      "start": -6,
      "stop": 6,
      "step": 0.1,
      "as": "Value"
    }
  },
  "transform": [
    {
      "calculate": "densityStudentT(datum.Value, 3)",
      "as": "Density"
    },
    {
      "calculate": "quantileStudentT(0.90, 3)",
      "as": "VaR"
    },
    {
      "calculate": "calculateCVaR(0.90, 3)",
      "as": "CVaR"
    }
  ],
  "layer": [
    {
      "mark": {
        "type": "line",
        "color": "blue"
      },
      "encoding": {
        "x": {
          "field": "Value",
          "title": "Value",
          "type": "quantitative"
        },
        "y": {
          "field": "Density",
          "title": "Density",
          "type": "quantitative"
        }
      }
    },
    {
      "transform": [
        {
          "filter": "datum.Value >= datum.VaR"
        }
      ],
      "mark": {
        "type": "area",
        "color": "red",
        "opacity": 0.3
      },
      "encoding": {
        "x": {
          "field": "Value",
          "type": "quantitative"
        },
        "y": {
          "field": "Density",
          "type": "quantitative"
        }
      }
    },
    {
      "mark": {
        "type": "rule",
        "color": "green"
      },
      "encoding": {
        "x": {
          "field": "VaR",
          "type": "quantitative"
        },
        "size": {
          "value": 2
        }
      }
    },
    {
      "mark": {
        "type": "text",
        "color": "green",
        "align": "left",
        "dx": 5
      },
      "encoding": {
        "text": {
          "value": "VaR"
        },
        "x": {
          "field": "VaR",
          "type": "quantitative"
        },
        "y": {
          "value": 0.45
        },
        "size": {
          "value": 12
        }
      }
    },
    {
      "mark": {
        "type": "rule",
        "color": "red"
      },
      "encoding": {
        "x": {
          "field": "CVaR",
          "type": "quantitative"
        },
        "size": {
          "value": 2
        }
      }
    },
    {
      "mark": {
        "type": "text",
        "color": "red",
        "align": "left",
        "dx": 5
      },
      "encoding": {
        "text": {
          "value": "CVaR"
        },
        "x": {
          "field": "CVaR",
          "type": "quantitative"
        },
        "y": {
          "value": 0.45
        },
        "size": {
          "value": 12
        }
      }
    }
  ],
  "title": "Probability Density Function (PDF) with VaR and CVaR for Student's t-Distribution"
}