Describe a target portfolio in Python¶
Use book() to return a desired portfolio across a universe. This is a different shape from per-instrument on_tick() rules; choose one entry style.
For per-instrument scalar signals sized jointly, use the separate forecast portfolio shape.
from atom.library.book import target
universe = ["TCS", "INFY", "RELIANCE"]
def book():
return target(weights={"TCS": 0.2, "INFY": 0.2, "RELIANCE": 0.1})
Weights are signed fractions: positive for long, negative for short. This example requests a 50% combined allocation before constraints and sizing. target(flat=True) returns an empty target and requests a flat portfolio.
Import target explicitly as shown. The constructor is a strategy-facing Python API; it is not automatically injected alongside the ordinary order vocabulary.
target(longs=[...], shorts=[...]) builds equal weights: both sides share half of gross exposure each; a single side uses full gross exposure. Available capacity, instrument support and execution determine confirmed holdings.
The platform translates the target into required orders. You do not need to call its order-conversion pipeline inside the strategy. For a scheduled book, read schedules and timeframes.
Read signed weights¶
For an equity basis of 10,000, a weight of 0.2 desires 2,000 long exposure. A weight of -0.2 describes the opposite direction. Two weights of 0.2 and -0.2 have 40% gross and zero net exposure; net zero does not mean no capital or margin is needed.
Explicit weights are used as authored; they are not automatically scaled to sum to one. Keys should be eligible instruments in the declared universe. A target is a desired book, and execution constraints determine admitted orders and confirmed holdings.
Understand equal-list defaults¶
| Constructor | Desired weights |
|---|---|
target(longs=["TCS", "INFY"]) |
+50% each. |
target(shorts=["TCS", "INFY"]) |
−50% each. |
target(longs=["TCS"], shorts=["INFY"]) |
+50% TCS and −50% INFY. |
target(flat=True) |
Empty target book; request flat holdings. |
If both sides are supplied, each side gets half of gross and divides it equally among its members. If only one side is supplied, it receives the full gross. To target a smaller combined allocation, supply explicit signed weights instead.
Recompute versus hold between evaluations¶
An undecorated book() is evaluated on each dispatched bar. Add a supported @recompute cadence if you intend periodic updates. A recomputation can adjust continuing holdings, enter new names and remove names absent from the target. Do not add independent on_tick() entry orders to the same target-book shape.
by_group carries a grouping hint; it is not itself a sector cap. Start with the explicit-weight example before adding advanced constraints or sizing policies that need additional inputs. See order reference for the live target signature.