Skip to content

Commit

Permalink
v2023.8.18 - better scheme lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
codereverser committed Aug 18, 2023
1 parent 0aefe11 commit 7f01b24
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 9 additions & 11 deletions casparser_isin/mf_isin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sqlite3
from typing import Optional

from rapidfuzz import process
from rapidfuzz import process, utils

from .utils import get_isin_db_path

Expand Down Expand Up @@ -93,19 +93,17 @@ def scheme_lookup(self, rta: str, scheme_name: str, rta_code: str):

args = {"rta": RTA_MAP.get(str(rta).upper(), ""), "rta_code": rta_code}

if (
"hdfc" in scheme_name.lower()
and re.search("dividend|idcw", scheme_name, re.I)
):
# Special case for old HDFC funds with scheme codes of format "H\d+"
if re.search("re-*invest", scheme_name, re.I):
where.append("name LIKE '%reinvest%'")
else:
where.append("name LIKE '%payout%'")
if "hdfc" in scheme_name.lower():
if re.search("direct", scheme_name, re.I):
where.append("name LIKE '%direct%'")
else:
where.append("name NOT LIKE '%direct%'")

if re.search("dividend|idcw", scheme_name, re.I):
if re.search("re-*invest", scheme_name, re.I):
where.append("name LIKE '%reinvest%'")
else:
where.append("name LIKE '%payout%'")
where.append("rta_code like :rta_code_d")
args.update(rta_code_d=f"{rta_code}%")
else:
Expand Down Expand Up @@ -154,7 +152,7 @@ def isin_lookup(
schemes = {
x["name"]: (x["name"], x["isin"], x["amfi_code"], x["type"]) for x in results
}
key, score, _ = process.extractOne(scheme_name, schemes.keys())
key, score, _ = process.extractOne(scheme_name, schemes.keys(), processor=utils.default_process)
if score >= min_score:
name, isin, amfi_code, scheme_type = schemes[key]
return SchemeData(
Expand Down
2 changes: 2 additions & 0 deletions tests/fixtures.csv
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ Franklin India Ultra Short Bond Fund- Super Inst. Plan-Segregated Portfolio 1 (e
Franklin India Ultra Short Bond Fund- Super Inst. Plan-Segregated Portfolio 1 (erstwhile 8.25% Vodafone Idea Ltd-10jul20-Daily Dividend Option) - Daily - IDCW# Payout,CAMS,FTI915,Franklin India Ultra Short Bond Fund- Super Inst Plan-Segregated Portfolio 1 (8.25% Vodafone Idea Ltd-10jul20-Daily Dividend Option) - Daily - IDCW,INF090I01VH6,147971
HDFC Balanced Fund - Regular Plan - Growth,CAMS,HBFG,hdfc balanced fund - growth option,INF179K01392,100122
HDFC Cash Management Fund - Savings Plan - Weekly IDCW# - Reinvest,CAMS,H51,hdfc money market fund-weekly idcw reinvestment,INF179KB1II2,101995
HDFC Cash Management Fund - Direct Savings Plan - Weekly IDCW# - Payout,CAMS,H51,hdfc money market fund-direct plan - weekly idcw payout,INF179KB1IA9,119094
HDFC Corporate Bond Fund - Direct Plan - Growth Option,CAMS,HMTOGT,hdfc corporate bond fund - direct plan - growth option,INF179K01XD8,118987
HDFC Flexi Cap Fund - Regular Plan - Growth,CAMS,H02,hdfc flexicap fund - growth option,INF179K01608,101762
HDFC Hybrid Equity Fund - Regular Plan - Growth,CAMS,HPREG,hdfc hybrid equity fund - regular plan - growth,INF179K01AS4,102948
HDFC Low Duration Fund - Regular Plan - Monthly IDCW# - Reinvest,CAMS,H60,hdfc low duration fund - retail - regular plan - monthly idcw reinvestment reinvestment,INF179K01467,105543
HDFC Low Duration Fund - Direct Plan - Growth,CAMS,H54,hdfc low duration fund - direct plan - growth,INF179K01VF7,118942
HDFC Mid-Cap Opportunities Fund - Regular Plan - Growth,CAMS,HMCOG,hdfc mid-cap opportunities fund - growth option,INF179K01CR2,105758
HDFC Short Term Debt Fund - Direct Plan - Growth Option,CAMS,HSTOGT,hdfc short term debt fund - direct plan - growth option,INF179K01YM7,119016
HDFC Short Term Debt Fund - Regular Plan - Fortnightly Dividend - Reinvest,CAMS,HSTOD,hdfc short term debt fund - regular plan - fortnightly dividend reinvestment reinvestment,INF179K01CW2,113048
Expand Down

0 comments on commit 7f01b24

Please sign in to comment.