Repository navigation
Conversation
…lt-in EMAX (#702) RunOptions.Worker swaps the built-in strategy for a worker dialed over loopback; everything else in the run is unchanged, journal included. examples/emax is the EMAX strategy written against the public SDK only, with a README. Parity tests run the built-in EMAX and the worker from the same data, settings and account (the six scenarios, a long two-instrument walk, and a real month through the store) and require identical journals, summaries and final positions. A worker that dies leaves a failed run with the events recorded until then. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #702. PR 2 of 2 (PR 1 is #716, the journal and the in-process path; the RunID port was #714).
What
trader backtest --worker host:porttrades with an external strategy process instead of the built-in EMAX. In the engine this isRunOptions.Worker:RunSeriesWithdials the worker (loopback only, the existingstrategyclient andstrategy_remote.goadapter) in place ofemaxEach. Nothing else changes: the same loop, account sizing, broker and journal.service.BacktestRequest.Workercarries it;run.jsonrecordsstrategy: {name: "remote", transport: "tcp", addr}.examples/emax: the canonical external strategy.main.gois the program (flags-addr,-short,-long,-stop,-tick, thenstrategy.ListenAndServe);emax/emax.gois the strategy and the EMA, written against the public SDK only (strategy,marketdata,num; a test keeps it that way). The README says how to run it, what the flags mean, how to compare with the built-in run and how to read the journal.onBarserror path. The one engine addition besidesWorkeris the strategy's name inSummary(x.strategy, fromstrategy.name()).Parity (the oracle is the unchanged built-in EMAX)
The same series, settings (windows 2 and 4, 1% stop), tick, fill assumptions and account (10,000 USD) are run with the built-in strategy and with the worker over loopback TCP, each journaled. Required equal: the whole journal (every order transition, fill and protective exit, in order, to the price), the summary (orders, trades, balance, equity, open positions) and the text a person reads. Only what names the strategy, the RunID and the wall clock may differ. The existing internal EMAX tests and fixtures are untouched.
trader_test.go): the six EMAX scenarios; a 1,500-bar, two-instrument seeded walk (over 100 fills, over 20 closed trades, stop-outs, shorts, stops cancelled by closes, so it is not a vacuous comparison).service/backtest_test.go): a real 600-hour month for two instruments built through the raw store and canonical build, with an odd spread so the mids are half ticks the engine rounds;RunBacktestwith and without a worker;run.jsoncompared after removingrun_id,strategy,started_at,ended_atand the result's strategy name;events.jsonlcompared line by line.cmd/trader): the example built and run as a separate process;trader backtest --workerprints the same summary as the built-in run.TestEMAXParity_ADifferentWorkerIsCaught).failedrun with the error (strategy remote: reading orders: EOF), noresult, and a journal that is exactly the first N lines of the full run's: nothing lost, nothing invented. A worker that is not listening, or on a non-loopback address, is afailedrun too.Findings and decisions to flag
ema, and no public indicator helper exists. I did not add a package for it. The duplication is marked inemax.go's package doc and protected two ways: the parity tests above, andTestEMAXParity_TheWorkersEMAIsTheBuiltInEMA, which feeds the same closes to both for windows 1, 2, 4, 10, 50 and 200 and requires the same float64 to the last bit. The stop arithmetic (MulRate,RoundDownto the tick, at least one tick) and the skip when a stop is above the largest price are copies too and are covered by the order comparison.-tickis a flag (default 0.00001, EURUSD and GBPUSD, the instruments the engine trades today). Another tick would need that flag.--from; the engine does not show those bars to a strategy that is not awarmer, and the service skips loading them for a worker. A run of the same range therefore agrees only when the month before--fromis not stored (or--fromis the start of the data); the parity tests use data with no earlier bars, a test shows the worker is not sent the bars beforetradeFrom, and the README and Users Guide say so. Warm-up over the wire would be a protocol change (a warm message), left for its own issue.newResulttolerates a trader with no strategy (an existing unit test builds one).Acceptance (#702)
/srv/trading/backtest/results, override by flag, environment or file; tests use temporary directories (PR 1).service).examples/emax/is independently runnable and documented, and shows how to find the journal (README; the CLI test runs the binary).195e457a…);make check(including-race) passes.Not here
Warm-up over the wire, data provenance and build digests, REST (#700), registration, a Trader-side listener, retention.
🤖 Generated with Claude Code