Skip to content

This project is a Python-based web application built with Streamlit for comprehensive portfolio analysis of financial markets under a given market stress factor. The tool integrates advanced data visualization libraries and APIs to provide users with insights into their financial holdings and download the analysis to a PDF.

License

Notifications You must be signed in to change notification settings

nishantm77/portfolio-rebalancing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Portfolio Rebalancing - Market Stress Simulator

Overview

This application is designed to analyze and simulate the performance of a stock portfolio under market stress conditions. It allows users to input stock tickers, set the number of stocks for each ticker, and apply a stress factor to simulate market drops. The application generates a comprehensive report that includes portfolio summaries and visualizations. Only usable for stocks listed on National Stock Exchange(NSE), India.

Features

  • Portfolio Input: Users can enter stock tickers and specify the number of stocks for each ticker.
  • Market Stress Simulation: Apply a stress factor to simulate market drops and observe the impact on portfolio value.
  • Portfolio Rebalancing: Automatically rebalance the portfolio based on target weights after applying market stress.
  • Visualizations: Interactive line plots to visualize portfolio values over time.
  • PDF Report Generation: Generate and download a PDF report summarizing the portfolio analysis.

Technologies Used

  • Streamlit: For building the web application interface.
  • Pandas: For data manipulation and analysis.
  • NumPy: For numerical operations.
  • Seaborn & Matplotlib: For data visualization.
  • Plotly: For interactive plotting.
  • ReportLab: For generating PDF reports.
  • NSEPython: For fetching historical stock data (simulated in this code).

Installation

To run this application, ensure you have Python installed along with the required libraries. You can install the necessary packages using pip in the requirements.txt file (the file needs to be in the same directory as the source code):

!pip install -r requirements.txt

Or you can just directly run the following command in the Terminal/Command Prompt:

pip install streamlit pandas numpy seaborn matplotlib plotly reportlab nsepython

Usage

  1. Clone the repository or download the code files.
  2. Navigate to the directory containing frame2.py.
  3. Run the Streamlit application using the following command:
streamlit run frame2.py
  1. Open the provided local URL in your web browser.
  2. Input the stock tickers, set the number of stocks, and adjust the stress factor as desired.
  3. Click on "Run Simulation" to see the results.
  4. Download the PDF report for a detailed analysis of your portfolio.

Functions

  1. Generates a PDF report summarizing the portfolio analysis.
generate_pdf_report(portfolio_data, start_date, end_date)
  1. Calculates custom weights based on the number of stocks for each ticker.
calculate_custom_weights(tickers, num_stocks)
  1. Fetches historical stock data for the specified tickers and date range.
fetch_historical_data(tickers, start_date, end_date)
  1. Calculates initial equal weights for the portfolio.
calculate_initial_weights(tickers)
  1. Applies a market stress factor to the portfolio prices.
apply_market_stress(prices, stress_factor)
  1. Calculates the total value of the portfolio based on prices and weights.
calculate_portfolio_value(prices, weights)
  1. Rebalances the portfolio towards target weights based on price changes.
rebalance_portfolio(prices, target_weights, initial_weights, trade_threshold)
  1. Displays a summary of the portfolio data in the Streamlit app.
display_portfolio_summary(portfolio_data, title)

###Note: This project is deployed publicly as a demo tester here: http://portfolio-rebalancing.streamlit.app/ . Only for educational purposes, not tested for commercial use.

About

This project is a Python-based web application built with Streamlit for comprehensive portfolio analysis of financial markets under a given market stress factor. The tool integrates advanced data visualization libraries and APIs to provide users with insights into their financial holdings and download the analysis to a PDF.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages