A stock performance tool based on the CAPM model
Project description
CAPM Metrics
A stock performance tool based on the Capital Asset Pricing Model (CAPM). This package allows you to analyze stock performance and expected returns based on market data.
Features
- Fetch historical stock data using the Yahoo Finance API.
- Calculate expected returns based on the CAPM model.
- Analyze stock performance against a market index.
- Get average yields from the 10-year Treasury note for risk-free return calculations.
Installation
You can install the capm-metrics
package via pip:
pip install capm-metrics
Usage
Here's a basic example of how to use the CAPMAnalyzer
class:
from capm_metric import CAPMAnalyzer
# Create an instance of CAPMAnalyzer
analyzer = CAPMAnalyzer()
# Analyze a stock (e.g., Apple Inc. with ticker 'AAPL')
results = analyzer.analyze('AAPL', period='1y')
# Print the results
print(results)
Parameters
symbol
(str): The stock symbol for analysis.market
(str, optional): The market index symbol (default:^GSPC
).period
(str, optional): Valid periods for fetching data (e.g.,1d
,1mo
,1y
, etc.).start
(str, optional): Download start date (YYYY-MM-DD).end
(str, optional): Download end date (YYYY-MM-DD).
Expected Output
The analyze
method returns an OrderedDict
containing:
company_name
: The full name of the company.symbol
: The stock symbol.start_date
: The start date of the analysis (YYYY-MM-DD).end_date
: The end date of the analysis (YYYY-MM-DD).expected_return
: The expected return calculated using CAPM.actual_return
: The actual return calculated over the analysis period.performance
: Indicates whether the stock overperformed or underperformed compared to the expected return.
Example
results = analyzer.analyze('AAPL', period='1y')
print(f"Expected Return: {results['expected_return']}")
print(f"Actual Return: {results['actual_return']}")
print(f"Performance: {results['performance']}")
Dependencies
numpy
pandas
yfinance
License
This project is licensed under the MIT License. See the LICENSE file for details.
Contributing
Contributions are welcome! Please open an issue or submit a pull request if you'd like to contribute.
Acknowledgments
This package uses the yfinance
library to fetch stock data, and the calculations are based on the Capital Asset Pricing Model (CAPM).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file capm-metrics-0.1.0.tar.gz
.
File metadata
- Download URL: capm-metrics-0.1.0.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6021ee1e8187413b0fcd0dd56a947cb818c1d6bae37d51b365bc2bdb099021d |
|
MD5 | 0e889862b6d3ae7befa7748608955ddc |
|
BLAKE2b-256 | f86b3b2e7739d13fb0b910a963172d82478df6959777556e96dd4320da79c0c1 |
File details
Details for the file capm_metrics-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: capm_metrics-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cfd88ed3228a0f64d39eb0d4f687a733e2473cac27a4b13f8ec6ac3782494c10 |
|
MD5 | 47daa7a3d4138858020ce39a70d5d805 |
|
BLAKE2b-256 | 869be7fcfd3311198024aba71db71e5b3c3dfbd9991cd2713e4c1f2238007b5f |