Leverage Ratio Simulations

GPT4 Generated Code Summary

This code is a Python script that uses libraries such as pandas, NumPy, yfinance, and matplotlib to analyze the impact of different leverage ratios on the returns of a stock portfolio. Here's a summary of its main components:

  1. Import Libraries: Imports pandas for data manipulation, NumPy for numerical operations, yfinance to fetch financial data, and matplotlib for plotting.

  2. Define Parameters:

    • tickers: A list of stock symbols (AAPL, META, MSFT) for which historical data is to be downloaded.

    • weights: The allocation weights for each stock in the portfolio.

    • start_date and end_date: The date range for the historical stock data.

    • leverage_ratios: An array of 50 different leverage ratios ranging from 0 to 5.

  3. Download Historical Data: Fetches the adjusted close prices for the specified stocks from Yahoo Finance for the given date range.

  4. Calculate Investment Returns for the Portfolio:

    • Computes daily percentage returns for each stock.

    • Calculates the weighted returns of the portfolio.

    • Applies different leverage ratios to these returns and computes the final value of the portfolio for each leverage ratio.

  5. Plot Results:

    • Plots the relationship between leverage ratios and the percentage return of the portfolio.

    • Sets up the plot with appropriate labels, title, and grid.

  6. Include Individual Stocks for Reference:

    • Calculates and plots the impact of the leverage ratios on the returns of each individual stock in the portfolio for comparison.

Finally, the script displays the plot, showing how different leverage ratios affect the returns of the portfolio and individual stocks.