Analyzing Factor Performance with Alphalens: Foreign Capital Factor Edition

Key Highlights of This Article

  • Basic Introduction to Alphalens
  • Overview of Foreign Capital Factors

Preface

You’ll inevitably encounter numerous factor strategies, whether you are an experienced trader or a beginner. By selecting factors that closely correlate with market performance, investors can more effectively predict asset returns and find stable sources of income in uncertain market environments. The essence of factor strategies lies in simplifying complex market phenomena into a few quantifiable drivers, helping us understand capital flows and risk distribution. These factors reveal the roots of market volatility and provide practical decision-making tools for investors.

This series of articles will use Alphalens to explore several key factors, gradually analyzing their impact on market performance. The first article focuses on “foreign capital,” examining the effects of foreign capital flows into the market. Next, we’ll delve into “value factors,” studying how they reflect a company’s intrinsic value. Finally, the last article will analyze “price-volume factors,” uncovering the interplay between price and trading volume.

If you’re interested in conducting similar factor analyses, you can use the alphalens-tej tool in TQuant Lab. By seamlessly integrating TEJ data and eliminating the need for complex data processing, this tool enables you to quickly evaluate factor performance and further support the development of your investment strategies.

What is Foreign Capital Factor

In China’s A-share market, “northern-bound funds,” entering the Chinese market through the Shanghai-Hong Kong Stock Connect and Shenzhen-Hong Kong Stock Connect, are regarded as direct indicators of foreign investors’ sentiment toward the Chinese market. These capital flows are often used to monitor market trends and have demonstrated significant influence in related studies. Consequently, northern-bound factors receive considerable attention and application in the Chinese market.

When analyzing northern-bound factors in Taiwan’s stock market, we can observe the changes in foreign holdings across different industries or individual stocks. Foreign investors account for a relatively high proportion of trading volume in the Taiwan market and have a notable impact on market movements. Due to the substantial scale of foreign capital, their buying and selling activities often drive short-term market fluctuations. This is particularly evident in specific industries or leading stocks, where these activities better reflect foreign investors’ preferences and capital flows. By tracking the changes in foreign capital factors, we can more accurately identify trends for asset allocation and even capture early warning signals of market risks.

Factors Used in This Article:

5-Day Change in Foreign Ownership Ratio

  • Formula: The change in “foreign ownership ratio” over the past 5 days.

5-Day Net Inflows

  • Formula: The total “foreign buying amount” over the past 5 days.

Data Source:

The data used in this article is sourced from the TEJAPI “Transaction Data — Chip Data (Daily)” table (TWN/APISHRACT). The fields utilized are “foreign ownership ratio” and “foreign buying amount (in TWD).”

Introduction to Alphalens

The Alphalens-tej package in TQuant Lab is a Python toolkit for factor analysis. Its core functionality assists investors in reviewing and evaluating factor performance, thereby formulating more effective factor strategies. For detailed instructions, refer to Alphalens. ipynb.

In quantitative investing, factors are indicators used to explain and predict asset returns. Common factors include the price-to-earnings ratio (P/E), price momentum, trading volume, etc.

Alphalens provides a series of powerful visualization tools and metrics, such as:

  • Mean Period Wise Return by Factor Quantile
  • Information Coefficient (IC)
  • Cumulative Returns by Quantile

These features help investors better understand a factor’s predictive power and stability. With Alphalens, investors can quickly analyze the performance of various factors under different market conditions and identify the factor combinations or strategies most suitable for them.

Furthermore, Alphalens integrates seamlessly with TEJ data, making it ideal for conducting factor backtesting and visualization analysis using TQuant Lab. This integration dramatically enhances the convenience and efficiency of factor research.

Single Factor Analysis

Due to space constraints, this section focuses only on calculating the factor’s IC (Information Coefficient) and IR (Information Ratio, i.e., risk-adjusted IC) and plotting bar charts of the average returns for each factor quantile.

