diff --git a/btlib/btlib.py b/btlib/btlib.py index d96ecc3..468fff8 100644 --- a/btlib/btlib.py +++ b/btlib/btlib.py @@ -47,11 +47,11 @@ class Strategy(ABC): @abstractmethod def init(self): - pass + """ Abstract method for initializing resources for the strategy """ @abstractmethod def next(self, i: int, record: Dict[Hashable, Any]): - pass + """ Abstract method defining the core functionality of the strategy """ def __init__(self): self.data = pd.DataFrame() diff --git a/tests/test_backtest.py b/tests/test_backtest.py index 8b27a3d..d7d79fa 100644 --- a/tests/test_backtest.py +++ b/tests/test_backtest.py @@ -88,6 +88,3 @@ def test_backtest_multiple_assets(self): pd.testing.assert_series_equal(result.returns, returns) self.assertEqual(result.trades, trades) self.assertEqual(result.open_positions, open_positions) - -if __name__ == '__main__': - unittest.main() \ No newline at end of file diff --git a/tests/test_position.py b/tests/test_position.py index 948292e..499e88e 100644 --- a/tests/test_position.py +++ b/tests/test_position.py @@ -64,6 +64,3 @@ def test_update_position_with_valid_values(self): self.assertAlmostEqual(position.profit_loss, 500.0) self.assertAlmostEqual(position.change_pct, 50.0) self.assertAlmostEqual(position.current_value, 1500.0) - -if __name__ == '__main__': - unittest.main() \ No newline at end of file diff --git a/tests/test_strategy.py b/tests/test_strategy.py index 0496c38..dbc6eb3 100644 --- a/tests/test_strategy.py +++ b/tests/test_strategy.py @@ -6,9 +6,10 @@ class CustomStrategy(Strategy): def init(self): - pass + """ Implementation for initialization """ + def next(self, i, record): - pass + """ Implementation for the core strategy logic """ class TestStrategy(unittest.TestCase): @@ -42,3 +43,9 @@ def test_open_sets_size_to_cash_divided_by_price_if_size_is_none(self): strategy.cash = 100 self.assertTrue(strategy.open(10, None)) self.assertEqual(strategy.open_positions[0].position_size, 10) + + # The close() method returns False if price is NaN or less than or equal to zero + def test_close_returns_false_if_price_or_size_invalid(self): + strategy = CustomStrategy() + self.assertFalse(strategy.close(nan)) + self.assertFalse(strategy.close(0))