Skip to main content

One-command quantitative portfolio risk analysis: optimisation, Monte Carlo, VaR, CVaR, GARCH, stress testing.

Project description

portfoliorisk

One-command quantitative portfolio risk analysis for everyone.

Created by Yash


Install

pip install portfoliorisk

Usage

Just give it your stocks and your investment amount:

import portfoliorisk as pr

pr.run(["AAPL", "JPM", "XOM", "GLD"], investment=10000)

That's it. A full risk report prints instantly in your terminal.


What You Get

═══════════════════════════════════════════════════════════════════════
  PORTFOLIORISK · FULL RISK ANALYSIS REPORT
═══════════════════════════════════════════════════════════════════════

  1 · PORTFOLIO COMPOSITION  (Max Sharpe Ratio Optimisation)
  2 · OPTIMISATION PERFORMANCE
  3 · MONTE CARLO SIMULATION  (10,000 paths · 252 trading days)
  4 · HISTORICAL MAXIMUM DRAWDOWN
  5 · GARCH(1,1) VOLATILITY MODEL
  6 · STRESS TEST RESULTS
  ── EXECUTIVE SUMMARY ──

What It Analyses

Analysis Description
Portfolio Optimisation Finds the best allocation across your stocks using the Efficient Frontier (Maximum Sharpe Ratio)
Monte Carlo Simulation Runs 10,000 simulated future scenarios over 1 year
Value at Risk (VaR) Maximum expected loss at 95% confidence
Conditional VaR (CVaR) Average loss in the worst 5% of scenarios
Fat-Tail Simulation Realistic crash modelling using Student-t distribution
GARCH(1,1) Model Measures how volatile your portfolio is right now + 7-day forecast
Max Drawdown Largest historical peak-to-trough loss
Stress Testing Impact of 2008 crisis, tech crash, rate hike on your portfolio

Examples

import portfoliorisk as pr

# Tech-heavy portfolio
pr.run(["AAPL", "MSFT", "GOOGL", "NVDA"], investment=25000)

# Balanced portfolio
pr.run(["SPY", "BND", "GLD", "QQQ"], investment=50000)

# Indian ADRs + US stocks
pr.run(["INFY", "WIT", "AAPL", "JPM"], investment=15000)

# Small portfolio
pr.run(["TSLA", "AMZN"], investment=5000)

Access the Results in Code

pr.run() also returns a dict so you can use the numbers yourself:

results = pr.run(["AAPL", "JPM", "XOM", "GLD"], investment=10000)

print(results["weights"])           # {'AAPL': 0.088, 'GLD': 0.608, ...}
print(results["sharpe_ratio"])      # 1.62
print(results["var_fattail"])       # 1661.02  ← realistic downside risk
print(results["max_drawdown"])      # -0.1623  ← worst historical dip
print(results["garch"]["beta"])     # 0.8822   ← volatility persistence

Requirements

  • Python 3.8+
  • Internet connection (to download stock data)

All dependencies install automatically with pip install portfoliorisk.


How It Works

Your tickers + investment amount
         ↓
  [1] Download 5 years of price data  (yfinance)
  [2] Compute optimal weights          (PyPortfolioOpt)
  [3] Run 10,000 Monte Carlo paths     (NumPy)
  [4] Calculate VaR & CVaR             (Normal + Fat-Tail)
  [5] Fit GARCH(1,1) volatility model  (arch)
  [6] Run stress test scenarios
  [7] Print full report to terminal

License

MIT © 2026 Yash

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

portfoliorisk-1.0.0.tar.gz (12.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

portfoliorisk-1.0.0-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file portfoliorisk-1.0.0.tar.gz.

File metadata

  • Download URL: portfoliorisk-1.0.0.tar.gz
  • Upload date:
  • Size: 12.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for portfoliorisk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 91637593b85d1d9a766024587339481d176f6c1a7d1b1a3d7c11aa843618d81c
MD5 9890a6a8ffa3994cf65b15fcdb01ac76
BLAKE2b-256 215e71a25c984fd9337afe671225ca50a82f669aeb619a23f40584f494d30af6

See more details on using hashes here.

File details

Details for the file portfoliorisk-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: portfoliorisk-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for portfoliorisk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 711579f6f5ed4f7bbc8f92078587010cd3465c5e8c666a1ca0fea22bbd68a060
MD5 b8bafc169c65d0b31ec9b0f4822f51b3
BLAKE2b-256 db95bad3610f2fac9437f10a4dd1d719470dfe4f0c1543f1e4c4fce3bead3df6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page