mirror of
https://github.com/wassname/options_backtester.git
synced 2026-06-27 17:31:05 +08:00
Add constant price sma test
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user