https://github.com/jgekko99/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
https://github.com/jgekko99/portfolio-risk-analysis-with-var-and-es-using-numba
asset-management numba numba-jit-compiler perfomance-python risk-management
Last synced: 3 months ago
JSON representation
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
- Host: GitHub
- URL: https://github.com/jgekko99/portfolio-risk-analysis-with-var-and-es-using-numba
- Owner: JGekko99
- License: mit
- Created: 2025-03-02T16:26:55.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2025-03-02T16:34:20.000Z (3 months ago)
- Last Synced: 2025-03-02T17:31:13.224Z (3 months ago)
- Topics: asset-management, numba, numba-jit-compiler, perfomance-python, risk-management
- Language: Python
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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
- Python 3.x
- [NumPy](https://numpy.org/)
- [Pandas](https://pandas.pydata.org/)
- [Matplotlib](https://matplotlib.org/)
- [yfinance](https://github.com/ranaroussi/yfinance)
- [Numba](http://numba.pydata.org/)## Installation
1. **Clone the repository:**
```bash
git clone https://github.com/yourusername/your-repo-name.git
cd your-repo-name
2. **Create a virtual environment (optional but recommended):**```bash
python -m venv venvActivate the virtual environment:
3. **Install the required packages:**
You can install packages from the requirements.txt file:
```bash
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.