Skip to main content

te_fo_index.py — TE-FO Index

Added 2026-10-03. backend/nseeod/te_fo_index.py publishes an index of all NSE F&O stocks as a regular te_asset / te_price series (code TE-FO, name TE-FO Index), so it can be charted next to every other instrument. Unlike the research series in ci_* (custom_index.py), it is meant to be used day to day: the Bhav Downloader extends it after every download.

Method​

Base 1000 at the first stock-futures expiry (2001-11-29). At each monthly expiry R(k) (expiry-day close):

StepRule
MembersEvery stock whose future expiring R(k+1) trades on R(k): the F&O list as it was then (custom_index.cycle_data, same rule as the leverage study). New F&O stocks join at the next expiry; stocks NSE drops leave when their last contract expires.
Quantityq_i = (NAV(R(k)) / N) / F_i(R(k)): the capital is split equally across the N stocks
Daily baropen / high / low / close = Σ q_i × the future's open / high / low / close; NAV = close
RollThe cycle ends at the expiring contracts' close on R(k+1); the next one starts at the new contracts' close with the NAV reached
Splits / bonusesRunning futures' earlier prices are scaled by the scr_corp_action factor when the contract's own jump confirms it (custom_index._ca_scaled)
  • No costs and no interest on the margin money. It's a pure price index of the futures portfolio. The leverage study's FO-EW-FUT-1X is the variant with 5 bps per side and NIFTY-implied collateral interest.
  • Open and close are exact. High and low are bounds, the sum of the members' highs and lows, because the stocks do not all top out at the same moment. EOD Chart therefore opens it as a line chart.
  • A day a contract does not trade (or has a zero open) takes its last close, so that leg's bar is flat.

Results (local, 2026-10-03)​

Period2001-11-29 → 2026-09-25, 6,169 days, 298 expiry cycles
NAV5,666.91
CAGR7.2%
Max drawdown−73.4%
Members per cycle29 (Nov 2001) → 264; 207 now
Splits / bonuses inside cycles284 scaled, 0 unconfirmed; 0 cycles skipped
OHLC consistency0 rows with high < max(open, close) or low > min(open, close)

The gap to FO-EW-FUT-1X (11.9%) is the collateral interest (≈ 5.9% a year at the NIFTY-implied rate) less that series' 1.2% a year of costs.

Survivorship-free membership​

Membership is kept in the index constituent tracker tables under TE-FO INDEX, so it is queried exactly like NIFTY 50:

SELECT * FROM idx_members_on('TE-FO Index', '2008-06-30'); -- 227 stocks, incl. AIRDECCAN, ADLABSFILM ...
TableTE-FO content
idx_constituentSource of truth. One snapshot per expiry: symbol, futures entry price (close_price), weight (weightage_pct = 100 / N), source = 'TE-FO'
idx_membershipIntervals [from_date, to_date), rebuilt from the snapshots. from_date = the day after the expiry it joined (its returns count from the next session); to_date = the day after the last expiry it was held; NULL = in the running cycle
idx_changeIN / OUT per expiry (the Nov 2001 launch batch has no IN)
idx_indexstock_count = members now, history_from = exact_from = 2001-11-30

index_members.py build --apply reloads only the NSE indices; it skips everything in index_members.EXTERNAL (TE-FO INDEX), which used to be wiped by its TRUNCATE.

Daily update​

BhavProcessor._update_te_fo_index() (nseeod/downloadbhav.py) runs after the corporate-action sync in both run_update() and run_update_for_date(). It calls update():

  1. find the last stored expiry on or before the last stored day;
  2. recompute from there, starting from the NAV stored on that expiry: the running cycle, plus any cycle that ended since;
  3. upsert te_price, replace that expiry's snapshots onward, rebuild intervals and changes;
  4. delete any stored day after the last computed one (a rolled-back bhav day).

The result is identical to a full build: tested by deleting the last 42 days and re-running, which matched to 0.0001 (4-dp rounding), with identical membership. Nothing stored yet → update() runs a full build. Log tag TE-FO. A force-update of an old date does not rewrite history: run build --apply after back-filling F&O data.

Usage​

Run from backend/:

python -m nseeod.te_fo_index build [--apply] # full recompute (~2 min); --apply replaces every TE-FO row
python -m nseeod.te_fo_index update # incremental (what the Bhav Downloader runs)
python -m nseeod.te_fo_index members --date 2015-06-30

API (app/api/te_index.py, generic over te_asset rows with sub_type = 'custom_index'): GET /api/te-index/symbols, /chart?code=TE-FO&from_date=&to_date=&timeframe=1D|1W|1M|1Q|1Y, /symbol-range?code=, /members?code=TE-FO&date=.

EOD Chart: NSE → FUT shows a TE-FO Index chip next to "Available Stocks". Picking it skips the expiry step and fills the date range with the full history.

te_asset row: asset_class = 'equity', sub_type = 'custom_index', value_kind = 'level', unit = 'points'.