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
# 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)Current portfolio state: equity, cash, positions (shares), position_values, daily/total PnL, current_drawdown, and long-short exposures (gross_exposure, net_exposure).
ctx.portfolio -> PortfolioStateReturns
PortfolioState dataclass
Example
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 {}Access OHLCV bars, returns, fundamentals, and per-field panels. See the Data API for every method.
ctx.data -> DataAccessorReturns
DataAccessor
Example
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")The formulaic alpha-operator library, bound onto the context. Same callables as podium_sdk.alpha_ops.
ctx.ops.<operator>(...)Returns
pd.Series / pd.DataFrame depending on the operator
Example
mom = (1 + ctx.data.returns(lookback=126)).prod() - 1
score = ctx.ops.rank(mom) # cross-sectional rank in [0, 1]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.
ctx.run_skill_script(skill_name: str, script_name: str, input_data: dict) -> dictParameters
| Name | Type | Required | Description |
|---|---|---|---|
| skill_name | str | ✓ | Skill folder name |
| script_name | str | ✓ | Exposed script (per SKILL.md) |
| input_data | dict | ✓ | JSON-serializable input |
Returns
dict: JSON result returned by the script
Example
weights = ctx.run_skill_script(
"portfolio-construction",
"compute_weights.py",
{"scores": scores, "max_weight": 0.05},
)See also Data API, Alpha Operators, and Skill Bundles.