<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by 刑无刀 on Medium]]></title>
        <description><![CDATA[Stories by 刑无刀 on Medium]]></description>
        <link>https://medium.com/@xingwudaodao?source=rss-31b3cb9566d8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*rj-hfMXXtdtkq4mZ</url>
            <title>Stories by 刑无刀 on Medium</title>
            <link>https://medium.com/@xingwudaodao?source=rss-31b3cb9566d8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 21:59:55 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@xingwudaodao/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[I Rebuilt alphalens in Rust: The Story Behind Ferric Alpha]]></title>
            <link>https://medium.com/@xingwudaodao/i-rebuilt-alphalens-in-rust-the-story-behind-ferric-alpha-5797a990cdbb?source=rss-31b3cb9566d8------2</link>
            <guid isPermaLink="false">https://medium.com/p/5797a990cdbb</guid>
            <category><![CDATA[quant]]></category>
            <category><![CDATA[factor-analysis]]></category>
            <category><![CDATA[alphalens]]></category>
            <dc:creator><![CDATA[刑无刀]]></dc:creator>
            <pubDate>Thu, 10 Sep 2026 07:06:42 GMT</pubDate>
            <atom:updated>2026-09-10T07:06:42.811Z</atom:updated>
            <content:encoded><![CDATA[<p>This did not start as a “let me build my own wheel” project.</p><p>I simply wanted to run a standard factor analysis workflow.</p><p>If you do quantitative research, the workflow is familiar. You start with a factor: value, momentum, quality, sentiment, analyst revision, or a signal derived from some alternative dataset. Then you align it to your universe and trading calendar. After that, you check whether it predicts future returns across different holding periods, whether the quantile returns are monotonic, whether turnover is acceptable, whether drawdowns are concentrated, and whether the result is stable enough to be worth more work.</p><p>Doing this once in a notebook is not hard.</p><p>Doing it in a way that is credible, reproducible, comparable, and fast enough to run across many experiments is a different problem.</p><p>Someone recommended alphalens.</p><p>That recommendation made sense. alphalens is one of the classic tools in the Python quantitative research ecosystem. It packaged a set of things many researchers repeat every day: cleaning factor data, computing forward returns, forming quantile portfolios, calculating IC, checking quantile returns, measuring turnover, and generating tear sheets. Its API and reports shaped the workflow of many factor researchers.</p><p>But when I opened the project, I ran into another reality:</p><p>alphalens has not been actively maintained for years.</p><p>That does not make it unimportant. In fact, the opposite is true. If people still recommend a project years later, it means the problem it solved was real. But the research environment has changed. Python versions changed. Pandas changed. Dataset sizes changed. Expectations around performance and engineering changed. A core research dependency that is no longer maintained eventually becomes a hidden cost: dependency pinning, compatibility work, environment friction, and performance ceilings.</p><p>So I decided to build a new implementation.</p><p>It is called Ferric Alpha.</p><p>Ferric means iron-bearing, and it naturally hints at Rust. Alpha points directly to quantitative factors. The name is meant to be straightforward: a Rust-built factor analysis toolkit for alpha research.</p><h3>Why Rust</h3><p>The default language for quantitative research tooling is usually Python.</p><p>That is reasonable. Python has a mature data science ecosystem. Researchers are comfortable in notebooks. Pandas, NumPy, SciPy, statsmodels, and Matplotlib are de facto standards. For exploratory work, Python has very low friction.</p><p>But the same workflow also exposes Python’s limits.</p><p>Factor analysis may look like a few notebook cells, but under the hood it is a lot of table computation: grouping by date, aligning by asset, cross-sectional ranking, quantile assignment, correlation, portfolio weights, forward returns, turnover, and grouped statistics. Once the research scale grows, these operations repeat constantly.</p><p>Rust fits that lower layer well.</p><p>It compiles directly to machine code. It has a high performance ceiling. Its memory model is strict enough for long-lived systems code. And through Python bindings, Rust code can still be exposed to researchers as a normal Python package. In other words, researchers do not have to leave their Python workflow, while the core computation can move to Rust.</p><p>Historically, Rust’s biggest obstacle has been its learning curve.</p><p>Ownership, lifetimes, the type system, and error handling are not friendly on day one. That is one reason Rust has remained much less common among researchers than Python, even though it has strong engineering advantages.</p><p>But the situation is changing.</p><p>We now have AI coding tools, Vibe Coding, and much stronger assistance for code generation, explanation, migration, and debugging. Rust’s learning curve has not disappeared, but it is no longer the same blocker it used to be. A person who understands the domain problem can use AI as a coding partner and spend more energy on data structures, algorithm definitions, test fixtures, and behavioral compatibility.</p><p>That is the basic bet behind Ferric Alpha:</p><p>Researchers keep using Python. Rust handles the performance-critical and engineering-heavy parts underneath.</p><h3>This Is Not About Showing Off Rust</h3><p>Ferric Alpha is not meant to be a toy “Rust version” of an existing Python library.</p><p>It is meant to solve a practical research problem:</p><p>I have a factor. I want to know whether it works, where it works, when it breaks, whether transaction costs will kill it, and whether the result can be reproduced.</p><p>The current version already covers a fairly complete factor analysis flow.</p><p>First, data preparation.</p><p>A researcher usually has two inputs. One is factor values, such as a daily signal for each asset. The other is price data, used to compute future returns over holding periods such as 1 day, 5 days, or 10 days. Ferric Alpha provides an alphalens-style preparation API that cleans these inputs into an explicit long-form table. It uses Polars as the core table engine instead of Pandas MultiIndex.</p><p>That design choice matters.</p><p>Pandas MultiIndex is flexible, but in complex workflows it can also make index semantics implicit. Ferric Alpha uses explicit columns such as date, asset, and factor. This is closer to a database or modern columnar engine model, and it gives Rust and Polars a cleaner path for high-performance execution.</p><p>Second, IC.</p><p>IC, or information coefficient, is usually understood as the correlation between factor ranks and future return ranks. If a factor consistently ranks future winners above future losers in the cross-section, its IC should tend to be positive.</p><p>For a researcher, IC is an early screening metric. You should not launch a strategy just because IC looks good. But if a factor shows no signal across holding periods and market regimes, it probably does not deserve much more time.</p><p>Ferric Alpha supports IC and mean IC. It helps answer practical questions: Does this factor have predictive power over 1-day, 5-day, or 10-day forward returns? Is the signal stable? Does it only appear in a short window?</p><p>Third, quantile returns.</p><p>Many researchers want a more intuitive view than correlation. If I split the universe into 5 or 10 buckets by factor value, does the top bucket outperform the bottom bucket?</p><p>Ferric Alpha supports mean return by quantile. It groups assets by factor quantile and computes the future return for each group. This is a useful early diagnostic. A good factor often shows not only a strong top bucket but also some degree of monotonicity from low to high quantiles.</p><p>If bucket 5 beats bucket 1 but the middle buckets are noisy, the result may be driven by outliers or an unstable sample.</p><p>Fourth, factor weights and factor returns.</p><p>When you want to turn a signal into a long/short portfolio, you need weights. For example: long high factor values and short low factor values. Or group neutral weights to reduce unwanted industry or group exposure.</p><p>Ferric Alpha supports factor weights and factor returns. It can construct portfolio weights from factor values and then compute the resulting portfolio returns across forward return periods. This moves the analysis closer to strategy research. It is no longer only asking whether the signal correlates with future returns. It asks what the return series would look like if you actually formed a portfolio from the signal.</p><p>Fifth, alpha and beta.</p><p>A factor portfolio may generate returns because the factor is useful, or because the portfolio simply has market exposure. If a portfolio looks profitable but is mostly a high-beta position in a rising market, its research value needs to be reassessed.</p><p>Ferric Alpha supports alpha/beta analysis. It lets researchers compare factor portfolio returns with a benchmark or market return. This metric does not make the final decision for you, but it helps separate factor skill from market exposure.</p><p>Sixth, turnover and rank autocorrelation.</p><p>This part is often underestimated.</p><p>If a factor’s ranking changes aggressively every day, paper returns may look good while real trading gets eaten by turnover and market impact. On the other hand, if the ranking is stable, rebalancing pressure is lower and the signal is easier to implement.</p><p>Ferric Alpha supports quantile turnover and factor rank autocorrelation. Quantile turnover measures membership changes in factor buckets. Rank autocorrelation measures how stable cross-sectional factor ranks are over time. Together, they help identify factors that look attractive in research but may be hard to trade.</p><p>Seventh, tear sheets and visualization.</p><p>Research is not only for machines. Whether a factor deserves more work is usually discussed by researchers, portfolio managers, traders, risk managers, and engineers. The result needs to be readable.</p><p>Ferric Alpha can generate a serializable tear sheet data model and render native HTML, SVG, and PNG. The default rendering path does not require Matplotlib, Pandas, Seaborn, SciPy, or statsmodels. You can display it inside a notebook or generate a self-contained HTML report for sharing.</p><p>This may sound like “just plotting”, but it has a real impact on research speed. A good tear sheet lets you quickly inspect whether IC is stable, whether quantile returns are monotonic, whether portfolio returns are concentrated in a few periods, whether turnover is too high, and whether rank autocorrelation looks healthy.</p><h3>Why Polars Instead of Recreating Pandas</h3><p>Ferric Alpha provides a Python API, but Pandas is not the core table engine.</p><p>The default runtime dependency is Polars.</p><p>The reason is direct: Polars is a modern columnar data engine. It has strong expression semantics, good performance, and a natural fit with Rust. Its design also matches Ferric Alpha’s direction: explicit schema, columnar computation, and fewer hidden index behaviors.</p><p>This is not an argument that Pandas is bad. Pandas remains one of the most important tools in Python data analysis. But if I were starting a new high-performance factor analysis library today, I would rather build the core abstraction on explicit long-form data and Polars.</p><p>For users, the intended result is simple:</p><ul><li>The API remains callable from Python.</li><li>Inputs and outputs are more explicit.</li><li>There is less hidden index behavior.</li><li>Grouping, sorting, aggregation, and correlation can use a more suitable execution layer.</li><li>The design is easier to extend to larger datasets over time.</li></ul><h3>Performance Compared With alphalens</h3><p>One of Ferric Alpha’s goals is to preserve a familiar research experience while improving the underlying computation layer.</p><p>The repository includes a reproducible benchmark against alphalens. The test uses the same deterministic long/short factor fixture for both engines. It measures function execution time only; fixture construction is outside the timed block.</p><p>Benchmark setup:</p><ul><li>Machine: Apple silicon macOS 26.3.1</li><li>Dataset: 250 assets, 252 sessions, 63,000 factor rows</li><li>Forward returns: 1D and 5D</li><li>ferric-alpha: 0.1.0, release build, Python 3.13.4, Polars 1.42.1</li><li>alphalens: 0.4.0, Python 3.9.25, Pandas 1.5.3, NumPy 1.23.5</li></ul><p>Ferric Alpha is faster across several core metrics:</p><ul><li>factor_information_coefficient: Ferric Alpha 13.616 ms, alphalens 124.205 ms, about 9.1x faster</li><li>factor_returns: Ferric Alpha 11.778 ms, alphalens 46.425 ms, about 3.9x faster</li><li>factor_weights: Ferric Alpha 15.153 ms, alphalens 43.330 ms, about 2.9x faster</li><li>mean_return_by_quantile: Ferric Alpha 21.022 ms, alphalens 60.900 ms, about 2.9x faster</li><li>quantile_turnover: Ferric Alpha 3.018 ms, alphalens 6.136 ms, about 2.0x faster</li><li>factor_rank_autocorrelation: Ferric Alpha 6.823 ms, alphalens 15.497 ms, about 2.3x faster</li></ul><p>The most interesting case is factor_rank_autocorrelation.</p><p>In an earlier implementation, this metric was not faster than alphalens. The issue was not Rust itself. The issue was the data structure. If each date and asset requires repeated map lookups with string keys, a lot of the performance advantage disappears.</p><p>The newer implementation adds a dense-matrix fast path for complete date-by-asset panels. Assets are encoded once, each date occupies one contiguous matrix row, and lagged rows are correlated directly. This avoids large amounts of per-date string-map overhead.</p><p>At the same time, the optimization does not drop compatibility. Sparse panels, changing universes, null factors, and non-finite values use the general compatibility path.</p><p>The optimized path was also checked against an alphalens oracle. On a shuffled 80-session by 37-asset panel with tied factor values, lags 1, 3, and 10 matched alphalens 0.4.0 exactly in null positions. The maximum absolute numeric difference was 1.11e-16, within a 1e-12 tolerance.</p><p>That is the engineering style I want for Ferric Alpha: not only making things fast, but being able to explain why they are fast and verify them against a trusted behavioral baseline.</p><h3>Who Should Try It Now</h3><p>Ferric Alpha is still pre-alpha.</p><p>That is worth saying plainly. It is not yet a battle-tested library that can blindly replace every internal research infrastructure component. The 0.1.x releases are intended for early factor research, API feedback, and compatibility validation.</p><p>If you are a quantitative researcher, it is already useful for:</p><ul><li>Checking IC and mean IC for a factor.</li><li>Inspecting forward returns by quantile.</li><li>Building long/short factor returns.</li><li>Analyzing alpha and beta.</li><li>Measuring quantile turnover and rank autocorrelation.</li><li>Generating a shareable native HTML tear sheet.</li><li>Keeping a Python research workflow while moving core computation into Rust.</li></ul><p>If you are a quantitative engineer, you may be more interested in:</p><ul><li>How to implement factor analytics with Rust and Polars.</li><li>How to provide a low-friction Python API for researchers.</li><li>How to migrate classic alphalens behavior onto a modern computation layer.</li><li>How to use oracles and golden fixtures for compatibility checks.</li><li>How to make visualization, reports, and notebook output maintainable.</li></ul><p>If you need a fully mature, feature-complete, long-proven library today, you should still be cautious. Ferric Alpha’s value is that it is early, but the direction is clear: rebuild the alphalens-style factor analysis experience with Rust underneath and Python at the user boundary.</p><h3>What I Want Ferric Alpha to Become</h3><p>The core value of alphalens was that it standardized a set of common factor research questions.</p><p>Ferric Alpha aims to inherit that idea while rebuilding the foundation:</p><ul><li>Rust for performance-sensitive computation.</li><li>Polars for modern columnar data processing.</li><li>Python APIs for familiar research workflows.</li><li>Native HTML/SVG/PNG tear sheets as a lightweight default output path.</li><li>Tests, oracles, and benchmarks as behavioral constraints instead of migration by intuition.</li></ul><p>I do not think the point is “Rust replaces Python”.</p><p>The better framing is that Rust and Python should each do what they are good at. Python remains excellent for exploration, expression, and notebook workflows. Rust is strong for core computation, performance, and maintainable systems code.</p><p>As AI coding tools improve, this combination will become more common. In the past, many teams avoided Rust because the learning cost and staffing cost were too high. Now AI can reduce the cost of experimentation and migration enough that domain experts can realistically build high-performance lower-level libraries.</p><p>Ferric Alpha is one attempt in that direction.</p><h3>Try It, Open Issues, or Star the Project</h3><p>GitHub:</p><p><a href="https://github.com/xingwudao/ferric-alpha">https://github.com/xingwudao/ferric-alpha</a></p><p>Documentation:</p><p><a href="https://xingwudao.github.io/ferric-alpha/">https://xingwudao.github.io/ferric-alpha/</a></p><p>Install:</p><pre>pip install ferric-alpha</pre><p>A minimal Python flow looks like this:</p><pre>import ferric_alpha as fa</pre><pre>factor_data = fa.get_clean_factor_and_forward_returns(<br>    factor=factor,<br>    prices=prices,<br>    quantiles=5,<br>    periods=[1, 5, 10],<br>)</pre><pre>mean_ic = fa.performance.mean_information_coefficient(factor_data)<br>quantile_returns = fa.performance.mean_return_by_quantile(factor_data)<br>report = fa.tears.create_full_tear_sheet_data(factor_data)<br>fa.plotting.render(report).save(&quot;factor-report.html&quot;)</pre><p>If you work on quantitative research, factor discovery, portfolio construction, or Rust + Python financial data tools, I would appreciate your feedback.</p><p>Issues are welcome.</p><p>I am especially interested in:</p><ul><li>Which alphalens behaviors you want prioritized.</li><li>Where the current Python API feels awkward.</li><li>Whether the Polars input/output model fits your workflow.</li><li>Which charts and tables are still missing from tear sheets.</li><li>Which real-world data sizes expose performance bottlenecks.</li><li>Where the documentation and quickstart need to be clearer.</li></ul><p>If the direction is useful to you, a GitHub star also helps.</p><p>For an open-source project, a star is not just vanity. It helps other people with the same problem discover the project, and it helps the project attract more real usage feedback.</p><p>Ferric Alpha is still early, but it can already run a complete factor analysis workflow. The next step is to keep improving compatibility, stability, documentation, examples, and performance.</p><p>A project that has not been actively maintained for years, but is still recommended again and again, is itself a signal:</p><p>The problem still matters.</p><p>Ferric Alpha is an attempt to revisit that problem seriously with today’s toolchain.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5797a990cdbb" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>