kensho-kfinance 1.0.3__tar.gz → 1.1.0a0__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.

Potentially problematic release.


This version of kensho-kfinance might be problematic. Click here for more details.

Files changed (50) hide show
  1. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/.gitignore +2 -0
  2. kensho_kfinance-1.1.0a0/.readthedocs.yaml +21 -0
  3. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/PKG-INFO +9 -3
  4. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/README.md +6 -1
  5. kensho_kfinance-1.1.0a0/docs/conf.py +66 -0
  6. kensho_kfinance-1.1.0a0/docs/index.rst +18 -0
  7. kensho_kfinance-1.1.0a0/docs/kfinance.rst +7 -0
  8. kensho_kfinance-1.1.0a0/docs/llm_tools.rst +7 -0
  9. kensho_kfinance-1.1.0a0/docs/requirements.txt +4 -0
  10. kensho_kfinance-1.1.0a0/docs/templates/apidoc/package.rst_t +50 -0
  11. kensho_kfinance-1.1.0a0/docs/templates/apidoc/toc.rst_t +10 -0
  12. kensho_kfinance-1.1.0a0/justfile +37 -0
  13. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/kensho_kfinance.egg-info/PKG-INFO +9 -3
  14. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/kensho_kfinance.egg-info/SOURCES.txt +7 -2
  15. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/kfinance/CHANGELOG.md +3 -0
  16. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/kfinance/fetch.py +22 -1
  17. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/kfinance/llm_tools.py +80 -21
  18. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/kfinance/meta_classes.py +74 -4
  19. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/kfinance/tests/test_fetch.py +32 -2
  20. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/kfinance/tests/test_objects.py +37 -0
  21. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/kfinance/tool_schemas.py +17 -1
  22. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/kfinance/version.py +2 -2
  23. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/scripts/lint.sh +4 -0
  24. kensho_kfinance-1.0.3/docs/index.rst +0 -9
  25. kensho_kfinance-1.0.3/docs/kfinance.rst +0 -5033
  26. kensho_kfinance-1.0.3/docs/llm_tools.rst +0 -191
  27. kensho_kfinance-1.0.3/scripts/docs/make_rst.py +0 -98
  28. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/.coveragerc +0 -0
  29. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/.github/workflows/ci-lint.yml +0 -0
  30. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/.github/workflows/ci-test.yml +0 -0
  31. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/.github/workflows/python-publish.yml +0 -0
  32. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/AUTHORS.md +0 -0
  33. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/CODE_OF_CONDUCT.md +0 -0
  34. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/CONTRIBUTING.md +0 -0
  35. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/LICENSE +0 -0
  36. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/kensho_kfinance.egg-info/dependency_links.txt +0 -0
  37. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/kensho_kfinance.egg-info/requires.txt +0 -0
  38. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/kensho_kfinance.egg-info/top_level.txt +0 -0
  39. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/kfinance/__init__.py +0 -0
  40. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/kfinance/constants.py +0 -0
  41. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/kfinance/kfinance.py +0 -0
  42. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/kfinance/prompt.py +0 -0
  43. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/kfinance/py.typed +0 -0
  44. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/kfinance/server_thread.py +0 -0
  45. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/kfinance/tests/__init__.py +0 -0
  46. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/pyproject.toml +0 -0
  47. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/scripts/copyright_line_check.sh +0 -0
  48. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/scripts/test.sh +0 -0
  49. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/setup.cfg +0 -0
  50. {kensho_kfinance-1.0.3 → kensho_kfinance-1.1.0a0}/setup.py +0 -0
