Start a stock simulation from a frozen holdings snapshot
Starting a stock simulation from existing holdings requires a dated quantity snapshot and an independently confirmed cash assumption. Stock market value is not cash that the virtual account can spend again. Freeze the opening assets, declare uncovered positions and let the simulation diverge independently from later real-account activity rather than silently synchronizing changes into its history.
This guide uses a fully synthetic holdings snapshot and synthetic later account update. It accesses no user account, statement service or broker. Initializing an ongoing shadow branch from existing holdings is an external extension, not a verified CoTrading feature or a capability implied by an original batch shadow backtest. The example establishes only its declared partial-scope virtual ledger.
Obtain a read-only opening snapshot
A real research input would need a confirmed snapshot timestamp, security identities, quantities, currency and source reference. Keep the raw export read-only and build normalized working data separately. A holdings list without an as-of boundary cannot establish which transactions preceded the experiment or whether later quantities accidentally entered its starting state.
The SEC fees bulletin recommends checking account statements and trade confirmations when understanding costs. Those records can help establish actual assets and charges, but this article imports none. Its account-like dictionaries are invented fixtures, not an anonymized extraction of a user’s real positions or a completed account reconciliation.
Our supplied snapshot is dated January one, 2026 at 16:00 UTC, with USD holdings A two shares, B three and C five. The timestamp is a fixture boundary, not a claim that any real exchange was open or those quotes existed then. The initializer requires an explicit offset and accepts only this example’s USD scope; currency conversions and multi-account consolidation are outside its contract.
Map quantities into the verified basket
The observation basket contains A and B. Exact supplied identities map to those two keys; C is uncovered. The initializer requires an explicit exclusion reason for every uncovered holding and no unrelated exclusions. Without that confirmation it raises an error rather than silently deleting C or renormalizing the remaining stocks into a supposedly complete account.
The accepted branch is therefore labeled active_partial_scope, and C’s exclusion remains attached to it. A five-share C position has not disappeared from the actual-like input; it is simply not part of the simulated account being studied. Its value is unknown here because no C quote is supplied. Do not call the A/B branch the investor’s complete portfolio or infer a full-account return from it.
Validate quantities as nonnegative integers under the fixture’s whole-share convention and reject blank security identities. Actual fractional holdings, share-class mappings, lot restrictions and corporate-action adjustments need separately verified handling. A stock’s presence in a planning basket does not prove the current application can obtain timely data or execute it under real market rules.
Confirm cash without selling the holdings on paper
At opening marks A=100 and B=50, covered stock value is 2100 + 350 = 350. When independent cash is None, the result is waiting_cash with covered_value=350 and no cash field. This is a valid preparation result, not an active account with 350 spendable money. The program does not liquidate the starting holdings or assume their value is an additional deposit.
After explicitly supplying cash 200, the branch opens with that cash, A two, B three and initial NAV 550. The 350 of stock and 200 of cash are different assets. The cash assumption must state whether it represents confirmed available funds or a deliberately chosen virtual research allocation; do not present an arbitrary experiment amount as a verified broker balance.
The Python Decimal documentation supports decimal-string arithmetic and finite checks used for money and marks. The initializer rejects NaN or nonpositive marks, negative or nonfinite cash, missing required marks and unconfirmed exclusions. The opening prices are assumed to be prepared for the supplied boundary; this small helper does not independently verify quote timestamps or market calendars.
Freeze the original input and independent branch
The fixture retains an original snapshot copy and a digest of its serialized representation. After initialization and later virtual activity, the original object and digest must remain unchanged. The branch receives its own copied share dictionary. These tests address accidental mutation in this program, not authentication of the snapshot source or proof that the opening time was independently preregistered.
The branch carries the original as-of time, USD currency, human-v1 label, accepted holdings and exclusion reasons. This version label identifies the demonstration’s manually supplied interpretation; the program does not generate or learn a rule. It receives a later illustrative buy request directly. A real observation workflow would also freeze the executable rule and its decision-time inputs before producing such requests.
Record the initialization decision separately from later events. Replacing opening quantities after observing the result changes the experiment’s starting exposure. If a source correction is discovered, preserve the original branch and explain the corrected version or rebuild from an independently trusted boundary. Do not edit only the ending balance while leaving its starting provenance unchanged.
Trace the first virtual transaction
At the next synthetic marks A=110 and B=45, the untraded branch is worth 200 + 2110 + 345 = 555. This change from 550 is valuation, not a new cash deposit. The proposed virtual purchase is one A at 110 with fee one. It requires 111 of the confirmed 200 cash and is affordable.
After the buy, cash is 89, A three shares and B three shares. Same-price NAV is 89 + 3110 + 345 = 554, exactly the pre-trade 555 less the fee. The function verifies the cash-plus-A bridge and leaves B unchanged; the separate full-branch valuation confirms all accepted holdings remain represented.
Now request another A at price 100 with fee one. It needs 101 but has only 89 cash, so the action is rejected. The existing stock value cannot fund it automatically. This counterexample targets double counting of opening assets, a different mechanism from excluding C or rejecting a missing quote. Borrowing and unconfirmed future sale proceeds are not enabled.
Keep later actual-like updates separate
The program constructs a later synthetic real-account-style snapshot showing B zero and cash 335. It does not feed that update into the branch, which still has B three and cash 89. This models the separation policy without accessing any actual account feed. A later human sale is not automatically a virtual sale under the frozen candidate rule.
At subsequent marks A=105 and B=40, the independent branch NAV is 89 + 3105 + 340 = 524. That is the value of the partial A/B virtual branch only. The later real-style input still contains uncovered C information and does not provide a directly comparable complete account valuation. Do not report their difference as the strategy’s counterfactual profit.
If intentional synchronization is wanted, define it as a new experiment or explicit external flow with documented quantities and cash effects. Silent synchronization can make a rule appear to anticipate human decisions and breaks attribution of virtual results. Keeping branches independent is essential for evaluating whether the frozen rule behaves differently from the supplied actual-like records.
Run and accept the initialization package
Download the complete example, save R648.py and run python R648.py with Python 3.12 or later. It uses only the standard library and synthetic snapshots. Assertions verify waiting cash, covered value 350, opening NAV 550, marks 555 and 554, cash 89, final partial NAV 524, unchanged source and refusal of unconfirmed exclusion, unaffordable action and NaN valuation.
Deliver the source boundary, accepted identity/quantity mapping, uncovered ledger, cash assumption, opening marks, rule reference and independent branch state. Mark incomplete scope prominently. None of these artifacts authorizes live trading or proves a winner-derived rule effective. Five profitable source rounds, if used by another preparation workflow, cannot substitute for valid opening assets or independent future observation.
FAQ
Can covered market value become the opening cash balance?
No. Existing shares remain shares. Unknown cash leaves the example waiting rather than creating an extra funded account.
Does a later real sale automatically change the simulation?
No. The branch remains independent. Any intentional state transfer needs an explicit new policy and recorded asset movements.