Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to get real-time Mutual Funds Information using Python?
Python provides powerful tools for accessing real-time mutual fund data through various APIs and libraries. The mftool module is particularly useful for Indian mutual funds, offering access to NAV data, scheme details, and historical performance from the Association of Mutual Funds in India (AMFI).
Installation
Before working with mutual fund data, install the required module ?
pip install mftool
Getting Started with Mftool
First, import the module and create an Mftool object ?
from mftool import Mftool
# Create Mftool object
mf = Mftool()
print("Mftool object created successfully")
Mftool object created successfully
Method 1: Getting Current Scheme Quote
Use get_scheme_quote() to fetch current NAV and basic information for a specific mutual fund scheme ?
from mftool import Mftool
mf = Mftool()
# Get current quote for scheme code 119551
quote_data = mf.get_scheme_quote('119551')
print("Scheme Name:", quote_data['scheme_name'])
print("NAV:", quote_data['nav'])
print("Date:", quote_data['last_updated'])
Scheme Name: Aditya Birla Sun Life Banking & PSU Debt Fund - Direct - IDCW NAV: 111.6462 Date: 08-May-2023
Method 2: Getting Detailed Scheme Information
Use get_scheme_details() to retrieve comprehensive scheme information ?
from mftool import Mftool
mf = Mftool()
# Get detailed information for scheme
details = mf.get_scheme_details("119551")
print("Fund House:", details['fund_house'])
print("Scheme Type:", details['scheme_type'])
print("Scheme Category:", details['scheme_category'])
print("Scheme Start Date:", details['scheme_start_date'])
Fund House: Aditya Birla Sun Life Mutual Fund Scheme Type: Open Ended Schemes Scheme Category: Debt Scheme - Banking and PSU Fund Scheme Start Date: 02-Jan-2013
Method 3: Historical NAV Data
Access historical Net Asset Value data using get_scheme_historical_nav() ?
from mftool import Mftool
mf = Mftool()
# Get historical NAV data
historical_data = mf.get_scheme_historical_nav("119551")
print("Fund House:", historical_data['fund_house'])
print("Recent NAV entries:")
# Display last 5 NAV records
for i, record in enumerate(historical_data['data'][:5]):
print(f"{i+1}. Date: {record['date']}, NAV: {record['nav']}")
Fund House: Aditya Birla Sun Life Mutual Fund Recent NAV entries: 1. Date: 08-05-2023, NAV: 111.64620 2. Date: 04-05-2023, NAV: 111.55600 3. Date: 03-05-2023, NAV: 111.53400 4. Date: 02-05-2023, NAV: 111.45510 5. Date: 28-04-2023, NAV: 111.38140
Getting All AMC Profiles
Retrieve information about all Asset Management Companies ?
from mftool import Mftool
mf = Mftool()
# Get all AMC profiles
amc_data = mf.get_all_amc_profiles(True)
print("Number of AMCs:", len(amc_data))
print("First few AMCs:")
# Display first 3 AMC names
for i, amc in enumerate(list(amc_data.keys())[:3]):
print(f"{i+1}. {amc}")
Number of AMCs: 44 First few AMCs: 1. Aditya Birla Sun Life Mutual Fund 2. HDFC Mutual Fund 3. ICICI Prudential Mutual Fund
Key Features Comparison
| Method | Function | Data Type |
|---|---|---|
get_scheme_quote() |
Current NAV & basic info | Real-time |
get_scheme_details() |
Comprehensive scheme info | Static |
get_scheme_historical_nav() |
Historical NAV data | Time series |
get_all_amc_profiles() |
All AMC information | Directory |
Conclusion
The mftool library provides an efficient way to access real-time and historical mutual fund data in Python. Use get_scheme_quote() for current NAV, get_scheme_historical_nav() for trend analysis, and combine methods for comprehensive investment research.
