smart-money-concept


Namesmart-money-concept JSON
Version 0.1.3 PyPI version JSON
download
home_pageNone
SummaryA Python implementation of Smart Money Concepts (SMC) for technical analysis using yfinance data.
upload_time2025-09-19 16:40:54
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
keywords finance trading technical-analysis smart-money-concepts yfinance
VCS
bugtrack_url
requirements yfinance pandas numpy matplotlib
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Smart Money Concepts (SMC) Python Package

A Python package for performing **Smart Money Concepts (SMC)** technical analysis using historical stock data from **yfinance**. This package provides a comprehensive framework for detecting market structures, order blocks, fair value gaps, and other SMC components, with visualization capabilities using **matplotlib**.

---

## 📌 Features
- **Market Structure Analysis**: Detects Break of Structure (BOS) and Change of Character (CHoCH) for swing and internal structures.
- **Order Blocks**: Identifies bullish and bearish order blocks for potential institutional trading zones.
- **Fair Value Gaps (FVG)**: Detects price imbalances with mitigation logic.
- **Equal Highs and Lows**: Marks potential reversal points with Equal Highs (EQH) and Equal Lows (EQL).
- **Premium and Discount Zones**: Calculates dynamic zones based on trailing extremes.
- **Visualization**: Plots candlestick charts with SMC indicators (BOS, CHoCH, order blocks, FVGs, etc.) using matplotlib.
- **Real-time Data**: Fetches OHLCV data from yfinance for stocks and indices.
- **Customizable Settings**: Configure analysis parameters like swing length, FVG thresholds, and visualization styles (colored or monochrome).

---

## ⚙️ Installation

### From PyPI (when published)
```bash
pip install smart-money-concept
```

---

## 📦 Requirements
- Python 3.8+
- yfinance>=0.2.40
- pandas>=2.0.0
- numpy>=1.24.0
- matplotlib>=3.7.0

---

## 🚀 Usage

The package provides a **SmartMoneyConcepts** class for analyzing market data and a **command-line interface (CLI)** for batch processing multiple stocks.

### Python Script Example
```python
import asyncio
from typing import List, Dict
from smart_money_concepts import SmartMoneyConcepts

async def main(stock_codes: List[str], period: str = "max", interval: str = "1d", batch_size: int = 10, delay: float = 2.0, visualize: bool = True):
    if not stock_codes:
        stock_codes = ["RELIANCE.NS"]  # Default to NSE-listed Reliance

    for i, stock_code in enumerate(stock_codes):
        print(f"\n==============================")
        print(f"🔍 Analyzing stock: {stock_code}")
        print(f"==============================")

        smc = SmartMoneyConcepts(stock_code=stock_code, period=period, interval=interval)
        
        # Retry logic for fetching data
        max_retries = 3
        for attempt in range(max_retries):
            try:
                success = await smc.fetch_ohlcv()
                if success:
                    smc.prepare_data()
                    smc.run_smc_analysis()
                    if visualize:
                        smc.visualize_smc(bars_to_show=250)
                    else:
                        smc.print_analysis_summary()  # Print summary even if visualization is skipped
                    break
                else:
                    print(f"❌ Analysis failed for {stock_code}!")
                    break
            except Exception as e:
                if "429" in str(e):  # Check for rate limit error
                    print(f"Rate limit hit for {stock_code}. Retrying ({attempt + 1}/{max_retries}) after delay...")
                    await asyncio.sleep(5)  # Wait longer for rate limit errors
                else:
                    print(f"Error for {stock_code}: {e}")
                    break
            if attempt == max_retries - 1:
                print(f"❌ Failed to fetch data for {stock_code} after {max_retries} attempts.")

        # Add delay after every batch_size stocks
        if (i + 1) % batch_size == 0 and i + 1 < len(stock_codes):
            print(f"Pausing for {delay} seconds after processing {batch_size} stocks...")
            await asyncio.sleep(delay)

if __name__ == "__main__":
    # Example stock list (use .NS for NSE-listed stocks, .BO for BSE, or others as needed)

    # Stocks
    stock_codes = ["RELIANCE.NS", "TCS.NS", "INFY.NS", "HDFCBANK.NS", "ICICIBANK.NS"]
    
    # Index
    # stock_codes = ["^NSEI"]
    
    asyncio.run(main(stock_codes, period="1y", interval="1d", batch_size=10, delay=2.0, visualize=True))
```

### CLI Example
```bash
python -m smart_money_concepts.cli --stocks ^NSEI RELIANCE.NS --period 1y --interval 1d
```