The data sample period used in this article spans from 2014 to 2024, and the stock pool consists of the top 100 market-cap stocks among all listed companies.

IC, IR Values, and Average Returns for Each Factor (Holding Period: 1 Month)
IC, IR Values, and Average Returns for Each Factor
(Holding Period: 1 Month)

Mean Return

  • This column shows the average return for each factor.
  • A negative value indicates that the factor’s overall performance during the holding period resulted in a negative return.

IC Mean

  • Represents the average Information Coefficient (IC), reflecting the correlation between the factor values and asset returns.
  • A positive IC Mean indicates a positive correlation, while a negative value indicates an inverse correlation.
  • Generally, the higher the absolute value of IC Mean, the stronger the factor’s predictive power.

IC Std

  • Refers to the standard deviation of IC values, indicating the volatility of IC.
  • A higher IC Std suggests lower stability in the factor’s predictions, whereas a lower IC Std indicates more consistent predictive performance.

IR (Information Ratio)

  • Calculated as the ratio of IC Mean to IC Std, representing the risk-adjusted performance of the factor.
  • The higher the absolute value of IR, the more stable and reliable the factor is in predicting asset returns.

IC > 0.03

  • This column represents the proportion of times the factor’s absolute IC value exceeds 0.03.
  • A higher proportion indicates a greater likelihood of the factor demonstrating stable correlations over time, confirming its predictive effectiveness across various periods.
Average Returns By Factor Quantile (5-Day Change in Foreign Ownership Ratio)
Average Returns By Factor Quantile (5-Day Change in Foreign Ownership Ratio)
Average Returns By Factor Quantile (5-Day Net Inflow)
Average Returns By Factor Quantile (5-Day Net Inflow)
  • Horizontal Axis: The horizontal axis represents the factor groups (Quantiles), which are divided into ten groups based on the size of the factor values. Group 1 contains the stocks with the lowest factor values, while Group 10 contains those with the highest.
  • Vertical Axis: The vertical axis represents the average return of each group, measured in basis points (bps), which is one ten-thousandth of a percent. This value reflects the average return over a specific holding period (in this case, 1 day).
  • Explanation: This chart illustrates the average return for each group during a one-day holding period. If the factor has predictive power, we generally expect the returns to show a monotonic trend, with Group 10 having higher average returns and Group 1 having lower average returns. This pattern can be used to construct a long-short portfolio.

Based on the table “IC, IR Values, and Average Returns for Each Factor,” neither of these factors demonstrates strong IC or IR values. Generally, a good factor should have an IC greater than 0.05 and an IR greater than 0.3. Therefore, these two factors show a low correlation with asset returns and need more stable predictive ability.
The “Average Returns by Factor Quantile Bar Chart “ also shows that these two factors are unable to effectively predict or indicate asset return trends. Typically, in the bar chart, we aim to see monotonicity in the factor, meaning that larger factor values correlate with higher returns or smaller factor values correlate with lower returns. Factors with this characteristic can support the construction of investment strategies with more stable and consistent returns.

Factor Synthesis

In the previous section, we observed that the predictive effectiveness of the “5-day holding proportion change” and “5-day net inflow” factors was suboptimal. Therefore, this section will attempt to synthesize these two factors and examine whether the predictive power improves after synthesis.

Calculating Factor Weights

When synthesizing multiple factors, assigning appropriate weights to each factor is crucial due to their varying explanatory power for future returns. Proper weighting enhances both the predictive performance and stability of the composite factor.

In this article, rank IC_IR is used to calculate factor weights. The rank IC_IR is determined by dividing the IR ratio of an individual factor (calculated over the past month) by the sum of the IR ratios for all factors. This provides the relative weight of each factor. Based on risk-adjusted IC, this weighting method assigns greater weight to factors with higher predictive power and stability.

To simulate the delay of factor signals in real-world trading, the final weight data is lagged (shifted) by one day. This ensures that only data from the previous period is used, thereby avoiding the use of future information in the model.

