Skip to content

Conversation

@blueberrycongee
Copy link

Summary

Add a new Finance tool that retrieves real-time and historical stock market data using Yahoo Finance API.

Features

  • 4 actions supported:

    • price - Get current stock price and trading info
    • history - Get historical price data
    • info - Get detailed company information
    • financials - Get financial statements summary
  • Multi-market support:

    • US stocks (AAPL, GOOGL, MSFT)
    • Hong Kong stocks (9988.HK)
    • Chinese A-shares (600519.SS, 000001.SZ)

Changes

File Description
qwen_agent/tools/finance.py Finance tool implementation (~295 lines)
qwen_agent/tools/init.py Export Finance class
setup.py Add [finance] optional dependency (yfinance)
examples/assistant_finance_bot.py Example usage
tests/tools/test_finance.py Unit tests

Installation

pip install qwen-agent[finance]

- Add Finance tool with support for: price, history, info, financials actions

- Support US stocks, Hong Kong stocks (.HK), and Chinese A-shares (.SS/.SZ)

- Add yfinance as optional dependency in setup.py

- Add example: assistant_finance_bot.py

- Add unit tests for Finance tool
@ycat3
Copy link

ycat3 commented Dec 17, 2025

Thank you for nice work. It works fine.
However STOCK_dividends returns wrong value, 100 times bigger.
I also add cosmetic change.
See #754

@blueberrycongee
Copy link
Author

@ycat3 Thank you for your feedback!

We have investigated the issue and found that while
yfinance
typically returns dividendYield as a decimal (e.g., 0.05 for 5%), there is a known upstream issue where Yahoo Finance data can sometimes be off by a factor of 100 (the "100x error"), causing it to appear as a percentage or larger.

To address this and ensure robustness, I've updated the code to handle both cases:

If the value is > 1, we treat it as a percentage (or an error-corrected value) and display it as is.
If the value is <= 1, we multiply by 100 to convert the decimal to a percentage.
This should resolve the discrepancy you observed while maintaining correctness for standard data.

@tuhahaha Could you please review these changes when you have a moment? Thanks!

@ycat3
Copy link

ycat3 commented Jan 27, 2026

Thank you blueberrycongee and tuhahaha.
I have checked and it works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants