adds get_stock_price tool
Browse files2 unmodified lines34567891011121314151617181920212232 unmodified lines555657585960612 unmodified linesimport requestsimport pytzimport yamlfrom tools.final_answer import FinalAnswerToolfrom Gradio_UI import GradioUI# Below is an example of a tool that does nothing. Amaze us with your creativity !@tooldef my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type#Keep this format for the description / args / args description but feel free to modify the tool"""A tool that does nothing yetArgs:arg1: the first argumentarg2: the second argument"""return "What magic will you build ?"@tooldef get_current_time_in_timezone(timezone: str) -> str:32 unmodified linesagent = CodeAgent(model=model,tools=[final_answer], ## add your tools here (don't remove final answer)max_steps=6,verbosity_level=1,grammar=None,2 unmodified lines3456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888932 unmodified lines1221231241251261271282 unmodified linesimport requestsimport pytzimport yamlimport yfinance as yffrom ta.momentum import RSIIndicator, StochasticOscillatorfrom ta.trend import MACDfrom ta.volume import volume_weighted_average_pricefrom tools.final_answer import FinalAnswerToolfrom Gradio_UI import GradioUI# # Below is an example of a tool that does nothing. Amaze us with your creativity !# @tool# def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type# #Keep this format for the description / args / args description but feel free to modify the tool# """A tool that does nothing yet# Args:# arg1: the first argument# arg2: the second argument# """# return "What magic will you build ?"@tooldef get_stock_price(ticker: str) -> Union[Dict, str]:"""A tool that fetches the historical stock price data and technical indicators for a given ticker.Args:ticker: A string representing a stocke ticker name (e.g AAPL)"""try:data = yf.download(ticker,start=dt.datetime.now() - dt.timedelta(weeks=24 * 3),end=dt.datetime.now(),interval="1wk",)df = data.copy()data.reset_index(inplace=True)data.Date = data.Date.astype(str)indicators = {}rsi_series = RSIIndicator(df["Close"], window=14).rsi().iloc[-12:]indicators["RSI"] = {date.strftime("%Y-%m-%d"): int(value)for date, value in rsi_series.dropna().to_dict().items()}stochastic_series = (StochasticOscillator(df["High"], df["Low"], df["Close"], window=14).stoch().iloc[-12:])indicators["Stochastic Oscillator"] = {date.strftime("%Y-%m-%d"): int(value)for date, value in stochastic_series.dropna().to_dict().items()}macd = MACD(df["Close"])macd_series = macd.macd().iloc[-12:]indicators["MACD"] = {date.strftime("%Y-%m-%d"): int(value)for date, value in macd_series.to_dict().items()}macd_signal_series = macd.macd_signal().iloc[-12:]indicators["MACD Signal"] = {date.strftime("%Y-%m-%d"): int(value)for date, value in macd_signal_series.to_dict().items()}vwap_series = volume_weighted_average_price(df["High"], df["Low"], df["Close"], df["Volume"]).iloc[-12:]indicators["vwap"] = {date.strftime("%Y-%m-%d"): int(value)for date, value in vwap_series.to_dict().items()}return {"stock_price": data.to_dict(orient="records"), "indicators": indicators}except Exception as e:return f"Error fetching price data: {str(e)}"@tooldef get_current_time_in_timezone(timezone: str) -> str:32 unmodified linesagent = CodeAgent(model=model,tools=[final_answer, get_stock_price], ## add your tools here (don't remove final answer)max_steps=6,verbosity_level=1,grammar=None,
app.py+75-8