iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
🤖

Fundamentals of Score Design for Systematic Trading

に公開

Introduction

We operate a Discord community for botters (automated traders) called Makedeco, who primarily utilize stock market APIs to build analysis and prediction models. This community is supported by JPX Market Innovation & Research, Inc. and AlpacaJapan.

https://market-api.dev/

While planning various events within Makedeco, I realized that foundational knowledge regarding the "scores" generated by machine learning models isn't widely shared. That realization prompted me to write this article.

Regarding past materials, the Stock Analysis Tutorial I created with JPX Market Innovation & Research, Inc. covers various topics comprehensively. However, that tutorial follows the format of a stock analysis competition held on SIGNATE and is written with the premise of generating scores for a specific competition task. (Note: I previously summarized how to design such stock analysis competitions, so please check it out if you're interested.)

When performing system trading, you also design these scores yourself, but it differs slightly from competition-based score design. Well, the essence is the same, but among many approaches, the common problem-solving design for formulating a stock investment strategy is to first design a score to assist in stock selection.

In competition design, because you are competing for points, the problem design and score design are almost synonymous. In contrast, while system trading involves diverse approaches, conducting stock analysis through score design has high affinity with data science methods. This article summarizes basic score design as a starting point for system trading.

Furthermore, the J-Quants API, which allows for retrieving Japanese stock data, is set to provide various premium data similar to what institutional investors use. This should open up opportunities for individual investors to consider investment strategies using data that was previously difficult to access. If you're interested, please join the Makedeco event on March 23rd!

https://mkdeco.connpass.com/event/273256/

How to Use Calculated Scores

In this article, a "score" refers to assigning a value to stocks within an investment universe—for example, assigning 0.3 to Stock A and 0.5 to Stock B in a 1:1 mapping. Once scores are calculated for multiple stocks, we assume they will be used in system trading as follows:

Including High-Scoring Stocks in the Investment Portfolio

With the expectation that scores correlate with future returns, high-scoring stocks are included in the investment portfolio. However, purchasing too many high-scoring but high-risk stocks can worsen performance from a return/risk perspective. Therefore, scores are often adjusted for risk (e.g., divided by the standard deviation of daily returns), and ingenuity is required in stock selection, such as deciding whether to use risk-adjusted scores.

Excluding Low-Scoring Stocks from the Investment Portfolio

If a score correlates with future returns, a low score indicates a high probability that the price will drop. Even when investing in a specific group of targets, scores can be used to exclude low-scoring stocks from that group.

Synthesizing Multiple Scores to Build New Strategies

When you have designed two good scores, you may want to calculate overall returns using a combined score while measuring the effect of each. In such cases, you add the scores together. It is helpful to adjust scores to be zero-mean when combining them; therefore, standardizing them with tools like StandardScaler is often convenient.

How are scores calculated?

I believe there are three representative approaches to calculating scores:

Method Description
Technical Analysis Technical analysis that allows for comparison across all stocks, such as the moving average deviation rate, can be used as a score as is.
Fundamental Analysis A method to generate normalized scores comparable between stocks based on fundamentals like ROE. This is a classic approach with numerous previous studies.
Machine Learning Models The method of generating scores using machine learning, which is frequently discussed in Makedeco.

When performing technical analysis, it is important to use technical indicators that allow for relative comparison with other stocks, such as the moving average deviation rate mentioned above. For example, while moving averages are useful for plotting on charts, they are not helpful as scores because they cannot be compared between stocks. It is crucial to use the moving average deviation rate instead of the moving average itself as a score; this applies to all technical analysis. If a value is comparable across stocks, it is possible to verify how much impact that value has on profitability. For instance, using evaluation methods reveals that the 200-day moving average deviation rate is reasonably effective.

Fundamental analysis is a bit more difficult because averages vary by industry, making direct comparisons tricky. However, it is common to define a stock universe in some way and then create scores by normalizing the data. Comparing stocks through fundamental analysis requires considerable expertise, so it is recommended to refer to literature such as factor investing. For example, reading this paper explains what to keep in mind when using ROE as a score.

How to Evaluate Scores?

When evaluating an investment strategy, it is essential to use an evaluation method that matches the strategy's purpose (e.g., day trading, long-term investment). In most cases, scores are evaluated against future price movements. These "future price movements" can be calculated in various ways depending on the purpose. Below are representative methods I have used in various projects, where the rate of change from the entry price to the exit price is calculated as the future price movement.

Entry Price Exit Price Use Case
Opening price of the next business day / Opening price of the afternoon session Closing price of the next business day Measured to verify if the score's effectiveness is valid within the same day. This is the basic score for intraday trading and has the highest reproducibility for machine learning.
Closing price of the next business day Closing price two business days later Measures whether the score's effectiveness persists overnight. Used for swing trading or to measure the basic performance of a score. This score was also used in Kaggle competitions.
Closing price of the next business day Closing price after one week or more Measures whether the identified effectiveness persists over multiple days. The target period varies depending on the strategy.
Closing price two business days later Closing price after a long period (one month or more) Used to verify that profitability does not depend on anomaly-like movements occurring the next day by using the closing price two business days later as the entry price. Adopted for verifying effectiveness in long-term investments, such as on a quarterly basis.

After defining these future price movements, scores are evaluated using the following methods.

Calculating Rank Correlation: Score vs. Future Price Movement

If the calculated score contains useful information regarding future returns—assuming that stocks with higher scores have higher future returns—the rank correlation will be greater than 0 (or less than 0 if a negative effect is expected).

To quantify this result, you can calculate the rank correlation between the score and the future price movement. This is a traditional metric that was temporarily adopted by Numerai (although their rules are now more complex). If you design a score where the ranking of stocks is similar to the ranking of their future returns, this value will be higher, making it an easy-to-understand metric for predictive performance. Note that most scores, when first created, will have a rank correlation near 0 relative to future price movements. Be aware that if you see a correlation of 0.1, it's highly likely to be an exceptionally good score.

For those who want to study this area comprehensively, I recommend reading UKI's articles.

https://qiita.com/blog_UKI/items/25dc1c2559c61890a449
https://qiita.com/blog_UKI/items/09fab7baecd677819895
https://qiita.com/blog_UKI/items/c718334247a083f250c7

Calculating the Spread of Returns for Each Quantile

Another major method is calculating the spread of returns for each quantile.

This is an evaluation method using the quantiles of scores for a universe of stocks. It assesses the difference in returns (profitability) obtained by continuously investing in the top X% and bottom X% of stocks based on the generated scores. In the quantitative approach, this is likely the most commonly used validation method to check first when evaluating features.

The procedure is slightly complex, so I won't go into detail about the calculation method in this article. However, if the score is working correctly, the expected outcome is that the P&L spread between each quantile return will widen over time, as shown above. In other words, you can confirm that high-scoring stocks are generating P&L while low-scoring stocks are not.

Conclusion

I have summarized the basic score design for starting system trading. This content is a written version of the materials used in the "Stock Analysis Seminar for Beginners: Everything from Data Analysis/Model Creation to Evaluation!" held at Makedeco on Wednesday, September 28, 2022.

https://speakerdeck.com/gamella/zhu-shi-nosisutemutoredochu-xin-zhe-nozui-chu-no-bu-ping-jia-fang-fa-wozhong-xin-ni

If you are interested in methods for generating scores, I have also summarized how to promote projects using machine learning, so please take a look at that as well.

https://zenn.dev/gamella/articles/3cd1bf254b68b8

Discussion