Finance Tools
enhancedtoolkits.finance.YFinanceTools ¶
YFinanceTools(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
209 210 211 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 304 305 306 | |
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
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 392 393 394 395 396 397 398 399 400 401 402 | |
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
804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 | |
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. One of: '1d', '5d', '1mo', '3mo', '6mo', '1y', '2y', '5y', '10y', 'ytd', 'max' | '1y' |
interval | str | The time interval. One of: '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
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 | |
get_llm_usage_instructions staticmethod ¶
Return precise, structured instructions for LLM tool calling.