A turn-of-the-month stock basket strategy with calendar-only entries
A turn-of-the-month stock basket needs a frozen exchange-session schedule before it needs a price indicator. Define the basket independently, enter at the last session’s opening in one month, and request liquidation at the fourth session’s opening in the next month. Hold cash outside that interval. Counting weekdays is insufficient because an exchange holiday can move the fourth executable session.
This guide uses a short real NYSE calendar window and synthetic prices for two ordinary stocks. It is not an ETF strategy, a full-year seasonality study or evidence of historical excess returns. CoTrading’s automatic calendar retrieval, basket execution and missing-bar handling remain planned or unverified; the downloadable script implements the explicitly limited fixture described here.
Freeze membership separately from the calendar
The basket is fixed before the illustrated month end: forty shares of A and twenty shares of B. Stock identifiers and quantities are declared inputs, not selected using a later winning return. For a larger experiment, define how membership and weights were determined, when changes became known and whether delisted securities remain represented. A calendar effect cannot justify replacing a losing member after its return is observed.
The entry schedule receives dates only. It does not examine closing prices, volatility, returns or subsequent performance. This makes the source of the trade timing inspectable. If a future version adds a trend filter, liquidity rank or earnings exclusion, it becomes a new conditional strategy and should preserve a separate experiment record instead of being described as the same calendar-only rule.
The explicit starting account is 1,000 cash and no shares. The chosen quantities cost 800 before fees at the supplied entry prices. They leave a cash reserve rather than claiming exact full investment. Commissions are one currency unit per completed stock order, so the two-stock entry costs two and the exit costs another two. There is no borrowing, short selling or interest income in this fixture.
Count provided exchange sessions
The NYSE hours and holiday calendar identifies July 3, 2026 as the observed Independence Day closure. The provided session list is June 29, June 30, July 1, July 2, July 6, July 7 and July 8. June 30 is explicitly supplied as the confirmed final June session. The function does not discover that fact from a truncated price file.
The next-month sessions are July 1, July 2, July 6 and July 7 for the first four positions. Therefore the planned entry is June 30 and the planned exit is July 7. A weekday-only list incorrectly includes July 3 and puts the fourth weekday on July 6. The one-session difference is a calendar error even if a particular price path happens to make it profitable.
Validate that dates are unique and increasing, that the confirmed month end is present and that no later provided date belongs to that same month. Require at least four sessions in the immediately following calendar month. Do not take three July sessions and borrow a fourth date from August. The script rejects that incomplete calendar rather than silently moving the meaning of the rule.
The fixture additionally rejects the known July 3 closure. It is not a universal holiday-validation library: a real study needs an externally frozen complete exchange calendar, including relevant special sessions. The contract for this short window does not establish that an arbitrary hand-written list is correct merely because its dates are sorted and its rows pass a count check.
Decide at the opening, with no later-price filter
The final session and following month’s first four sessions can be scheduled from the confirmed calendar. At the June 30 opening, request both stock purchases without consulting that day’s close. At the July 7 opening, request both liquidations. This is an opening-to-opening exposure window, not a claim that the strategy holds only overnight or trades at month-end closing prices.
For a production system, record the exchange timezone, order-submission cutoff and eligibility for the opening mechanism. A planned opening date is not a guarantee of a particular fill. This fixture supplies executable opening prices and implements a simple commission model. Taxes, spreads, auction uncertainty, foreign exchange and actual broker restrictions require separately specified inputs.
An annual backtest must also define initial and terminal partial months. If the dataset starts after a planned entry, the account must not invent that earlier purchase. If it ends before the fourth next-month session, report an open position or an explicitly separate terminal valuation. Closing everything on the last available row would introduce a dataset-boundary rule that the calendar strategy did not request.
Reconcile the normal two-stock account
On June 30, buy forty A at 10 and twenty B at 20. The principal is 400 plus 400, and two fees reduce cash from 1,000 to 198. Holdings are A forty and B twenty, cumulative fees two. The account’s opening equity after the purchases is 998 when the shares are valued at those entry prices.
On July 7, sell forty A at 10.5 for 419 net and twenty B at 19 for 379 net. Ending cash is 198 plus 419 plus 379, or 996. Holdings are empty and total fees are four. A contributes a price gain of twenty, B a price loss of twenty, and the combined zero price profit becomes a four-unit net loss after commissions.
The script asserts exact quantities, sides, prices, order fees, entry cash, final cash and empty holdings. It does not settle for checking a single ending equity number. Those details are necessary because offsetting quantity or fee errors can accidentally produce the same total while representing a different basket or cost model.
Keep a missing price distinct from a closed exchange
The independent execution control retains the same valid July 7 session but removes B’s executable opening bar. The calendar does not move: liquidation is still requested that day. A sells normally, while B stays held and receives a missing_executable_bar rejection. After selling A, cash is 617, B inventory is twenty and fees total three.
At the next provided session, July 8, B has an executable price of 18.5. Sell its twenty shares for 369 net. Final cash is 986, holdings empty and fees four. The ten-unit difference from the normal account is twenty B shares times the half-unit price decline. It comes from delayed execution, not from silently redefining the fourth session as July 8.
Do not fill B at a carried July 7 price or pretend that its missing bar makes the whole exchange closed. A stock-specific data or trading problem differs from an exchange calendar closure. A larger portfolio may use another blocked-order policy, but it should retain the original requested date, reason, remaining inventory and eventual execution date so the cause of the exposure is visible.
Run the fixture and preserve its limits
Download the complete example, then run python R593.py with Python 3.12 or newer. Only the standard library is needed. The prices and account are synthetic; the short session-date window is frozen from the cited calendar. Output shows the provided dates, planned schedule, normal orders, missing-bar rejection and delayed exit account.
The assertions also reject incomplete following-month calendars, the official closed date and a cross-month attempt to borrow an August session. The schedule function has no price input, so appending favorable returns cannot change the intended dates. To extend the research, freeze more real sessions and point-in-time membership, then compare multiple periods without selecting only a successful month. One controlled cash bridge validates mechanics and leaves historical economic evidence as an unresolved research requirement.
Report requested and actual exit dates together
A portfolio report should retain July 7 as the requested exit for both stocks, show A’s completed sale and B’s rejection, and then attach B’s July 8 fill. Reporting only the final flat account would conceal the extra session of exposure. Reporting only the calendar signal would conceal its financial consequence. Keep the calendar version and price-coverage status alongside the cash ledger so a later corrected bar can be evaluated as a new data version rather than silently rewriting the original experiment.
FAQ
Why is the exit July 7 rather than July 6?
July 3 is an exchange holiday in this supplied 2026 window. July 7 is the fourth actual July session; July 6 is only the fourth weekday under the incorrect shortcut.
Does a missing stock bar change the calendar signal?
No. It blocks that stock’s execution. The control retains the requested July 7 exit and records the actual July 8 liquidation separately.