Skip to content

Commit

Permalink
ADDED: Investment risk analyst agent
Browse files Browse the repository at this point in the history
  • Loading branch information
AquibPy committed Jun 24, 2024
1 parent d303418 commit c425c7a
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 0 deletions.
Empty file.
65 changes: 65 additions & 0 deletions investment_risk_analyst_agent/agents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from crewai import Agent
from investment_risk_analyst_agent.tools import search_tool,scrape_tool
from dotenv import load_dotenv
load_dotenv()
from langchain_google_genai import ChatGoogleGenerativeAI
import os
import settings

llm=ChatGoogleGenerativeAI(model=settings.GEMINI_FLASH,
verbose=True,
temperature=0.5,
google_api_key=os.getenv("GOOGLE_API_KEY"))

data_analyst_agent = Agent(
role="Data Analyst",
goal="Monitor and analyze market data in real-time to identify trends and predict market movements.",
backstory="""
Specializing in financial markets, this agent employs statistical modeling and machine learning techniques to provide critical insights.
Renowned for its proficiency in data analysis, the Data Analyst Agent serves as a pivotal resource for informing trading decisions.
""",
verbose=True,
allow_delegation=True,
tools=[scrape_tool, search_tool],
llm = llm
)

trading_strategy_agent = Agent(
role="Trading Strategy Developer",
goal="Develop and test various trading strategies leveraging insights from the Data Analyst Agent.",
backstory="""
Possessing a deep understanding of financial markets and quantitative analysis, this agent formulates and optimizes trading strategies.
It assesses the performance of diverse approaches to identify the most profitable and risk-averse options.
""",
verbose=True,
allow_delegation=True,
tools=[scrape_tool, search_tool],
llm = llm
)

execution_agent = Agent(
role="Trade Advisor",
goal="Recommend optimal trade execution strategies based on approved trading plans.",
backstory="""
Specializing in the analysis of timing, price, and logistical details of potential trades,
this agent evaluates these factors to provide well-founded recommendations.
Its expertise ensures that trades are executed efficiently and in alignment with the overall strategy.""",
verbose=True,
allow_delegation=True,
tools=[scrape_tool, search_tool],
llm = llm
)

risk_management_agent = Agent(
role="Risk Advisor",
goal="Evaluate and provide insights on the risks associated with potential trading activities.",
backstory="""
With extensive expertise in risk assessment models and market dynamics,
this agent thoroughly examines the potential risks of proposed trades.
It delivers comprehensive analyses of risk exposure and recommends safeguards to ensure that trading activities align with the firm's risk tolerance.
""",
verbose=True,
allow_delegation=True,
tools=[scrape_tool, search_tool],
llm = llm
)
44 changes: 44 additions & 0 deletions investment_risk_analyst_agent/crew.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from crewai import Crew, Process
from dotenv import load_dotenv
load_dotenv()
from langchain_google_genai import ChatGoogleGenerativeAI
# import settings
import os
from investment_risk_analyst_agent.agents import data_analyst_agent,trading_strategy_agent,execution_agent,risk_management_agent
from investment_risk_analyst_agent.tasks import data_analysis_task,strategy_development_task,risk_assessment_task,execution_planning_task

llm=ChatGoogleGenerativeAI(model="gemini-1.5-flash",
verbose=True,
temperature=0.7,
google_api_key=os.getenv("GOOGLE_API_KEY"))


financial_trading_crew = Crew(
agents=[data_analyst_agent,
trading_strategy_agent,
execution_agent,
risk_management_agent],

tasks=[data_analysis_task,
strategy_development_task,
execution_planning_task,
risk_assessment_task],

manager_llm=llm,
process=Process.hierarchical,
verbose=True
)

def run_crew(input_data):
result = financial_trading_crew.kickoff(inputs=input_data)
return result

if __name__=='__main__':
financial_trading_inputs ={
'stock_selection': 'AAPL',
'initial_capital': '100000',
'risk_tolerance': 'Medium',
'trading_strategy_preference': 'Day Trading',
'news_impact_consideration': True
}
print(run_crew(input_data=financial_trading_inputs))
50 changes: 50 additions & 0 deletions investment_risk_analyst_agent/tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from crewai import Task
from investment_risk_analyst_agent.tools import search_tool,scrape_tool
from investment_risk_analyst_agent.agents import data_analyst_agent,trading_strategy_agent,execution_agent,risk_management_agent

data_analysis_task = Task(
description=(
"Continuously monitor and analyze market data for the selected stock ({stock_selection}). "
"Employ statistical modeling and machine learning techniques to identify trends and predict market movements."
),
expected_output=(
"Generate insights and alerts regarding significant market opportunities or threats for {stock_selection}."
),
agent=data_analyst_agent,
tools=[scrape_tool, search_tool],
)

strategy_development_task = Task(
description=(
"Develop and refine trading strategies based on insights from the Data Analyst and user-defined risk tolerance ({risk_tolerance}). "
"Incorporate trading preferences ({trading_strategy_preference}) in the strategy development process."
),
expected_output=(
"A set of potential trading strategies for {stock_selection} that align with the user's risk tolerance."
),
agent=trading_strategy_agent,
tools=[scrape_tool, search_tool],
)

execution_planning_task = Task(
description=(
"Analyze approved trading strategies to determine the optimal execution methods for {stock_selection}, "
"considering current market conditions and pricing strategies."
),
expected_output=(
"Comprehensive execution plans detailing how and when to execute trades for {stock_selection}."
),
agent=execution_agent,
)

risk_assessment_task = Task(
description=(
"Evaluate the risks associated with the proposed trading strategies and execution plans for {stock_selection}. "
"Provide a detailed analysis of potential risks and recommend mitigation strategies."
),
expected_output=(
"A comprehensive risk analysis report detailing potential risks and mitigation recommendations for {stock_selection}."
),
agent=risk_management_agent,
tools=[scrape_tool, search_tool],
)
9 changes: 9 additions & 0 deletions investment_risk_analyst_agent/tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from crewai_tools import ScrapeWebsiteTool, SerperDevTool
import os
from dotenv import load_dotenv
load_dotenv()

os.environ['SERPER_API_KEY'] = os.getenv('SERPER_API_KEY')

search_tool = SerperDevTool()
scrape_tool = ScrapeWebsiteTool()

0 comments on commit c425c7a

Please sign in to comment.