You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
Gourav Kumar 7898546799 backup 2 years ago
.env.sample added Readme and sample env file 2 years ago
.gitignore First commit 2 years ago
.pylintrc Added docstrings, made changes for pylint 2 years ago
Dockerfile Added Dockerfile for docker image creation: 2 years ago
mf_bot.py Added docstrings, made changes for pylint 2 years ago
readme.md backup 2 years ago
requirements.txt updated requirements 2 years ago

readme.md

Telegram India Mutual Funds Bot

This is a Telegram bot which allows you to search for any open ended mutual funds in India and get their returns, both CAGR as well as SIP returns.

Notable features of the bot

The search feature relies on PostgreSQL Full Text Search functionality. It utilizes a pre-computed column of ts_vector docs which includes the fund name, fund category, and fund sub-category. This allows users to search for a fund of a particular category even if they don't know the name. For example, searching for Birla large will return Birla Frontline Equity Fund.

The ts_vector column also utilizes a gin index to make the text search blazingly fast.

The search feature also ensures that the search is agnostic to word order. So you can search for large cap birla and still get the results above. This handles cases where some funds are named Direct plan growth option and some are named growth direct. The search also handled specific confusing cases like difference in how funds spell midcap (mid-cap, mid cap, midcap, etc.) and excludes the word fund. It also employs a negation parameter, allowing the user to exclude certiain words/characters using - symbol. So searching for Mirae large -emerging will exclude Mirae Emerging Bluechip Fund from the results.

Return calculation

Returns calculation offloads bulk of the calculation to SQL since this removes the overload of fetching the entire data and converting them to Numpy arrays. only iterative calculations are performed inside the Python script. The return calculation SQL query therefore gives only the relevant NAVs. The SIP return calculation also adds amount and units column inside the query itself and returns only the relevant dates. Window functions are extensively utilized to perform these calculations in the query.

The resulting array is then sliced in Numpy array to perform the final XIRR calculation. The XIRR function also utilizes numpy array to vectorize calculations and perform it at blazingly fast speeds. All this combined means that SIP returns calculation for 1-3-5-7-10 years takes an average of 50 milliseconds for any fund.

Usage and deployment

How to use

To get started, visit @india_mf_bot on Telegram. Type @india_mf_bot and start typing the fund name to search for a fund. It's an inline search, so do not send the message. Just select a fund from the list that shows up. The basic info for the selected fund will show up. It will also have two buttons for returns and SIP returns. These will be shown inside the original message itself.

How to deploy

The bot can either be deployed as it is, or can be containerized. To bot relies on a PostgreSQL Database which has a list of funds, their categories and sub-categories, their entire NAV history, etc.

To run the bot:

  1. Clone this repository
  2. Rename .env.sample to .env
  3. Get a token from the BotFather channel on Telegram. This will need to be copied to the env file.
  4. Add the database credentials to the env file as well.
  5. Create a virtual environment
  6. Install all the dependencies from requirements.txt
  7. Run the mf_bot.py script

To run the bot in a container:

  1. Carry out steps 1-4 in the previous list
  2. run the build command docker build -t word-bot .
  3. run the container using docker run -d --env-file ./.env --add-host=host:<host-ip> --name mf-bot mf-bot

The bot should now be running. Visit the bot channel and you will be able to search for any fund and get their details.

To-do

  • Get returns and SIP returns working
  • Allow fetching of returns for different set of periods
  • Allow fetchign of SIP returns for 10th and 25th