Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
allow order_percent to work with various market values #477
# this is how it works today (and this still works) # put 50% of my portfolio in AAPL order_percent('AAPL', 0.5) # note that if this were a fully invested portfolio, it would become 150% levered. # take half of my available cash and buy AAPL order_percent('AAPL', 0.5, percent_of='cash') # rebalance my short position, as a percentage of my current short book order_target_percent('MSFT', 0.1, percent_of='shorts') # rebalance within a custom group of stocks tech_stocks = ('AAPL', 'MSFT', 'GOOGL') tech_filter = lambda p: p.sid in tech_stocks for stock in tech_stocks: order_target_percent(stock, 1/3, percent_of_fn=tech_filter)
@twiecki added tests.
Along the way, I discovered a problem with
The main problem was that
For example, consider:
This is surprising and undesirable -- you should never end up with more shares than you requested, and to the same
When I looked at the existing
I also added a new unit test to check for
A big part of this was exposing the
I have a question regarding the issue with floats and order_target. Does this come up because order_target_percent and order_target_value can end up passing floats to order_target?
Currently zipline does not support ordering fractional shares, so
@humdings zipline does coerce all shares to be ints, but it does it at the lowest level in the
@jlowin Travis seems to be complaining: