Metadata-Version: 2.1
Name: trend-classifier
Version: 0.1.2
Summary: Package for automated signal segmentation, trend classification and analysis.
Home-page: https://github.com/izikeros/trend_classifier
License: MIT
Keywords: trend,timeseries,classification,segmentation,analysis,algotrading,finance
Author: Krystian Safjan
Author-email: ksafjan@gmail.com
Requires-Python: >=3.8,<3.11
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Financial and Insurance Industry
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Utilities
Requires-Dist: matplotlib (>=3.5.3,<4.0.0)
Requires-Dist: numpy (>=1.23.2,<2.0.0)
Requires-Dist: pydantic (>=1.10.1,<2.0.0)
Project-URL: Documentation, https://github.com/izikeros/trend_classifier
Project-URL: Repository, https://github.com/izikeros/trend_classifier
Description-Content-Type: text/markdown

# Trend classifier

Library for automated signal segmentation, trend classification and analysis.

## Installation

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

   ```sh
   pip3 install trend-classifier
   ```

## Usage
### Pandas DataFrame Input
usage:
```python
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()`:
```python
seg.plot_segments(fig_size=(8, 4))
```

![Segmentation example](https://github.com/izikeros/trend_classifier/blob/main/img/screenshoot_1.jpg?raw=true)

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:
```python
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',
    )
```

## License

[MIT](LICENSE) © [Krystian Safjan](https://safjan.com/).

