File size: 2,381 Bytes
559318d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4cd7f66..0d5255e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,12 @@
 # Changelog
 
+## 1.2.1
+
+### Fixed
+
+- Fix mis-classification of STP (Systematic Transfer Plan) for
+  Kfintech-serviced schemes. (discussion #141)
+
 ## 1.2.0
 
 ### New
diff --git a/casparser/__init__.py b/casparser/__init__.py
index b106f27..19ccb3b 100644
--- a/casparser/__init__.py
+++ b/casparser/__init__.py
@@ -9,4 +9,4 @@ __all__ = [
     "CapitalGainsReport",
 ]
 
-__version__ = "1.2.0"
+__version__ = "1.2.1"
diff --git a/casparser/parsers/_classify.py b/casparser/parsers/_classify.py
index f92a055..52baa1f 100644
--- a/casparser/parsers/_classify.py
+++ b/casparser/parsers/_classify.py
@@ -37,6 +37,15 @@ DIVIDEND_RE = re.compile(
 )
 REINVEST_RE = re.compile(r"reinvest", re.I)
 
+# Systematic Transfer Plan. A switch by another name — money is moved
+# between two schemes on a schedule. The two RTAs word it differently:
+# CAMS prints "Systematic Transfer Plan Switch In/Out …" (already caught by
+# the "switch" keyword), while KFintech prints it letter-spaced as
+# "S T P In/Out (…)", which matches none of the plain substring checks and
+# used to fall through to PURCHASE / REDEMPTION. Detecting it here — spacing
+# tolerated — lets both RTAs classify consistently as SWITCH_IN / SWITCH_OUT.
+STP_RE = re.compile(r"\bs\s*t\s*p\b|systematic\s+transfer", re.I)
+
 # Counterparty folio embedded in a gift transfer description. Both RTAs
 # name the other folio but punctuate differently — KFin uses a colon
 # ("Folio No: 12345678901"), CAMS a dot ("Folio No.87654321") — so accept
@@ -82,7 +91,7 @@ def get_transaction_type(
     elif units > 0:
         if "gift" in description:
             txn_type = TransactionType.GIFT_IN
-        elif "switch" in description:
+        elif "switch" in description or STP_RE.search(description):
             txn_type = (
                 TransactionType.SWITCH_IN_MERGER
                 if "merger" in description
@@ -109,7 +118,7 @@ def get_transaction_type(
             re.I,
         ):
             txn_type = TransactionType.REVERSAL
-        elif "switch" in description:
+        elif "switch" in description or STP_RE.search(description):
             txn_type = (
                 TransactionType.SWITCH_OUT_MERGER
                 if "merger" in description