Skip to main content

Fetches fund data from the TEFAS website.

Project description

tefasfon v1.1.0

Fetches fund data from the TEFAS (Turkey Electronic Fund Trading Platform) website.

Installation

pip install tefasfon

Installing the package also registers the tefasfon command in your terminal.

Standalone Binary (no Python required)

Pre-built executables are available on the Releases page for Windows, Linux, and macOS. Download the file for your platform and run it directly without a Python installation.

# Windows
tefasfon-windows.exe funds -t SEC -s 01.01.2025 -e 31.01.2025 -x

# Linux / macOS
chmod +x tefasfon-linux   # or tefasfon-macos
./tefasfon-linux funds -t SEC -s 01.01.2025 -e 31.01.2025 -x

CLI

All four data types are available as subcommands.

tefasfon <command> [options]

Commands:
  funds       General fund information
  portfolio   Portfolio breakdown (asset allocation)
  returns     Return data

Common options:
  -t, --fund-type   SEC · PEN · ETF · RE · VC        (required)
  -s, --start-date  DD.MM.YYYY                        (required)
  -e, --end-date    DD.MM.YYYY                        (required)
  -c, --fund-codes  CODE [CODE ...]                   filter by fund code(s)
  -f, --fund-title-contains  KEYWORD [KEYWORD ...]   filter by fund title
  -x, --save-to-excel                                 save result to .xlsx
  -o, --output  csv | json                            print to stdout

Examples

# Save securities funds for April 2026 to Excel
tefasfon funds -t SEC -s 01.04.2026 -e 30.04.2026 -x

# Filter by fund code, output as CSV
tefasfon funds -t PEN -s 01.04.2026 -e 30.04.2026 -c AEK AEY -o csv

# Filter by title keyword, output as JSON
tefasfon funds -t ETF -s 01.04.2026 -e 30.04.2026 -f ALTIN -o json

# Return-based (standard periods)
tefasfon returns -t SEC -b RB -x

# Return-based (specific date range)
tefasfon returns -t PEN -b RB -s 01.04.2026 -e 30.04.2026 -o csv

# Size-based returns
tefasfon returns -t RE -b SB -s 01.04.2026 -e 30.04.2026 -x

# Pipe CSV output to a file
tefasfon funds -t SEC -s 01.04.2026 -e 30.04.2026 -o csv > funds.csv

For returns, --basis (-b) is required: RB (return-based), SB (size-based), MB (management fee-based). --start-date and --end-date are optional for RB but required for SB and MB.

Python API

get_funds

Fetches general information by date range and fund type.

Parameters

Parameter Type Default Description
fund_type str "SEC" Securities · "PEN" Pension · "ETF" Exchange-Traded Fund · "RE" Real Estate · "VC" Venture Capital
start_date str DD.MM.YYYY
end_date str DD.MM.YYYY
fund_codes list | None None Filter by exact fund code(s)
fund_title_contains list | None None Filter by term(s) in fund name
save_to_excel bool False Save result to .xlsx

Returns pandas.DataFrame

Columns

Column Description
fonKodu Fund code
fonUnvan Fund name
tarih Date
fiyat Price
tedPaySayisi Number of shares in circulation
kisiSayisi Number of investors
portfoyBuyukluk Portfolio size (TRY)
borsaBultenFiyat Exchange bulletin price

Example

from tefasfon import get_funds

df = get_funds(
    fund_type="SEC",
    start_date="01.04.2026",
    end_date="30.04.2026",
)

df = get_funds(
    fund_type="PEN",
    start_date="01.04.2026",
    end_date="30.04.2026",
    fund_codes=["AEK", "AEY"],
)

df = get_funds(
    fund_type="ETF",
    start_date="01.04.2026",
    end_date="30.04.2026",
    fund_title_contains=["ALTIN", "GÜMÜŞ"],
)

get_portfolio

Fetches portfolio breakdown by date range and fund type.

Parameters

Parameter Type Default Description
fund_type str "SEC" Securities · "PEN" Pension · "ETF" Exchange-Traded Fund · "RE" Real Estate · "VC" Venture Capital
start_date str DD.MM.YYYY
end_date str DD.MM.YYYY
fund_codes list | None None Filter by exact fund code(s)
fund_title_contains list | None None Filter by term(s) in fund name
save_to_excel bool False Save result to .xlsx

Returns pandas.DataFrame

Columns

Column Description
fonKodu Fund code
fonUnvan Fund name
tarih Date
hs Stocks (%)
yhs Foreign stocks (%)
dt Government bonds (%)
hb Treasury bills (%)
vdm Time deposits (%)
vmtl Time deposits in TL (%)
tr Reverse repo (%)
byf ETFs (%)
yyf Foreign investment funds (%)
km Precious metals (%)
kkstl Lease certificates in TL (%)
osks Private sector lease certificates (%)

Other columns represent additional asset class breakdowns; null means no allocation.

Example

from tefasfon import get_portfolio

df = get_portfolio(
    fund_type="PEN",
    start_date="01.04.2026",
    end_date="30.04.2026",
)

get_returns

Fetches fund return data by fund type and basis.

Parameters

Parameter Type Default Description
fund_type str "SEC" Securities · "PEN" Pension · "ETF" Exchange-Traded Fund · "RE" Real Estate · "VC" Venture Capital
basis str "RB" Return-based · "SB" Size-based · "MB" Management fee-based
start_date str | None None DD.MM.YYYY, optional for "RB", required for "SB" and "MB"
end_date str | None None DD.MM.YYYY, optional for "RB", required for "SB" and "MB"
fund_codes list | None None Filter by exact fund code(s)
fund_title_contains list | None None Filter by term(s) in fund name
save_to_excel bool False Save result to .xlsx

Returns pandas.DataFrame

Columns (RB, without date)

Column Description
fonKodu Fund code
fonUnvan Fund name
getiri1a 1-month return (%)
getiri3a 3-month return (%)
getiri6a 6-month return (%)
getiri1y 1-year return (%)
getiriyb Year-to-date return (%)
getiri3y 3-year return (%)
getiri5y 5-year return (%)
riskDegeri Risk level

Columns (RB, with date)

Column Description
fonKodu Fund code
fonUnvan Fund name
getiriOrani Return for the given period (%)
riskDegeri Risk level

Columns (SB)

Column Description
fonKodu Fund code
fonUnvan Fund name
ilkPortfoyDegeri Portfolio size at start (TRY)
sonPortfoyDegeri Portfolio size at end (TRY)
portBuyuklukDegisim Portfolio size change (%)
ilkPayAdedi Share count at start
sonPayAdedi Share count at end
payAdetDegisim Share count change (%)
netGetiriOrani Net return (%)

Columns (MB)

Column Description
fonKodu Fund code
fonUnvan Fund name
fonTurAciklama Fund type description
tefasDurum TEFAS status
fonTurKod Fund type code
kurucuKod Founder code
altbaslik1 Label for uygulananYu1Y (API-provided field name)
uygulananYu1Y Applied management fee, 1 year (%)
altbaslik2 Label for fonIcTuzukYu1G (API-provided field name)
fonIcTuzukYu1G Management fee per fund prospectus, annual (%)
yillikGetiri Annual return (%)
altbaslik3 Label for fonTopGiderKesoran (API-provided field name)
fonTopGiderKesoran Total expense ratio (string, Turkish decimal format, e.g. "1,65")

Example

from tefasfon import get_returns

# Return-based (standard periods)
df = get_returns(
    fund_type="ETF",
    basis="RB",
)

# Return-based (specific date range)
df = get_returns(
    fund_type="PEN",
    basis="RB",
    start_date="01.04.2026",
    end_date="30.04.2026",
)

# Size-based
df = get_returns(
    fund_type="RE",
    basis="SB",
    start_date="01.04.2026",
    end_date="30.04.2026",
)

# Management fee-based
df = get_returns(
    fund_type="SEC",
    basis="MB",
    start_date="01.04.2026",
    end_date="30.04.2026",
)

analyze_funds

Calculates performance metrics from a get_funds() DataFrame.

Parameters

Parameter Type Default Description
df pd.DataFrame Output of get_funds()
price_col str "fiyat" Price column
fund_code_col str "fonKodu" Fund code column
fund_title_col str "fonUnvan" Fund name column
date_col str "tarih" Date column
freq str "D" Return frequency: D B W M Q A/Y
risk_free_annual float 0.0 Annual risk-free rate (e.g. 0.10 = 10%)
periods_per_year int | None None Inferred from freq if not set
method str "simple" "simple" or "log"
drop_empty bool True Drop funds with insufficient data

Returns pandas.DataFrame sorted by Sharpe ratio (descending)

Columns

Column Description
Fund Code Fund code
Fund Name Fund name
Observations Number of return observations
Cumulative Return Total return over the period
Annualized Return Annualized return
Annualized Volatility Annualized standard deviation of returns
Sharpe Ratio Risk-adjusted return (annualized)

Example

from tefasfon import get_funds, analyze_funds

df = get_funds(
    fund_type="SEC",
    start_date="01.01.2026",
    end_date="30.04.2026",
)

metrics = analyze_funds(
    df,
    freq="B",
    method="log",
    risk_free_annual=0.40,
)

Changelog

v1.1.0

  • Added CLI: all functions accessible from the terminal via the tefasfon command.
  • Added --output csv and --output json flags for stdout output and shell piping.
  • Added standalone pre-built binaries for Windows, Linux, and macOS (no Python required).

v1.0.0 (04/05/2026)

  • No browser needed. Google Chrome no longer has to be installed.
  • Faster. Data is fetched directly from the API with no page rendering.
  • Function renamed from fetch_tefas_data to get_funds.
  • Added get_portfolio and get_returns.
  • lang, headless, and wait_seconds parameters removed.

v0.4.1 (18/10/2025)

  • fund_title_contains now matches whole words only.

v0.4.0 (18/10/2025)

  • Added analyze_funds.

v0.3.0 (15/10/2025)

  • Added fund_codes and fund_title_contains filters.

v0.2.0 (05/09/2025)

  • Returns an empty DataFrame instead of raising an error when no data is found.

v0.1.0 (20/07/2025)

  • First release.

Contributing

Bug reports, feature requests, and pull requests are welcome at github.com/urazakgul/tefasfon.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tefasfon-1.1.0.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tefasfon-1.1.0-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file tefasfon-1.1.0.tar.gz.

File metadata

  • Download URL: tefasfon-1.1.0.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for tefasfon-1.1.0.tar.gz
Algorithm Hash digest
SHA256 d40181bdd661a2d86ee50a566cf54da5bce9aaa88d74eb6a0f511632030a3d79
MD5 8213d0b87eb086f2338592219398223a
BLAKE2b-256 8f78aae7269b84377398f2d40565bf124d7ae8c99f35c23517a500526b766c9e

See more details on using hashes here.

File details

Details for the file tefasfon-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: tefasfon-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for tefasfon-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eb6808c99293e3d1423d8f32c77ea169e644f7b452c7c50af597a55659a28a1c
MD5 811111d4d6741106fe274adfa88054ef
BLAKE2b-256 c126c46331bfd316a6460a2436ffc866a6c5fc90a800db3681add0ddc1c05cbd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page