{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# FinGPT-Forecaster Re-implemented with FinRobot" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this demo, we set up an agent to emulate the behavior of model in the fingpt-forecaster project with AutoGen, which takes a company's ticker symbol, recent basic financials and market news as input and predict its stock movements.\n", "\n", "For detail of the original project, check out [FinGPT-Forecaster](https://github.com/AI4Finance-Foundation/FinGPT/tree/master/fingpt/FinGPT_Forecaster)! đŸ”„[Demo](https://huggingface.co/spaces/FinGPT/FinGPT-Forecaster), [Medium Blog](https://medium.datadriveninvestor.com/introducing-fingpt-forecaster-the-future-of-robo-advisory-services-50add34e3d3c) & [Model](https://huggingface.co/FinGPT/fingpt-forecaster_dow30_llama2-7b_lora) on HuggingfaceđŸ€—!\n", "\n", "This is a default bot, for more configurable demo, see [advanced tutorial](../tutorials_advanced/agent_fingpt_forecaster.ipynb)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import autogen\n", "from finrobot.utils import get_current_date, register_keys_from_json\n", "from finrobot.agents.workflow import SingleAssistant" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "After importing all the necessary packages and functions, we instantiate a SingleAssistant workflow \"Market_Analyst\".\n", "We also need the config for OpenAI & Finnhub here. \n", "- for openai configuration, rename OAI_CONFIG_LIST_sample to OAI_CONFIG_LIST and replace the api keys\n", "- for finnhub configuration, rename config_api_keys_sample to config_api_keys and replace the api keys" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "# Read OpenAI API keys from a JSON file\n", "llm_config = {\n", " \"config_list\": autogen.config_list_from_json(\n", " \"../OAI_CONFIG_LIST\",\n", " filter_dict={\"model\": [\"gpt-4-0125-preview\"]},\n", " ),\n", " \"timeout\": 120,\n", " \"temperature\": 0,\n", "}\n", "\n", "# Register FINNHUB API keys\n", "register_keys_from_json(\"../config_api_keys\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Define the assistant, and simply start chatting!" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\u001b[33mUser_Proxy\u001b[0m (to Market_Analyst):\n", "\n", "Use all the tools provided to retrieve information available for APPLE upon 2024-05-23. Analyze the positive developments and potential concerns of APPLE with 2-4 most important factors respectively and keep them concise. Most factors should be inferred from company related news. Then make a rough prediction (e.g. up/down by 2-3%) of the APPLE stock price movement for next week. Provide a summary analysis to support your prediction.\n", "\n", "--------------------------------------------------------------------------------\n", "\u001b[33mMarket_Analyst\u001b[0m (to User_Proxy):\n", "\n", "\u001b[32m***** Suggested tool call (call_5xXm48aC8GmhlHfygA8zWO7Z): get_company_profile *****\u001b[0m\n", "Arguments: \n", "{\"symbol\": \"AAPL\"}\n", "\u001b[32m************************************************************************************\u001b[0m\n", "\u001b[32m***** Suggested tool call (call_BGHV5ASEpZCGcG3z5K49TlEW): get_company_news *****\u001b[0m\n", "Arguments: \n", "{\"symbol\": \"AAPL\", \"start_date\": \"2024-05-16\", \"end_date\": \"2024-05-23\"}\n", "\u001b[32m*********************************************************************************\u001b[0m\n", "\u001b[32m***** Suggested tool call (call_YfjiPBOstzubJdzdCyCnGhfv): get_financial_basics *****\u001b[0m\n", "Arguments: \n", "{\"symbol\": \"AAPL\"}\n", "\u001b[32m*************************************************************************************\u001b[0m\n", "\u001b[32m***** Suggested tool call (call_GPCnZaJrmUixSgPp5x9rgHs0): get_stock_data *****\u001b[0m\n", "Arguments: \n", "{\"symbol\": \"AAPL\", \"start_date\": \"2024-05-16\", \"end_date\": \"2024-05-23\"}\n", "\u001b[32m*******************************************************************************\u001b[0m\n", "\n", "--------------------------------------------------------------------------------\n", "\u001b[35m\n", ">>>>>>>> EXECUTING FUNCTION get_company_profile...\u001b[0m\n", "Finnhub client initialized\n", "\u001b[35m\n", ">>>>>>>> EXECUTING FUNCTION get_company_news...\u001b[0m\n", "Finnhub client initialized\n", "\u001b[35m\n", ">>>>>>>> EXECUTING FUNCTION get_financial_basics...\u001b[0m\n", "Finnhub client initialized\n", "\u001b[35m\n", ">>>>>>>> EXECUTING FUNCTION get_stock_data...\u001b[0m\n", "\u001b[33mUser_Proxy\u001b[0m (to Market_Analyst):\n", "\n", "\u001b[33mUser_Proxy\u001b[0m (to Market_Analyst):\n", "\n", "\u001b[32m***** Response from calling tool (call_5xXm48aC8GmhlHfygA8zWO7Z) *****\u001b[0m\n", "[Company Introduction]:\n", "\n", "Apple Inc is a leading entity in the Technology sector. Incorporated and publicly traded since 1980-12-12, the company has established its reputation as one of the key players in the market. As of today, Apple Inc has a market capitalization of 2927276.17 in USD, with 15334.08 shares outstanding.\n", "\n", "Apple Inc operates primarily in the US, trading under the ticker AAPL on the NASDAQ NMS - GLOBAL MARKET. As a dominant force in the Technology space, the company continues to innovate and drive progress within the industry.\n", "\u001b[32m**********************************************************************\u001b[0m\n", "\n", "--------------------------------------------------------------------------------\n", "\u001b[33mUser_Proxy\u001b[0m (to Market_Analyst):\n", "\n", "\u001b[32m***** Response from calling tool (call_BGHV5ASEpZCGcG3z5K49TlEW) *****\u001b[0m\n", " date headline summary\n", "0 20240112064122 The Biggest Bitcoin ETF Threat No One Is Talking About A majority of bitcoin ETF issuers have chosen Coinbase as a custodian, which is a concentration of risk. Even if that is the safest option, new cybersecurity standards are needed for making crypto custody truly safe.\n", "1 20240517093800 Harbor Capital Appreciation Fund's 1st-Quarter Commentary: A Review Looking for stock market analysis and research with proves results? Zacks.com offers in-depth financial research with over 30years of proven results.\n", "2 20240517173300 Market Clubhouse Morning Memo - May 17th, 2024 (Trade Strategy For SPY, QQQ, AAPL, MSFT, NVDA, GOOGL, META And TSLA) Looking for stock market analysis and research with proves results? Zacks.com offers in-depth financial research with over 30years of proven results.\n", "3 20240518143623 Building A $50,000 Dividend Portfolio With 3 ETFs And 3 High Dividend Yield Stocks Check here to learn how to build a diversified dividend portfolio with ETFs and single companies, offering stable income and attractive total returns for investors.\n", "4 20240519210000 Facebook Parent’s Plan to Win AI Race: Give Its Tech Away Free Meta Platforms CEO Mark Zuckerberg has trained his “Eye of Sauron” on its artificial-intelligence strategy, which comes with risks.\n", "5 20240520183000 Forget Apple: This Other Buyback Stock Soared 28% Over the Last Year, and Could Be Headed Even Higher Apple made headlines following its announced $110 billion share buyback, but another company also buying back stock may be the better opportunity.\n", "6 20240521090900 Microsoft's latest tools turn anyone into software developer: Build 2024 Looking for stock market analysis and research with proves results? Zacks.com offers in-depth financial research with over 30years of proven results.\n", "7 20240521105000 3 Stocks That Could Be the Next Apple, Amazon, or Google by 2034 Looking for stock market analysis and research with proves results? Zacks.com offers in-depth financial research with over 30years of proven results.\n", "8 20240522090000 ‘Hold Music’ Is Annoying. It Doesn’t Have to Be That Way. Companies really don’t give that much thought to what we listen to as we wait. They should start paying more attention.\n", "9 20240522170600 Here Are All 44 Stocks Warren Buffett Holds for Berkshire Hathaway's $378 Billion Portfolio Despite holding stakes in close to four-dozen stocks, 82% of Berkshire's $378 billion of invested assets is concentrated in eight core companies.\n", "\u001b[32m**********************************************************************\u001b[0m\n", "\n", "--------------------------------------------------------------------------------\n", "\u001b[33mUser_Proxy\u001b[0m (to Market_Analyst):\n", "\n", "\u001b[32m***** Response from calling tool (call_YfjiPBOstzubJdzdCyCnGhfv) *****\u001b[0m\n", "{\n", " \"10DayAverageTradingVolume\": 17.2618,\n", " \"13WeekPriceReturnDaily\": 4.706,\n", " \"26WeekPriceReturnDaily\": 1.5372,\n", " \"3MonthADReturnStd\": 24.229355,\n", " \"3MonthAverageTradingVolume\": 20.63892,\n", " \"52WeekHigh\": 199.615,\n", " \"52WeekHighDate\": \"2023-12-14\",\n", " \"52WeekLow\": 164.08,\n", " \"52WeekLowDate\": \"2024-04-19\",\n", " \"52WeekPriceReturnDaily\": 11.273,\n", " \"5DayPriceReturnDaily\": 0.5584,\n", " \"assetTurnoverAnnual\": 1.0871,\n", " \"assetTurnoverTTM\": 1.1073,\n", " \"beta\": 1.1417378,\n", " \"bookValuePerShareAnnual\": 3.9965,\n", " \"bookValuePerShareQuarterly\": 4.8374,\n", " \"bookValueShareGrowth5Y\": -6.64,\n", " \"capexCagr5Y\": -3.82,\n", " \"cashFlowPerShareAnnual\": 6.4041,\n", " \"cashFlowPerShareQuarterly\": 6.645,\n", " \"cashFlowPerShareTTM\": 6.86253,\n", " \"cashPerSharePerShareAnnual\": 3.9585,\n", " \"cashPerSharePerShareQuarterly\": 4.3781,\n", " \"currentDividendYieldTTM\": 0.5173,\n", " \"currentEv/freeCashFlowAnnual\": 30.1134,\n", " \"currentEv/freeCashFlowTTM\": 29.4235,\n", " \"currentRatioAnnual\": 0.988,\n", " \"currentRatioQuarterly\": 1.0371,\n", " \"dividendGrowthRate5Y\": 6.58,\n", " \"dividendPerShareAnnual\": 0.9542,\n", " \"dividendPerShareTTM\": 0.975,\n", " \"dividendYieldIndicatedAnnual\": 0.52383447,\n", " \"ebitdPerShareAnnual\": 7.9328,\n", " \"ebitdPerShareTTM\": 8.2919,\n", " \"ebitdaCagr5Y\": 9.04,\n", " \"ebitdaInterimCagr5Y\": 13.39,\n", " \"enterpriseValue\": 2998809.5,\n", " \"epsAnnual\": 6.1341,\n", " \"epsBasicExclExtraItemsAnnual\": 6.1341,\n", " \"epsBasicExclExtraItemsTTM\": 6.4308,\n", " \"epsExclExtraItemsAnnual\": 6.1341,\n", " \"epsExclExtraItemsTTM\": 6.4308,\n", " \"epsGrowth3Y\": 23.26,\n", " \"epsGrowth5Y\": 15.56,\n", " \"epsGrowthQuarterlyYoy\": 0.25,\n", " \"epsGrowthTTMYoy\": 9.26,\n", " \"epsInclExtraItemsAnnual\": 6.1341,\n", " \"epsInclExtraItemsTTM\": 6.4308,\n", " \"epsNormalizedAnnual\": 6.1341,\n", " \"epsTTM\": 6.4308,\n", " \"focfCagr5Y\": 9.2,\n", " \"grossMargin5Y\": 41.05,\n", " \"grossMarginAnnual\": 44.13,\n", " \"grossMarginTTM\": 46.58,\n", " \"inventoryTurnoverAnnual\": 37.9777,\n", " \"inventoryTurnoverTTM\": 30.2839,\n", " \"longTermDebt/equityAnnual\": 1.5332,\n", " \"longTermDebt/equityQuarterly\": 1.2377,\n", " \"marketCapitalization\": 2926914.5,\n", " \"monthToDatePriceReturnDaily\": 12.0766,\n", " \"netIncomeEmployeeAnnual\": 0.6025,\n", " \"netIncomeEmployeeTTM\": 0.6235,\n", " \"netInterestCoverageAnnual\": 622.5082,\n", " \"netInterestCoverageTTM\": 622.5082,\n", " \"netMarginGrowth5Y\": 2.46,\n", " \"netProfitMargin5Y\": 23.73,\n", " \"netProfitMarginAnnual\": 25.31,\n", " \"netProfitMarginTTM\": 26.04,\n", " \"operatingMargin5Y\": 27.72,\n", " \"operatingMarginAnnual\": 29.82,\n", " \"operatingMarginTTM\": 30.74,\n", " \"payoutRatioAnnual\": 15.49,\n", " \"payoutRatioTTM\": 0.1508,\n", " \"pbAnnual\": 43.4754,\n", " \"pbQuarterly\": 35.6899,\n", " \"pcfShareAnnual\": 26.4776,\n", " \"pcfShareTTM\": 26.4728,\n", " \"peAnnual\": 30.1759,\n", " \"peBasicExclExtraTTM\": 29.1557,\n", " \"peExclExtraAnnual\": 30.96975,\n", " \"peExclExtraTTM\": 29.1557,\n", " \"peInclExtraTTM\": 29.1557,\n", " \"peNormalizedAnnual\": 30.1759,\n", " \"peTTM\": 26.3771,\n", " \"pfcfShareAnnual\": 29.3914,\n", " \"pfcfShareTTM\": 28.718,\n", " \"pretaxMargin5Y\": 27.89,\n", " \"pretaxMarginAnnual\": 29.67,\n", " \"pretaxMarginTTM\": 30.92,\n", " \"priceRelativeToS&P50013Week\": -1.8546,\n", " \"priceRelativeToS&P50026Week\": -16.2866,\n", " \"priceRelativeToS&P5004Week\": 7.1353,\n", " \"priceRelativeToS&P50052Week\": -16.6774,\n", " \"priceRelativeToS&P500Ytd\": -12.317,\n", " \"psAnnual\": 7.6364,\n", " \"psTTM\": 6.9387,\n", " \"ptbvAnnual\": 4.8643,\n", " \"ptbvQuarterly\": 6.4066,\n", " \"quickRatioAnnual\": 0.9444,\n", " \"quickRatioQuarterly\": 0.9868,\n", " \"receivablesTurnoverAnnual\": 13.2873,\n", " \"receivablesTurnoverTTM\": 19.1901,\n", " \"revenueEmployeeAnnual\": 2.3807,\n", " \"revenueEmployeeTTM\": 2.3703,\n", " \"revenueGrowth3Y\": 11.77,\n", " \"revenueGrowth5Y\": 7.61,\n", " \"revenueGrowthQuarterlyYoy\": -4.31,\n", " \"revenueGrowthTTMYoy\": -0.9,\n", " \"revenuePerShareAnnual\": 24.2393,\n", " \"revenuePerShareTTM\": 24.677,\n", " \"revenueShareGrowth5Y\": 12.79,\n", " \"roa5Y\": 23.36,\n", " \"roaRfy\": 27.51,\n", " \"roaTTM\": 0.2913,\n", " \"roe5Y\": 130.41,\n", " \"roeRfy\": 156.07999999999998,\n", " \"roeTTM\": 1.4833,\n", " \"roi5Y\": 44.8,\n", " \"roiAnnual\": 55.66,\n", " \"roiTTM\": 57.06,\n", " \"tangibleBookValuePerShareAnnual\": 5.8583,\n", " \"tangibleBookValuePerShareQuarterly\": 6.7916,\n", " \"tbvCagr5Y\": 11.34,\n", " \"totalDebt/totalEquityAnnual\": 1.804,\n", " \"totalDebt/totalEquityQuarterly\": 1.4097,\n", " \"yearToDatePriceReturnDaily\": -0.8466,\n", " \"bookValue\": 74194,\n", " \"cashRatio\": 0.2640483920466476,\n", " \"currentRatio\": 1.0371,\n", " \"ebitPerShare\": 1.8041,\n", " \"eps\": 1.5284,\n", " \"ev\": 2719868.8,\n", " \"fcfMargin\": 0.228,\n", " \"fcfPerShareTTM\": 6.645,\n", " \"grossMargin\": 0.4658,\n", " \"longtermDebtTotalAsset\": 0.2722,\n", " \"longtermDebtTotalCapital\": 0.5136,\n", " \"longtermDebtTotalEquity\": 1.2377,\n", " \"netDebtToTotalCapital\": 0.4021,\n", " \"netDebtToTotalEquity\": 0.969,\n", " \"netMargin\": 0.2604,\n", " \"operatingMargin\": 0.3074,\n", " \"pb\": 35.6899,\n", " \"pfcfTTM\": 25.9812,\n", " \"pretaxMargin\": 0.3092,\n", " \"ptbv\": 6.4066,\n", " \"quickRatio\": 0.9868,\n", " \"roicTTM\": 0.5706,\n", " \"rotcTTM\": 0.6721,\n", " \"salesPerShare\": 5.8684,\n", " \"sgaToSale\": 0.5342,\n", " \"tangibleBookValue\": 138050,\n", " \"totalDebtToEquity\": 1.4097,\n", " \"totalDebtToTotalAsset\": 0.31,\n", " \"totalDebtToTotalCapital\": 0.585,\n", " \"totalRatio\": 1.2819\n", "}\n", "\u001b[32m**********************************************************************\u001b[0m\n", "\n", "--------------------------------------------------------------------------------\n", "\u001b[33mUser_Proxy\u001b[0m (to Market_Analyst):\n", "\n", "\u001b[32m***** Response from calling tool (call_GPCnZaJrmUixSgPp5x9rgHs0) *****\u001b[0m\n", " Open High Low Close Volume Dividends Stock Splits\n", "Date \n", "2024-05-16 00:00:00-04:00 190.470001 191.100006 189.660004 189.839996 52845200 0.0 0.0\n", "2024-05-17 00:00:00-04:00 189.509995 190.809998 189.179993 189.869995 41282900 0.0 0.0\n", "2024-05-20 00:00:00-04:00 189.330002 191.919998 189.009995 191.039993 44361300 0.0 0.0\n", "2024-05-21 00:00:00-04:00 191.089996 192.729996 190.919998 192.350006 42309400 0.0 0.0\n", "2024-05-22 00:00:00-04:00 192.270004 192.820007 190.270004 190.899994 34581900 0.0 0.0\n", "\u001b[32m**********************************************************************\u001b[0m\n", "\n", "--------------------------------------------------------------------------------\n", "\u001b[33mMarket_Analyst\u001b[0m (to User_Proxy):\n", "\n", "### Positive Developments for Apple\n", "\n", "1. **Share Buyback Announcement**: Apple's announcement of a $110 billion share buyback program is a strong signal of confidence from the management in the company's future prospects. This move is likely to support the stock price by reducing the number of shares outstanding, potentially increasing earnings per share (EPS) over time.\n", "\n", "2. **Financial Performance and Stability**: Apple's financial basics show a robust picture with a gross margin of 46.58% and an operating margin of 30.74%, indicating efficient operations and strong profitability. The company's EPS growth over the past year (9.26%) and a dividend growth rate of 6.58% over the past five years reflect its ability to generate and return value to shareholders.\n", "\n", "### Potential Concerns\n", "\n", "1. **Market Competition**: The news highlights other companies and technologies potentially challenging Apple's market position. For instance, Microsoft's development of tools that turn anyone into a software developer could democratize app development, potentially impacting Apple's ecosystem advantage.\n", "\n", "2. **Investor Sentiment and Market Dynamics**: The comparison of Apple's stock to another company that soared 28% over the last year following a buyback suggests that investors might be looking for quicker gains elsewhere. This could lead to volatility in Apple's stock price if investors perceive better opportunities in other stocks.\n", "\n", "### Stock Price Movement Prediction for Next Week\n", "\n", "Given the recent share buyback announcement and Apple's strong financial performance, there is a positive outlook for the stock. However, the broader market dynamics and competition could introduce some volatility. Considering the 5-day price return of 0.5584% and the overall positive sentiment, **Apple's stock price is likely to experience a slight uptick next week, potentially increasing by 1-2%**. This prediction is based on the company's solid financials, strategic share buyback, and the general market conditions reflected in the recent stock performance.\n", "\n", "### Summary Analysis\n", "\n", "Apple's recent share buyback announcement and its strong financial metrics, including high gross and operating margins, suggest a robust outlook for the company. Despite potential concerns regarding market competition and investor sentiment towards quicker gains, Apple's fundamental strength and strategic moves position it well for short-term growth. The slight increase in stock price over the past week, coupled with the company's overall performance, supports a cautiously optimistic prediction for the stock's movement in the coming week.\n", "\n", "--------------------------------------------------------------------------------\n", "\u001b[33mUser_Proxy\u001b[0m (to Market_Analyst):\n", "\n", "\n", "\n", "--------------------------------------------------------------------------------\n", "\u001b[33mMarket_Analyst\u001b[0m (to User_Proxy):\n", "\n", "TERMINATE\n", "\n", "--------------------------------------------------------------------------------\n" ] } ], "source": [ "company = \"APPLE\"\n", "\n", "assitant = SingleAssistant(\n", " \"Market_Analyst\",\n", " llm_config,\n", " # set to \"ALWAYS\" if you want to chat instead of simply receiving the prediciton\n", " human_input_mode=\"NEVER\",\n", ")\n", "assitant.chat(\n", " f\"Use all the tools provided to retrieve information available for {company} upon {get_current_date()}. Analyze the positive developments and potential concerns of {company} \"\n", " \"with 2-4 most important factors respectively and keep them concise. Most factors should be inferred from company related news. \"\n", " f\"Then make a rough prediction (e.g. up/down by 2-3%) of the {company} stock price movement for next week. Provide a summary analysis to support your prediction.\"\n", ")" ] } ], "metadata": { "kernelspec": { "display_name": "finrobot", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.14" } }, "nbformat": 4, "nbformat_minor": 2 }