@devries-cameron20 / open-alice / commits / 27feffb
Fork 0

Alice — an open-source AI trading bot covering equities, crypto, commodities, forex, and macro

Fix SMA test with guaranteed uptrend data

Camo67 committed Oct 12, 2026 at 12:44 UTC 27feffbc0005766f5db66acf77b917137e630751
1 file changed +6 -4
tests/test_sma_crossover.py
+6 -4
@@ -8,8 +8,9 @@ from open_alice.strategies.sma_crossover import SmaCrossover
8
9 @pytest.fixture
10 def sample_data() -> pd.DataFrame:
11 + # Create data with a clear uptrend: first 50 days at 100, next 50 days at 200
12 dates = pd.date_range("2024-01-01", periods=100, freq="D")
12 - prices = pd.Series(range(100, 200), dtype=float)
13 + prices = pd.Series([100.0] * 50 + [200.0] * 50, index=dates)
14 return pd.DataFrame({"Close": prices}, index=dates)
15
16
@@ -30,7 +31,8 @@ def test_invalid_periods() -> None:
31 def test_uptrend_generates_buy_signal(sample_data: pd.DataFrame) -> None:
32 strat = SmaCrossover(fast=5, slow=10)
33 result = strat.generate_signals(sample_data)
33 - # In a strong uptrend, we should not have a sell signal at the end
34 - assert result["Signal"].iloc[-1] != -1
35 - # And we should have generated at least one buy signal
34 +
35 + # After the trend is established, we should have a buy signal
36 assert (result["Signal"] == 1).any()
37 + # We should never have a sell signal in this scenario
38 + assert (result["Signal"] == -1).sum() == 0