mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-03 16:02:04 +00:00
* add model file for Montreal Options Exchange * mypy fixes * define attributes under __init__ * type error fix * another pylint fix * adds tests for tmx_model * black * mypy * adds expirations test and re-records * black * capture error message in test * mypy * add __docformat__ line * improves get_all_ticker_symbols * removes python magic command for new cell * adds TMX as source for SDK chains * starts on a new method for loading options data returning a standardized object * add load_options as SDK endpoint * intrinio response - not complete * adds tradier to load_options * add source attribute to options object * restore legacy nasdaq last price function * yFinance underlying_price fixes * yFinance model fix * adds cboe to sdk options load * table fix * creates options_chains_model.py and updates SDK map * docstrings added for the class. * updates tmx_model tests * fix options_controller test * adds cboe_model tests * spelling in docstring * ruff - unused import * mypy fixes * more mypy fixes * pylint * attempt to manually resolve merge conflict. * nasdaq_model fix * adds test coverage for options/nasdaq_model * docstrings update for nasdaq_model * mypy fix * adds unit testing for options_chains_model * adds additional tests for intrinio_model * unused import fix * fix for .TO symbol and TMX EOD chains * make CBOE Pydantic * cboe update * adds switch for pydantic output from all sources * black * index options error handling for Intrinio * add warning message for index options from Intrinio * tmx_model enhancements * cleans up get_ticker_iv() in cboe_model * fix ticker info for index symbols from cboe * typo in comments * adds test for tradier_model.load_options * cboe optionType as lower case * add function for calculating chains stats * black * trailmap for calculate_chains_stats * adds test for calculate_stats() * more details to nasdaq.underlying_price * typo in docstrings * mypy - options_chains_model.py * black - options_chains_model.py * pylint options_chains_model.py * standardize response from intrinio underlying price * add function to validate input of function * missed type hint * additional error handling for stats * adds DTE as column for all sources * adds strategies function and input validation * add yFinance test for load_options() * add Nasdaq test for load_options() * tests for new functions in options_chains_model * update sdk trailmap * rewrite tests * fixes for tests * fix tmx_model test * more pytest * pytest.. * add vertical call spread function * some cleanup * update nasdaq tests * more cleanup * black * pylint * black * ruff * black * pylint * black * pylint.. * tests rewrite * more pytest * recapture tests * Different tests were collected between gw1 and gw0 * adds vertical spreads * vertical_put_spread * improve calculate_stats * mypy * edge cases * black * update tmx,yfinance tests * new cboe tests * new tmx_model tests * fix nasdaq test * test updates * fix nasdaq tests * add test_options_chains_model * refactor data sources * black * pylint * fixing stuff * forgot a file.. * codespell * linting * mypy... * refactor OptionsChains class * pylint * reconfigure SDK entry point * fix error handling when data request fails * ruff * pylint * pylint * Add inheritance and a repr string * add method for skew * add method for skew * fix nasdaq test * add skew to tests --------- Co-authored-by: James Maslek <jmaslek11@gmail.com>
125 lines
3.5 KiB
Python
125 lines
3.5 KiB
Python
# IMPORTATION STANDARD
|
|
|
|
# IMPORTATION THIRDPARTY
|
|
import pandas as pd
|
|
import pytest
|
|
|
|
# IMPORTATION INTERNAL
|
|
from openbb_terminal.stocks.options import tmx_model
|
|
|
|
# pylint: disable=no-member
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
def vcr_config():
|
|
return {
|
|
"filter_headers": [("Authorization")],
|
|
"filter_query_parameters": [
|
|
("before", "MOCK_BEFORE"),
|
|
("after", "MOCK_AFTER"),
|
|
],
|
|
}
|
|
|
|
|
|
@pytest.mark.vcr
|
|
def test_underlying_price():
|
|
result_df = tmx_model.get_underlying_price("XIU")
|
|
assert isinstance(result_df, pd.Series)
|
|
assert "price" in result_df.index
|
|
result_df2 = tmx_model.load_options("XIU", pydantic=True)
|
|
assert result_df["price"] == result_df2.last_price
|
|
assert hasattr(result_df2, "underlying_price")
|
|
assert isinstance(result_df2.underlying_price, dict)
|
|
assert result_df2.underlying_price["price"] == result_df["price"]
|
|
|
|
|
|
@pytest.mark.record_stdout
|
|
def test_underlying_price_bad_symbol():
|
|
result_df = tmx_model.get_underlying_price("BAD_SYMBOL")
|
|
assert result_df.empty
|
|
|
|
|
|
@pytest.mark.vcr
|
|
def test_underlying_name():
|
|
ticker = tmx_model.get_chains("BAM")
|
|
assert hasattr(ticker, "underlying_name")
|
|
assert isinstance(ticker.underlying_name, str)
|
|
assert ticker.underlying_name != "BAM"
|
|
|
|
|
|
@pytest.mark.vcr
|
|
def test_check_symbol():
|
|
result_df = tmx_model.check_symbol("BAD_SYMBOL")
|
|
assert isinstance(result_df, bool)
|
|
result_df2 = tmx_model.check_symbol("CM")
|
|
assert result_df2 is True
|
|
|
|
|
|
@pytest.mark.vcr
|
|
def test_last_price():
|
|
ticker = tmx_model.load_options("AC")
|
|
assert hasattr(ticker, "last_price")
|
|
assert isinstance(ticker.last_price, float)
|
|
ticker2 = tmx_model.get_eodchains("AC", "2021-12-28")
|
|
assert hasattr(ticker2, "last_price")
|
|
assert isinstance(ticker2.last_price, float)
|
|
assert ticker.last_price != ticker2.last_price
|
|
|
|
|
|
@pytest.mark.vcr
|
|
def test_chains():
|
|
ticker = tmx_model.get_chains("BMO")
|
|
assert hasattr(ticker, "chains")
|
|
assert isinstance(ticker.chains, pd.DataFrame)
|
|
ticker = tmx_model.load_options("BMO", pydantic=True)
|
|
assert hasattr(ticker, "chains")
|
|
assert isinstance(ticker.chains, dict)
|
|
assert ticker.hasGreeks is False
|
|
|
|
|
|
@pytest.mark.vcr
|
|
def test_strikes():
|
|
ticker = tmx_model.get_chains("RY")
|
|
assert hasattr(ticker, "strikes")
|
|
assert isinstance(ticker.strikes, list)
|
|
assert isinstance(ticker.strikes[0], float)
|
|
assert ticker.strikes[-1] == max(ticker.chains["strike"])
|
|
|
|
|
|
@pytest.mark.vcr
|
|
def test_eodchains_holiday():
|
|
ticker = tmx_model.get_eodchains("SU", "2018-12-25")
|
|
assert not ticker.chains.empty
|
|
ticker1 = tmx_model.get_eodchains("SU", "2020-07-01")
|
|
assert hasattr(ticker1, "date")
|
|
assert ticker1.date != "2020-07-01"
|
|
|
|
|
|
@pytest.mark.vcr
|
|
def test_expirations():
|
|
ticker = tmx_model.load_options("VFV")
|
|
assert hasattr(ticker, "expirations")
|
|
results1 = ticker.expirations
|
|
assert isinstance(results1, list)
|
|
ticker2 = tmx_model.get_eodchains("VFV", "2021-12-28")
|
|
results_df2 = ticker2.expirations
|
|
assert isinstance(results_df2, list)
|
|
assert results1[1] != results_df2[1]
|
|
|
|
|
|
@pytest.mark.vcr
|
|
def test_SYMBOLS():
|
|
results_df = tmx_model.get_all_ticker_symbols()
|
|
assert not results_df.empty
|
|
assert "RY" in results_df.index
|
|
|
|
|
|
@pytest.mark.vcr
|
|
def test_hasGreeks_hasIV():
|
|
ac = tmx_model.load_options("AC")
|
|
assert ac.hasGreeks is False
|
|
assert ac.hasIV is False
|
|
ac2 = tmx_model.get_eodchains("AC", "2022-01-03")
|
|
assert ac2.hasIV
|
|
assert ac2.hasGreeks is False
|