capm-metrics


Namecapm-metrics JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/C-Shi/capm_metrics
SummaryA stock performance tool based on the CAPM model
upload_time2024-10-25 20:48:43
maintainerNone
docs_urlNone
authorCheng Shi
requires_python>=3.9
licenseMIT
keywords capm stock analysis finance
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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:

```bash
pip install capm-metrics
```

## Usage

Here's a basic example of how to use the `CAPMAnalyzer` class:

```python
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

```python
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](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).



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/C-Shi/capm_metrics",
    "name": "capm-metrics",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "CAPM stock analysis finance",
    "author": "Cheng Shi",
    "author_email": "mr.cheng.shi@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/f8/6b/3b2e7739d13fb0b910a963172d82478df6959777556e96dd4320da79c0c1/capm-metrics-0.1.0.tar.gz",
    "platform": null,
    "description": "# CAPM Metrics\n\nA 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.\n\n## Features\n\n- Fetch historical stock data using the Yahoo Finance API.\n- Calculate expected returns based on the CAPM model.\n- Analyze stock performance against a market index.\n- Get average yields from the 10-year Treasury note for risk-free return calculations.\n\n## Installation\n\nYou can install the `capm-metrics` package via pip:\n\n```bash\npip install capm-metrics\n```\n\n## Usage\n\nHere's a basic example of how to use the `CAPMAnalyzer` class:\n\n```python\nfrom capm_metric import CAPMAnalyzer\n\n# Create an instance of CAPMAnalyzer\nanalyzer = CAPMAnalyzer()\n\n# Analyze a stock (e.g., Apple Inc. with ticker 'AAPL')\nresults = analyzer.analyze('AAPL', period='1y')\n\n# Print the results\nprint(results)\n```\n\n### Parameters\n\n- `symbol` (str): The stock symbol for analysis.\n- `market` (str, optional): The market index symbol (default: `^GSPC`).\n- `period` (str, optional): Valid periods for fetching data (e.g., `1d`, `1mo`, `1y`, etc.).\n- `start` (str, optional): Download start date (YYYY-MM-DD).\n- `end` (str, optional): Download end date (YYYY-MM-DD).\n\n### Expected Output\n\nThe `analyze` method returns an `OrderedDict` containing:\n\n- `company_name`: The full name of the company.\n- `symbol`: The stock symbol.\n- `start_date`: The start date of the analysis (YYYY-MM-DD).\n- `end_date`: The end date of the analysis (YYYY-MM-DD).\n- `expected_return`: The expected return calculated using CAPM.\n- `actual_return`: The actual return calculated over the analysis period.\n- `performance`: Indicates whether the stock overperformed or underperformed compared to the expected return.\n\n## Example\n\n```python\nresults = analyzer.analyze('AAPL', period='1y')\nprint(f\"Expected Return: {results['expected_return']}\")\nprint(f\"Actual Return: {results['actual_return']}\")\nprint(f\"Performance: {results['performance']}\")\n```\n\n## Dependencies\n\n- `numpy`\n- `pandas`\n- `yfinance`\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n## Contributing\n\nContributions are welcome! Please open an issue or submit a pull request if you'd like to contribute.\n\n## Acknowledgments\n\nThis package uses the `yfinance` library to fetch stock data, and the calculations are based on the Capital Asset Pricing Model (CAPM).\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A stock performance tool based on the CAPM model",
    "version": "0.1.0",
    "project_urls": {
        "Bug Tracker": "https://github.com/C-Shi/capm_metrics/issues",
        "Documentation": "https://github.com/C-Shi/capm_metrics#readme",
        "Homepage": "https://github.com/C-Shi/capm_metrics"
    },
    "split_keywords": [
        "capm",
        "stock",
        "analysis",
        "finance"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "869be7fcfd3311198024aba71db71e5b3c3dfbd9991cd2713e4c1f2238007b5f",
                "md5": "47daa7a3d4138858020ce39a70d5d805",
                "sha256": "cfd88ed3228a0f64d39eb0d4f687a733e2473cac27a4b13f8ec6ac3782494c10"
            },
            "downloads": -1,
            "filename": "capm_metrics-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "47daa7a3d4138858020ce39a70d5d805",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 4598,
            "upload_time": "2024-10-25T20:48:41",
            "upload_time_iso_8601": "2024-10-25T20:48:41.009713Z",
            "url": "https://files.pythonhosted.org/packages/86/9b/e7fcfd3311198024aba71db71e5b3c3dfbd9991cd2713e4c1f2238007b5f/capm_metrics-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f86b3b2e7739d13fb0b910a963172d82478df6959777556e96dd4320da79c0c1",
                "md5": "0e889862b6d3ae7befa7748608955ddc",
                "sha256": "f6021ee1e8187413b0fcd0dd56a947cb818c1d6bae37d51b365bc2bdb099021d"
            },
            "downloads": -1,
            "filename": "capm-metrics-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "0e889862b6d3ae7befa7748608955ddc",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 4392,
            "upload_time": "2024-10-25T20:48:43",
            "upload_time_iso_8601": "2024-10-25T20:48:43.035796Z",
            "url": "https://files.pythonhosted.org/packages/f8/6b/3b2e7739d13fb0b910a963172d82478df6959777556e96dd4320da79c0c1/capm-metrics-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-25 20:48:43",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "C-Shi",
    "github_project": "capm_metrics",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "capm-metrics"
}
        
Elapsed time: 0.40570s