kensho-kfinance 2.7.0__py3-none-any.whl → 2.9.0__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.

Files changed (58) hide show
  1. {kensho_kfinance-2.7.0.dist-info → kensho_kfinance-2.9.0.dist-info}/METADATA +2 -2
  2. kensho_kfinance-2.9.0.dist-info/RECORD +70 -0
  3. kfinance/CHANGELOG.md +6 -0
  4. kfinance/decimal_with_unit.py +78 -0
  5. kfinance/fetch.py +15 -16
  6. kfinance/kfinance.py +108 -122
  7. kfinance/meta_classes.py +28 -27
  8. kfinance/models/business_relationship_models.py +26 -0
  9. kfinance/models/capitalization_models.py +90 -0
  10. kfinance/models/competitor_models.py +13 -0
  11. kfinance/models/currency_models.py +345 -0
  12. kfinance/models/date_and_period_models.py +48 -0
  13. kfinance/models/id_models.py +7 -0
  14. kfinance/models/industry_models.py +12 -0
  15. kfinance/{constants.py → models/line_item_models.py} +1 -165
  16. kfinance/models/permission_models.py +15 -0
  17. kfinance/models/price_models.py +70 -0
  18. kfinance/models/segment_models.py +8 -0
  19. kfinance/models/statement_models.py +9 -0
  20. kfinance/tests/test_batch_requests.py +61 -31
  21. kfinance/tests/test_client.py +1 -1
  22. kfinance/tests/test_decimal_with_unit.py +60 -0
  23. kfinance/tests/test_example_notebook.py +1 -0
  24. kfinance/tests/test_fetch.py +23 -12
  25. kfinance/tests/test_models/__init__.py +0 -0
  26. kfinance/tests/test_models/test_capitalization_models.py +83 -0
  27. kfinance/tests/test_models/test_price_models.py +58 -0
  28. kfinance/tests/test_objects.py +107 -57
  29. kfinance/tests/test_tools.py +35 -11
  30. kfinance/tool_calling/get_advisors_for_company_in_transaction_from_identifier.py +10 -7
  31. kfinance/tool_calling/get_business_relationship_from_identifier.py +2 -1
  32. kfinance/tool_calling/get_capitalization_from_identifier.py +4 -5
  33. kfinance/tool_calling/get_competitors_from_identifier.py +2 -1
  34. kfinance/tool_calling/get_cusip_from_ticker.py +1 -1
  35. kfinance/tool_calling/get_earnings.py +1 -1
  36. kfinance/tool_calling/get_financial_line_item_from_identifier.py +3 -1
  37. kfinance/tool_calling/get_financial_statement_from_identifier.py +3 -1
  38. kfinance/tool_calling/get_history_metadata_from_identifier.py +2 -1
  39. kfinance/tool_calling/get_info_from_identifier.py +1 -1
  40. kfinance/tool_calling/get_isin_from_ticker.py +1 -1
  41. kfinance/tool_calling/get_latest.py +2 -1
  42. kfinance/tool_calling/get_latest_earnings.py +1 -1
  43. kfinance/tool_calling/get_merger_info_from_transaction_id.py +6 -5
  44. kfinance/tool_calling/get_mergers_from_identifier.py +4 -1
  45. kfinance/tool_calling/get_n_quarters_ago.py +2 -1
  46. kfinance/tool_calling/get_next_earnings.py +1 -1
  47. kfinance/tool_calling/get_prices_from_identifier.py +4 -3
  48. kfinance/tool_calling/get_segments_from_identifier.py +3 -1
  49. kfinance/tool_calling/get_transcript.py +1 -1
  50. kfinance/tool_calling/resolve_identifier.py +1 -1
  51. kfinance/tool_calling/shared_models.py +1 -1
  52. kfinance/version.py +2 -2
  53. kensho_kfinance-2.7.0.dist-info/RECORD +0 -54
  54. {kensho_kfinance-2.7.0.dist-info → kensho_kfinance-2.9.0.dist-info}/WHEEL +0 -0
  55. {kensho_kfinance-2.7.0.dist-info → kensho_kfinance-2.9.0.dist-info}/licenses/AUTHORS.md +0 -0
  56. {kensho_kfinance-2.7.0.dist-info → kensho_kfinance-2.9.0.dist-info}/licenses/LICENSE +0 -0
  57. {kensho_kfinance-2.7.0.dist-info → kensho_kfinance-2.9.0.dist-info}/top_level.txt +0 -0
  58. /kfinance/{tests/scratch.py → models/__init__.py} +0 -0
