Giter Club home page Giter Club logo

mftool's Introduction

Python library for getting realtime Mutual Funds data in India

Python Pypi Dependencies License Documentation Downloads

Introduction

mftool is a library for getting publically available real time Mutual Funds data in India. It can be used in various types of projects which requires getting live quotes for a given mutual fund scheme or build large data sets for further data analytics.

Features

  • Getting last updated quotes for Mutual fund scheme using scheme codes.
  • Return data in Dataframe, json and dictionary formats.
  • Getting quotes for all the schemes available with AMFI.
  • Helper APIs to check whether a given Scheme code is correct.
  • Getting all historical NAVs for a schemes.
  • Getting list of all schemes with there Scheme codes.
  • Get daily scheme performance.

Documentation

Related Projects -

  1. Forecasting of Mutual Funds here
  2. Predict Cryptocurrency in Indian Rupees here

Buy Me A Coffee

mftool's People

Contributors

dependabot[bot] avatar kk-ships avatar nayakwadis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

mftool's Issues

All functions are not working

Hello, I am using your library for a project of mine but certain functions such as get_mutual_fund_ranking() and get_average_aum() are showing mftool as no attribute for these functions. Could you please clarify soon
Thanks

Source for Scheme_codes.txt

Hi,

Different sources seem to have different data on the number of schemes. Where do you get the Scheme_codes.txt from?

Unable to fetch data from AMFI.

For the last few weeks, I am unable to fetch data from AMFI.

from mftool import Mftool
mf = Mftool()
mf.get_open_ended_debt_scheme_performance()
{'Long Duration': [], 'Medium to Long Duration': [], 'Medium Duration': [], 'Short Duration': [], 'Low Duration': [], 'Ultra Short Duration': [], 'Liquid': [], 'Money Market': [], 'Overnight': [], 'Dynamic Bond': [], 'Corporate Bond': [], 'Credit Risk': [], 'Banking and PSU': [], 'Floater': [], 'FMP': [], 'Gilt': [], 'Gilt with 10 year constant duration': []}
mf.get_open_ended_equity_scheme_performance()
{'Large Cap': [], 'Large & Mid Cap': [], 'Multi Cap': [], 'Mid Cap': [], 'Small Cap': [], 'Value': [], 'ELSS': [], 'Contra': [], 'Dividend Yield': [], 'Focused': []}
mf.get_open_ended_hybrid_scheme_performance()
{'Aggressive Hybrid': [], 'Balanced Hybrid': [], 'Conservative Hybrid': [], 'Equity Savings': [], 'Arbitrage': [], 'Multi Asset Allocation': []}

Can i contact you? :)

Hey Nayak, sorry to ping you like this :) i could not get your contact... i would like to contact you and work on this project, would you mind pinging me? my id srbharadwaj at gamil dot com

Update scheme code list.

There are some newer funds that aren't on the list.
For example -
edelweiss us technology equity fund of fund direct growth

get_scheme_info is not working as expected.

I am trying to execute get_scheme_info() for "0P0000XVYC" but it is not working .
I am getting :
"Exception: yfinance failed to decrypt Yahoo data response"

what could be the cause?

Sample code for reference:
mfToolObject = Mftool() scheme_info = mfToolObject.get_scheme_info("0P0000XVYC") print(scheme_info)

Find benchmark given scheme code

Hi,

Is there a way to get the benchmark of a scheme given its scheme code? I am trying to compare the historical performance of several funds with that of their benchmarks, and it would be helpful to easily find their benchmarks.

Thanks for developing and maintaining mftool!

Error while requesting for function get_scheme_info()

while requesting for any code for getting scheme info i'm getting this error: " UnboundLocalError: cannot access local variable 'response' where it is not associated with a value " . I'm getting error for each and every scheme code

code:
from mftool import Mftool
mf = Mftool()
data = mf.get_scheme_info('110024')
print(data)

[Feature Request] helper functions to calculate risk ratios

Hey, great work with the mftool lib.

Not sure if this fits in the scope or goals of the library, but it would be great if we can add helper functions for calculating risk ratio like alpha, beta, Sharpie Ration, Sortino Ratio, etc.

These can be generic functions that accept data for both the MF & returns against which the ratio is calculated.

This will be helpful for individuals or projects which use this library to analyze funds.

Add feature to use proxies

Hey, could you add in a feature to add a proxy dictionary to the requests. I am behind a firewall and need to pass all requests through a proxy for this to work.

Dirty data in scheme_category and scheme_type

After collating all the mutual funds through get_scheme_details() and then passing value_counts() for scheme_category and scheme_type we get the following results.

Income                                                            3483
IDF                                                               2592
1099 Days                                                          990
1                                                                  799
Growth                                                             496
Debt Scheme - Liquid Fund                                          443
Equity Scheme - Sectoral/ Thematic                                 412
Debt Scheme - Low Duration Fund                                    338
Debt Scheme - Ultra Short Duration Fund                            316
Debt Scheme - Short Duration Fund                                  251
Debt Scheme - Dynamic Bond                                         222
Debt Scheme - Overnight Fund                                       220
Equity Scheme - ELSS                                               206
Other Scheme - FoF Domestic                                        196
Debt Scheme - Corporate Bond Fund                                  194
Debt Scheme - Banking and PSU Fund                                 192
Debt Scheme - Money Market Fund                                    192
Hybrid Scheme - Aggressive Hybrid Fund                             187
Hybrid Scheme - Arbitrage Fund                                     180
Debt Scheme - Credit Risk Fund                                     171
Equity Scheme - Multi Cap Fund                                     164
Hybrid Scheme - Equity Savings                                     158
Equity Scheme - Large Cap Fund                                     148
Debt Scheme - Medium Duration Fund                                 141
Debt Scheme - Gilt Fund                                            135
Hybrid Scheme - Conservative Hybrid Fund                           132
Other Scheme - Index Funds                                         130
Equity Scheme - Large & Mid Cap Fund                               124
Equity Scheme - Mid Cap Fund                                       109
Debt Scheme - Medium to Long Duration Fund                         107
Other Scheme - FoF Overseas                                        107
Hybrid Scheme - Dynamic Asset Allocation or Balanced Advantage     104
ELSS                                                               102
Equity Scheme - Small Cap Fund                                      99
Equity Scheme - Focused Fund                                        91
Other Scheme - Other  ETFs                                          83
Solution Oriented Scheme - Retirement Fund                          80
Debt Scheme - Floater Fund                                          76
Equity Scheme - Value Fund                                          64
Direct                                                              58
5 Year Plan                                                         56
Hybrid Scheme - Multi Asset Allocation                              53
1150 DAYS                                                           52
Half Yearly Dividend                                                38
Debt Scheme - Gilt Fund with 10 year constant duration              35
1194 DAYS                                                           32
Debt Scheme - Long Duration Fund                                    24
Equity Scheme - Dividend Yield Fund                                 24
1098 Days                                                           21
Solution Oriented Scheme - Children’s Fund                          20
DIRECT                                                              17
Liquid                                                              16
1111 DAYS                                                           15
Gilt                                                                13
Equity Scheme - Contra Fund                                         12
Other Scheme - Gold ETF                                             11
Hybrid Scheme - Balanced Hybrid Fund                                11
1100 Days                                                           10
Formerly Super Institutional Plan                                    8
FV Rs 32.161                                                         7
54EB Growth                                                          6
erstwhile Cash Option                                                6
Payout                                                               4
91 Days                                                              3
G                                                                    3
Compulsory Reinvestment                                              3
1100 DAYS                                                            2
Equity Scheme - Focussed Fund                                        1
Div                                                                  1
Merger of Capex & Energy Opportunities                               1
Annual Dividend                                                      1
Open Ended Schemes                                                                                   6229
Close Ended Schemes                                                                                  3775
IL&FS Mutual Fund                                                                                    2590
135488;INF174K01Y15;-;Kotak FMP Series 180                                                            986
141923;INF179KB1W87;-;HDFC HOF - I - 1140D November 2017                                              755
Interval Fund Schemes                                                                                  68
112659;INF090I01403;-;Franklin India Fixed Tenure Fund - Series XII - Plan C                           56
142488;INF200KA1SK1;-;SBI DEBT FUND SERIES C - 9                                                       52
141581;INF179KB1V39;-;HDFC EOF - II - 1100D June 2017                                                  44
125254;INF174K01YR7;INF174K01YS5;Kotak Bond Short Term Plan-                                           38
144152;INF194KA14U2;-;IDFC EQUITY OPPORTUNITY SERIES 6                                                 32
132800;INF205K01L62;-;Invesco India Fixed Maturity Plan-Series 24-Plan F                               21
119416;INF955L01AN6;-;BARODA PIONEER LIQUID FUND - PLAN B                                              17
131466;INF200K011U0;-;SBI DEBT FUND SERIES A - 44                                                      15
119341;INF955L01AD7;-;BARODA PIONEER GILT FUND - Plan B                                                12
119337;INF955L01AA3;-;Baroda Pioneer Dynamic Bond Fund - Plan B                                        11
134838;INF174K01R71;-;Kotak FMP Series 175                                                             10
140463;INF955L01GU8;-;Baroda Pioneer Short Term Bond Fund - Plan B -                                    7
101281;INF179K01LA9;-;HDFC Index FundSensex Plan                                                        7
103182;-;-;Aditya Birla Sun Life Income Fund-Plan G                                                     6
101221;INF109K01TW3;-;ICICI Prudential Money Market Fund Retail Growth                                  6
103394;-;INF903J01GX6;Sundaram Money Fund Regular weekly Dividend. Rein                                 5
120471;INF192K01EA7;-;JM Short Term Fund                                                                5
133524;INF955L01GA0;-;Baroda Pioneer Credit Risk Fund -Plan B-                                          5
133662;INF174K01G82;-;Kotak FMP Series 171                                                              4
113483;-;INF251K01DM8;BNP PARIBAS LOW DURATION Fund-Regular Plan- Daily Dividend Option                 3
143611;-;INF192K01DU7;JM Low Duration Fund                                                              3
105556;INF903J01JO9;INF903J01EQ5;Sundaram Low Duration Fund Regular Weekly Dividend                     3
130158;INF200K016J2;-;SBI Debt Fund Series A - 29                                                       3
102055;INF200K01743;-;SBI Magnum Income Plus Fund - Savings Plan                                        3
120455;-;INF192K01DM4;JM Ultra Short Duration Fund -                                                    3
135174;INF192K01KQ0;INF192K01KR8;JM Arbitrage Fund                                                      2
119362;INF955L01BQ7;-;BARODA PIONEER INCOME FUND - Plan B                                               2
120492;INF192K01CC7;-;JM Multicap Fund                                                                  2
134664;INF192K01JY6;INF192K01KB2;JM G-Sec Fund -                                                        2
130983;INF200K010P2;-;SBI DEBT FUNDS SERIES A - 39                                                      2
IIFCL Mutual Fund                                                                                       2
139259;INF192K01LC8;-;JM Liquid Fund Unclaimed Redemption IEF                                           2
100042;INF209K01ME4;-;Aditya Birla Sun Life Liquid Fund-Retail                                          1
129210;INF903J01F76;INF903J01F84;Sundaram Infrastructure Advantage Fund                                 1
119326;INF955L01948;-;BARODA PIONEER HYBRID EQUITY FUND - Plan B                                        1
138655;INF663L01SO6;-;DHFL Pramerica Hybrid Fixed Term Fund - Series 19 - Regular Plan - Dividend       1
102546;INF090I01692;-;Franklin India Life Stage Fund of Funds The 50s Plus Flo                          1
138534;INF223JA1669;-;DHFL Pramerica Hybrid Fixed Term Fund - Series 4 - Dividend                       1
100062;-;INF209K01DQ7;Aditya Birla Sun Life Gilt Plus-Regular Plan                                      1
119390;INF955L01AO4;-;BARODA PIONEER CONSERVATIVE HYBRID FUND - Plan B                                  1
138985;INF223JA1AR0;-;DHFL Pramerica Large Cap Fund - Series 1 - Direct Plan - Dividend                 1
138988;INF223JA1AP4;-;DHFL Pramerica Large Cap Fund - Series 1 - Regular Plan - Dividend                1

