Skip to content

Python financial analytics engine featuring portfolio optimization, risk modeling, Monte Carlo simulation, and automated testing.

Notifications You must be signed in to change notification settings

IanGregoire/python-financial-project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📊 Python Financial Project – Portfolio & Risk Toolkit

A production‑style Python financial analytics project that demonstrates market data ingestion, return calculations, risk modeling, portfolio optimization, Monte Carlo simulation, and automated testing.

This project is designed to be resume‑ready, interview‑ready, and extensible for real‑world financial engineering, risk, and data analyst roles.


🚀 Project Overview

The goal of this project is to replicate a mini financial analytics engine similar to what you’d find in professional trading, risk, or portfolio management systems.

It covers the full pipeline:

  1. Market data ingestion (Yahoo Finance)
  2. Data cleaning and validation
  3. Return & volatility calculations
  4. Risk metrics (VaR / CVaR)
  5. Portfolio optimization (minimum variance)
  6. Monte Carlo simulations
  7. Automated unit testing

🧠 Key Concepts Demonstrated

  • Pricing vs valuation
  • Market risk & volatility
  • Portfolio diversification
  • Risk metrics (tail risk)
  • Optimization under constraints
  • Statistical simulation
  • Testing & validation discipline

🗂️ Project Structure

financial-project/
│
├── data/                     # Optional local data storage
│   ├── raw/
│   └── processed/
│
├── src/                      # Core application logic
│   ├── __init__.py
│   ├── data_loader.py        # Market data ingestion
│   ├── returns.py            # Return & volatility calculations
│   ├── risk.py               # VaR / CVaR metrics
│   ├── portfolio.py          # Portfolio optimization
│   ├── simulation.py         # Monte Carlo engine
│   └── utils.py              # Validation & performance metrics
│
├── tests/                    # Automated unit tests
│   ├── test_returns.py
│   ├── test_risk.py
│   └── test_portfolio.py
│
├── notebooks/                # Exploratory analysis (optional)
│   └── analysis.ipynb
│
├── main.py                   # Application entry point
├── requirements.txt
└── README.md

📦 Installation

1️⃣ Clone the repository

git clone https://github.com/your-username/python-financial-project.git
cd python-financial-project

2️⃣ Create a virtual environment (recommended)

python -m venv venv
source venv/bin/activate   # macOS / Linux
venv\Scripts\activate      # Windows

3️⃣ Install dependencies

pip install -r requirements.txt

📚 Dependencies

  • Python 3.9+
  • numpy
  • pandas
  • scipy
  • matplotlib
  • yfinance
  • pytest

▶️ Running the Project

The main driver script is main.py.

From the project root:

python main.py

Output includes:

  • Sample price data
  • Annualized volatility
  • Value at Risk (VaR)
  • Conditional VaR (CVaR)
  • Minimum‑variance portfolio weights
  • Sharpe ratio
  • Monte Carlo simulation plot

📈 Example Output

Annualized Volatility:
AAPL     0.29
MSFT     0.27
GOOGL    0.31

Min Variance Portfolio Weights:
AAPL: 34.12%
MSFT: 41.87%
GOOGL: 24.01%

Portfolio Sharpe Ratio: 1.12

A Monte Carlo chart of simulated portfolio paths will also be displayed.


🧪 Running Tests

This project includes unit tests to validate financial logic.

Run all tests:

pytest

Tests cover:

  • Return calculations
  • Volatility sanity checks
  • Portfolio optimization constraints
  • Risk metric behavior

🧩 Core Modules Explained

data_loader.py

  • Downloads market data using Yahoo Finance
  • Uses auto_adjust=True for stable adjusted prices
  • Normalizes output for single or multiple tickers

returns.py

  • Log return calculations
  • Annualized volatility

risk.py

  • Value at Risk (VaR)
  • Conditional Value at Risk (CVaR)

portfolio.py

  • Mean‑variance optimization
  • Long‑only constraints
  • Fully invested portfolio

simulation.py

  • Monte Carlo price path simulation
  • Configurable horizon and number of simulations

utils.py

  • Data validation
  • Sharpe ratio calculation

🔬 Financial Assumptions

  • Trading days per year: 252
  • Returns assumed to be normally distributed (Monte Carlo)
  • Long‑only portfolios (no short selling)
  • Zero risk‑free rate by default

These assumptions can be easily modified.


💡 Extensions & Future Work

This project is intentionally designed to be extensible. Possible next steps:

  • CAPM & beta estimation
  • Fama‑French factor models
  • Efficient frontier visualization
  • Backtesting engine
  • Transaction costs & slippage
  • SQL database integration
  • REST API with FastAPI
  • Interactive dashboard with Streamlit

🏁 Why This Project Matters

This project demonstrates:

  • Strong Python fundamentals
  • Financial theory translated into code
  • Clean, testable architecture
  • Risk‑aware thinking
  • Production‑style engineering habits

It is well‑suited for:

  • Financial Engineer roles
  • Quantitative Analyst roles
  • Risk & Market Data teams
  • Data Analyst positions in finance

📬 Contact

Feel free to reach out or fork the project to build your own extensions.

Happy modeling 📈

About

Python financial analytics engine featuring portfolio optimization, risk modeling, Monte Carlo simulation, and automated testing.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published