@@ -0,0 +1,58 @@
1
+ from decimal import Decimal
2
+
3
+ from kfinance.decimal_with_unit import Money, Shares
4
+ from kfinance.models.price_models import PriceHistory, Prices
5
+
6
+
7
+ class TestPriceHistory:
8
+ api_resp = {
9
+ "currency": "USD",
10
+ "prices": [
11
+ {
12
+ "date": "2024-06-25",
13
+ "open": "445.790000",
14
+ "high": "449.240000",
15
+ "low": "442.770000",
16
+ "close": "448.780000",
17
+ "volume": "999134",
18
+ },
19
+ {
20
+ "date": "2024-06-26",
21
+ "open": "446.320000",
22
+ "high": "449.120000",
23
+ "low": "443.560000",
24
+ "close": "448.360000",
25
+ "volume": "1630769",
26
+ },
27
+ ],
28
+ }
29
+
30
+ def test_price_history_deserialization(self) -> None:
31
+ """
32
+ GIVEN a price history API response
33
+ WHEN we deserialize the response into a PriceHistory object
34
+ THEN the deserialization succeeds and returns the expected value.
35
+ """
36
+ expected_price_history = PriceHistory.model_construct(
37
+ prices=[
38
+ Prices(
39
+ date="2024-06-25",
40
+ open=Money(value=Decimal("445.79"), unit="USD", conventional_decimals=2),
41
+ high=Money(value=Decimal("449.24"), unit="USD", conventional_decimals=2),
42
+ low=Money(value=Decimal("442.77"), unit="USD", conventional_decimals=2),
43
+ close=Money(value=Decimal("448.78"), unit="USD", conventional_decimals=2),
44
+ volume=Shares(value=Decimal("999134"), unit="Shares", conventional_decimals=0),
45
+ ),
46
+ Prices(
47
+ date="2024-06-26",
48
+ open=Money(value=Decimal("446.32"), unit="USD", conventional_decimals=2),
49
+ high=Money(value=Decimal("449.12"), unit="USD", conventional_decimals=2),
50
+ low=Money(value=Decimal("443.56"), unit="USD", conventional_decimals=2),
51
+ close=Money(value=Decimal("448.36"), unit="USD", conventional_decimals=2),
52
+ volume=Shares(value=Decimal("1630769"), unit="Shares", conventional_decimals=0),
53
+ ),
54
+ ]
55
+ )
56
+
57
+ price_history = PriceHistory.model_validate(self.api_resp)
58
+ assert price_history == expected_price_history
@@ -10,18 +10,19 @@ import pandas as pd
10
10
  from PIL.Image import open as image_open
11
11
  import time_machine
12
12
 
13
- from kfinance.constants import BusinessRelationshipType
14
13
  from kfinance.kfinance import (
15
- AdvisedCompany,
16
14
  BusinessRelationships,
17
15
  Company,
18
16
  Earnings,
19
17
  MergerOrAcquisition,
18
+ ParticipantInMerger,
20
19
  Security,
21
20
  Ticker,
22
21
  TradingItem,
23
22
  Transcript,
24
23
  )
24
+ from kfinance.models.business_relationship_models import BusinessRelationshipType
25
+ from kfinance.models.capitalization_models import Capitalizations
25
26
  from kfinance.pydantic_models import CompanyIdAndName, RelationshipResponse
26
27
 
27
28
 
@@ -124,16 +125,40 @@ MOCK_COMPANY_DB = {
124
125
  },
