Back to Insights

Handling Corporate Actions in Historical Data for Backtesting"

By Virexan Research Topic: Adjusted data for backtesting"

Handling Corporate Actions in Historical Data for Backtesting

"My strategy made 1000% return on ITC last year!"

The client was ecstatic. We looked at his backtest. He was using raw data for ITC (Indian Tobacco Company). In June, the stock price "dropped" by 50% overnight. His short-selling bot made a killing.

The reality? It was a Stock Split, not a crash. His strategy actually lost money.

This is the hidden killer of quantitative strategies: Corporate Actions. If your data pipeline doesn't handle dividends, splits, rights issues, and bonus shares correctly, your backtest is worthless.

At Virexan Capital, we spend more engineering hours on data integrity than on strategy logic. Here is why.

The Types of Data Adjustment

There are two ways to store historical price data:

    li> Raw (Unadjusted): The actual price traded on that day.

  • Adjusted: The price mathematically modified to account for corporate actions.

1. Stock Splits & Bonus Issues


If a stock trading at ₹1000 undergoes a 1:10 split, the price becomes ₹100.
    li> Raw Data: Shows a 90% crash.

  • Adjusted Data: Divides all historical prices by 10. The chart looks smooth.
The Trap: If you initiate a trade based on "Price Growth," you MUST use Adjusted Data. If you calculate P&L, you MUST use Raw Data (because you actually bought at ₹1000, not ₹100).

2. Dividends

A stock trading at ₹100 pays a ₹5 dividend. The price drops to ₹95 on the ex-dividend date.
    li> The Trap: A Mean Reversion bot sees a 5% drop and buys. But there was no real drop in value; cash just moved from the company to the shareholder.
  • The Fix: Backward adjustment of all historical prices by the dividend percentage.

The Engineering Challenge: "Point-in-Time" Data

Professional backtesting engines at Virexan Capital don't just use one dataset. We use a Point-in-Time (PIT) database.

Why?
Imagine you are testing a strategy that buys "Low P/E Stocks."

    li> Today (2024), we know Reliance's earnings for Q4 2023.

  • But on Jan 1, 2024, those earnings hadn't been released yet.

  • If your backtest uses the Q4 earnings to make a decision on Jan 1, you are cheating (Look-Ahead Bias).
Our Architecture:
We store data with "Knowledge Dates."
    li> Date: 2024-01-01 | Earnings: NULL

  • Date: 2024-01-15 | Earnings: Released

The backtest simulates exactly what data was available on that day*.

Coding the adjustments (Python)

Calculating adjustment factors is tricky. The formula for a split is simple (Factor = Old Shares / New Shares). Dividends are harder.

Virexan Standard:
We generally recommend Total Return Data for backtesting performance (assumes dividends are reinvested) but Raw Price Data for signal generation (because indicators like RSI are technical, not fundamental).

def adjustprice(rawprice, adjustment_factor):
    """
    Adjust historical price for splits/bonuses.
    Factor = 0.5 for a 2-for-1 split.
    """
    return rawprice * adjustmentfactor

Why Free Data Sources Fail

APIs like Yahoo Finance often provide "Adjusted Close" but they overwrite history silently.

    li> On Monday, the history for 2020 is X.

  • On Tuesday (after a split), the history for 2020 is Y.

  • If you stored Monday's data locally, your database is now corrupt.
The Virexan Solution:
We build ETL (Extract, Transform, Load) pipelines that re-sync historical data nightly from reliable vendors (like Bloomberg or reputable exchange feeds) to detect and apply new adjustment factors.

Don't Let Bad Data Ruin Good Logic

A strategy is only as good as the data it runs on. If you are serious about automated trading, stop using free CSVs you found online.

Build a robust data infrastructure.

Contact Virexan Engineering to audit your data pipeline.

---

Related Articles


Need This Logic in Your Portfolio?

We don't just write about algorithms; we build them. Hire **Virexan Capital** to engineer your custom trading infrastructure.

Start a Discussion View Services