Monte Carlo Value at Risk (VaR) model for stock portfolios. Uses parametric simulation (geometric Brownian motion) across 10,000 paths. Reports 90%, 95%, 99% confidence VaR over a 21-day horizon.
install.packages(c("prettydoc", "knitr", "rmarkdown"))prettydoc is required to knit the HTML report. knitr and rmarkdown are required by RStudio's knit button.
- Open
var_project.Rin RStudio. - Press Ctrl+Shift+S (source with echo) — or run
source("var_project.R"). - Console prompts for share count per ticker — enter an integer and press Enter for each.
- Outputs: portfolio value (PLN), histogram of simulated P&L, VaR at 90/95/99% confidence.
- Open
VaR Markdown Report.Rmdin RStudio. - Click Knit (or press Ctrl+Shift+K).
- Share counts are hardcoded in the Rmd (
md_Num_Sharesvector) — edit that vector before knitting if needed. - Output:
VaR-Markdown-Report.htmlusing theprettydoccayman theme.
Each CSV must have at minimum:
| Column | Description |
|---|---|
Date |
Trading date |
Close |
Daily closing price |
Six Polish equities in data/ (ALE, DNP, MAK, PCO, PKO, TAR) sourced from Stooq.
- Volatility = annualized historical vol (252 trading days).
- Risk-free rate hardcoded to 5.08% (4-week T-bill, May 31 2023) — update
rfr_investinvar_project.Ras needed. - Currency: Polish złoty (zł).