125
126
  "mergers": {
126
127
  "target": [
127
- {"transaction_id": 10998717, "merger_title": "Closed M/A of Microsoft Corporation"},
128
- {"transaction_id": 28237969, "merger_title": "Closed M/A of Microsoft Corporation"},
128
+ {
129
+ "transaction_id": 10998717,
130
+ "merger_title": "Closed M/A of Microsoft Corporation",
131
+ "closed_date": "2021-01-01",
132
+ },
133
+ {
134
+ "transaction_id": 28237969,
135
+ "merger_title": "Closed M/A of Microsoft Corporation",
136
+ "closed_date": "2022-01-01",
137
+ },
129
138
  ],
130
139
  "buyer": [
131
- {"transaction_id": 517414, "merger_title": "Closed M/A of MongoMusic, Inc."},
132
- {"transaction_id": 596722, "merger_title": "Closed M/A of Digital Anvil, Inc."},
140
+ {
141
+ "transaction_id": 517414,
142
+ "merger_title": "Closed M/A of MongoMusic, Inc.",
143
+ "closed_date": "2023-01-01",
144
+ },
145
+ {
146
+ "transaction_id": 596722,
147
+ "merger_title": "Closed M/A of Digital Anvil, Inc.",
148
+ "closed_date": "2023-01-01",
149
+ },
133
150
  ],
134
151
  "seller": [
135
- {"transaction_id": 455551, "merger_title": "Closed M/A of VacationSpot.com, Inc."},
136
- {"transaction_id": 456045, "merger_title": "Closed M/A of TransPoint, LLC"},
152
+ {
153
+ "transaction_id": 455551,
154
+ "merger_title": "Closed M/A of VacationSpot.com, Inc.",
155
+ "closed_date": "2024-01-01",
156
+ },
157
+ {
158
+ "transaction_id": 456045,
159
+ "merger_title": "Closed M/A of TransPoint, LLC",
160
+ "closed_date": "2025-01-01",
161
+ },
137
162
  ],
138
163
  },
139
164
  "advisors": {
@@ -329,23 +354,26 @@ class MockKFinanceApiClient:
329
354
  company_id: int,
330
355
  start_date: Optional[str] = None,
331
356
  end_date: Optional[str] = None,
332
- ) -> dict:
333
- return {
334
- "market_caps": [
335
- {
336
- "date": "2025-01-01",
337
- "market_cap": "3133802247084.000000",
338
- "tev": "3152211247084.000000",
339
- "shares_outstanding": 7434880776,
340
- },
341
- {
342
- "date": "2025-01-02",
343
- "market_cap": "3112092395218.000000",
344
- "tev": "3130501395218.000000",
345
- "shares_outstanding": 7434880776,
346
- },
347
- ]
348
- }
357
+ ) -> Capitalizations:
358
+ return Capitalizations.model_validate(
359
+ {
360
+ "currency": "USD",
361
+ "market_caps": [
362
+ {
363
+ "date": "2025-01-01",
364
+ "market_cap": "3133802247084.000000",
365
+ "tev": "3152211247084.000000",
366
+ "shares_outstanding": 7434880776,
367
+ },
368
+ {
369
+ "date": "2025-01-02",
370
+ "market_cap": "3112092395218.000000",
371
+ "tev": "3130501395218.000000",
372
+ "shares_outstanding": 7434880776,
373
+ },
374
+ ],
375
+ }
376
+ )
349
377
 
