Code Monkey home page Code Monkey logo

trend_classifier's Introduction

Trend classifier

pre-commit.ci status Black formatter flake8 pytest Maintainability Test Coverage

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.

trend_classifier's People

Contributors

izikeros avatar pre-commit-ci[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

trend_classifier's Issues

Problem with segmentation

Screenshot 2023-04-29 at 17 33 39

I am working with a small number of values. If I drop the n value below a certain value, it throws me this error :
ValueError: On entry to DLASCL parameter number 4 had an illegal value.

Also if you look at the image I uploaded, segmentation in seg 3 is not really good.

(seg 3 is the one in the middle )

Error on segmentation

when I ran on Python 3.10 the sample code on the readme file got this error:
trend_classifier/segmentation.py:63: UserWarning: No data frame provided, column argument will be ignored. self._handle_input_data(column=column, df=df, x=x, y=y)

and when I ran on Python 3.8 get the following error:
/trend_classifier/segment.py", line 20, in Segment slopes: list[float] = [] TypeError: 'type' object is not subscriptable

error in run

Hi there
to run your own sample I reach an error
plz check that:

.conda\envs\at\lib\site-packages\trend_classifier\configuration.py", line 13, in Config
alpha: float | None = 2

TypeError: unsupported operand type(s) for |: 'type' and 'NoneType'

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.