Screen.Recording.2024-08-17.161043.mp4
The Capital Asset Pricing Model (CAPM) project is designed to help users understand and apply the CAPM in real-world scenarios. The CAPM is a foundational concept in finance that describes the relationship between systematic risk and expected return for assets, particularly stocks. This project leverages Python, Streamlit, and various financial libraries to allow users to calculate and visualize key metrics like beta and alpha for a portfolio of stocks against a benchmark index (e.g., S&P 500).
- Dynamic Data Download: Download historical stock prices and market index data using Yahoo Finance.
- Risk and Return Analysis: Calculate daily returns, beta, and alpha for individual stocks relative to the market.
- Interactive Visualizations: Visualize stock returns, regression lines, and bar plots for beta values.
- User-Friendly Interface: Use Streamlit to create an interactive web app where users can input stock tickers, start dates, and end dates.
- Installation
- Usage
- Project Structure
- Key Concepts
- Example Outputs
- Future Enhancements
- Contributing
- License
-
Clone the Repository
git clone https://github.com/shubh123a3/Capital-Asset-Pricing-model.git cd Capital-Asset-Pricing-model
-
Install Dependencies
Use pip to install the required packages:
pip install -r requirements.txt
-
Run the Application
Start the Streamlit app by running:
streamlit run app.py
- Input Stock Tickers: Enter the stock tickers (e.g., AAPL, MSFT) separated by commas.
- Select Date Range: Choose the start and end dates for your analysis.
- Download Data: Click the button to download historical data.
- Analyze and Visualize: View calculated beta, alpha, and regression plots. Additionally, see bar plots of beta values across different stocks.
Capital-Asset-Pricing-model/
│
├── app.py # Main Streamlit application
├── helpers.py # Helper functions for calculations and plotting
├── requirements.txt # List of dependencies
├── README.md # Project documentation (this file)
└── data/ # Directory to store downloaded data (optional)
CAPM is a model used to determine the expected return on an asset, given the risk-free rate, the asset's beta, and the expected market return.
[ \text{Expected Return} = \text{Risk-Free Rate} + \beta \times (\text{Market Return} - \text{Risk-Free Rate}) ]
Beta is a measure of an asset's volatility in relation to the overall market. A beta greater than 1 indicates the asset is more volatile than the market, while a beta less than 1 indicates less volatility.
Alpha represents the excess return of an asset over the expected return predicted by the CAPM. Positive alpha indicates outperformance, while negative alpha indicates underperformance.
Beta values:
AAPL: 1.2
MSFT: 1.1
TSLA: 2.3
Alpha values:
AAPL: 0.03
MSFT: 0.02
TSLA: 0.05
- Portfolio Optimization: Extend the project to include Markowitz portfolio optimization.
- Real-Time Data: Integrate real-time stock data for live analysis.
- Historical Risk-Free Rate: Automate the fetching of historical risk-free rates.
Contributions are welcome! Please open an issue or submit a pull request for any features or bug fixes.
This project is licensed under the MIT License - see the LICENSE file for details.