Skip to content
All library documents

Why Daily Data Cannot Be Converted into Tick or Volume Bars

Article Quant Q&A · Author: Occhima

Summary

The document explains why daily forex observations cannot be transformed into tick bars or volume bars. Daily prices are aggregates of underlying market activity, so they do not retain the sequence of individual quotes, trades, or trade sizes needed to construct those event-based bars. Recovering that detail requires a source that supplies sufficiently granular trade data.

Given timestamped trades with prices and sizes, the document describes three aggregations: time bars group records into fixed intervals and calculate price OHLC values and total size; tick bars group a fixed number of records; and volume bars group trades according to cumulative traded size. These are practical pandas-style procedures, but the examples assume an available trade-level dataset. They cannot recreate missing trades from daily returns, and the method’s usefulness depends on the quality and completeness of the input feed. The discussion also distinguishes a price change from the underlying tick or trade record, a distinction important when choosing data for bar construction.

Key ideas

  • Daily aggregates do not contain enough information to reconstruct the individual trades or quotes that formed them.
  • Tick bars group a fixed number of trade records, while volume bars group records by cumulative traded size.
  • Time bars aggregate trade data into fixed clock intervals and can summarize prices and traded size.
  • Constructing these bars requires granular timestamped trade data with price and size fields.
  • The resulting bars reflect the input feed and its definitions, so data quality constrains the analysis.

Tags

Full text
# Converting time bars to tick bars or volume bars in python


# Converting time bars to tick bars or volume bars in python












Recently I've started reading Advances in Financial Machine Learning by Marcos Lopez de Prado. In the second chapter the author defines some essential financial data structures, like tick bars, volume bars, etc. I was wondering how I could transform a series of daily returns of forex data, acquired using `yfinance` lib for `python 3.7`, in to any kind of those bars de Prado mentions.

Below, I'll leave the snippet I used to get the data.

```
import yfinance as yf

df = yf.Ticker("BRL=X").history(period='max').Close.pct_change().dropna()
```

## Answer by chrisaycock (score 7, accepted)

https://quant.stackexchange.com/a/54495

As mentioned in my comment, tick data is the individual quotes and trades; Yahoo only has daily data. As an analogy, you can always make a high-definition photo more blurry and pixelated, but you can't add detail and definition to a bad picture. Daily data is just an aggregate of individual ticks, so you can't get the individual ticks from daily data.

You will need a different source for tick data, and those are usually commercial. (Vendors sell to professional traders, after all.)

With that said, once you do get some tick data, aggregations are pretty straightforward. I've included some pandas code here for posterity; this assumes a trades Dataframe with price and size columns, indexed by timestamp.

#### Time Bars

Just give the frequency you desire. Here is an example of five-minute bars:

```
trades.groupby(pd.Grouper(freq="5min")).agg({'price': 'ohlc', 'size': 'sum'})
```

#### Tick Bars

We'll define a helper function to round-down to the nearest integer:

```
def bar(xs, y): return np.int64(xs / y) * y
```

Then group by the bars of the Dataframe's row number. Here's an example of 10-tick bars:

```
trades.groupby(bar(np.arange(len(trades)), 10)).agg({'price': 'ohlc', 'size': 'sum'})
```

#### Volume Bars

Group by the bars of the cumulative volume. Here's an example for n shares traded:

```
trades.groupby(bar(np.cumsum(trades['size']), n)).agg({'price': 'ohlc', 'size': 'sum'}
```

## Answer by John (score 0)

https://quant.stackexchange.com/a/54480

a tick is a change in the price, it is not a second or minute at regular tine intervals, it's frequency is driven by market moves whilst daily data is aggregated, therefore by definition it is impossible to deduct tick data from any other time frequency.

to extract this in python, there are multiple ways, I personally use Dukascopy, where you can download free csv extract and feed them easily into your python program using pandas.

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.