{"id":14364,"date":"2023-07-18T14:00:00","date_gmt":"2023-07-18T06:00:00","guid":{"rendered":"https:\/\/www.tejwin.com\/?post_type=insight&#038;p=14364"},"modified":"2026-03-03T13:17:37","modified_gmt":"2026-03-03T05:17:37","slug":"how-to-avoid-common-mistakes-during-trading-loss-avoidance","status":"publish","type":"insight","link":"https:\/\/www.tejwin.com\/en\/insight\/how-to-avoid-common-mistakes-during-trading-loss-avoidance\/","title":{"rendered":"How to avoid common mistakes during trading &#8211; Loss Avoidance"},"content":{"rendered":"\n<figure class=\"wp-block-image aligncenter size-full caption-align-center\"><img fetchpriority=\"high\" decoding=\"async\" width=\"1024\" height=\"576\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/image-203.png\" alt=\"How to avoid common mistakes during trading - Loss Avoidance\" class=\"wp-image-14365\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/image-203.png 1024w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-203-300x169.png 300w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-203-150x84.png 150w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-203-768x432.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">photo by <a href=\"https:\/\/unsplash.com\/@jstrippa\" class=\"ek-link\" target=\"_blank\" rel=\"noopener\">James Harrison on 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-69f7be2ab2285\" 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-69f7be2ab2285\"  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\/how-to-avoid-common-mistakes-during-trading-loss-avoidance\/#Highlights\" >Highlights<\/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\/how-to-avoid-common-mistakes-during-trading-loss-avoidance\/#Introduction\" >Introduction<\/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\/how-to-avoid-common-mistakes-during-trading-loss-avoidance\/#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-4\" href=\"https:\/\/www.tejwin.com\/en\/insight\/how-to-avoid-common-mistakes-during-trading-loss-avoidance\/#Database\" >Database<\/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\/how-to-avoid-common-mistakes-during-trading-loss-avoidance\/#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-6\" href=\"https:\/\/www.tejwin.com\/en\/insight\/how-to-avoid-common-mistakes-during-trading-loss-avoidance\/#Performance_Calculation\" >Performance Calculation<\/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\/how-to-avoid-common-mistakes-during-trading-loss-avoidance\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.tejwin.com\/en\/insight\/how-to-avoid-common-mistakes-during-trading-loss-avoidance\/#Source_code\" >Source code<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.tejwin.com\/en\/insight\/how-to-avoid-common-mistakes-during-trading-loss-avoidance\/#Extended_reading\" >Extended reading<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.tejwin.com\/en\/insight\/how-to-avoid-common-mistakes-during-trading-loss-avoidance\/#Related_link\" >Related link<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Highlights\"><\/span>Highlights<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Article Difficulty: \u2605\u2606\u2606\u2606\u2606<\/li>\n\n\n\n<li>Using Loss Avoidance for Automated Trading Strategies<\/li>\n\n\n\n<li>Studying the Effectiveness of Loss Avoidance using Listed Stock Price Data<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Introduction\"><\/span>Introduction<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>\u201cLoss avoidance\u201d is a crucial topic in investing, whether for novice investors or experienced experts. As we pursue investment returns, the risk of losses is ever-present. Therefore, adopting effective loss avoidance strategies is vital to protect our capital and enhance the chances of investment success.<br>The effectiveness of loss avoidance goes beyond reducing potential losses; it can also improve the overall performance of investment portfolios.&nbsp;<\/p>\n\n\n\n<p>By identifying and avoiding investment opportunities that may lead to significant losses, we can prevent overexposure to high-risk assets or markets. Through asset diversification and risk management strategies, we can maintain relatively stable investment returns during market fluctuations and mitigate the impact of losses.<\/p>\n\n\n\n<p>Effective loss avoidance strategies can also help us manage emotions and psychological factors in investments. Market volatility and uncertainty often trigger panic and impulsive decision-making, leading investors to act irrationally. However, with clear rules and strategies, we can remain calm and rational in response to market changes, thereby reducing losses stemming from emotionally driven investment decisions.<\/p>\n\n\n\n<p>In this article, we will use Python and the tejapi to fetch stock price data to examine the differences between implementing loss avoidance and not taking any loss avoidance measures. By understanding and applying loss avoidance, we will be better equipped to protect our investments, reduce potential losses, and enhance long-term returns.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Editing_Environment_and_Module_Requirements\"><\/span>Editing Environment and Module Requirements<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>This article uses a Mac operating system and Visual studio code as the editor.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import tejapi\nimport matplotlib.pyplot as plt\ntejapi.ApiConfig.api_key = \"your api key\"\ntejapi.ApiConfig.ignoretz = True<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Database\"><\/span>Database<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><a href=\"https:\/\/api.tej.com.tw\/columns.html?idCode=TWN\/EWPRCD\" class=\"ek-link\" target=\"_blank\" rel=\"noopener\">Securities Trading Data Table (TWN\/EWPRCD) &#8211; Closing Price Data<\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Data_Import\"><\/span>Data Import<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The data period for the example will be from June 12, 2023, to July 12, 2023, using the stock price of Silks Hotel Management Consulting Co., Ltd. (2739). We will fetch the unadjusted closing prices.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code># Select 2739 recent stock prices\n\ncompany = '2739'\nprice_data = tejapi.get('TWN\/EWPRCD', \n                coid = company,\n                mdate={\n                    # start date  \n                    'gte':'2023-06-12', \n                    # end date\n                    'lte':'2023-07-12'}, \n                opts={'columns': &#91;'coid','mdate','close_d']}, \n                paginate=True\n            )\nprint(price_data)\n<\/code><\/pre>\n\n\n\n<p>After obtaining the closing price data, we can proceed with visualizing the data.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>date = &#91;]\nfor d in price_data&#91;'mdate']:\n    date.append(str(d)&#91;5:7]+'\/'+str(d)&#91;8:10])\n\n    \nplt.figure(figsize=(11, 6))\nplt.plot(date, price_data&#91;'close_d'], label='stock price', color='blue') \nplt.title('stock price')  # set figure title\nplt.xlabel('Days')  # set X-axis label\nplt.ylabel('price')  # Set Y-axis label\nplt.show()<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full caption-align-center\"><img decoding=\"async\" width=\"1024\" height=\"595\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/image-206.png\" alt=\"\" class=\"wp-image-14371\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/image-206.png 1024w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-206-300x174.png 300w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-206-150x87.png 150w, https:\/\/www.tejwin.com\/wp-content\/uploads\/image-206-768x446.png 768w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><figcaption class=\"wp-element-caption\">Stock price trend<\/figcaption><\/figure>\n\n\n\n<p>We can observe that the stock price experienced a small increase during this period, followed by a continuous decline. This situation is suitable for conducting a loss avoidance test.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Performance_Calculation\"><\/span>Performance Calculation<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>get_day1_price = price_data&#91;'close_d']&#91;0]\nprint('purchase price:',get_day1_price)\nno_strategy = 0\nif_strategy = 0\n\n\nfor i in range(0, len(price_data&#91;'close_d'])):\n    no_strategy = no_strategy + price_data&#91;'close_d']&#91;i]-get_day1_price\n    # If the price decrease more than 10 percent of original price , it will be sold.\n    if price_data&#91;'close_d']&#91;i] &lt; get_day1_price*0.9:\n        if_strategy += 0\n    else:\n        if_strategy = if_strategy + price_data&#91;'close_d']&#91;i]-get_day1_price\n\n\nprint('No-loss-avoidance operation settlement surplus:',no_strategy)\nprint('circumvention operation to settle the surplus:',if_strategy)<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image aligncenter size-full caption-align-center\"><img decoding=\"async\" width=\"612\" height=\"70\" src=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/fig2-2.jpg\" alt=\"\" class=\"wp-image-14403\" srcset=\"https:\/\/www.tejwin.com\/wp-content\/uploads\/fig2-2.jpg 612w, https:\/\/www.tejwin.com\/wp-content\/uploads\/fig2-2-300x34.jpg 300w, https:\/\/www.tejwin.com\/wp-content\/uploads\/fig2-2-150x17.jpg 150w\" sizes=\"(max-width: 612px) 100vw, 612px\" \/><figcaption class=\"wp-element-caption\">performance comparison<\/figcaption><\/figure>\n\n\n\n<p>After calculation, it was found that implementing the loss avoidance strategy resulted in an additional profit of NT$30 per share compared to investors who continued to hold the stocks. Therefore, it is considered the best strategy to have discipline in selling when the stock price falls below the predetermined value.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>This implementation demonstrated a trading strategy focused on loss avoidance. Using code, we observed that implementing sell orders under specific stock price conditions resulted in higher profits than holding onto the stocks.<\/p>\n\n\n\n<p>However, it is essential to note that each investor\u2019s situation and risk tolerance differ. This example represents one possible strategy and does not guarantee profits in all situations. In actual investing, we must carefully consider our goals, risk preferences, and timeframes and adopt an investment strategy that suits our needs.<\/p>\n\n\n\n<p>Furthermore, this implementation serves as a reminder to be mindful of market risks and uncertainties. Various factors influence stock prices, including market sentiment, economic changes, company performance, etc. Regardless of our investment strategy, we cannot eliminate risk entirely. Therefore, exercising caution and establishing risk management mechanisms to navigate unforeseen market fluctuations is crucial.<\/p>\n\n\n\n<p>While the code in this implementation provides faster and more accurate analysis results, we should also handle data carefully and ensure that the information and indicators used are reliable and effective. Proper data analysis and research form the foundation for making informed investment decisions.<\/p>\n\n\n\n<p>In summary, loss avoidance is an essential aspect of investing, and leveraging automated trading can help us achieve this goal. However, we must select appropriate strategies based on our circumstances and market conditions while managing risk prudently. This approach will lead to more robust outcomes in our investments.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Source_code\"><\/span>Source code<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\/19fc1bfe8d76d501e4d5c178ea9a12eb\" class=\"ek-link\" target=\"_blank\" rel=\"noopener\">Click here to go Github<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Extended_reading\"><\/span>Extended reading<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/www.tejwin.com\/en\/insight\/bollinger-bands-trading-strategy\/\" target=\"_blank\" aria-label=\" (opens in a new tab)\" rel=\"noreferrer noopener\" class=\"ek-link\">Bollinger Bands Trading Strategy<\/a><\/li>\n\n\n\n<li><a aria-label=\"\u7f8a\u7fa4\u6307\u6a19\u61c9\u7528 (opens in a new tab)\" href=\"https:\/\/www.tejwin.com\/en\/insight\/herding-indicators\/\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"ek-link\">Application of Herding Indicator<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Related_link\"><\/span>Related link<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/api.tej.com.tw\/index.html\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"ek-link\">TEJ API<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/eshop.tej.com.tw\/E-Shop\/Edata_intro\" target=\"_blank\" rel=\"noreferrer noopener\" class=\"ek-link\">TEJ E-Shop<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u201cLoss avoidance\u201d is a crucial topic in investing, whether for novice investors or experienced experts. As we pursue investment returns, the risk of losses is ever-present. Therefore, adopting effective loss avoidance strategies is vital to protect our capital and enhance the chances of investment success.<br \/>\nIn this article, we will use Python and the tejapi to fetch stock price data to examine the differences between implementing loss avoidance and without loss avoidance measures. By understanding and applying loss avoidance, we will be better equipped to protect our investments, reduce potential losses, and enhance long-term returns.<\/p>\n","protected":false},"featured_media":14315,"template":"","tags":[2904,3176],"insight-category":[690,3509,50],"class_list":["post-14364","insight","type-insight","status-publish","has-post-thumbnail","hentry","tag-beginners-guide","tag-python-2","insight-category-data-analysis","insight-category-fintech-en","insight-category-fintech"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/14364","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":4,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/14364\/revisions"}],"predecessor-version":[{"id":44095,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/14364\/revisions\/44095"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media\/14315"}],"wp:attachment":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media?parent=14364"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/tags?post=14364"},{"taxonomy":"insight-category","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight-category?post=14364"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}