Helping investors beat the market.

Ivann Fok
3 weeks, 5 days ago · 767 Views


Ivann Fok

Ivan is the founder of He is passionate about technology and finance and has worked as a software developer at a hedge fund where he was responsible for building the fund's trading system. He hopes that PyInvesting will help investors adopt a data driven approach to investing and support them in their journey towards financial freedom.

3 Ways to Evaluate the Performance of your Investment Strategy
Do you happen to know that one guy who only invests a single stock because it is the hottest stock in the market? This guy is usually the loudest person in the room and will always brag about how much money he made just dumping his entire net worth into a Tesla stock. Let’s call him, Mr Tesla.  Another guy that you might know, loves to invest in tech companies. He is the guy that queues up for hours just to get hold of the latest iPhone on the same day that it is released into the market. Because of his obsession with technology and IT gadgets, his favourite stocks to invest in are Facebook, Apple, Amazon, Netflix and Google also known as FAANG stocks. Let’s call him, Mr FAANG. Mr FAANG holds an equal weighted portfolio of FAANG stocks and rebalances his portfolio once a year using a strategic allocation backtest.  One day, Mr Tesla and Mr FAANG bumped into each other at a bar, got drunk, and started arguing with each other about who is the better investor.      Mr Tesla: “My returns are higher!”  Mr FAANG: “But your risk is higher too!”  They both have a point. Mr Tesla has a higher return of 44.6% vs Mr FAANG’s less impressive 34.5%. However, Mr FAANG’s portfolio has a lower volatility of 25.3% vs Mr Tesla’s portfolio of 53.5%.   So who is the better investor? Introducing risk adjusted returns While Mr Tesla does indeed have a significantly higher annualized return than Mr FAANG, he achieves this annualized return at more than double the volatility of Mr FAANG. To compare Mr Tesla’s performance against Mr FAANG, we need to use a performance metric that rewards investment strategies with high returns while penalizing strategies with high risks. This is known as the risk adjusted returns of a strategy. Investors generally prefer higher risk adjusted returns as compared to simply higher returns because it accounts for the difference in risk between strategies.  Sharpe ratio The Sharpe ratio is one of the most common measurements of risk adjusted returns. It is the excess return of your strategy divided by its volatility. The excess return can be obtained by subtracting the risk free rate from the annualized returns of your strategy. The risk free rate is the return from investing in a safe instrument such as the yield for US treasury bonds.  Sharpe ratio = (Annualized returns - Risk free rate) / Volatility  The higher the returns of a strategy, the larger the numerator, the higher the Sharpe ratio. The higher the volatility, the larger the denominator, the lower the Sharpe ratio. Doing the math for both strategies, Mr FAANG comes out ahead of Mr Tesla with a Sharpe of 1.25 vs 0.78.  Sortino ratio The next measure of risk adjusted returns is the Sortino ratio. This ratio is slightly different from the Sharpe ratio where instead of dividing the excess returns by the volatility, we divide the excess returns by the semi deviation. The semi deviation is calculated by measuring the volatility on days when the strategy has negative portfolio returns.  Sortino ratio = (Annualized returns - Risk free rate) / Semi deviation Using the semi deviation makes sense because any investor should welcome upside volatility as it translates to higher returns. By differentiating between harmful volatility from the overall volatility of a strategy, the Sortino ratio provides a better representation of risk adjusted returns than the Sharpe ratio.  Going back to Mr FAANG’s and Mr Tesla’s investment strategy, we can see that Mr FAANG still comes out ahead of Mr Tesla with a higher Sortino ratio of 1.60 vs 1.11 Calmar Ratio The Calmar ratio is another measure of risk adjusted returns. Unlike the Sharpe and Sortino ratios that depend on volatility, the Calmar ratio looks at the maximum drawdown of a strategy.  The maximum drawdown is the maximum loss from peak to trough of your portfolio’s value before a new peak is attained. For example, the maximum drawdown of the S&P 500 was 56% as it lost 56% from its peak in October 2007 to March 2009 before going on to recover from the global financial crisis. The Calmar ratio is calculated by dividing your strategy’s annualized returns by its max drawdown. Calmar ratio = Annualized returns / Max drawdown The Calmar ratio might appeal more to some investors because the max drawdown is a better indicator of your strategies risk. While volatility is commonly used as a proxy for risk, it does not give the investor an idea of how much he could lose during black swan events like what we saw during the recent Covid crisis.  Comparing Mr FAANG’s and Mr Tesla’s investment strategy, we can see that Mr FAANG wins with a higher Calmar ratio of 1.08 vs 0.74 How do you improve your risk adjusted returns? Overall, Mr FAANG’s investment strategy has higher risk adjusted returns as compared to Mr Tesla. All 3 performance metrics (Sharpe, Sortino and Calmar ratios) were higher for Mr FAANG’s strategy.  There are 3 key reasons why Mr FAANG’s strategy outperformed with higher risk adjusted returns.  Diversification. Everyone knows that the only free lunch on wall street is diversification and that we should never put all our eggs in one basket. By spreading his bets among 5 different stocks, Mr FAANG was able to reduce the risk of his portfolio as compared to Mr Tesla who was all in on a single stock. The logic behind this is that by investing in different stocks, the portfolio’s volatility is lower because of different stocks moving in different directions and at different pace where the correlation between different stocks is less than 1. Equal weighting. By equal weighting the portfolio among 5 different stocks, there is a much smaller concentration risk in the portfolio as compared to holding a single stock. By allocating the weights equally between different stocks, it ensures that even if one of the stocks does not do well, the impact on the overall portfolio will be limited. We are betting on the average performance of every stock in the portfolio rather than on a single stock hitting a home run for us.   Rebalancing. The purpose of rebalancing is to adjust the weight of each stock in the portfolio back to its target weight so that we can maintain our equal weighting over time. As the different stocks in the portfolio have different performance, over time this difference in returns gets larger causing the weights between each stock to differ from their target allocation of 20% per stock. Rebalancing involves taking profits on some stocks that have performed well and reinvesting these profits into stocks that have fallen in value. This allows us to keep the weights between different stocks equal over time and reduce concentration risk in our portfolio. Happy investing, and may the odds be in your favour. If you want to develop an effective investment strategy, learning how to utilize the results of backtesting can be one of the best decisions you ever make since backtesting can help you identify an incorrect or correct investment before your money is on the line. PyInvesting is a backtesting platform that helps investors create their own robo advisors on the cloud without writing a single line of code.
Ivann Fok · 1 day, 6 hours ago
Top 3 factors that determine which investment strategy is right for you
When it comes to investing, every investor has their own personal tastes and preferences. Investors approaching retirement tend to be more conservative and prefer strategies with lower risks while young working adults usually have a higher risk appetite and are willing to stomach some volatility in exchange for higher returns. Whichever strategy you choose, it is important that you are comfortable with the risk it entails so that you are able to stick to your strategy and avoid making emotional decisions.  There are three key factors that determine which investment strategy is right for you.  Risk tolerance Expected returns Effort required to implement the strategy Risk tolerance The first factor is your risk tolerance which is the amount of risk you are willing to take on in exchange for a return on your investment. Generally, investment strategies with higher risks should be rewarded with higher returns. You should choose an investment strategy with a target risk that you are comfortable with and will not cause you to lose sleep at night. Many investors are often attracted to the high returns from an investment strategy. However when markets get volatile, and they start seeing huge fluctuations in their portfolio’s value, they are unable to stick to the plan and get shaken out of their positions. They end up panic selling and crystalizing huge losses on their portfolio.  One way you can measure the risk of your strategy is to backtest your investment strategy and find out the maximum drawdown of your strategy. The maximum drawdown tells us what is the maximum amount of money you can lose on your portfolio during a crisis. For example, during the 2008 crisis, the S&P 500 lost 55% from it’s peak value in October 2007 to March 2009.  You need to ask yourself how much are you prepared to lose if markets were to crash and are you willing to stay the course. Retirees who need to gradually withdraw their funds for their daily expenses should only invest a small percentage of their wealth that they can afford to lose. Young working adults on the other hand should take on more risk because they have time on their side to ride out any market crashes.  For me personally at 30 years old, I’m comfortable with a 50% drawdown on my portfolio if a black swan event such as the 2008 global financial crisis were to happen again. When I’m 50 years old, I would be comfortable with a 30% drawdown on my portfolio.  Expected Returns The second factor that determines your investment strategy is expected returns. How quickly do you need your money to grow to achieve your financial goals?  The math shows that if you save $50 a day for 20 years at a 10% rate of return, you will end up with over a million dollars. However, if your investment strategy is expected to make 5% a year, it is extremely unlikely that you will hit a million dollars at the same saving rate. This could mean being able to free yourself from the corporate rat race a few years earlier and being able to provide a significantly higher standard of living for your loved ones.  You can measure the expected returns of your strategy by backtesting it using historical prices and calculating the annualized returns. Check out this tutorial video below to find out how you can analyze the performance of your investment strategy.   Once you get the annualized returns from your backtested investment strategy as shown below, you can plug that value into the CPF retirement calculator to find out whether you are able to hit your financial goals. Effort Required  The third factor is how much effort you are willing to spend on managing your investments. Some strategies require less work to maintain than others and would appeal to more hands off investors. It is important to choose a strategy that fits the amount of effort you are willing to commit to implement the strategy. This is because if you choose a strategy that requires more time to implement than you are willing to commit, you could end up finding it a chore to manage your portfolio and eventually give up on following your strategy. For investors who are not willing to spend a lot of time managing their portfolio, long term strategies such as the Ray Dalio all weather strategy, would be a great fit. This strategy involves allocating a fixed percentage of your portfolio in specific asset classes such as stocks, bonds, REITs and commodities and rebalancing the portfolio once a year to the portfolio’s target allocation. Investors that are able to spend more time managing their portfolios are able to adopt more active strategies such as a moving average strategy where they monitor their positions on a weekly basis. Note that actively monitoring your positions does not necessarily mean you are trading every week. The investor could simply be frequently checking each position more frequently but only opportunistically trading a small number of stocks in the portfolio if they change their buy or sell conviction.  Backtest your investment strategy When choosing our investment strategy, it is important to consider our risk tolerance, our expected return and the amount of effort we are willing to spend on managing our portfolio. Having the right investment strategy will allow us to stay invested even when markets are volatile and help us achieve our financial goals.  Backtesting your investment strategy will allow you to estimate the strategies expected risk and return, and understand the amount of effort required to manage your portfolio. While most portfolio backtesting methods involve expertise in programming and statistics, we can use platforms such as to simply fill in a form and create a backtest. The website will run your investment strategy using live prices and send you an email with the orders you need to trade on your personal account.  Stay the course, and may the odds be in your favor.
Ivann Fok · 6 days, 5 hours ago
Ivann Fok · 1 week, 3 days ago
Beating the S&P 500 by selecting US stocks with strong fundamentals Most long term investors rely on fundamental data to decide which stocks they should include in their portfolios. Fundamental data can be obtained from financial statements such as the company’s balance sheet, income statement and cash flow statement. These reports provide valuable insights into the company’s financial health, profitability and growth. These are key fundamental factors that investors should look out for as they are highly correlated to the stocks performance.  However, measuring these fundamental factors is a tedious process. Investors need to comb through hundreds of financial reports to search for these factors and then combine these different factors together to rank the available stocks. Fortunately with the help of technology, this whole process has been simplified for us. Here is how you can go live and profit from a fundamental strategy for US stocks.  Introducing PyInvesting is a website that provides financial data and backtesting tools to help you go live with your own investment strategies. Think of it as a platform where you can build your own personal robo adviser that helps you comb through hundreds of financial reports and tells you which stocks you should buy or sell. We are going to use PyInvesting to create our fundamental strategy for US stocks. Let’s go! First go to where we will be creating a fundamental backtest. A backtest is a simulation of our investment strategy using historical data. If the simulation results are poor where the strategy significantly underperformed its benchmark, it confirms that the strategy does not work. In contrast, if the strategy significantly outperforms its benchmark, it gives us confidence that it’s likely to perform well going forward. The backtest also tells us what stocks we should be holding in our portfolio so we know which stocks to buy or sell when we go live with our strategy.  Click on the “Select your stocks” button which opens a window to select stocks for your fundamentals backtest. Under template portfolios, click on “S&P 500” to select s&p 500 stocks from the index. The default benchmark is the SPDR S&P 500 Index (which passive investors can use to invest in the s&p 500) where we will compare the historical performance of our fundamentals investment strategy against the s&p 500 historical prices. Financial Health We want to select companies with a healthy balance sheet and a low debt to equity ratio because these companies have strong abilities to repay their creditors. Because these companies have relatively low leverage, these companies are usually quite resilient and are able to survive through tough periods without going bankrupt. As a result, investors holding these stocks tend to lose less money during a crisis because these stocks are well positioned to weather a storm.  Profitability Next, we want to select companies that are highly profitable, and have a high return on equity. A high return on equity implies that the company’s management is efficient in using investment financing to grow their business and is hence able to provide better returns to investors. A low return on equity implies that the company could be mismanaged where the management is investing in unproductive assets. Return on equity is also a measure of how efficient the company is using its resources. A high return on equity could mean that the company is increasing its profits with a relatively low amount of capital.  Growth Finally, we want to select growth companies whose earnings increase at a much faster rate than the overall economy. These companies have high profit growth and tend to reinvest their earnings into profitable areas of their business. They usually do not pay dividends and choose to reinvest profits to further grow their business. Most growth companies such as Tesla, Google, and Amazon are in the technology sector where they are constantly investing in innovative ideas and expanding into new businesses. Growth companies are able to provide huge returns to investors by focusing on revenue growth and maintaining leadership in their industry. Constructing our portfolio strategy To select stocks with strong financial health, profitability and growth, we are going to select 3 factors shown below. Stocks with the highest return on equity, highest profit growth and lowest debt to equity. These 3 factors are equally weighted at 33% each. All other factors in the table are allocated a weight of 0%. The website will automatically combine these 3 factors for you using a z-scoring approach where the factors are normalized using the mean and volatility. Subsequently, we need to decide how many stocks to hold in the portfolio. I decided to hold 20 equally weighted stocks in my portfolio to avoid concentration risks. Every month, the stocks from the S&P 500 are ranked based on these 3 fundamental factors and the top 20 stocks are selected to form an equal weighted portfolio.  Performance The results show that our fundamental strategy for US stocks significantly outperforms the S&P 500 benchmark with an annualized return of 17.8% vs 9.0% since 2006. The strategy also has a higher Sharpe Ratio of 0.73 vs the S&P 500 which has a Sharpe Ratio of 0.37 implying that the strategy has higher risk adjusted returns. While the strategy has a higher volatility than the S&P 500, it has a lower semi deviation than the S&P 500. This means that the strategy has lower downside volatility and higher upside volatility. The max drawdown of the strategy is also significantly lower than the S&P 500 where it lost 46% during the 2008 crisis vs the S&P 500 which lost 55.2%.  Overall, this backtest confirms that the fundamental strategy for US stocks works where if we select stocks with the highest return on equity, highest profit growth and lowest debt to equity ratio, we can expect to outperform the S&P 500 by 8.8% every year. This strategy is suitable for long term fundamental investors who can afford to take on some market risk in exchange for significantly higher returns.   The website also shows the current positions in the portfolio which users can trade on their own personal account. Subscribers have the option of “going live” with their portfolios where they will receive daily email updates to notify them if their strategy decides to make a trade. I’ve added a link below for users to check out the backtest results from this strategy. Do consider signing up for a free account with PyInvesting to receive future updates. In my next article, I will be explaining how to use the relative strength backtest. Stay tuned and I’ll see you guys next time!
Ivann Fok · 1 month, 1 week ago
Outperforming the market with high dividend yield stocks
One of the key factors most investors look out for when purchasing stocks is how much dividend the stock pays. A dividend is a reward that the company pays to its investors which usually stems from its net profit. When a company pays high dividends, it usually indicates that a company is doing well and is able to distribute part of its earnings to its investors. These companies tend to be large, established companies with strong and predictable cash flow. However, not all companies that pay high dividends make good investments. Some companies continue making dividend payments even when they are not profitable. This is to maintain their track record of making regular dividend payments. An example would include Exxon Mobil, a huge oil and gas company. Exxon Mobil has a consistent tracking record of paying dividends every quarter since 2013. However, an investor that bought the company since 2013 would have lost 14% vs the S&P 500 which made 101% during that period.   Do high dividend yield stocks outperform? To find out whether the dividend yield factor is able to select stocks that outperform the market, I run a backtest using Python code to simulate the performance of the strategy using historical data.  From an investment universe of 500 stocks, I select 50 stocks with the highest trailing dividend yield. The trailing dividend yield is the dividends per share over the trailing 12 months divided by the stock price. It is a measure of how much cash flow you are receiving for every dollar you invest in the stock. To select the stocks, I rank each stock in the universe based on their trailing dividend yield. I equal weight each of the 50 stocks in the portfolio to reduce the concentration risk of the portfolio. This will prevent my portfolio from taking a big hit if any single stock crashes. In addition, stocks with the strongest signal within each sector are selected such that no single sector has a weight larger than 20% of the portfolio. This reduces sector risk and allows us to isolate the source of out performance due to the high dividend yield signal.   Performance The backtest results show that the high dividend yield strategy has an annualized return of 10% and volatility of 20.7%. The strategy has cumulative return of 255%, outperforming the S&P 500 benchmark by almost 55% since 2006. We can also analyse the performance of the high dividend yield strategy over different periods. The plots above show that during the great financial crisis, the strategy’s performance was almost in line with the S&P 500 benchmark. During the crisis recovery period from 2009 to 2012, the strategy significantly outperformed the benchmark by 80%. However from 2013 to 2019, the strategy has been giving up some of those gains, under performing the benchmark by 60%.   Conclusion By selecting a portfolio of stocks with the highest dividend yield in each sector, we were able to develop a strategy which outperforms the market. The simulation also showed that the strategy performed well during the crisis recovery period but gave up a significant chunk of its gains during the new normal period from 2013 to 2019. In the next article, I will be discussing how we can improve the performance of the high dividend yield strategy by combining it with the quality factor.
Ivann Fok · 1 month, 2 weeks ago
Choosing high quality value stocks that outperform
When it comes to investing, everyone loves to talk about glamorous stocks such as the FAANG stocks (Facebook, Apple, Amazon, Netflix, Google). These are the stocks that get a lot of attention from investors and make good conversation topics at parties. However, is now the best time to be holding these stocks? Probably not, if you are a believer in value investing as these highly popular stocks are pretty expensive relative to their earnings. In my previous article, I wrote about how the value investment theme of selecting cheap stocks outperforms expensive stocks. While I was explaining the question of why value stocks outperform over time, we also discussed how value investing is subjected to risks such as the value trap, where cheap stocks continue to remain cheap because the company fails to improve and innovate. This implies that value investing doesn't work all the time and there is certainly room for improving the strategy. Can we do better in selecting value stocks that outperform stocks in general? In this article, I investigate how we can improve our value investing strategy by filtering for high quality stocks. By selecting stocks that are both cheap and are highly profitable, it is possible to increase the performance of our strategy. The best part about this strategy is that it is completely rules based so there is no room for opinions and speculation. Everything is straight forward based on the valuation and profitability numbers. By using a systematic value investing strategy, we are able to remove emotions and completely rely on logic to make our investment decisions. How do we select quality value stocks? From an investment universe of 500 stocks, I select 50 stocks with the lowest price to earnings ratio (PE ratio) and the highest return on equity (ROE). The PE ratio is a stock’s adjusted close price divided by its earnings per share (EPS). A low PE ratio implies that the stock is trading at a low price relative to its earnings. A cheap stock has a low PE ratio. The company’s ROE is its net income divided by its average total common equity. It is a measure of how much profit a company can generate with every dollar of capital. A high ROE implies that a company is highly efficient because it is able to generate profit with relatively little capital. A quality stock has a high ROE. To select the stocks, I rank each stock in the universe based on their inverse PE ratio (since we want stocks with a low PE ratio to have a high ranking) and ROE. Next, I take the average of each stock’s PE ratio ranking and ROE ranking. This gives me an overall signal which combines both value and quality factors and allows me to select low price high quality stocks.  Risk management I equal weight each of the 50 stocks in the portfolio to reduce the concentration risk of the portfolio. This will prevent my portfolio from taking a big hit if any single stock crashes. In addition, stocks with the strongest signal within each sector are selected such that no single sector has a weight larger than 20% of the portfolio. This reduces sector risk and allows us to isolate the source of outperformance due to the value and quality signal. I do not want the strategy to outperform or underperform because it was overly exposed to a single sector but rather because the strategy was invested in cheap and high quality stocks across all sectors. Performance I used Quantopian to backtest this python value investing strategy. The backtest results show that the quality value strategy has a cumulative return of 238%, outperforming the S&P 500 benchmark by almost 50% since 2006. More importantly, by including the quality factor to our pure value investing signal, the performance of our strategy has improved! The quality value strategy makes an annual return of 9.6% vs the pure value strategy which makes 8.9%. Besides increasing the returns of the strategy, the quality value strategy has a lower volatility of 19.4% vs the pure value strategy’s volatility of 19.7%. This means that the risk of the strategy has decreased. As a result, by combining the quality factor to our value factor, the risk adjusted returns of the strategy has increased. Hence for the same level of risk, the quality value strategy makes a higher return. This is reflected by the higher Sharpe ratio of the quality value strategy 0.57 vs 0.53 of the pure value strategy. Conclusion By combining the quality factor with our initial value investing strategy, our backtest has shown that we are able to achieve higher risk adjusted returns. This is because the stocks from our quality value strategy are both cheap and highly profitable. This strategy appeals to value fundamental investors that have a long investment horizon. While Warren Buffet once said that it’s better to buy a wonderful company at a fair price than a fair company at a wonderful price, I would argue that it’s even better to buy a wonderful company at a wonderful price.
Ivann Fok · 1 year, 3 months ago
Will value investing make you rich?
Warren Buffet, the 3rd richest person in the world with a net wealth of 86.3 billion, made his fortunes through value investing. Can we replicate his strategy to get similar results? I ran a historical simulation of a value investing strategy and will be answering the following questions: What are the rules used to select value stocks? How profitable is the value investment strategy if we used it from 2006 until today? What is value investing? Value investing is an investment strategy that selects stocks which are cheap relative to their earnings. These stocks are undervalued relative to other stocks due to the market’s overreaction to bad news. This gives value investors the opportunity to take advantage of the low prices to make huge profits when the prices revert back to their fair value. However, a value investment strategy is not without risks. A cheap stock can become cheaper if the company fails to improve, manage its cost and innovate. This is known as a value trap, which is every value investor’s nightmare. Hence, value investors take on this risk for the chance to be rewarded with huge profits in the long run. Their investment horizons are usually at least 3 years and they will close their positions once the price is no longer attractive relative to its fair value.   How do we select value stocks? From an investment universe of 500 stocks in the S&P 500, I select 50 stocks (top 10%) within the universe with the lowest price to earnings ratio (PE ratio). A low PE ratio implies that the stock is trading at a low price relative to its earnings which is an ideal candidate for value investors looking for cheap deals. I equal weight each of the 50 stocks in the portfolio to reduce the concentration risk of the portfolio i.e. each stock in the portfolio has a target weight of 2%. The weights will deviate from 2% as the prices of stocks within the portfolio go up or down. If the weights deviate too far, the stock is re-balanced back to it’s target weight. I’m not interested in how a single stock or a few stocks perform, but how the value investment theme performs. This means looking at a group of stocks (10% of the universe) with a low PE ratio and finding out if it outperforms the market as a whole. Another key aspect of the portfolio construction is sector neutrality. A stock that is cheap in the tech sector may be considered expensive to a stock in the utilities sector based on PE ratios. It does not make sense to compare the PE ratio of stocks between sectors because each sector has its own unique characteristics. Hence we select the stocks with the lowest PE ratios within each sector to ensure that we do not end up with a bias towards sector that tend to have lower valuations. The plot below shows that the portfolio does not tilt towards any specific sector with every sector having a weight of under 20%.   Simulation Results The simulation results show that the value investment strategy has an annual return of 8.9%. The strategy outperformed the S&P, making a cumulative return of 210%. While the strategy’s total returns are high, it’s comes with higher risk. It’s annual volatility is 19.7% vs the market’s historical volatility of 17%. In addition, there are certain periods where the strategy performs worse than the market. If we compare the performance since 2013, the simulation shows that while the S&P makes 130%, the strategy only makes 80%. That’s a whopping 50% difference in performance. An investor that bought value stocks since 2013 will not be too happy!   Conclusion Value investing has shown promising results overall, providing exceptional returns during certain periods in the past. Cheap stocks do have the tendency to outperform expensive stocks. However, there are still risks involved where the investor might not be rewarded for taking on the value risk premium, such as the period from 2013 onward. This goes to show why most successful value investors have a long investment horizon from 3 years onward. This gives them ample time to ride out periods of under-performance for the chance of making huge profits in the long run. Find out what Datascience Investor has to say about value investing:
Ivann Fok · 1 year, 3 months ago
How Do You Trade Trends in the Market?
The turtle strategy was used by one of the most successful trend followers in history, Richard Dennis, who borrowed $1,600 and reportedly made $200 million in about ten years. The strategy states that when the price of instruments hits a 3 month high, we buy. And when the price of an instrument hits a 3 month low, we sell. The strategy provides an effective form of capital protection for investors yet allows investors to participate in the upswings of the market.   Backtesting the turtle strategy To test the effectiveness of the turtle strategy, I simulated the strategy using a backtesting framework built with Python. The simulation works by: Pulling historical prices of the S&P 500 ETF (SPY) into my database. Building the trading signals by using the rolling maximum/minimum of a 3 month window period. Submitting orders whenever a buy or sell signal was generated. Generating plots to show the results of the backtest. The plots below show the results of my simulation. The top plot shows the price of the S&P 500 (dark blue line) sandwiched between it’s rolling maximum (light blue line) and rolling minimum (purple line). Following the rules of the turtle strategy, when the price of the index crosses above it’s rolling maximum, we go long on the index. When the price of the index crosses below its rolling minimum, we close our long position. The profit and loss (PNL) value of the portfolio is shown in the lower graph. $1 million dollars invested in 2002 would result in slightly over $2.5 million today. While the returns may look unimpressive, traders typically use highly leveraged financial instruments such as futures contracts to magnify gains. This is possible because of the lower risk of the strategy which provides downside protection. For example, during the 2008 recession, the portfolio only lost 18% vs the market (down 56%). To most investors, however, this strategy would not be appealing because of its high turnover. We can see that to employ this strategy, investors would need to frequently buy and sell the index. This is highly inconvenient and would result in high trading cost.   Can we do better? The original turtle strategy used a 3-month signal horizon to trade the market (i.e. they bought the index when it’s price hit a 3 month high and sold the index when it’s price hit a 3 month low). With a computer, we can easily run the strategy using different parameters for the signal horizon and figure out the set of parameters that results in the best performance. Here are the results. The metric I used to gauge the performance of the strategy is the Sharpe ratio, which measures the return to risk ratio. The higher the Sharpe ratio, the higher the return of the strategy for a given level of risk. The results show that the strategy using 80 days for the maximum rolling window and 110 days for the minimum rolling window has the highest Sharpe ratio of 0.26. Now let’s re-run our simulation using these parameters. The results show that $1 million dollars invested in 2002 would result in slightly over $3.5 million today. That is a whooping 170% higher than the original turtle strategy. The frequency of trades is also much lower, making it easier to implement and incurring lower transaction cost. When it comes to investing, everyone has their own styles and strategies. I rely on systematic strategies because I can simulate their performance and convince myself that they can outperform the market.
Ivann Fok · 1 year, 3 months ago
Navigating the Trade War Between US and China
Thanks to Trump's indomitable will, the markets have been thrown into chaos for the past year with no breakthrough in sight. How can a fundamental investor navigate the waters and position ourselves to make money? In the next few weeks, I seek to answer 3 key questions that every investor should be thinking about right now: Do we remain invested? Which sector is best? Who is the winner?   Do we remain invested? People often quote Warren Buffett but never truly understand how to apply his principles in investing. The first thing we have to understand as investors is that the market is dynamic, and every cycle is unique; what's important is your ability to analyse the facts and weigh the risks before you proceed. So, when Warren Buffett said "Be fearful when others are greedy and greedy when others are fearful", what does he really mean? In a greedy bull market, at what point do you say enough is enough and get out? When Buffett says to be fearful, does he mean we should have the fear of missing out? Some funds prefer to drown out the noise and follow a rational, quantitative strategy - you can't go wrong if you just follow the trend, right? But as a fundamental investor, we should seek to predict the trend, and the only way to do so is to have a view, a conviction. So here's my view on the US-China trade war (I'll operate under the assumption that our readers here are already up to date with the specifics): For the longest time, it has been the DNA of US tech companies is to be in creme de le creme of the value chain. Apple is a classic example - they have not manufactured a single thing in the entirety of the company's history, all the components and final assembly of the iPhone is built in South Korea, Taiwan, and of course China. The simple reason is creating software and designing hardware gives you the highest margins, it is completely asset-light (high recurring FCF generation), and by diversifying your supply chain, you actively reduce your R&D burden and increases your bargaining power with suppliers. We often see Apple's suppliers make razor thin margins, spend millions on R&D only to fail to make the cut as the next supplier, and deal with inventory problems as they expand too fast on production capacity only to be disappointed with low purchase orders. Yet, these companies are only able to do that because 1. labour is cheap in China (workers are literally begging to work over-time to get extra pay), 2. the logistics network has been perfected over the last decade and manufacturers have found a way to increase cost-efficiency in any way possible, and well, 3. the US doesn't want to deal with all the environmental pollution that comes with manufacturing so let's have someone else do the dirty work. The proof is in the pudding - Apple has sustained a ~40% gross margin since the dawn of day, while other smartphone companies are still making a meager 5-10%. Apple is only one of many examples, we can look no further from America's iron grip on the Semiconductors industry (US owns 100% of the global CPU market with Intel & AMD).  Yet, Trump's tariffs is a regressive policy that will destroy the benefits of such globalization - any production relocation will take time (just setting up a factory could take 6-12 months) and all the cost-benefits for US companies discussed above will pretty much be moot. Some components manufacturers I've talked to in my time admittedly would rather take on a 25% tariff than move their production base out of China. So what is Trump thinking by imposing tariffs? What good comes out of relocating manufacturing to the US, and does it really create more jobs? Is toiling away in a factory the American dream? Furthermore, other players like Samsung assemble their smartphones in Vietnam/India, while Huawei hardly has any market share in the US so the tariffs will only serve to graze their ego. Way to go at leveling the playing field for everybody else, Trump. However, when the tariffs on China were announced - the US conveniently put Apple in the tariff-free category. On the surface, Trump may be threatening to throw all of us back into the stone age, but it is clear he knows what he's doing. Protectionism is well and alive. So that tariffs are clearly not an effective way to shut down China - China could simply slap retaliatory tariffs, costs will increase for consumers globally, demand slows down and so does the economy. Furthermore, while tariffs can fuel the US budget for fiscal spending or tax cuts to cushion the impact, they ultimately follow the law of diminishing marginal returns - as the trade deficit between US-China closes, so does the tariffs collected, and now you need the Fed to cut interest rates to prevent a recession. What a complete waste of everybody's time. What do you do when your Plan A doesn't work? Go to Plan B. The US announced in May that Huawei (China's crown jewel) will be blacklisted on the basis of undermining US national security. This really puts Huawei in a bind because the blacklist covers everything under the sun that has at least 25% US origin in their production/formulation. This means that 1. all US products/services are basically cut off from Huawei, 2. any product/service around the world that have some form of raw material / IP sourced from the US are also in play - violation of the blacklist could lead to similar sanctions imposed. So Huawei can't produce any network equipment or smartphones anymore, because 1. US controls pretty much all the key components (Intel, Qualcomm, Broadcom, Xilinx) that cannot be readily replaced by their Chinese counterparts. 2. US controls a lot of IP, so China can only dream about producing their own chips - EDA tools used for chip design supplied by Synopsys/Cadence are now cut off from Huawei, and ARM being unable to license their IP for Huawei's Application Processors limit them in the same capacity. 3. US is light years ahead in software, and Google's compliance means their Android OS which runs 80% of the world's smartphones is no longer available to Huawei in the form of key updates and apps like Gmail, Maps, YouTube etc. Make no mistake, Huawei's 1,000-strong team of software engineers has worked singularly and tirelessly to create their own OS (now dubbed HongMeng) even before the tariffs were in sight, to no avail. When ZTE first got banned, many investors balked at the idea that it would implicate Huawei. Afterall, Huawei is a completely different beast than ZTE, controlling ~25% of the global networking equipment market, and also 13% of the global smartphone market share (and recently overtook Apple as #2) - choking Huawei would be the same as choking the growth drivers of US companies which have seen a steady increase in % revenue mix from China. No single company could snap up Huawei's market share that quickly, and China isn't going to just sit quietly while being roasted. Sure enough, China has announced their own blacklist, targeting any firms that fall under China's definition of engaging in "unilateralism and trade protectionism". Not to mention, China has a history making life difficult for any firms that don't abide by their law, such as imposing tough bureaucracy, compliance checks, outright export control / shutdown of operations. Winter is coming, and I wouldn't like to be Apple, Starbucks or FedEx, just to name a few. Oh, and has everybody forgotten that China controls 70% of the global supply of rare earths? Rare earths are essential to the production of key components such as Semiconductors and Batteries (no wonder China controls >50% of the global EV-battery supply chain, and is the world's No.1 producer of Electric Vehicles). China could very well go down the path of Mutually Assured Destruction (in short, MAD-ness) - if Huawei can't produce, so can't you, World.  However, let's cover all bases. If Trump's aim is to truly decouple the world from China, then someone must fill the void. If we look through our history books, the US has plenty of capacity to be self-sufficient, but they chose not to be. Case in point, the US has been a net importer of crude oil for 75 years until recently, and when they decided to become a net exporter, down came the oil price. If you think about crude oil as a precious and depleting natural resource, you'd want to keep as much of it for yourself as possible. The US soil has enough oil reserves saved up over the years for them to be the last man standing. We could apply the same logic with rare earths - the US was the leading global producer of rare earths from the 1960s to 80s before they shifted out, and current domestic production is only 1% of what the US is capable of. Talk about planning ahead. This current model will work in the favour of the US indefinitely, why risk it now?  Again, we keep in mind that Trump has shown willingness to make tactical adjustments to his game - Huawei has been given a 90-day reprieve on the ban, and with that China has been holding back on opening Pandora's box. So Plan B isn't the best idea, how about Plan C? The Trump administration has stepped up efforts on restricting academic visas and increasing scrutiny on Chinese researchers working in the US. China fires back and issues travel advisory to citizens travelling to the US, and we are already seeing a decline in revenues for US consumer companies such as PVH Corp. or Tiffany & Co. What's next? Does Trump have a Plan D? By now you should be seeing a pattern. Trump isn't fumbling in the dark, he's throwing more chips into this big game of chicken. These are negotiating tools to begin with, and his goal was never to close the trade deficit, or support the farmers (well 51% of his votes needed to come from somewhere, right?). The true aim is to cripple China, who has been growing at blinding speeds and spearheading innovation beyond the likes of US companies (Huawei in 5G, Alibaba in e-commerce, AI from start-ups like Megvii/SenseTime etc.), all on the back of "stealing" US IP, and having unfair trade practices such as giving domestic companies free subsidies, interest-free loans, tax rebates etc. Reading back-and-forth on the trade deal debate, it seems the Trump administration had wanted China to put in writing to block IP transfer of any sort, and ban outright government support to domestic companies - something China claims to infringe on their sovereignty (and let's be honest, Chinese firms would go out of business in a matter of days without the lifelines given by the government at the rate that they are burning cash). Then we take a step back, and we see Trump isn't just picking a fight with China, he's been slapping tariffs on everybody else - the EU, Mexico etc. In EU's case, to cripple Airbus which has been winning the duopoly with US Boeing with what Trump claims to be the help of subsidies from the EU (how about asking Boeing to stop driving their planes into the ground?). In Mexico's case, illegal immigrants and crime. So it is clear that the tariffs are just Trump's method of getting countries to give him what he wants. It's a terrible idea, but it's also the only one he's got.    Let's recap  Trump doesn't want to plunge the world into recession. All is well if countries get bullied into a trade deal, America wins again. If Trump's big gamble doesn't pay off, he's quite likely willing to take a step back. Then the issue here is that China isn't any other nation, and it sure isn't like the country it was 10 years ago. Since Xi's consolidation of power, he's given himself a lifetime on the iron throne. While Trump has limited time, even on the assumption that he gets re-elected in 2020, Xi can outlast him thanks to a convenient constitutional revision. Furthermore, the Chinese economy has never been stronger on the back of Xi's anti-corruption campaign and nationwide book-cleaning / deleveraging. Fun fact: China is the largest creditor of US treasuries (17.3% of total foreign-owned debt), and the Chinese poured in US$46bn/29bn of FDI into the US during 2017/18 compared to the ~US$13bn the US invests into China each year. China has become a proud nation and its people have a strong sense of nationalism with an unrivaled control over money flows. In the long-run, China is on track to overtake the US in technology - the US graduates 50,000 engineers a year, while China is churning out 260,000. Why should China take a knee in a race they are poised to win? As Xi's latest visit to Jiangxi Province would imply, China's new 15-year "long march" has just begun, and it seems like Russia's coming along. Ultimately, the likely scenario is that a trade deal will happen. Trump will concede on some points in the trade deal, and China would have given up a big chunk of their growth at the end of it. However, until then, there's no way of telling when it will happen - my best guess would be by end-3Q19, just as Trump prepares for his 2020 campaign. What does this means for us fundamentalists? If you haven't gotten out of stocks, take some pain and get out. By "get out", I mean everything - stocks, bonds, alternatives, nothing is safe until it is. If we just look back over our shoulder, we have another 15% downside to the recent low of Dec-2018, and that was before additional tariffs came into the picture. The silver lining, however, is that the storm should soon be over and you'll have plenty of time and upside to play catch up. For those who got out early, sit back, relax and enjoy the show. It's time to think about where you want to invest when the time is ripe.  Disclaimer: This post is the culmination of public information and progressive news reports, meant to reflect my personal course of action. Readers should take the time to fact check and review my arguments for themselves before following my recommendation.
MG · 1 year, 8 months ago