Skip to content

This repository contains a Python script that performs portfolio risk analysis on selected assets using Value at Risk (VaR) and Expected Shortfall (ES) measures. The script uses Numba to optimize the risk calculations, downloads historical data from Yahoo Finance with yfinance, and visualizes the portfolio's return distribution

License

Notifications You must be signed in to change notification settings

JGekko99/Portfolio-Risk-Analysis-with-VaR-and-ES-using-Numba

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Portfolio Risk Analysis with VaR and ES using Numba

This repository contains a Python script that performs portfolio risk analysis on selected assets using Value at Risk (VaR) and Expected Shortfall (ES) measures. The script uses Numba to optimize the risk calculations, downloads historical data from Yahoo Finance with yfinance, and visualizes the portfolio's return distribution.

Features

  • Data Acquisition: Downloads historical stock data for specified assets.
  • Data Cleaning: Handles missing data by dropping incomplete rows.
  • Risk Metrics: Calculates portfolio Value at Risk (VaR) and Expected Shortfall (ES) using a Numba-optimized function.
  • Visualization: Plots a histogram of daily portfolio returns with a marked VaR threshold.
  • Interactivity: Provides verbose output and interactive prompts to follow each step of the analysis.

Requirements

Installation

  1. Clone the repository:

    git clone https://github.com/yourusername/your-repo-name.git
    cd your-repo-name
  2. Create a virtual environment (optional but recommended):

    python -m venv venv
    

Activate the virtual environment:

  1. Install the required packages: You can install packages from the requirements.txt file:
    pip install -r requirements.txt
    

Usage

Run the script using Python:

python var.py

  1. The script will walk you through several steps:
  2. Configuration of assets, weights, and time period.
  3. Downloading and cleaning historical data.
  4. Calculating daily returns and portfolio returns.
  5. Computing VaR and Expected Shortfall.
  6. Visualizing the return distribution.

Follow the on-screen prompts (press Enter to continue) to observe the progress at each step.

Contributing

Contributions are welcome! If you have suggestions or improvements, please open an issue or submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

This repository contains a Python script that performs portfolio risk analysis on selected assets using Value at Risk (VaR) and Expected Shortfall (ES) measures. The script uses Numba to optimize the risk calculations, downloads historical data from Yahoo Finance with yfinance, and visualizes the portfolio's return distribution

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages