Skip to content

Commit c2abe88

Browse files
committed
Fix tests
1 parent 6ff8466 commit c2abe88

File tree

2 files changed

+19
-21
lines changed

2 files changed

+19
-21
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ pd_df.tail(10)
846846

847847
#### Nadaraya-Watson Envelope (NWE)
848848

849-
The Nadaraya-Watson Envelope uses Gaussian kernel regression to create a smoothed price estimate, then adds an envelope based on the mean absolute error (MAE) scaled by a multiplier. This is a non-repainting (endpoint) implementation inspired by the TradingView "Nadaraya-Watson Envelope [LuxAlgo]" indicator. It is useful for identifying overbought/oversold zones and mean-reversion opportunities.
849+
The Nadaraya-Watson Envelope uses Gaussian kernel regression to create a smoothed price estimate, then adds an envelope based on the mean absolute error (MAE) scaled by a multiplier. This is a non-repainting (endpoint) implementation. It is useful for identifying overbought/oversold zones and mean-reversion opportunities.
850850

851851
Calculation:
852852
- Kernel weights: `w(i) = exp(-i² / (2 × h²))` for `i = 0..lookback-1`
@@ -958,8 +958,6 @@ pd_df.tail(10)
958958

959959
The SuperTrend Clustering indicator uses K-means clustering to optimize the ATR multiplier factor for the SuperTrend calculation. It computes multiple SuperTrend variations with different factors, evaluates their performance, and clusters them into "best", "average", and "worst" groups. The best-performing factor is then used to generate an adaptive trailing stop with buy/sell signals.
960960

961-
Based on the LuxAlgo SuperTrend AI indicator concept.
962-
963961
```python
964962
def supertrend_clustering(
965963
data: Union[PdDataFrame, PlDataFrame],

tests/indicators/test_supertrend.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import pandas as pd
33
import numpy as np
44

5-
from pyindicators import supertrend_ai, supertrend, get_supertrend_stats
5+
from pyindicators import supertrend_clustering, supertrend, get_supertrend_stats
66

77

88
class TestSuperTrend(unittest.TestCase):
@@ -66,14 +66,14 @@ def test_supertrend_custom_parameters(self):
6666
result = supertrend(self.df.copy(), atr_length=14, factor=2.0)
6767
self.assertIn('supertrend', result.columns)
6868

69-
def test_supertrend_ai_returns_dataframe(self):
70-
"""Test that supertrend_ai returns a DataFrame."""
71-
result = supertrend_ai(self.df.copy(), max_data=100)
69+
def test_supertrend_clustering_returns_dataframe(self):
70+
"""Test that supertrend_clustering returns a DataFrame."""
71+
result = supertrend_clustering(self.df.copy(), max_data=100)
7272
self.assertIsInstance(result, pd.DataFrame)
7373

74-
def test_supertrend_ai_columns(self):
75-
"""Test that supertrend_ai adds expected columns."""
76-
result = supertrend_ai(self.df.copy(), max_data=100)
74+
def test_supertrend_clustering_columns(self):
75+
"""Test that supertrend_clustering adds expected columns."""
76+
result = supertrend_clustering(self.df.copy(), max_data=100)
7777

7878
expected_columns = [
7979
'supertrend', 'supertrend_trend', 'supertrend_ama',
@@ -82,10 +82,10 @@ def test_supertrend_ai_columns(self):
8282
for col in expected_columns:
8383
self.assertIn(col, result.columns)
8484

85-
def test_supertrend_ai_factor_range(self):
86-
"""Test that supertrend_ai uses factors within specified range."""
85+
def test_supertrend_clustering_factor_range(self):
86+
"""Test that supertrend_clustering uses factors within specified range."""
8787
min_mult, max_mult = 1.0, 3.0
88-
result = supertrend_ai(
88+
result = supertrend_clustering(
8989
self.df.copy(),
9090
min_mult=min_mult,
9191
max_mult=max_mult,
@@ -98,20 +98,20 @@ def test_supertrend_ai_factor_range(self):
9898
self.assertGreaterEqual(factor, min_mult - 0.1)
9999
self.assertLessEqual(factor, max_mult + 0.1)
100100

101-
def test_supertrend_ai_cluster_options(self):
102-
"""Test supertrend_ai with different cluster options."""
101+
def test_supertrend_clustering_cluster_options(self):
102+
"""Test supertrend_clustering with different cluster options."""
103103
for cluster in ['best', 'average', 'worst']:
104-
result = supertrend_ai(
104+
result = supertrend_clustering(
105105
self.df.copy(),
106106
from_cluster=cluster,
107107
max_data=100
108108
)
109109
self.assertIn('supertrend', result.columns)
110110

111-
def test_supertrend_ai_invalid_factor_range(self):
111+
def test_supertrend_clustering_invalid_factor_range(self):
112112
"""Test that invalid factor range raises error."""
113113
with self.assertRaises(ValueError):
114-
supertrend_ai(self.df.copy(), min_mult=5.0, max_mult=1.0)
114+
supertrend_clustering(self.df.copy(), min_mult=5.0, max_mult=1.0)
115115

116116
def test_get_supertrend_stats(self):
117117
"""Test statistics function."""
@@ -123,9 +123,9 @@ def test_get_supertrend_stats(self):
123123
self.assertIn('current_trend', stats)
124124
self.assertIn(stats['current_trend'], ['bullish', 'bearish'])
125125

126-
def test_get_supertrend_stats_ai(self):
127-
"""Test statistics for AI version includes additional fields."""
128-
result = supertrend_ai(self.df.copy(), max_data=100)
126+
def test_get_supertrend_stats_clustering(self):
127+
"""Test statistics for clustering version includes additional fields."""
128+
result = supertrend_clustering(self.df.copy(), max_data=100)
129129
stats = get_supertrend_stats(result)
130130

131131
self.assertIn('avg_factor', stats)

0 commit comments

Comments
 (0)