{"action":"created","issue":{"url":"https://api.github.com/repos/quantopian/zipline/issues/477","labels_url":"https://api.github.com/repos/quantopian/zipline/issues/477/labels{/name}","comments_url":"https://api.github.com/repos/quantopian/zipline/issues/477/comments","events_url":"https://api.github.com/repos/quantopian/zipline/issues/477/events","html_url":"https://github.com/quantopian/zipline/pull/477","id":55834624,"number":477,"title":"allow order_percent to work with various market values","user":{"login":"jlowin","id":153965,"avatar_url":"https://avatars.githubusercontent.com/u/153965?v=3","gravatar_id":"","url":"https://api.github.com/users/jlowin","html_url":"https://github.com/jlowin","followers_url":"https://api.github.com/users/jlowin/followers","following_url":"https://api.github.com/users/jlowin/following{/other_user}","gists_url":"https://api.github.com/users/jlowin/gists{/gist_id}","starred_url":"https://api.github.com/users/jlowin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jlowin/subscriptions","organizations_url":"https://api.github.com/users/jlowin/orgs","repos_url":"https://api.github.com/users/jlowin/repos","events_url":"https://api.github.com/users/jlowin/events{/privacy}","received_events_url":"https://api.github.com/users/jlowin/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/quantopian/zipline/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/quantopian/zipline/labels/Needs%20Review","name":"Needs Review","color":"eb6420"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":10,"created_at":"2015-01-28T23:48:53Z","updated_at":"2015-02-09T23:49:55Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/quantopian/zipline/pulls/477","html_url":"https://github.com/quantopian/zipline/pull/477","diff_url":"https://github.com/quantopian/zipline/pull/477.diff","patch_url":"https://github.com/quantopian/zipline/pull/477.patch"},"body":"Currently, `order_percent()` and `order_target_percent()` both operate as a percentage of `self.portfolio.portfolio_value`. This PR lets them operate as percentages of other important MVs.\r\n\r\n(also adds `context.get_market_value()`, which enables this functionality)\r\n\r\nFor example:\r\n```python\r\n# this is how it works today (and this still works)\r\n# put 50% of my portfolio in AAPL\r\norder_percent('AAPL', 0.5)\r\n# note that if this were a fully invested portfolio, it would become 150% levered.\r\n\r\n# take half of my available cash and buy AAPL\r\norder_percent('AAPL', 0.5, percent_of='cash')\r\n\r\n# rebalance my short position, as a percentage of my current short book\r\norder_target_percent('MSFT', 0.1, percent_of='shorts')\r\n\r\n# rebalance within a custom group of stocks\r\ntech_stocks = ('AAPL', 'MSFT', 'GOOGL')\r\ntech_filter = lambda p: p.sid in tech_stocks\r\nfor stock in tech_stocks:\r\n    order_target_percent(stock, 1/3, percent_of_fn=tech_filter)\r\n```"},"comment":{"url":"https://api.github.com/repos/quantopian/zipline/issues/comments/73616559","html_url":"https://github.com/quantopian/zipline/pull/477#issuecomment-73616559","issue_url":"https://api.github.com/repos/quantopian/zipline/issues/477","id":73616559,"user":{"login":"coveralls","id":2354108,"avatar_url":"https://avatars.githubusercontent.com/u/2354108?v=3","gravatar_id":"","url":"https://api.github.com/users/coveralls","html_url":"https://github.com/coveralls","followers_url":"https://api.github.com/users/coveralls/followers","following_url":"https://api.github.com/users/coveralls/following{/other_user}","gists_url":"https://api.github.com/users/coveralls/gists{/gist_id}","starred_url":"https://api.github.com/users/coveralls/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coveralls/subscriptions","organizations_url":"https://api.github.com/users/coveralls/orgs","repos_url":"https://api.github.com/users/coveralls/repos","events_url":"https://api.github.com/users/coveralls/events{/privacy}","received_events_url":"https://api.github.com/users/coveralls/received_events","type":"User","site_admin":false},"created_at":"2015-02-09T23:49:55Z","updated_at":"2015-02-09T23:49:55Z","body":"\n[![Coverage Status](https://coveralls.io/builds/1896109/badge)](https://coveralls.io/builds/1896109)\n\nCoverage increased (+0.38%) to 87.3% when pulling **ad1d9f8860e8c49de4ef98da935046b9c1af4040 on jlowin:mod-order_percent** into **65c038d0dae0bd66807aeb4ab1611a0233dbb580 on quantopian:master**.\n"}}