Package for automated signal segmentation, trend classification and analysis.
Project description
Trend classifier
Library for automated signal segmentation, trend classification and analysis.
Installation
-
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()
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file trend-classifier-0.1.11.tar.gz
.
File metadata
- Download URL: trend-classifier-0.1.11.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.16.1 CPython/3.12.4 Darwin/23.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 285a3a26bba4debefa2f3f2418bd19c9848e4705d93beb01b078e6da31279349 |
|
MD5 | 48d4082922caf28de34d9df2ca790c58 |
|
BLAKE2b-256 | a351864a594b90088a1ec93d09e484751a00313a1530e700148c8867ad0fd443 |
File details
Details for the file trend_classifier-0.1.11-py3-none-any.whl
.
File metadata
- Download URL: trend_classifier-0.1.11-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: pdm/2.16.1 CPython/3.12.4 Darwin/23.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3061193299a3ab6ab49e95098ffe8578d9a08dafdb480ba50eaf75c59afa3038 |
|
MD5 | b715a28b33127147dfa7e48b04a612d7 |
|
BLAKE2b-256 | 6a83090e5db09a015da27ba86c92557bf357f63fb316ad52b4b9db860eb07156 |