Skip to main content

Package for automated signal segmentation, trend classification and analysis.

Project description

Trend classifier

pre-commit.ci status Black formatter flake8 pytest Maintainability codecov

Library for automated signal segmentation, trend classification and analysis.

Installation

  1. The package is pip-installable. To install it, run:

    pip3 install trend-classifier
    

Usage

Pandas DataFrame Input

usage:

import yfinance as yf
from trend_classifier import Segmenter

# download data from yahoo finance
df = yf.download("AAPL", start="2018-09-15", end="2022-09-05", interval="1d", progress=False)

x_in = list(range(0, len(df.index.tolist()), 1))
y_in = df["Adj Close"].tolist()

seg = Segmenter(x_in, y_in, n=20)
seg.calculate_segments()

For graphical output use Segmenter.plot_segments():

seg.plot_segments()

Segmentation example

After calling method Segmenter.calculate_segments() segments are identified and information is stored in Segmenter.segments as list of Segment objects. Each Segment object. Each Segment object has attributes such as 'start', 'stop' - range of indices for the extracted segment, slope and many more attributes that might be helpful for further analysis.

Exemplary info on one segment:

from devtools import debug
debug(seg.segments[3])

and you should see something like this:

    seg.segments[3]: Segment(
        start=154,
        stop=177,
        slope=-0.37934038908585044,
        offset=109.54630934894907,
        slopes=[
            -0.45173184100846725,
            -0.22564684358754555,
            0.15555037018051593,
            0.34801127785130714,
        ],
        offsets=[
            121.65628807526804,
            83.56079272220015,
            17.32660986821478,
            -17.86417581658647,
        ],
        slopes_std=0.31334199799377654,
        offsets_std=54.60900279722876,
        std=0.933497081795997,
        span=82.0,
        reason_for_new_segment='offset',
    )

export results to tabular format (pandas DataFrame):

seg.segments.to_dataframe()

(NOTE: for clarity reasons, not all columns are shown in the screenshot above)

Alternative approach

  • Smooth out the price data using the Savitzky-Golay filter,
  • label the highs and lows.
  • higher highs and higher lows indicates an uptrend.

The requirement here is than you need OHLC data for the assets you would like to analyse.

License

MIT © Krystian Safjan.

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

trend_classifier-0.2.1.tar.gz (14.8 kB view details)

Uploaded Source

Built Distribution

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

trend_classifier-0.2.1-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file trend_classifier-0.2.1.tar.gz.

File metadata

  • Download URL: trend_classifier-0.2.1.tar.gz
  • Upload date:
  • Size: 14.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for trend_classifier-0.2.1.tar.gz
Algorithm Hash digest
SHA256 16321d2996e2ae2baacb802a59da87e818c773f20352c533008371a943c50fcb
MD5 3341e12374c007d663337c1e6a2bafe0
BLAKE2b-256 3eb2bf0d0daf1e6ce41cd3c77771386bfdfcd84d7bc14dbb6df29be91cd77808

See more details on using hashes here.

File details

Details for the file trend_classifier-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for trend_classifier-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1fa45328a0d2aaf8864c5113b68324414cb9d642cb8a9f94b18fbd78ef1ef42e
MD5 1bfe69d7de0d8fdec00f6667c0d047a5
BLAKE2b-256 2d749245515996d0f98fb02986982d7ccfaf043d4cc70d3ca52ba02c58d934e4

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