Skip to content

Trading Days

Query Source: adopted from here

Introduction

To gauge the effect of an event on market measures like volume and volatility, one simple way is to compare the measures before and after the event. To make a fair comparison, it makes sense to use the same number of trading days in the before and after data sample periods.

One of such events is stock split or reverse split. The most common split ratios are 2-for-1, which means that the stockholder will have two for every share held earlier. Reverse stock splits are the opposite transaction, where a company divides, instead of multiplies, the number of shares that stockholders own, raising the market price accordingly. Three key pieces of information about a stock split is:

  • symbol: the trading identifier of the stock
  • date: the effective date of the split
  • split ratio: how many new shares one existing share is converted to

Question

The function getSplitEvents simulates the stock split events which contain the trading identifier (sym), effective date (date) and the split ratio (splitRatio). The function getDailyVolume simulates the daily volume around the stock split effective date.

getSplitEvents:{
    ([]sym:`ABC`DEF;date:2020.04.08 2020.04.13;splitRatio:0.2 10)
  };

getDailyVolume:{
    dates:2020.03.10+til 50;
    weekdays:dates where 1<dates mod 7;
    tradingDays:weekdays except 2020.04.10;
    nDays:count tradingDays;

    seed:-314159;
    system "S ",string seed;
    volABC:([]sym:nDays#`ABC;date:tradingDays;dailyVolume:nDays?200000+nDays?300000);
    volABC:update floor dailyVolume*0.2 from volABC where date<2020.04.08;

    system "S ",string seed;
    volDEF:([]sym:nDays#`DEF;date:tradingDays;dailyVolume:nDays?800000+nDays?300000);
    volDEF:update dailyVolume*10 from volDEF where date<2020.04.13;

    `date xasc volABC,volDEF
  };

events:getSplitEvents[];
volume:getDailyVolume[];

Find the 5-day Average Daily Volume (ADV) before and after the split event.

Answer

Below is the suggested answer:

/ Find the distinct trading days and sort them in ascending order
tradingDays:`date xasc select distinct date from volume;

/ Find the start date and end date of the 10 trading days around each date
/ Note that the end date is calculated as current date plus 4
/ One implicit assumption is here the tradingDays table is continuous, i.e.
/ no missing trading day in this table.
tradingDays:update startDate:date i-5,endDate:date i+4 from tradingDays;

/ Join the start/end date with the effective date of the stock split so
/ that for each effective date, we know the stop date it need to look
/ backward and forward.
events:events lj `date xkey tradingDays;

/ Join the target data period and effective date with volume data
volume:volume lj `sym xkey select sym,effectiveDate:date,startDate,endDate from events;

/ Keep only volume data within the target data period
volume:select from volume where date within (startDate;endDate);

/ Label each day as before or after the split effective date
volume:update label:?[date<effectiveDate;`Before;`After] from volume;

/ Calculate the average volume by symbol and whether it is before or after the split
select adv:avg dailyVolume by sym,label from volume