Skip to main content

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

Metadata

Release files for portfoliorisk 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for portfoliorisk 1.0.4
File Interpreter ABI Platform Actions
portfoliorisk-1.0.4-py3-none-any.whl Python 3 none any Details for portfoliorisk-1.0.4-py3-none-any.whl

Release files / portfoliorisk-1.0.4-py3-none-any.whl

Download URL portfoliorisk-1.0.4-py3-none-any.whl
Size 14.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ac9cea1b3dc5cac9b212ab31b6e1d6677801d5965b2c4327544818028d2c1c28
BLAKE2b-256 checksum
How to use checksums
6cb740dc121ed62d538707db6dd5e1570f541c1309a44cf2bec5e8979898a178
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Security for portfoliorisk 1.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page