How to compute Value-at-Risk (VaR) of a Stock Portfolio using Python

Опубликовано: 11 Июль 2026
на канале: JustWriteTheCode
1,503
52

In this video we'll see how to compute the Value-at-Risk (VaR) of a stock portfolio using Python.

From Wikipedia: Value at risk (VaR) is a measure of the risk of loss for investments. It estimates how much a set of investments might lose (with a given probability), given normal market conditions, in a set time period such as a day.

In particular, we will consider a simple 4-stock portfolio (AAPL, META, MSFT, SPY), an initial investment of USD 1 Million and a confidence level of 5%, i.e. we compute the 95% VaR of our portfolio.

00:00 - Introduction
00:53 - Download data and calculate portfolio daily returns
04:40 - Variance-Covariance matrix
05:15 - Investment mean and standard deviation
07:48 - 1-Day VaR
10:26 - n-Days VaR
13:09 - Distribution of daily returns