This approach aligns the synthesized factor with practical trading scenarios, improving its robustness and applicability in real-world investment strategies.

Daily Factor Weight
Daily Factor Weight

Factor Synthesis Methodology

Calculating the composite factor involves generating a single composite factor by taking a weighted average of each factor based on its assigned weight, representing the overall effect of all aspects.

Detailed Steps:

  1. Align Data: First, align the raw factor data with the index of the weight data. Fill any missing values with 0 to ensure data completeness.
  2. Weight Factors: Calculate each factor’s weighted value by multiplying its raw value by the corresponding pre-computed weight.
  3. Compute the Weighted Average: Specifically, the weighted average is calculated by multiplying each factor’s original value by its corresponding weight and then summing these values to produce the composite factor.
  4. Resulting Composite Factor: The composite factor generated through this process accounts for the relative importance of each factor, providing a more stable predictive effect in multi-factor strategies.

Using this method, the composite factor reflects the relative significance of the individual factors and their collective predictive power, enhancing stability and effectiveness in multi-factor strategies.

Raw Factor Data
Raw Factor Data
Composite Factor Data
Composite Factor Data

Analysis of Composite Factors

Similar to single-factor analysis, we will also import the new composite factor data into Alphalens for evaluation.

Average Returns By Composite Factor Quantile
Average Returns By Composite Factor Quantile
  • Horizontal Axis: Represents the quantiles (1 to 10), where higher quantiles indicate larger composite factor values.
  • Vertical Axis: Represents the average return for each quantile in basis points (bps).
  • Color Labels: Different colors indicate the holding periods, showing how the composite factor’s performance varies over time.
Cumulative Returns By Holding Period
Cumulative Returns By Holding Period
  • Horizontal Axis: Represents the years, showing the time evolution of cumulative returns.
  • Vertical Axis: Displays the log cumulative returns, where higher values indicate greater accumulated returns.
  • Color Labels: Different colored lines represent the cumulative returns for specific quantiles (e.g., Quantile 1, Quantile 5, Quantile 10).

Due to the calculation method of cumulative returns in Alphalens, only the cumulative returns for a 1-day holding period are presented in the line chart. These charts show that the composite factor’s predictive power significantly surpasses that of the individual factors before synthesis.
The results show that the 10th quantile achieves the highest returns, while the 1st quantile has the lowest returns. Furthermore, the returns across quantiles exhibit a clear monotonic increasing trend.
Based on these findings, we can further explore constructing a long-short hedge portfolio by going long on stocks in the 10th and shorting stocks in the 1st quantile. This approach aims to maximize returns through effective portfolio hedging.

Conclusion

Through the analysis in this article, we demonstrated how to use Alphalens to evaluate factor performance and apply it in practical investment strategies. Initially, the IC and IR analyses of single factors revealed that the “5-day holding proportion change” and “5-day net inflow” factors performed poorly in predicting asset returns. The quantitative results also indicated a need for more stable monotonicity, making constructing effective long-short hedge strategies challenging. However, we observed a significant improvement in predictive power by synthesizing these factors into a composite factor.
In the composite factor analysis, a clear monotonic relationship between factor values and asset returns was evident, with higher quantiles achieving higher average returns. This monotonicity makes the composite factor well-suited for long-short hedge strategies, enhancing investment portfolios’ stability and return potential. Overall, this article illustrated the process from single-factor analysis to composite factor construction and backtesting, strengthening factor predictive power while reducing strategy risk to some extent.
In the future, practical applications could explore more advanced factor integration methods and alternative weight calculation approaches. Additionally, incorporating considerations such as slippage and transaction costs would further assess the strategy’s real-world feasibility. With these refinements, multi-factor strategies will be better equipped to adapt to market volatility and consistently create value in dynamic market environments!

Start Building Portfolios That Outperform the Market!

Extended Reading

Relevant Links

Back
Procesing