Verify stock factor direction before building a long-only basket
A lower-is-better stock factor must reach a long-only portfolio through an explicit direction mapping. Preserve the raw measurement, create a utility score with a declared preference, name the preferred group consistently and construct nonnegative share targets. A negative utility score is not a sell-short instruction.
This guide uses four invented US stocks with synthetic risk measurements and prices. Lower raw values are preferred by assumption for this experiment, not established as universally superior investments. CoTrading factor-direction checks remain planned or unverified. The deliverable is a direction contract, a hand-calculated cross section and a separate executed-quantity ledger.
Separate measurement, preference and instruction
The raw field describes something measured, such as an annualized volatility estimate or a positive valuation multiple. Its unit and valid domain belong to the data definition. The preference field says whether larger or smaller valid observations are favored. The execution field says how many shares to buy or sell. These three concepts should not share one ambiguous column called signal.
In this fixture the raw observations are A at 0.10, B at 0.20, C at 0.30 and D at 0.40. Treat them as supplied synthetic measurements, not as estimates calculated from historical returns. The economic hypothesis prefers lower values. It does not imply that a negative raw volatility is valid or that all valuation metrics should share the same domain.
Validate each metric before applying direction. A missing observation remains missing; an invalid denominator does not become an attractive negative valuation score. Otherwise a seemingly successful sign inversion can rank data errors ahead of real stocks. Document exclusions separately so direction and coverage changes can be diagnosed independently.
Choose one mapping and preserve its meaning
Define utility as minus the valid raw value. Higher utility is always preferred in the selection layer. Utilities become minus 0.10, minus 0.20, minus 0.30 and minus 0.40. Descending utility therefore selects A and B for two long slots, exactly matching direct ascending raw-value selection.
Use a stable identifier as the secondary sorting key. Python’s sorting documentation describes explicit key-based ordering. The example applies the sign conversion once, then sorts by preferred utility; reversing the sorted list again would invert the economic direction a second time.
Keep raw and utility columns together in the exported panel. A reviewer should be able to point to the lowest raw observation and find it in the highest-utility group without interpreting a chart’s colors. The transformation is a representation choice. It does not add forecast information or prove that the chosen raw metric predicts the subsequent return.
Make group names and order meaning agree
If groups are sorted by utility, label the highest group as preferred high utility and show that it corresponds to low raw values. If a report instead names groups by raw-value quintiles, the preferred group may be the lowest-numbered one. Save the mapping rather than assume that a column called top always means the same thing.
The account here is long-only. Every selected stock receives a positive target of forty shares. Unselected stocks receive zero target. The negative signs in utility never flow into quantity as negative shares. This explicit conversion avoids an interface in which a factor measurement is accidentally interpreted as a signed trade instruction.
Targets are desired holdings, not repeated buy orders. A persistent selected member should not receive another forty-share purchase merely because its utility is negative again tomorrow. A production execution layer must compare target quantity with actual holdings and apply its market rules. The small fixture starts flat and demonstrates entry only.
Reconstruct the approved basket’s cash
Start with 1,000 USD-equivalent teaching units and no shares. Both selected stocks have a supplied entry open of ten. Buy forty A shares and forty B shares, charging a fictional fee of one for each order. Purchase notional is 800 and total fees two, so cash remains 198.
At the supplied later marks, A is 10.2 and B 9.9. Their positions are worth 408 and 396. Add cash 198 to obtain equity 1,002. The account has a two-unit marked gain from its initial capital after entry fees, while both positions remain open. It is not a fully liquidated profit because no sale or exit charge has occurred.
The chosen stocks do not both rise, which is useful for checking the ledger. The direction contract governs selection from measurements, not a promise that every chosen name will have a positive return. Retain the individual values so a favorable total cannot hide an incorrect sign or an omitted losing position.
Use reversed direction as an outcome trap
The deliberately wrong implementation sorts raw values descending and selects D and C. It pays the same two entry fees and also keeps 198 cash. Later D at 10.3 and C at 10.1 give position values 412 and 404, so its equity is 1,014. The wrong-direction basket happens to outperform the approved basket on this invented path.
That outcome does not justify changing the direction after seeing returns. It is the boundary test: performance can look better even while the code violates the declared hypothesis. Acceptance must compare expected members and quantity signs, not choose whichever account has the larger final number. Both paths need their own explicit orders.
Also avoid treating a high-minus-low statistical spread as an executable short portfolio. A subtraction between group returns is an analytical contrast; actual short trading would require a separately specified instrument, borrowing and execution model. This guide supplies only positive long entries and makes no assertion that unselected names can be borrowed or shorted.
Run the direction acceptance file
Download the complete example, save it as R567.py and run python R567.py with Python 3.12 or later. It uses only the standard library and synthetic inputs. The repository source is docs/growth/research/round-5/examples/R567.py.
Assertions require A/B after the declared sign conversion, D/C in the intentionally reversed control, nonnegative quantities despite negative utilities, cash 198 and marked equities 1,002 and 1,014. The output includes raw values, utilities and actual buy orders, making each layer inspectable instead of exposing only the preferred group’s return.
Extend direction checks to real research
Save metric definition, valid domain, preference rationale, transform, tie policy, group labels and target semantics in the same version. Review one very low valid value, one very high value, one tie and one unavailable observation before loading a large panel. A valuation metric with losses needs an explicit domain policy rather than a blanket assumption that the smallest numeric value is attractive.
If a vendor reverses a rating scale or changes its definition, update the mapping and rerun the member assertions. Do not discover the reversal only from an unexpected negative correlation. Keep score transformation changes separate from quantity-rule changes so cost and exposure differences can be attributed to the correct layer.
The completion condition is consistency: a hand-selected economically preferred stock must be selected by the code, the preferred label must point to it and the ledger must contain only permitted long quantities. Historical return evaluation comes afterward and may reject the economic hypothesis without changing what the original experiment meant. Preserve that distinction rather than relabel a failed directional hypothesis as a successful opposite strategy.
Check equivalent representations at the boundary
For this fixture, direct ascending raw-value sorting and descending negative-utility sorting must give the same selected names. The script checks that equivalence. It is a useful handoff invariant because an accidental extra reversal can leave every number finite and every order syntactically valid while selecting the wrong end of the cross section.
Preserve the preference rationale outside the performance report. It should identify the economic measurement and the intended direction, not cite the favorable control result as its reason. A new rating scale or a metric with a different valid domain can require a new mapping. Review that mapping before account evaluation so negative utility, negative raw observations and negative trading quantities cannot be conflated into one generic “negative factor” category.
FAQ
Do negative utility values mean short positions?
No. Utility controls ordering; this contract converts selected names into positive long-share targets.
Can I reverse direction if the control basket performs better?
That requires a new disclosed experiment. It cannot retroactively repair a violation of the original specification.