Quick Start¶
Get up and running with trend_classifier in 5 minutes.
Basic Usage¶
1. Import and Load Data¶
import yfinance as yf
from trend_classifier import Segmenter
# Download Apple stock data
df = yf.download("AAPL", start="2020-01-01", end="2023-01-01", progress=False)
print(f"Loaded {len(df)} data points")
2. Create Segmenter and Detect Trends¶
# Create segmenter with DataFrame input
seg = Segmenter(df=df, column="Close", n=40)
# Calculate segments
seg.calculate_segments()
print(f"Found {len(seg.segments)} segments")
3. Visualize Results¶
4. Analyze Segments¶
# Export to DataFrame
df_segments = seg.segments.to_dataframe()
print(df_segments[["start", "stop", "slope", "std"]])
Output:
start stop slope std
0 0 45 0.234521 1.234567
1 46 120 -0.156789 2.345678
2 121 200 0.089012 1.567890
...
Using Arrays Instead of DataFrames¶
import numpy as np
# Your data as arrays
x = np.arange(500)
y = np.cumsum(np.random.randn(500)) # Random walk
# Create segmenter
seg = Segmenter(x=x, y=y, n=30)
seg.calculate_segments()
seg.plot_segments()
Choosing a Detector¶
trend_classifier supports multiple detection algorithms:
What's Next?¶
- Tutorials - Deep dive into each feature
- How-To: Choose a Detector - Pick the right algorithm
- API Reference - Complete documentation