@@ -98,3 +98,5 @@ dmypy.json
98
98
  .idea/*
99
99
  .vscode/
100
100
 
101
+
102
+ kfinance/version.py
@@ -0,0 +1,21 @@
1
+ version: 2
2
+ build:
3
+ os: ubuntu-22.04
4
+ tools:
5
+ python: "3.10"
6
+ # You can also specify other tool versions:
7
+ # nodejs: "16"
8
+ # borrowed from here:
9
+ # https://docs.readthedocs.com/platform/stable/build-customization.html#avoid-having-a-dirty-git-index
10
+ jobs:
11
+ pre_install:
12
+ - git update-index --assume-unchanged docs/conf.py
13
+
14
+ # Build documentation in the docs/ directory with Sphinx
15
+ sphinx:
16
+ configuration: docs/conf.py
17
+
18
+ # Dependencies required to build your docs
19
+ python:
20
+ install:
21
+ - requirements: docs/requirements.txt
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: kensho-kfinance
3
- Version: 1.0.3
3
+ Version: 1.1.0a0
4
4
  Summary: Python CLI for kFinance
5
5
  Author-email: Luke Brown <luke.brown@kensho.com>, Michelle Keoy <michelle.keoy@kensho.com>, Keith Page <keith.page@kensho.com>, Matthew Rosen <matthew.rosen@kensho.com>, Nick Roshdieh <nick.roshdieh@kensho.com>
6
6
  Project-URL: source, https://github.com/kensho-technologies/kfinance
@@ -28,6 +28,7 @@ Requires-Dist: mypy<2,>=1.15.0; extra == "dev"
28
28
  Requires-Dist: pytest<7,>=6.1.2; extra == "dev"
29
29
  Requires-Dist: pytest-cov<7,>=6.0.0; extra == "dev"
30
30
  Requires-Dist: ruff<1,>=0.9.4; extra == "dev"
31
+ Dynamic: license-file
31
32
 
32
33
  # kFinance
33
34
 
@@ -39,7 +40,7 @@ Any questions or suggestions can be sent to the [kFinance Maintainers](kfinance-
39
40
 
40
41
  # Setup
41
42
 
42
- You can install kFinance on [PyPI](https://pypi.org/project/kfinance/) via
43
+ You can install kFinance on [PyPI](https://pypi.org/project/kensho-kfinance/) via
43
44
 
44
45
  `pip install kensho-kfinance`
45
46
 
@@ -49,6 +50,11 @@ To receive access, please email [S&P Global Market Intelligence](market.intellig
49
50
 
50
51
  Once access is obtained, get started using the [Authentication Guide](https://docs.kensho.com/llmreadyapi/kf-authentication) and [Usage Guide](https://docs.kensho.com/llmreadyapi/usage).
51
52
 
53
+ # Versioning
54
+ The kFinance uses semantic versioning (major, minor, patch).
55
+ To bump the version, add a new entry in [CHANGELOG.md](kfinance%2FCHANGELOG.md).
56
+ This will generate a new version of the library as part of the release process.
57
+
52
58
  # License
53
59
 
54
60
  Use is solely in accordance with the signed agreement between your entity and S&P.
@@ -8,7 +8,7 @@ Any questions or suggestions can be sent to the [kFinance Maintainers](kfinance-
8
8
 
9
9
  # Setup
10
10
 
11
- You can install kFinance on [PyPI](https://pypi.org/project/kfinance/) via
11
+ You can install kFinance on [PyPI](https://pypi.org/project/kensho-kfinance/) via
12
12
 
13
13
  `pip install kensho-kfinance`
14
14
 
@@ -18,6 +18,11 @@ To receive access, please email [S&P Global Market Intelligence](market.intellig
18
18
 
19
19
  Once access is obtained, get started using the [Authentication Guide](https://docs.kensho.com/llmreadyapi/kf-authentication) and [Usage Guide](https://docs.kensho.com/llmreadyapi/usage).
20
20
 
21
+ # Versioning
22
+ The kFinance uses semantic versioning (major, minor, patch).
23
+ To bump the version, add a new entry in [CHANGELOG.md](kfinance%2FCHANGELOG.md).
24
+ This will generate a new version of the library as part of the release process.
25
+
21
26
  # License
22
27
 
23
28
  Use is solely in accordance with the signed agreement between your entity and S&P.
@@ -0,0 +1,66 @@
1
+ # Configuration file for the Sphinx documentation builder.
2
+ #
3
+ # For the full list of built-in configuration values, see the documentation:
4
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html
5
+
6
+ # -- Project information -----------------------------------------------------
7
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
8
+ from importlib.metadata import version as get_version
9
+
10
+ project = 'kensho-kfinance'
11
+ copyright = '2025, Kensho Technologies'
12
+ author = 'Kensho Technologies'
13
+
14
+ # borrowed from here:
15
+ # https://setuptools-scm.readthedocs.io/en/latest/usage/#usage-from-sphinx
16
+ release: str = get_version(project)
17
+ # for example take major/minor
18
+ version: str = ".".join(release.split('.')[:2])
19
+
20
+ # -- General configuration ---------------------------------------------------
21
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
22
+
23
+ # borrowed from internal Kensho Sphinx configuration
24
+ extensions = [
25
+ "sphinx.ext.autodoc",
26
+ "sphinx.ext.intersphinx",
27
+ "sphinx.ext.coverage",
28
+ "sphinx.ext.mathjax",
29
+ "sphinx.ext.githubpages",
30
+ "sphinx.ext.autosummary",
31
+ "sphinx.ext.viewcode",
32
+ "sphinx.ext.napoleon",
33
+ # 3rd party extensions
34
+ # m2r2 is to add support to .md files specifically to include README.md files.
35
+ # See this discussion: https://github.com/sphinx-doc/sphinx/issues/7000
36
+ "m2r2",
37
+ # A ReadTheDocs theme for Sphinx
38
+ "sphinx_rtd_theme",
39
+ ]
40
+
41
+ napoleon_google_docstring = True
42
+ napoleon_use_ivar = True
43
+
44
+ autosummary_generate = True
45
+
46
+ # Don't prepend module path prefixes to function definitions. Makes automodule docs less cluttered
47
+ add_module_names = False
48
+
49
+ # Add any paths that contain templates here, relative to this directory.
50
+ templates_path = ["templates"]
51
+
52
+ # The suffix of source filenames.
53
+ source_suffix = [".rst", ".md"]
54
+
55
+
56
+
57
+ # -- Options for HTML output -------------------------------------------------
58
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
59
+
60
+ html_theme = 'sphinx_rtd_theme'
61
+
62
+ # https://sphinx-rtd-theme.readthedocs.io/en/stable/configuring.html
63
+ html_theme_options = {"body_min_width": 0, "body_max_width": "none"}
64
+
65
+ # https://www.sphinx-doc.org/en/1.4.9/config.html#confval-html_sidebars
66
+ html_sidebars = {"**": ["globaltoc.html", "relations.html", "searchbox.html"]}
@@ -0,0 +1,18 @@
1
+ Index
2
+ #####################
3
+
4
+ Documentation page for kensho-kfinance library.
5
+
6
+ .. toctree::
7
+ :hidden:
8
+ :glob:
9
+ :maxdepth: 1
10
+
11
+ kfinance <kfinance>
12
+ llm_tools <llm_tools>
13
+
14
+ Indices and tables
15
+ ==================
16
+
17
+ * :ref:`genindex`
18
+ * :ref:`modindex`
@@ -0,0 +1,7 @@
1
+ kfinance
2
+ ========
3
+
4
+ .. automodule:: kfinance.kfinance
5
+ :members:
6
+ :undoc-members:
7
+ :inherited-members:
@@ -0,0 +1,7 @@
1
+ llm_tools
2
+ =========
3
+
4
+ .. automodule:: kfinance.llm_tools
5
+ :members:
6
+ :undoc-members:
7
+ :inherited-members:
@@ -0,0 +1,4 @@
1
+ sphinx==8.1.3
2
+ m2r2==0.3.3.post2
3
+ sphinx-rtd-theme==3.0.2
4
+ docutils==0.20
@@ -0,0 +1,50 @@
1
+ {% raw %}
2
+ {%- macro automodule(modname, options) -%}
3
+ .. automodule:: {{ modname }}
4
+ {%- for option in options %}
5
+ :{{ option }}:
6
+ {%- endfor %}
7
+ {%- endmacro %}
8
+
9
+ {%- macro toctree(docnames) -%}
10
+ .. toctree::
11
+ :maxdepth: {{ maxdepth }}
12
+ {% for docname in docnames %}
13
+ {{ docname }}
14
+ {%- endfor %}
15
+ {%- endmacro %}
16
+
17
+ {%- if is_namespace %}
18
+ {{- [pkgname, "namespace"] | join(" ") | e | heading }}
19
+ {% else %}
20
+ {{- [pkgname] | join(" ") | e | heading }}
21
+ {% endif %}
22
+
23
+ {%- if modulefirst and not is_namespace %}
24
+ {{ automodule(pkgname, automodule_options) }}
25
+ {% endif %}
26
+
27
+ {%- if subpackages %}
28
+ {{ toctree(subpackages) }}
29
+ {% endif %}
30
+
31
+ {%- if submodules %}
32
+ {% if separatemodules %}
33
+ {{ toctree(submodules) }}
34
+ {% else %}
35
+ {%- for submodule in submodules %}
36
+ {% if show_headings %}
37
+ {{- [submodule] | join(" ") | e | heading(2) }}
38
+ {% endif %}
39
+ {{ automodule(submodule, automodule_options) }}
40
+ {% endfor %}
41
+ {%- endif %}
42
+ {%- endif %}
43
+
44
+ {%- if not modulefirst and not is_namespace %}
45
+ Module contents
46
+ ---------------
47
+
48
+ {{ automodule(pkgname, automodule_options) }}
49
+ {% endif %}
50
+ {% endraw %}
@@ -0,0 +1,10 @@
1
+ {% raw %}
2
+ Index Tree
3
+ ==========
4
+
5
+ .. toctree::
6
+ :maxdepth: {{ maxdepth }}
7
+ {% for docname in docnames %}
8
+ {{ docname }}
9
+ {%- endfor %}
10
+ {% endraw %}
@@ -0,0 +1,37 @@
1
+ set dotenv-load
2
+
3
+ # Just is a command runner. It can be used to provide a shorthand to run
4
+ # complex commands, for example `just lint` for `python -m kensho_lint.lint...`
5
+
6
+ # Here are some installation instructions:
7
+ # https://github.com/casey/just?tab=readme-ov-file#installation
8
+ # Once installed, you can run any of the commands in this file by
9
+ # prepending them with `just`, for example `just lint` to run the linter.
10
+ # Run `just` shows a list of all available commands
11
+
12
+ # If there are commands that you believe can be useful to other contributors,
13
+ # feel free to add them.
14
+
15
+
16
+ default:
17
+ just --list
18
+
19
+ alias l := lint
20
+ # Lint the app directory (both lint and l work). For verbose, use `just lint --verbose`
21
+ lint *args:
22
+ python -m mypy --config-file pyproject.toml kfinance {{args}}
23
+ # The ruff linters (check) and formatters (format) are separate.
24
+ # See https://docs.astral.sh/ruff/formatter/#sorting-imports
25
+ python -m ruff --config pyproject.toml check kfinance --fix {{args}}
26
+ python -m ruff --config pyproject.toml format kfinance {{args}}
27
+
28
+ alias t := unit-test
29
+ # Run unit tests. Use args for optional settings
30
+ unit-test *args:
31
+ python -m pytest {{args}}
32
+
33
+ # Build the sphinx documents locally
34
+ # First, copy the dependencies in docs/requirements.txt into pyproject.toml and install in a venv.
35
+ # Don't merge changes to pyproject and docs/output into the remote repo!
36
+ sphinx *args:
37
+ sphinx-build docs docs/output
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: kensho-kfinance
3
- Version: 1.0.3
3
+ Version: 1.1.0a0
4
4
  Summary: Python CLI for kFinance
5
5
  Author-email: Luke Brown <luke.brown@kensho.com>, Michelle Keoy <michelle.keoy@kensho.com>, Keith Page <keith.page@kensho.com>, Matthew Rosen <matthew.rosen@kensho.com>, Nick Roshdieh <nick.roshdieh@kensho.com>
6
6
  Project-URL: source, https://github.com/kensho-technologies/kfinance
@@ -28,6 +28,7 @@ Requires-Dist: mypy<2,>=1.15.0; extra == "dev"
28
28
  Requires-Dist: pytest<7,>=6.1.2; extra == "dev"
29
29
  Requires-Dist: pytest-cov<7,>=6.0.0; extra == "dev"
30
30
  Requires-Dist: ruff<1,>=0.9.4; extra == "dev"
31
+ Dynamic: license-file
31
32
 
32
33
  # kFinance
33
34
 
@@ -39,7 +40,7 @@ Any questions or suggestions can be sent to the [kFinance Maintainers](kfinance-
39
40
 
40
41
  # Setup
41
42
 
42
- You can install kFinance on [PyPI](https://pypi.org/project/kfinance/) via
43
+ You can install kFinance on [PyPI](https://pypi.org/project/kensho-kfinance/) via
43
44
 
44
45
  `pip install kensho-kfinance`
45
46
 
@@ -49,6 +50,11 @@ To receive access, please email [S&P Global Market Intelligence](market.intellig
49
50
 
50
51
  Once access is obtained, get started using the [Authentication Guide](https://docs.kensho.com/llmreadyapi/kf-authentication) and [Usage Guide](https://docs.kensho.com/llmreadyapi/usage).
51
52
 
53
+ # Versioning
54
+ The kFinance uses semantic versioning (major, minor, patch).
55
+ To bump the version, add a new entry in [CHANGELOG.md](kfinance%2FCHANGELOG.md).
56
+ This will generate a new version of the library as part of the release process.
57
+
52
58
  # License
53
59
 
54
60
  Use is solely in accordance with the signed agreement between your entity and S&P.
@@ -1,18 +1,24 @@
1
1
  .coveragerc
2
2
  .gitignore
3
+ .readthedocs.yaml
3
4
  AUTHORS.md
4
5
  CODE_OF_CONDUCT.md
5
6
  CONTRIBUTING.md
6
7
  LICENSE
7
8
  README.md
9
+ justfile
8
10
  pyproject.toml
9
11
  setup.py
10
12
  .github/workflows/ci-lint.yml
11
13
  .github/workflows/ci-test.yml
12
14
  .github/workflows/python-publish.yml
15
+ docs/conf.py
13
16
  docs/index.rst
14
17
  docs/kfinance.rst
15
18
  docs/llm_tools.rst
19
+ docs/requirements.txt
20
+ docs/templates/apidoc/package.rst_t
21
+ docs/templates/apidoc/toc.rst_t
16
22
  kensho_kfinance.egg-info/PKG-INFO
17
23
  kensho_kfinance.egg-info/SOURCES.txt
18
24
  kensho_kfinance.egg-info/dependency_links.txt
@@ -35,5 +41,4 @@ kfinance/tests/test_fetch.py
35
41
  kfinance/tests/test_objects.py
36
42
  scripts/copyright_line_check.sh
37
43
  scripts/lint.sh
38
- scripts/test.sh
39
- scripts/docs/make_rst.py
44
+ scripts/test.sh
@@ -1,4 +1,7 @@
1
1
  # Changelog
2
+ ## v1.1.0
3
+ - Add market cap, TEV, and shares outstanding
4
+
2
5
  ## v1.0.3
3
6
  - Fix typo for get_history_metadata_from_identifier.
4
7
 
@@ -5,7 +5,14 @@ import jwt
5
5
  import requests
6
6
 
7
7
  from .constants import BusinessRelationshipType, IdentificationTriple
8
- from .version import __version__ as kfinance_version
8
+
9
+
10
+ # version.py gets autogenerated by setuptools-scm and is not available
11
+ # during local development.
12
+ try:
13
+ from .version import __version__ as kfinance_version
14
+ except ImportError:
15
+ kfinance_version = "dev"
9
16
 
10
17
 
11
18
  DEFAULT_API_HOST: str = "https://kfinance.kensho.com"
@@ -175,6 +182,20 @@ class KFinanceApiClient:
175
182
  url = f"{self.url_base}pricing/{trading_item_id}/metadata"
176
183
  return self.fetch(url)
177
184
 
185
+ def fetch_market_caps_tevs_and_shares_outstanding(
186
+ self,
187
+ company_id: int,
188
+ start_date: Optional[str] = None,
189
+ end_date: Optional[str] = None,
190
+ ) -> dict:
191
+ """Get the market cap, TEV, and shares outstanding for a company."""
192
+ url = (
193
+ f"{self.url_base}market_cap/{company_id}/"
194
+ f"{start_date if start_date is not None else 'none'}/"
195
+ f"{end_date if end_date is not None else 'none'}"
196
+ )
197
+ return self.fetch(url)
198
+
178
199
  def fetch_price_chart(
179
200
  self,
180
201
  trading_item_id: int,
@@ -4,7 +4,7 @@ import copy
4
4
  import datetime
5
5
  from enum import Enum
6
6
  from functools import partial
7
- from typing import TYPE_CHECKING, Callable
7
+ from typing import TYPE_CHECKING, Callable, Literal
8
8
 
9
9
  from langchain_core.tools import StructuredTool
10
10
 
@@ -31,23 +31,25 @@ class Model(Enum):
31
31
 
32
32
 
33
33
  def get_latest(use_local_timezone: bool = True) -> LatestPeriods:
34
- """Get the latest annual reporting year, latest quarterly reporting quarter and year, and current date. The output is a dictionary with the following schema::
34
+ """Get the latest annual reporting year, latest quarterly reporting quarter and year, and current date.
35
35
 
36
- {
37
- "annual": {
38
- "latest_year": int
39
- },
40
- "quarterly": {
41
- "latest_quarter": int,
42
- "latest_year": int
43
- },
44
- "now": {
45
- "current_year": int,
46
- "current_quarter": int,
47
- "current_month": int,
48
- "current_date": str # in format Y-m-d
36
+ The output is a dictionary with the following schema::
37
+
38
+ {
39
+ "annual": {
40
+ "latest_year": int
41
+ },
42
+ "quarterly": {
43
+ "latest_quarter": int,
44
+ "latest_year": int
45
+ },
46
+ "now": {
47
+ "current_year": int,
48
+ "current_quarter": int,
49
+ "current_month": int,
50
+ "current_date": str # in format Y-m-d
51
+ }
49
52
  }
50
- }
51
53
 
52
54
  Args:
53
55
  use_local_timezone: whether to use the local timezone of the user
@@ -86,12 +88,14 @@ def get_latest(use_local_timezone: bool = True) -> LatestPeriods:
86
88
 
87
89
 
88
90
  def get_n_quarters_ago(n: int) -> YearAndQuarter:
89
- """Get the year and quarter corresponding to [n] quarters before the current quarter. The output is a dictionary with the following schema::
91
+ """Get the year and quarter corresponding to [n] quarters before the current quarter.
90
92
 
91
- {
92
- "year": int,
93
- "quarter": int
94
- }
93
+ The output is a dictionary with the following schema::
94
+
95
+ {
96
+ "year": int,
97
+ "quarter": int
98
+ }
95
99
 
96
100
  Args:
97
101
  n: number of quarters before the current quarter
@@ -210,6 +214,31 @@ def get_prices_from_identifier(
210
214
  )
211
215
 
212
216
 
217
+ def get_capitalization_from_identifier(
218
+ self: Client,
219
+ identifier: str,
220
+ capitalization: Literal["market_cap", "tev", "shares_outstanding"],
221
+ start_date: str | None = None,
222
+ end_date: str | None = None,
223
+ ) -> str:
224
+ """Get the historical market cap, tev (Total Enterprise Value), or shares outstanding of an identifier, where the identifier can be a ticker, ISIN or CUSIP, between inclusive start_date and inclusive end date.
225
+
226
+ Args:
227
+ identifier: A unique identifier, which can be a ticker symbol, ISIN, or CUSIP.
228
+ capitalization: The capitalization to retrieve (market_cap, tev, or shares_outstanding)
229
+ start_date: The start date for historical price retrieval in format YYYY-MM-DD
230
+ end_date: The end date for historical price retrieval in format YYYY-MM-DD
231
+ """
232
+ ticker = self.ticker(identifier)
233
+ capitalization_to_func: dict[Literal["market_cap", "tev", "shares_outstanding"], Callable] = {
234
+ "market_cap": ticker.market_cap,
235
+ "tev": ticker.tev,
236
+ "shares_outstanding": ticker.shares_outstanding,
237
+ }
238
+ func = capitalization_to_func[capitalization]
239
+ return func(start_date=start_date, end_date=end_date).to_markdown()
240
+
241
+
213
242
  def get_financial_statement_from_identifier(
214
243
  self: Client,
215
244
  identifier: str,
@@ -297,6 +326,7 @@ def _llm_tools(self: Client) -> dict[str, Callable]:
297
326
  ),
298
327
  "get_history_metadata_from_identifier": partial(get_history_metadata_from_identifier, self),
299
328
  "get_prices_from_identifier": partial(get_prices_from_identifier, self),
329
+ "get_capitalization_from_identifier": partial(get_capitalization_from_identifier, self),
300
330
  "get_financial_statement_from_identifier": partial(
301
331
  get_financial_statement_from_identifier, self
302
332
  ),
@@ -323,6 +353,7 @@ def _llm_tool_metadata() -> dict:
323
353
  "get_earnings_call_datetimes_from_identifier": tool_schemas.GetEarningsCallDatetimesFromIdentifier,
324
354
  "get_history_metadata_from_identifier": tool_schemas.GetHistoryMetadataFromIdentifier,
325
355
  "get_prices_from_identifier": tool_schemas.GetPricesFromIdentifier,
356
+ "get_capitalization_from_identifier": tool_schemas.GetCapitalizationFromIdentifier,
326
357
  "get_financial_statement_from_identifier": tool_schemas.GetFinancialStatementFromIdentifier,
327
358
  "get_financial_line_item_from_identifier": tool_schemas.GetFinancialLineItemFromIdentifier,
328
359
  "get_business_relationship_from_identifier": tool_schemas.GetBusinessRelationshipFromIdentifier,
@@ -516,6 +547,34 @@ _base_tool_descriptions = [
516
547
  "additionalProperties": False,
517
548
  },
518
549
  },
550
+ {
551
+ "name": "get_capitalization_from_identifier",
552
+ "description": "Get the historical market cap, tev (Total Enterprise Value), or shares outstanding of an identifier, where the identifier can be a ticker, ISIN or CUSIP, between inclusive start_date and inclusive end date.",
553
+ "input_schema": {
554
+ "type": "object",
555
+ "properties": {
556
+ "identifier": {
557
+ "type": "string",
558
+ "description": "A unique identifier, which can be a ticker symbol, ISIN, or CUSIP.",
559
+ },
560
+ "capitalization": {
561
+ "type": "string",
562
+ "description": "The capitalization to retrieve (market_cap, tev, or shares_outstanding).",
563
+ "enum": ["market_cap", "tev", "shares_outstanding"],
564
+ },
565
+ "start_date": {
566
+ "type": "string",
567
+ "description": "The start date for historical price retrieval in format YYYY-MM-DD",
568
+ },
569
+ "end_date": {
570
+ "type": "string",
571
+ "description": "The end date for historical price retrieval in format YYYY-MM-DD",
572
+ },
573
+ },
574
+ "required": ["identifier", "capitalization"],
575
+ "additionalProperties": False,
576
+ },
577
+ },
519
578
  {
520
579
  "name": "get_financial_statement_from_identifier",
521
580
  "description": "Get the financial statement associated with an identifier",
@@ -1,7 +1,7 @@
1
1
  from datetime import datetime
2
2
  from functools import cache, cached_property
3
3
  import logging
4
- from typing import TYPE_CHECKING, Any, Callable, Optional
4
+ from typing import TYPE_CHECKING, Any, Callable, Literal, Optional
5
5
 
6
6
  import numpy as np
7
7
  import pandas as pd
@@ -18,9 +18,7 @@ logger = logging.getLogger(__name__)
18
18
 
19
19
 
20
20
  class CompanyFunctionsMetaClass:
21
- def __init__(self) -> None:
22
- """Init company functions"""
23
- self.kfinance_api_client: KFinanceApiClient
21
+ kfinance_api_client: KFinanceApiClient
24
22
 
25
23
  @cached_property
26
24
  def company_id(self) -> Any:
@@ -239,6 +237,78 @@ class CompanyFunctionsMetaClass:
239
237
  Companies(self.kfinance_api_client, companies["previous"]),
240
238
  )
241
239
 
240
+ def market_cap(
241
+ self,
242
+ start_date: Optional[str] = None,
243
+ end_date: Optional[str] = None,
244
+ ) -> pd.DataFrame:
245
+ """Retrieves market caps for a company between start and end date.
246
+
247
+ :param start_date: The start date in format "YYYY-MM-DD", default to None
248
+ :type start_date: str, optional
249
+ :param end_date: The end date in format "YYYY-MM-DD", default to None
250
+ :type end_date: str, optional
251
+ :return: A DataFrame with a `market_cap` column. The dates are the index.
252
+ :rtype: pd.DataFrame
253
+ """
254
+
255
+ return self._fetch_market_cap_tev_or_shares_outstanding(
256
+ column_to_extract="market_cap", start_date=start_date, end_date=end_date
257
+ )
258
+
259
+ def tev(
260
+ self,
261
+ start_date: Optional[str] = None,
262
+ end_date: Optional[str] = None,
263
+ ) -> pd.DataFrame:
264
+ """Retrieves TEV (total enterprise value) for a company between start and end date.
265
+
266
+ :param start_date: The start date in format "YYYY-MM-DD", default to None
267
+ :type start_date: str, optional
268
+ :param end_date: The end date in format "YYYY-MM-DD", default to None
269
+ :type end_date: str, optional
270
+ :return: A DataFrame with a `tev` column. The dates are the index.
271
+ :rtype: pd.DataFrame
272
+ """
273
+
274
+ return self._fetch_market_cap_tev_or_shares_outstanding(
275
+ column_to_extract="tev", start_date=start_date, end_date=end_date
276
+ )
277
+
278
+ def shares_outstanding(
279
+ self,
280
+ start_date: Optional[str] = None,
281
+ end_date: Optional[str] = None,
282
+ ) -> pd.DataFrame:
283
+ """Retrieves shares outstanding for a company between start and end date.
284
+
285
+ :param start_date: The start date in format "YYYY-MM-DD", default to None
286
+ :type start_date: str, optional
287
+ :param end_date: The end date in format "YYYY-MM-DD", default to None
288
+ :type end_date: str, optional
289
+ :return: A DataFrame with a `shares_outstanding` column. The dates are the index.
290
+ :rtype: pd.DataFrame
291
+ """
292
+
293
+ return self._fetch_market_cap_tev_or_shares_outstanding(
294
+ column_to_extract="shares_outstanding", start_date=start_date, end_date=end_date
295
+ )
296
+
297
+ def _fetch_market_cap_tev_or_shares_outstanding(
298
+ self,
299
+ column_to_extract: Literal["market_cap", "tev", "shares_outstanding"],
300
+ start_date: str | None,
301
+ end_date: str | None,
302
+ ) -> pd.DataFrame:
303
+ """Helper function to fetch market cap, TEV, and shares outstanding."""
304
+
305
+ df = pd.DataFrame(
306
+ self.kfinance_api_client.fetch_market_caps_tevs_and_shares_outstanding(
307
+ company_id=self.company_id, start_date=start_date, end_date=end_date
308
+ )["market_caps"]
309
+ )
310
+ return df.set_index("date")[[column_to_extract]].apply(pd.to_numeric).replace(np.nan, None)
311
+
242
312
 
243
313
  for line_item in LINE_ITEMS:
244
314
  line_item_name = line_item["name"]