In some backtests I'm noticing a significant decrease in remaining margin, which I can't explain. For example, the attached backtest sells 2 bear credit spreads:

1. Sell SPXW 220105C04730000, Buy SPXW 220105C04780000 on 2022-01-032. Sell SPXW 220105C04760000, Buy SPXW 220105C04810000 on 2022-01-04

Both spreads are $50 wide, so, assuming a $100k account, I don't expect used margin to ever go below $90k ($100k - $50*100*2).

However, after trading both spreads, the final remaining margin is as low as $37k. But if trading only one of the spreads, they only take about $2k of margin:

_doSpread1 _doSpread2 Final remaining margin True False 98,690 False True 98,710 True True 37,828.30

How can total margin required for both spreads be more than the sum of margin required for each of them?

From the logs it looks like remaining margin takes a huge hit when selling the second spread (goes down to $16k) and eventually restores to $37k:

1/3/2022 9:31:00 AM: remaining margin before spread 1: 100000.0
1/3/2022 9:31:00 AM: remaining margin after spread 1: 94950.0000
1/4/2022 9:31:00 AM: remaining margin before spread 2: 94245.0000
1/4/2022 9:31:00 AM: remaining margin after spread 2: 16649.25000000000000000000000
1/5/2022 4:15:00 PM: remaining margin final: 37828.300000000

How exactly do we arrive at such numbers, like dropping from $94k to $16k when trading a $50 spread? Am I missing something obvious in how required margin is calculated?