Code Monkey home page Code Monkey logo

reticker's Introduction

reticker

reticker is a Python 3.8 package to extract what look like stock tickers from the given text. It uses a configurably created regular expression. It does not however validate or use a whitelist of tickers.

cicd badge

Examples

>>> import reticker

>>> reticker.TickerExtractor().extract("Comparing FNGU vs $WEBL vs SOXL- who wins? And what about $cldl vs $Skyu? BTW, will the $w+Z pair still grow? IMHO, SOXL is king! [V]isa is A-okay!")
["FNGU", "WEBL", "SOXL", "CLDL", "SKYU", "W", "Z", "V", "A"]

>>> reticker.TickerExtractor().extract("Which of BTC-USD, $ETH-USD and $ada-usd is best?\nWhat about $Brk.a and $Brk.B? Compare futures MGC=F and SIL=F.")
['BTC-USD', 'ETH-USD', 'ADA-USD', 'BRK.A', 'BRK.B', 'MGC=F', 'SIL=F']

Features

  • Optional matching of prefixed uppercase (e.g. $SPY), unprefixed uppercase (e.g. SPY), prefixed lowercase (e.g. $spy), and prefixed titlecase tickers (e.g. $Spy) is enabled by default, but can individually be disabled. At least one of the four must be enabled.
  • Two-part tickers are also matched using a customizable set of separator characters.
  • The results are in the order they are first found.
  • By default, the results are deduplicated, although this can be disabled.
  • A configurable blacklist of common false-positives is used.
  • A configurable remapping of tickers is supported.
  • For lower level use, a configurably created compiled regular expression can be accessed.

Links

Caption Link
Repo https://github.com/impredicative/reticker/
Changelog https://github.com/impredicative/reticker/releases
Package https://pypi.org/project/reticker/

Installation

Python โ‰ฅ3.8 is required. To install, run:

pip install reticker

No additional third-party packages are required or installed.

Usage

Default usage

>>> import reticker

>>> extractor = reticker.TickerExtractor()
>>> type(extractor.pattern)
<class 're.Pattern'>

>>> extractor.extract("Has $GLD/IAU bottomed yet? What's the prospect for gold miners like $nugt? Maybe check gold futures MGC=F!")
['GLD', 'IAU', 'NUGT', 'MGC=F']

Customized usage

>>> import reticker

# Custom config:
>>> ticker_match_config = reticker.TickerMatchConfig(prefixed_uppercase=True, unprefixed_uppercase=False, prefixed_lowercase=False, prefixed_titlecase=False)
>>> extractor = reticker.TickerExtractor(deduplicate=False, match_config=ticker_match_config)
>>> extractor.extract("Which is better - $LTC or $ADA? $doge and ETH are already so high.")
['LTC', 'ADA']

# Separators:
>>> reticker.TickerExtractor(match_config=reticker.TickerMatchConfig(separators="-=")).extract("BTC-USD")
['BTC-USD']
>>> reticker.TickerExtractor(match_config=reticker.TickerMatchConfig(separators="")).extract("BTC-USD")
['BTC', 'USD']

# Blacklist:
>>> reticker.config.BLACKLIST.add("EUR")
>>> reticker.config.BLACKLIST.remove("I")
>>> reticker.TickerExtractor().extract("I see that EUR isn't a ticker, but URE is one.")
['I', 'URE']

# Mapping:
>>> reticker.config.MAPPING["BTC"] = "BTC-USD"
>>> reticker.TickerExtractor().extract("What is the Yahoo Finance symbol for BTC?")
['BTC-USD']
>>> reticker.config.MAPPING["COMP"] = ["COMP", "COMP-USD"]
>>> reticker.TickerExtractor().extract('Is COMP for the equity named "Compass" or for the crypto named "Compound"? I want both!')
['COMP', 'COMP-USD']

reticker's People

Contributors

impredicative avatar worker701 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

beyondcoast

reticker's Issues

Blacklist not working

Hi there,

I was wondering how the BLACKLIST works? I tried the snippet mentioned in the readme but that is giving me Cannot find reference 'config' in '__init__.py' . I used:

import reticker

reticker.config.BLACKLIST.add("EUR")
reticker.TickerExtractor().extract("EUR isn't a ticker, but URE is one.")

Appreciate your help.

Support unprefixed single letters, e.g. V

Single letters are matched when prefixed with $. Can this behavior be extended?

English words with single letters that will need to be blacklisted after this change:

  • A
  • I

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.