getting import error due to relative import

from .utils import Utilities, is_holiday, get_today, get_friday, render_response
ImportError: attempted relative import with no known parent package

I am getting ImportError as the utils.py module is being import using relative path.

Adjusting navs

Hi!

First, I wanted to say thanks for this awesome library! Just wanted to show some appreciation before I get into the weeds.

Sorry, that was a bug on my end.

Thanks again!

Unable to download performance data

Thanks for the update on performance data (issue #23 ). But apologies, I'm not a tech guy.
I upgraded the Python library installed on my system (using pip install --upgrade mftool), but that didn't work. Can you suggest what else I can do?

Results not being populated for couple of MFs

Hi,
I have been using your API for the last few months and it is really fantastic as I have never got a single issue until yesterday. Appreciate your awesome work. I recently tried with couple of mutual funds but I am not getting results out of it and instead the result set is empty. Can you please check and resolve at the earliest ?

MF numbers - 119066 ('HDFC Childrens Gift Fund - Direct Plan') and 120724 ('UTI CCF Investment Plan - Direct Plan - Growth Option')

FYI : I'm using the latest version of the package.

Addition of fund manager details

The get scheme details functions works well and provides most of the necessary information.

But an important, detail, the fund manager name and tenure at the MF is missing.

Is there any way we can add these 2 data points?

It's a common data point on most websites - https://www.valueresearchonline.com/funds/14890/axis-banking-and-psu-debt-fund?utm_source=direct-click&utm_medium=funds&utm_term=&utm_content=Axis+Banking+%26+PSU+Debt+Reg&utm_campaign=vro-search#fund-manager

Is there any alternative to mfapi ?

Since few days https://api.mfapi.in/mf/ is not reachable looks like it was an open API and is no longer alive. This project majorly relies on that API, are there any alternative APIs to it we can use instead of the mfapi.in ? Or if anyone is aware of who was the owner of that open api, to reach out incase if they are looking for maintainers.

KeyError: 'user_agent'

Error:
File "/Users/vkamlesh/src/finpy/list_key.py", line 7, in
mf = Mftool()
File "/Users/vkamlesh/src/finpy/mftodef get_open_ended_solution_scheme_performance(self, as_json=False):
"""

Implementing functionality for Solution-oriented and Other category funds.

def get_open_ended_solution_scheme_performance(self, as_json=False):
    """
    gets the daily performance of open ended Solution-Oriented schemes for all AMCs
    :return: json format
    :raises: HTTPError, URLError
    """
    get_open_ended_solution_scheme_url = self._get_open_ended_equity_scheme_url.replace('SEQ','SOLU')
    scheme_performance = {}
    for key in self._open_ended_solution_category.keys():
        scheme_performance_url = get_open_ended_solution_scheme_url.replace('CAT',self._open_ended_solution_category[key])
        scheme_performance[key] = self.get_daily_scheme_performance(scheme_performance_url, False)
    return self.render_response(scheme_performance,as_json)


def get_open_ended_other_scheme_performance(self, as_json=False):
    """
    gets the daily performance of open ended index and FoF schemes for all AMCs
    :return: json format
    :raises: HTTPError, URLError
    """
    get_open_ended_other_scheme_url = self._get_open_ended_equity_scheme_url.replace('SEQ','OTH')
    scheme_performance = {}
    for key in self._open_ended_solution_category.keys():
        scheme_performance_url = get_open_ended_other_scheme_url.replace('CAT',self._open_ended_other_category[key])
        scheme_performance[key] = self.get_daily_scheme_performance(scheme_performance_url, False)
    return self.render_response(scheme_performance,as_json)    

remove ETF from get_open_ended_other_scheme_performance() and create separate function for ETF

Can we move ETF into a different function?
Problem Statement: In case if someone requires information such as NAV,1/3/5 years return for a direct option and ETF. It would require to dump all data and filter out (latest NAV- Regular','1-Year Return(%)- Regular','3-Year Return(%)- Regular','5-Year Return(%)- Regular). Due to filtration, ETF performance can't be capture.
code snippet

Attached excel file.
Other_Fund_Direct_Performance.xlsx

KeyError on 77 schemes

Firstly, thanks for this helpful tool.

The below command shows that an MF exists with code 120626.

list(mf.get_scheme_codes().keys())[5587:5588]

['120626']

But it throws a key error when retrieving the details.


mf.get_scheme_details(120626)

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
 in 
----> 1 mf.get_scheme_details(120626)

~\miniconda3\lib\site-packages\mftool\mftool.py in get_scheme_details(self, code, as_json)
    131             response = self._session.get(url).json()
    132             scheme_data = response['meta']
--> 133             scheme_info['fund_house'] = scheme_data['fund_house']
    134             scheme_info['scheme_type'] = scheme_data['scheme_type']
    135             scheme_info['scheme_category'] = scheme_data['scheme_category']

KeyError: 'fund_house'

77 MF schemes are generating this error. I have attached a CSV file with the scheme code and scheme name for these 77 schemes.
failed.zip

Move constants to a json file?

Can we move the below constants to a json file
so that in case url changes or a new AMC is added, we dont need to update the 'mftool' as such but can just edit the file
Idea is to separate all constants and logic to different files

for amc in [3,53,1,4,59,46,32,6,47,54,27,9,37,20,57,48,68,62,65,63,42,70,16,17,56,18,69,45,55,21,58,64,10,13,35,
                    22,66,33,25,26,61,28,71]:
# URL list
        self._get_quote_url = 'https://www.amfiindia.com/spages/NAVAll.txt'
        self._get_scheme_url = 'https://api.mfapi.in/mf/'
        self._get_amc_details_url = 'https://www.amfiindia.com/modules/AMCProfileDetail'
        self._get_fund_ranking = 'https://www.crisil.com/content/crisil/en/home/what-we-do/financial-products' \
                                 '/mf-ranking/_jcr_content/wrapper_100_par/tabs/1/mf_rating.mfRating.json'
        self._get_open_ended_equity_scheme_url = 'http://www.valueresearchonline.com/amfi/fund-performance-data/?' \
                                                 'end-type=1&primary-category=SEQ&category=CAT&amc=ALL'
        self._open_ended_equity_category = {'Large Cap': 'SEQ_LC','Large & Mid Cap': 'SEQ_LMC',
                                            'Multi Cap': 'SEQ_MLC','Mid Cap': 'SEQ_MC',
                                            'Small Cap': 'SEQ_SC','Value': 'SEQ_VAL',
                                            'ELSS': 'SEQ_ELSS','Contra': 'SEQ_CONT',
                                            'Dividend Yield': 'SEQ_DIVY','Focused': 'SEQ_FOC'}
        self._open_ended_debt_category = {'Long Duration' : 'SDT_LND', 'Medium to Long Duration': 'SDT_MLD',
                                          'Medium Duration':'SDT_MD','Short Duration':'SDT_SD',
                                          'Low Duration': 'SDT_LWD', 'Ultra Short Duration':'SDT_USD',
                                          'Liquid':'SDT_LIQ', 'Money Market':'SDT_MM',
                                          'Overnight':'SDT_OVNT', 'Dynamic Bond':'SDT_DB',
                                          'Corporate Bond':'SDT_CB', 'Credit Risk':'SDT_CR',
                                          'Banking and PSU':'SDT_BPSU', 'Floater':'SDT_FL',
                                          'FMP':'SDT_FMP', 'Gilt':'SDT_GL',
                                          'Gilt with 10 year constant duration': 'SDT_GL10CD'}
        self._open_ended_hybrid_category= {'Aggressive Hybrid':'SHY_AH','Balanced Hybrid':'SHY_BH',
                                            'Conservative Hybrid':'SHY_CH','Equity Savings':'SHY_EQS',
                                            'Arbitrage':'SHY_AR','Multi Asset Allocation':'SHY_MAA'}

Scheme categories are wrong for many mutual funds

Set of all scheme category:
{'Debt Scheme - Overnight Fund', 'FV Rs 32.161', 'Equity Scheme - Dividend Yield Fund', 'Hybrid Scheme - Equity Savings', 'Debt Scheme - Ultra Short Duration Fund', 'Equity Scheme - Large Cap Fund', 'ank', 'Other Scheme -
FoF Overseas', '1098 Days', 'IDF', 'Debt Scheme - Money Market Fund', 'Debt Scheme - Medium Duration Fund', 'Debt Scheme - Corporate Bond Fund', 'Debt Scheme - Dynamic Bond', 'Equity Scheme - Small Cap Fund', 'Debt Scheme

  • Medium to Long Duration Fund', 'Debt Scheme - Liquid Fund', '1194 DAYS', 'Direct', '1100 Days', 'Equity Scheme - ELSS', 'Hybrid Scheme - Arbitrage Fund', 'Equity Scheme - Value Fund', 'Growth', 'ELSS', 'Half Yearly Dividend', 'Hybrid Scheme - Multi Asset Allocation', 'Income', 'Hybrid Scheme - Dynamic Asset Allocation or Balanced Advantage', 'Debt Scheme - Short Duration Fund', 'Solution Oriented Scheme - Children’s Fund', 'Debt Scheme -
    Gilt Fund with 10 year constant duration', 'Hybrid Scheme - Aggressive Hybrid Fund', 'Hybrid Scheme - Balanced
    Hybrid Fund', 'Equity Scheme - Mid Cap Fund', 'Debt Scheme - Gilt Fund', '1', 'Other Scheme - Index Funds', 'Equity Scheme - Contra Fund', 'Equity Scheme - Multi Cap Fund', 'Other Scheme - FoF Domestic', 'Solution Oriented Scheme - Retirement Fund', 'Debt Scheme - Low Duration Fund', 'Debt Scheme - Credit Risk Fund', '1099 Days', 'Formerly Known as IIFL Mutual Fund', 'Gilt', 'Hybrid Scheme - Conservative Hybrid Fund', 'Equity Scheme - Large & Mid Cap Fund', 'Debt Scheme - Banking and PSU Fund', 'Debt Scheme - Long Duration Fund', 'Debt Scheme - Floater Fund'}

AUM data

Hi! Your library is fantastic and very useful. However, I'm unable to fetch AUM data for the mutual funds. Is there a remedy for this?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.