47 lines
2.5 KiB
Python
Executable File
47 lines
2.5 KiB
Python
Executable File
import functools
|
|
import time
|
|
import json
|
|
|
|
|
|
def create_trader(llm, memory):
|
|
def trader_node(state, name):
|
|
company_name = state["company_of_interest"]
|
|
investment_plan = state["investment_plan"]
|
|
market_research_report = state["market_report"]
|
|
sentiment_report = state["sentiment_report"]
|
|
news_report = state["news_report"]
|
|
fundamentals_report = state["fundamentals_report"]
|
|
|
|
curr_situation = f"{market_research_report}\n\n{sentiment_report}\n\n{news_report}\n\n{fundamentals_report}"
|
|
past_memories = memory.get_memories(curr_situation, n_matches=2)
|
|
|
|
past_memory_str = ""
|
|
if past_memories:
|
|
for i, rec in enumerate(past_memories, 1):
|
|
past_memory_str += rec["recommendation"] + "\n\n"
|
|
else:
|
|
past_memory_str = "No past memories found."
|
|
|
|
context = {
|
|
"role": "user",
|
|
"content": f"Based on a comprehensive analysis by a team of analysts, here is a SHORT-TERM investment plan (1-2 week horizon) tailored for {company_name}. This plan incorporates insights from current technical market trends, near-term catalysts, and social media sentiment. Use this plan as a foundation for evaluating your next SHORT-TERM position decision.\n\nProposed Investment Plan: {investment_plan}\n\nLeverage these insights to make an informed and strategic position decision for the next 1-2 weeks.",
|
|
}
|
|
|
|
messages = [
|
|
{
|
|
"role": "system",
|
|
"content": f"""You are a trading agent analyzing market data to make SHORT-TERM position decisions (1-2 week horizon). Based on your analysis, provide a specific position recommendation: LONG (bullish, expecting price increase in 1-2 weeks), SHORT (bearish, expecting price decrease in 1-2 weeks), or HOLD (neutral, no position change). Focus on near-term catalysts, momentum, and what is likely to happen in the next 1-2 weeks. End with a firm decision and always conclude your response with 'FINAL POSITION RECOMMENDATION: **LONG/HOLD/SHORT**' to confirm your recommendation. Do not forget to utilize lessons from past decisions to learn from your mistakes. Here is some reflections from similar situations you traded in and the lessons learned: {past_memory_str}""",
|
|
},
|
|
context,
|
|
]
|
|
|
|
result = llm.invoke(messages)
|
|
|
|
return {
|
|
"messages": [result],
|
|
"trader_investment_plan": result.content,
|
|
"sender": name,
|
|
}
|
|
|
|
return functools.partial(trader_node, name="Trader")
|