2626class MatchType (Enum ):
2727 """Security matching result."""
2828
29- TICKER_AND_ISIN = "ticker_and_isin"
29+ ISIN_TICKER = "isin_ticker"
30+ ISIN_TICKER_US = "isin_ticker_us"
3031 ISIN_NAME = "isin_name"
32+ TICKER_COUNTRY_NAME = "ticker_country_name"
3133 TICKER_NAME = "ticker_name"
34+ TICKER_US_NAME = "ticker_us_name"
3235
3336
3437@dataclass (frozen = True , slots = True )
@@ -59,29 +62,46 @@ def match(
5962 ) -> MatchResult :
6063 """Match SecurityProviderRecords according to matching hierarchy."""
6164
62- left_ticker = left .identifier_value (SecurityIdentifierType .TICKER ,)
63- right_ticker = right .identifier_value (SecurityIdentifierType .TICKER ,)
65+ left_ticker = left .identifier_value (SecurityIdentifierType .TICKER )
66+ left_ticker_cleaned = left .identifier_value_cleaned (SecurityIdentifierType .TICKER )
67+ left_ticker_country = left .identifier_country (SecurityIdentifierType .TICKER )
68+ left_ticker_us = left .identifier_country (SecurityIdentifierType .TICKER_US )
69+ right_ticker = right .identifier_value (SecurityIdentifierType .TICKER )
70+ right_ticker_cleaned = right .identifier_value_cleaned (SecurityIdentifierType .TICKER )
71+ right_ticker_country = right .identifier_country (SecurityIdentifierType .TICKER )
72+ right_ticker_us = right .identifier_country (SecurityIdentifierType .TICKER_US )
6473
6574 left_isin = left .identifier_value (SecurityIdentifierType .ISIN ,)
6675 right_isin = right .identifier_value (SecurityIdentifierType .ISIN ,)
6776
68- # 1 . Ticker + ISIN
77+ # 1a . Ticker + ISIN
6978 if (
70- left_ticker
71- and right_ticker
79+ left_ticker_cleaned
80+ and right_ticker_cleaned
7281 and left_isin
7382 and right_isin
74- and left_ticker == right_ticker
83+ and left_ticker_cleaned == right_ticker_cleaned
84+ and left_isin == right_isin
85+ ):
86+ return MatchResult (matched = True , match_type = MatchType .ISIN_TICKER )
87+
88+ # 1b. Ticker + ISIN
89+ if (
90+ left_ticker_us
91+ and right_ticker_us
92+ and left_isin
93+ and right_isin
94+ and left_ticker_us == right_ticker_us
7595 and left_isin == right_isin
7696 ):
77- return MatchResult (matched = True , match_type = MatchType .TICKER_AND_ISIN , )
97+ return MatchResult (matched = True , match_type = MatchType .ISIN_TICKER_US )
7898
7999 # 2. ISIN + similar name
80100 if (
81101 left_isin
82102 and right_isin
83103 and left_isin == right_isin
84- and left_ticker != right_ticker
104+ and left_ticker_cleaned != right_ticker_cleaned
85105 ):
86106 similarity = name_similarity (left .name , right .name )
87107
@@ -93,12 +113,32 @@ def match(
93113 name_similarity = similarity ,
94114 )
95115
96- # 3. Ticker + similar name
116+ # 3. Ticker incl. country postfix + similar name
97117 if (
98- left_ticker
118+ not (left_isin and right_isin )
119+ and left_ticker
120+ and left_ticker_country
99121 and right_ticker
122+ and right_ticker_country
100123 and left_ticker == right_ticker
101124 ):
125+
126+ similarity = name_similarity (left .name , right .name )
127+
128+ if similarity >= self ._name_similarity_threshold :
129+ return MatchResult (
130+ matched = True ,
131+ match_type = MatchType .TICKER_COUNTRY_NAME ,
132+ name_similarity = similarity ,
133+ )
134+
135+ # 4. Ticker + similar name
136+ if (
137+ not (left_isin and right_isin )
138+ and left_ticker_cleaned
139+ and right_ticker_cleaned
140+ and left_ticker_cleaned == right_ticker_cleaned
141+ ):
102142 similarity = name_similarity (left .name , right .name )
103143
104144 if similarity >= self ._name_similarity_threshold :
@@ -108,4 +148,20 @@ def match(
108148 name_similarity = similarity ,
109149 )
110150
151+ # 5. Ticker-US + similar name
152+ if (
153+ not (left_isin and right_isin )
154+ and left_ticker_us
155+ and right_ticker_us
156+ and left_ticker_us == right_ticker_us
157+ ):
158+ similarity = name_similarity (left .name , right .name )
159+
160+ if similarity >= self ._name_similarity_threshold :
161+ return MatchResult (
162+ matched = True ,
163+ match_type = MatchType .TICKER_US_NAME ,
164+ name_similarity = similarity ,
165+ )
166+
111167 return MatchResult (matched = False )
0 commit comments