Quantopian's community platform is shutting down. Please read this post for more information and download your code.
Back to Community
github repository

I created a github repository, for the purpose of managing and sharing code to be run on Quantopian (and learning github):

https://github.com/gkiehne/quantopian

As a test case, I posted a function:

def rebalance_portfolio(context, data, desired_port):  
    #rebalance portfolio  
    current_amount = np.zeros_like(desired_port)  
    desired_amount = np.zeros_like(desired_port)  
    if not context.init:  
        positions_value = context.portfolio.starting_cash  
    else:  
        positions_value = context.portfolio.positions_value + context.portfolio.cash  
    for i, stock in enumerate(context.stocks):  
        current_amount[i] = context.portfolio.positions[stock].amount  
        desired_amount[i] = desired_port[i]*positions_value/data[stock].price

    diff_amount = desired_amount - current_amount

    for i, stock in enumerate(context.stocks):  
        order(stock, diff_amount[i]) #order_stock

If you have suggested improvements to the rebalance function, please comment on github (not sure...perhaps I'll need to grant access on an individual basis...if so, just post a request here...or via github, if you can).

Grant

3 responses

Hello Ad,

Yes, it's the same idea. The repository, https://github.com/quantopian/quantopian-algos, was set up by Quantopian. I'd like to have my own, for organization, version control, and collaboration. We'll see how it works out.

Grant

Oh, okay! Versioning this kind of stuff is always a nice idea. Github can be used for waaay more than just source code. Good luck with it.

Ad