350
378
  def fetch_segments(
351
379
  self,
@@ -376,8 +404,8 @@ class MockKFinanceApiClient:
376
404
  def fetch_mergers_for_company(self, company_id):
377
405
  return copy.deepcopy(MOCK_COMPANY_DB[company_id]["mergers"])
378
406
 
379
- def fetch_merger_info(self, transaction_id):
380
- return copy.deepcopy(MOCK_MERGERS_DB[transaction_id])
407
+ def fetch_merger_info(self, transaction_id: int):
408
+ return copy.deepcopy(MOCK_MERGERS_DB[str(transaction_id)])
381
409
 
382
410
  def fetch_advisors_for_company_in_merger(self, transaction_id, advised_company_id):
383
411
  return copy.deepcopy(MOCK_COMPANY_DB[advised_company_id]["advisors"][transaction_id])
@@ -440,26 +468,31 @@ class TestCompany(TestCase):
440
468
  def setUp(self):
441
469
  """setup tests"""
442
470
  self.kfinance_api_client = MockKFinanceApiClient()
443
- self.msft_company = AdvisedCompany(
444
- self.kfinance_api_client, company_id=msft_company_id, transaction_id=msft_buys_mongo
471
+ self.msft_company = ParticipantInMerger(
472
+ kfinance_api_client=self.kfinance_api_client,
473
+ transaction_id=msft_buys_mongo,
474
+ company=Company(
475
+ kfinance_api_client=self.kfinance_api_client,
476
+ company_id=msft_company_id,
477
+ ),
445
478
  )
446
479
 
447
480
  def test_company_id(self) -> None:
448
481
  """test company id"""
449
482
  expected_company_id = msft_company_id
450
- company_id = self.msft_company.company_id
483
+ company_id = self.msft_company.company.company_id
451
484
  self.assertEqual(expected_company_id, company_id)
452
485
 
453
486
  def test_info(self) -> None:
454
487
  """test info"""
455
488
  expected_info = MOCK_COMPANY_DB[msft_company_id]["info"]
456
- info = self.msft_company.info
489
+ info = self.msft_company.company.info
457
490
  self.assertEqual(expected_info, info)
458
491
 
459
492
  def test_name(self) -> None:
460
493
  """test name"""
461
494
  expected_name = MOCK_COMPANY_DB[msft_company_id]["info"]["name"]
462
- name = self.msft_company.name
495
+ name = self.msft_company.company.name
463
496
  self.assertEqual(expected_name, name)
464
497
 
465
498
  def test_founding_date(self) -> None:
@@ -467,7 +500,7 @@ class TestCompany(TestCase):
467
500
  expected_founding_date = datetime.strptime(
468
501
  MOCK_COMPANY_DB[msft_company_id]["info"]["founding_date"], "%Y-%m-%d"
469
502
  ).date()
470
- founding_date = self.msft_company.founding_date
503
+ founding_date = self.msft_company.company.founding_date
471
504
  self.assertEqual(expected_founding_date, founding_date)
472
505
 
473
506
  def test_earnings_call_datetimes(self) -> None:
@@ -477,7 +510,7 @@ class TestCompany(TestCase):
477
510
  MOCK_COMPANY_DB[msft_company_id]["earnings_call_dates"]["earnings"][0]
478
511
  ).replace(tzinfo=timezone.utc)
479
512
  ]
480
- earnings_call_datetimes = self.msft_company.earnings_call_datetimes
513
+ earnings_call_datetimes = self.msft_company.company.earnings_call_datetimes
481
514
  self.assertEqual(expected_earnings_call_datetimes, earnings_call_datetimes)
482
515
 
483
516
  def test_income_statement(self) -> None:
@@ -489,7 +522,7 @@ class TestCompany(TestCase):
489
522
  .apply(pd.to_numeric)
490
523
  .replace(np.nan, None)
491
524
  )
492
- income_statement = self.msft_company.income_statement()
525
+ income_statement = self.msft_company.company.income_statement()
493
526
  pd.testing.assert_frame_equal(expected_income_statement, income_statement)
494
527
 
495
528
  def test_revenue(self) -> None:
@@ -501,14 +534,14 @@ class TestCompany(TestCase):
501
534
  .replace(np.nan, None)
502
535
  .set_index(pd.Index(["revenue"]))
503
536
  )
504
- revenue = self.msft_company.revenue()
537
+ revenue = self.msft_company.company.revenue()
505
538
  pd.testing.assert_frame_equal(expected_revenue, revenue)
506
539
 
507
540
  def test_business_segments(self) -> None:
508
541
  """test business statement"""
509
542
  expected_segments = MOCK_COMPANY_DB[msft_company_id]["segments"]
510
543
 
511
- business_segment = self.msft_company.business_segments()
544
+ business_segment = self.msft_company.company.business_segments()
512
545
  self.assertEqual(expected_segments, business_segment)
513
546
 
514
547
  def test_relationships(self) -> None:
@@ -519,7 +552,9 @@ class TestCompany(TestCase):
519
552
 
520
553
  expected_suppliers = MOCK_COMPANY_DB[msft_company_id][BusinessRelationshipType.supplier]
521
554
 
