kensho-kfinance 2.4.3__py3-none-any.whl → 2.6.1__py3-none-any.whl
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.
- {kensho_kfinance-2.4.3.dist-info → kensho_kfinance-2.6.1.dist-info}/METADATA +1 -1
- {kensho_kfinance-2.4.3.dist-info → kensho_kfinance-2.6.1.dist-info}/RECORD +23 -20
- kfinance/CHANGELOG.md +12 -0
- kfinance/batch_request_handling.py +2 -16
- kfinance/constants.py +14 -0
- kfinance/fetch.py +56 -0
- kfinance/kfinance.py +403 -90
- kfinance/meta_classes.py +37 -12
- kfinance/tests/conftest.py +4 -0
- kfinance/tests/test_batch_requests.py +0 -32
- kfinance/tests/test_fetch.py +21 -0
- kfinance/tests/test_objects.py +239 -3
- kfinance/tests/test_tools.py +101 -23
- kfinance/tool_calling/__init__.py +2 -4
- kfinance/tool_calling/get_advisors_for_company_in_transaction_from_identifier.py +39 -0
- kfinance/tool_calling/get_competitors_from_identifier.py +24 -0
- kfinance/tool_calling/get_merger_info_from_transaction_id.py +62 -0
- kfinance/tool_calling/get_mergers_from_identifier.py +41 -0
- kfinance/version.py +2 -2
- kfinance/tool_calling/get_earnings_call_datetimes_from_identifier.py +0 -19
- {kensho_kfinance-2.4.3.dist-info → kensho_kfinance-2.6.1.dist-info}/WHEEL +0 -0
- {kensho_kfinance-2.4.3.dist-info → kensho_kfinance-2.6.1.dist-info}/licenses/AUTHORS.md +0 -0
- {kensho_kfinance-2.4.3.dist-info → kensho_kfinance-2.6.1.dist-info}/licenses/LICENSE +0 -0
- {kensho_kfinance-2.4.3.dist-info → kensho_kfinance-2.6.1.dist-info}/top_level.txt +0 -0
|
@@ -4,11 +4,9 @@ from kfinance.tool_calling.get_business_relationship_from_identifier import (
|
|
|
4
4
|
GetBusinessRelationshipFromIdentifier,
|
|
5
5
|
)
|
|
6
6
|
from kfinance.tool_calling.get_capitalization_from_identifier import GetCapitalizationFromIdentifier
|
|
7
|
+
from kfinance.tool_calling.get_competitors_from_identifier import GetCompetitorsFromIdentifier
|
|
7
8
|
from kfinance.tool_calling.get_cusip_from_ticker import GetCusipFromTicker
|
|
8
9
|
from kfinance.tool_calling.get_earnings import GetEarnings
|
|
9
|
-
from kfinance.tool_calling.get_earnings_call_datetimes_from_identifier import (
|
|
10
|
-
GetEarningsCallDatetimesFromIdentifier,
|
|
11
|
-
)
|
|
12
10
|
from kfinance.tool_calling.get_financial_line_item_from_identifier import (
|
|
13
11
|
GetFinancialLineItemFromIdentifier,
|
|
14
12
|
)
|
|
@@ -39,7 +37,6 @@ ALL_TOOLS: list[Type[KfinanceTool]] = [
|
|
|
39
37
|
GetIsinFromTicker,
|
|
40
38
|
GetCusipFromTicker,
|
|
41
39
|
GetInfoFromIdentifier,
|
|
42
|
-
GetEarningsCallDatetimesFromIdentifier,
|
|
43
40
|
GetEarnings,
|
|
44
41
|
GetLatestEarnings,
|
|
45
42
|
GetNextEarnings,
|
|
@@ -52,4 +49,5 @@ ALL_TOOLS: list[Type[KfinanceTool]] = [
|
|
|
52
49
|
GetBusinessRelationshipFromIdentifier,
|
|
53
50
|
ResolveIdentifier,
|
|
54
51
|
GetSegmentsFromIdentifier,
|
|
52
|
+
GetCompetitorsFromIdentifier,
|
|
55
53
|
]
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
from typing import Type
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel, Field
|
|
4
|
+
|
|
5
|
+
from kfinance.constants import Permission
|
|
6
|
+
from kfinance.kfinance import AdvisedCompany
|
|
7
|
+
from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class GetAdvisorsForCompanyInTransactionFromIdentifierArgs(ToolArgsWithIdentifier):
|
|
11
|
+
transaction_id: int | None = Field(description="The ID of the merger.", default=None)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class GetAdvisorsForCompanyInTransactionFromIdentifier(KfinanceTool):
|
|
15
|
+
name: str = "get_advisors_for_company_in_transaction_from_identifier"
|
|
16
|
+
description: str = 'Get the companies advising a company in a given transaction. For example, "Who advised S&P Global during their purchase of Kensho?"'
|
|
17
|
+
args_schema: Type[BaseModel] = GetAdvisorsForCompanyInTransactionFromIdentifierArgs
|
|
18
|
+
required_permission: Permission | None = Permission.MergersPermission
|
|
19
|
+
|
|
20
|
+
def _run(self, identifier: str, transaction_id: int) -> list:
|
|
21
|
+
ticker = self.kfinance_client.ticker(identifier)
|
|
22
|
+
advised_company = AdvisedCompany(
|
|
23
|
+
kfinance_api_client=ticker.kfinance_api_client,
|
|
24
|
+
company_id=ticker.company.company_id,
|
|
25
|
+
transaction_id=transaction_id,
|
|
26
|
+
)
|
|
27
|
+
advisors = advised_company.advisors
|
|
28
|
+
|
|
29
|
+
if advisors:
|
|
30
|
+
return [
|
|
31
|
+
{
|
|
32
|
+
"advisor_company_id": advisor.company_id,
|
|
33
|
+
"advisor_company_name": advisor.name,
|
|
34
|
+
"advisor_type_name": advisor.advisor_type_name,
|
|
35
|
+
}
|
|
36
|
+
for advisor in advisors
|
|
37
|
+
]
|
|
38
|
+
else:
|
|
39
|
+
return []
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
from kfinance.constants import CompetitorSource, Permission
|
|
2
|
+
from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class GetCompetitorsFromIdentifierArgs(ToolArgsWithIdentifier):
|
|
6
|
+
# no description because the description for enum fields comes from the enum docstring.
|
|
7
|
+
competitor_source: CompetitorSource
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class GetCompetitorsFromIdentifier(KfinanceTool):
|
|
11
|
+
name: str = "get_competitors_from_identifier"
|
|
12
|
+
description: str = "Retrieves a list of competitors for a given company, optionally filtered by the source of the competitor information."
|
|
13
|
+
args_schema = GetCompetitorsFromIdentifierArgs
|
|
14
|
+
required_permission: Permission | None = Permission.CompetitorsPermission
|
|
15
|
+
|
|
16
|
+
def _run(
|
|
17
|
+
self,
|
|
18
|
+
identifier: str,
|
|
19
|
+
competitor_source: CompetitorSource,
|
|
20
|
+
) -> dict:
|
|
21
|
+
ticker = self.kfinance_client.ticker(identifier)
|
|
22
|
+
return self.kfinance_client.kfinance_api_client.fetch_competitors(
|
|
23
|
+
company_id=ticker.company_id, competitor_source=competitor_source
|
|
24
|
+
)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
from typing import Type
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel, Field
|
|
4
|
+
|
|
5
|
+
from kfinance.constants import Permission
|
|
6
|
+
from kfinance.kfinance import MergerOrAcquisition
|
|
7
|
+
from kfinance.tool_calling.shared_models import KfinanceTool
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class GetMergerInfoFromTransactionIdArgs(BaseModel):
|
|
11
|
+
transaction_id: int | None = Field(description="The ID of the merger.", default=None)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class GetMergerInfoFromTransactionId(KfinanceTool):
|
|
15
|
+
name: str = "get_merger_info_from_transaction_id"
|
|
16
|
+
description: str = 'Get the timeline, the participants, and the consideration of the merger or acquisition from the given transaction ID. For example, "How much was Ben & Jerrys purchased for?" or "What was the price per share for LinkedIn?" or "When did S&P purchase Kensho?"'
|
|
17
|
+
args_schema: Type[BaseModel] = GetMergerInfoFromTransactionIdArgs
|
|
18
|
+
required_permission: Permission | None = Permission.MergersPermission
|
|
19
|
+
|
|
20
|
+
def _run(self, transaction_id: int) -> dict:
|
|
21
|
+
merger_or_acquisition = MergerOrAcquisition(
|
|
22
|
+
kfinance_api_client=self.kfinance_client.kfinance_api_client,
|
|
23
|
+
transaction_id=transaction_id,
|
|
24
|
+
merger_title=None,
|
|
25
|
+
)
|
|
26
|
+
merger_timeline = merger_or_acquisition.get_timeline
|
|
27
|
+
merger_participants = merger_or_acquisition.get_participants
|
|
28
|
+
merger_consideration = merger_or_acquisition.get_consideration
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
"timeline": [
|
|
32
|
+
{"status": timeline["status"], "date": timeline["date"].strftime("%Y-%m-%d")}
|
|
33
|
+
for timeline in merger_timeline.to_dict(orient="records")
|
|
34
|
+
],
|
|
35
|
+
"participants": {
|
|
36
|
+
"target": {
|
|
37
|
+
"company_id": merger_participants["target"].company_id,
|
|
38
|
+
"company_name": merger_participants["target"].name,
|
|
39
|
+
},
|
|
40
|
+
"buyers": [
|
|
41
|
+
{"company_id": buyer.company_id, "company_name": buyer.name}
|
|
42
|
+
for buyer in merger_participants["buyers"]
|
|
43
|
+
],
|
|
44
|
+
"sellers": [
|
|
45
|
+
{"company_id": seller.company_id, "company_name": seller.name}
|
|
46
|
+
for seller in merger_participants["sellers"]
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
"consideration": {
|
|
50
|
+
"currency_name": merger_consideration["currency_name"],
|
|
51
|
+
"current_calculated_gross_total_transaction_value": merger_consideration[
|
|
52
|
+
"current_calculated_gross_total_transaction_value"
|
|
53
|
+
],
|
|
54
|
+
"current_calculated_implied_equity_value": merger_consideration[
|
|
55
|
+
"current_calculated_implied_equity_value"
|
|
56
|
+
],
|
|
57
|
+
"current_calculated_implied_enterprise_value": merger_consideration[
|
|
58
|
+
"current_calculated_implied_enterprise_value"
|
|
59
|
+
],
|
|
60
|
+
"details": merger_consideration["details"].to_dict(orient="records"),
|
|
61
|
+
},
|
|
62
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
from typing import Type
|
|
2
|
+
|
|
3
|
+
from pydantic import BaseModel
|
|
4
|
+
|
|
5
|
+
from kfinance.constants import Permission
|
|
6
|
+
from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class GetMergersFromIdentifier(KfinanceTool):
|
|
10
|
+
name: str = "get_mergers_from_identifier"
|
|
11
|
+
description: str = 'Get the transaction IDs that involve the given identifier. For example, "Which companies did Microsoft purchase?" or "Which company bought Ben & Jerrys?"'
|
|
12
|
+
args_schema: Type[BaseModel] = ToolArgsWithIdentifier
|
|
13
|
+
required_permission: Permission | None = Permission.MergersPermission
|
|
14
|
+
|
|
15
|
+
def _run(self, identifier: str) -> dict:
|
|
16
|
+
ticker = self.kfinance_client.ticker(identifier)
|
|
17
|
+
mergers_and_acquisitions = ticker.company.mergers_and_acquisitions
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
"target": [
|
|
21
|
+
{
|
|
22
|
+
"transaction_id": merger_or_acquisition.transaction_id,
|
|
23
|
+
"merger_title": merger_or_acquisition.merger_title,
|
|
24
|
+
}
|
|
25
|
+
for merger_or_acquisition in mergers_and_acquisitions["target"]
|
|
26
|
+
],
|
|
27
|
+
"buyer": [
|
|
28
|
+
{
|
|
29
|
+
"transaction_id": merger_or_acquisition.transaction_id,
|
|
30
|
+
"merger_title": merger_or_acquisition.merger_title,
|
|
31
|
+
}
|
|
32
|
+
for merger_or_acquisition in mergers_and_acquisitions["buyer"]
|
|
33
|
+
],
|
|
34
|
+
"seller": [
|
|
35
|
+
{
|
|
36
|
+
"transaction_id": merger_or_acquisition.transaction_id,
|
|
37
|
+
"merger_title": merger_or_acquisition.merger_title,
|
|
38
|
+
}
|
|
39
|
+
for merger_or_acquisition in mergers_and_acquisitions["seller"]
|
|
40
|
+
],
|
|
41
|
+
}
|
kfinance/version.py
CHANGED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import json
|
|
2
|
-
from typing import Type
|
|
3
|
-
|
|
4
|
-
from pydantic import BaseModel
|
|
5
|
-
|
|
6
|
-
from kfinance.constants import Permission
|
|
7
|
-
from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class GetEarningsCallDatetimesFromIdentifier(KfinanceTool):
|
|
11
|
-
name: str = "get_earnings_call_datetimes_from_identifier"
|
|
12
|
-
description: str = "Get earnings call datetimes associated with an identifier."
|
|
13
|
-
args_schema: Type[BaseModel] = ToolArgsWithIdentifier
|
|
14
|
-
required_permission: Permission | None = Permission.EarningsPermission
|
|
15
|
-
|
|
16
|
-
def _run(self, identifier: str) -> str:
|
|
17
|
-
ticker = self.kfinance_client.ticker(identifier)
|
|
18
|
-
earnings_call_datetimes = ticker.earnings_call_datetimes
|
|
19
|
-
return json.dumps([dt.isoformat() for dt in earnings_call_datetimes])
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|