{"id":26199037,"url":"https://github.com/null-none/py-fear-and-greed","last_synced_at":"2025-07-16T04:43:24.404Z","repository":{"id":276106456,"uuid":"928226439","full_name":"null-none/py-fear-and-greed","owner":"null-none","description":"Fear \u0026 Greed Index","archived":false,"fork":false,"pushed_at":"2025-07-08T20:31:26.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-07-08T21:35:29.315Z","etag":null,"topics":["data","fear-and-greed","python","trading"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/null-none.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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}},"created_at":"2025-02-06T09:27:26.000Z","updated_at":"2025-07-08T20:31:30.000Z","dependencies_parsed_at":"2025-02-06T10:42:10.352Z","dependency_job_id":null,"html_url":"https://github.com/null-none/py-fear-and-greed","commit_stats":null,"previous_names":["null-none/py-fear-and-greed"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/null-none/py-fear-and-greed","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/null-none%2Fpy-fear-and-greed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/null-none%2Fpy-fear-and-greed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/null-none%2Fpy-fear-and-greed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/null-none%2Fpy-fear-and-greed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/null-none","download_url":"https://codeload.github.com/null-none/py-fear-and-greed/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/null-none%2Fpy-fear-and-greed/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265482289,"owners_count":23774028,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["data","fear-and-greed","python","trading"],"created_at":"2025-03-12T02:56:06.857Z","updated_at":"2025-07-16T04:43:24.389Z","avatar_url":"https://github.com/null-none.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"## Fear \u0026 Greed Index \n\n**Explanation**\n\n1. **Data Sources**:\n\n• ^VIX: Volatility Index (used for fear calculation).\n\n• ^GSPC: S\u0026P 500 Index (used for market momentum).\n\n• GC=F: Gold futures (safe-haven asset).\n\n• TLT: 20+ Year Treasury Bond ETF (safe-haven asset).\n\n• SPY: S\u0026P 500 ETF (proxy for trading volume).\n\n2. **Normalization**:\n\n• We normalize each metric to a scale of 0-100 for easier calculation.\n\n1. **Index Calculation**:\n\n• Combine normalized scores to compute the average Fear and Greed Index.\n\n2. **Outputs**:\n\n• The index ranges from 0 (extreme fear) to 100 (extreme greed).\n\n#### Example\n\n```python\nimport yfinance as yf\nimport numpy as np\nimport pandas as pd\n\nfrom src.fear_and_greed import FearAndGreed  # Make sure the path is correct\n\n\ndef fetch_data():\n    # Fetch VIX data (Volatility Index)\n    vix = yf.download(\"^VIX\", period=\"7d\", interval=\"1d\", auto_adjust=False)[\"Close\"]\n    vix_latest = vix.iloc[-1] if not vix.empty else np.nan\n\n    # Fetch S\u0026P 500 data (Market Momentum)\n    sp500 = yf.download(\"^GSPC\", period=\"1mo\", interval=\"1d\", auto_adjust=False)[\n        \"Close\"\n    ]\n    market_momentum = (\n        ((sp500.iloc[-1] - sp500.mean()) / sp500.mean()) * 100\n        if not sp500.empty\n        else np.nan\n    )\n\n    # Fetch Gold and Bond data for safe-haven ratio\n    gold = yf.download(\"GC=F\", period=\"1mo\", interval=\"1d\", auto_adjust=False)[\"Close\"]\n    bonds = yf.download(\"TLT\", period=\"1mo\", interval=\"1d\", auto_adjust=False)[\"Close\"]\n\n    safe_haven_ratio = (\n        (\n            (list(gold.iloc[-1])[-1] + list(bonds.iloc[-1])[-1])\n            / list(sp500.iloc[-1])[-1]\n        )\n        * 100\n        if not gold.empty and not bonds.empty and not sp500.empty\n        else np.nan\n    )\n\n    # Trading volume data (SPY as a proxy)\n    spy = yf.download(\"SPY\", period=\"1mo\", interval=\"1d\", auto_adjust=False)\n    if not spy.empty:\n        trading_volume_change = (\n            (spy[\"Volume\"].iloc[-1] - spy[\"Volume\"].mean()) / spy[\"Volume\"].mean()\n        ) * 100\n    else:\n        trading_volume_change = np.nan\n\n    return vix_latest, market_momentum, safe_haven_ratio, trading_volume_change\n\n\ndef interpret_score(score):\n    \"\"\"\n    Interprets the Fear and Greed score and returns a human-readable label.\n    \"\"\"\n    if score \u003c 20:\n        return \"Extreme Fear\"\n    elif score \u003c 40:\n        return \"Fear\"\n    elif score \u003c 60:\n        return \"Neutral\"\n    elif score \u003c 80:\n        return \"Greed\"\n    else:\n        return \"Extreme Greed\"\n\n\ndef main():\n    print(\"Fetching data from Yahoo Finance...\")\n    vix, momentum, haven, volume = fetch_data()\n\n    fg = FearAndGreed()\n    score = fg.calculate(list(vix)[-1], list(momentum)[-1], haven, list(volume)[-1])\n    print(interpret_score(score))\n\n\nif __name__ == \"__main__\":\n    main()\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnull-none%2Fpy-fear-and-greed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnull-none%2Fpy-fear-and-greed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnull-none%2Fpy-fear-and-greed/lists"}