Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
general questions about initializing cash and margins

In the quantopian, there's a small window to enter the initial cash.

I always feel this is annoying. Every time I need to set the initial cash = the notional amount in my algorithm.
Otherwise the whole backtest give me small return as a lot cash is not being used. why can't just discard the initial cash window?

And another problem is the margin problem. is there any margin check process before u go short or go long?
I don't see anything like that. It seems I can short as many as i want.?

1 response

I think the answer to your first question is no but I am not entirely confident in that answer. I can provide an answer to your second question. There is no margin check built-in. Add this function to your code and perform the check.

def marginRequirements(portfolio):  
    req = 0  
    for stock in portfolio.positions:  
        amount = portfolio.positions[stock].amount  
        last_price = portfolio.positions[stock].last_sale_price  
        if amount > 0:  
            req += .25 * amount * last_price  
        elif amount < 0:  
            if last_price < 5:  
                req += max(2.5 * amount, abs(amount * last_price))  
            else:  
                req += max(5 * amount, abs(0.3 * amount * last_price))  
    return req