How to get real-time Mutual Funds Information using Python?


Python is a computer language that may be used to obtain real-time data about mutual funds by utilising a variety of programming libraries and APIs. Python is a well-liked programming language that provides a wide range of effective tools for data analysis and visualisation, making it the perfect option for working with financial data like mutual fund statistics.

You can use APIs like the Yahoo Finance API or the Alpha Vantage API to obtain real-time mutual fund data. With the help of these APIs, you can get real-time information about a variety of mutual funds, including their current price, historical price data, and other crucial characteristics like their performance over time.

Algorithm to get real-time Mutual Funds Information using Python

You can use Python to obtain real-time mutual fund information by following a few algorithmic steps. Some of the steps are as follows −

Step 1 − Select the data you want to retrieve: Prior to beginning the coding process, select the precise data from the mutual fund data that you wish to retrieve. This could contain information such as the fund's name, symbol, price, NAV, expense ratio, and other crucial stats.

Step 2 − Select an API: After deciding on the precise data you wish to access, you must select an API that offers this data's availability. To get real-time mutual fund data, APIs like those offered by Alpha Vantage or Yahoo Finance are frequently used.

Step 3 − Obtain an API key: You normally need to do this in order to access the data via the API. Your requests will be authenticated using this key to make sure you have the right to access the information.

Step 4 − Submit a request to the API: You can submit a request to the API using the Python requests package, along with your API key and the required parameters, to get the information you need.

Step 5 − Parse the response: As soon as the API sends you a response, you must parse the data to draw out the particular details in which you are interested. To organise and shape the data into a more useful format, you can use Python's pandas package.

Step 6 − Save the data: Once you have the data you require, you may save it in a database or CSV file for analysis or visualisation in the future.

Step 7 − Automate the procedure: Using Python's scheduling tools, such as cron or Windows Task Scheduler, you can continuously receive real-time mutual fund data by automating the procedure. With no need for manual involvement, you will be able to access and store the data on a regular basis.

Using Python, you may obtain real-time mutual fund information by following the stages in the algorithm. You can continually receive and analyse real-time mutual fund data for investment decisions by deciding on the data you want to retrieve, selecting an API, obtaining an API key, sending a request to the API, parsing the answer, saving the data, and automating the process.

Approaches to get real-time Mutual Funds Information

To access real-time Mutual Funds Information, we will create Python programmes. Investors today frequently use the word "mutual funds," therefore let's provide some assistance to them. Real-time data from AFM (Association of Mutual Funds) will be collected with the aid of Mftool Modules.

Get the most recent quotes from Mutual Funds utilising scheme codes using Mftool's features.

Get all of the AMF's registered schemes, the history of Net Asset Value (NAV), and a complete list of schemes with their scheme codes.

However, before we explain various methods for obtaining real-time information on mutual funds, you must install the following module in your terminal −

Syntax

pip install mftool

Approach 1

We will begin our first approaches by creating an object for Mftool by importing a module.

!pip install mftool
# import module
from mftool import Mftool

obj = Mftool()

Using the get_scheme_quote() methods to obtain a Scheme Quote.

Note: This page includes all scheme codes.

# pass the scheme code into
# methods
data = obj.get_scheme_quote('119551')
print(data)

Output

Note − the output might be different each time you run it, as it depends upon the module mftool

Use the get_scheme_details() methods to retrieve Scheme Details for a certain Scheme code.

obj.get_scheme_details("119551")

Output

Approach 2

Utilise the get_scheme_historical_nav() methods to access the data for Scheme Historical NAV.

data = obj.get_scheme_historical_nav("119551")
print(data)

Output

