Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
short selling and cash management

Hi folks,

I'm not much of a trader and would like to know how short selling works.

for example let's say i short sell 100 shares of ibm at $100ea for a total of $10k. What happens to that money in a live trading account? Does it appear in my account as available cash or is the money held as collateral?

second question, in a backtest environment, I have the following code:

    cash = context.portfolio.cash  
    while cash > 10000:  
        if cash > 40000:  
            order_target_value(downlist[idx], -20000)  
            order_target_value(uplist[idx], 20000)  
            cash = cash - 40000  
            idx += 1  
        else:  
            order_target_value(downlist[idx], -cash/2)  
            order_target_value(uplist[idx], cash/2)  
            cash = 0  

to me, it feels as though this piece of code will take on more and more leverage since cash is added to "context.portfolio.cash" on the short sells. is there a better way to manage cash to keep the leverage ratio close to 1?

thanks!