bfinance 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bfinance-0.1.0/.gitignore +54 -0
- bfinance-0.1.0/CONTRIBUTING.md +64 -0
- bfinance-0.1.0/LICENSE +64 -0
- bfinance-0.1.0/PKG-INFO +315 -0
- bfinance-0.1.0/README.md +281 -0
- bfinance-0.1.0/compare_tools.py +107 -0
- bfinance-0.1.0/docs/AI_AGENT_INTEGRATION.md +152 -0
- bfinance-0.1.0/docs/API_REFERENCE.md +366 -0
- bfinance-0.1.0/docs/YFINANCE_MIGRATION_GUIDE.md +104 -0
- bfinance-0.1.0/examples/ai_demo.py +47 -0
- bfinance-0.1.0/examples/custom_ratios_demo.py +39 -0
- bfinance-0.1.0/examples/master_verification.py +98 -0
- bfinance-0.1.0/examples/numerical_audit.py +102 -0
- bfinance-0.1.0/examples/quickstart.py +28 -0
- bfinance-0.1.0/exports/BAJAJ-AUTO_10Y_Financial_Model.xlsx +0 -0
- bfinance-0.1.0/exports/BAJAJ-AUTO_AI_Dossier.md +124 -0
- bfinance-0.1.0/exports/BAJAJ-AUTO_Investment_Memo_Prompt.md +141 -0
- bfinance-0.1.0/exports/HDFCBANK_10Y_Financial_Model.xlsx +0 -0
- bfinance-0.1.0/exports/HDFCBANK_AI_Dossier.md +133 -0
- bfinance-0.1.0/exports/HDFCBANK_Investment_Memo_Prompt.md +150 -0
- bfinance-0.1.0/exports/INFY_10Y_Financial_Model.xlsx +0 -0
- bfinance-0.1.0/exports/INFY_AI_Dossier.md +138 -0
- bfinance-0.1.0/exports/INFY_Investment_Memo_Prompt.md +155 -0
- bfinance-0.1.0/exports/RELIANCE_10Y_Financial_Model.xlsx +0 -0
- bfinance-0.1.0/exports/RELIANCE_AI_Dossier.md +131 -0
- bfinance-0.1.0/exports/RELIANCE_Investment_Memo_Prompt.md +148 -0
- bfinance-0.1.0/exports/TCS_10Y_Financial_Model.xlsx +0 -0
- bfinance-0.1.0/exports/TCS_AI_Dossier.md +122 -0
- bfinance-0.1.0/exports/TCS_Investment_Memo_Prompt.md +139 -0
- bfinance-0.1.0/generate_exports.py +41 -0
- bfinance-0.1.0/pyproject.toml +61 -0
- bfinance-0.1.0/src/bfinance/__init__.py +64 -0
- bfinance-0.1.0/src/bfinance/ai/__init__.py +13 -0
- bfinance-0.1.0/src/bfinance/ai/context.py +194 -0
- bfinance-0.1.0/src/bfinance/ai/prompts.py +81 -0
- bfinance-0.1.0/src/bfinance/ai/tools.py +93 -0
- bfinance-0.1.0/src/bfinance/cache/__init__.py +7 -0
- bfinance-0.1.0/src/bfinance/cache/sqlite_cache.py +121 -0
- bfinance-0.1.0/src/bfinance/download.py +180 -0
- bfinance-0.1.0/src/bfinance/market/__init__.py +17 -0
- bfinance-0.1.0/src/bfinance/market/corporate.py +87 -0
- bfinance-0.1.0/src/bfinance/market/derivatives.py +128 -0
- bfinance-0.1.0/src/bfinance/market/fast_info.py +106 -0
- bfinance-0.1.0/src/bfinance/market/ohlcv.py +142 -0
- bfinance-0.1.0/src/bfinance/market/quotes.py +80 -0
- bfinance-0.1.0/src/bfinance/market/ratios.py +228 -0
- bfinance-0.1.0/src/bfinance/models/__init__.py +24 -0
- bfinance-0.1.0/src/bfinance/models/company.py +107 -0
- bfinance-0.1.0/src/bfinance/models/options.py +30 -0
- bfinance-0.1.0/src/bfinance/models/statements.py +48 -0
- bfinance-0.1.0/src/bfinance/screener/__init__.py +9 -0
- bfinance-0.1.0/src/bfinance/screener/charts.py +57 -0
- bfinance-0.1.0/src/bfinance/screener/client.py +264 -0
- bfinance-0.1.0/src/bfinance/screener/parser.py +401 -0
- bfinance-0.1.0/src/bfinance/screens.py +169 -0
- bfinance-0.1.0/src/bfinance/sector.py +108 -0
- bfinance-0.1.0/src/bfinance/ticker.py +656 -0
- bfinance-0.1.0/src/bfinance/tickers.py +89 -0
- bfinance-0.1.0/src/bfinance/utils/__init__.py +26 -0
- bfinance-0.1.0/src/bfinance/utils/downloader.py +64 -0
- bfinance-0.1.0/src/bfinance/utils/excel.py +83 -0
- bfinance-0.1.0/src/bfinance/utils/exceptions.py +27 -0
- bfinance-0.1.0/src/bfinance/utils/formatting.py +80 -0
- bfinance-0.1.0/src/bfinance/utils/symbols.py +45 -0
- bfinance-0.1.0/tests/conftest.py +20 -0
- bfinance-0.1.0/tests/test_ai_module.py +76 -0
- bfinance-0.1.0/tests/test_batch_download.py +26 -0
- bfinance-0.1.0/tests/test_custom_ratios.py +38 -0
- bfinance-0.1.0/tests/test_exhaustive_screener_and_yfinance.py +381 -0
- bfinance-0.1.0/tests/test_live_yfinance_parity.py +129 -0
- bfinance-0.1.0/tests/test_screener_depth.py +94 -0
- bfinance-0.1.0/tests/test_screener_extra_features.py +66 -0
- bfinance-0.1.0/tests/test_ticker_yfinance_compat.py +198 -0
- bfinance-0.1.0/tests/test_valuation_charts.py +42 -0
- bfinance-0.1.0/uv.lock +1908 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
__pycache__/
|
|
2
|
+
*.py[cod]
|
|
3
|
+
*$py.class
|
|
4
|
+
*.so
|
|
5
|
+
.Python
|
|
6
|
+
build/
|
|
7
|
+
develop-eggs/
|
|
8
|
+
dist/
|
|
9
|
+
downloads/
|
|
10
|
+
eggs/
|
|
11
|
+
.eggs/
|
|
12
|
+
lib/
|
|
13
|
+
lib64/
|
|
14
|
+
parts/
|
|
15
|
+
sdist/
|
|
16
|
+
var/
|
|
17
|
+
wheels/
|
|
18
|
+
share/python-wheels/
|
|
19
|
+
*.egg-info/
|
|
20
|
+
.installed.cfg
|
|
21
|
+
*.egg
|
|
22
|
+
MANIFEST
|
|
23
|
+
|
|
24
|
+
# Virtual environments
|
|
25
|
+
.env
|
|
26
|
+
.venv
|
|
27
|
+
env/
|
|
28
|
+
venv/
|
|
29
|
+
ENV/
|
|
30
|
+
|
|
31
|
+
# Unit test / coverage reports
|
|
32
|
+
htmlcov/
|
|
33
|
+
.tox/
|
|
34
|
+
.nox/
|
|
35
|
+
.coverage
|
|
36
|
+
.coverage.*
|
|
37
|
+
.cache
|
|
38
|
+
nosetests.xml
|
|
39
|
+
coverage.xml
|
|
40
|
+
*.cover
|
|
41
|
+
*.py,cover
|
|
42
|
+
.hypothesis/
|
|
43
|
+
.pytest_cache/
|
|
44
|
+
cover/
|
|
45
|
+
|
|
46
|
+
# IDE / OS
|
|
47
|
+
.vscode/
|
|
48
|
+
.idea/
|
|
49
|
+
*.swp
|
|
50
|
+
*.swo
|
|
51
|
+
.DS_Store
|
|
52
|
+
Thumbs.db
|
|
53
|
+
*.sqlite3
|
|
54
|
+
*.db
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# Contributing to `bfinance`
|
|
2
|
+
|
|
3
|
+
Thank you for your interest in contributing to `bfinance`! We welcome bug reports, feature suggestions, documentation improvements, and pull requests.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## ๐ ๏ธ Development Setup
|
|
8
|
+
|
|
9
|
+
`bfinance` uses [`uv`](https://github.com/astral-sh/uv) as its fast package and project manager.
|
|
10
|
+
|
|
11
|
+
### 1. Clone the Repository
|
|
12
|
+
```bash
|
|
13
|
+
git clone https://github.com/bfinance-org/bfinance.git
|
|
14
|
+
cd bfinance
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### 2. Install Dependencies
|
|
18
|
+
```bash
|
|
19
|
+
# Sync dependencies and development tools
|
|
20
|
+
uv sync --extra dev
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## ๐งช Running Tests
|
|
26
|
+
|
|
27
|
+
`bfinance` has an automated test suite covering yfinance parity, Screener ingestion, custom ratios, and AI engines:
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# Run all tests
|
|
31
|
+
uv run pytest
|
|
32
|
+
|
|
33
|
+
# Run a specific test suite with verbose output
|
|
34
|
+
uv run pytest tests/test_ticker_yfinance_compat.py -v
|
|
35
|
+
|
|
36
|
+
# Run with coverage report
|
|
37
|
+
uv run pytest --cov=bfinance
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## ๐ Coding Conventions & Guidelines
|
|
43
|
+
|
|
44
|
+
1. **yfinance 1.7.0+ Compatibility**:
|
|
45
|
+
- Never break API signatures of existing `yfinance` methods (`history()`, `fast_info`, `info`, `download()`, `Tickers`, `Sector`).
|
|
46
|
+
- If adding a parameter, ensure it matches `yfinance` defaults or is backward-compatible.
|
|
47
|
+
2. **Indian Market Invariants**:
|
|
48
|
+
- Currency is always Indian Rupee (`INR` / `โน`).
|
|
49
|
+
- Market caps and financial statement totals should support Indian numeral formatting (Crores `Cr`, Lakhs `L`).
|
|
50
|
+
- Timezone for market hours is strictly `Asia/Kolkata`.
|
|
51
|
+
3. **Anti-Blocking & Network Hygiene**:
|
|
52
|
+
- Always route web requests through `ScreenerClient` to preserve adaptive request pacing (`150ms`), jitter, User-Agent rotation, and SQLite caching.
|
|
53
|
+
4. **Zero-Crash Graceful Degradation**:
|
|
54
|
+
- Core properties must handle missing data and invalid tickers gracefully when `raise_errors=False`.
|
|
55
|
+
- Log warnings using `logging.getLogger("bfinance")`.
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## ๐ Submitting Pull Requests
|
|
60
|
+
|
|
61
|
+
1. Fork the repo and create a feature branch (`git checkout -b feature/my-enhancement`).
|
|
62
|
+
2. Add permanent unit tests in `tests/` for any new feature or bug fix.
|
|
63
|
+
3. Ensure all tests pass (`uv run pytest`).
|
|
64
|
+
4. Commit your changes and open a Pull Request.
|
bfinance-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 bfinance Contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
|
23
|
+
================================================================================
|
|
24
|
+
LEGAL DISCLAIMER, NON-AFFILIATION & TERMS OF USE NOTICE
|
|
25
|
+
================================================================================
|
|
26
|
+
|
|
27
|
+
1. EDUCATIONAL AND RESEARCH PURPOSE ONLY
|
|
28
|
+
This software, documentation, and associated scripts are developed and
|
|
29
|
+
distributed exclusively for educational, academic, and research purposes.
|
|
30
|
+
Nothing contained in this package constitutes financial, investment, legal,
|
|
31
|
+
tax, or accounting advice.
|
|
32
|
+
|
|
33
|
+
2. NO INVESTMENT ADVICE & ZERO LIABILITY
|
|
34
|
+
The authors, maintainers, and contributors of this software are NOT SEBI-
|
|
35
|
+
registered Research Analysts (RA) or Registered Investment Advisors (RIA).
|
|
36
|
+
No calculations, valuation metrics, screeners, AI context outputs, or
|
|
37
|
+
timeseries generated by this tool constitute a recommendation, endorsement,
|
|
38
|
+
or solicitation to buy, sell, or hold any equity, derivative, commodity,
|
|
39
|
+
or financial instrument.
|
|
40
|
+
Under no circumstances shall the authors or contributors be liable for any
|
|
41
|
+
direct, indirect, incidental, special, exemplary, punitive, or consequential
|
|
42
|
+
damages, including but not limited to loss of capital, trading losses,
|
|
43
|
+
missed profits, business interruption, or data corruption arising from the
|
|
44
|
+
use or inability to use this software.
|
|
45
|
+
|
|
46
|
+
3. INDEPENDENCE & NON-AFFILIATION DISCLAIMER
|
|
47
|
+
"bfinance" is an independent, community-driven open-source project.
|
|
48
|
+
This project is NOT affiliated, associated, authorized, endorsed by, or in
|
|
49
|
+
any way officially connected with:
|
|
50
|
+
- Yahoo! Inc. or yfinance (Ran Aroussi)
|
|
51
|
+
- Screener.in / Mittal Analytics Pvt. Ltd.
|
|
52
|
+
- National Stock Exchange of India Ltd. (NSE)
|
|
53
|
+
- BSE Ltd. (Bombay Stock Exchange)
|
|
54
|
+
- Any financial institution, broker, or regulatory body.
|
|
55
|
+
All brand names, product trademarks, scrip symbols, and registered logos
|
|
56
|
+
belong exclusively to their respective statutory owners.
|
|
57
|
+
|
|
58
|
+
4. UPSTREAM COMPLIANCE & FAIR USAGE
|
|
59
|
+
Users of this library are solely and exclusively responsible for ensuring
|
|
60
|
+
their automated scripts and queries comply with all applicable local laws,
|
|
61
|
+
data privacy regulations, and the Terms of Service / Acceptable Use Policies
|
|
62
|
+
of any upstream web services or data providers.
|
|
63
|
+
For mission-critical, enterprise, commercial, or automated algorithmic
|
|
64
|
+
trading environments, users should license official authorized market data feeds.
|
bfinance-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: bfinance
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: High-performance Python SDK for Indian equities (NSE & BSE) โ a 1:1 drop-in replacement for yfinance supercharged with 10-year financials, concalls, and live market microstructure.
|
|
5
|
+
Author-email: bfinance contributors <community@bfinance.org>
|
|
6
|
+
License: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Keywords: bse,derivatives,finance,indian-stocks,investing,nse,options,quantitative-finance,screener,stock-market,yfinance
|
|
9
|
+
Classifier: Development Status :: 4 - Beta
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Intended Audience :: Financial and Insurance Industry
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Topic :: Office/Business :: Financial :: Investment
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Requires-Dist: beautifulsoup4>=4.12.0
|
|
21
|
+
Requires-Dist: httpx>=0.27.0
|
|
22
|
+
Requires-Dist: lxml>=5.2.0
|
|
23
|
+
Requires-Dist: openpyxl>=3.1.0
|
|
24
|
+
Requires-Dist: pandas>=2.2.0
|
|
25
|
+
Requires-Dist: pydantic>=2.7.0
|
|
26
|
+
Requires-Dist: tabulate>=0.9.0
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest-cov>=5.0.0; extra == 'dev'
|
|
30
|
+
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
31
|
+
Requires-Dist: ruff>=0.4.0; extra == 'dev'
|
|
32
|
+
Requires-Dist: yfinance>=1.7.0; extra == 'dev'
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
35
|
+
# ๐ฎ๐ณ `bfinance` (Bharat Finance)
|
|
36
|
+
|
|
37
|
+
<p align="center">
|
|
38
|
+
<b>The High-Performance Python SDK for Indian Equities (NSE & BSE)</b><br>
|
|
39
|
+
<i>A 1:1 drop-in replacement for <code>yfinance</code> (1.7.0+ compatible) supercharged with 10-year audited Ind AS financials, concalls with streamable audio MP3s, institutional stock screeners, multi-tab Excel models, and native AI/LLM data feeds.</i>
|
|
40
|
+
</p>
|
|
41
|
+
|
|
42
|
+
<p align="center">
|
|
43
|
+
<img src="https://img.shields.io/badge/Python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13-blue?style=flat-square" alt="Python Versions">
|
|
44
|
+
<img src="https://img.shields.io/badge/yfinance%20Parity-1.7.0%20Compatible-green?style=flat-square" alt="yfinance 1.7.0 Compatible">
|
|
45
|
+
<img src="https://img.shields.io/badge/Coverage-NSE%20%26%20BSE-orange?style=flat-square" alt="NSE and BSE">
|
|
46
|
+
<img src="https://img.shields.io/badge/Tests-54%2F54%20Passing-brightgreen?style=flat-square" alt="Tests Passing">
|
|
47
|
+
<img src="https://img.shields.io/badge/License-MIT-purple?style=flat-square" alt="MIT License">
|
|
48
|
+
</p>
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## ๐ Why `bfinance`?
|
|
53
|
+
|
|
54
|
+
Standard financial libraries like `yfinance` often fail Indian equity investors: Yahoo Finance truncates Indian financial statements to just **4โ5 years**, frequently experiences **missing fundamental data**, lacks **conference calls and shareholding patterns**, and breaks with upstream API changes.
|
|
55
|
+
|
|
56
|
+
`bfinance` solves this completely. It gives you the **exact same API as `yfinance` 1.7.0+** so your existing code, charting tools, and backtesters work with **zero code changes**, while giving you access to deep Indian corporate data:
|
|
57
|
+
|
|
58
|
+
| Dimension | `yfinance` (Standard) | `bfinance` (Supercharged) |
|
|
59
|
+
| :--- | :---: | :---: |
|
|
60
|
+
| **API Syntax Parity** | 1.7.0+ Standard | **100% Drop-in Equivalent** (`yf.Ticker` $\leftrightarrow$ `bf.Ticker`) |
|
|
61
|
+
| **Financial Statements Depth** | 4 to 5 Years (Standard Yahoo) | **10 to 13+ Years** (Audited Ind AS Statements) |
|
|
62
|
+
| **Quarterly Statement History**| 4 to 5 Quarters | **12 to 16+ Historical Quarters** |
|
|
63
|
+
| **Institutional Shareholding** | Basic / Often Empty | **12Q Quarterly & 11Y Annual Trends** (Promoter, FII, DII, Govt, Public) |
|
|
64
|
+
| **Conference Calls & Transcripts**| โ None | **40+ Concalls** with **Direct Audio MP3s**, BSE PDFs & Presentations |
|
|
65
|
+
| **Annual Reports & Credit Ratings**| โ None | **15+ Years Annual Report PDFs** & CRISIL/ICRA Credit Rationales |
|
|
66
|
+
| **Sector & Industry Hierarchy**| Generic Global Taxonomy | **4-Level Indian Taxonomy** + Index Memberships (`Nifty 50`, `Sensex`) |
|
|
67
|
+
| **Institutional Stock Screens**| โ None | **Built-in Screens**: Coffee Can, Magic Formula, Debt-Free, High Yield |
|
|
68
|
+
| **Custom Ratios & Scoring** | โ None | **Piotroski 9-Point Score**, **Graham Number**, **EV/EBITDA**, Screener search |
|
|
69
|
+
| **Excel Financial Modeling** | โ None | **1-Line Multi-Tab `.xlsx` Export** matching Screener "Export to Excel" |
|
|
70
|
+
| **AI / LLM Context Engine** | โ None | **Native Token-Dense Markdown/JSON Dossiers** & Prompt Factories |
|
|
71
|
+
| **Anti-Blocking Architecture** | โ None | **Persistent SQLite Cache** (24h TTL), User-Agent pool, Jitter pacing |
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## ๐ฆ Installation
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
# Using pip
|
|
79
|
+
pip install bfinance
|
|
80
|
+
|
|
81
|
+
# Using uv (recommended)
|
|
82
|
+
uv add bfinance
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
87
|
+
## โก 30-Second Quickstart (Zero-Change Migration from `yfinance`)
|
|
88
|
+
|
|
89
|
+
Simply replace `import yfinance as yf` with `import bfinance as yf`:
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
import bfinance as yf
|
|
93
|
+
|
|
94
|
+
# 1. Initialize any NSE or BSE ticker (supports RELIANCE, RELIANCE.NS, 500325.BO)
|
|
95
|
+
ticker = yf.Ticker("RELIANCE")
|
|
96
|
+
|
|
97
|
+
# 2. Exact yfinance 1.7.0 APIs work out of the box!
|
|
98
|
+
print("Live CMP:", ticker.fast_info.last_price)
|
|
99
|
+
print("Market Cap:", ticker.fast_info.market_cap)
|
|
100
|
+
|
|
101
|
+
# Historical OHLCV (Exact DataFrame schema with Dividends & Splits)
|
|
102
|
+
hist = ticker.history(period="1mo", actions=True)
|
|
103
|
+
print(hist.tail())
|
|
104
|
+
|
|
105
|
+
# 3. Access 10-Year Audited Financial Statements
|
|
106
|
+
print(ticker.financials) # 10+ Years Ind AS Annual Income Statement
|
|
107
|
+
print(ticker.balance_sheet) # 10+ Years Annual Balance Sheet
|
|
108
|
+
print(ticker.cashflow) # 10+ Years Cash Flow Statement
|
|
109
|
+
print(ticker.quarterly_income_stmt) # 12+ Quarters Results
|
|
110
|
+
|
|
111
|
+
# 4. Multi-ticker downloading (yf.download equivalent)
|
|
112
|
+
data = yf.download(["TCS", "INFY", "HDFCBANK"], period="5d")
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## ๐ Indian Market Superpowers
|
|
118
|
+
|
|
119
|
+
### 1. Conference Calls with Direct Audio MP3 Streaming
|
|
120
|
+
Access over 40+ historical quarterly earnings calls, download PDFs, and stream raw audio:
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
import bfinance as bf
|
|
124
|
+
|
|
125
|
+
stock = bf.Ticker("TCS")
|
|
126
|
+
|
|
127
|
+
for call in stock.concalls[:3]:
|
|
128
|
+
print(f"[{call.date}] {call.title}")
|
|
129
|
+
print(" โข PDF Transcript:", call.transcript_url)
|
|
130
|
+
print(" โข Audio MP3 Link:", call.audio_url)
|
|
131
|
+
|
|
132
|
+
# Download the latest concall audio MP3 straight to disk
|
|
133
|
+
stock.download_concall_audio(index=0, dest_path="./tcs_concall.mp3")
|
|
134
|
+
|
|
135
|
+
# Download the latest transcript PDF
|
|
136
|
+
stock.download_concall_transcript(index=0, dest_path="./tcs_transcript.pdf")
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
---
|
|
140
|
+
|
|
141
|
+
### 2. Dual Cadence Institutional Shareholding Trends
|
|
142
|
+
Track institutional accumulation across FIIs, Mutual Funds, and Promoters:
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
stock = bf.Ticker("RELIANCE")
|
|
146
|
+
|
|
147
|
+
# 12+ Quarters Distribution
|
|
148
|
+
print("Quarterly Shareholding (12Q):\n", stock.shareholding)
|
|
149
|
+
|
|
150
|
+
# 11+ Years Historical Long-Term Trend
|
|
151
|
+
print("Annual Shareholding (11Y):\n", stock.shareholding_yearly)
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
### 3. Complete 4-Level Sector Hierarchy & Index Memberships
|
|
157
|
+
```python
|
|
158
|
+
stock = bf.Ticker("RELIANCE")
|
|
159
|
+
|
|
160
|
+
print("Sector:", stock.sector) # Energy
|
|
161
|
+
print("Industry Group:", stock.industry_group) # Oil, Gas & Consumable Fuels
|
|
162
|
+
print("Industry:", stock.industry) # Petroleum Products
|
|
163
|
+
print("Sub-Industry:", stock.sub_industry) # Refineries & Marketing
|
|
164
|
+
print("Indices:", stock.indices) # ['BSE Sensex', 'Nifty 50', 'BSE 500', ...]
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
---
|
|
168
|
+
|
|
169
|
+
### 4. Custom Ratios & Quantitative Scoring Engine
|
|
170
|
+
Search Screener's 500+ ratio directory and compute advanced investment metrics:
|
|
171
|
+
|
|
172
|
+
```python
|
|
173
|
+
stock = bf.Ticker("RELIANCE")
|
|
174
|
+
|
|
175
|
+
# 1. Joseph Piotroski 9-Point F-Score
|
|
176
|
+
print("Piotroski Score:", stock.piotroski_score, "/ 9")
|
|
177
|
+
|
|
178
|
+
# 2. Benjamin Graham Maximum Fair Value
|
|
179
|
+
print("Graham Number: โน", stock.graham_number)
|
|
180
|
+
|
|
181
|
+
# 3. Enterprise Value & Multiples
|
|
182
|
+
print("Enterprise Value: โน", stock.enterprise_value, "Cr")
|
|
183
|
+
print("EV / EBITDA:", stock.ev_to_ebitda, "x")
|
|
184
|
+
print("Interest Coverage Ratio:", stock.interest_coverage, "x")
|
|
185
|
+
|
|
186
|
+
# 4. Search Screener's 500+ ratio catalog
|
|
187
|
+
results = bf.ratios.search("graham")
|
|
188
|
+
for r in results:
|
|
189
|
+
print(r["name"], "->", r["description"])
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
### 5. Institutional Stock Screeners
|
|
195
|
+
Run pre-built institutional strategies or custom filters:
|
|
196
|
+
|
|
197
|
+
```python
|
|
198
|
+
import bfinance as bf
|
|
199
|
+
|
|
200
|
+
# 1. Saurabh Mukherjea Coffee Can (10Y ROCE > 15% & ROE > 15%)
|
|
201
|
+
coffee_df = bf.screens.coffee_can.run(max_stocks=10)
|
|
202
|
+
print(coffee_df[['Symbol', 'Name', 'Price', 'ROCE_%', 'ROE_%']])
|
|
203
|
+
|
|
204
|
+
# 2. Joel Greenblatt Magic Formula (High ROCE + Attractive P/E)
|
|
205
|
+
magic_df = bf.screens.magic_formula.run(max_stocks=10)
|
|
206
|
+
|
|
207
|
+
# 3. Other built-in screens
|
|
208
|
+
bf.screens.debt_free_compounders.run()
|
|
209
|
+
bf.screens.high_dividend_yield.run()
|
|
210
|
+
bf.screens.undervalued_growth.run()
|
|
211
|
+
|
|
212
|
+
# 4. Custom Screener Predicate
|
|
213
|
+
growth_screen = bf.screens.custom(
|
|
214
|
+
name="High ROE Midcaps",
|
|
215
|
+
filter_fn=lambda t: (t.info.get("marketCapInCr") or 0) > 10000 and ((t.info.get("returnOnEquity") or 0) * 100) > 20
|
|
216
|
+
)
|
|
217
|
+
print(growth_screen.run(max_stocks=5))
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
### 6. 1-Line Multi-Tab Excel Financial Model Exporter
|
|
223
|
+
Export complete 10+ year statements and valuation ratios into an 8-sheet `.xlsx` workbook matching Screener's "Export to Excel":
|
|
224
|
+
|
|
225
|
+
```python
|
|
226
|
+
stock = bf.Ticker("RELIANCE")
|
|
227
|
+
stock.to_excel("Reliance_10Y_Financial_Model.xlsx")
|
|
228
|
+
```
|
|
229
|
+
*Generates sheets: `Overview`, `Profit & Loss`, `Quarters`, `Balance Sheet`, `Cash Flow`, `Shareholding`, `Ratios History`, and `Peers`.*
|
|
230
|
+
|
|
231
|
+
---
|
|
232
|
+
|
|
233
|
+
## ๐ค Native AI / LLM Data Feed Engine
|
|
234
|
+
|
|
235
|
+
Feed 100% of corporate data directly to AI agents (Gemini, Claude, GPT, DeepSeek, LangChain, LlamaIndex, CrewAI):
|
|
236
|
+
|
|
237
|
+
```python
|
|
238
|
+
stock = bf.Ticker("RELIANCE")
|
|
239
|
+
|
|
240
|
+
# 1. Generate token-dense Markdown financial dossier
|
|
241
|
+
markdown_dossier = stock.to_ai_context(format="markdown")
|
|
242
|
+
|
|
243
|
+
# 2. Or generate structured JSON dictionary
|
|
244
|
+
json_dossier = stock.to_ai_context(format="json")
|
|
245
|
+
|
|
246
|
+
# 3. Ready-to-run prompt templates
|
|
247
|
+
memo_prompt = stock.to_investment_memo_prompt() # Initiation Coverage Note
|
|
248
|
+
audit_prompt = stock.to_forensic_audit_prompt() # Forensic Accounting Check
|
|
249
|
+
concall_prompt = stock.to_concall_analyst_prompt() # Earnings Call Analysis
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
### AI Agent Function Calling Tools
|
|
253
|
+
```python
|
|
254
|
+
from bfinance.ai import BFinanceAITools
|
|
255
|
+
|
|
256
|
+
# Get native OpenAI / Gemini tool calling schemas
|
|
257
|
+
tools = BFinanceAITools.get_openai_tools()
|
|
258
|
+
|
|
259
|
+
# Execute tool call returned by LLM
|
|
260
|
+
result = BFinanceAITools.execute_tool(
|
|
261
|
+
name="get_stock_dossier",
|
|
262
|
+
arguments={"symbol": "TCS", "format": "markdown"}
|
|
263
|
+
)
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+
---
|
|
267
|
+
|
|
268
|
+
## ๐ก๏ธ Anti-Blocking & Zero-Crash Architecture
|
|
269
|
+
|
|
270
|
+
`bfinance` is engineered for production environments where reliability and uptime are paramount:
|
|
271
|
+
|
|
272
|
+
1. **Persistent SQLite Caching (`~/.cache/bfinance/cache.db`)**:
|
|
273
|
+
- Fundamentals cached for **24 hours**, search queries for **7 days**, chart timeseries for **6 hours**.
|
|
274
|
+
- **99% of requests resolve in < 1ms from disk cache** without touching remote servers.
|
|
275
|
+
2. **Adaptive Request Pacing & Jitter**:
|
|
276
|
+
- Automatic `150ms` pacing + `10โ50ms` Gaussian micro-jitter to prevent WAF burst detection.
|
|
277
|
+
3. **Desktop Browser Pool Rotation**:
|
|
278
|
+
- Automatically rotates realistic Chrome, Safari, Firefox, and Edge user-agents with complete browser headers.
|
|
279
|
+
4. **Exponential Backoff**:
|
|
280
|
+
- Recovers gracefully from HTTP 429 rate limits without aggressive retry spam.
|
|
281
|
+
5. **Zero-Crash Graceful Degradation (`raise_errors=False` default)**:
|
|
282
|
+
- Missing data, invalid symbols, or delisted companies log structured warnings via standard Python `logging` and return safe empty DataFrames/dictionaries instead of throwing uncaught exceptions.
|
|
283
|
+
|
|
284
|
+
---
|
|
285
|
+
|
|
286
|
+
## ๐ Detailed Documentation & Guides
|
|
287
|
+
|
|
288
|
+
* ๐ **[API Reference Manual](docs/API_REFERENCE.md)**: Exhaustive function-by-function guide.
|
|
289
|
+
* ๐ **[yfinance Migration Guide](docs/YFINANCE_MIGRATION_GUIDE.md)**: Step-by-step migration notes.
|
|
290
|
+
* ๐ค **[AI Agent Integration Guide](docs/AI_AGENT_INTEGRATION.md)**: Using `bfinance` with LangChain, LlamaIndex, CrewAI, and OpenAI/Gemini.
|
|
291
|
+
* ๐งช **[Contributing & Development](CONTRIBUTING.md)**: Testing and development setup.
|
|
292
|
+
|
|
293
|
+
---
|
|
294
|
+
|
|
295
|
+
## ๐งช Test Suite
|
|
296
|
+
|
|
297
|
+
`bfinance` maintains an exhaustive test suite with **54/54 tests passing**:
|
|
298
|
+
|
|
299
|
+
```bash
|
|
300
|
+
# Run full test suite with uv
|
|
301
|
+
uv run pytest
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
---
|
|
305
|
+
|
|
306
|
+
## ๐ License & Legal Disclaimers
|
|
307
|
+
|
|
308
|
+
### License
|
|
309
|
+
This project is licensed under the **MIT License**. See [`LICENSE`](LICENSE) for complete terms.
|
|
310
|
+
|
|
311
|
+
### โ ๏ธ Legal, Financial & Non-Affiliation Disclaimer
|
|
312
|
+
1. **Educational & Academic Purpose Only**: `bfinance` is an open-source software library developed strictly for academic, educational, and research purposes. It is **NOT** financial, investment, accounting, tax, or legal advice.
|
|
313
|
+
2. **No Investment Liability**: The developers, maintainers, and contributors are not SEBI-registered Research Analysts (RA) or Investment Advisors (RIA). No output from this library constitutes a recommendation or solicitation to buy, sell, or hold any security or financial derivative. Users assume **100% full responsibility** for their own financial decisions and trading operations. In no event shall the authors be liable for any direct, indirect, or consequential financial losses.
|
|
314
|
+
3. **Independent Project & Non-Affiliation**: `bfinance` is an independent open-source project and is **not affiliated, endorsed, authorized, or certified by** Yahoo! Inc., `yfinance`, Screener.in (Mittal Analytics), NSE India, BSE India, or any of their parent entities or subsidiaries. All product names, trademarks, ticker symbols, and brand logos belong to their respective owners.
|
|
315
|
+
4. **Data Verification & Fair Usage**: Data is fetched from publicly accessible endpoints. Users are responsible for complying with the Terms of Service and rate limits of any upstream platforms. For mission-critical commercial applications, users should subscribe to official authorized market data providers.
|