{'fund_house': 'Aditya Birla Sun Life Mutual Fund', 'scheme_type': 'Open Ended Schemes', 
'scheme_category': 'Debt Scheme - Banking and PSU Fund', 'scheme_code': 119551, 'scheme_name': 
'Aditya Birla Sun Life Banking & PSU Debt Fund  - DIRECT - IDCW', 'scheme_start_date': {'date': 
'02-01-2013', 'nav': '103.00590'}, 'data': [{'date': '08-05-2023', 'nav': '111.64620'}, {'date': '04-
05-2023', 'nav': '111.55600'}, {'date': '03-05-2023', 'nav': '111.53400'}, {'date': '02-05-2023', 
'nav': '111.45510'}, {'date': '28-04-2023', 'nav': '111.38140'}, {'date': '27-04-2023', 'nav': 
'111.37470'}, {'date': '26-04-2023', 'nav': '111.31570'}, {'date': '25-04-2023', 'nav': '111.28450'}, 
{'date': '24-04-2023', 'nav': '111.24440'}, {'date': '21-04-2023', 'nav': '111.11770'}, {'date': '20-
04-2023', 'nav': '111.06950'}, {'date': '19-04-2023', 'nav': '111.06690'}, {'date': '18-04-2023', 
'nav': '111.02900'}, {'date': '17-04-2023', 'nav': '110.99470'}, {'date': '13-04-2023', 'nav': 
'110.92730'}, {'date': '12-04-2023', 'nav': '110.91340'}, {'date': '11-04-2023', 'nav': '110.84700'}, 
{'date': '10-04-2023', 'nav': '110.83390'}, {'date': '06-04-2023', 'nav': '110.76920'}, {'date': '05-
04-2023', 'nav': '110.54930'}, {'date': '03-04-2023', 'nav': '110.43690'}, {'date': '31-03-2023', 
'nav': '110.38870'}, {'date': '29-03-2023', 'nav': '110.25250'}, {'date': '28-03-2023', 'nav': 
'110.11560'}, {'date': '27-03-2023', 'nav': '110.14690'}, {'date': '24-03-2023', 'nav': '110.07940'}, 
{'date': '23-03-2023', 'nav': '110.06250'}, {'date': '21-03-2023', 'nav': '109.98100'}, {'date': '20-
03-2023', 'nav': '109.95090'}, {'date': '17-03-2023', 'nav': '109.83660'}, {'date': '16-03-2023', 
'nav': '109.79880'}, {'date': '15-03-2023', 'nav': '109.81230'}, {'date': '14-03-2023', 'nav': 
'109.78890'}, {'date': '13-03-2023', 'nav': '109.73450'}, {'date': '10-03-2023', 'nav': '109.57690'}, 
{'date': '09-03-2023', 'nav': '109.54100'}, {'date': '08-03-2023', 'nav': '109.51030'}, {'date': '06-
03-2023', 'nav': '109.53130'}, {'date': '03-03-2023', 'nav': '109.48740'}, {'date': '02-03-2023', 
'nav': '109.44700'}, {'date': '01-03-2023', 'nav': '109.43000'}, {'date': '28-02-2023', 'nav': 
'109.44420'}, {'date': '27-02-2023', 'nav': '109.43410'}, {'date': '24-02-2023', 'nav': '109.42340'}, 
{'date': '23-02-2023', 'nav': '109.40900'}, {'date': '22-02-2023', 'nav': '109.38180'}, {'date': '21-
02-2023', 'nav': '109.41820'}, {'date': '20-02-2023', 'nav': '109.37800'}, {'date': '17-02-2023', 
'nav': '109.29240'}, {'date': '16-02-2023', 'nav': '109.32430'}, {'date': '15-02-2023', 'nav': 
'109.29290'}, {'date': '14-02-2023', 'nav': '109.24800'}, {'date': '13-02-2023', 'nav': '109.28260'}, 
{'date': '10-02-2023', 'nav': '109.24120'}, {'date': '09-02-2023', 'nav': '109.24460'}, {'date': '08-
02-2023', 'nav': '109.24720'}, {'date': '07-02-2023', 'nav': '109.28260'}, {'date': '06-02-2023', 
'nav': '109.26620'}, {'date': '03-02-2023', 'nav': '109.24250'}, {'date': '02-02-2023', 'nav': 
'109.21860'}, {'date': '01-02-2023', 'nav': '109.18490'}, {'date': '31-01-2023', 'nav': '109.06780'}, 
{'date': '30-01-2023', 'nav': '109.00720'}, {'date': '27-01-2023', 'nav': '108.97870'}, {'date': '25-
01-2023', 'nav': '108.99620'}, {'date': '24-01-2023', 'nav': '108.99950'}, {'date': '23-01-2023', 
'nav': '108.98030'}, {'date': '20-01-2023', 'nav': '108.93350'}, {'date': '19-01-2023', 'nav': 
'108.95780'}, {'date': '18-01-2023', 'nav': '108.92900'}, {'date': '17-01-2023', 'nav': '108.90980'}, 
{'date': '16-01-2023', 'nav': '108.89450'}, {'date': '13-01-2023', 'nav': '108.84410'}, {'date': '12-
01-2023', 'nav': '108.81540'}, {'date': '11-01-2023', 'nav': '108.76820'}, {'date': '10-01-2023', 
'nav': '108.74090'}, {'date': '09-01-2023', 'nav': '108.71890'}, {'date': '06-01-2023', 'nav': 
'108.62350'}, {'date': '05-01-2023', 'nav': '108.64050'}, {'date': '04-01-2023', 'nav': '108.62620'}, 
{'date': '03-01-2023', 'nav': '108.62700'}, {'date': '02-01-2023', 'nav': '108.59220'}, {'date': '30-
12-2022', 'nav': 

We can now alter this data to suit our needs.

# dict demonstration
data['fund_house']

Output

Aditya Birla Sun Life Mutual Fund

With the get_all_amc_profiles() module, all AMC profiles.

data = obj.get_all_amc_profiles(True)
print(data)

Output

Conclusion

Several APIs that offer access to financial data can be used to obtain real-time mutual fund information in Python. The Alpha Vantage API is a well-liked API that provides historical and real-time data for stocks, mutual funds, and other financial instruments. You must receive an API key in order to utilize the Alpha Vantage API in Python. You can accomplish this by signing up on their website. Once you have the API key, you can send HTTP requests and obtain data from the API using the Python Requests package.

Updated on: 24-Jul-2023

492 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements