Five robots, one dollar bet: grouping strategies by behaviour
A worked Forex example shows how to group trading robots by currency exposure, co-activity and marked PnL, then test whether those groups hold up across sessions.

Five labels on the same side of the dollar
Opening Range, Cable Snapback, Yen Channel, Aussie Drift and Franc Reversal sound like five assignments on a research desk. At 08:30 UTC in an invented European session, all five robots are carrying short US dollar exposure. Some bought a pair, and others sold one. Each log has a different explanation for the entry. A sixth robot, Cross Close, stays flat until later that day. What has to happen in the market for several of these apparently different systems to struggle together?
An individual equity curve compresses a long sequence of decisions into a history of marked account value. It can show whether a robot lost money in a particular week, but the curve alone seldom tells you whether that robot shared its neighbours’ exposure at the critical minute, whether it had already gone flat, or whether they were all paying to exit at the same time. A clean end-of-day comparison may bring an overnight trend follower and a ten-minute contrarian together simply because both finished up on the same dates. It could also put two concurrent dollar shorts far apart because one traded through a volatile part of the session and the other left early.
Here, a behaviour group is a set of robots that resemble each other on specified measurements over specified observations. A group defined by opening hours answers a different question from a group defined by how portfolios respond to currency moves. Grouping is descriptive. A colour on a chart carries no instruction about position size, whether to combine strategies, or what they might earn. State the dependency you want to investigate before choosing a similarity measure. In this exercise the first dependency is a shared dollar move while the five systems have inventory. Later we ask about common execution conditions and joint losses.
Every robot, quote, schedule, position, observation and result below is hypothetical. The first session is a constructed example of what one might discover, so five simultaneous dollar shorts say nothing about how often this happens. Work outward from that single snapshot. Identify the inventory, reconstruct the time spent together, and see what different summaries would make visible. The interesting result is the discrepancy between plausible summaries, particularly when they tell you to inspect different parts of the same log.
Describe the robots in two layers
Give every strategy a stable ID and record the rule description separately from observed behaviour. Opening Range, or A, buys EUR/USD on an opening breakout and plans to hold for about an hour. Cable Snapback, B, buys GBP/USD after a dip and aims to exit within forty-five minutes. Yen Channel, C, sells USD/JPY on a channel break with a forty-five-minute hold.
Aussie Drift, D, buys AUD/USD on momentum with an hour planned. Franc Reversal, E, sells USD/CHF on a reversal and holds for roughly an hour. A through E use the European morning research window in this example, regardless of where their currencies are issued. Cross Close, F, buys EUR/GBP on a reversion signal in a later window and can carry inventory for four hours.
| Robot | Pair | Example direction | Window | Planned hold | Logic family | Example event exposure |
|---|---|---|---|---|---|---|
| A | EUR/USD | Buy | Morning | 60 min | Breakout | Open at 08:40 USD event |
| B | GBP/USD | Buy | Morning | 45 min | Reversion | Open at 08:40 USD event |
| C | USD/JPY | Sell | Morning | 45 min | Breakout | Open at 08:40 USD event |
| D | AUD/USD | Buy | Morning | 60 min | Momentum | Open at 08:40 USD event |
| E | USD/CHF | Sell | Morning | 60 min | Reversion | Open at 08:40 USD event |
| F | EUR/GBP | Buy | Later | 240 min | Reversion | Flat at the event, open at later EUR event |
The 08:40 USD event and a later EUR event at 14:00 are invented. The event feature describes the positions in this scenario. In a longer record it would become a measured fraction of covered event windows with inventory, accompanied by the count of eligible windows. A robot may allow trading around a release and happen to be flat that day. Conversely, a rule that forbids fresh orders can still leave a prior trade open. The distinction determines whether the event field can be derived from configuration or needs an actual position history.
Keep the logic family in the profile because it suggests what to look for when behaviour changes. If a breakout and a reversion entry align today, tomorrow the same drop could make one buy and the other sell. Record typical realised holding time from the logs alongside the intended hold, ideally with an upper quantile when there is enough data. A strategy usually flat within an hour may overlap a later strategy through a handful of lengthy exceptions. With two layers, a reviewer can trace a claimed difference to an observed outcome or to a rule awaiting observation.
Put both legs of each trade on the same ledger
At 08:30, value the snapshot in USD at simultaneous illustrative mid quotes. A buys 10,000 EUR at 1.10 USD per euro, carrying positive 10,000 EUR and negative 11,000 USD. B buys 8,000 GBP at 1.25, giving positive 8,000 GBP and negative 10,000 USD. C sells 9,000 USD at 150 JPY per dollar, giving negative 9,000 USD and positive 1,350,000 JPY. D buys 10,000 AUD at 0.65, giving positive 10,000 AUD and negative 6,500 USD. E sells 5,000 USD at 0.90 CHF per dollar, giving negative 5,000 USD and positive 4,500 CHF. F has no position at this instant. For the arithmetic, assume the existing positions were all opened at those same prices. These economic legs describe the simplified trades, while the broker’s funding and margin would require a separate ledger.
The five signed USD legs sum to negative 41,500 USD. At entry quotes, the foreign legs are worth positive 41,500 USD in total, so the initial marked value of this simplified exchange is zero. Both statements can hold at once. If each foreign currency then becomes worth exactly one percent less in dollars, without new fills or costs, the foreign legs are worth 41,085 USD while the USD legs stay fixed. The combined mark falls by 415 dollars. An identical percentage shock requires care with quote direction. In this scenario the new EUR/USD mark is 1.089, and the new USD/JPY mark is 150 divided by 0.99, about 151.51515. The yen’s dollar value falls by precisely one percent under that reciprocal quote.
Later, assume F buys 5,000 EUR at 0.88 GBP per euro. Its legs are positive 5,000 EUR and negative 4,400 GBP. At the stated dollar conversion rates they are worth positive 5,500 USD and negative 5,500 USD. Under the same proportional shock they would be worth positive and negative 5,445 USD. Their sum stays zero in this stylised move. A change in the relationship between euro and sterling can still move the mark. If F trades alongside A on another day, both have a positive euro leg even though F has no direct USD leg. Preserve the full currency vector so the choice of reporting currency cannot hide a shared component. The gross and net exposure article develops related aggregation conventions.
Measure how much of the session they actually share
The ledger captures one instant. For a co-activity measure, read intervals from filled entries and exits, with the end excluded. Suppose A holds from 08:00 to 09:00, B from 08:15 to 09:00, C from 08:00 to 08:45, D from 08:30 to 09:30 and E from 07:45 to 08:45. F holds from 12:00 to 16:00. All five morning positions overlap for fifteen minutes from 08:30 inclusive to 08:45 exclusive. There is a long period when at least one robot is active, and a much shorter period when the particular stack of exposures in the ledger exists. An event at 08:40 sits inside the overlap. An event at 08:45 sits on a boundary whose treatment depends on the fill order and clock resolution.
For A and B the intersection is forty-five minutes and the union is sixty. Their intersection-to-union ratio is 0.75. A and D share thirty minutes across a ninety-minute union, giving one third. Informal labels such as “morning trader” lose this distinction. The ratio also differs from asking how much of B’s active time A covers, which is forty-five out of forty-five in this example. The symmetric ratio helps compare pairs. The conditional measure helps when your question is whether a short strategy tends to arrive inside another’s longer holding period.
Repeat the calculation with direction. Both robots can be open and hold opposite dollar signs, or one can be open in a currency cross with zero direct dollar leg. Position overlap, same-sign dollar overlap, and exposure size during the overlap are three separable observations. Use the raw intervals for a first comparison and keep weighting by size in a second view. A researcher can then spot whether a big same-sign concentration reflects a habitual pattern or one unusual order.
There is also an order-side question. Two robots might never hold inventory together but submit orders within the same second, compete for a quote, and then exit at different speeds. Compare timestamps for decisions, submissions and fills if those fields exist. An overlap of intended entries can coexist with zero overlap in executed inventory. Sparse order timestamps belong on their own grid or in an event matching study. For a holding overlap, reconstruct intervals from fills and account explicitly for partial closes, unresolved positions and the timezone.
Measure money on a common clock
For PnL, put each robot on the same regular grid and compute the change in marked value between consecutive snapshots, accounting for trades, realised increments and costs so that closing a position cannot count the same gain twice. In the thought experiment, marked PnL means economic value through time, inclusive of open inventory. Choose a single valuation convention. Mid marks plus separately recorded costs against mid can work for a market-move study. If the ledger already uses actual fill prices, reconcile their share of execution cost before any additional adjustment. An executable-side valuation asks how much inventory liquidation might have been worth at that moment and will behave differently when spreads widen. Mixing conventions within a matrix can group feed treatments instead of strategies.
Choose a common reporting currency and decide whether to compare money or normalised changes. Four dollars on a fixed common 10,000 USD reference is four basis points. One robot’s percentage change on 2,000 dollars and another’s on 20,000 can look very different in a distance on magnitudes, even when the underlying dollar changes match. Pearson correlation for two nonconstant series is invariant to positive constant scaling of either series. Scaling still matters for average losses, group sums, mixed-feature distances and denominators that change through time. If a robot’s denominator jumps with margin usage, the choice can manufacture a new pattern. Preserve a common denominator for an absolute comparison and state explicitly when an experiment instead equalises sensitivities to study shape.
Counting trades per interval can expose bursts of decisions. It says little about whether there are open positions during intervals with zero fills. A closes once at 09:00 yet its marked PnL can move throughout the preceding hour. B can close, reopen and close again within one bucket. It ends flat but still generates PnL through the trades and their costs. A sequence based on close events assigns A’s price move to the exit bucket. That can shift apparent synchrony toward matching exit times while missing a shared adverse move at 08:40.
Select the grid before inspecting which one makes a candidate pair look most distinct. Fast common shocks can disappear into hourly marks after a recovery. Minute marks may overstate precision if one feed updates sporadically. For this study, compare five-minute bars over fully covered mornings, with finer event analysis only where timestamps and marks support it. Use end-of-bucket inventory for snapshots and fill intervals for time overlap, so a position open across a boundary is treated consistently.
Distinguish idle zeros from missing observations
Imagine a complete interval after F closes. Its flat position and lack of fills justify zero incremental trading PnL in the simplified ledger, assuming no costs post in that interval. A feed outage during F’s open afternoon position gives an unknown change in mark. Replacing it with zero says the inventory had no change in value, a statement the record cannot support. A stale quote can be just as misleading. Store quote age and position state together so a flat observation with an irrelevant missing quote remains distinguishable from open inventory with no usable mark. If fills or reconciliation are missing, even the flat claim may need to be withheld.
Keep missing, flat and active states identifiable after aggregation. A known flat interval can legitimately have a recorded commission or financing charge, so state and PnL need separate fields. An unknown realised outcome after a lost fill message is a different data problem from a known position with a missing mark. Have one coverage mask for fills and another for prices, and record the policy that decides which combination qualifies a row for each analysis. A single global flag can otherwise discard good holding-time observations because a quote was unavailable at an unrelated boundary.
One useful comparison is whole-schedule versus jointly active PnL. Whole-schedule includes verified idle zeros. It addresses what the combined stream looks like over the common reporting horizon. Jointly active uses covered intervals where both robots carry positions, which addresses the response while both have inventory. It changes the population. Conditioning on overlapping trades may select volatile mornings when both entry rules were triggered. Report the count and calendar span of those observations with the statistic. If A and F have no overlap, the conditional correlation is undefined, while a full-schedule correlation may still be calculable. That separation keeps evidence about shared live exposure distinct from evidence about the full schedule.
The mask matters especially in a six-robot matrix. Computing each pair on whatever rows happen to be available can compare A and B during a release week, and A and E during quiet days. Review pair counts and common days first. For a small study, one clean shared panel makes the main matrix interpretable, with a separate report explaining what coverage was lost. When the common panel becomes too small, restrict the question to comparable robots or show unavailable comparisons explicitly. Monthly gaps deserve their own entry in the research journal because coverage can be related to market stress.
Read the correlation beside the exposure
Use A and B over four hypothetical five-minute intervals starting at 08:30, with the final interval ending at 08:50 and both robots still open. Suppose their USD marked changes after applying the same valuation convention are, respectively, minus four, plus four, minus four and plus four dollars for A, and plus three, minus one, minus three and plus one for B. In this miniature calculation both series sum to zero. The sum of cross-products is minus twelve, minus four, plus twelve and plus four, which totals zero. The sums of squared changes are sixty-four and twenty. The resulting Pearson correlation is exactly zero, as the centred cross-product numerator vanishes and both series have positive variation.
At 08:30 those two robots have a shared short USD leg of 21,000 dollars. Their foreign legs would lose 210 dollars in the special proportional shock from the ledger. Observed prices in ordinary intervals can move at different speeds and in different directions. Sterling and the euro can react to different local flows. Four interval marks are an arithmetic demonstration, far too little to estimate a dependable correlation. One could see a larger positive value in a session dominated by a broad dollar move, or a negative one if the currencies move against each other. Use inventory to propose a mechanism and marked changes to see how it appeared in a specified sample.
For paired, nonconstant vectors, SciPy’s correlation distance documentation defines the centred distance as one minus correlation under its usual unweighted setting. The four interval vectors therefore have distance one on that measure. If either series is constant, the centred norm vanishes and the calculation has no defined correlation. A robot with zero changes throughout an inactive period needs a separate status in the matrix.
When you turn signs into distances, decide whether opposite directions should be far apart. One minus correlation places perfectly opposing traces at distance two. For studying a common market driver, you may also want to flag strong inverse moves and inspect whether their positions point to opposing exposure to the same driver. That is a separate diagnostic with a different interpretation. Low linear correlation gives no assurance of stable independence, and high correlation by itself does not identify a cause.
Record rare joint losses before averaging them away
Consider a separate hypothetical ten-session record with intact marks. Define an event before looking at outcomes and treat all ten mornings as the denominator. Say A has two sessions with an event-window loss greater than 50 USD, B has three, and both cross that threshold on one session. The joint count is one out of ten. Conditional on A crossing the threshold, B does so one out of two. Conditional on B crossing, A does so one out of three. These are three views of the same small table, each addressing a different question. The sample is too small for precise frequency estimates. If the threshold is meaningful only relative to position size, a distinct normalised loss study can accompany the dollar threshold.
If the only joint loss occurs when both positions were already open before a release and both paid wider spreads on exit, examine two plausible sources of loss. Reconstruct the mark change through the window, then compare recorded execution against the specified benchmark at valid timestamps. If the marks deteriorate while fill costs stay ordinary, the currency move is a stronger explanation within the example. If recorded fill costs rise as marks barely move, inspect a shared execution dependency. Both effects can occur together, and attributing each needs enough observations to reconcile the trade ledger.
Build a joint-loss register with the event time, currency legs before the event, time overlaps, prices used, costs, loss thresholds and data-quality flags. Keep observations with zero or one threshold crossing too. Removing every quiet event leaves a set selected by the outcome. Store a separate all-session view for loss episodes outside scheduled releases, because unscheduled shocks and routine liquidity transitions would be invisible in an event-only record. If a release leads to repeated five-minute loss observations, keep the session as an additional counting unit so one episode does not appear to be ten independent shocks.
Consider a group where frequent minor wins and losses offset, but every member holds through the same rare move. Average co-movement is then answering a question about all intervals, where this particular move has little weight. Event-conditioned overlap and the joint-loss register tell you where to look in the raw record. Correlated outcomes may still have an explanation unrelated to currency direction, including a stale feed used by every strategy. Write down the plausible explanation and a check that could weaken it. For an execution explanation, a joint deterioration visible before any order was submitted would shift attention toward market marks or data quality.
Assign weights to features you can defend
Build a distance specification from the question and expose its parts. For the six robots, suppose it uses three binary differences. Charge 0.50 when their direct USD exposure categories in the reference scenario differ, 0.30 when morning versus later activity differs, and 0.20 when the logic family differs. A and B differ only in family, so their distance is 0.20. B and E share all three feature values and score zero despite different pairs. B and F share a family while differing in exposure category and session, giving 0.80. Zero here means agreement on the chosen features. The identity of pair, position size and typical duration can explain meaningful differences among robots a simplified distance ties.
If you include categorical pair and family values, treat a mismatch as a mismatch or define a deliberate similarity structure. Assigning breakout the number one, momentum two and reversion three creates an ordering with no established meaning. Encoding categories as indicators makes comparison possible, but weighting every indicator independently can make one field with many categories dominate, especially when including both pair and its component currencies. Set the importance on the field or family of features. Check what gets counted more than once. Active at the USD event and active in the morning are identical across the morning five on this day. Giving both a full independent weight would exaggerate the evidence for a shared schedule.
For quantitative features, document the scale. A raw difference between forty-five and 240 minutes will dwarf a co-activity difference bounded by one. Choose a scale that matches the question, such as a capped difference divided by an explicitly chosen duration, or compute conventional scaling from a reference period and freeze it for future comparisons. A coarse hold band can be easier to defend when sample counts are small. Try multiple reasonable choices. If A and B stay close only when logic gets almost no weight, the finding is conditional on your study being about exposure and schedule.
Missingness needs a rule at this stage too. Withhold a distance where an essential feature is unknown. If incomplete auxiliary features are allowed, show what was compared, because rescaling the remaining weights can make a poorly covered pair appear close. For an initial map of six robots, publish the feature values beside the matrix so the effect of each choice can be checked directly. A cluster plot becomes reproducible when a reader also has the currency signs, time window and weights.
Choose linkage that fits the distance
Using the simple weighted mismatch above, agglomerative clustering starts with one group per robot and successively joins groups. Under average linkage, the distance between two groups is the mean of all cross-group pair distances. B and E can first join at zero. A and C also match across the three fields and can join at zero.
The average distance from that second pair to B and E is 0.20, since all four cross-pair comparisons differ only in family. D differs in family from A, B, C and E, so its distance to each of them is also 0.20. The order of merges at that height can vary with tie handling, so an interpretation of the little branches would be fragile. At a threshold of 0.25 the five morning robots are together and F remains separate.
For the last merge between F and the morning five, the distances to B and E are 0.80 each. The distances to A, C and D are 1.00 each. Their mean is 0.92. That height describes dissimilarity under the proposed weights. A dendrogram records the grouping procedure, whose inputs in this example contain neither observed joint loss rates nor a labelled hierarchy of market mechanisms. Treating its branches as permanent, biological-style categories would assign the diagram a causal meaning the feature definitions never supplied.
SciPy’s linkage reference distinguishes a condensed vector of distances from a two-dimensional input of observations. Passing an entire square dissimilarity matrix as the latter would make its rows into observations. The resulting clustering compares distance profiles and will generally answer a different question. Check the order of robot IDs when constructing the condensed vector. A shuffle in only one side of an export may leave the tree looking sensible with the labels attached to the wrong rows.
Ward linkage is correctly defined for Euclidean distances in the linkage formulation documented by SciPy. It aims to merge groups with a small increase in within-group squared variation. It can be considered when you choose Euclidean feature vectors with an appropriate scaling and interpretation. Here we have specified a mixed-feature dissimilarity and would need to establish the Euclidean property before using Ward. Use average linkage with the specified dissimilarity. If switching to an explicit vector representation with Ward, record the new distance and the motivation. Scikit-learn’s clustering guide discusses how algorithm choice and evaluation depend on the representation and structure being sought.
Track what changes when the market or schedule changes
Suppose in a second hypothetical period C is observed in a later session and tends to buy USD/JPY, changing both of its exposure and schedule categories. F still operates later with zero direct USD leg. Keep C’s breakout logic field fixed. In a three-category exposure scheme that distinguishes short, long and absent direct USD legs, C remains a mismatch to F on exposure and family, at distance 0.70. Its distance from A is 0.80, and its distance from B, D and E is 1.00. Reapplying the same rule and the 0.25 threshold leaves a group of A, B, D and E, with C and F each separate. C and F can be closer to each other than C is to the morning group without joining at the declared cut.
A shift in behaviour can come from a different market regime under identical rules, a changed run configuration, or a data problem that changes observed participation. Distinguish those explanations with configuration histories and coverage records. Rebuild features on comparable time windows, such as successive months of covered sessions with the same timezone conventions, and check how many days actually had both strategies available. Also check changes in relative position size. A robot could preserve its directional category while its absolute exposure doubles, something the illustrative distance omits.
Measure pairwise co-membership across windows. The percentage of eligible windows in which A and C share a group makes sense even when group labels are arbitrary. Give the numerator and eligible denominator, and record which windows were removed. Where observations come in dependent blocks, a sensitivity exercise can resample groups of consecutive sessions and see whether a proposed grouping survives plausible changes in the sample. A cluster repeatedly recovered from adjacent overlapping windows may rely on the same market episode each time. Look at the dates and whether a single release keeps turning up in overlapping samples.
Test group stability separately from the story that explains a group. Stable same-session behaviour could come from a schedule shared by design and still say little about sensitivity to a particular release. An unstable group can also reflect a robust rule reacting correctly to a change in market conditions. Reinspect which features moved and whether those variations matter for the research question before trying to stabilise the labels by changing weights.
Compare a group summary with the positions underneath
Suppose a reviewer asks how much of the five-robot group is usually exposed during a release. A report that shows only the mean signed USD leg per robot would give negative 8,300 dollars at 08:30. Multiplying by five recovers negative 41,500, but the member mean is easy to misread as the group’s exposure. It also obscures the difference between A’s 11,000 and E’s 5,000. Keep the total next to the individual legs and state which positions contribute at that timestamp. When the question is persistence, repeat the inventory calculation across times of interest and show both the share of covered snapshots with a concentration and the size when a concentration occurs.
The same distinction applies to equal-weight versus actual-size views. Normalise each of A through E to a 10,000 USD short leg in the arithmetic example and the joint short becomes 50,000 USD. The common proportional shock now gives a hypothetical loss of 500 dollars. The difference from the original 415 dollars comes entirely from imposed sizes. The new view asks how similar their signed economic directions would be at a fixed dollar sensitivity to this shock. It cannot stand in for the marked PnL of the original trades. Even within the normalised view, a move specific to one of the foreign currencies would distribute losses differently.
Check whether a group representative would conceal an important member. If B and E tie on the simple distance, either can stand for the feature values, but the sample exchange rates and relative sensitivities differ. B buys sterling and E buys francs through its sale of USD/CHF. A sterling-only fall of one percent against USD, holding the other marks fixed, gives B a 100-dollar loss at its original size and leaves E unchanged. This hypothetical shock is another way to decide which distinctions to preserve before reducing a group to a label.
Keep the member-level record behind every group summary. A second reviewer should be able to reconstruct both the aggregate and a differently weighted view from the same inputs. That makes the grouping useful even if the reviewer chooses a different definition of sameness. It also reveals whether a single member or a small number of minutes is doing most of the work behind a convincing aggregate chart.
Choose the next comparison for what it can reveal
The first grouping leaves five interesting ways to express a morning dollar short and one candidate with a different-looking profile. If there is time to investigate only one new comparison, select F for a test of the difference. Its session and cross currency make it a useful contrast to A, while its reversion logic gives it something in common with B and E. The choice is about where to spend research effort. F’s realised relationship to the group, event behaviour, and capacity to trade at comparable prices are all open questions. Allocation would require separate evidence and decisions.
Set up the test with A and F, and keep B and E as checks on the family-based explanation. Choose a calendar with an identifiable morning window, a later window and comparable coverage. Predefine a currency-sign ledger, co-activity interval rule and a consistently marked five-minute panel. Include an EUR-event study because A and F both buy EUR in the example, and keep the USD-event study to see when timing or indirect exposures matter. If F’s actual orders cluster in the morning as often as those of its comparators, the session hypothesis weakens. If it regularly suffers along with A through a relative euro move when both are active, the absence of a direct dollar leg has missed a shared dependency.
Keep the comparison grounded by recording why F was picked and what evidence would change your mind. Leave the invented 0.80 B–F distance in the worked example. Give the observed distance, coverage and component values their own entry. Store any subsequent change to the feature weights as a new analysis with its own motivation. A research journal for trading experiments gives the comparison a place to live alongside versions, assumptions and data checks. Include a short list of inconclusive cases with the underlying records you would need to settle them, such as missing inventory during the event window.
A successful first pass should leave you able to point to the rows that explain a group, the minutes it existed and the observations that might break the story. The next study can then reuse those questions across additional periods or a new pair of robots without treating a convenient partition as permanent. The Forex demo is available as material for study and testing. One starting exercise is to build a two-leg ledger for one simultaneous position snapshot and compare it with a marked PnL panel before attempting to group a larger set.



