What potentials race conditions can there be in the following?

  • SecurityPortfolioManager.TotalPortfolioValue
  • QCAlgorithm.Liquidate

The reason I'm asking is that I observed weird behavior when testing logic that's supposed to liquidate the algorithm if the effective draw down reaches a certain level. 1) It triggered when not expected, speculatively because there being some "gap" of cashbook + security value when issuing orders. 2) Liquidate did in fact not manage to fully liquidate the portfolio, but ended up with a small inverse position. I'm guessing this might be some race against order that were open at time of Liquidate call?

Author