Spaces:
Sleeping
Sleeping
Download tests/test_strategy_fallback.py from rickyviale/polymonte-v113: direct link, hf CLI and curl.
- Browser
- Download file 1.79 kB
-
https://huggingface.co/spaces/rickyviale/polymonte-v113/resolve/main/tests/test_strategy_fallback.py
- Command line
-
hf download hf://spaces/rickyviale/polymonte-v113/tests/test_strategy_fallback.py
-
curl -L -o test_strategy_fallback.py https://huggingface.co/spaces/rickyviale/polymonte-v113/resolve/main/tests/test_strategy_fallback.py
1.79 kB
| import os | |
| import sys | |
| import unittest | |
| sys.path.insert(0, os.path.dirname(os.path.dirname(__file__))) | |
| import strategy | |
| from risk_manager import RiskManager | |
| class StrategyFallbackTests(unittest.TestCase): | |
| def test_lstm_predict_returns_probability_in_range(self): | |
| closes = [100 + i * 0.2 for i in range(40)] | |
| prob = strategy.lstm_predict(closes) | |
| self.assertGreaterEqual(prob, 0.0) | |
| self.assertLessEqual(prob, 1.0) | |
| def test_health_reports_fallback_mode(self): | |
| health = strategy.get_health_status() | |
| self.assertIn("status", health) | |
| self.assertTrue(health["model_loaded"]) | |
| def test_duplicate_signals_are_suppressed(self): | |
| state = {"AAPL": {"signal": "BUY", "prob": 0.7, "timestamp": strategy.datetime.utcnow()}} | |
| self.assertFalse(strategy.should_emit_signal("AAPL", "BUY", 0.71, "BULL", state)) | |
| self.assertTrue(strategy.should_emit_signal("AAPL", "SELL", 0.2, "BEAR", state)) | |
| def test_weak_signals_are_rejected(self): | |
| self.assertFalse(strategy.should_take_trade("BUY", 0.56, "SIDEWAYS", 50.0, 5.0, 100.0)) | |
| self.assertTrue(strategy.should_take_trade("BUY", 0.78, "BULL", 38.0, 1.0, 100.0)) | |
| self.assertFalse(strategy.should_take_trade("BUY", 0.8, "BULL", 80.0, 1.0, 100.0)) | |
| def test_risk_manager_sets_sensible_levels(self): | |
| manager = RiskManager() | |
| levels = manager.exit_levels(100.0, "BUY", 0.8, 0.82) | |
| self.assertLess(levels["stop_loss"], 100.0) | |
| self.assertGreater(levels["take_profit"], 100.0) | |
| self.assertGreater(levels["trailing_stop"], 0.0) | |
| size = manager.position_size(10000.0, 100.0, 1.0, 0.82) | |
| self.assertGreater(size, 0) | |
| self.assertLessEqual(size, 10000) | |
| if __name__ == "__main__": | |
| unittest.main() | |