522
- suppliers_via_method = self.msft_company.relationships(BusinessRelationshipType.supplier)
555
+ suppliers_via_method = self.msft_company.company.relationships(
556
+ BusinessRelationshipType.supplier
557
+ )
523
558
  self.assertIsInstance(suppliers_via_method, BusinessRelationships)
524
559
  # Company ids should match
525
560
  self.assertEqual(
@@ -532,23 +567,35 @@ class TestCompany(TestCase):
532
567
  )
533
568
 
534
569
  # Fetching via property should return the same result
535
- suppliers_via_property = self.msft_company.supplier
570
+ suppliers_via_property = self.msft_company.company.supplier
536
571
  self.assertEqual(suppliers_via_property, suppliers_via_method)
537
572
 
538
573
  def test_mergers(self) -> None:
539
574
  expected_mergers = MOCK_COMPANY_DB[msft_company_id]["mergers"]
540
- mergers = self.msft_company.mergers_and_acquisitions
575
+ mergers = self.msft_company.company.mergers_and_acquisitions
541
576
  mergers_json = {
542
577
  "target": [
543
- {"transaction_id": merger.transaction_id, "merger_title": merger.merger_title}
578
+ {
579
+ "transaction_id": merger.transaction_id,
580
+ "merger_title": merger.merger_title,
581
+ "closed_date": merger.closed_date,
582
+ }
544
583
  for merger in mergers["target"]
545
584
  ],
546
585
  "buyer": [
547
- {"transaction_id": merger.transaction_id, "merger_title": merger.merger_title}
586
+ {
587
+ "transaction_id": merger.transaction_id,
588
+ "merger_title": merger.merger_title,
589
+ "closed_date": merger.closed_date,
590
+ }
548
591
  for merger in mergers["buyer"]
549
592
  ],
550
593
  "seller": [
551
- {"transaction_id": merger.transaction_id, "merger_title": merger.merger_title}
594
+ {
595
+ "transaction_id": merger.transaction_id,
596
+ "merger_title": merger.merger_title,
597
+ "closed_date": merger.closed_date,
598
+ }
552
599
  for merger in mergers["seller"]
553
600
  ],
554
601
  }
@@ -567,7 +614,7 @@ class TestCompany(TestCase):
567
614
  company_ids: list[int] = []
568
615
  advisor_type_names: list[str] = []
569
616
  for advisor in advisors:
570
- company_ids.append(advisor.company_id)
617
+ company_ids.append(advisor.company.company_id)
571
618
  advisor_type_names.append(advisor.advisor_type_name)
572
619
  self.assertListEqual(expected_company_ids, company_ids)
573
620
  self.assertListEqual(expected_advisor_type_names, advisor_type_names)
@@ -843,12 +890,14 @@ class TestTicker(TestCase):
843
890
  THEN the Ticker object can correctly extract market caps from the dict.
