Add constant price sma test

This commit is contained in:
Juan Pablo Amoroso
2020-03-19 14:36:11 -03:00
parent 565931c062
commit ff70bf12eb
2 changed files with 16 additions and 4 deletions
+7
View File
@@ -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)
@@ -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()
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()