Skip to content

debu2211/Markowitz-Portfolio

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Markowitz Portfolio Management

This project explores equity portfolio construction with Modern Portfolio Theory. It ranks NIFTY 50 stocks by risk-adjusted performance, selects the strongest candidates, simulates thousands of portfolio allocations, plots the efficient frontier, and compares the optimized portfolio against the NIFTY 50 benchmark.

What The Notebook Does

  • Loads historical NIFTY 50 closing-price data.
  • Cleans missing values and removes unavailable tickers.
  • Calculates CAGR, annualized volatility, and Sharpe ratio for each stock.
  • Selects the top 15 stocks by Sharpe ratio.
  • Simulates random portfolio weights to estimate return, volatility, and Sharpe ratio.
  • Uses constrained optimization to trace the efficient frontier.
  • Calculates the number of shares for an example investment amount.
  • Backtests the selected portfolio against the NIFTY 50 benchmark.
  • Reports portfolio metrics including return, volatility, beta, alpha, Sharpe ratio, Treynor ratio, drawdown, and downside-risk measures.

Repository Structure

.
├── markovitz.ipynb      # Main analysis notebook
├── requirements.txt     # Python dependencies
├── data/
│   └── README.md        # Dataset expectations
└── README.md

Setup

Create a virtual environment and install the required packages:

python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txt

If you are running the notebook in Google Colab, install the packages from requirements.txt in a setup cell before running the analysis.

Data

The original notebook expects a CSV file named nifty50 (1).csv with a Date column and one price column per ticker. The dataset is not committed to this repository, so place your CSV in the project root before running the notebook.

Expected shape:

Date,RELIANCE.NS,TCS.NS,INFY.NS,...
2020-01-01,1495.42,2167.30,731.20,...

The later backtest section also downloads recent prices through Yahoo Finance using yfinance and pandas-datareader.

Methodology

The notebook follows a classic mean-variance workflow:

  1. Estimate each stock's historical return with CAGR.
  2. Estimate annualized risk from daily percentage returns.
  3. Rank stocks with the Sharpe ratio, using a risk-free rate assumption.
  4. Generate random long-only portfolios and identify the highest Sharpe allocation.
  5. Solve constrained optimization problems for target returns to approximate the efficient frontier.
  6. Compare the optimized portfolio with the market benchmark over a later period.

Current Limitations

  • The analysis depends on a local CSV that must be supplied separately.
  • The notebook contains hardcoded dates, tickers, and risk-free-rate assumptions.
  • The workflow is exploratory rather than packaged as reusable Python modules.
  • Results may change when market data changes or Yahoo Finance returns missing values.

Next Improvements

  • Replace the manual CSV upload with a reproducible data download step.
  • Move repeated calculations into a small Python module.
  • Add saved charts or screenshots of the efficient frontier and benchmark comparison.
  • Add configuration for tickers, dates, investment amount, and risk-free rate.
  • Add tests for the portfolio metric calculations.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors