-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrew.py
More file actions
79 lines (67 loc) · 3.34 KB
/
Copy pathcrew.py
File metadata and controls
79 lines (67 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from crewai import Agent, Task, Crew, Process
from langchain.llms import Ollama
from tools.yf_tech_analysis_tool import yf_tech_analysis
from tools.yf_fundamental_analysis_tool import yf_fundamental_analysis
from tools.sentiment_analysis_tool import sentiment_analysis
from tools.competitor_analysis_tool import competitor_analysis
from tools.risk_assessment_tool import risk_assessment
def create_crew(stock_symbol):
# Initialize Ollama LLM
llm = Ollama(model="tinyllama") # Make sure you have the llama2 model installed in Ollama
# Define Agents
researcher = Agent(
role='Stock Market Researcher',
goal='Gather and analyze comprehensive data about the stock',
backstory="You're an experienced stock market researcher with a keen eye for detail and a talent for uncovering hidden trends.",
tools=[yf_tech_analysis, yf_fundamental_analysis, competitor_analysis],
llm=llm
)
analyst = Agent(
role='Financial Analyst',
goal='Analyze the gathered data and provide investment insights',
backstory="You're a seasoned financial analyst known for your accurate predictions and ability to synthesize complex information.",
tools=[yf_tech_analysis, yf_fundamental_analysis, risk_assessment],
llm=llm
)
sentiment_analyst = Agent(
role='Sentiment Analyst',
goal='Analyze market sentiment and its potential impact on the stock',
backstory="You're an expert in behavioral finance and sentiment analysis, capable of gauging market emotions and their effects on stock performance.",
tools=[sentiment_analysis],
llm=llm
)
strategist = Agent(
role='Investment Strategist',
goal='Develop a comprehensive investment strategy based on all available data',
backstory="You're a renowned investment strategist known for creating tailored investment plans that balance risk and reward.",
tools=[],
llm=llm
)
# Define Tasks
research_task = Task(
description=f"Research {stock_symbol} using advanced technical and fundamental analysis tools. Provide a comprehensive summary of key metrics, including chart patterns, financial ratios, and competitor analysis.",
agent=researcher
)
sentiment_task = Task(
description=f"Analyze the market sentiment for {stock_symbol} using news and social media data. Evaluate how current sentiment might affect the stock's performance.",
agent=sentiment_analyst
)
analysis_task = Task(
description=f"Synthesize the research data and sentiment analysis for {stock_symbol}. Conduct a thorough risk assessment and provide a detailed analysis of the stock's potential.",
agent=analyst
)
strategy_task = Task(
description=f"Based on all the gathered information about {stock_symbol}, develop a comprehensive investment strategy. Consider various scenarios and provide actionable recommendations for different investor profiles.",
agent=strategist
)
# Create Crew
crew = Crew(
agents=[researcher, sentiment_analyst, analyst, strategist],
tasks=[research_task, sentiment_task, analysis_task, strategy_task],
process=Process.sequential
)
return crew
def run_analysis(stock_symbol):
crew = create_crew(stock_symbol)
result = crew.kickoff()
return result