diff --git a/backtester/test/conftest.py b/backtester/test/conftest.py index 8803969..46c0a7a 100644 --- a/backtester/test/conftest.py +++ b/backtester/test/conftest.py @@ -26,6 +26,13 @@ def ivy_portfolio_datahandler(): return data +@pytest.fixture(scope='module') +def constant_price_stocks(): + data = TiingoData(SAMPLE_DATA_STOCKS) + data['adjClose'] = data['close'] = 10.0 + return data + + @pytest.fixture(scope='module') def sample_options_datahandler(): data = HistoricalOptionsData(SAMPLE_DATA_OPTIONS) diff --git a/backtester/test/datahandler/test_tiingo_data.py b/backtester/test/datahandler/test_tiingo_data.py index 31539f3..e5cc720 100644 --- a/backtester/test/datahandler/test_tiingo_data.py +++ b/backtester/test/datahandler/test_tiingo_data.py @@ -1,10 +1,15 @@ -from backtester.datahandler import TiingoData - - def test_sma(sample_stocks_datahandler): data = sample_stocks_datahandler data.sma(30) for symbol in data['symbol'].unique(): symbol_data = data.query('symbol == "{}"'.format(symbol)) sma = symbol_data.rolling(30)['adjClose'].mean().fillna(0) - assert (symbol_data['sma'] == sma).all() \ No newline at end of file + assert (symbol_data['sma'] == sma).all() + + +def test_constant_price_sma(constant_price_stocks): + fixed_price = constant_price_stocks['adjClose'].iloc[0] + for window in range(1, 20): + constant_price_stocks.sma(window) + for _symbol, data in constant_price_stocks.groupby('symbol'): + assert (data['sma'][window:] == fixed_price).all()