844
891
  """
845
892
 
846
- expected_dataframe = pd.DataFrame(
847
- {"market_cap": {"2025-01-01": 3133802247084.0, "2025-01-02": 3112092395218.0}}
848
- )
849
- expected_dataframe.index.name = "date"
893
+ expected_response = {
894
+ "market_cap": [
895
+ {"2025-01-01": {"unit": "USD", "value": "3133802247084.00"}},
896
+ {"2025-01-02": {"unit": "USD", "value": "3112092395218.00"}},
897
+ ]
898
+ }
850
899
  market_caps = self.msft_ticker_from_ticker.market_cap()
851
- pd.testing.assert_frame_equal(expected_dataframe, market_caps)
900
+ assert market_caps == expected_response
852
901
 
853
902
 
854
903
  class TestTranscript(TestCase):
@@ -964,9 +1013,10 @@ class TestMerger(TestCase):
964
1013
  def setUp(self):
965
1014
  self.kfinance_api_client = MockKFinanceApiClient()
966
1015
  self.merger = MergerOrAcquisition(
967
- self.kfinance_api_client,
968
- transaction_id=msft_buys_mongo,
1016
+ kfinance_api_client=self.kfinance_api_client,
1017
+ transaction_id=int(msft_buys_mongo),
969
1018
  merger_title="Closed M/A of MongoMusic, Inc.",
1019
+ closed_date=date(2021, 1, 1),
970
1020
  )
971
1021
 
972
1022
  def test_merger_info(self) -> None:
@@ -978,16 +1028,16 @@ class TestMerger(TestCase):
978
1028
  ],
979
1029
  "participants": {
980
1030
  "target": {
981
- "company_id": self.merger.get_participants["target"].company_id,
982
- "company_name": self.merger.get_participants["target"].name,
1031
+ "company_id": self.merger.get_participants["target"].company.company_id,
1032
+ "company_name": self.merger.get_participants["target"].company.name,
983
1033
  },
984
1034
  "buyers": [
985
- {"company_id": company.company_id, "company_name": company.name}
986
- for company in self.merger.get_participants["buyers"]
1035
+ {"company_id": buyer.company.company_id, "company_name": buyer.company.name}
1036
+ for buyer in self.merger.get_participants["buyers"]
987
1037
  ],
988
1038
  "sellers": [
989
- {"company_id": company.company_id, "company_name": company.name}
990
- for company in self.merger.get_participants["sellers"]
1039
+ {"company_id": seller.company.company_id, "company_name": seller.company.name}
1040
+ for seller in self.merger.get_participants["sellers"]
991
1041
  ],
992
1042
  },
993
1043
  "consideration": {
@@ -9,14 +9,12 @@ from pytest import raises
9
9
  from requests_mock import Mocker
10
10
  import time_machine
11
11
 
12
- from kfinance.constants import (
13
- BusinessRelationshipType,
14
- Capitalization,
15
- CompetitorSource,
16
- SegmentType,
17
- StatementType,
18
- )
19
12
  from kfinance.kfinance import Client, NoEarningsDataError
13
+ from kfinance.models.business_relationship_models import BusinessRelationshipType
14
+ from kfinance.models.capitalization_models import Capitalization
15
+ from kfinance.models.competitor_models import CompetitorSource
16
+ from kfinance.models.segment_models import SegmentType
17
+ from kfinance.models.statement_models import StatementType
20
18
  from kfinance.tests.conftest import SPGI_COMPANY_ID, SPGI_SECURITY_ID, SPGI_TRADING_ITEM_ID
21
19
  from kfinance.tests.test_objects import MOCK_COMPANY_DB, MOCK_MERGERS_DB, ordered
22
20
  from kfinance.tool_calling import (
@@ -164,6 +162,7 @@ class TestGetCapitalizationFromIdentifier:
164
162
  requests_mock.get(
165
163
  url=f"https://kfinance.kensho.com/api/v1/market_cap/{SPGI_COMPANY_ID}/none/none",
166
164
  json={
165
+ "currency": "USD",
167
166
  "market_caps": [
168
167
  {
169
168
  "date": "2024-04-10",
@@ -177,11 +176,16 @@ class TestGetCapitalizationFromIdentifier:
177
176
  "tev": "147105066761.000000",
178
177
  "shares_outstanding": 313099562,
179
178
  },
180
- ]
179
+ ],
181
180
  },
182
181
  )
183
182
 
184
- expected_response = "| date | market_cap |\n|:-----------|-------------:|\n| 2024-04-10 | 1.32767e+11 |\n| 2024-04-11 | 1.32416e+11 |"
183
+ expected_response = {
184
+ "market_cap": [
185
+ {"2024-04-10": {"unit": "USD", "value": "132766738270.00"}},
186
+ {"2024-04-11": {"unit": "USD", "value": "132416066761.00"}},
187
+ ]
188
+ }
185
189
 
186
190
  tool = GetCapitalizationFromIdentifier(kfinance_client=mock_client)
187
191
  args = GetCapitalizationFromIdentifierArgs(
@@ -442,6 +446,7 @@ class TestPricesFromIdentifier:
442
446
  url=f"https://kfinance.kensho.com/api/v1/pricing/{SPGI_TRADING_ITEM_ID}/none/none/day/adjusted",
443
447
  # truncated response
444
448
  json={
449
+ "currency": "USD",
445
450
  "prices": [
446
451
  {
447
452
  "date": "2024-04-11",
@@ -459,10 +464,29 @@ class TestPricesFromIdentifier:
459
464
  "close": "417.810000",
460
465
  "volume": "1182229",
461
466
  },
462
- ]
467
+ ],
463
468
  },
464
469
  )
465
- expected_response = "| date | open | high | low | close | volume |\n|:-----------|-------:|-------:|-------:|--------:|------------:|\n| 2024-04-11 | 424.26 | 425.99 | 422.04 | 422.92 | 1.12916e+06 |\n| 2024-04-12 | 419.23 | 421.94 | 416.45 | 417.81 | 1.18223e+06 |"
470
+ expected_response = {
471
+ "prices": [
472
+ {
473
+ "date": "2024-04-11",
474
+ "open": {"value": "424.26", "unit": "USD"},
475
+ "high": {"value": "425.99", "unit": "USD"},
476
+ "low": {"value": "422.04", "unit": "USD"},
477
+ "close": {"value": "422.92", "unit": "USD"},
478
+ "volume": {"value": "1129158", "unit": "Shares"},
479
+ },
480
+ {
481
+ "date": "2024-04-12",
482
+ "open": {"value": "419.23", "unit": "USD"},
483
+ "high": {"value": "421.94", "unit": "USD"},
484
+ "low": {"value": "416.45", "unit": "USD"},
485
+ "close": {"value": "417.81", "unit": "USD"},
486
+ "volume": {"value": "1182229", "unit": "Shares"},
487
+ },
488
+ ]
489
+ }
466
490
 
467
491
  tool = GetPricesFromIdentifier(kfinance_client=mock_client)
468
492
  response = tool.run(GetPricesFromIdentifierArgs(identifier="SPGI").model_dump(mode="json"))
@@ -2,8 +2,8 @@ from typing import Type
2
2
 
3
3
  from pydantic import BaseModel, Field
4
4
 
5
- from kfinance.constants import Permission
6
- from kfinance.kfinance import AdvisedCompany
5
+ from kfinance.kfinance import Company, ParticipantInMerger
6
+ from kfinance.models.permission_models import Permission
7
7
  from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
8
8
 
9
9
 
@@ -19,18 +19,21 @@ class GetAdvisorsForCompanyInTransactionFromIdentifier(KfinanceTool):
19
19
 
20
20
  def _run(self, identifier: str, transaction_id: int) -> list:
21
21
  ticker = self.kfinance_client.ticker(identifier)
22
- advised_company = AdvisedCompany(
22
+ participant_in_merger = ParticipantInMerger(
23
23
  kfinance_api_client=ticker.kfinance_api_client,
24
- company_id=ticker.company.company_id,
25
24
  transaction_id=transaction_id,
25
+ company=Company(
26
+ kfinance_api_client=ticker.kfinance_api_client,
27
+ company_id=ticker.company.company_id,
28
+ ),
26
29
  )
27
- advisors = advised_company.advisors
30
+ advisors = participant_in_merger.advisors
28
31
 
29
32
  if advisors:
30
33
  return [
31
34
  {
32
- "advisor_company_id": advisor.company_id,
33
- "advisor_company_name": advisor.name,
35
+ "advisor_company_id": advisor.company.company_id,
36
+ "advisor_company_name": advisor.company.name,
34
37
  "advisor_type_name": advisor.advisor_type_name,
35
38
  }
36
39
  for advisor in advisors
@@ -2,8 +2,9 @@ from typing import Type
2
2
 
3
3
  from pydantic import BaseModel
4
4
 
5
- from kfinance.constants import BusinessRelationshipType, Permission
6
5
  from kfinance.kfinance import BusinessRelationships
6
+ from kfinance.models.business_relationship_models import BusinessRelationshipType
7
+ from kfinance.models.permission_models import Permission
7
8
  from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
8
9
 
9
10
 
@@ -2,7 +2,8 @@ from datetime import date
2
2
 
3
3
  from pydantic import Field
4
4
 
5
- from kfinance.constants import Capitalization, Permission
5
+ from kfinance.models.capitalization_models import Capitalization
6
+ from kfinance.models.permission_models import Permission
6
7
  from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
7
8
 
8
9
 
@@ -29,8 +30,6 @@ class GetCapitalizationFromIdentifier(KfinanceTool):
29
30
  capitalization: Capitalization,
30
31
  start_date: str | None = None,
31
32
  end_date: str | None = None,
32
- ) -> str:
33
+ ) -> dict:
33
34
  ticker = self.kfinance_client.ticker(identifier)
34
- return getattr(ticker, capitalization.value)(
35
- start_date=start_date, end_date=end_date
36
- ).to_markdown()
35
+ return getattr(ticker, capitalization.value)(start_date=start_date, end_date=end_date)
@@ -1,4 +1,5 @@
1
- from kfinance.constants import CompetitorSource, Permission
1
+ from kfinance.models.competitor_models import CompetitorSource
2
+ from kfinance.models.permission_models import Permission
2
3
  from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
3
4
 
4
5
 
@@ -2,7 +2,7 @@ from typing import Type
2
2
 
3
3
  from pydantic import BaseModel, Field
4
4
 
5
- from kfinance.constants import Permission
5
+ from kfinance.models.permission_models import Permission
6
6
  from kfinance.tool_calling.shared_models import KfinanceTool
7
7
 
8
8
 
@@ -2,8 +2,8 @@ from typing import Type
2
2
 
3
3
  from pydantic import BaseModel
4
4
 
5
- from kfinance.constants import Permission
6
5
  from kfinance.kfinance import NoEarningsDataError
6
+ from kfinance.models.permission_models import Permission
7
7
  from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
8
8
 
9
9
 
@@ -2,7 +2,9 @@ from typing import Literal, Type
2
2
 
3
3
  from pydantic import BaseModel, Field
4
4
 
5
- from kfinance.constants import LINE_ITEM_NAMES_AND_ALIASES, PeriodType, Permission
5
+ from kfinance.models.date_and_period_models import PeriodType
6
+ from kfinance.models.line_item_models import LINE_ITEM_NAMES_AND_ALIASES
7
+ from kfinance.models.permission_models import Permission
6
8
  from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier, ValidQuarter
7
9
 
8
10
 
@@ -2,7 +2,9 @@ from typing import Literal, Type
2
2
 
3
3
  from pydantic import BaseModel, Field
4
4
 
5
- from kfinance.constants import PeriodType, Permission, StatementType
5
+ from kfinance.models.date_and_period_models import PeriodType
6
+ from kfinance.models.permission_models import Permission
7
+ from kfinance.models.statement_models import StatementType
6
8
  from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier, ValidQuarter
7
9
 
8
10
 
@@ -2,7 +2,8 @@ from typing import Type
2
2
 
3
3
  from pydantic import BaseModel
4
4
 
5
- from kfinance.constants import HistoryMetadata, Permission
5
+ from kfinance.models.permission_models import Permission
6
+ from kfinance.models.price_models import HistoryMetadata
6
7
  from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
7
8
 
8
9
 
@@ -2,7 +2,7 @@ from typing import Type
2
2
 
3
3
  from pydantic import BaseModel
4
4
 
5
- from kfinance.constants import Permission
5
+ from kfinance.models.permission_models import Permission
6
6
  from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
7
7
 
8
8
 
@@ -2,7 +2,7 @@ from typing import Type
2
2
 
3
3
  from pydantic import BaseModel, Field
4
4
 
5
- from kfinance.constants import Permission
5
+ from kfinance.models.permission_models import Permission
6
6
  from kfinance.tool_calling.shared_models import KfinanceTool
7
7
 
8
8
 
@@ -2,7 +2,8 @@ from typing import Type
2
2
 
3
3
  from pydantic import BaseModel, Field
4
4
 
5
- from kfinance.constants import LatestPeriods, Permission
5
+ from kfinance.models.date_and_period_models import LatestPeriods
6
+ from kfinance.models.permission_models import Permission
6
7
  from kfinance.tool_calling.shared_models import KfinanceTool
7
8
 
8
9
 
@@ -2,8 +2,8 @@ from typing import Type
2
2
 
3
3
  from pydantic import BaseModel
4
4
 
5
- from kfinance.constants import Permission
6
5
  from kfinance.kfinance import NoEarningsDataError
6
+ from kfinance.models.permission_models import Permission
7
7
  from kfinance.tool_calling.shared_models import KfinanceTool, ToolArgsWithIdentifier
8
8
 
9
9