Skip to content

markowizard.allocation

allocation

Capital allocation line (CAL) analysis: mixing a risky portfolio with a risk-free asset.

CapitalAllocator

CapitalAllocator(
    portfolio: Series | Mapping[str, float],
    risk_free_rate: float,
)

Combines a risky portfolio with a risk-free asset to explore how different allocations affect overall expected return and risk.

Parameters:

Name Type Description Default
portfolio Series or dict - like

A dictionary or Series representing a single portfolio, containing at least 'Expected Return' (expected return) and 'Risk' (risk/std).

required
risk_free_rate float

Risk-free rate (e.g., monthly rate).

required

Attributes:

Name Type Description
portfolio dict

The risky portfolio data.

rf float

Risk-free rate.

capital_allocation_line

capital_allocation_line(steps: int = 21) -> list[dict]

Generate points along the Capital Allocation Line.

Parameters:

Name Type Description Default
steps int

Number of allocation points (default 21, i.e., 0% to 100% in 5% increments).

21

Returns:

Type Description
list of dict

Each dict has keys 'p' (risk-free proportion), 'expected_return', 'risk', and 'label'.

expected_returns

expected_returns(p: float) -> tuple[float, float]

Expected return and risk for a given allocation to the risk-free asset.

Parameters:

Name Type Description Default
p float

Proportion allocated to risk-free (0 to 1).

required

Returns:

Type Description
tuple of (expected_return, risk)

final_allocation

final_allocation(p: float) -> dict[str, float]

Compute the final allocation weights given proportion p in the risk-free asset.

Parameters:

Name Type Description Default
p float

Proportion allocated to the risk-free asset (0 to 1).

required

Returns:

Type Description
dict[str, float]
Mapping of asset names (including 'Risk-Free' for risk-free) to

their allocation percentages.

weigh_risk_free staticmethod

weigh_risk_free(
    value: float, risk_free_value: float, p: float
) -> float

Combine a risky value with a risk-free value given proportion p allocated to the risk-free asset.

Parameters:

Name Type Description Default
value float

Value from the risky portfolio (e.g., expected return or risk).

required
risk_free_value float

Corresponding value for the risk-free asset (0 for risk, rf for return).

required
p float

Proportion allocated to the risk-free asset (0 to 1).

required

Returns:

Type Description
float

Weighted value.