Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

capm_metrics-0.1.1.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

capm_metrics-0.1.1-py3-none-any.whl (7.2 kB view details)

Uploaded Python 3

File details

Details for the file capm_metrics-0.1.1.tar.gz.

File metadata

  • Download URL: capm_metrics-0.1.1.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for capm_metrics-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4f510d7418e37fe8a2788129a1e79a3af41961ab9e0789130948e0b209f67ecd
MD5 d19393f193bf0ad81c7338fe7f1a565c
BLAKE2b-256 1a356f54a498f35d3b0645cefdb34bc53a63d50685847d05323fcf5b922aa0bd

See more details on using hashes here.

File details

Details for the file capm_metrics-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: capm_metrics-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 7.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for capm_metrics-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ae0276e2298836f9878af407fbdc757888a26da95bee24ee2e10079396644a6d
MD5 9f6649c3c849ef482ba432ba5556da59
BLAKE2b-256 4eb88e124248b68d8c106ef05fe2dd59ab538d1859dad6929887001df779a52f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page