{"id":27736744,"url":"https://github.com/marcusrprojects/stock-return-analyzer","last_synced_at":"2026-04-29T00:32:11.896Z","repository":{"id":290307413,"uuid":"973987538","full_name":"marcusrprojects/stock-return-analyzer","owner":"marcusrprojects","description":"Analyze and visualize cumulative stock returns against a benchmark (e.g., S\u0026P 500) across multiple time scopes using Python, yfinance, and Matplotlib.","archived":false,"fork":false,"pushed_at":"2025-04-28T06:14:35.000Z","size":413,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-28T14:41:29.702Z","etag":null,"topics":["cumulative-return","data-visualization","matplotlib","pandas","python","stock-analysis","yfinance"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marcusrprojects.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-04-28T05:02:08.000Z","updated_at":"2025-04-28T06:14:38.000Z","dependencies_parsed_at":"2025-04-28T06:23:48.569Z","dependency_job_id":"071f7867-a3cf-4b4e-b00c-73b669ea61b7","html_url":"https://github.com/marcusrprojects/stock-return-analyzer","commit_stats":null,"previous_names":["marcusrprojects/stock-return-analyzer"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/marcusrprojects/stock-return-analyzer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcusrprojects%2Fstock-return-analyzer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcusrprojects%2Fstock-return-analyzer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcusrprojects%2Fstock-return-analyzer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcusrprojects%2Fstock-return-analyzer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marcusrprojects","download_url":"https://codeload.github.com/marcusrprojects/stock-return-analyzer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marcusrprojects%2Fstock-return-analyzer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32405901,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-28T19:38:08.556Z","status":"ssl_error","status_checked_at":"2026-04-28T19:37:55.688Z","response_time":56,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cumulative-return","data-visualization","matplotlib","pandas","python","stock-analysis","yfinance"],"created_at":"2025-04-28T14:30:03.767Z","updated_at":"2026-04-29T00:32:11.880Z","avatar_url":"https://github.com/marcusrprojects.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Stock Cumulative Returns Analyzer\n\n![Language](https://img.shields.io/badge/Language-Python-blue.svg)\n[![Python Version](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)\n![Libraries](https://img.shields.io/badge/Libraries-yfinance%20|%20pandas%20|%20matplotlib-orange.svg)\n\n\n## Overview\n\nThis project provides a Python script (`cr_stock_analyzer.py`) to analyze and visualize the cumulative returns of a specified stock compared to a benchmark (defaulting to the S\u0026P 500 - ^GSPC). It fetches historical data using `yfinance`, processes it with `pandas`, and generates a multi-scope comparison plot using `matplotlib`. The script offers various command-line options for customization, including changing tickers, time periods, and plot aesthetics.\n\n## Features\n\n*   Fetches historical stock data via the `yfinance` library.\n*   Retrieves benchmark data (default: S\u0026P 500 ^GSPC).\n*   Aligns stock and benchmark data to common trading dates.\n*   Normalizes closing prices based on the start date of the overall fetched data.\n*   Calculates and plots cumulative returns relative to the start of *each specific scope*.\n*   Visualizes comparisons across multiple time scopes: 1 Month, 3 Months, 6 Months, 1 Year, 5 Years, 10 Years.\n*   Applies progressive smoothing (rolling mean) for longer timeframes (1Y+) to highlight trends.\n*   Generates a 2x3 grid plot for easy comparison across scopes.\n*   Offers command-line arguments for customizing:\n    *   Stock and benchmark tickers\n    *   Data fetching period\n    *   Plot colors (stock line, benchmark line, background, text)\n    *   Font family\n    *   Display options (fill, grid, ticks, labels, legend)\n    *   Saving the plot to a file (PNG format) with customizable paths/names.\n\n## Example Output\n\n*(Generated using default settings: GOOG vs. ^GSPC with specific color theme)*\n\n![Example Plot](./data_viz/GOOG-vs-GSPC-CR-20250428_0051.png)\n\n## Setup and Installation\n\n1.  **Clone the repository:**\n    ```bash\n    git clone https://github.com/marcusrprojects/stock-return-analyzer.git\n    cd stock-return-analyzer\n    ```\n2.  **Create and activate a virtual environment (recommended):**\n    ```bash\n    # Create\n    python3 -m venv venv\n    # Activate (Linux/macOS)\n    source venv/bin/activate\n    # Activate (Windows CMD)\n    # venv\\Scripts\\activate.bat\n    # Activate (Windows PowerShell)\n    # venv\\Scripts\\Activate.ps1\n    ```\n3.  **Install dependencies:**\n    ```bash\n    pip install -r requirements.txt\n    ```\n\n## Usage\n\nRun the script from your terminal.\n\n**Basic Usage (Defaults: DIS vs ^GSPC, max period, saves to `data_viz/`):**\n```bash\npython cr_stock_analyzer.py\n```\n\nAnalyze a different stock (e.g., AAPL) for the last 5 years:\n```bash\npython cr_stock_analyzer.py -t AAPL -p 5y\n```\n\nChange benchmark (e.g., Nasdaq ^IXIC) and output file:\n```bash\npython cr_stock_analyzer.py -t MSFT -b \"^IXIC\" -o outputs/msft_vs_nasdaq.png\n```\n\nCustomize Appearance (e.g., different colors, no fill):\n```bash\npython cr_stock_analyzer.py -t NVDA --stock-color green --bench-color gray --bg-color white --graph-bg-color lightgray --no-fill\n```\n\nPrevent saving the plot:\n```bash\npython cr_stock_analyzer.py --no-save\n```\n\nShow axis labels and use tight X-axis limits:\n```bash\npython cr_stock_analyzer.py --show-labels --tight-xlim\n```\n\nView all options:\n```bash\npython cr_stock_analyzer.py --help\n```\n\n\n## Files\n- `cr_stock_analyzer.py`: The main Python script for analysis and plotting.\n- `requirements.txt`: Lists the necessary Python packages with pinned versions for reproducibility.\n- `README.md`: This file.\n- `data_viz/` (Optional): Default directory where generated plots are saved if no output path is specified. Consider adding this to .gitignore if you don't want generated images tracked by Git.\n\n## Acknowledgements\nData sourced from Yahoo Finance via the yfinance library.\nBuilt with the help of pandas, numpy, and matplotlib.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcusrprojects%2Fstock-return-analyzer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarcusrprojects%2Fstock-return-analyzer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarcusrprojects%2Fstock-return-analyzer/lists"}