Modeling short-selling accounts

Discussion in 'Strategy Building' started by nijshar28, May 8, 2020.

  1. I am having trouble modeling short-selling mechanics in my backtesting system.

    When I sell stock short, I make the following changed to account variables in my backtesting program:
    1. Credit Balance += 200% of the stock value sold short (assuming a 100% initial margin requirement)
    2. Cash -= 100% of the stock value (the cash is transferred to the Credit Balance account to collaterize the short sale)
    3. Short Market Value (SMV) -= 100% of stock value (this is the market value of the shorted stock)
    4. Net Account Value += Credit Balance + Short Market Value + Cash
    When I close out the short position later, I change my accounts as follows:
    1. Credit Balance -= 100% of the stock value bought back
    2. Short Market Value (SMV) += 100% of stock value bought back
    3. Net Account Value += Credit Balance + Short Market Value + Cash
    I am pretty sure this second part (closing out the short position) is wrong. At the very least, my cash position should also be affected. Any suggestions on how to fix it? Thank you.