Last active
May 6, 2022 18:35
-
-
Save roldan/ac97d9dfbce8c69f3ea2461267a98ebb to your computer and use it in GitHub Desktop.
Extraer strike de tickers de opciones BYMA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
def extract_strike_from_symbol(symbol, underlying_price): | |
strike = re.findall('[\d\.]+', symbol)[0].strip('.') | |
if len(strike) > 4 and '.' not in strike: | |
s1 = float(strike[:4] + '.' + strike[4:]) | |
s2 = float(strike[:3] + '.' + strike[3:]) | |
diff1 = abs((float(underlying_price) / s1 - 1) * 100) | |
diff2 = abs((float(underlying_price) / s2 - 1) * 100) | |
strike = s1 if diff1 < diff2 else s2 | |
return float(strike) | |
symbols = [ | |
['GFGV18254J', 180], | |
['GFGC350.OC', 180], | |
['COMC7.09OC', 7], | |
['LOMC201.2J', 200], | |
['BYMV1500JU', 1200], | |
['BYMC10272G', 1200], | |
['BYMV97724G', 1200] | |
] | |
for symbol in symbols: | |
print('{} {}'.format(symbol[0], extract_strike_from_symbol(symbol[0], symbol[1]))) | |
''' | |
GFGV18254J 182.54 | |
GFGC350.OC 350.0 | |
COMC7.09OC 7.09 | |
LOMC201.2J 201.2 | |
BYMV1500JU 1500.0 | |
BYMC10272G 1027.2 | |
BYMV97724G 977.24 | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment