Automating Mutual Fund Tracking with mftool in Python

While manual API requests are great for learning, scaling your finance apps requires a more robust approach. mftool is a dedicated Python wrapper that simplifies AMFI data retrieval into a few lines of code.

pip install mftool # install MF tool library
While working at Colab platform we need to install this .
!pip install mftool deprecated yfinance # install required libraries

Initializing the Mftool Instance

This code initializes the mftool library by creating an instance of the Mftool class, which serves as the primary controller for all data operations. When mf = Mftool() is executed, the library automatically establishes a connection to the AMFI servers and downloads the master list of all available mutual fund schemes into your system's memory. Printing the mf object confirms that the instance is active and provides its memory address, signaling that the environment is ready for searching funds or fetching real-time NAV data.
from mftool import Mftool 
mf = Mftool() 
print(mf) # Displays the object status
Output
<mftool.mftool.Mftool object at 0x789aa20a0e60>
The get_scheme_codes() method fetches the entire AMFI database and stores it as a Python dictionary. It maps unique numerical Scheme Codes to their full Fund Names, allowing for instant data lookups. This master list serves as the foundation for searching and validating any mutual fund in your portfolio.
all_schemes = mf.get_scheme_codes() # Returns a dictionary: { "code": "name" } 
print(all_schemes)
From Scheme code ( key of the dictionary ) get the Scheme name ( value )
print(all_schemes['118955']) # Accessing fund name by its scheme code
The get_scheme_quote() method is the most efficient way to retrieve a real-time snapshot of a fund, returning a dictionary containing the latest NAV, fund name, and update date for any specific scheme code.
details = mf.get_scheme_quote("118955")
print(f"Fund: {details['scheme_name']}") 
print(f"Latest NAV: {details['nav']} Date : {details['last_updated']}")
Output
Fund: HDFC Flexi Cap Fund - Growth Option - Direct Plan
Latest NAV: 2283.796 Date : 09-Feb-2026

Automating Portfolio Valuation

This script automates the valuation of a multi-fund portfolio by iterating through a list of investment dictionaries. For each fund, it passes the schemeCode to the get_scheme_quote() method to fetch the real-time NAV, then multiplies that price by your owned units to calculate the current market value. The results are aggregated into a new list, scheme_data, providing a comprehensive snapshot that includes updated dates, precise NAVs, and total investment values for every holding.
input_schemes = [
    {"schemeCode": 120251, "schemeName": "ICICI Prudential Equity & Debt Fund Direct Growth", "Units": 100.02},
    {"schemeCode": 118955, "schemeName": "HDFC Flexi Cap Direct Plan Growth", "Units": 250.589},
    {"schemeCode": 120334, "schemeName": "ICICI Prudential Multi Asset Fund Direct Growth", "Units": 200.567}
]

scheme_data = []

for scheme in input_schemes:
    scheme_code = scheme['schemeCode']
    units = scheme['Units']

    # Get scheme details including NAV and last updated date
    details = mf.get_scheme_quote(str(scheme_code))

    # Extract information
    scheme_name = details['scheme_name']
    last_updated = details['last_updated']
    nav = float(details['nav'])

    # Calculate value
    value = units * nav

    # Store the processed data
    scheme_data.append({
        'Scheme Code': scheme_code,
        'Scheme Name': scheme_name,
        'Last Updated Date': last_updated,
        'NAV': nav,
        'Units': units,
        'Value': value
    })

# Print the collected data to verify
for data in scheme_data:
    print(data)
Output ( based on the nav data of the day )
{'Scheme Code': 120251, 'Scheme Name': 'ICICI Prudential Equity & Debt Fund - Direct Plan - Growth', 'Last Updated Date': '10-Feb-2026', 'NAV': 459.65, 'Units': 100.02, 'Value': 45974.193}
{'Scheme Code': 118955, 'Scheme Name': 'HDFC Flexi Cap Fund - Growth Option - Direct Plan', 'Last Updated Date': '10-Feb-2026', 'NAV': 2293.459, 'Units': 250.589, 'Value': 574715.597351}
{'Scheme Code': 120334, 'Scheme Name': 'ICICI Prudential Multi-Asset Fund - Direct Plan - Growth', 'Last Updated Date': '10-Feb-2026', 'NAV': 918.3019, 'Units': 200.567, 'Value': 184181.0571773}

Managing Investments with Excel or CSV Files

Keeping track of your savings is much simpler when using an Excel file, as it allows you to easily update your portfolio whenever you buy or sell schemes. By integrating Pandas with mftool, our script can automatically read your latest holdings, fetch live NAVs, and calculate the total current value of your entire portfolio in seconds.
You can download this sample Excel file to test the automation script:
!wget https://www.plus2net.com/python/download/input_schemes.xlsx # download sample excel file
By using Pandas library read_excel() or read_csv() functions we will get the details in a dataframe.
import pandas as pd

# Load the Excel file into a pandas DataFrame 
df_input_schemes = pd.read_excel('input_schemes.xlsx') 
display(df_input_schemes.head())

Full code is here.
scheme_data_from_excel = []

for index, scheme in df_input_schemes.iterrows():
    scheme_code = scheme['schemeCode'] 
    units = scheme['Units']

    # Get scheme details including NAV and last updated date
    details = mf.get_scheme_quote(str(scheme_code))

    # Extract information
    scheme_name = details['scheme_name']
    last_updated = details['last_updated']
    nav = float(details['nav'])

    # Calculate value
    value = units * nav

    # Store the processed data
    scheme_data_from_excel.append({
        'Scheme Code': scheme_code,
        'Scheme Name': scheme_name,
        'Last Updated Date': last_updated,
        'NAV': nav,
        'Units': units,
        'Value': value
    })

# Create a DataFrame from the collected data
df_investment_summary = pd.DataFrame(scheme_data_from_excel)

# Calculate the total investment value
total_investment_value = df_investment_summary['Value'].sum()

print("Investment Summary:")
display(df_investment_summary)
print(f"\nTotal Investment Value: {total_investment_value:.2f}")

By combining the mftool library with Pandas, you transform a static Excel sheet into a dynamic financial dashboard. This automated workflow eliminates the need for manual data entry, reduces the risk of calculation errors, and provides an instant "Grand Total" of your net worth across different fund houses. Whether you are tracking a few schemes or a complex portfolio, this script offers a professional, scalable solution for real-time investment monitoring.



Using Mututal Fund API Mutual Fund NAV Tracker using Tkinter GUI
Subhendu Mohapatra — author at plus2net
Subhendu Mohapatra

Author

🎥 Join me live on YouTube

Passionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.



Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2025   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer