beacon.fund¶
Investable vehicles: IndexFund composes an IndexCalculator and a
BacktestEngine to track an index, with management-fee accrual; ETF
extends it with a ticker, creation-unit size, market-price simulation, and
tracking-performance analysis.
fund ¶
The init.py for the 'fund' module.
This module models financial funds, particularly ETFs and index funds.
IndexFund ¶
IndexFund(
fund_id: str,
target_index_definition: IndexDefinition,
index_agent: IndexCalculator,
portfolio: Portfolio,
data_provider: DataFetcher,
management_fee_bps: int = 0,
)
An index fund that tracks a target index.
The fund delegates the whole pipeline — target weight calculation and the
simulated tracking portfolio — to :class:~beacon.backtest.main.Backtest,
the front door composing :class:~beacon.index.calculation.IndexCalculator
and :class:~beacon.backtest.engine.BacktestEngine (BN-161). It contains
no buy/sell logic of its own — rebalancing and portfolio accounting are
delegated entirely to the backtest engine.
Initializes an IndexFund.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fund_id
|
str
|
A unique identifier for the fund. |
required |
target_index_definition
|
IndexDefinition
|
The definition of the index the fund aims to track. |
required |
index_agent
|
IndexCalculator
|
The IndexCalculator used to compute the target index's weight schedule. |
required |
portfolio
|
Portfolio
|
The Portfolio object seeding the fund's capital. Its cash balance is used as the backtest engine's initial capital; the fund no longer mutates this portfolio directly. |
required |
data_provider
|
DataFetcher
|
DataFetcher instance for market data. |
required |
management_fee_bps
|
int
|
The annual management fee in basis points (e.g., 10 bps = 0.1%). |
0
|
Source code in build/cache/py-beacon-2c9c3936c65abdb6b8403c50a023f58355be30ee/src/beacon/fund/base.py
index_result
property
¶
The target :class:IndexResult from the most recent run, if any.
backtest_result
property
¶
The :class:BacktestResult from the most recent run, if any.
run_backtest ¶
run_backtest(
start_date: str | None = None,
end_date: str | None = None,
transaction_cost_bps: float = 0.0,
) -> BacktestResult
Compute target weights and simulate the tracking portfolio.
Delegates the whole calculate-then-simulate composition to
:class:~beacon.backtest.main.Backtest (BN-161), which fingerprints
the calculation, reuses a cached IndexResult when the data source
allows it, and hands the schedule to a backtest engine that manages
its own portfolio. The resulting :class:BacktestResult is cached on
the fund and returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_date
|
str | None
|
First simulation date (YYYY-MM-DD). Defaults to the target index's base date. |
None
|
end_date
|
str | None
|
Last simulation date (YYYY-MM-DD). Required. |
None
|
transaction_cost_bps
|
float
|
Trading cost applied by the engine to each trade's notional. Distinct from the fund's management fee. |
0.0
|
Returns:
| Type | Description |
|---|---|
BacktestResult
|
The BacktestResult produced by the engine. |
Source code in build/cache/py-beacon-2c9c3936c65abdb6b8403c50a023f58355be30ee/src/beacon/fund/base.py
rebalance_to_index ¶
Align the fund's tracking portfolio with the target index.
Thin wrapper that ensures the composed calculator + engine pipeline has
been run through current_date. All weight computation is delegated to
the :class:IndexCalculator and all trading to the
:class:BacktestEngine; this class performs no buy/sell logic itself.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_date
|
Timestamp
|
The date through which to simulate. |
required |
Source code in build/cache/py-beacon-2c9c3936c65abdb6b8403c50a023f58355be30ee/src/beacon/fund/base.py
calculate_nav ¶
Return the fund's Net Asset Value as of current_date.
The gross NAV is read from the backtest-engine-managed portfolio; the accrued management fee is then deducted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_date
|
Timestamp
|
The date for which to calculate NAV. |
required |
Returns:
| Type | Description |
|---|---|
float
|
The fee-adjusted Net Asset Value. |
Source code in build/cache/py-beacon-2c9c3936c65abdb6b8403c50a023f58355be30ee/src/beacon/fund/base.py
ETF ¶
ETF(
fund_id: str,
etf_ticker: str,
target_index_definition: IndexDefinition,
index_agent: IndexCalculator,
portfolio: Portfolio,
data_provider: DataFetcher,
management_fee_bps: int = 0,
creation_unit_size: int = 50000,
)
Bases: IndexFund
Represents an Exchange Traded Fund (ETF), which is a type of IndexFund with additional characteristics like market price and creation/redemption units.
Initializes an ETF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fund_id
|
str
|
A unique identifier for the fund. |
required |
etf_ticker
|
str
|
The market ticker symbol for the ETF. |
required |
target_index_definition
|
IndexDefinition
|
The definition of the index the ETF tracks. |
required |
index_agent
|
IndexCalculator
|
Calculation agent for the target index. |
required |
portfolio
|
Portfolio
|
The Portfolio object representing the ETF's holdings. |
required |
data_provider
|
DataFetcher
|
DataFetcher for market data. |
required |
management_fee_bps
|
int
|
Annual management fee in basis points. |
0
|
creation_unit_size
|
int
|
The number of ETF shares in a creation/redemption unit. |
50000
|
Source code in build/cache/py-beacon-2c9c3936c65abdb6b8403c50a023f58355be30ee/src/beacon/fund/etf.py
simulate_market_price ¶
simulate_market_price(
current_date: Timestamp,
market_factors: dict[str, Any] | None = None,
) -> float
Simulates the ETF's market price based on its NAV and other market factors. (Future Scope: Initial focus on NAV tracking implies market price might closely follow NAV, or be supplied externally if backtesting against actual ETF data).
For a basic simulation, market price might be NAV plus some noise or bid-ask spread. This is a placeholder for more sophisticated modeling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
current_date
|
Timestamp
|
The date for which to simulate the price. |
required |
market_factors
|
dict[str, Any] | None
|
A dictionary of factors that might influence the price (e.g., market sentiment, liquidity, bid-ask spread). |
None
|
Returns:
| Type | Description |
|---|---|
float
|
The simulated market price of the ETF. |
Source code in build/cache/py-beacon-2c9c3936c65abdb6b8403c50a023f58355be30ee/src/beacon/fund/etf.py
get_tracking_performance ¶
Calculate tracking metrics from a completed backtest.
Compares the backtest's trading_nav against the tracked index's
index_levels using the tracking methods built into
:class:~beacon.backtest.result.BacktestResult. The result must carry
an index_result for the comparison to be possible.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result
|
BacktestResult
|
A BacktestResult produced by tracking this ETF's index. It already contains both the portfolio NAV and the target index. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float | str]
|
A dictionary with float |
dict[str, float | str]
|
|
dict[str, float | str]
|
to compare against, a single |
dict[str, float | str]
|
whose value is an explanatory string — hence the |
dict[str, float | str]
|
value type. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If result is None. |