kensho-kfinance 2.8.0__py3-none-any.whl → 3.0.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.
- {kensho_kfinance-2.8.0.dist-info → kensho_kfinance-3.0.0.dist-info}/METADATA +2 -2
- kensho_kfinance-3.0.0.dist-info/RECORD +110 -0
- kfinance/CHANGELOG.md +6 -0
- kfinance/__init__.py +1 -0
- kfinance/client/README.md +9 -0
- kfinance/{batch_request_handling.py → client/batch_request_handling.py} +63 -27
- kfinance/{fetch.py → client/fetch.py} +23 -29
- kfinance/{kfinance.py → client/kfinance.py} +105 -111
- kfinance/{meta_classes.py → client/meta_classes.py} +26 -35
- kfinance/{decimal_with_unit.py → client/models/decimal_with_unit.py} +1 -1
- kfinance/{tests → client/models/tests}/test_decimal_with_unit.py +1 -1
- kfinance/client/tests/__init__.py +0 -0
- kfinance/{tests → client/tests}/test_batch_requests.py +8 -6
- kfinance/{tests → client/tests}/test_client.py +25 -19
- kfinance/{tests → client/tests}/test_fetch.py +11 -29
- kfinance/{tests → client/tests}/test_group_objects.py +1 -1
- kfinance/{tests → client/tests}/test_objects.py +111 -63
- kfinance/{tests/conftest.py → conftest.py} +14 -2
- kfinance/domains/README.md +14 -0
- kfinance/domains/__init__.py +0 -0
- kfinance/domains/business_relationships/__init__.py +0 -0
- kfinance/{models → domains/business_relationships}/business_relationship_models.py +10 -0
- kfinance/domains/business_relationships/business_relationship_tools.py +74 -0
- kfinance/domains/business_relationships/tests/__init__.py +0 -0
- kfinance/domains/business_relationships/tests/test_business_relationship_tools.py +55 -0
- kfinance/domains/capitalizations/__init__.py +0 -0
- kfinance/{models → domains/capitalizations}/capitalization_models.py +24 -17
- kfinance/domains/capitalizations/capitalization_tools.py +89 -0
- kfinance/domains/capitalizations/tests/__init__.py +0 -0
- kfinance/{tests/test_models → domains/capitalizations/tests}/test_capitalization_models.py +8 -10
- kfinance/domains/capitalizations/tests/test_capitalization_tools.py +85 -0
- kfinance/domains/companies/__init__.py +0 -0
- kfinance/domains/companies/company_identifiers.py +175 -0
- kfinance/domains/companies/company_models.py +27 -0
- kfinance/domains/companies/company_tools.py +66 -0
- kfinance/domains/companies/tests/__init__.py +0 -0
- kfinance/domains/companies/tests/test_company_tools.py +26 -0
- kfinance/domains/competitors/__init__.py +0 -0
- kfinance/{models → domains/competitors}/competitor_models.py +7 -0
- kfinance/domains/competitors/competitor_tools.py +62 -0
- kfinance/domains/competitors/tests/__init__.py +0 -0
- kfinance/domains/competitors/tests/test_competitor_tools.py +45 -0
- kfinance/domains/cusip_and_isin/__init__.py +0 -0
- kfinance/domains/cusip_and_isin/cusip_and_isin_tools.py +80 -0
- kfinance/domains/cusip_and_isin/tests/__init__.py +0 -0
- kfinance/domains/cusip_and_isin/tests/test_cusip_and_isin_tools.py +57 -0
- kfinance/domains/earnings/__init__.py +0 -0
- kfinance/domains/earnings/earning_models.py +41 -0
- kfinance/domains/earnings/earning_tools.py +174 -0
- kfinance/domains/earnings/tests/__init__.py +0 -0
- kfinance/domains/earnings/tests/test_earnings_tools.py +195 -0
- kfinance/domains/line_items/__init__.py +0 -0
- kfinance/domains/line_items/line_item_tools.py +114 -0
- kfinance/domains/line_items/tests/__init__.py +0 -0
- kfinance/domains/line_items/tests/test_line_item_tools.py +86 -0
- kfinance/domains/mergers_and_acquisitions/__init__.py +0 -0
- kfinance/domains/mergers_and_acquisitions/merger_and_acquisition_tools.py +176 -0
- kfinance/domains/mergers_and_acquisitions/tests/__init__.py +0 -0
- kfinance/domains/mergers_and_acquisitions/tests/test_merger_and_acquisition_tools.py +124 -0
- kfinance/domains/prices/__init__.py +0 -0
- kfinance/{models → domains/prices}/price_models.py +1 -1
- kfinance/domains/prices/price_tools.py +165 -0
- kfinance/domains/prices/tests/__init__.py +0 -0
- kfinance/{tests/test_models → domains/prices/tests}/test_price_models.py +2 -2
- kfinance/domains/prices/tests/test_price_tools.py +141 -0
- kfinance/domains/segments/__init__.py +0 -0
- kfinance/domains/segments/segment_tools.py +91 -0
- kfinance/domains/segments/tests/__init__.py +0 -0
- kfinance/domains/segments/tests/test_segment_tools.py +80 -0
- kfinance/domains/statements/__init__.py +0 -0
- kfinance/domains/statements/statement_tools.py +113 -0
- kfinance/domains/statements/tests/__init__.py +0 -0
- kfinance/domains/statements/tests/test_statement_tools.py +73 -0
- kfinance/integrations/README.md +8 -0
- kfinance/integrations/__init__.py +0 -0
- kfinance/integrations/mcp/__init__.py +0 -0
- kfinance/{mcp.py → integrations/mcp/mcp.py} +2 -2
- kfinance/integrations/tests/__init__.py +0 -0
- kfinance/{tests → integrations/tests}/test_example_notebook.py +4 -4
- kfinance/{tool_calling → integrations/tool_calling}/README.md +2 -2
- kfinance/integrations/tool_calling/__init__.py +0 -0
- kfinance/integrations/tool_calling/all_tools.py +55 -0
- kfinance/{tool_calling → integrations/tool_calling}/prompts.py +3 -2
- kfinance/integrations/tool_calling/static_tools/README.md +4 -0
- kfinance/integrations/tool_calling/static_tools/__init__.py +0 -0
- kfinance/{tool_calling → integrations/tool_calling/static_tools}/get_latest.py +3 -3
- kfinance/{tool_calling → integrations/tool_calling/static_tools}/get_n_quarters_ago.py +3 -3
- kfinance/integrations/tool_calling/static_tools/tests/__init__.py +0 -0
- kfinance/integrations/tool_calling/static_tools/tests/test_get_lastest.py +30 -0
- kfinance/integrations/tool_calling/static_tools/tests/test_get_n_quarters_ago.py +24 -0
- kfinance/integrations/tool_calling/tests/__init__.py +0 -0
- kfinance/integrations/tool_calling/tests/test_tool_calling_models.py +69 -0
- kfinance/{tool_calling/shared_models.py → integrations/tool_calling/tool_calling_models.py} +37 -7
- kfinance/version.py +2 -2
- kensho_kfinance-2.8.0.dist-info/RECORD +0 -70
- kfinance/models/id_models.py +0 -7
- kfinance/prompt.py +0 -526
- kfinance/pydantic_models.py +0 -33
- kfinance/tests/test_tools.py +0 -804
- kfinance/tool_calling/__init__.py +0 -53
- kfinance/tool_calling/get_advisors_for_company_in_transaction_from_identifier.py +0 -39
- kfinance/tool_calling/get_business_relationship_from_identifier.py +0 -30
- kfinance/tool_calling/get_capitalization_from_identifier.py +0 -35
- kfinance/tool_calling/get_competitors_from_identifier.py +0 -25
- kfinance/tool_calling/get_cusip_from_ticker.py +0 -20
- kfinance/tool_calling/get_earnings.py +0 -33
- kfinance/tool_calling/get_financial_line_item_from_identifier.py +0 -48
- kfinance/tool_calling/get_financial_statement_from_identifier.py +0 -44
- kfinance/tool_calling/get_history_metadata_from_identifier.py +0 -17
- kfinance/tool_calling/get_info_from_identifier.py +0 -16
- kfinance/tool_calling/get_isin_from_ticker.py +0 -20
- kfinance/tool_calling/get_latest_earnings.py +0 -30
- kfinance/tool_calling/get_merger_info_from_transaction_id.py +0 -68
- kfinance/tool_calling/get_mergers_from_identifier.py +0 -41
- kfinance/tool_calling/get_next_earnings.py +0 -30
- kfinance/tool_calling/get_prices_from_identifier.py +0 -46
- kfinance/tool_calling/get_segments_from_identifier.py +0 -44
- kfinance/tool_calling/get_transcript.py +0 -23
- kfinance/tool_calling/resolve_identifier.py +0 -18
- {kensho_kfinance-2.8.0.dist-info → kensho_kfinance-3.0.0.dist-info}/WHEEL +0 -0
- {kensho_kfinance-2.8.0.dist-info → kensho_kfinance-3.0.0.dist-info}/licenses/AUTHORS.md +0 -0
- {kensho_kfinance-2.8.0.dist-info → kensho_kfinance-3.0.0.dist-info}/licenses/LICENSE +0 -0
- {kensho_kfinance-2.8.0.dist-info → kensho_kfinance-3.0.0.dist-info}/top_level.txt +0 -0
- /kfinance/{models → client}/__init__.py +0 -0
- /kfinance/{models → client}/industry_models.py +0 -0
- /kfinance/{tests → client/models}/__init__.py +0 -0
- /kfinance/{models → client/models}/currency_models.py +0 -0
- /kfinance/{models → client/models}/date_and_period_models.py +0 -0
- /kfinance/{tests/test_models → client/models/tests}/__init__.py +0 -0
- /kfinance/{models → client}/permission_models.py +0 -0
- /kfinance/{server_thread.py → client/server_thread.py} +0 -0
- /kfinance/{models → domains/line_items}/line_item_models.py +0 -0
- /kfinance/{models → domains/segments}/segment_models.py +0 -0
- /kfinance/{models → domains/statements}/statement_models.py +0 -0
kfinance/prompt.py
DELETED
|
@@ -1,526 +0,0 @@
|
|
|
1
|
-
from datetime import datetime
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
PROMPT = """
|
|
5
|
-
Think carefully before answering.
|
|
6
|
-
|
|
7
|
-
RULES:
|
|
8
|
-
- Always initialize the Ticker object first, e.g. amazon = client.ticker("AMZN"), e.g. microsoft = client.ticker("MSFT")
|
|
9
|
-
- The client will always be initialized.
|
|
10
|
-
- When provided with a common nickname for a company, identify the company and use its stock ticker.
|
|
11
|
-
- Only use the functions given.
|
|
12
|
-
- Follow the documentation carefully.
|
|
13
|
-
- If a time range is not specified, do not index into the dataframe and provide all the rows and columns as they are.
|
|
14
|
-
- If a temporal question is asked, make sure to include the latest date that you've got information for. Its ok to reference the past.
|
|
15
|
-
- If the question asks for quarterly updates, include the current year (XXXX).
|
|
16
|
-
- Only output executable code with no comments.
|
|
17
|
-
- Only output the code without any code block formatting (no ```python).
|
|
18
|
-
- Do not index into balance_sheet, cashflow or income_statement and only use the functions provided.
|
|
19
|
-
- Include import statements if needed in generated code, e.g. import datetime, or import pandas as pd.
|
|
20
|
-
- Make sure that a metric is not provided in the function list before performing calculations.
|
|
21
|
-
- If a question asks for a specific metric that is not provided in the function list, please calculate it with mathematical operations by utilizing the provided functions.
|
|
22
|
-
- For calculations where each operand is a single year or quarter, make sure to index into the dataframe of each operand using .iloc, e.g. .iloc[0, -1] for the most recent item.
|
|
23
|
-
- For ltm or ytd calculations, make sure to use .reset_index(drop=True).
|
|
24
|
-
- Use dateutil.relativedelta instead of datetime.timedelta.
|
|
25
|
-
- If the latest quarter is needed, use client.get_latest.
|
|
26
|
-
- If the question asks for lowest or highest prices, use ['low'] or ['high'] to index into the dataframe.
|
|
27
|
-
Use only the following functions to answer finance questions in concise, correct Python code.
|
|
28
|
-
|
|
29
|
-
FUNCTIONS:
|
|
30
|
-
def get_latest(self) -> dict:
|
|
31
|
-
\"""
|
|
32
|
-
Get the latest quarter and year. The output is a dictionary with the following schema:
|
|
33
|
-
{
|
|
34
|
-
"quarterly": {
|
|
35
|
-
"latest_quarter": int,
|
|
36
|
-
"latest_year": int
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
Examples:
|
|
40
|
-
Question:
|
|
41
|
-
What was SPGI's total revenue in the last quarter?
|
|
42
|
-
Answer:
|
|
43
|
-
spgi = client.ticker("SPGI")
|
|
44
|
-
latest_periods = client.get_latest()
|
|
45
|
-
latest_year = latest_periods["quarterly"]["latest_year"]
|
|
46
|
-
latest_quarter = latest_periods["quarterly"]["latest_quarter"]
|
|
47
|
-
spgi_latest_quarter_revenue = spgi.total_revenue(start_year=latest_year, start_quarter=latest_quarter, end_year=latest_year, end_quarter=latest_quarter)
|
|
48
|
-
spgi_latest_quarter_revenue
|
|
49
|
-
\"""
|
|
50
|
-
def get_n_quarters_ago(self, n: int) -> dict:
|
|
51
|
-
\"""
|
|
52
|
-
Get the year and quarter corresponding to [n] quarters before the current quarter. The output is a dictionary with the following schema:
|
|
53
|
-
{
|
|
54
|
-
"year": int,
|
|
55
|
-
"quarter": int
|
|
56
|
-
}
|
|
57
|
-
Examples:
|
|
58
|
-
Question:
|
|
59
|
-
What is Microsoft's total revenue in the last 10 quarters?
|
|
60
|
-
Answer:
|
|
61
|
-
microsoft = client.ticker("MSFT")
|
|
62
|
-
latest_periods = client.get_latest()
|
|
63
|
-
latest_year = latest_periods["quarterly"]["latest_year"]
|
|
64
|
-
latest_quarter = latest_periods["quarterly"]["latest_quarter"]
|
|
65
|
-
last_10_quarters = client.get_n_quarters_ago(10)
|
|
66
|
-
total_revenue = microsoft.total_revenue(period_type="quarterly", start_year=last_10_quarters["year"], start_quarter=last_10_quarters["quarter"], end_year=latest_year, end_quarter=latest_quarter)
|
|
67
|
-
total_revenue
|
|
68
|
-
\"""
|
|
69
|
-
def ticker(self, identifier: str, exchange_code: Optional[str] = None) -> Ticker:
|
|
70
|
-
\"""
|
|
71
|
-
Returns the Ticker object
|
|
72
|
-
Param identifier (str): Provide either the ticker (the unique ticker symbol, the company's primary security ticker), the ISIN, or the CUSIP that can be used as an identifier for the ticker object.
|
|
73
|
-
Param exchange_code (str): Provide the stock exchange code.
|
|
74
|
-
For example, call the method with a ticker symbol, ISIN, or CUSIN with its respective company name:
|
|
75
|
-
amazon = client.ticker("AMZN")
|
|
76
|
-
Question:
|
|
77
|
-
What is Medibank Private Limited income statement?
|
|
78
|
-
Answer:
|
|
79
|
-
medibank = client.ticker("MPL", "ASX")
|
|
80
|
-
medibank.income_statement()
|
|
81
|
-
|
|
82
|
-
Question:
|
|
83
|
-
What is Tata Consultancy balance sheet?
|
|
84
|
-
Answer:
|
|
85
|
-
tata = client.ticker("TCS", "NSEI")
|
|
86
|
-
tata.balance_sheet()
|
|
87
|
-
|
|
88
|
-
Question:
|
|
89
|
-
What is Honda's cash flow statement?
|
|
90
|
-
Answer:
|
|
91
|
-
honda = client.ticker("7267")
|
|
92
|
-
honda.cashflow()
|
|
93
|
-
|
|
94
|
-
Question:
|
|
95
|
-
What was the EBITDA for CUSIP 550021109 in Q2 2023?
|
|
96
|
-
# Use CUSIP as ticker identifier
|
|
97
|
-
company1_ticker = client.ticker("550021109")
|
|
98
|
-
company1_ebitda = company1_ticker.net_income(start_year=2023, start_quarter=2, end_year=2023, end_quarter=2)
|
|
99
|
-
company1_ebitda
|
|
100
|
-
|
|
101
|
-
Question:
|
|
102
|
-
ISIN US45166V2051 net income 2023?
|
|
103
|
-
# Use ISIN as ticker identifier
|
|
104
|
-
company1_ticker = client.ticker("US45166V2051")
|
|
105
|
-
company1_net_income = company1_ticker.net_income(start_year=2023)
|
|
106
|
-
company1_net_income
|
|
107
|
-
\"""
|
|
108
|
-
class Ticker:
|
|
109
|
-
\"""
|
|
110
|
-
Attributes:
|
|
111
|
-
history_metadata (dict): A dictionary describing meta information about ticker history with the following keys:
|
|
112
|
-
- currency (str): The currency in which the ticker is traded.
|
|
113
|
-
- symbol (str): The symbol representing the ticker.
|
|
114
|
-
- exchange_name (str): The name of the exchange where the ticker is traded.
|
|
115
|
-
- instrument_type (str): The type of financial instrument.
|
|
116
|
-
- first_trade_date (datetime.date): The date when the ticker was first traded.
|
|
117
|
-
earnings_call_datetimes (list): A list of datetime objects representing company future and historical earnings dates with timezone information.
|
|
118
|
-
isin (str): Company ISIN
|
|
119
|
-
company_id (int)
|
|
120
|
-
security_id (int)
|
|
121
|
-
cusip (str)
|
|
122
|
-
trading_item_id (int): Trading item ID
|
|
123
|
-
name (str): The name of the company.
|
|
124
|
-
status (str): The operational status of the company.
|
|
125
|
-
type (str): The type of the company.
|
|
126
|
-
simple_industry (str): The industry in which the company operates.
|
|
127
|
-
number_of_employees (Decimal)
|
|
128
|
-
founding_date (datetime.date)
|
|
129
|
-
webpage (str)
|
|
130
|
-
address (str): The street address of the company.
|
|
131
|
-
city (str)
|
|
132
|
-
zip_code (str)
|
|
133
|
-
state (str)
|
|
134
|
-
country (str)
|
|
135
|
-
iso_country (str)
|
|
136
|
-
info (dict): A dictionary with the following keys:
|
|
137
|
-
- name (str): The name of the company.
|
|
138
|
-
- status (str): The operational status of the company.
|
|
139
|
-
- type (str): The type of the company.
|
|
140
|
-
- simple_industry (str): The industry in which the company operates.
|
|
141
|
-
- number_of_employees (Decimal)
|
|
142
|
-
- founding_date (datetime.date)
|
|
143
|
-
- webpage (str)
|
|
144
|
-
- address (str): The street address of the company.
|
|
145
|
-
- city (str)
|
|
146
|
-
- zip_code (str)
|
|
147
|
-
- state (str)
|
|
148
|
-
- country (str)
|
|
149
|
-
- iso_country (str)
|
|
150
|
-
\"""
|
|
151
|
-
Functions:
|
|
152
|
-
The following functions share the same signature, parameters and return shape.
|
|
153
|
-
|
|
154
|
-
Here is the general signature of the functions:
|
|
155
|
-
def function_name(period_type: Optional[str] = None, start_year: Optional[int] = None, end_year: Optional[int] = None, start_quarter: Optional[int] = None, end_quarter: Optional[int] = None) -> pd.DataFrame:
|
|
156
|
-
\"""
|
|
157
|
-
Parameters:
|
|
158
|
-
period_type: Optional[str], default to None
|
|
159
|
-
The period type of the data requested.
|
|
160
|
-
Options:
|
|
161
|
-
"annual": For annual data set to "annual"
|
|
162
|
-
"quarterly": For quarterly data set to "quarterly"
|
|
163
|
-
"ytd": For year to date data also known as ytd, set to "ytd"
|
|
164
|
-
"ltm": For last twelve months data also known as LTM, set to "ltm"
|
|
165
|
-
If any other values are passed in, the function will error.
|
|
166
|
-
start_year (Optional[int]): The starting year for the data range.
|
|
167
|
-
end_year (Optional[int]): The ending year for the data range. If the question is about "the last x years" or the "latest", and end_year is not provided, put end_year as the current year - 1. Otherwise, put the end_year as the current year.
|
|
168
|
-
start_quarter (Optional[int]): The starting quarter (1-4) within the starting year.
|
|
169
|
-
end_quarter (Optional[int]): The ending quarter (1-4) within the ending year.
|
|
170
|
-
|
|
171
|
-
Function Names:
|
|
172
|
-
- balance_sheet()
|
|
173
|
-
- income_statement()
|
|
174
|
-
- cash_flow()
|
|
175
|
-
- revenue()
|
|
176
|
-
- finance_division_revenue()
|
|
177
|
-
- insurance_division_revenue()
|
|
178
|
-
- revenue_from_sale_of_assets()
|
|
179
|
-
- revenue_from_sale_of_investments()
|
|
180
|
-
- revenue_from_interest_and_investment_income()
|
|
181
|
-
- other_revenue()
|
|
182
|
-
- total_other_revenue()
|
|
183
|
-
- fees_and_other_income()
|
|
184
|
-
- total_revenue()
|
|
185
|
-
- cost_of_goods_sold()
|
|
186
|
-
- finance_division_operating_expense()
|
|
187
|
-
- insurance_division_operating_expense()
|
|
188
|
-
- finance_division_interest_expense()
|
|
189
|
-
- cost_of_revenue()
|
|
190
|
-
- gross_profit()
|
|
191
|
-
- selling_general_and_admin_expense()
|
|
192
|
-
- exploration_and_drilling_costs()
|
|
193
|
-
- provision_for_bad_debts()
|
|
194
|
-
- pre_opening_costs()
|
|
195
|
-
- total_selling_general_and_admin_expense()
|
|
196
|
-
- research_and_development_expense()
|
|
197
|
-
- depreciation_and_amortization()
|
|
198
|
-
- amortization_of_goodwill_and_intangibles()
|
|
199
|
-
- impairment_of_oil_gas_and_mineral_properties()
|
|
200
|
-
- total_depreciation_and_amortization()
|
|
201
|
-
- other_operating_expense()
|
|
202
|
-
- total_other_operating_expense()
|
|
203
|
-
- total_operating_expense()
|
|
204
|
-
- operating_income()
|
|
205
|
-
- interest_expense()
|
|
206
|
-
- interest_and_investment_income()
|
|
207
|
-
- net_interest_expense()
|
|
208
|
-
- income_from_affiliates()
|
|
209
|
-
- currency_exchange_gains()
|
|
210
|
-
- other_non_operating_income()
|
|
211
|
-
- total_other_non_operating_income()
|
|
212
|
-
- ebt_excluding_unusual_items()
|
|
213
|
-
- restructuring_charges()
|
|
214
|
-
- merger_charges()
|
|
215
|
-
- merger_and_restructuring_charges()
|
|
216
|
-
- impairment_of_goodwill()
|
|
217
|
-
- gain_from_sale_of_assets()
|
|
218
|
-
- gain_from_sale_of_investments()
|
|
219
|
-
- asset_writedown()
|
|
220
|
-
- in_process_research_and_development_expense()
|
|
221
|
-
- insurance_settlements()
|
|
222
|
-
- legal_settlements()
|
|
223
|
-
- other_unusual_items()
|
|
224
|
-
- total_other_unusual_items()
|
|
225
|
-
- total_unusual_items()
|
|
226
|
-
- ebt_including_unusual_items()
|
|
227
|
-
- income_tax_expense()
|
|
228
|
-
- earnings_from_continued_operations()
|
|
229
|
-
- earnings_from_discontinued_operations()
|
|
230
|
-
- extraordinary_item_and_accounting_change()
|
|
231
|
-
- net_income_to_company()
|
|
232
|
-
- minority_interest_in_earnings()
|
|
233
|
-
- net_income()
|
|
234
|
-
- premium_on_redemption_of_preferred_stock()
|
|
235
|
-
- preferred_stock_dividend()
|
|
236
|
-
- other_preferred_stock_adjustments()
|
|
237
|
-
- other_adjustments_to_net_income()
|
|
238
|
-
- preferred_dividends_and_other_adjustments()
|
|
239
|
-
- net_income_allocable_to_general_partner()
|
|
240
|
-
- net_income_to_common_shareholders_including_extra_items()
|
|
241
|
-
- net_income_to_common_shareholders_excluding_extra_items()
|
|
242
|
-
- cash_and_equivalents()
|
|
243
|
-
- short_term_investments()
|
|
244
|
-
- trading_asset_securities()
|
|
245
|
-
- total_cash_and_short_term_investments()
|
|
246
|
-
- accounts_receivable()
|
|
247
|
-
- other_receivables()
|
|
248
|
-
- notes_receivable()
|
|
249
|
-
- total_receivables()
|
|
250
|
-
- inventory()
|
|
251
|
-
- prepaid_expense()
|
|
252
|
-
- finance_division_loans_and_leases_short_term()
|
|
253
|
-
- finance_division_other_current_assets()
|
|
254
|
-
- loans_held_for_sale()
|
|
255
|
-
- deferred_tax_asset_current_portion()
|
|
256
|
-
- restricted_cash()
|
|
257
|
-
- other_current_assets()
|
|
258
|
-
- total_current_assets()
|
|
259
|
-
- gross_property_plant_and_equipment()
|
|
260
|
-
- accumulated_depreciation()
|
|
261
|
-
- net_property_plant_and_equipment()
|
|
262
|
-
- long_term_investments()
|
|
263
|
-
- goodwill()
|
|
264
|
-
- other_intangibles()
|
|
265
|
-
- finance_division_loans_and_leases_long_term()
|
|
266
|
-
- finance_division_other_non_current_assets()
|
|
267
|
-
- long_term_accounts_receivable()
|
|
268
|
-
- long_term_loans_receivable()
|
|
269
|
-
- long_term_deferred_tax_assets()
|
|
270
|
-
- long_term_deferred_charges()
|
|
271
|
-
- other_long_term_assets()
|
|
272
|
-
- total_assets()
|
|
273
|
-
- accounts_payable()
|
|
274
|
-
- accrued_expenses()
|
|
275
|
-
- short_term_borrowings()
|
|
276
|
-
- current_portion_of_long_term_debt()
|
|
277
|
-
- current_portion_of_capital_leases()
|
|
278
|
-
- current_portion_of_long_term_debt_and_capital_leases()
|
|
279
|
-
- finance_division_debt_current_portion()
|
|
280
|
-
- finance_division_other_current_liabilities()
|
|
281
|
-
- current_income_taxes_payable()
|
|
282
|
-
- current_unearned_revenue()
|
|
283
|
-
- current_deferred_tax_liability()
|
|
284
|
-
- other_current_liability()
|
|
285
|
-
- total_current_liabilities()
|
|
286
|
-
- long_term_debt()
|
|
287
|
-
- capital_leases()
|
|
288
|
-
- finance_division_debt_non_current_portion()
|
|
289
|
-
- finance_division_other_non_current_liabilities()
|
|
290
|
-
- non_current_unearned_revenue()
|
|
291
|
-
- pension_and_other_post_retirement_benefit()
|
|
292
|
-
- non_current_deferred_tax_liability()
|
|
293
|
-
- other_non_current_liabilities()
|
|
294
|
-
- total_liabilities()
|
|
295
|
-
- preferred_stock_redeemable()
|
|
296
|
-
- preferred_stock_non_redeemable()
|
|
297
|
-
- preferred_stock_convertible()
|
|
298
|
-
- preferred_stock_other()
|
|
299
|
-
- preferred_stock_additional_paid_in_capital()
|
|
300
|
-
- preferred_stock_equity_adjustment()
|
|
301
|
-
- treasury_stock_preferred_stock_convertible()
|
|
302
|
-
- treasury_stock_preferred_stock_non_redeemable()
|
|
303
|
-
- treasury_stock_preferred_stock_redeemable()
|
|
304
|
-
- total_preferred_equity()
|
|
305
|
-
- common_stock()
|
|
306
|
-
- additional_paid_in_capital()
|
|
307
|
-
- retained_earnings()
|
|
308
|
-
- treasury_stock()
|
|
309
|
-
- other_equity()
|
|
310
|
-
- total_common_equity()
|
|
311
|
-
- total_equity()
|
|
312
|
-
- total_liabilities_and_equity()
|
|
313
|
-
- common_shares_outstanding()
|
|
314
|
-
- adjustments_to_cash_flow_net_income()
|
|
315
|
-
- other_amortization()
|
|
316
|
-
- total_other_non_cash_items()
|
|
317
|
-
- net_decrease_in_loans_originated_and_sold()
|
|
318
|
-
- provision_for_credit_losses()
|
|
319
|
-
- loss_on_equity_investments()
|
|
320
|
-
- stock_based_compensation()
|
|
321
|
-
- tax_benefit_from_stock_options()
|
|
322
|
-
- net_cash_from_discontinued_operation()
|
|
323
|
-
- other_operating_activities()
|
|
324
|
-
- change_in_trading_asset_securities()
|
|
325
|
-
- change_in_accounts_receivable()
|
|
326
|
-
- change_in_inventories()
|
|
327
|
-
- change_in_accounts_payable()
|
|
328
|
-
- change_in_unearned_revenue()
|
|
329
|
-
- change_in_income_taxes()
|
|
330
|
-
- change_in_deferred_taxes()
|
|
331
|
-
- change_in_other_net_operating_assets()
|
|
332
|
-
- change_in_net_operating_assets()
|
|
333
|
-
- cash_from_operations()
|
|
334
|
-
- capital_expenditure()
|
|
335
|
-
- sale_of_property_plant_and_equipment()
|
|
336
|
-
- cash_acquisitions()
|
|
337
|
-
- divestitures()
|
|
338
|
-
- sale_of_real_estate()
|
|
339
|
-
- sale_of_intangible_assets()
|
|
340
|
-
- net_cash_from_investments()
|
|
341
|
-
- net_decrease_in_investment_loans_originated_and_sold()
|
|
342
|
-
- other_investing_activities()
|
|
343
|
-
- total_other_investing_activities()
|
|
344
|
-
- cash_from_investing()
|
|
345
|
-
- short_term_debt_issued()
|
|
346
|
-
- long_term_debt_issued()
|
|
347
|
-
- total_debt_issued()
|
|
348
|
-
- short_term_debt_repaid()
|
|
349
|
-
- long_term_debt_repaid()
|
|
350
|
-
- total_debt_repaid()
|
|
351
|
-
- issuance_of_common_stock()
|
|
352
|
-
- repurchase_of_common_stock()
|
|
353
|
-
- issuance_of_preferred_stock()
|
|
354
|
-
- repurchase_of_preferred_stock()
|
|
355
|
-
- common_dividends_paid()
|
|
356
|
-
- preferred_dividends_paid()
|
|
357
|
-
- total_dividends_paid()
|
|
358
|
-
- special_dividends_paid()
|
|
359
|
-
- other_financing_activities()
|
|
360
|
-
- cash_from_financing()
|
|
361
|
-
- foreign_exchange_rate_adjustments()
|
|
362
|
-
- miscellaneous_cash_flow_adjustments()
|
|
363
|
-
- net_change_in_cash()
|
|
364
|
-
- depreciation()
|
|
365
|
-
- depreciation_of_rental_assets()
|
|
366
|
-
- sale_proceeds_from_rental_assets()
|
|
367
|
-
- basic_eps()
|
|
368
|
-
- basic_eps_excluding_extra_items()
|
|
369
|
-
- basic_eps_from_accounting_change()
|
|
370
|
-
- basic_eps_from_extraordinary_items()
|
|
371
|
-
- basic_eps_from_accounting_change_and_extraordinary_items()
|
|
372
|
-
- weighted_average_basic_shares_outstanding()
|
|
373
|
-
- diluted_eps()
|
|
374
|
-
- diluted_eps_excluding_extra_items()
|
|
375
|
-
- weighted_average_diluted_shares_outstanding()
|
|
376
|
-
- normalized_basic_eps()
|
|
377
|
-
- normalized_diluted_eps()
|
|
378
|
-
- dividends_per_share()
|
|
379
|
-
- distributable_cash_per_share()
|
|
380
|
-
- diluted_eps_from_accounting_change_and_extraordinary_items()
|
|
381
|
-
- diluted_eps_from_accounting_change()
|
|
382
|
-
- diluted_eps_from_extraordinary_items()
|
|
383
|
-
- diluted_eps_from_discontinued_operations()
|
|
384
|
-
- funds_from_operations()
|
|
385
|
-
- ebitda()
|
|
386
|
-
- ebita()
|
|
387
|
-
- ebit()
|
|
388
|
-
- ebitdar()
|
|
389
|
-
- net_debt()
|
|
390
|
-
- effective_tax_rate()
|
|
391
|
-
- current_ratio()
|
|
392
|
-
- quick_ratio()
|
|
393
|
-
- total_debt_to_capital()
|
|
394
|
-
- net_working_capital()
|
|
395
|
-
- working_capital()
|
|
396
|
-
- change_in_net_working_capital()
|
|
397
|
-
- total_debt()
|
|
398
|
-
- total_debt_to_equity_ratio()
|
|
399
|
-
Returns:
|
|
400
|
-
A Pandas DataFrame with column headers as a string with the time period.
|
|
401
|
-
For quarterly, ytd, or ltm data: <Year>'Q'<Quarter>, such as '2023Q4'.
|
|
402
|
-
For annual data: <Year>, such as '2021'.
|
|
403
|
-
For example, to access the value for 2023Q3, use df['2023Q3']. Or to access into year 2021, use df['2021'].
|
|
404
|
-
|
|
405
|
-
Examples:
|
|
406
|
-
Question:
|
|
407
|
-
What is the return on equity for IBM from 2020 to 2023?
|
|
408
|
-
Answer:
|
|
409
|
-
ibm = client.ticker("IBM")
|
|
410
|
-
net_income = ibm.net_income(start_year=2020, end_year=2023)
|
|
411
|
-
total_equity = ibm.total_equity(start_year=2020, end_year=2023)
|
|
412
|
-
roe = net_income.reset_index(drop=True) / total_equity.reset_index(drop=True)
|
|
413
|
-
roe
|
|
414
|
-
|
|
415
|
-
Question:
|
|
416
|
-
What is the revenue CAGR for META from 2019 to 2023?
|
|
417
|
-
Answer:
|
|
418
|
-
meta = client.ticker("META")
|
|
419
|
-
revenue = meta.revenue(start_year=2019, end_year = 2023)
|
|
420
|
-
cagr = (revenue['2023'] / revenue['2019']) ** (1/4) - 1
|
|
421
|
-
cagr
|
|
422
|
-
|
|
423
|
-
Question:
|
|
424
|
-
What is BoFa's gross profit in the last 4 years?
|
|
425
|
-
Answer:
|
|
426
|
-
bac = client.ticker("BAC")
|
|
427
|
-
# Don't have information for the current year, so check last year
|
|
428
|
-
end_year = datetime.date.today().year - 1
|
|
429
|
-
gross_profit = bac.gross_profit(start_year=end_year - 4, end_year=end_year)
|
|
430
|
-
gross_profit
|
|
431
|
-
|
|
432
|
-
Question:
|
|
433
|
-
What is Chipotle's working capital from 2019 to 2021?
|
|
434
|
-
Answer:
|
|
435
|
-
chipotle = client.ticker("CMG")
|
|
436
|
-
working_capital = chipotle.working_capital(start_year=2019, end_year=2021)
|
|
437
|
-
working_capital
|
|
438
|
-
|
|
439
|
-
Question:
|
|
440
|
-
What is the percentage change in gross profit for Microsoft from 2021 to now?
|
|
441
|
-
Answer:
|
|
442
|
-
microsoft = client.ticker("MSFT")
|
|
443
|
-
end_year = datetime.date.today().year - 1
|
|
444
|
-
gross_profit = microsoft.gross_profit(start_year=2021, end_year=end_year)
|
|
445
|
-
percentage_change = (gross_profit[str(end_year)] - gross_profit["2021"]) / gross_profit["2021"] * 100
|
|
446
|
-
percentage_change
|
|
447
|
-
|
|
448
|
-
Question:
|
|
449
|
-
What is Airbnb's quick ratio quarterly for the last 4 years?
|
|
450
|
-
Answer:
|
|
451
|
-
airbnb = client.ticker("ABNB")
|
|
452
|
-
quick_ratio = airbnb.quick_ratio(period_type="quarterly", start_year=datetime.datetime.now().year - 4, end_year=datetime.datetime.now().year)
|
|
453
|
-
quick_ratio
|
|
454
|
-
|
|
455
|
-
Question:
|
|
456
|
-
LTM EBITDA from Q3 of 2022 to Q1 of 2024 for Exxon?
|
|
457
|
-
Answer:
|
|
458
|
-
exxon = client.ticker("XOM")
|
|
459
|
-
ebitda = exxon.ebitda(period_type="ltm", start_year=2022, start_quarter=3, end_year=2024, end_quarter=1)
|
|
460
|
-
ebitda
|
|
461
|
-
|
|
462
|
-
Question:
|
|
463
|
-
What is Verizon's year to date capex?
|
|
464
|
-
Answer:
|
|
465
|
-
verizon = client.ticker("VZ")
|
|
466
|
-
capital_expenditure = verizon.capital_expenditure(period_type="ytd")
|
|
467
|
-
capital_expenditure
|
|
468
|
-
\"""
|
|
469
|
-
|
|
470
|
-
Functions:
|
|
471
|
-
The following functions `history` and `price_chart` share the same parameters.
|
|
472
|
-
|
|
473
|
-
def history(self, periodicity: Optional[str] = "day", adjusted: Optional[bool] = True, start_date: Optional[str] = None, end_date: Optional[str] = None) -> pd.DataFrame:
|
|
474
|
-
Retrieves the historical price data for a given asset over a specified date range.
|
|
475
|
-
Returns:
|
|
476
|
-
A pd.DataFrame containing historical price data with columns corresponding to the specified periodicity,
|
|
477
|
-
with Date as the index, and columns "open", "high", "low", "close", "volume" in type decimal.
|
|
478
|
-
The Date index is a string that depends on the periodicity.
|
|
479
|
-
If periodicity="day", the Date index is the day in format "YYYY-MM-DD", eg "2024-05-13".
|
|
480
|
-
If periodicity="week", the Date index is the week number of the year in format "YYYY Week ##", eg "2024 Week 2".
|
|
481
|
-
If periodicity="month", the Date index is the month name of the year in format "<Month> YYYY", eg "January 2024".
|
|
482
|
-
If periodicity="year", the Date index is the year in format "YYYY", eg "2024".
|
|
483
|
-
|
|
484
|
-
def price_chart(self, periodicity: Optional[str] = "day", adjusted: Optional[bool] = True, start_date: Optional[str] = None, end_date: Optional[str] = None) -> Image:
|
|
485
|
-
Retrieves the plotted historical price data for a given asset over a specified date range as an Image.
|
|
486
|
-
Returns:
|
|
487
|
-
An Image object with the plotted price data.
|
|
488
|
-
\"""
|
|
489
|
-
Shared Parameters of function `history` and `price_chart`:
|
|
490
|
-
periodicity: Optional[str], default "day"
|
|
491
|
-
The frequency or interval at which the historical data points are sampled or aggregated. Periodicity is not the same as the date range. The date range specifies the time span over which the data is retrieved, while periodicity determines how the data within that date range is aggregated.
|
|
492
|
-
Options:
|
|
493
|
-
"day": Data points are returned for each day within the specified date range.
|
|
494
|
-
"week": Data points are aggregated weekly, with each row representing a week.
|
|
495
|
-
"month": Data points are aggregated monthly, with each row representing a month.
|
|
496
|
-
"year": Data points are aggregated yearly, with each row representing a year.
|
|
497
|
-
adjusted: Optional[bool], default True
|
|
498
|
-
Whether to retrieve adjusted prices that account for corporate actions such as dividends and splits.
|
|
499
|
-
start_date: Optional[str], default None
|
|
500
|
-
The start date for historical price retrieval in format "YYYY-MM-DD".
|
|
501
|
-
end_date: Optional[str], default None
|
|
502
|
-
The end date for historical price retrieval in format "YYYY-MM-DD".
|
|
503
|
-
If end_date is not specified, put end_date as today.
|
|
504
|
-
|
|
505
|
-
Examples:
|
|
506
|
-
Question:
|
|
507
|
-
What were Apple's prices for the the last 3 weeks?
|
|
508
|
-
Answer:
|
|
509
|
-
from dateutil.relativedelta import relativedelta
|
|
510
|
-
apple = client.ticker("AAPL")
|
|
511
|
-
end_date = datetime.date.today()
|
|
512
|
-
start_date = end_date - datetime.relativedelta(days=3*7)
|
|
513
|
-
prices = apple.history(periodicity="day", start_date=str(start_date), end_date=str(end_date))
|
|
514
|
-
prices
|
|
515
|
-
|
|
516
|
-
Question:
|
|
517
|
-
What was Nvidia's prices for the last 2 years on a weekly basis?
|
|
518
|
-
Answer:
|
|
519
|
-
from dateutil.relativedelta import relativedelta
|
|
520
|
-
nvda = client.ticker("NVDA")
|
|
521
|
-
end_date = datetime.date.today()
|
|
522
|
-
start_date = end_date - datetime.relativedelta(days=2*365)
|
|
523
|
-
prices = nvda.history(periodicity="week", start_date=str(start_date), end_date=str(end_date))
|
|
524
|
-
prices
|
|
525
|
-
\"""
|
|
526
|
-
""".replace("XXXX", str(datetime.now().year))
|
kfinance/pydantic_models.py
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
from pydantic import BaseModel
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
class TranscriptComponent(BaseModel):
|
|
5
|
-
"""A transcript component with person name, text, and component type."""
|
|
6
|
-
|
|
7
|
-
person_name: str
|
|
8
|
-
text: str
|
|
9
|
-
component_type: str
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class RelationshipResponseNoName(BaseModel):
|
|
13
|
-
"""A response from the relationship endpoint before adding the company name.
|
|
14
|
-
|
|
15
|
-
Each element in `current` and `previous` is a company_id.
|
|
16
|
-
"""
|
|
17
|
-
|
|
18
|
-
current: list[int]
|
|
19
|
-
previous: list[int]
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
class CompanyIdAndName(BaseModel):
|
|
23
|
-
"""A company_id and name"""
|
|
24
|
-
|
|
25
|
-
company_id: int
|
|
26
|
-
company_name: str
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
class RelationshipResponse(BaseModel):
|
|
30
|
-
"""A response from the relationship endpoint that includes both company_id and name."""
|
|
31
|
-
|
|
32
|
-
current: list[CompanyIdAndName]
|
|
33
|
-
previous: list[CompanyIdAndName]
|