Context API

StrategyContext is passed to every strategy method. It exposes the current date, portfolio state, market data, config, and the alpha-operator namespace. Strategies read from the context and return target weights — there is no order-submission API on the context.

Fields

python
# StrategyContext is passed to initialize/universe/signal/risk_limits:

ctx.date              # str — current trading date (YYYY-MM-DD)
ctx.portfolio         # PortfolioState — equity, cash, positions, PnL, drawdown
ctx.data              # DataAccessor — OHLCV, returns, fundamentals, panels
ctx.config            # dict — strategy config (from strategy.json)
ctx.security_master   # pd.DataFrame — symbol -> sector, market cap, etc.
ctx.ops               # alpha operators namespace (ctx.ops.rank, ...)
ctx.run_skill_script  # call an exposed skill script (bundles only)

ctx.portfolio

Current portfolio state: equity, cash, positions (shares), position_values, daily/total PnL, current_drawdown, and long-short exposures (gross_exposure, net_exposure).

python
ctx.portfolio -> PortfolioState

Returns

PortfolioState dataclass

Example

python
1
2
3
4
5
6
def signal(self, ctx):
    equity = ctx.portfolio.equity
    held = set(ctx.portfolio.positions.keys())
    dd = ctx.portfolio.current_drawdown
    # ... use state to size the next set of weights
    return {}

ctx.data

Access OHLCV bars, returns, fundamentals, and per-field panels. See the Data API for every method.

python
ctx.data -> DataAccessor

Returns

DataAccessor

Example

python
1
2
3
returns = ctx.data.returns(lookback=126)   # DataFrame: dates x symbols
close = ctx.data.close(lookback=20)        # close-price panel
km = ctx.data.fundamentals("AAPL", "key_metrics_ttm")

ctx.ops

The formulaic alpha-operator library, bound onto the context. Same callables as podium_sdk.alpha_ops.

python
ctx.ops.<operator>(...)

Returns

pd.Series / pd.DataFrame depending on the operator

Example

python
1
2
mom = (1 + ctx.data.returns(lookback=126)).prod() - 1
score = ctx.ops.rank(mom)            # cross-sectional rank in [0, 1]

ctx.run_skill_script

Execute an exposed skill script (JSON-in / JSON-out) in a hardened subprocess sandbox. Available only when the strategy is submitted as a multi-file bundle with a skills/ directory.

python
ctx.run_skill_script(skill_name: str, script_name: str, input_data: dict) -> dict

Parameters

NameTypeRequiredDescription
skill_namestrSkill folder name
script_namestrExposed script (per SKILL.md)
input_datadictJSON-serializable input

Returns

dict: JSON result returned by the script

Example

python
1
2
3
4
5
weights = ctx.run_skill_script(
    "portfolio-construction",
    "compute_weights.py",
    {"scores": scores, "max_weight": 0.05},
)