Lesson 1.2.2 · 60 min
ETFs: replication, tracking error, leveraged ETFs and UCITS
An ETF is a fund that trades like a stock. Behind it there is a creation and redemption mechanism that keeps its price pinned to the value of its portfolio, a way of replicating the index and costs that can be measured. This lesson measures them on seven years of a fictitious ETF and its 2x and inverse versions, and explains why a European retail investor cannot buy most US ETFs.
- Module
- 1.2 · Asset classes
- Duration
- 60 min
- Prerequisites
- 1.2.1 · Stocks: splits, dividends and corporate actions, 0.7.1 · Simple and log returns, compound interest and descriptive statistics
- Author
- Jesús Cuesta
- Updated
Level 1 lessons
1.1 · How markets work
1.2 · Asset classes
- 1.2.1 Stocks: splits, dividends and corporate actions
- 1.2.2 ETFs: replication, tracking error, leveraged ETFs and UCITS
- 1.2.3 Futures: specifications, margin, roll and contango
- 1.2.4 Forex: pairs, pips, lots, rollover and CFDs
- 1.2.5 Options: calls, puts, intrinsic value and time value
- 1.2.6 Crypto: spot, perpetuals, funding and custody
- 1.2.7 Fixed income and interest rates; CFDs and leveraged products
1.3 · Market data sources
- 1.3.1 Types of market data: EOD, bars, ticks, order book and reference
- 1.3.2 Free market data sources
- 1.3.3 Retail and prosumer market data APIs
- 1.3.4 Professional market data providers
- 1.3.5 Crypto and on-chain data
- 1.3.6 Brokers as market data sources
- 1.3.7 Market data licensing and terms of use
- 1.3.8 How to choose a market data provider
1.4 · Financial data engineering
- 1.4.1 Downloading over REST and websockets: pagination, rate limits and retries
- 1.4.2 Data cleaning: missing values, bad ticks, gaps and time zones
- 1.4.3 Adjusting for splits and dividends: adjusted and unadjusted prices
- 1.4.4 Universes without survivorship bias: delistings, mergers and symbol changes
- 1.4.5 Building bars: time, tick, volume, dollar and imbalance
- 1.4.6 Continuous futures series: roll rules, difference adjustment and ratio adjustment
- 1.4.7 Storage: CSV, Parquet, partitioning, DuckDB, TimescaleDB and ArcticDB
- 1.4.8 Reproducible pipeline: download, validation, incremental updates and quality tests
1.5 · Fundamental and macro data
1.6 · Financial exploratory analysis
1.7 · Programmed technical analysis
A fund that trades like a stock
An ETF (exchange-traded fund) is an investment fund whose shares are bought and sold on an exchange during the session, like a stock. Almost all of them replicate an index. It has two prices:
- Net asset value (NAV): what the fund's portfolio is worth, minus its expenses, divided by the number of shares. It is calculated once a day with the closing prices. During the session, many exchanges publish a continuous estimate (iNAV).
- Market price: the price at which the shares cross on the exchange. It is set by supply and demand.
That the two prices almost coincide is no accident: it is guaranteed by an arbitrage mechanism that only a few intermediaries can use. The fund's costs are summarized in the TER (total expense ratio), an annual percentage that is deducted from the net asset value day by day. And the dividends of the portfolio are paid out to the investor (distributing share class) or reinvested (accumulating share class).
The data for this lesson, etf_indice_diario.csv, is seven years of a fictitious index, ISX, and of four series
of products that track it: a physical ETF with a TER of 0.07% (its net asset value and its exchange price) and two
daily-reset ETFs, one 2x and one inverse (x−1).
import numpy as np
import pandas as pd
etf = pd.read_csv("etf_indice_diario.csv", parse_dates=["fecha"],
index_col="fecha")
print(len(etf), "sessions")
etf.head(3)1760 sessions
indice etf_vl etf_precio etf_2x_precio etf_inverso_precio
fecha
2019-01-02 991.65 99.165 99.16 100.0000 100.0000
2019-01-03 992.89 99.287 99.24 100.2407 99.8858
2019-01-04 998.27 99.831 99.80 101.3178 99.3553ISX is a net total return index: it adds the dividends of its stocks, after withholding tax, as if they were reinvested. It is the correct benchmark for an accumulating ETF. Comparing it with a price index, which does not add dividends, would make the ETF look as if it beats its index (lesson 1.2.1).
Creation and redemption: the authorized participant
An ordinary fund issues and redeems shares with each investor. An ETF only does so with authorized participants (APs): large intermediaries with a contract with the fund manager. Everyone else buys and sells already existing shares on the exchange.
Mermaid source
flowchart LR AP[Participant] -- basket --> G[ETF manager] G -- shares --> AP AP -- sells and buys --> B[Exchange] B --> I[Investors]
- Creation. The participant delivers the basket of index stocks (or cash) to the fund manager and receives a large block of new shares (a “creation unit”), which it sells on the exchange.
- Redemption. The participant buys shares on the exchange, delivers them to the fund manager and receives the basket.
That two-way path is an arbitrage. If the ETF trades above its net asset value (premium), the participant has an incentive to create shares with the basket and sell them dear; if it trades below (discount), to buy them cheap on the exchange and redeem them. Both operations push the price toward the net asset value. That is why a liquid ETF trades within a few basis points of its portfolio:
prima = 1e4 * (etf["etf_precio"] / etf["etf_vl"] - 1) # basis points
print(prima.describe().round(2))
prima.nsmallest(3).round(1)count 1760.00
mean -0.68
std 9.24
min -113.78
25% -3.37
50% 0.11
75% 3.51
max 16.81
dtype: float64
fecha
2020-03-17 -113.8
2020-03-31 -106.5
2020-04-03 -102.4
dtype: float64In half of the sessions the price is between −3.4 and +3.5 basis points from the net asset value. The median is 0.1. The extremes are concentrated in a few weeks: on March 17, 2020 the ETF closed at a discount of 113.8 basis points, 1.14%.
The figure shows the range of the premium or discount in each month. 76 of the 84 months fit in a ±15 basis point band; March and April 2020 break out, with discounts of more than 100 basis points. It is not that the mechanism fails: it is that the arbitrage costs more. When the basket's stocks have wide spreads and intermediaries shrink their balance sheets, the participant only redeems if the discount covers that cost. In bond ETFs, whose bonds trade much less than stocks, the same mechanism lets larger discounts through when the market comes under strain.
prima.abs().groupby(prima.index.year).mean().round(2)fecha
2019 4.05
2020 9.06
2021 3.86
2022 3.97
2023 4.16
2024 3.88
2025 4.13
dtype: float64In 2020, the average size of the premium or discount is more than double that of any other year. For a trading system, the consequence is direct: the price of an ETF in a crisis may not be the value of what it contains. A backtest that uses the net asset value as the execution price, or the other way round, gets it wrong precisely on the days that matter most.
Physical and synthetic replication
There are two ways of giving a fund the return of an index:
| Full physical | Physical by sampling | Synthetic (swap) | |
|---|---|---|---|
| What the fund holds | All the index stocks, with their weights | A representative sample | Any basket of collateral assets |
| Where the return comes from | The portfolio | The portfolio, with sampling error | A swap with a bank that pays the index |
| Main risk | Rebalancing costs | Larger tracking error | Swap counterparty |
| Extra income | Securities lending | Securities lending | Depends on the contract |
| Useful for | Liquid indexes | Indexes of thousands of stocks | Hard-to-access markets, commodities |
In synthetic replication, the fund buys a basket of assets (which may have nothing to do with the index) and signs a total return swap with a counterparty: the fund hands over the return of its basket and receives that of the index.
Mermaid source
flowchart LR F[Fund] -- return of its basket --> C[Counterparty] C -- index return --> F F --> K[Basket as collateral]
The risk is that the counterparty does not pay. The UCITS Directive limits it: the exposure to one counterparty in OTC derivatives cannot exceed 10% of the fund's assets if it is a credit institution, and 5% in other cases (Article 52). In practice, the swap is reset when its value approaches that limit. Physical replication has its own smaller counterparty risk, when it lends its stocks in exchange for a fee.
The same directive sets diversification limits: a UCITS fund cannot invest more than 5% of its assets in securities of a single issuer, which can be raised to 10% as long as those above 5% do not add up to more than 40%. A very concentrated index cannot be replicated as is in a UCITS; there are capped versions of the index for that.
Tracking difference and tracking error
Two measures summarize how well an ETF follows its index, and they are not the same:
The tracking difference (TD) is the fund's return minus the index's over a period, for example a calendar year. It is what the ETF costs the investor. The tracking error (TE) is the annualized standard deviation of the daily differences: it measures how irregular the replication is, not how much is lost.
fin = etf.groupby(etf.index.year).last()
inicio = fin.shift()
inicio.iloc[0] = etf.iloc[0] # 2019 starts at the first session
anual = 100 * (fin / inicio - 1)
td = pd.DataFrame({"indice": anual["indice"],
"etf_vl": anual["etf_vl"]})
td["dif_replica"] = td["etf_vl"] - td["indice"]
print(td.round(2))
print(f"Mean: {td['dif_replica'].mean():.3f} points a year") indice etf_vl dif_replica
fecha
2019 26.57 26.36 -0.21
2020 3.75 3.66 -0.08
2021 28.64 28.46 -0.18
2022 -21.56 -21.58 -0.02
2023 18.83 18.81 -0.03
2024 22.89 22.69 -0.20
2025 26.54 26.37 -0.17
Mean: -0.128 points a yearEvery year the fund returns somewhat less than its index: between 0.02 and 0.21 points, 0.128 on average. The TER alone explains 0.07 points; the rest is replication error, which adds in some years and subtracts in others. That is why the tracking difference of a single year is not enough to judge an ETF: several are needed.
r = etf.pct_change().dropna()
dif = r["etf_vl"] - r["indice"]
te = 100 * np.sqrt(252) * dif.groupby(dif.index.year).std()
print(te.round(3))
print(f"Total: {100 * np.sqrt(252) * dif.std():.3f} % annualized")fecha
2019 0.073
2020 0.078
2021 0.078
2022 0.080
2023 0.080
2024 0.085
2025 0.084
dtype: float64
Total: 0.080 % annualizedA tracking error of 0.08% annualized is very low: the fund follows the index almost day by day. Its tracking difference is, however, always negative: the cost is small but systematic. For a long-term investor, the tracking difference is the figure that matters; for someone who uses the ETF to hedge a portfolio over a few days, the tracking error.
Two practical details when comparing with real data. First, tracking difference is measured on the net asset
value, not on the exchange price, which adds each day's premium or discount (the etf_precio column). Second, the
index has to be the same one the fund declares: price, gross or net total return, in the same currency.
Leveraged and inverse ETFs: the daily reset
A 2x leveraged ETF promises twice the daily return of its index; an inverse one, the daily return with its sign flipped. To achieve it, the fund manager resets its exposure every day at the close (with swaps or futures): if the fund is worth 100, the next day it needs an exposure of 200 to the index. That word, daily, changes everything. Two days are enough to see it:
dias = pd.Series([0.10, -1 / 11]) # +10% and then −9.09%
for nombre, L in [("index", 1), ("x2", 2), ("inverse", -1)]:
valor = 100 * (1 + L * dias).prod()
print(f"{nombre:8s} {valor:7.2f}")index 100.00
x2 98.18
inverse 98.18The index rises 10% and falls 9.09%: it returns to 100. The 2x rises 20% (to 120) and then falls 18.18% from 120: it ends at 98.18. The inverse falls 10% and then rises 9.09% from 90: 98.18 as well. Neither of the two recovers the starting point. The return over a period is the product of the daily returns, and as soon as the days have different signs.
With seven years of data, the period from January 2022 to June 2023 has the worst for these products: a lot of volatility and little net trend.
tramo = etf.loc["2022-01-03":"2023-06-30"]
rent = 100 * (tramo.iloc[-1] / tramo.iloc[0] - 1)
print(rent.round(1))
print(f"Twice the index: {2 * rent['indice']:.1f}")indice 13.8
etf_vl 13.7
etf_precio 13.7
etf_2x_precio 9.9
etf_inverso_precio -14.0
dtype: float64
Twice the index: 27.6The index gains 13.8%. Whoever expected double from the 2x, 27.6%, gets 9.9%: less than the index itself. The inverse loses 14.0%, somewhat more than the index gains. The header figure plots the three paths: the 2x drifts away from “twice the index” with each swing and never recovers.
How much of the difference is volatility and how much is cost? The 2x fund pays, on top of the TER (0.95% a year in this data), the financing of the extra exposure: it borrows what it puts into the index above its net assets, at the three-month rate. The two can be separated by rebuilding a cost-free 2x from the daily returns of the index:
ri = tramo["indice"].pct_change().dropna()
x2_sin_costes = 100 * ((1 + 2 * ri).prod() - 1)
print(f"Twice the index: {2 * rent['indice']:5.1f} %")
print(f"x2 without costs: {x2_sin_costes:5.1f} %")
print(f"x2 actual: {rent['etf_2x_precio']:5.1f} %")
sigma = ri.std() * np.sqrt(252)
anos = len(ri) / 252
print(f"Index volatility: {sigma:.1%} over {anos:.2f} years")Twice the index: 27.6 %
x2 without costs: 16.9 %
x2 actual: 9.9 %
Index volatility: 26.4% over 1.48 yearsOf the 17.7 points that separate the promised 27.6% from the actual 9.9%, 10.7 are eaten by volatility (the cost-free 2x already stops at 16.9%) and the other 7 by financing and the fee. The index volatility over the period, 26.4% annualized for 1.48 years, is high: with half the volatility, the decay would be a quarter as large.
The approximation that explains it comes from working with logarithms. For a product with leverage and an index with volatility , over years and without costs:
For , the decay term is ; for , too (). The decay grows with the square of volatility and linearly with time. In a market with a strong trend and little volatility, the effect reverses: the 2x can return more than double, because each day it reinvests the previous gain.
UCITS versus the US: PRIIPs and the KID
The ETFs sold to retail investors in the EU are almost always UCITS (OICVM in Spanish terminology): funds harmonized by Directive 2009/65/EC, with diversification, liquidity and leverage limits, and a passport to be marketed throughout the Union from the member state in which they are domiciled. US ETFs are governed by US regulation and are not UCITS.
The practical difference for a Spanish investor comes from another rule, Regulation (EU) 1286/2014 (PRIIPs). Its core rules are three:
- Article 5.1. Before making it available to retail investors, the manufacturer of a packaged investment product has to draw up a key information document (KID) and publish it on its website.
- Article 6.4. The document is short: a maximum of three sides of A4-sized paper, with risk, performance scenarios and costs in a common format that makes it possible to compare products.
- Article 13.1. Whoever advises on the product or sells it to a retail investor has to provide them with the KID in good time before they are bound.
An ETF is a packaged product. UCITS had a transitional exemption (Article 32) that was extended until December 31, 2022; since January 1, 2023 they also use the PRIIPs KID (Directive 2021/2261). US-domiciled ETFs do not usually have a KID: their manager does not market them in the EU and has no obligation to draw it up. Without a KID, the European broker cannot comply with Article 13 and cannot sell them to a retail client.
Mermaid source
flowchart TB
O[Buy order] --> C{Retail?}
C -- no --> E[Executed]
C -- yes --> K{Has a KID?}
K -- yes --> E
K -- no --> R[Broker rejects it]| UCITS ETF (EU) | US ETF | |
|---|---|---|
| Framework | Directive 2009/65/EC | US regulation |
| Domicile | An EU member state | US |
| PRIIPs KID | Yes | Usually not |
| Sale to retail investors in the EU | Yes | No, in practice |
| Professional clients in the EU | Yes | Yes: the KID is for retail |
| Diversification | 5/10/40 and counterparty limits | Its own rules |
The regulation applies to sales to retail investors. A client classified as professional under MiFID II, with the requirements that entails, can buy an ETF without a KID. For a trading system the consequence is one of data and design: a backtest with a US ETF (SPY, for example) can be a good experiment, but to trade it from a European retail account you have to find the UCITS equivalent, which has another ticker, sometimes another currency, another exchange, other trading hours and, if it is accumulating, does not pay dividends.
What this changes in your data
- Price or net asset value. An ETF has two series. Execution is simulated with the price; replication is measured with the net asset value. In a crisis they can diverge by 1% or more.
- The right index. To measure an accumulating ETF, a net total return index; against a price index, the ETF seems to beat it.
- Daily-reset products. Their series is not built by multiplying the index's: it is compounded day by day, with financing and fees.
- The tradable universe. What can be bought from an EU retail account is not what appears on US screens; a backtest universe should be that of the products that will be traded (lesson 1.3.8).
- Dividends and share classes. A distributing ETF has ex-dates like a stock (lesson 1.2.1); an accumulating one does not.
Exercises
- Calculate the return of the inverse ETF in each year and compare it with minus the index return. In which year is the difference largest and why?
Solution
inv = pd.DataFrame({"inverso": anual["etf_inverso_precio"],
"menos_indice": -anual["indice"]})
inv["diferencia"] = inv["inverso"] - inv["menos_indice"]
inv.round(1) inverso menos_indice diferencia
fecha
2019 -19.5 -26.6 7.1
2020 -11.4 -3.7 -7.6
2021 -24.3 -28.6 4.3
2022 24.1 21.6 2.5
2023 -12.0 -18.8 6.8
2024 -12.0 -22.9 10.9
2025 -20.3 -26.5 6.3The inverse does not return “minus the index” in any year. In six of the seven it loses less (or gains more) than promised, for two reasons: it earns interest on the cash from the sale it replicates (in the data formula, twice the three-month rate) and, in years of trending rises, each daily loss is applied to a base that has already shrunk. The largest difference is in 2024 (+10.9 points), with rates above 4% and an index that rises 22.9%. The exception is 2020: the index ends almost flat (+3.7%) after a violent fall and recovery, and the inverse loses 11.4%, 7.6 points worse than the promised −3.7%. It is volatility decay again: there and back, without a trend.
- Compare year by year the return of the 2x with that of a cost-free 2x built from the daily returns of the index. How much do financing and the fee cost each year?
Solution
ri_todo = etf["indice"].pct_change().fillna(0)
sin_costes = (1 + 2 * ri_todo).groupby(etf.index.year).prod()
coste = pd.DataFrame({
"x2_sin_costes": 100 * (sin_costes - 1),
"x2_real": anual["etf_2x_precio"],
})
coste["coste"] = coste["x2_real"] - coste["x2_sin_costes"]
coste.round(1) x2_sin_costes x2_real coste
fecha
2019 58.0 53.2 -4.8
2020 -0.7 -2.0 -1.3
2021 62.1 60.2 -1.8
2022 -42.3 -44.2 -1.9
2023 34.8 26.9 -7.9
2024 49.0 40.3 -8.7
2025 50.2 42.8 -7.4The cost moves with interest rates: from 1.3 to 1.9 points in 2020, 2021 and 2022, with rates close to zero for much of those years; 4.8 in 2019, with the three-month rate around 2%; and from 7.4 to 8.7 points from 2023 to 2025, with the rate between 4% and 5%. The fee (0.95%) is the small part: financing the extra exposure is most of the cost of a leveraged ETF. And it grows with the fund itself, because it is paid on its value each day.
- A Spanish retail client wants to buy a US ETF that replicates an index of technology stocks. Their broker rejects the order. Explain the reason and what alternatives they have.
Solution
The ETF is a packaged investment product. To sell it to a retail investor, the broker has to provide the KID first (Article 13 of Regulation 1286/2014), and the US manager has not drawn it up because it does not market the fund in the EU. Without a KID, the sale is not possible. The alternatives: a UCITS ETF that replicates the same index (or a very similar one), domiciled in the EU and with a KID; or, if they meet the requirements, ask to be classified as a professional client, which has other consequences (less protection). Buying the index stocks one by one is also possible: stocks are not packaged products.
Each answer is folded under its question
Self-assessment
An ETF trades at a 1% discount to its net asset value. What does an authorized participant do if it can operate normally?
- ABuys shares on the exchange and redeems them with the fund manager in exchange for the basket, which is worth 1% more
- BCreates new shares and sells them on the exchange
- CNothing: the fund manager absorbs the discount
- DShort-sells the basket of stocks
Show answer
Answer A. Buys shares on the exchange and redeems them with the fund manager in exchange for the basket, which is worth 1% more
At a discount, the share on the exchange is worth less than what it contains. The participant buys it cheap, redeems it in kind and sells the basket. That buying on the exchange pushes the price toward the net asset value. If the basket's market is under stress (March 2020), the arbitrage costs more and the discount persists.
What is the difference between tracking difference and tracking error?
- ANone, they are synonyms
- BTracking difference is the fund's return minus the index's over a period; tracking error is the volatility (annualized standard deviation) of the daily differences
- CTracking error only exists in synthetic ETFs
- DTracking difference is the management fee
Show answer
Answer B. Tracking difference is the fund's return minus the index's over a period; tracking error is the volatility (annualized standard deviation) of the daily differences
Tracking difference says how much is lost (or gained) against the index; tracking error, how regularly. A fund can have a minimal tracking error and a negative, stable tracking difference equal to its costs.
An index rises 10% one day and falls 9.09% the next: it returns to the starting point. What happens to a daily-reset 2x ETF, without costs?
- AIt also returns to the starting point
- BIt gains 2%
- CIt loses slightly less than 2%: it rises 20% and then falls 18.18%
- DIt loses 20%
Show answer
Answer C. It loses slightly less than 2%: it rises 20% and then falls 18.18%
1.20 × (1 − 0.1818) = 0.9818. With the daily reset, the fund multiplies each day's return, not the period's. In markets that go back and forth, that costs money even if the index does not move.
Under Regulation (EU) 1286/2014, what must whoever sells a packaged investment product to a retail investor do?
- ANothing, if the product is listed on a regulated exchange
- BProvide the key information document (KID) in good time before the investor is bound
- CRequest authorization from the CNMV (Spain's securities regulator) for each trade
- DHand over the fund's full prospectus
Show answer
Answer B. Provide the key information document (KID) in good time before the investor is bound
Article 13 requires the KID to be provided before the sale, and Article 5 requires the manufacturer to draw it up and publish it. If the manager of a US ETF does not draw up a KID, the European broker cannot sell it to a retail client.
In the course data, between January 2022 and June 2023 the index rises 13.8%. How much does the 2x ETF rise?
- A27.6%
- B13.8%
- C9.9%
- D−14.0%
Show answer
Answer C. 9.9%
9.9%, less than the index itself. The period has a lot of volatility and little trend: volatility decay and the financing of the extra exposure eat up more than double the rise. The −14.0% belongs to the inverse ETF.
Key points
- The authorized participant creates and redeems shares in exchange for the index basket. That arbitrage keeps the ETF price within a few basis points of its net asset value, except when the basket's market comes under strain.
- Tracking difference measures how much is lost against the index (in the course ETF, between −0.02 and −0.21 points a year); tracking error, the daily dispersion (0.08% annualized).
- Physical replication: the fund holds the stocks. Synthetic: it holds another basket and a swap that pays it the index, with counterparty risk limited by UCITS.
- A leveraged or inverse ETF multiplies each day's return, not the period's. In volatile, trendless markets it loses against L times the index; it is not suited to holding long-term positions.
- In the EU, a packaged product needs a KID to be sold to retail investors (Regulation 1286/2014). US-domiciled ETFs do not usually have one, so European brokers do not offer them to retail clients.