Follow ______ on twitter.

2.1.2 Tools for Assessing Market Risks

Code

Vega-Lite Chart

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.17.0.json",
  "config": {
    "view": {
      "continuousWidth": 300,
      "continuousHeight": 300
    }
  },
  "data": {
    "sequence": {
      "start": 0,
      "stop": 4,
      "step": 0.1,
      "as": "Loss"
    }
  },
  "transform": [
    {
      "calculate": "densityLogNormal(datum.Loss, 0, 0.5)",
      "as": "Density"
    }
  ],
  "layer": [
    {
      "mark": {
        "type": "line",
        "color": "blue"
      },
      "encoding": {
        "x": {
          "field": "Loss",
          "title": "Loss",
          "type": "quantitative"
        },
        "y": {
          "field": "Density",
          "title": "Density",
          "type": "quantitative"
        }
      }
    },
    {
      "transform": [
        {
          "filter": "datum.Loss >= 2.2857142857142856 && datum.Loss <= 4"
        }
      ],
      "mark": {
        "type": "area",
        "color": "red",
        "opacity": 0.3
      },
      "encoding": {
        "x": {
          "field": "Loss",
          "type": "quantitative"
        },
        "y": {
          "field": "Density",
          "type": "quantitative"
        }
      }
    },
    {
      "data": {
        "values": [
          {
            "Loss": 1.1331484530668263
          }
        ]
      },
      "mark": {
        "type": "rule",
        "color": "green"
      },
      "encoding": {
        "x": {
          "field": "Loss",
          "type": "quantitative"
        }
      }
    },
    {
      "data": {
        "values": [
          {
            "Loss": 2.276016608514317
          }
        ]
      },
      "mark": {
        "type": "rule",
        "color": "red",
        "strokeDash": [
          3,
          3
        ]
      },
      "encoding": {
        "x": {
          "field": "Loss",
          "type": "quantitative"
        }
      }
    },
    {
      "data": {
        "values": [
          {
            "Loss": 2.8585912953125416
          }
        ]
      },
      "mark": {
        "type": "rule",
        "color": "red"
      },
      "encoding": {
        "x": {
          "field": "Loss",
          "type": "quantitative"
        }
      }
    },
    {
      "data": {
        "values": [
          {
            "x": 1.1331484530668263,
            "y": 0.2
          },
          {
            "x": 2.276016608514317,
            "y": 0.2
          }
        ]
      },
      "mark": {
        "type": "line",
        "color": "blue",
        "strokeWidth": 2
      },
      "encoding": {
        "x": {
          "field": "x",
          "type": "quantitative"
        },
        "y": {
          "field": "y",
          "type": "quantitative"
        }
      }
    },
    {
      "data": {
        "values": [
          {
            "x": 1.1331484530668263,
            "y": 0.3
          },
          {
            "x": 2.8585912953125416,
            "y": 0.3
          }
        ]
      },
      "mark": {
        "type": "line",
        "color": "blue",
        "strokeWidth": 2
      },
      "encoding": {
        "x": {
          "field": "x",
          "type": "quantitative"
        },
        "y": {
          "field": "y",
          "type": "quantitative"
        }
      }
    },
    {
      "data": {
        "values": [
          {
            "x": 1.1331484530668263,
            "y": 0.2,
            "angle": 180
          },
          {
            "x": 2.276016608514317,
            "y": 0.2,
            "angle": 0
          },
          {
            "x": 1.1331484530668263,
            "y": 0.3,
            "angle": 180
          },
          {
            "x": 2.8585912953125416,
            "y": 0.3,
            "angle": 0
          }
        ]
      },
      "mark": {
        "type": "point",
        "color": "blue",
        "shape": "triangle",
        "size": 100
      },
      "encoding": {
        "angle": {
          "field": "angle",
          "type": "quantitative"
        },
        "x": {
          "field": "x",
          "type": "quantitative"
        },
        "y": {
          "field": "y",
          "type": "quantitative"
        }
      }
    },
    {
      "data": {
        "values": [
          {
            "Loss": 1.4822456789483234,
            "Density": 0.22,
            "label": "VaR = 1.14"
          },
          {
            "Loss": 1.735539021034508,
            "Density": 0.32,
            "label": "CVaR = 1.73"
          }
        ]
      },
      "mark": {
        "type": "text",
        "align": "left",
        "angle": 0,
        "baseline": "middle",
        "color": "blue",
        "dx": 5,
        "dy": 0
      },
      "encoding": {
        "text": {
          "field": "label",
          "type": "nominal"
        },
        "x": {
          "field": "Loss",
          "type": "quantitative"
        },
        "y": {
          "field": "Density",
          "type": "quantitative"
        }
      }
    },
    {
      "data": {
        "values": [
          {
            "Loss": 1.1331484530668263,
            "Density": 0.72,
            "label": "Mean = 1.13"
          },
          {
            "Loss": 2.276016608514317,
            "Density": 0.78,
            "label": "CL@95% = 2.28"
          },
          {
            "Loss": 2.8585912953125416,
            "Density": 0.84,
            "label": "CCL@95% = 2.86"
          }
        ]
      },
      "mark": {
        "type": "text",
        "align": "left",
        "angle": 0,
        "baseline": "middle",
        "color": "black",
        "dx": 5,
        "dy": 0
      },
      "encoding": {
        "text": {
          "field": "label",
          "type": "nominal"
        },
        "x": {
          "field": "Loss",
          "type": "quantitative"
        },
        "y": {
          "field": "Density",
          "type": "quantitative"
        }
      }
    }
  ],
  "title": "Probability Density Function (PDF) of Lognormal Distribution (μ=0, σ=0.5)"
}