The library for getting real time Mutual funds info
Installing mftool is very simple and it has no external dependencies. All its dependencies are part of standard python distribution.
pip install mftool
>>> from mftool import Mftool >>> mf = Mftool() >>> print mf Driver Class for The Association of Mutual Funds in India (AMFI)
Warning : Always use AMFI codes of schemes are presented here or use below function
>>> all_scheme_codes = mf.get_scheme_codes() # you can use as_json=True to get all codes in json format >>> print(all_scheme_codes)
Before going though other fundamental APIs. We will first see how to get a quote. Assume that we want to fetch current nav of ANY scheme. The only thing we need is Code for this company.
>>> q = mf.get_scheme_quote('119597') # it's ok to use both string or integer as codes. >>> print(q) {"scheme_code": "119597", "scheme_name": "xxxxxxxxxxxxx", "last_updated": "16-Aug-2019", "nav": "40.0138" }
>>> mf.get_scheme_details("117865") {'fund_house': 'xxxxxxxxxxxxx', 'scheme_type': 'IL&FS Mutual Fund', 'scheme_category': 'IDF', 'scheme_code': 117865, 'scheme_name': 'xxxxxxxxxxxxx - Growth Option', 'scheme_start_date': {'date': '10-09-2012', 'nav': '10.01030'} }
Get data as Dataframe
>>> df = mf.get_scheme_historical_nav("119597",as_Dataframe=True) >>> print(df) nav date 20-10-2021 82.30800 19-10-2021 83.97800 18-10-2021 85.41100 ... ...
Get data as JSON
>>> data = mf.get_scheme_historical_nav("119597",as_json=True) >>> print(data) {'fund_house': 'xxxxxxxxxxxxx', 'scheme_type': 'Open Ended Schemes', 'scheme_category': 'Debt Scheme - Banking and PSU Fund', 'scheme_code': 119597, 'scheme_name': 'xxxxxxxxxxxxx - Direct Plan-Dividend', 'scheme_start_date': {'date': '02-01-2013', 'nav': '103.00590'}, 'data': [{'date': '16-08-2019', 'nav': '149.33110'}, {'date': '14-08-2019', 'nav': '149.08090'}, {'date': '13-08-2019', 'nav': '149.45110'}, {'date': '09-08-2019', 'nav': '149.42480'}, . . . ] }
Note : Output has been truncated for better legibility.
Alternative, view historical data with one day change
>>> df = mf.history('0P0000XVAA',start=None,end=None,period='3mo',as_dataframe=True) >>> print(df) nav dayChange date 03-08-2021 78.269997 NaN 04-08-2021 77.545998 -0.723999 05-08-2021 77.081001 -0.464996 06-08-2021 77.349998 0.268997 . .
Note : To use mf.history(), we have to use new scheme codes presented here
To get daily Performance of open ended equity schemes for all AMCs
>>> value = mf.get_open_ended_equity_scheme_performance(True) >>> print(value) { "Large Cap": [{ "scheme_name": "xxxxxxxxxxxxxxxx", "benchmark": "NIFTY 50 Total Return", "latest NAV- Regular": "xxxxx", "latest NAV- Direct": "xxxxx", "1-Year Return(%)- Regular": "8.72", "1-Year Return(%)- Direct": "9.48", "3-Year Return(%)- Regular": "10.22", "3-Year Return(%)- Direct": "11.22", "5-Year Return(%)- Regular": "7.33", "5-Year Return(%)- Direct": "8.33" }, . . . . ], "Large & Mid Cap": [ { "scheme_name": "xxxxxxxxxxxxxxxxxx", "benchmark": "NIFTY Large Midcap 250 Total Return Index", "latest NAV- Regular": "xxxxx", "latest NAV- Direct": "xxxxx", "1-Year Return(%)- Regular": "13.45", "1-Year Return(%)- Direct": "14.45", "3-Year Return(%)- Regular": "9.15", "3-Year Return(%)- Direct": "10.35", "5-Year Return(%)- Regular": "8.32", "5-Year Return(%)- Direct": "9.41" }, . . ]}
>>> value = mf.get_open_ended_debt_scheme_performance(True) >>> print(value)
>>> value = mf.get_open_ended_hybrid_scheme_performance(True) >>> print(value)
>>> value = mf.get_open_ended_solution_scheme_performance(True) >>> print(value)