#### CLI Options:
- `--stocks`: List of stock codes (e.g., ^NSEI, RELIANCE.NS). Default: RELIANCE.NS.
- `--period`: Data period (e.g., 1d, 1mo, 1y, max). Default: 1y.
- `--interval`: Data interval (e.g., 1m, 1h, 1d). Default: 1d.
- `--batch-size`: Number of stocks to process before pausing. Default: 10.
- `--delay`: Delay (seconds) between batches. Default: 2.0.
- `--no-visualize`: Disable visualization and print analysis summary only.

---

## 📊 Example Output
The package generates a detailed analysis summary and optional visualizations, including:
- Candlestick charts with swing and internal structure breaks (BOS/CHoCH).
- Order blocks, fair value gaps, and equal highs/lows.
- Premium, equilibrium, and discount zones.

---

## 📂 Project Structure
```
smart_money_concepts/
├── smart_money_concepts/
│   ├── __init__.py
│   ├── smc.py
│   ├── cli.py
├── README.md
├── pyproject.toml
├── requirements.txt
```

---

## 🙌 Credits
This project was inspired by and builds upon the following resources:

- **[Code Tech (YouTube)](https://www.youtube.com/watch?v=s6YWq-W7V6g)** → This code is Take from YouTube tutorial by Code Tech, which provides a detailed walkthrough of building an SMC indicator in Python
- **[LuxAlgo](https://www.luxalgo.com/library/indicator/smart-money-concepts-smc/)** → The conceptual framework and feature set are inspired by LuxAlgo's Smart Money Concepts indicator.

---

## 🤝 Contributing
Contributions are welcome! Please submit a pull request or open an issue on the GitHub repository for bug reports, feature requests, or improvements.

---

## ⚠️ Notes
- **Rate Limits**: The package uses yfinance for data fetching, which may be subject to rate limits. Built-in retry logic handles HTTP 429 errors.
- **Internet Connection**: Ensure a stable internet connection for fetching market data.
- **Disclaimer**: This package is for educational purposes and should not be used as financial advice. Trading involves risks, and past performance does not guarantee future results.

---

## 📬 Contact
For questions or support, please open an issue on the GitHub repository.

---


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "smart-money-concept",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "finance, trading, technical-analysis, smart-money-concepts, yfinance",
    "author": null,
    "author_email": "Prasad <mr.xprasadx@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/bc/81/cb29577196167b62da168565c35f6ce77a55d50f423a78781bae1914074f/smart_money_concept-0.1.3.tar.gz",
    "platform": null,
    "description": "# Smart Money Concepts (SMC) Python Package\r\n\r\nA Python package for performing **Smart Money Concepts (SMC)** technical analysis using historical stock data from **yfinance**. This package provides a comprehensive framework for detecting market structures, order blocks, fair value gaps, and other SMC components, with visualization capabilities using **matplotlib**.\r\n\r\n---\r\n\r\n## \ud83d\udccc Features\r\n- **Market Structure Analysis**: Detects Break of Structure (BOS) and Change of Character (CHoCH) for swing and internal structures.\r\n- **Order Blocks**: Identifies bullish and bearish order blocks for potential institutional trading zones.\r\n- **Fair Value Gaps (FVG)**: Detects price imbalances with mitigation logic.\r\n- **Equal Highs and Lows**: Marks potential reversal points with Equal Highs (EQH) and Equal Lows (EQL).\r\n- **Premium and Discount Zones**: Calculates dynamic zones based on trailing extremes.\r\n- **Visualization**: Plots candlestick charts with SMC indicators (BOS, CHoCH, order blocks, FVGs, etc.) using matplotlib.\r\n- **Real-time Data**: Fetches OHLCV data from yfinance for stocks and indices.\r\n- **Customizable Settings**: Configure analysis parameters like swing length, FVG thresholds, and visualization styles (colored or monochrome).\r\n\r\n---\r\n\r\n## \u2699\ufe0f Installation\r\n\r\n### From PyPI (when published)\r\n```bash\r\npip install smart-money-concept\r\n```\r\n\r\n---\r\n\r\n## \ud83d\udce6 Requirements\r\n- Python 3.8+\r\n- yfinance>=0.2.40\r\n- pandas>=2.0.0\r\n- numpy>=1.24.0\r\n- matplotlib>=3.7.0\r\n\r\n---\r\n\r\n## \ud83d\ude80 Usage\r\n\r\nThe package provides a **SmartMoneyConcepts** class for analyzing market data and a **command-line interface (CLI)** for batch processing multiple stocks.\r\n\r\n### Python Script Example\r\n```python\r\nimport asyncio\r\nfrom typing import List, Dict\r\nfrom smart_money_concepts import SmartMoneyConcepts\r\n\r\nasync def main(stock_codes: List[str], period: str = \"max\", interval: str = \"1d\", batch_size: int = 10, delay: float = 2.0, visualize: bool = True):\r\n    if not stock_codes:\r\n        stock_codes = [\"RELIANCE.NS\"]  # Default to NSE-listed Reliance\r\n\r\n    for i, stock_code in enumerate(stock_codes):\r\n        print(f\"\\n==============================\")\r\n        print(f\"\ud83d\udd0d Analyzing stock: {stock_code}\")\r\n        print(f\"==============================\")\r\n\r\n        smc = SmartMoneyConcepts(stock_code=stock_code, period=period, interval=interval)\r\n        \r\n        # Retry logic for fetching data\r\n        max_retries = 3\r\n        for attempt in range(max_retries):\r\n            try:\r\n                success = await smc.fetch_ohlcv()\r\n                if success:\r\n                    smc.prepare_data()\r\n                    smc.run_smc_analysis()\r\n                    if visualize:\r\n                        smc.visualize_smc(bars_to_show=250)\r\n                    else:\r\n                        smc.print_analysis_summary()  # Print summary even if visualization is skipped\r\n                    break\r\n                else:\r\n                    print(f\"\u274c Analysis failed for {stock_code}!\")\r\n                    break\r\n            except Exception as e:\r\n                if \"429\" in str(e):  # Check for rate limit error\r\n                    print(f\"Rate limit hit for {stock_code}. Retrying ({attempt + 1}/{max_retries}) after delay...\")\r\n                    await asyncio.sleep(5)  # Wait longer for rate limit errors\r\n                else:\r\n                    print(f\"Error for {stock_code}: {e}\")\r\n                    break\r\n            if attempt == max_retries - 1:\r\n                print(f\"\u274c Failed to fetch data for {stock_code} after {max_retries} attempts.\")\r\n\r\n        # Add delay after every batch_size stocks\r\n        if (i + 1) % batch_size == 0 and i + 1 < len(stock_codes):\r\n            print(f\"Pausing for {delay} seconds after processing {batch_size} stocks...\")\r\n            await asyncio.sleep(delay)\r\n\r\nif __name__ == \"__main__\":\r\n    # Example stock list (use .NS for NSE-listed stocks, .BO for BSE, or others as needed)\r\n\r\n    # Stocks\r\n    stock_codes = [\"RELIANCE.NS\", \"TCS.NS\", \"INFY.NS\", \"HDFCBANK.NS\", \"ICICIBANK.NS\"]\r\n    \r\n    # Index\r\n    # stock_codes = [\"^NSEI\"]\r\n    \r\n    asyncio.run(main(stock_codes, period=\"1y\", interval=\"1d\", batch_size=10, delay=2.0, visualize=True))\r\n```\r\n\r\n### CLI Example\r\n```bash\r\npython -m smart_money_concepts.cli --stocks ^NSEI RELIANCE.NS --period 1y --interval 1d\r\n```\r\n\r\n#### CLI Options:\r\n- `--stocks`: List of stock codes (e.g., ^NSEI, RELIANCE.NS). Default: RELIANCE.NS.\r\n- `--period`: Data period (e.g., 1d, 1mo, 1y, max). Default: 1y.\r\n- `--interval`: Data interval (e.g., 1m, 1h, 1d). Default: 1d.\r\n- `--batch-size`: Number of stocks to process before pausing. Default: 10.\r\n- `--delay`: Delay (seconds) between batches. Default: 2.0.\r\n- `--no-visualize`: Disable visualization and print analysis summary only.\r\n\r\n---\r\n\r\n## \ud83d\udcca Example Output\r\nThe package generates a detailed analysis summary and optional visualizations, including:\r\n- Candlestick charts with swing and internal structure breaks (BOS/CHoCH).\r\n- Order blocks, fair value gaps, and equal highs/lows.\r\n- Premium, equilibrium, and discount zones.\r\n\r\n---\r\n\r\n## \ud83d\udcc2 Project Structure\r\n```\r\nsmart_money_concepts/\r\n\u251c\u2500\u2500 smart_money_concepts/\r\n\u2502   \u251c\u2500\u2500 __init__.py\r\n\u2502   \u251c\u2500\u2500 smc.py\r\n\u2502   \u251c\u2500\u2500 cli.py\r\n\u251c\u2500\u2500 README.md\r\n\u251c\u2500\u2500 pyproject.toml\r\n\u251c\u2500\u2500 requirements.txt\r\n```\r\n\r\n---\r\n\r\n## \ud83d\ude4c Credits\r\nThis project was inspired by and builds upon the following resources:\r\n\r\n- **[Code Tech (YouTube)](https://www.youtube.com/watch?v=s6YWq-W7V6g)** \u2192 This code is Take from YouTube tutorial by Code Tech, which provides a detailed walkthrough of building an SMC indicator in Python\r\n- **[LuxAlgo](https://www.luxalgo.com/library/indicator/smart-money-concepts-smc/)** \u2192 The conceptual framework and feature set are inspired by LuxAlgo's Smart Money Concepts indicator.\r\n\r\n---\r\n\r\n## \ud83e\udd1d Contributing\r\nContributions are welcome! Please submit a pull request or open an issue on the GitHub repository for bug reports, feature requests, or improvements.\r\n\r\n---\r\n\r\n## \u26a0\ufe0f Notes\r\n- **Rate Limits**: The package uses yfinance for data fetching, which may be subject to rate limits. Built-in retry logic handles HTTP 429 errors.\r\n- **Internet Connection**: Ensure a stable internet connection for fetching market data.\r\n- **Disclaimer**: This package is for educational purposes and should not be used as financial advice. Trading involves risks, and past performance does not guarantee future results.\r\n\r\n---\r\n\r\n## \ud83d\udcec Contact\r\nFor questions or support, please open an issue on the GitHub repository.\r\n\r\n---\r\n\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A Python implementation of Smart Money Concepts (SMC) for technical analysis using yfinance data.",
    "version": "0.1.3",
    "project_urls": {
        "Homepage": "https://github.com/Prasad1612/smart-money-concept",
        "Issues": "https://github.com/Prasad1612/smart-money-concept/issues",
        "Repository": "https://github.com/Prasad1612/smart-money-concept"
    },
    "split_keywords": [
        "finance",
        " trading",
        " technical-analysis",
        " smart-money-concepts",
        " yfinance"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "02f100e3eb95c11f9b6eab7e1fe07da6abc36a197980a8678f371deb1cef4aa8",
                "md5": "e82ebae9fac51b40ab204d050e10f2bc",
                "sha256": "aeec1ac0d07ca188e7c5e199b4106dbf8155abc2f70539b51f0f2b91cae06f2c"
            },
            "downloads": -1,
            "filename": "smart_money_concept-0.1.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e82ebae9fac51b40ab204d050e10f2bc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 17546,
            "upload_time": "2025-09-19T16:40:52",
            "upload_time_iso_8601": "2025-09-19T16:40:52.950782Z",
            "url": "https://files.pythonhosted.org/packages/02/f1/00e3eb95c11f9b6eab7e1fe07da6abc36a197980a8678f371deb1cef4aa8/smart_money_concept-0.1.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "bc81cb29577196167b62da168565c35f6ce77a55d50f423a78781bae1914074f",
                "md5": "211b3cb6eac340009881a519b7ff7be5",
                "sha256": "33dcf65d0f29aeba9462428c08c0d318bdd21f20971af6e5eeff51bf81946636"
            },
            "downloads": -1,
            "filename": "smart_money_concept-0.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "211b3cb6eac340009881a519b7ff7be5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 16104,
            "upload_time": "2025-09-19T16:40:54",
            "upload_time_iso_8601": "2025-09-19T16:40:54.435072Z",
            "url": "https://files.pythonhosted.org/packages/bc/81/cb29577196167b62da168565c35f6ce77a55d50f423a78781bae1914074f/smart_money_concept-0.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-09-19 16:40:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Prasad1612",
    "github_project": "smart-money-concept",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "yfinance",
            "specs": [
                [
                    ">=",
                    "0.2.40"
                ]
            ]
        },
        {
            "name": "pandas",
            "specs": [
                [
                    ">=",
                    "2.0.0"
                ]
            ]
        },
        {
            "name": "numpy",
            "specs": [
                [
                    ">=",
                    "1.24.0"
                ]
            ]
        },
        {
            "name": "matplotlib",
            "specs": [
                [
                    ">=",
                    "3.7.0"
                ]
            ]
        }
    ],
    "lcname": "smart-money-concept"
}
        
Elapsed time: 1.32957s