MCPcopy Index your code
hub / github.com/MingyuJ666/Stockagent

github.com/MingyuJ666/Stockagent @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
62 symbols 171 edges 8 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

When AI Meets Finance (StockAgent): Large Language Model-based Stock Trading in Simulated Real-world Environments

workflow schematic

Can AI Agents simulate real-world trading environments to investigate the impact of external factors on stock trading activities (e.g., macroeconomics, policy changes, company fundamentals, and global events)? These factors, which frequently influence trading behaviors, are critical elements in the quest for maximizing investors' profits. Our work attempts to solve this problem through large language model-based agents. We have developed a multi-agent AI system called StockAgent, driven by LLMs, designed to simulate investors' trading behaviors in response to the real stock market. The StockAgent allows users to evaluate the impact of different external factors on investor trading and to analyze trading behavior and profitability effects. Additionally, StockAgent avoids the test set leakage issue present in existing trading simulation systems based on AI Agents. Specifically, it prevents the model from leveraging prior knowledge it may have acquired related to the test data. We evaluate different LLMs under the framework of StockAgent in a stock trading environment that closely resembles real-world conditions. The experimental results demonstrate the impact of key external factors on stock market trading, including trading behavior and stock price fluctuation rules. This research explores the study of agents' free trading gaps in the context of no prior knowledge related to market data. The patterns identified through StockAgent simulations provide valuable insights for LLM-based investment advice and stock recommendation.

Link

ARXIV LINK: https://arxiv.org/pdf/2407.18957

Accepted by Transactions on Intelligent Systems and Technology (ACM TIST)

Architecture

architect

The Workflow of Trading Simulation Flow. There are four Phases, namely Initial Phase, Trading Phase, Post-Trading Phase and Special Events Phase. In the Post-Trading Phase, Daily events and Quarterly events occur with daily and quarterly frequency respectively. A Specific Events Phase is an event that occurs randomly and acts on a random trading day.

Quick Start

Environment

conda create --name stockagent python=3.9
conda activate stockagent

git clone https://github.com/dhh1995/PromptCoder
cd PromptCoder
pip install -e .
cd ..

git clone <This Github Project>
cd Stockagent
pip install -r requirements.txt

API keys

Use GPTs as agent LLM:

export OPENAI_API_KEY=YOUR_OPENAI_API_KEY

Use Gemini as agent LLM:

export GOOGLE_API_KEY=YOUR_GEMINI_API_KEY

Start simulation

You can choose a basic LLM and start simulation in one line:

python main.py --model MODEL_NAME

We set gemini-pro for default LLM.

About ’procoder‘

Here we use the: https://github.com/dhh1995/PromptCoder.git this tool, please download after its installation.

Citation

If you find the code is valuable, please use this citation.

@article{zhang2024ai,
  title={When ai meets finance (stockagent): Large language model-based stock trading in simulated real-world environments},
  author={Zhang, Chong and Liu, Xinyi and Zhang, Zhongmou and Jin, Mingyu and Li, Lingyao and Wang, Zhenting and Hua, Wenyue and Shu, Dong and Zhu, Suiyuan and Jin, Xiaobo and others},
  journal={arXiv preprint arXiv:2407.18957},
  year={2024}
}

Core symbols most depended-on inside this repo

format
called by 41
log/custom_logger.py
get_price
called by 20
stock.py
run_api
called by 7
agent.py
_get_setting
called by 5
util.py
get_agent
called by 4
main.py
expand_experiment_seeds
called by 3
util.py
write_to_excel
called by 2
record.py
create_trade_record
called by 2
record.py

Shape

Method 37
Function 16
Class 9

Languages

Python100%

Modules by API surface

agent.py18 symbols
record.py16 symbols
util.py8 symbols
secretary.py7 symbols
stock.py6 symbols
log/custom_logger.py4 symbols
main.py3 symbols

For agents

$ claude mcp add Stockagent \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact