{"id":1499,"date":"2024-06-12T13:00:00","date_gmt":"2024-06-12T13:00:00","guid":{"rendered":"https:\/\/www.tejwin.com\/en\/insights\/trend-following-strategy\/"},"modified":"2024-06-12T13:00:00","modified_gmt":"2024-06-12T13:00:00","slug":"trend-following-strategy","status":"publish","type":"insight","link":"https:\/\/www.tejwin.com\/en\/insights\/trend-following-strategy\/","title":{"rendered":"Trend-Following Strategy: A Trading Method Used by Fund Managers"},"content":{"rendered":"<figure class=\"wp-block-image aligncenter size-full caption-align-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"Trend-Following Strategy\" class=\"wp-image-23765\" height=\"2667\" src=\"https:\/\/www.tejwin.com\/en\/wp-content\/uploads\/2026\/08\/Calico-kitten-MacBook.jpg\" style=\"aspect-ratio:1.5;object-fit:cover\" width=\"4000\"\/><figcaption class=\"wp-element-caption\">Photo by <a href=\"https:\/\/unsplash.com\/@riiiis?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash\" rel=\"noopener\" target=\"_blank\">riis riiiis<\/a> on <a class=\"ek-link\" href=\"https:\/\/unsplash.com\/photos\/calico-kitten-standing-in-front-of-macbook-pro-g3B53PbBfwU?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash\" rel=\"noopener\" target=\"_blank\">Unsplash<\/a><\/figcaption><\/figure>\n<h2 class=\"wp-block-heading\"><strong>Summary<\/strong><\/h2>\n<ul class=\"wp-block-list\">\n<li><strong>Difficulty:<\/strong> \u2605\u2605\u2605\u2606\u2606<\/li>\n<li><strong>Focus:<\/strong> Exploring the relationship between trend-following strategies and expected stock returns.<\/li>\n<li><strong>Implementation:<\/strong> Designing and backtesting trend following trading strategies using the TQuant Lab platform to assess risk and performance.<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\"><strong>Introduction<\/strong><\/h2>\n<p class=\"wp-block-paragraph\">Over the past two decades, trend following has been a successful trading strategy used by many fund managers, professional traders, and global macro hedge funds to profit in global futures markets. Applying trend-following strategies to stocks has recently gained significant attention, with a surge in published research and articles. Increasingly, the literature suggests that the trend effects observed in futures markets can similarly apply to stock markets.<br \/>Michael W. Covel, the founder of the renowned trend-following company TrendFollowing.com, presents a unique perspective. He states, \u201cIn capital markets, investors often seek to establish \u2018causal relationships\u2019 in price movements, believing it provides a sense of security to their strategies. However, trend following takes a different path. It doesn\u2019t attempt to predict market directions, but instead, it places a strong emphasis on discipline, precise trading rules, and strict risk control to navigate market volatility.\u201d<br \/>Additionally, <a class=\"ek-link\" href=\"https:\/\/www.cis.upenn.edu\/~mkearns\/finread\/trend.pdf\" rel=\"noopener\" target=\"_blank\"><strong>Cole Wilcox and Eric Crittenden<\/strong><\/a> (2005) outlined the conditions for implementing a trend-following strategy in the U.S. stock market:<\/p>\n<ul class=\"wp-block-list\">\n<li><strong>Investment Scope:<\/strong> Includes the 100 most liquid U.S. stocks with prices not less than $5.<\/li>\n<li><strong>Entry Condition:<\/strong> An entry signal is generated if today\u2019s closing price equals or exceeds the highest closing price in the stock\u2019s history.<\/li>\n<li><strong>Exit Condition:<\/strong> Uses a 10-period Average True Range (ATR) as a trailing stop signal. The stock is exited when its price falls below the current price minus the ATR.<\/li>\n<\/ul>\n<p class=\"wp-block-paragraph\">Based on these principles, this article designs a trend-following strategy suitable for investors\u2019 reference in the Taiwanese stock market.<\/p>\n<h2 class=\"wp-block-heading\"><strong>Trend-Following Strategy<\/strong><\/h2>\n<ul class=\"wp-block-list\">\n<li><strong>Investment Scope:<\/strong> Invest in the most liquid Taiwanese stocks with prices not less than NT$10.<\/li>\n<li><strong>Entry Condition:<\/strong> If today\u2019s closing price exceeds the previous year\u2019s highest closing price, an entry signal is generated.<\/li>\n<li><strong>Exit Condition:<\/strong> This strategy uses a 10-day Average True Range (ATR) as a trailing stop signal. The stock is exited when its price falls below the current price minus the ATR.<\/li>\n<li><strong>Position Management:<\/strong> Investors hold all stocks that meet the entry criteria and have not triggered a stop-loss. The portfolio is equally weighted and rebalanced daily.<\/li>\n<li><strong>Transaction Costs:<\/strong> TQuant Lab\u2019s Taiwan fee model.<\/li>\n<\/ul>\n<p class=\"wp-block-paragraph\"><em>Note: To increase entry opportunities, the entry condition of \u201chighest closing price in history\u201d is modified to \u201chighest closing price in the past year.\u201d Readers may adjust this condition as they see fit.<\/em><\/p>\n<h3 class=\"wp-block-heading\"><strong>Editing Environment and Module Requirements<\/strong><\/h3>\n<p class=\"wp-block-paragraph\">This article uses macOS and Jupyter Notebook as the editor.<\/p>\n<h2 class=\"wp-block-heading\"><strong>Data Import<\/strong><\/h2>\n<pre class=\"wp-block-code\"><code>import os\nimport tejapi\nimport pandas as pd\nimport numpy as np\nimport matplotlib.pyplot as plt\n\ntej_key = 'your key'\napi_base = 'https:\/\/api.tej.com.tw'\nos.environ['TEJAPI_KEY'] = tej_key\nos.environ['TEJAPI_BASE'] = api_base\nstart = '2019-04-01'\nend = '2024-04-01'<\/code><\/pre>\n<h3 class=\"wp-block-heading\">Utilize the <code>get_universe<\/code> function to obtain the stock pool.<\/h3>\n<p class=\"wp-block-paragraph\">The data spans from April 1, 2019, to April 1, 2024. We filter all common stocks listed on the Taiwanese stock market as the stock pool and include the Taiwan Weighted Index (IR0001) for market comparison. Finally, we ingest the bundle.<\/p>\n<p class=\"wp-block-paragraph\"><em>Note: To access all common stocks listed on the market, data for 1,890 stocks needs to be retrieved. The large volume of data may result in local memory insufficiency or significant API key usage. Please use it with caution.<\/em><\/p>\n<h2 class=\"wp-block-heading\">Creating Pipeline Function and Custom Factor<\/h2>\n<h3 class=\"wp-block-heading\">Custom Factor Function<\/h3>\n<p class=\"wp-block-paragraph\">The <code>CustomFactor<\/code> allows users to design customized factors as needed. In this case study, we use it to handle:<\/p>\n<ul class=\"wp-block-list\">\n<li><strong>Average True Range (ATR)<\/strong><\/li>\n<li><strong>Highest Price in the Past Year (N_Year_Highest)<\/strong><\/li>\n<\/ul>\n<p class=\"wp-block-paragraph\"><code>Pipeline()<\/code> provides users with the capability to quickly process quantitative indicators and price-volume data for multiple stocks. In this case study, we use it to handle:<\/p>\n<ul class=\"wp-block-list\">\n<li>Stocks trading above their highest price in the past year, priced over NT$10, and ranked in the top ten for trading volume (vol_rank)<\/li>\n<li>Current day\u2019s closing price (curr_price)<\/li>\n<li>Stop-loss point (atr)<\/li>\n<li>Highest price in the past year (highest_price)<\/li>\n<\/ul>\n<figure class=\"wp-block-image size-full is-resized caption-align-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"Trend-Following Strategy\" class=\"wp-image-23866\" height=\"1122\" src=\"https:\/\/www.tejwin.com\/en\/wp-content\/uploads\/2026\/08\/E688AAE59C96-2024-06-05-E4B88BE58D884.40.10.png\" style=\"width:840px;height:auto\" width=\"2506\"\/><figcaption class=\"wp-element-caption\">Pipeline Information<\/figcaption><\/figure>\n<h2 class=\"wp-block-heading\">Creating <code>Initialize<\/code> Function<\/h2>\n<p class=\"wp-block-paragraph\">The <code>initialize()<\/code> function is used to define the daily trading environment before trading starts. In this example, we set:<\/p>\n<ul class=\"wp-block-list\">\n<li>Slippage costs<\/li>\n<li>Taiwan stock market fee model<\/li>\n<li>Taiwan Weighted Index (<em>IR0001<\/em>) as the benchmark index<\/li>\n<li>Incorporation of strategy factors designed in the Pipeline into the trading process<\/li>\n<li>Setting the <code>context.stop_loss<\/code> variable to record stop-loss points during backtesting<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\">Creating <code>handle_data<\/code> Function<\/h2>\n<p class=\"wp-block-paragraph\">The <code>handle_data()<\/code> function is a crucial part of constructing the strategy. It is called daily after the backtest starts and is primarily responsible for setting the trading strategy, placing orders, and recording trading information. <\/p>\n<p class=\"wp-block-paragraph\">For detailed trading rules for this strategy, please refer to <a class=\"ek-link\" href=\"https:\/\/github.com\/tejtw\/TEJAPI_Python_Medium_Application\/blob\/f656231677aa8f89d04ef1f862665b9b3c0da146\/%E8%B6%A8%E5%8B%A2%E8%B7%9F%E8%B9%A4.ipynb\" rel=\"noopener\" target=\"_blank\">trend_following.ipynb<\/a>.<\/p>\n<h2 class=\"wp-block-heading\">Executing the Trend-Following Strategy<\/h2>\n<p class=\"wp-block-paragraph\">Use <code>run_algorithm()<\/code> to execute the above-set strategy, setting the trading period from <code>start_dt<\/code> (<em>2019-04-16<\/em>) to <code>end_dt<\/code> (<em>2024-04-01<\/em>), using the <code>tquant<\/code> dataset, with an initial capital of one million NT dollars. The output <code>results<\/code> includes the daily performance and transaction details.<\/p>\n<figure class=\"wp-block-image size-full caption-align-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"Trend-Following Strategy\" class=\"wp-image-23868\" height=\"864\" src=\"https:\/\/www.tejwin.com\/en\/wp-content\/uploads\/2026\/08\/E688AAE59C96-2024-06-05-E4B88BE58D884.55.06.png\" width=\"2602\"\/><figcaption class=\"wp-element-caption\">Cumulative Return<\/figcaption><\/figure>\n<div style=\"border: 1px black; border-style: solid none; text-align: center; border-color: #296580; padding: 24px; margin-top: 24px; margin-bottom: 24px;\">\n<p style=\"margin: 0px; font-size: 24px; font-weight: bold; line-height: 1.5;\">Start Building Portfolios That Outperform the Market!<\/p>\n<div style=\"margin-top: 32px;\"><strong><a href=\"\/en\/databank-solution\/market-data\/\" style=\"border: none; border-radius: 4px; background-color: #296580; color: white; font-size: 20px; width: fit-content; text-decoration: none; padding: 12px 30px 12px 30px;\">TEJ Market Databank<\/a><\/strong><\/div>\n<\/div>\n<h2 class=\"wp-block-heading\">Performance Evaluation Using Pyfolio<\/h2>\n<figure class=\"wp-block-image size-full caption-align-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"Trend-Following Strategy\" class=\"wp-image-24000\" height=\"885\" src=\"https:\/\/www.tejwin.com\/en\/wp-content\/uploads\/2026\/08\/E59088E4BDB5E59C96E5838F-1.png\" width=\"1705\"\/><figcaption class=\"wp-element-caption\">Backtest Performance Comparison with Market<\/figcaption><\/figure>\n<p class=\"wp-block-paragraph\">The momentum factor strategy achieved an annualized return of approximately 31.1% over these 57 months, with a cumulative return of 266.536%. Although there was a slight underperformance compared to the market in the initial stages, overall profitability was superior to the market. The beta value of 0.79 indicates that the strategy is less sensitive to market fluctuations, reflecting the core concept of trend following, which does not focus on overall market volatility or predict market directions. However, due to the strategy\u2019s focus on stock price movements, it targets stocks breaking new highs, which intuitively results in higher volatility, reaching 26.1%. Although high, this volatility primarily trends upward, as indicated by the Sortino Ratio of 1.17, an ideal figure (a lower Sortino Ratio means higher negative returns per unit risk).<\/p>\n<figure class=\"wp-block-image size-full caption-align-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"Trend-Following Strategy\" class=\"wp-image-24002\" height=\"351\" src=\"https:\/\/www.tejwin.com\/en\/wp-content\/uploads\/2026\/08\/E688AAE59C96-2024-06-07-E4B88AE58D889.17.29.png\" width=\"1070\"\/><figcaption class=\"wp-element-caption\">Annualized Return Bar Chart<\/figcaption><\/figure>\n<p class=\"wp-block-paragraph\">Apart from the bearish year of 2022, all other trading years showed positive returns.<\/p>\n<figure class=\"wp-block-image size-full caption-align-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"Trend-Following Strategy\" class=\"wp-image-24004\" height=\"515\" src=\"https:\/\/www.tejwin.com\/en\/wp-content\/uploads\/2026\/08\/E688AAE59C96-2024-06-07-E4B88AE58D889.40.45.png\" width=\"1604\"\/><figcaption class=\"wp-element-caption\">Long\/Short Position Holdings Changes<\/figcaption><\/figure>\n<p class=\"wp-block-paragraph\">The chart of long and short position holdings indicates that, under the strategy\u2019s setup with a maximum of 10 stocks, the number of holdings mostly stayed around 10, with a minimum of 4. <\/p>\n<figure class=\"wp-block-image size-full caption-align-center\"><img loading=\"lazy\" decoding=\"async\" alt=\"Trend-Following Strategy\" class=\"wp-image-24006\" height=\"536\" src=\"https:\/\/www.tejwin.com\/en\/wp-content\/uploads\/2026\/08\/E688AAE59C96-2024-06-07-E4B88AE58D889.49.22.png\" width=\"1603\"\/><figcaption class=\"wp-element-caption\">Turnover Rate Distribution<\/figcaption><\/figure>\n<p class=\"wp-block-paragraph\">Due to daily rebalancing, the turnover rate was occasionally high, warranting attention to transaction fees.<\/p>\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n<p class=\"wp-block-paragraph\">This strategy applies the research of <a class=\"ek-link\" href=\"https:\/\/www.cis.upenn.edu\/~mkearns\/finread\/trend.pdf\" rel=\"noopener\" target=\"_blank\">Cole Wilcox and Eric Crittenden<\/a> (2005) to verify the profitability of trend following in the Taiwanese stock market, yielding the following results:<\/p>\n<ul class=\"wp-block-list\">\n<li><strong>Advantages:<\/strong> Excellent profitability, intuitive and simple entry and exit conditions.<\/li>\n<li><strong>Disadvantages:<\/strong> Daily rebalancing results in a higher turnover rate, requiring additional attention to transaction fees.<\/li>\n<\/ul>\n<p class=\"wp-block-paragraph\">Investors are welcome to refer to this strategy. We will continue introducing various indicators constructed using the TEJ database and backtest their performance. Readers interested in various trading backtests are encouraged to consider <strong><a class=\"ek-link\" href=\"https:\/\/tquant.tejwin.com\/\" rel=\"noreferrer noopener\" target=\"_blank\">TQuant Lab<\/a><\/strong>\u2018s related packages to build their trading strategies using high-quality databases.<\/p>\n<p class=\"wp-block-paragraph\"><strong>Disclaimer:<\/strong> This strategy is for reference only and does not represent any product or investment advice.<\/p>\n<div class=\"wp-block-buttons is-layout-flex wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button has-custom-width wp-block-button__width-100 has-custom-font-size\" style=\"font-size:22px\"><a class=\"wp-block-button__link has-background wp-element-button\" href=\"\/en\/databank-solution\/market-data\/\" style=\"border-radius:16px;background:linear-gradient(135deg,rgb(160,209,216) 0%,rgb(51,145,181) 50%,rgb(50,95,191) 100%)\"><strong>Access to Comprehensive Retail Investors Data<\/strong><br \/><strong>Start Building Portfolios That Outperform the Market Today!<\/strong><\/a><\/div>\n<\/div>\n<div aria-hidden=\"true\" class=\"wp-block-spacer\" style=\"height:22px\"><\/div>\n<p class=\"has-text-align-center wp-block-paragraph\" style=\"font-size:32px\"><mark class=\"has-inline-color has-vivid-cyan-blue-color\" style=\"background-color:rgba(0, 0, 0, 0)\"><strong><em>\u201cTaiwan stock market data, TEJ collect it all.\u201d<\/em><\/strong><\/mark><\/p>\n<p class=\"wp-block-paragraph\">The characteristics of the Taiwan stock market differ from those of other European and American markets, and <mark class=\"has-inline-color has-black-color\" style=\"background-color:rgba(0, 0, 0, 0)\"><span class=\"ek-underline\" style=\"text-decoration: underline;\">the dynamics of retail investors are worth noting<\/span><\/mark>. Especially in the first quarter of 2024, with the <strong><mark class=\"has-inline-color\" style=\"background-color:rgba(0, 0, 0, 0);color:#c05d5d\">Taiwan Stock Exchange reaching a new high of 20,000 points<\/mark><\/strong> due to the rise in TSMC\u2019s stock price, global institutional investors are paying more attention to the performance of the Taiwan stock market.\u00a0<\/p>\n<p class=\"wp-block-paragraph\"><strong><mark class=\"has-inline-color\" style=\"background-color:rgba(0, 0, 0, 0);color:#0978b8\">Taiwan Economical Journal (TEJ)<\/mark><\/strong>, a financial database established in Taiwan for over 30 years, serves local financial institutions and academic institutions, and has long-term cooperation with internationally renowned data providers, providing high-quality financial data for five financial markets in Asia.\u00a0<\/p>\n<ul class=\"wp-block-list\">\n<li><strong><mark class=\"has-inline-color has-black-color\" style=\"background-color:#ebc766\">Complete Coverage<\/mark><\/strong>: Includes all listed companies on stock markets in Taiwan, China, Hong Kong, Japan, Korea, etc.\u00a0<\/li>\n<li><strong><mark class=\"has-inline-color\" style=\"background-color:#ebc766\">Comprehensive Analysis of Enterprises<\/mark><\/strong>: Operational aspects, financial aspects, securities market performance, ESG sustainability, etc.\u00a0<\/li>\n<li><strong><mark class=\"has-inline-color\" style=\"background-color:#ebc766\">High-Quality Database<\/mark><\/strong>: TEJ data is cleaned, checked, enhanced, and integrated to ensure it meets the information needs of financial and market analysis.\u00a0<\/li>\n<\/ul>\n<p class=\"wp-block-paragraph\">With TEJ\u2019s assistance, you can access relevant information about major stock markets in Asia, such as securities market, financials data, enterprise operations, board of directors, sustainability data, etc., providing investors with timely and high-quality content. Additionally, TEJ offers advisory services to help solve problems in theoretical practice and financial management!<\/p>\n<div class=\"wp-block-buttons is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-3e41869c wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button has-custom-width wp-block-button__width-100 has-custom-font-size\" style=\"font-size:21px\"><a class=\"wp-block-button__link has-background has-text-align-center wp-element-button\" href=\"\/en\/contact\/\" style=\"border-radius:16px;background:linear-gradient(135deg,rgb(160,209,216) 0%,rgb(51,145,181) 50%,rgb(50,95,191) 100%)\"><strong>Want to Learn More About Our Databases?<br \/>Contact Us and Get the Free Trial!<\/strong><\/a><\/div>\n<\/div>\n<h2 class=\"wp-block-heading\">Extended Reading<\/h2>\n<ul class=\"wp-block-list\">\n<li><a class=\"ek-link\" href=\"\/en\/insight\/high-dividend-etf\/\">The Gospel for Dividend Investors? Backtesting Performance of High Dividend ETF<\/a><\/li>\n<li><a class=\"ek-link\" href=\"\/en\/insight\/tquant-lab-insider-transfer-strategy\/\">Insider Transfer Strategy: A Solution to Timing Difficulties<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Over the past two decades, trend-following has been a successful trading strategy used by many fund managers, professional traders, and global macro hedge funds to profit in global futures markets. Recently, the application of trend following strategies to stocks has gained significant attention, with a surge in published research and articles. Increasingly, literature suggests that the trend effects observed in futures markets can similarly apply to stock markets.<\/p>\n","protected":false},"featured_media":1492,"template":"","tags":[50,65,70,71],"insight_category":[13],"class_list":["post-1499","insight","type-insight","status-publish","has-post-thumbnail","hentry","tag-market-data","tag-python","tag-tej-api","tag-quantitative-strategy","insight_category-quant-research"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight\/1499","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"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media\/1492"}],"wp:attachment":[{"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/media?parent=1499"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/tags?post=1499"},{"taxonomy":"insight_category","embeddable":true,"href":"https:\/\/www.tejwin.com\/en\/wp-json\/wp\/v2\/insight_category?post=1499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}