Importing Libraries
First, we need to import several libraries, each with its specific purpose:
yfinance helps us obtain stock data, tablib is a Python library for processing stock data and calculating technical indicators, and streamlit enables API interaction and web interface display, among other functions.
Defining Large Model API and AI Analysis Functions
We can call the Qwen2 large model through the SiliconFlow platform, which has recently been launched for public testing and allows free access to a quota of 42 yuan, approximately 300 million tokens. It is compatible with the OpenAI interface and can be used after installing the OpenAI Python library. After that, we can directly call the relevant interfaces of OpenAI, as the platform supports most parameters related to OpenAI. By modifying the base_url, model, and api_key parameters, it can be used directly. The supported model parameters are shown in the figure.
To interact with the SiliconFlow API, we define a function: siliconflow_run, which communicates with SiliconFlow via the API key, sends requests, and receives responses:
User Input and Stock Data Acquisition
Through the sidebar of Streamlit, we obtain the stock code and date input by the user. This part of the code allows users to input parameters through the web interface. We define functions to obtain stock names and stock data, which retrieve stock names and stock data via API and implement a retry mechanism.
Technical Analysis Data Analysis and Display
After obtaining the data, we calculate technical indicators and call the AI analysis function, then display the results on the web interface:
Through this system, we can obtain stock data in real-time, calculate various technical indicators, and combine them with the latest AI large model for intelligent analysis. It can quickly provide intelligent support for our investment decisions, especially for investors who do not fully understand complex financial indicators, helping them better understand market trends. However, in practice, we also need to consider various factors such as fundamentals for a comprehensive analysis, and then make scientific investment decisions.
Long press to scan the code to obtain the complete code and document download password for this article: