Finance Tools
enhancedtoolkits.finance.EnhancedYFinanceTools ¶
EnhancedYFinanceTools(enable_caching: bool = True, cache_ttl: int = 300, rate_limit_delay: float = 0.1, **kwargs)
Bases: StrictToolkit
Enhanced YFinance Tools v2.0
A production-ready financial data toolkit with comprehensive error handling, input validation, caching, and consistent data formatting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
enable_caching | bool | Whether to enable response caching | True |
cache_ttl | int | Cache time-to-live in seconds | 300 |
rate_limit_delay | float | Delay between API requests in seconds | 0.1 |
Source code in src/enhancedtoolkits/finance.py
Functions¶
fetch_current_stock_price ¶
Retrieves the current price of a stock given its ticker symbol.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ticker | str | The ticker symbol of the stock | required |
Returns:
Type | Description |
---|---|
str | JSON string containing current price information |
Raises:
Type | Description |
---|---|
YFinanceValidationError | If ticker is invalid |
YFinanceDataError | If price data cannot be retrieved |
Source code in src/enhancedtoolkits/finance.py
fetch_company_information ¶
Retrieve comprehensive information about a company.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ticker | str | The ticker symbol of the company | required |
Returns:
Type | Description |
---|---|
str | JSON string containing company information |
Raises:
Type | Description |
---|---|
YFinanceValidationError | If ticker is invalid |
YFinanceDataError | If company data cannot be retrieved |
Source code in src/enhancedtoolkits/finance.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
|
fetch_ticker_news ¶
Retrieve the latest news articles for a given stock ticker.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ticker | str | The stock ticker symbol | required |
max_articles | int | Maximum number of articles to return | 10 |
Returns:
Type | Description |
---|---|
str | JSON string containing news articles |
Raises:
Type | Description |
---|---|
YFinanceValidationError | If ticker is invalid |
YFinanceDataError | If news data cannot be retrieved |
Source code in src/enhancedtoolkits/finance.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
|
fetch_earnings_history ¶
Retrieves the earnings history for a specified stock ticker.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ticker | str | The stock ticker symbol | required |
Returns:
Type | Description |
---|---|
str | JSON string containing earnings history |
Raises:
Type | Description |
---|---|
YFinanceValidationError | If ticker is invalid |
YFinanceDataError | If earnings data cannot be retrieved |
Source code in src/enhancedtoolkits/finance.py
fetch_income_statement ¶
Retrieves the income statement for a given stock ticker.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ticker | str | The stock ticker symbol | required |
Returns:
Type | Description |
---|---|
str | JSON string containing income statement data |
Raises:
Type | Description |
---|---|
YFinanceValidationError | If ticker is invalid |
YFinanceDataError | If financial data cannot be retrieved |
Source code in src/enhancedtoolkits/finance.py
fetch_quarterly_financials ¶
Retrieve the quarterly financials for a given stock ticker.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ticker | str | The stock ticker symbol | required |
Returns:
Type | Description |
---|---|
str | JSON string containing quarterly financial data |
Raises:
Type | Description |
---|---|
YFinanceValidationError | If ticker is invalid |
YFinanceDataError | If financial data cannot be retrieved |
Source code in src/enhancedtoolkits/finance.py
fetch_balance_sheet ¶
Retrieve the balance sheet for a given stock ticker.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ticker | str | The stock ticker symbol | required |
Returns:
Type | Description |
---|---|
str | JSON string containing balance sheet data |
Raises:
Type | Description |
---|---|
YFinanceValidationError | If ticker is invalid |
YFinanceDataError | If financial data cannot be retrieved |
Source code in src/enhancedtoolkits/finance.py
fetch_quarterly_balance_sheet ¶
Retrieve the quarterly balance sheet for a given stock ticker.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ticker | str | The stock ticker symbol | required |
Returns:
Type | Description |
---|---|
str | JSON string containing quarterly balance sheet data |
Raises:
Type | Description |
---|---|
YFinanceValidationError | If ticker is invalid |
YFinanceDataError | If financial data cannot be retrieved |
Source code in src/enhancedtoolkits/finance.py
fetch_cashflow_statement ¶
Retrieve the annual cash flow statement for a given stock ticker.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ticker | str | The stock ticker symbol | required |
Returns:
Type | Description |
---|---|
str | JSON string containing cash flow data |
Raises:
Type | Description |
---|---|
YFinanceValidationError | If ticker is invalid |
YFinanceDataError | If financial data cannot be retrieved |
Source code in src/enhancedtoolkits/finance.py
fetch_quarterly_cashflow_statement ¶
Retrieve the quarterly cash flow statement for a given stock ticker.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ticker | str | The stock ticker symbol | required |
Returns:
Type | Description |
---|---|
str | JSON string containing quarterly cash flow data |
Raises:
Type | Description |
---|---|
YFinanceValidationError | If ticker is invalid |
YFinanceDataError | If financial data cannot be retrieved |
Source code in src/enhancedtoolkits/finance.py
fetch_major_shareholders ¶
Retrieve the list of major shareholders for a given stock ticker.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ticker | str | The stock ticker symbol | required |
Returns:
Type | Description |
---|---|
str | JSON string containing major shareholders data |
Raises:
Type | Description |
---|---|
YFinanceValidationError | If ticker is invalid |
YFinanceDataError | If holder data cannot be retrieved |
Source code in src/enhancedtoolkits/finance.py
fetch_institutional_shareholders ¶
Retrieve the list of institutional shareholders for a given stock ticker.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ticker | str | The stock ticker symbol | required |
Returns:
Type | Description |
---|---|
str | JSON string containing institutional shareholders data |
Raises:
Type | Description |
---|---|
YFinanceValidationError | If ticker is invalid |
YFinanceDataError | If holder data cannot be retrieved |
Source code in src/enhancedtoolkits/finance.py
fetch_analyst_recommendations ¶
Retrieve stock recommendations for a given ticker.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ticker | str | The stock ticker symbol | required |
Returns:
Type | Description |
---|---|
str | JSON string containing stock recommendations |
Raises:
Type | Description |
---|---|
YFinanceValidationError | If ticker is invalid |
YFinanceDataError | If recommendation data cannot be retrieved |
Source code in src/enhancedtoolkits/finance.py
fetch_sustainability_scores ¶
Retrieve sustainability scores for a given stock ticker.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ticker | str | The stock ticker symbol | required |
Returns:
Type | Description |
---|---|
str | JSON string containing sustainability scores |
Raises:
Type | Description |
---|---|
YFinanceValidationError | If ticker is invalid |
YFinanceDataError | If sustainability data cannot be retrieved |
Source code in src/enhancedtoolkits/finance.py
fetch_price_history ¶
Retrieves the price history of a specified stock ticker.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ticker | str | The stock ticker symbol | required |
period | str | The time period ('1d', '5d', '1mo', '3mo', '6mo', '1y', '2y', '5y', '10y', 'ytd', 'max') | '1y' |
interval | str | The time interval ('1m', '2m', '5m', '15m', '30m', '60m', '90m', '1h', '1d', '5d', '1wk', '1mo', '3mo') | '1d' |
Returns:
Type | Description |
---|---|
str | JSON string containing price history data |
Raises:
Type | Description |
---|---|
YFinanceValidationError | If ticker, period, or interval is invalid |
YFinanceDataError | If price history cannot be retrieved |
Source code in src/enhancedtoolkits/finance.py
get_llm_usage_instructions staticmethod
¶
Returns a set of detailed instructions for LLMs on how to use each tool in EnhancedYFinanceTools. Each instruction includes the method name, description, parameters, types, and example values.
Source code in src/enhancedtoolkits/finance.py
1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 |
|