{"id":19224,"date":"2023-10-31T14:30:00","date_gmt":"2023-10-31T06:30:00","guid":{"rendered":"https:\/\/www.tejwin.com\/insight\/tejapi-llm\/"},"modified":"2023-11-17T14:25:20","modified_gmt":"2023-11-17T06:25:20","slug":"tejapi-llm","status":"publish","type":"insight","link":"https:\/\/www.tejwin.com\/en\/insight\/tejapi-llm\/","title":{"rendered":"Implementation of Deviation Rate Trading Strategy using TEJAPI and\u00a0LLM"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large caption-align-center\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/\/image-326-1024x768.png\" alt=\"LLM\" class=\"wp-image-18910\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/image-326-1024x768.png 1024w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-326-300x225.png 300w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-326-150x113.png 150w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-326-768x576.png 768w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-326-1536x1152.png 1536w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-326-2048x1536.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">photo by Mike Hindle on <a href=\"https:\/\/unsplash.com\/photos\/a-laptop-computer-with-a-mouse-and-keyboard-eJ7x1TYw6cI\" class=\"ek-link\" target=\"_blank\" rel=\"noopener\">Unsplash<\/a><\/figcaption><\/figure>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_81 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69f11e1f0f203\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"ez-toc-cssicon\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69f11e1f0f203\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tejapi-llm\/#Highlight\" >Highlight<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tejapi-llm\/#Preface\" >Preface<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tejapi-llm\/#Trading_Strategy\" >Trading Strategy<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tejapi-llm\/#Editing_Environment_and_Module_Requirements\" >Editing Environment and Module Requirements<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tejapi-llm\/#Database\" >Database<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tejapi-llm\/#Data_Import\" >Data Import<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tejapi-llm\/#Application_of_LangChain_based_on_LLM\" >Application of LangChain based on&nbsp;LLM<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tejapi-llm\/#Import_the_LangChain_module_to_leverage_its_functionality\" >Import the LangChain module to leverage its functionality<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tejapi-llm\/#Construct_the_gpt-35-turbo-0301_model\" >Construct the gpt-3.5-turbo-0301 model<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tejapi-llm\/#Import_stock_price_data\" >Import stock price&nbsp;data<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tejapi-llm\/#Interactive_market_analysis\" >Interactive market&nbsp;analysis<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tejapi-llm\/#Add_a_dialogue_box\" >Add a dialogue box<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tejapi-llm\/#Set_up_the_trading_strategy\" >Set up the trading&nbsp;strategy<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tejapi-llm\/#Generate_a_detailed_result_report\" >Generate a detailed result&nbsp;report<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tejapi-llm\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tejapi-llm\/#Source_Code\" >Source Code<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tejapi-llm\/#Extended_Reading\" >Extended Reading<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/www.tejwin.com\/en\/insight\/tejapi-llm\/#Related_Links\" >Related Links<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Highlight\"><\/span><strong>Highlight<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Article Difficulty\uff1a\u2605\u2606\u2606\u2606\u2606<\/li>\n\n\n\n<li>Using TEJAPI stock price database as the basis for LLM analysis.<\/li>\n\n\n\n<li>Providing prompts to the model in a question-and-answer format for automated trading analysis.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Preface\"><\/span><strong>Preface<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In today\u2019s complex financial landscape, investors and traders no longer rely on traditional research methods. Instead, they turn to highly intelligent data analysis tools to better understand stock market trends, identify investment opportunities, and make informed financial decisions. In this fast-paced financial environment, converting a vast amount of market data into actionable insights is crucial.<\/p>\n\n\n\n<p>In this context, the combination of LLM (Large Language Model) and TEJAPI provides powerful capabilities for textual analysis. LLM is a robust model based on natural language processing, capable of understanding and generating natural language to explore market news, company reports, social media comments, and other forms of textual data for a deeper understanding of market sentiment and events. TEJAPI, on the other hand, offers rich financial market data for precise analysis by LLM.<\/p>\n\n\n\n<p>This article explores how combining LLM and TEJAPI enhances the efficiency and accuracy of stock market analysis. It elaborates on how this integration aids in identifying market trends, analyzing stock performance, discovering key information in market news, and providing third-party investment insights. This combination not only benefits professional traders and investors but also provides ordinary investors with additional ways to grasp the market.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Trading_Strategy\"><\/span><strong>Trading Strategy<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Using the deviation rate as a trading strategy prompt<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>If the closing price is higher than the highest price three days ago, and the closing deviation rate is &gt;= 0, exit at the opening price on that day.<\/li>\n\n\n\n<li>If the previous day\u2019s closing price is lower than the lowest price three days ago, and the closing deviation rate is &lt;= 0, enter at the opening price on that day.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Editing_Environment_and_Module_Requirements\"><\/span><strong>Editing Environment and Module Requirements<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>This article uses the Mac operating system and Jupyter Notebook as the editor.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"db4c\"><span class=\"ez-toc-section\" id=\"Database\"><\/span>Database<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p id=\"232a\"><a href=\"https:\/\/api.tej.com.tw\/columndoc.html?subId=42\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"ek-link\">\u4e0a\u5e02(\u6ac3)\u672a\u8abf\u6574\u80a1\u50f9(\u65e5)(TWN\/APRCD)<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Data_Import\"><\/span><strong>Data Import<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Data period from May 20, 2023, to June 30, 2023, using TSMC (2330) as an example, fetching unadjusted opening and closing prices for analysis.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import tejapi\napi_key = 'your key'\ntejapi.ApiConfig.api_base=\"http:\/\/api.tej.com.tw\"\ntejapi.ApiConfig.api_key = api_key\ntejapi.ApiConfig.ignoretz = True\n\n\ndef get_stock_price(gte, lte, ticker):\n\n    stock = tejapi.get('TWN\/APRCD',\n                       mdate = {'gte':gte, 'lte':lte},\n                       coid = ticker,\n                       chinese_column_name = True\n    )\n    return stock<\/code><\/pre>\n\n\n\n<p>This time, the LLM used is OpenAI\u2019s gpt-3.5-turbo-0301. To begin, you need to input your personal API key, which can be obtained by applying on the official OpenAI website.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import os\nimport openai\nos.environ&#91;'OPENAI_API_KEY'] = 'your api key'\nopenai.api_key = os.environ&#91;'OPENAI_API_KEY']<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Application_of_LangChain_based_on_LLM\"><\/span><strong>Application of LangChain based on&nbsp;LLM<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>LangChain is an open-source Python library that provides the necessary tools to build AI applications based on Large Language Models (LLM). Developers can easily integrate with LLM to accomplish tasks such as text generation, question answering, translation, and dialogues. LLM itself lacks memory capabilities, but with LangChain technology, conversation records can be stored, offering a seamless conversational experience that resembles interacting with a human.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Import_the_LangChain_module_to_leverage_its_functionality\"><\/span><strong>Import the LangChain module to leverage its functionality<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>from langchain.chat_models import ChatOpenAI\nfrom langchain.chains import ConversationChain\nfrom langchain.memory import ConversationBufferWindowMemory<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Construct_the_gpt-35-turbo-0301_model\"><\/span><strong>Construct the gpt-3.5-turbo-0301 model<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>llm_model = 'gpt-3.5-turbo-0301'\nllm = ChatOpenAI(temperature=0.0, model=llm_model)\nmemory = ConversationBufferWindowMemory(k=5) # \u8a2d\u5b9a\u53ea\u4fdd\u7559\u4e94\u6b21\u5c0d\u8a71\u4ee5\u524d\u7684\u7d00\u9304\n\n# \u5efa\u7acb\u5c0d\u8a71\u93c8\nconversation = ConversationChain(\n    llm=llm, \n    memory = memory,\n    verbose=False\n)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Import_stock_price_data\"><\/span><strong>Import stock price&nbsp;data<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>gte = '2023-05-20'\nlte = '2023-06-30'\nstock = get_stock_price(gte, lte, '2330')\n\n# \u6642\u9593 \u958b\u6536\u76e4\u50f9\u683c\ndate_price = ''\nfor i in range(len(stock)):\n    date = stock&#91;'\u5e74\u6708\u65e5']&#91;i].strftime('%Y-%m-%d')\n#     opens = stock&#91;'\u958b\u76e4\u50f9(\u5143)']&#91;i]\n    closes = stock&#91;'\u6536\u76e4\u50f9(\u5143)']&#91;i]\n    open_price = stock&#91;'\u958b\u76e4\u50f9(\u5143)']&#91;i]\n    date_price += f'date: {date} '\n#     date_price += f'\u958b\u76e4\u50f9: {opens} '\n    date_price += (f'open: {open_price} ' + f'close: {closes}\\n')\n    \n\nprompt = f'\u5e6b\u6211\u5206\u6790\u5e02\u5834\u6ce2\u52d5\u8da8\u52e2\uff0c\u4ee5\u4e0b\u70ba\u80a1\u50f9\u8cc7\u6599\uff1a\\n'+ date_price + '\u5e6b\u6211\u7528\u7e41\u9ad4\u4e2d\u6587\u5206\u6790'\nprint(prompt)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Interactive_market_analysis\"><\/span><strong>Interactive market&nbsp;analysis<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Add_a_dialogue_box\"><\/span><strong>Add a dialogue box<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>print(conversation.predict(input=prompt))<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full caption-align-center\"><img decoding=\"async\" width=\"984\" height=\"57\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/Screen-Shot-2023-10-24-at-9.59.01-AM.png\" alt=\"\" class=\"wp-image-18939\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/Screen-Shot-2023-10-24-at-9.59.01-AM.png 984w, https:\/\/www.tejwin.com\/wp-content\/uploads\/Screen-Shot-2023-10-24-at-9.59.01-AM-300x17.png 300w, https:\/\/www.tejwin.com\/wp-content\/uploads\/Screen-Shot-2023-10-24-at-9.59.01-AM-150x9.png 150w, https:\/\/www.tejwin.com\/wp-content\/uploads\/Screen-Shot-2023-10-24-at-9.59.01-AM-768x44.png 768w\" sizes=\"(max-width: 984px) 100vw, 984px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>print(conversation.predict(input='\u7528\u4e09\u5929\u7684\u79fb\u52d5\u5e73\u5747\uff0c\u5e6b\u6211\u8a08\u7b97\u5f9e\u516d\u6708\u958b\u59cb\u6bcf\u6b21\u6536\u76e4\u7576\u5929\u7684\u4e56\u96e2\u7387\uff0c\u7522\u51fa\u8868\u683c'))<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full caption-align-center\"><img decoding=\"async\" width=\"348\" height=\"413\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/Screen-Shot-2023-10-24-at-10.29.52-AM.png\" alt=\"\" class=\"wp-image-18943\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/Screen-Shot-2023-10-24-at-10.29.52-AM.png 348w, https:\/\/www.tejwin.com\/wp-content\/uploads\/Screen-Shot-2023-10-24-at-10.29.52-AM-253x300.png 253w, https:\/\/www.tejwin.com\/wp-content\/uploads\/Screen-Shot-2023-10-24-at-10.29.52-AM-126x150.png 126w\" sizes=\"(max-width: 348px) 100vw, 348px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Set_up_the_trading_strategy\"><\/span><strong>Set up the trading&nbsp;strategy<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>print(conversation.predict(input='\u5e6b\u6211\u7528\u672c\u91d1\u5341\u842c\u5143\u5728\u516d\u6708\u7b2c\u4e00\u5929\u9032\u5834\uff0c\u524d\u4e00\u5929\u6536\u76e4\u50f9\u5927\u65bc\u56db\u5929\u524d\u6700\u9ad8\u50f9\uff0c\u4e14\u6536\u76e4\u4e56\u96e2\u7387&gt;=0\uff0c\u5247\u7576\u5929\u958b\u76e4\u50f9\u51fa\u5834\u3002\\\n                                  \u5728\u524d\u4e00\u5929\u6536\u76e4\u50f9\u5c0f\u65bc\u56db\u5929\u524d\u6700\u4f4e\u50f9\uff0c\u4e14\u6536\u76e4\u4e56\u96e2\u7387&lt;=0\uff0c\u5247\u7576\u5929\u958b\u76e4\u50f9\u9032\u5834\uff0c\u751f\u6210\u8868\u683c'))<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"872\" height=\"453\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/Screen-Shot-2023-10-24-at-10.31.16-AM.png\" alt=\"\" class=\"wp-image-18945\" style=\"aspect-ratio:1.924944812362031;width:765px;height:auto\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/Screen-Shot-2023-10-24-at-10.31.16-AM.png 872w, https:\/\/www.tejwin.com\/wp-content\/uploads\/Screen-Shot-2023-10-24-at-10.31.16-AM-300x156.png 300w, https:\/\/www.tejwin.com\/wp-content\/uploads\/Screen-Shot-2023-10-24-at-10.31.16-AM-150x78.png 150w, https:\/\/www.tejwin.com\/wp-content\/uploads\/Screen-Shot-2023-10-24-at-10.31.16-AM-768x399.png 768w\" sizes=\"(max-width: 872px) 100vw, 872px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Generate_a_detailed_result_report\"><\/span><strong>Generate a detailed result&nbsp;report<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>print(conversation.predict(input='\u5e6b\u6211\u7522\u51fa\u8a73\u7d30\u8868\u683c\u5831\u8868\uff0c\u5305\u542b\u7372\u5229\u91d1\u984d\u5927\u5c0f\u3001\u7e3d\u7372\u5229\u5927\u5c0f'))<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"908\" height=\"904\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/Screen-Shot-2023-10-24-at-10.32.24-AM.png\" alt=\"\" class=\"wp-image-18947\" style=\"aspect-ratio:1.0044247787610618;width:541px;height:auto\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/Screen-Shot-2023-10-24-at-10.32.24-AM.png 908w, https:\/\/www.tejwin.com\/wp-content\/uploads\/Screen-Shot-2023-10-24-at-10.32.24-AM-300x300.png 300w, https:\/\/www.tejwin.com\/wp-content\/uploads\/Screen-Shot-2023-10-24-at-10.32.24-AM-150x150.png 150w, https:\/\/www.tejwin.com\/wp-content\/uploads\/Screen-Shot-2023-10-24-at-10.32.24-AM-768x765.png 768w\" sizes=\"(max-width: 908px) 100vw, 908px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"21d9\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>This presentation introduces the use of LLM for a deviation rate trading strategy. In situations where the market exhibits oversold conditions (deviation rate &lt; 0) and the closing price is higher than the highest price over a certain period, it is judged that the stock price will gradually return to the moving average; hence, a long position is initiated. Conversely, when the stock price shows overbought conditions (deviation rate &gt; 0) and the closing price is lower than the lowest price over a certain period, indicating an overvaluation with a downward trend, the existing long position is closed. The rapid analytical conclusions are facilitated by the language model\u2019s computational and analytical capabilities.<\/p>\n\n\n\n<p>However, it is crucial to reiterate that the targets mentioned in this article are for illustrative purposes only and do not represent recommendations or advice on any financial products. Additionally, the outcomes generated by the language model do not guarantee absolute correctness and require further confirmation. Therefore, readers interested in topics such as strategy construction, performance backtesting, and research evidence are encouraged to explore solutions available in <a href=\"https:\/\/eshop.tej.com.tw\/E-Shop\/index\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"ek-link\">TEJ E Shop<\/a>, which provides comprehensive databases for various tests.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Source_Code\"><\/span><strong>Source Code<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/gist.github.com\/tej87681088\/aac61698c312a70fce778b903911464a\" class=\"ek-link\" target=\"_blank\" rel=\"noopener\">Github<\/a><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Extended_Reading\"><\/span>Extended Reading<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.tejwin.com\/en\/insight\/analysis-of-the-chip-concentration\/\" class=\"ek-link\">Analysis of the chip concentration<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/www.tejwin.com\/wp-admin\/post.php?post=17017&amp;action=edit&amp;lang=en\" class=\"ek-link\">Herding indicators<\/a><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Related_Links\"><\/span>Related Links<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/api.tej.com.tw\/index.html\" class=\"ek-link\" target=\"_blank\" rel=\"noopener\">TEJ API <\/a>HomePage<\/li>\n\n\n\n<li><a href=\"https:\/\/eshop.tej.com.tw\/E-Shop\/Edata_intro\" class=\"ek-link\" target=\"_blank\" rel=\"noopener\">TEJ E-Shop<\/a> Database Purchase<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>This article explores how the combination of LLM and TEJAPI enhances the efficiency and precision of stock market analysis. It elucidates how this integration contributes to identifying market trends, analyzing stock performance, discovering key information in market news, and providing third-party investment insights. This synergy not only aids professional traders and investors but also offers ordinary investors more ways to grasp the dynamics of the market.<\/p>\n","protected":false},"featured_media":18911,"template":"","tags":[2612,2371,3005,3007,2541],"insight-category":[690,50],"class_list":["post-19224","insight","type-insight","status-publish","has-post-thumbnail","hentry","tag-openai","tag-python","tag-tejapi-application","tag-tejapi-data-analysis","tag-2541","insight-category-data-analysis","insight-category-fintech"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/19224","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight"}],"about":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/types\/insight"}],"version-history":[{"count":0,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/19224\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media\/18911"}],"wp:attachment":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media?parent=19224"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/tags?post=19224"},{"taxonomy":"insight-category","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight-category?post=19224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}