AI4Finance-Foundation / FinRobot
- ΠΏΡΡΠ½ΠΈΡΠ°, 31 ΠΌΠ°Ρ 2024β―Π³. Π² 00:00:07
FinRobot: An Open-Source AI Agent Platform for Financial Applications using LLMs π π π
FinRobot is an AI Agent Platform that transcends the scope of FinGPT, representing a comprehensive solution meticulously designed for financial applications. It integrates a diverse array of AI technologies, extending beyond mere language models. This expansive vision highlights the platform's versatility and adaptability, addressing the multifaceted needs of the financial industry.
Concept of AI Agent: an AI Agent is an intelligent entity that uses large language models as its brain to perceive its environment, make decisions, and execute actions. Unlike traditional artificial intelligence, AI Agents possess the ability to independently think and utilize tools to progressively achieve given objectives.
Perception: This module captures and interprets multimodal financial data from market feeds, news, and economic indicators, using sophisticated techniques to structure the data for thorough analysis.
Brain: Acting as the core processing unit, this module perceives data from the Perception module with LLMs and utilizes Financial Chain-of-Thought (CoT) processes to generate structured instructions.
Action: This module executes instructions from the Brain module, applying tools to translate analytical insights into actionable outcomes. Actions include trading, portfolio adjustments, generating reports, or sending alerts, thereby actively influencing the financial environment.
The Smart Scheduler is central to ensuring model diversity and optimizing the integration and selection of the most appropriate LLM for each task.
The main folder finrobot has three subfolders agents, data_source, functional.
FinRobot
βββ finrobot (main folder)
β βββ agents
β βββ agent_library.py
β βββ workflow.py
β βββ data_source
β βββ finnhub_utils.py
β βββ finnlp_utils.py
β βββ fmp_utils.py
β βββ sec_utils.py
β βββ yfinance_utils.py
β βββ functional
β βββ analyzer.py
β βββ charting.py
β βββ coding.py
β βββ quantitative.py
β βββ reportlab.py
β βββ text.py
β βββ toolkits.py
β βββ utils.py
β
βββ configs
βββ experiments
βββ tutorials_beginner (hands-on tutorial)
β βββ agent_fingpt_forecaster.ipynb
β βββ agent_annual_report.ipynb
βββ tutorials_advanced (advanced tutorials for potential finrobot developers)
β βββ agent_trade_strategist.ipynb
β βββ agent_fingpt_forecaster.ipynb
β βββ agent_annual_report.ipynb
β βββ lmm_agent_mplfinance.ipynb
β βββ lmm_agent_opt_smacross.ipynb
βββ setup.py
βββ OAI_CONFIG_LIST_sample
βββ config_api_keys_sample
βββ requirements.txt
βββ README.md
1. (Recommended) Create a new virtual environment
conda create --name finrobot python=3.10
conda activate finrobot
2. download the FinRobot repo use terminal or download it manually
git clone https://github.com/AI4Finance-Foundation/FinRobot.git
cd FinRobot
3. install finrobot & dependencies from source or pypi
get our latest release from pypi
pip install -U finrobot
or install from this repo directly
pip install -e .
4. modify OAI_CONFIG_LIST_sample file
1) rename OAI_CONFIG_LIST_sample to OAI_CONFIG_LIST
2) remove the four lines of comment within the OAI_CONFIG_LIST file
3) add your own openai api-key <your OpenAI API key here>
5. modify config_api_keys_sample file
1) rename config_api_keys_sample to config_api_keys
2) remove the comment within the config_api_keys file
3) add your own finnhub-api "YOUR_FINNHUB_API_KEY"
4) add your own financialmodelingprep and sec-api keys "YOUR_FMP_API_KEY" and "YOUR_SEC_API_KEY" (for financial report generation)
6. start navigating the tutorials or the demos below:
# find these notebooks in tutorials
1) agent_annual_report.ipynb
2) agent_fingpt_forecaster.ipynb
3) agent_trade_strategist.ipynb
4) lmm_agent_mplfinance.ipynb
5) lmm_agent_opt_smacross.ipynb
Takes a company's ticker symbol, recent basic financials, and market news as input and predicts its stock movements.
import autogen
from finrobot.utils import get_current_date, register_keys_from_json
from finrobot.agents.workflow import SingleAssistant
# Read OpenAI API keys from a JSON file
llm_config = {
"config_list": autogen.config_list_from_json(
"../OAI_CONFIG_LIST",
filter_dict={"model": ["gpt-4-0125-preview"]},
),
"timeout": 120,
"temperature": 0,
}
# Register FINNHUB API keys
register_keys_from_json("../config_api_keys")
company = "NVDA"
assitant = SingleAssistant(
"Market_Analyst",
llm_config,
# set to "ALWAYS" if you want to chat instead of simply receiving the prediciton
human_input_mode="NEVER",
)
assitant.chat(
f"Use all the tools provided to retrieve information available for {company} upon {get_current_date()}. Analyze the positive developments and potential concerns of {company} "
"with 2-4 most important factors respectively and keep them concise. Most factors should be inferred from company related news. "
f"Then make a rough prediction (e.g. up/down by 2-3%) of the {company} stock price movement for next week. Provide a summary analysis to support your prediction."
)
Take a company's 10-k form, financial data, and market data as input and output an equity research report
import os
import autogen
from textwrap import dedent
from finrobot.utils import register_keys_from_json
from finrobot.agents.workflow import SingleAssistantShadow
llm_config = {
"config_list": autogen.config_list_from_json(
"../OAI_CONFIG_LIST",
filter_dict={
"model": ["gpt-4-0125-preview"],
},
),
"timeout": 120,
"temperature": 0.5,
}
register_keys_from_json("../config_api_keys")
# Intermediate strategy modules will be saved in this directory
work_dir = "../report"
os.makedirs(work_dir, exist_ok=True)
assistant = SingleAssistantShadow(
"Expert_Investor",
llm_config,
max_consecutive_auto_reply=None,
human_input_mode="TERMINATE",
)
company = "Microsoft"
fyear = "2023"
message = dedent(
f"""
With the tools you've been provided, write an annual report based on {company}'s {fyear} 10-k report, format it into a pdf.
Pay attention to the followings:
- Explicitly explain your working plan before you kick off.
- Use tools one by one for clarity, especially when asking for instructions.
- All your file operations should be done in "{work_dir}".
- Display any image in the chat once generated.
- All the paragraphs should combine between 400 and 450 words, don't generate the pdf until this is explicitly fulfilled.
"""
)
assistant.chat(message, use_cache=True, max_turns=50,
summary_method="last_msg")
Financial CoT:
Disclaimer: The codes and documents provided herein are released under the Apache-2.0 license. They should not be construed as financial counsel or recommendations for live trading. It is imperative to exercise caution and consult with qualified financial professionals prior to any trading or investment actions.