openmarkets 0.1.0.dev102__tar.gz → 0.1.0.dev112__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- openmarkets-0.1.0.dev112/.github/workflows/mirror.yaml +14 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/.pre-commit-config.yaml +2 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/PKG-INFO +7 -5
- {openmarkets-0.1.0.dev102/other/mkt → openmarkets-0.1.0.dev112}/README.md +3 -3
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/pyproject.toml +17 -8
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/_version.py +2 -2
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/tools/options.py +58 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/tests/tools/test_financial_statements.py +1 -1
- openmarkets-0.1.0.dev112/tests/tools/test_options.py +363 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/live.pyi +1 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/utils.pyi +1 -0
- openmarkets-0.1.0.dev102/.vscode/settings.json +0 -7
- openmarkets-0.1.0.dev102/tests/tools/test_options.py +0 -115
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/.editorconfig +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/.gemini/config.yaml +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/.git-blame-ignore-revs +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/.gitattributes +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/.github/CODEOWNERS +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/.gitignore +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/.python-version +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/.vscode/mcp.json +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/CITATION.cff +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/LICENSE +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/docs/api.md +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/docs/index.md +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/mkdocs.yml +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112/other/mcp-server-yfinance}/README.md +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/other/mcp-server-yfinance/mcp_server_yfinance/__main__.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/other/mcp-server-yfinance/pyproject.toml +0 -0
- {openmarkets-0.1.0.dev102/other/mcp-server-yfinance → openmarkets-0.1.0.dev112/other/mkt}/README.md +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/other/mkt/mkt/__main__.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/other/mkt/pyproject.toml +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/pyrightconfig.json +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/__init__.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/__main__.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/core/__init__.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/core/exceptions.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/core/models.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/core/registry.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/core/serializers.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/core/server.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/core/utils.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/py.typed +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/schemas/__init__.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/services/__init__.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/tools/__init__.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/tools/analyst_data.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/tools/calendar.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/tools/corporate_actions.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/tools/crypto.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/tools/extended_market.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/tools/financial_statements.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/tools/funds.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/tools/historical_data.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/tools/market_data.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/tools/news.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/tools/screener.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/tools/stock_info.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/tools/technical_analysis.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/tests/core/test_exceptions.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/tests/core/test_models.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/tests/core/test_registry.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/tests/core/test_serializers.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/tests/core/test_server.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/tests/core/test_utils.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/tests/tools/test_analyst_data.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/tests/tools/test_calendar.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/tests/tools/test_corporate_actions.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/tests/tools/test_crypto.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/tests/tools/test_extended_market.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/tests/tools/test_funds.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/tests/tools/test_funds_2.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/tests/tools/test_historical_data.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/tests/tools/test_market_data.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/tests/tools/test_stock_info.py +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/__init__.pyi +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/base.pyi +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/cache.pyi +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/const.pyi +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/data.pyi +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/domain/__init__.pyi +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/domain/domain.pyi +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/domain/industry.pyi +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/domain/market.pyi +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/domain/sector.pyi +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/exceptions.pyi +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/lookup.pyi +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/multi.pyi +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/pricing_pb2.pyi +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/scrapers/__init__.pyi +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/scrapers/analysis.pyi +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/scrapers/fundamentals.pyi +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/scrapers/funds.pyi +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/scrapers/history.pyi +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/scrapers/holders.pyi +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/scrapers/quote.pyi +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/screener/__init__.pyi +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/screener/query.pyi +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/screener/screener.pyi +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/search.pyi +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/shared.pyi +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/ticker.pyi +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/tickers.pyi +0 -0
- {openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/version.pyi +0 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
name: Mirror to GitLab
|
|
2
|
+
on: [push, workflow_dispatch]
|
|
3
|
+
jobs:
|
|
4
|
+
mirror:
|
|
5
|
+
runs-on: ubuntu-latest
|
|
6
|
+
steps:
|
|
7
|
+
- uses: actions/checkout@v3
|
|
8
|
+
with:
|
|
9
|
+
fetch-depth: 0
|
|
10
|
+
- uses: yesolutions/mirror-action@master
|
|
11
|
+
with:
|
|
12
|
+
REMOTE: 'https://gitlab.com/danchev-org/openmarkets.git'
|
|
13
|
+
GIT_USERNAME: danchev-org
|
|
14
|
+
GIT_PASSWORD: ${{ secrets.GIT_PASSWORD }}
|
|
@@ -20,6 +20,8 @@ repos:
|
|
|
20
20
|
args: [--fix, --exit-non-zero-on-fix]
|
|
21
21
|
exclude: "^typings/"
|
|
22
22
|
- id: ruff-format
|
|
23
|
+
# Install the configuration into the git hook through pre-commit:
|
|
24
|
+
# `pre-commit install --hook-type commit-msg`
|
|
23
25
|
- repo: https://github.com/commitizen-tools/commitizen
|
|
24
26
|
rev: v4.8.3
|
|
25
27
|
hooks:
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: openmarkets
|
|
3
|
-
Version: 0.1.0.
|
|
3
|
+
Version: 0.1.0.dev112
|
|
4
4
|
Summary: A Model Context Protocol (MCP) server for agentic retrieval of financial market data. This server leverages YFinance to provide a simple and efficient way to access historical stock prices, dividends, stock splits, company information, and other financial metrics.
|
|
5
|
-
Project-URL: Homepage, https://
|
|
5
|
+
Project-URL: Homepage, https://openmarkets.dev
|
|
6
|
+
Project-URL: Source, https://github.com/danchev/openmarkets
|
|
7
|
+
Project-URL: Documentation, https://danchev.github.io/openmarkets
|
|
6
8
|
Project-URL: Issues, https://github.com/danchev/openmarkets/issues
|
|
7
9
|
Author-email: Dobri Danchev <python-dist@danchev.net>
|
|
8
10
|
License: AGPL-3.0-or-later
|
|
@@ -72,7 +74,7 @@ This MCP server can be used with various LLM applications that support the Model
|
|
|
72
74
|
```json
|
|
73
75
|
{
|
|
74
76
|
"mcpServers": {
|
|
75
|
-
"
|
|
77
|
+
"openmarkets": {
|
|
76
78
|
"command": "uvx",
|
|
77
79
|
"args": [
|
|
78
80
|
"openmarkets@latest"
|
|
@@ -88,7 +90,7 @@ This MCP server can be used with various LLM applications that support the Model
|
|
|
88
90
|
|
|
89
91
|
For quick installation, use one of the one-click installation buttons below:
|
|
90
92
|
|
|
91
|
-
[](https://insiders.vscode.dev/redirect/mcp/install?name=
|
|
93
|
+
[](https://insiders.vscode.dev/redirect/mcp/install?name=openmarkets&config=%7B%22command%22%3A%22uvx%22%2C%22args%22%3A%5B%22openmarkets%22%5D%7D) [](https://insiders.vscode.dev/redirect/mcp/install?name=openmarkets&config=%7B%22command%22%3A%22uvx%22%2C%22args%22%3A%5B%22openmarkets%22%5D%7D&quality=insiders)
|
|
92
94
|
|
|
93
95
|
For manual installation, add the following JSON block to your User Settings (JSON) file in VS Code. You can do this by pressing `Ctrl + Shift + P` and typing `Preferences: Open Settings (JSON)`.
|
|
94
96
|
|
|
@@ -102,7 +104,7 @@ Optionally, you can add it to a file called `.vscode/mcp.json` in your workspace
|
|
|
102
104
|
{
|
|
103
105
|
"mcp": {
|
|
104
106
|
"servers": {
|
|
105
|
-
"
|
|
107
|
+
"openmarkets": {
|
|
106
108
|
"command": "uvx",
|
|
107
109
|
"args": [
|
|
108
110
|
"openmarkets@latest"
|
|
@@ -37,7 +37,7 @@ This MCP server can be used with various LLM applications that support the Model
|
|
|
37
37
|
```json
|
|
38
38
|
{
|
|
39
39
|
"mcpServers": {
|
|
40
|
-
"
|
|
40
|
+
"openmarkets": {
|
|
41
41
|
"command": "uvx",
|
|
42
42
|
"args": [
|
|
43
43
|
"openmarkets@latest"
|
|
@@ -53,7 +53,7 @@ This MCP server can be used with various LLM applications that support the Model
|
|
|
53
53
|
|
|
54
54
|
For quick installation, use one of the one-click installation buttons below:
|
|
55
55
|
|
|
56
|
-
[](https://insiders.vscode.dev/redirect/mcp/install?name=
|
|
56
|
+
[](https://insiders.vscode.dev/redirect/mcp/install?name=openmarkets&config=%7B%22command%22%3A%22uvx%22%2C%22args%22%3A%5B%22openmarkets%22%5D%7D) [](https://insiders.vscode.dev/redirect/mcp/install?name=openmarkets&config=%7B%22command%22%3A%22uvx%22%2C%22args%22%3A%5B%22openmarkets%22%5D%7D&quality=insiders)
|
|
57
57
|
|
|
58
58
|
For manual installation, add the following JSON block to your User Settings (JSON) file in VS Code. You can do this by pressing `Ctrl + Shift + P` and typing `Preferences: Open Settings (JSON)`.
|
|
59
59
|
|
|
@@ -67,7 +67,7 @@ Optionally, you can add it to a file called `.vscode/mcp.json` in your workspace
|
|
|
67
67
|
{
|
|
68
68
|
"mcp": {
|
|
69
69
|
"servers": {
|
|
70
|
-
"
|
|
70
|
+
"openmarkets": {
|
|
71
71
|
"command": "uvx",
|
|
72
72
|
"args": [
|
|
73
73
|
"openmarkets@latest"
|
|
@@ -43,7 +43,9 @@ dependencies = [
|
|
|
43
43
|
]
|
|
44
44
|
|
|
45
45
|
[project.urls]
|
|
46
|
-
Homepage = "https://
|
|
46
|
+
Homepage = "https://openmarkets.dev"
|
|
47
|
+
Source = "https://github.com/danchev/openmarkets"
|
|
48
|
+
Documentation = "https://danchev.github.io/openmarkets"
|
|
47
49
|
Issues = "https://github.com/danchev/openmarkets/issues"
|
|
48
50
|
|
|
49
51
|
[project.scripts]
|
|
@@ -72,20 +74,27 @@ raw-options.fallback_version = "0.0.0"
|
|
|
72
74
|
[dependency-groups]
|
|
73
75
|
dev = [
|
|
74
76
|
"pyright>=1.1.402",
|
|
75
|
-
"
|
|
77
|
+
"refurb>=2.1.0",
|
|
78
|
+
"ruff>=0.12.0",
|
|
79
|
+
"ty>=0.0.1a11",
|
|
80
|
+
{include-group = "test"},
|
|
81
|
+
{include-group = "commit"},
|
|
82
|
+
]
|
|
83
|
+
test = [
|
|
84
|
+
"pytest>=8.4.1",
|
|
76
85
|
"pytest-cov>=6.2.1",
|
|
77
86
|
"pytest-xdist>=3.7.0",
|
|
78
87
|
"pytest-asyncio>= 1.0.0",
|
|
79
|
-
"refurb>=2.1.0",
|
|
80
|
-
"ruff>=0.11.10",
|
|
81
|
-
"ty>=0.0.1a4",
|
|
82
88
|
]
|
|
83
|
-
commit = ["commitizen>=4.8.3", "pre-commit>=4.2.0"]
|
|
84
89
|
docs = [
|
|
85
90
|
"mkdocs>=1.6.1",
|
|
86
91
|
"mkdocs-glightbox>=0.4.0",
|
|
87
|
-
"mkdocs-material[imaging]>=9.
|
|
88
|
-
"mkdocstrings-python>=1.12
|
|
92
|
+
"mkdocs-material[imaging]>=9.6.14",
|
|
93
|
+
"mkdocstrings-python>=1.16.12",
|
|
94
|
+
]
|
|
95
|
+
commit = [
|
|
96
|
+
"commitizen>=4.8.3",
|
|
97
|
+
"pre-commit>=4.2.0",
|
|
89
98
|
]
|
|
90
99
|
|
|
91
100
|
[tool.ruff]
|
|
@@ -17,5 +17,5 @@ __version__: str
|
|
|
17
17
|
__version_tuple__: VERSION_TUPLE
|
|
18
18
|
version_tuple: VERSION_TUPLE
|
|
19
19
|
|
|
20
|
-
__version__ = version = '0.1.0.
|
|
21
|
-
__version_tuple__ = version_tuple = (0, 1, 0, '
|
|
20
|
+
__version__ = version = '0.1.0.dev112'
|
|
21
|
+
__version_tuple__ = version_tuple = (0, 1, 0, 'dev112')
|
|
@@ -152,6 +152,64 @@ async def get_options_by_moneyness(
|
|
|
152
152
|
return json.dumps({"error": f"Failed to filter options data: {str(e)}"})
|
|
153
153
|
|
|
154
154
|
|
|
155
|
+
async def get_options_skew(ticker: str, expiration_date: Optional[str] = None) -> str:
|
|
156
|
+
"""Analyze and return the volatility skew for call and put options.
|
|
157
|
+
|
|
158
|
+
This function retrieves the implied volatility for each strike price of both call and put options
|
|
159
|
+
for a given stock ticker and expiration date. If no expiration date is provided, the nearest available
|
|
160
|
+
expiration is used. The result is a JSON string containing lists of strike/implied volatility pairs
|
|
161
|
+
for calls and puts, which can be used to visualize or analyze the volatility skew.
|
|
162
|
+
|
|
163
|
+
Args:
|
|
164
|
+
ticker: Stock ticker symbol (e.g., 'AAPL').
|
|
165
|
+
expiration_date: Expiration date in 'YYYY-MM-DD' format. If None, uses the nearest expiration.
|
|
166
|
+
|
|
167
|
+
Returns:
|
|
168
|
+
JSON string with two keys:
|
|
169
|
+
- "call_skew": List of dicts with 'strike' and 'impliedVolatility' for call options.
|
|
170
|
+
- "put_skew": List of dicts with 'strike' and 'impliedVolatility' for put options.
|
|
171
|
+
If data is unavailable or an error occurs, returns a JSON string with an "error" key.
|
|
172
|
+
"""
|
|
173
|
+
try:
|
|
174
|
+
stock = yf.Ticker(ticker)
|
|
175
|
+
|
|
176
|
+
# If no expiration date is provided, use the nearest available expiration
|
|
177
|
+
if not expiration_date:
|
|
178
|
+
expirations = stock.options
|
|
179
|
+
if not expirations:
|
|
180
|
+
return json.dumps({"error": "No options data available for this ticker."})
|
|
181
|
+
expiration_date = expirations[0]
|
|
182
|
+
|
|
183
|
+
option_chain = stock.option_chain(expiration_date)
|
|
184
|
+
# Check if option chain data is available and not empty
|
|
185
|
+
if not option_chain or (option_chain.calls.empty and option_chain.puts.empty):
|
|
186
|
+
return json.dumps({"error": f"No options data available for {ticker} on {expiration_date}."})
|
|
187
|
+
|
|
188
|
+
call_skew = []
|
|
189
|
+
if not option_chain.calls.empty:
|
|
190
|
+
# Ensure required columns are present in calls DataFrame
|
|
191
|
+
if "strike" not in option_chain.calls.columns or "impliedVolatility" not in option_chain.calls.columns:
|
|
192
|
+
return json.dumps({"error": "Missing 'strike' or 'impliedVolatility' in call options data."})
|
|
193
|
+
call_skew = option_chain.calls[["strike", "impliedVolatility"]].to_dict("records")
|
|
194
|
+
|
|
195
|
+
put_skew = []
|
|
196
|
+
if not option_chain.puts.empty:
|
|
197
|
+
# Ensure required columns are present in puts DataFrame
|
|
198
|
+
if "strike" not in option_chain.puts.columns or "impliedVolatility" not in option_chain.puts.columns:
|
|
199
|
+
return json.dumps({"error": "Missing 'strike' or 'impliedVolatility' in put options data."})
|
|
200
|
+
put_skew = option_chain.puts[["strike", "impliedVolatility"]].to_dict("records")
|
|
201
|
+
|
|
202
|
+
result = {
|
|
203
|
+
"call_skew": call_skew,
|
|
204
|
+
"put_skew": put_skew,
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
return json.dumps(result, indent=2, cls=JSONSerializer)
|
|
208
|
+
except Exception as e:
|
|
209
|
+
# Catch and report any errors from yfinance or data processing
|
|
210
|
+
return json.dumps({"error": f"Failed to get volatility skew analysis: {str(e)}"})
|
|
211
|
+
|
|
212
|
+
|
|
155
213
|
def register_options_tools(mcp: FastMCP):
|
|
156
214
|
"""Register options tools with the MCP server."""
|
|
157
215
|
module = sys.modules[__name__]
|
{openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/tests/tools/test_financial_statements.py
RENAMED
|
@@ -304,7 +304,7 @@ class TestFinancialStatementFunctions:
|
|
|
304
304
|
expected_error = json.dumps({"error": "No cash flow data available"})
|
|
305
305
|
assert result == expected_error
|
|
306
306
|
|
|
307
|
-
async def
|
|
307
|
+
async def test_get_income_statement_2(self):
|
|
308
308
|
mock_df_non_empty = create_mock_df()
|
|
309
309
|
mock_df_empty = create_mock_df(empty=True)
|
|
310
310
|
|
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from unittest.mock import MagicMock, patch
|
|
3
|
+
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
import openmarkets.tools.options as opt
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@pytest.mark.asyncio
|
|
10
|
+
@patch("yfinance.Ticker")
|
|
11
|
+
async def test_get_options_expiration_dates_success(mock_ticker_cls):
|
|
12
|
+
mock_ticker = MagicMock()
|
|
13
|
+
mock_ticker.options = ["2024-06-21", "2024-06-28"]
|
|
14
|
+
mock_ticker_cls.return_value = mock_ticker
|
|
15
|
+
|
|
16
|
+
result = await opt.get_options_expiration_dates("AAPL")
|
|
17
|
+
data = json.loads(result)
|
|
18
|
+
assert "expiration_dates" in data
|
|
19
|
+
assert data["expiration_dates"] == ["2024-06-21", "2024-06-28"]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@pytest.mark.xfail
|
|
23
|
+
@pytest.mark.asyncio
|
|
24
|
+
@patch("yfinance.Ticker")
|
|
25
|
+
async def test_get_options_expiration_dates_error(mock_ticker_cls):
|
|
26
|
+
mock_ticker_cls.side_effect = Exception("fail")
|
|
27
|
+
result = await opt.get_options_expiration_dates("AAPL")
|
|
28
|
+
data = json.loads(result)
|
|
29
|
+
assert "error" in data
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@pytest.mark.asyncio
|
|
33
|
+
@patch("yfinance.Ticker")
|
|
34
|
+
async def test_get_option_chain_success(mock_ticker_cls):
|
|
35
|
+
mock_calls = MagicMock()
|
|
36
|
+
mock_calls.to_dict.return_value = [{"strike": 100}]
|
|
37
|
+
mock_puts = MagicMock()
|
|
38
|
+
mock_puts.to_dict.return_value = [{"strike": 90}]
|
|
39
|
+
mock_chain = MagicMock(calls=mock_calls, puts=mock_puts)
|
|
40
|
+
mock_ticker = MagicMock()
|
|
41
|
+
mock_ticker.options = ["2024-06-21"]
|
|
42
|
+
mock_ticker.option_chain.return_value = mock_chain
|
|
43
|
+
mock_ticker_cls.return_value = mock_ticker
|
|
44
|
+
|
|
45
|
+
result = await opt.get_option_chain("AAPL", "2024-06-21")
|
|
46
|
+
data = json.loads(result)
|
|
47
|
+
assert "calls" in data and "puts" in data
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@pytest.mark.asyncio
|
|
51
|
+
@patch("yfinance.Ticker")
|
|
52
|
+
async def test_get_option_chain_no_expirations(mock_ticker_cls):
|
|
53
|
+
mock_ticker = MagicMock()
|
|
54
|
+
mock_ticker.options = []
|
|
55
|
+
mock_ticker_cls.return_value = mock_ticker
|
|
56
|
+
|
|
57
|
+
result = await opt.get_option_chain("AAPL")
|
|
58
|
+
data = json.loads(result)
|
|
59
|
+
assert "error" in data
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@pytest.mark.asyncio
|
|
63
|
+
@patch("yfinance.Ticker")
|
|
64
|
+
async def test_get_options_volume_analysis_success(mock_ticker_cls):
|
|
65
|
+
import pandas as pd
|
|
66
|
+
|
|
67
|
+
calls = pd.DataFrame({"volume": [10, 20], "openInterest": [100, 200]})
|
|
68
|
+
puts = pd.DataFrame({"volume": [5, 15], "openInterest": [50, 150]})
|
|
69
|
+
mock_chain = MagicMock(calls=calls, puts=puts)
|
|
70
|
+
mock_ticker = MagicMock()
|
|
71
|
+
mock_ticker.options = ["2024-06-21"]
|
|
72
|
+
mock_ticker.option_chain.return_value = mock_chain
|
|
73
|
+
mock_ticker_cls.return_value = mock_ticker
|
|
74
|
+
|
|
75
|
+
result = await opt.get_options_volume_analysis("AAPL", "2024-06-21")
|
|
76
|
+
data = json.loads(result)
|
|
77
|
+
assert "total_call_volume" in data
|
|
78
|
+
assert data["total_call_volume"] == 30
|
|
79
|
+
assert data["total_put_volume"] == 20
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@pytest.mark.asyncio
|
|
83
|
+
@patch("yfinance.Ticker")
|
|
84
|
+
async def test_get_options_by_moneyness_success(mock_ticker_cls):
|
|
85
|
+
import pandas as pd
|
|
86
|
+
|
|
87
|
+
calls = pd.DataFrame({"strike": [95, 100, 105]})
|
|
88
|
+
puts = pd.DataFrame({"strike": [90, 100, 110]})
|
|
89
|
+
mock_chain = MagicMock(calls=calls, puts=puts)
|
|
90
|
+
mock_ticker = MagicMock()
|
|
91
|
+
mock_ticker.options = ["2024-06-21"]
|
|
92
|
+
mock_ticker.option_chain.return_value = mock_chain
|
|
93
|
+
mock_ticker.info = {"currentPrice": 100}
|
|
94
|
+
mock_ticker_cls.return_value = mock_ticker
|
|
95
|
+
|
|
96
|
+
result = await opt.get_options_by_moneyness("AAPL", moneyness_range=0.05)
|
|
97
|
+
data = json.loads(result)
|
|
98
|
+
assert "calls" in data and "puts" in data
|
|
99
|
+
assert all(95 <= c["strike"] <= 105 for c in data["calls"])
|
|
100
|
+
assert all(95 <= p["strike"] <= 105 for p in data["puts"])
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
@pytest.mark.asyncio
|
|
104
|
+
@patch("yfinance.Ticker")
|
|
105
|
+
async def test_get_options_by_moneyness_no_price(mock_ticker_cls):
|
|
106
|
+
mock_chain = MagicMock(calls=[], puts=[])
|
|
107
|
+
mock_ticker = MagicMock()
|
|
108
|
+
mock_ticker.options = ["2024-06-21"]
|
|
109
|
+
mock_ticker.option_chain.return_value = mock_chain
|
|
110
|
+
mock_ticker.info = {}
|
|
111
|
+
mock_ticker_cls.return_value = mock_ticker
|
|
112
|
+
|
|
113
|
+
result = await opt.get_options_by_moneyness("AAPL")
|
|
114
|
+
data = json.loads(result)
|
|
115
|
+
assert "error" in data
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
@pytest.mark.asyncio
|
|
119
|
+
@patch("yfinance.Ticker")
|
|
120
|
+
async def test_get_options_skew_success_with_date(mock_ticker_cls):
|
|
121
|
+
import pandas as pd
|
|
122
|
+
mock_ticker_instance = MagicMock()
|
|
123
|
+
mock_ticker_cls.return_value = mock_ticker_instance
|
|
124
|
+
|
|
125
|
+
# Mock options dates
|
|
126
|
+
mock_ticker_instance.options = ("2025-01-01", "2025-02-01")
|
|
127
|
+
|
|
128
|
+
# Mock option_chain data
|
|
129
|
+
calls_data = {"strike": [100, 105], "impliedVolatility": [0.5, 0.45]}
|
|
130
|
+
puts_data = {"strike": [90, 95], "impliedVolatility": [0.6, 0.55]}
|
|
131
|
+
mock_calls_df = pd.DataFrame(calls_data)
|
|
132
|
+
mock_puts_df = pd.DataFrame(puts_data)
|
|
133
|
+
|
|
134
|
+
mock_option_chain_data = MagicMock()
|
|
135
|
+
mock_option_chain_data.calls = mock_calls_df
|
|
136
|
+
mock_option_chain_data.puts = mock_puts_df
|
|
137
|
+
mock_ticker_instance.option_chain.return_value = mock_option_chain_data
|
|
138
|
+
|
|
139
|
+
ticker = "TEST"
|
|
140
|
+
expiration_date = "2025-01-01"
|
|
141
|
+
result_str = await opt.get_options_skew(ticker, expiration_date)
|
|
142
|
+
result_json = json.loads(result_str)
|
|
143
|
+
|
|
144
|
+
assert "error" not in result_json
|
|
145
|
+
assert "call_skew" in result_json
|
|
146
|
+
assert "put_skew" in result_json
|
|
147
|
+
assert result_json["call_skew"] == mock_calls_df[["strike", "impliedVolatility"]].to_dict("records")
|
|
148
|
+
assert result_json["put_skew"] == mock_puts_df[["strike", "impliedVolatility"]].to_dict("records")
|
|
149
|
+
mock_ticker_instance.option_chain.assert_called_once_with(expiration_date)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
@pytest.mark.asyncio
|
|
153
|
+
@patch("yfinance.Ticker")
|
|
154
|
+
async def test_get_options_skew_success_no_date(mock_ticker_cls):
|
|
155
|
+
import pandas as pd
|
|
156
|
+
mock_ticker_instance = MagicMock()
|
|
157
|
+
mock_ticker_cls.return_value = mock_ticker_instance
|
|
158
|
+
|
|
159
|
+
# Mock options dates - nearest is '2025-01-01'
|
|
160
|
+
nearest_expiration = "2025-01-01"
|
|
161
|
+
mock_ticker_instance.options = (nearest_expiration, "2025-02-01")
|
|
162
|
+
|
|
163
|
+
# Mock option_chain data
|
|
164
|
+
calls_data = {"strike": [110, 115], "impliedVolatility": [0.3, 0.25]}
|
|
165
|
+
puts_data = {"strike": [100, 105], "impliedVolatility": [0.4, 0.35]}
|
|
166
|
+
mock_calls_df = pd.DataFrame(calls_data)
|
|
167
|
+
mock_puts_df = pd.DataFrame(puts_data)
|
|
168
|
+
|
|
169
|
+
mock_option_chain_data = MagicMock()
|
|
170
|
+
mock_option_chain_data.calls = mock_calls_df
|
|
171
|
+
mock_option_chain_data.puts = mock_puts_df
|
|
172
|
+
mock_ticker_instance.option_chain.return_value = mock_option_chain_data
|
|
173
|
+
|
|
174
|
+
ticker = "TEST"
|
|
175
|
+
result_str = await opt.get_options_skew(ticker, None) # No expiration_date
|
|
176
|
+
result_json = json.loads(result_str)
|
|
177
|
+
|
|
178
|
+
assert "error" not in result_json
|
|
179
|
+
assert result_json["call_skew"] == mock_calls_df[["strike", "impliedVolatility"]].to_dict("records")
|
|
180
|
+
assert result_json["put_skew"] == mock_puts_df[["strike", "impliedVolatility"]].to_dict("records")
|
|
181
|
+
# Should be called with the first expiration date
|
|
182
|
+
mock_ticker_instance.option_chain.assert_called_once_with(nearest_expiration)
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
@pytest.mark.asyncio
|
|
186
|
+
@patch("yfinance.Ticker")
|
|
187
|
+
async def test_get_options_skew_error_no_expirations(mock_ticker_cls):
|
|
188
|
+
mock_ticker_instance = MagicMock()
|
|
189
|
+
mock_ticker_cls.return_value = mock_ticker_instance
|
|
190
|
+
mock_ticker_instance.options = () # No expiration dates
|
|
191
|
+
|
|
192
|
+
ticker = "TEST"
|
|
193
|
+
result_str = await opt.get_options_skew(ticker, None)
|
|
194
|
+
result_json = json.loads(result_str)
|
|
195
|
+
|
|
196
|
+
assert "error" in result_json
|
|
197
|
+
assert result_json["error"] == "No options data available for this ticker."
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
@pytest.mark.asyncio
|
|
201
|
+
@patch("yfinance.Ticker")
|
|
202
|
+
async def test_get_options_skew_error_no_data_for_date(mock_ticker_cls):
|
|
203
|
+
import pandas as pd
|
|
204
|
+
mock_ticker_instance = MagicMock()
|
|
205
|
+
mock_ticker_cls.return_value = mock_ticker_instance
|
|
206
|
+
|
|
207
|
+
expiration_date = "2025-01-01"
|
|
208
|
+
mock_ticker_instance.options = (expiration_date,)
|
|
209
|
+
|
|
210
|
+
# Mock option_chain to return empty calls and puts
|
|
211
|
+
mock_empty_df = pd.DataFrame()
|
|
212
|
+
mock_option_chain_empty = MagicMock()
|
|
213
|
+
mock_option_chain_empty.calls = mock_empty_df
|
|
214
|
+
mock_option_chain_empty.puts = mock_empty_df
|
|
215
|
+
mock_ticker_instance.option_chain.return_value = mock_option_chain_empty
|
|
216
|
+
|
|
217
|
+
ticker = "TEST"
|
|
218
|
+
result_str = await opt.get_options_skew(ticker, expiration_date)
|
|
219
|
+
result_json = json.loads(result_str)
|
|
220
|
+
|
|
221
|
+
assert "error" in result_json
|
|
222
|
+
assert result_json["error"] == f"No options data available for {ticker} on {expiration_date}."
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
@pytest.mark.asyncio
|
|
226
|
+
@patch("yfinance.Ticker")
|
|
227
|
+
async def test_get_options_skew_error_missing_strike_calls(mock_ticker_cls):
|
|
228
|
+
import pandas as pd
|
|
229
|
+
mock_ticker_instance = MagicMock()
|
|
230
|
+
mock_ticker_cls.return_value = mock_ticker_instance
|
|
231
|
+
|
|
232
|
+
expiration_date = "2025-01-01"
|
|
233
|
+
mock_ticker_instance.options = (expiration_date,)
|
|
234
|
+
|
|
235
|
+
# Calls data missing 'strike'
|
|
236
|
+
calls_data = {"impliedVolatility": [0.5, 0.45]}
|
|
237
|
+
puts_data = {"strike": [90, 95], "impliedVolatility": [0.6, 0.55]}
|
|
238
|
+
mock_calls_df_missing_strike = pd.DataFrame(calls_data)
|
|
239
|
+
mock_puts_df = pd.DataFrame(puts_data)
|
|
240
|
+
|
|
241
|
+
mock_option_chain_data = MagicMock()
|
|
242
|
+
mock_option_chain_data.calls = mock_calls_df_missing_strike
|
|
243
|
+
mock_option_chain_data.puts = mock_puts_df # Puts are fine
|
|
244
|
+
mock_ticker_instance.option_chain.return_value = mock_option_chain_data
|
|
245
|
+
|
|
246
|
+
ticker = "TEST"
|
|
247
|
+
result_str = await opt.get_options_skew(ticker, expiration_date)
|
|
248
|
+
result_json = json.loads(result_str)
|
|
249
|
+
|
|
250
|
+
assert "error" in result_json
|
|
251
|
+
assert result_json["error"] == "Missing 'strike' or 'impliedVolatility' in call options data."
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
@pytest.mark.asyncio
|
|
255
|
+
@patch("yfinance.Ticker")
|
|
256
|
+
async def test_get_options_skew_error_missing_iv_puts(mock_ticker_cls):
|
|
257
|
+
import pandas as pd
|
|
258
|
+
mock_ticker_instance = MagicMock()
|
|
259
|
+
mock_ticker_cls.return_value = mock_ticker_instance
|
|
260
|
+
|
|
261
|
+
expiration_date = "2025-01-01"
|
|
262
|
+
mock_ticker_instance.options = (expiration_date,)
|
|
263
|
+
|
|
264
|
+
calls_data = {"strike": [100, 105], "impliedVolatility": [0.5, 0.45]}
|
|
265
|
+
# Puts data missing 'impliedVolatility'
|
|
266
|
+
puts_data = {"strike": [90, 95]}
|
|
267
|
+
mock_calls_df = pd.DataFrame(calls_data)
|
|
268
|
+
mock_puts_df_missing_iv = pd.DataFrame(puts_data)
|
|
269
|
+
|
|
270
|
+
mock_option_chain_data = MagicMock()
|
|
271
|
+
mock_option_chain_data.calls = mock_calls_df # Calls are fine
|
|
272
|
+
mock_option_chain_data.puts = mock_puts_df_missing_iv
|
|
273
|
+
mock_ticker_instance.option_chain.return_value = mock_option_chain_data
|
|
274
|
+
|
|
275
|
+
ticker = "TEST"
|
|
276
|
+
result_str = await opt.get_options_skew(ticker, expiration_date)
|
|
277
|
+
result_json = json.loads(result_str)
|
|
278
|
+
|
|
279
|
+
assert "error" in result_json
|
|
280
|
+
assert result_json["error"] == "Missing 'strike' or 'impliedVolatility' in put options data."
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
@pytest.mark.asyncio
|
|
284
|
+
@patch("yfinance.Ticker")
|
|
285
|
+
async def test_get_options_skew_error_yfinance_exception(mock_ticker_cls):
|
|
286
|
+
mock_ticker_instance = MagicMock()
|
|
287
|
+
mock_ticker_cls.return_value = mock_ticker_instance
|
|
288
|
+
|
|
289
|
+
expiration_date = "2025-01-01"
|
|
290
|
+
mock_ticker_instance.options = (expiration_date,)
|
|
291
|
+
|
|
292
|
+
# Mock option_chain to raise a generic exception
|
|
293
|
+
error_message = "Test yfinance download error"
|
|
294
|
+
mock_ticker_instance.option_chain.side_effect = Exception(error_message)
|
|
295
|
+
|
|
296
|
+
ticker = "TEST"
|
|
297
|
+
result_str = await opt.get_options_skew(ticker, expiration_date)
|
|
298
|
+
result_json = json.loads(result_str)
|
|
299
|
+
|
|
300
|
+
assert "error" in result_json
|
|
301
|
+
assert result_json["error"] == f"Failed to get volatility skew analysis: {error_message}"
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
@pytest.mark.asyncio
|
|
305
|
+
@patch("yfinance.Ticker")
|
|
306
|
+
async def test_get_options_skew_empty_calls_data(mock_ticker_cls):
|
|
307
|
+
import pandas as pd
|
|
308
|
+
mock_ticker_instance = MagicMock()
|
|
309
|
+
mock_ticker_cls.return_value = mock_ticker_instance
|
|
310
|
+
|
|
311
|
+
expiration_date = "2025-01-01"
|
|
312
|
+
mock_ticker_instance.options = (expiration_date,)
|
|
313
|
+
|
|
314
|
+
# Empty calls DataFrame, valid puts DataFrame
|
|
315
|
+
mock_empty_calls_df = pd.DataFrame(columns=["strike", "impliedVolatility"])
|
|
316
|
+
puts_data = {"strike": [90, 95], "impliedVolatility": [0.6, 0.55]}
|
|
317
|
+
mock_puts_df = pd.DataFrame(puts_data)
|
|
318
|
+
|
|
319
|
+
mock_option_chain_data = MagicMock()
|
|
320
|
+
mock_option_chain_data.calls = mock_empty_calls_df
|
|
321
|
+
mock_option_chain_data.puts = mock_puts_df
|
|
322
|
+
mock_ticker_instance.option_chain.return_value = mock_option_chain_data
|
|
323
|
+
|
|
324
|
+
ticker = "TEST"
|
|
325
|
+
result_str = await opt.get_options_skew(ticker, expiration_date)
|
|
326
|
+
result_json = json.loads(result_str)
|
|
327
|
+
|
|
328
|
+
assert "error" not in result_json
|
|
329
|
+
assert "call_skew" in result_json
|
|
330
|
+
assert result_json["call_skew"] == [] # Expect empty list for call_skew
|
|
331
|
+
assert "put_skew" in result_json
|
|
332
|
+
assert result_json["put_skew"] == mock_puts_df[["strike", "impliedVolatility"]].to_dict("records")
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
@pytest.mark.asyncio
|
|
336
|
+
@patch("yfinance.Ticker")
|
|
337
|
+
async def test_get_options_skew_empty_puts_data(mock_ticker_cls):
|
|
338
|
+
import pandas as pd
|
|
339
|
+
mock_ticker_instance = MagicMock()
|
|
340
|
+
mock_ticker_cls.return_value = mock_ticker_instance
|
|
341
|
+
|
|
342
|
+
expiration_date = "2025-01-01"
|
|
343
|
+
mock_ticker_instance.options = (expiration_date,)
|
|
344
|
+
|
|
345
|
+
# Valid calls DataFrame, empty puts DataFrame
|
|
346
|
+
calls_data = {"strike": [100, 105], "impliedVolatility": [0.5, 0.45]}
|
|
347
|
+
mock_calls_df = pd.DataFrame(calls_data)
|
|
348
|
+
mock_empty_puts_df = pd.DataFrame(columns=["strike", "impliedVolatility"])
|
|
349
|
+
|
|
350
|
+
mock_option_chain_data = MagicMock()
|
|
351
|
+
mock_option_chain_data.calls = mock_calls_df
|
|
352
|
+
mock_option_chain_data.puts = mock_empty_puts_df
|
|
353
|
+
mock_ticker_instance.option_chain.return_value = mock_option_chain_data
|
|
354
|
+
|
|
355
|
+
ticker = "TEST"
|
|
356
|
+
result_str = await opt.get_options_skew(ticker, expiration_date)
|
|
357
|
+
result_json = json.loads(result_str)
|
|
358
|
+
|
|
359
|
+
assert "error" not in result_json
|
|
360
|
+
assert "call_skew" in result_json
|
|
361
|
+
assert result_json["call_skew"] == mock_calls_df[["strike", "impliedVolatility"]].to_dict("records")
|
|
362
|
+
assert "put_skew" in result_json
|
|
363
|
+
assert result_json["put_skew"] == [] # Expect empty list for put_skew
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import json
|
|
2
|
-
from unittest.mock import MagicMock, patch
|
|
3
|
-
|
|
4
|
-
import pytest
|
|
5
|
-
|
|
6
|
-
import openmarkets.tools.options as opt
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
@pytest.mark.asyncio
|
|
10
|
-
@patch("yfinance.Ticker")
|
|
11
|
-
async def test_get_options_expiration_dates_success(mock_ticker_cls):
|
|
12
|
-
mock_ticker = MagicMock()
|
|
13
|
-
mock_ticker.options = ["2024-06-21", "2024-06-28"]
|
|
14
|
-
mock_ticker_cls.return_value = mock_ticker
|
|
15
|
-
|
|
16
|
-
result = await opt.get_options_expiration_dates("AAPL")
|
|
17
|
-
data = json.loads(result)
|
|
18
|
-
assert "expiration_dates" in data
|
|
19
|
-
assert data["expiration_dates"] == ["2024-06-21", "2024-06-28"]
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
@pytest.mark.xfail
|
|
23
|
-
@pytest.mark.asyncio
|
|
24
|
-
@patch("yfinance.Ticker")
|
|
25
|
-
async def test_get_options_expiration_dates_error(mock_ticker_cls):
|
|
26
|
-
mock_ticker_cls.side_effect = Exception("fail")
|
|
27
|
-
result = await opt.get_options_expiration_dates("AAPL")
|
|
28
|
-
data = json.loads(result)
|
|
29
|
-
assert "error" in data
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
@pytest.mark.asyncio
|
|
33
|
-
@patch("yfinance.Ticker")
|
|
34
|
-
async def test_get_option_chain_success(mock_ticker_cls):
|
|
35
|
-
mock_calls = MagicMock()
|
|
36
|
-
mock_calls.to_dict.return_value = [{"strike": 100}]
|
|
37
|
-
mock_puts = MagicMock()
|
|
38
|
-
mock_puts.to_dict.return_value = [{"strike": 90}]
|
|
39
|
-
mock_chain = MagicMock(calls=mock_calls, puts=mock_puts)
|
|
40
|
-
mock_ticker = MagicMock()
|
|
41
|
-
mock_ticker.options = ["2024-06-21"]
|
|
42
|
-
mock_ticker.option_chain.return_value = mock_chain
|
|
43
|
-
mock_ticker_cls.return_value = mock_ticker
|
|
44
|
-
|
|
45
|
-
result = await opt.get_option_chain("AAPL", "2024-06-21")
|
|
46
|
-
data = json.loads(result)
|
|
47
|
-
assert "calls" in data and "puts" in data
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
@pytest.mark.asyncio
|
|
51
|
-
@patch("yfinance.Ticker")
|
|
52
|
-
async def test_get_option_chain_no_expirations(mock_ticker_cls):
|
|
53
|
-
mock_ticker = MagicMock()
|
|
54
|
-
mock_ticker.options = []
|
|
55
|
-
mock_ticker_cls.return_value = mock_ticker
|
|
56
|
-
|
|
57
|
-
result = await opt.get_option_chain("AAPL")
|
|
58
|
-
data = json.loads(result)
|
|
59
|
-
assert "error" in data
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
@pytest.mark.asyncio
|
|
63
|
-
@patch("yfinance.Ticker")
|
|
64
|
-
async def test_get_options_volume_analysis_success(mock_ticker_cls):
|
|
65
|
-
import pandas as pd
|
|
66
|
-
|
|
67
|
-
calls = pd.DataFrame({"volume": [10, 20], "openInterest": [100, 200]})
|
|
68
|
-
puts = pd.DataFrame({"volume": [5, 15], "openInterest": [50, 150]})
|
|
69
|
-
mock_chain = MagicMock(calls=calls, puts=puts)
|
|
70
|
-
mock_ticker = MagicMock()
|
|
71
|
-
mock_ticker.options = ["2024-06-21"]
|
|
72
|
-
mock_ticker.option_chain.return_value = mock_chain
|
|
73
|
-
mock_ticker_cls.return_value = mock_ticker
|
|
74
|
-
|
|
75
|
-
result = await opt.get_options_volume_analysis("AAPL", "2024-06-21")
|
|
76
|
-
data = json.loads(result)
|
|
77
|
-
assert "total_call_volume" in data
|
|
78
|
-
assert data["total_call_volume"] == 30
|
|
79
|
-
assert data["total_put_volume"] == 20
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
@pytest.mark.asyncio
|
|
83
|
-
@patch("yfinance.Ticker")
|
|
84
|
-
async def test_get_options_by_moneyness_success(mock_ticker_cls):
|
|
85
|
-
import pandas as pd
|
|
86
|
-
|
|
87
|
-
calls = pd.DataFrame({"strike": [95, 100, 105]})
|
|
88
|
-
puts = pd.DataFrame({"strike": [90, 100, 110]})
|
|
89
|
-
mock_chain = MagicMock(calls=calls, puts=puts)
|
|
90
|
-
mock_ticker = MagicMock()
|
|
91
|
-
mock_ticker.options = ["2024-06-21"]
|
|
92
|
-
mock_ticker.option_chain.return_value = mock_chain
|
|
93
|
-
mock_ticker.info = {"currentPrice": 100}
|
|
94
|
-
mock_ticker_cls.return_value = mock_ticker
|
|
95
|
-
|
|
96
|
-
result = await opt.get_options_by_moneyness("AAPL", moneyness_range=0.05)
|
|
97
|
-
data = json.loads(result)
|
|
98
|
-
assert "calls" in data and "puts" in data
|
|
99
|
-
assert all(95 <= c["strike"] <= 105 for c in data["calls"])
|
|
100
|
-
assert all(95 <= p["strike"] <= 105 for p in data["puts"])
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
@pytest.mark.asyncio
|
|
104
|
-
@patch("yfinance.Ticker")
|
|
105
|
-
async def test_get_options_by_moneyness_no_price(mock_ticker_cls):
|
|
106
|
-
mock_chain = MagicMock(calls=[], puts=[])
|
|
107
|
-
mock_ticker = MagicMock()
|
|
108
|
-
mock_ticker.options = ["2024-06-21"]
|
|
109
|
-
mock_ticker.option_chain.return_value = mock_chain
|
|
110
|
-
mock_ticker.info = {}
|
|
111
|
-
mock_ticker_cls.return_value = mock_ticker
|
|
112
|
-
|
|
113
|
-
result = await opt.get_options_by_moneyness("AAPL")
|
|
114
|
-
data = json.loads(result)
|
|
115
|
-
assert "error" in data
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/other/mcp-server-yfinance/pyproject.toml
RENAMED
|
File without changes
|
{openmarkets-0.1.0.dev102/other/mcp-server-yfinance → openmarkets-0.1.0.dev112/other/mkt}/README.md
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/tools/corporate_actions.py
RENAMED
|
File without changes
|
|
File without changes
|
{openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/tools/extended_market.py
RENAMED
|
File without changes
|
{openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/tools/financial_statements.py
RENAMED
|
File without changes
|
|
File without changes
|
{openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/tools/historical_data.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/src/openmarkets/tools/technical_analysis.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/scrapers/__init__.pyi
RENAMED
|
File without changes
|
{openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/scrapers/analysis.pyi
RENAMED
|
File without changes
|
{openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/scrapers/fundamentals.pyi
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/screener/__init__.pyi
RENAMED
|
File without changes
|
|
File without changes
|
{openmarkets-0.1.0.dev102 → openmarkets-0.1.0.dev112}/typings/yfinance/screener/screener.pyi
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|