Skip to main content

Use a regular expression to extract possible stock tickers from text

Project description

reticker

reticker uses Python 3.8 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? IMHO, SOXL is king!\nBTW, will the $w+$Z pair still grow?")
['FNGU', 'WEBL', 'SOXL', 'CLDL', 'SKYU', 'W', 'Z']

>>> 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, unprefixed uppercase, prefixed lowercase, and prefixed titlecase tickers 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/
Donation BTC / LTC / ETH / DOGE

Installation

Python ≥3.8 is required. To install, run:

pip install reticker

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.TickerExtractor().extract("EUR isn't a ticker, but URE is one.")
['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']

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

reticker-3.1.3.tar.gz (19.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

reticker-3.1.3-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

Details for the file reticker-3.1.3.tar.gz.

File metadata

  • Download URL: reticker-3.1.3.tar.gz
  • Upload date:
  • Size: 19.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for reticker-3.1.3.tar.gz
Algorithm Hash digest
SHA256 f7efc1454ec0faa0f17d0c5a36ed1e69901670394bd9627b93e759e21e7b2dca
MD5 5dddbd8ec1632e2691f7ff62640b3c95
BLAKE2b-256 d187f625cf759f787771ab56829b10ab85aea3b1de72f1f1cf09d7c1c42f22b6

See more details on using hashes here.

File details

Details for the file reticker-3.1.3-py3-none-any.whl.

File metadata

  • Download URL: reticker-3.1.3-py3-none-any.whl
  • Upload date:
  • Size: 19.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.5

File hashes

Hashes for reticker-3.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b9a245525cc3e3c9d17b21fb498d4728f8747c61d6008985ae016803bc5859df
MD5 00020982ab5ac01b9618b2253f40dcb2
BLAKE2b-256 2fadc0dc0a05266d60181a50e0cf428868033cd30dcb358475e299de9c2a0fc4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page