{"action":"created","comment":{"url":"https://api.github.com/repos/quantopian/zipline/pulls/comments/30078401","id":30078401,"diff_hunk":"@@ -104,33 +152,71 @@ def position_values(self):\n         self._position_last_sale_prices is changed.\n         \"\"\"\n         if self._position_values is None:\n-            vals = list(map(mul, self._position_amounts.values(),\n-                        self._position_last_sale_prices.values()))\n+            # Apply value multipliers to quantities\n+            vals = map(mul, self._position_amounts.values(),\n+                       self._position_value_multiplier.values())\n+            # Apply last sale prices to quantities\n+            vals = list(map(mul, vals,\n+                            self._position_last_sale_prices.values()))\n             self._position_values = vals\n         return self._position_values\n \n+    @property\n+    def position_exposures(self):\n+        \"\"\"\n+        Invalidate any time self._position_amounts or\n+        self._position_last_sale_prices is changed.\n+        \"\"\"\n+        if self._position_exposures is None:\n+            # Apply exposure multipliers to quantities\n+            vals = map(mul, self._position_amounts.values(),\n+                       self._position_exposure_multiplier.values())\n+            # Apply last sale prices to quantities\n+            vals = list(map(mul, vals,\n+                            self._position_last_sale_prices.values()))\n+            self._position_exposures = vals\n+        return self._position_exposures\n+\n     def calculate_positions_value(self):\n         if len(self.position_values) == 0:\n             return np.float64(0)\n \n         return sum(self.position_values)\n \n+    def calculate_positions_exposure(self):\n+        if len(self.position_exposures) == 0:\n+            return np.float64(0)\n+\n+        return sum(self.position_exposures)\n+\n     def _longs_count(self):\n-        return sum(map(lambda x: x > 0, self.position_values))\n+        return sum(map(lambda x: x > 0, self.position_exposures))","path":"zipline/finance/performance/position_tracker.py","position":188,"original_position":188,"commit_id":"4c1e652c7ad6111aa6d194f20ac55733f645efc6","original_commit_id":"3d950ae87cc6727d9404228f60e598c49e9dfe0a","user":{"login":"ssanderson","id":1588357,"avatar_url":"https://avatars.githubusercontent.com/u/1588357?v=3","gravatar_id":"","url":"https://api.github.com/users/ssanderson","html_url":"https://github.com/ssanderson","followers_url":"https://api.github.com/users/ssanderson/followers","following_url":"https://api.github.com/users/ssanderson/following{/other_user}","gists_url":"https://api.github.com/users/ssanderson/gists{/gist_id}","starred_url":"https://api.github.com/users/ssanderson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ssanderson/subscriptions","organizations_url":"https://api.github.com/users/ssanderson/orgs","repos_url":"https://api.github.com/users/ssanderson/repos","events_url":"https://api.github.com/users/ssanderson/events{/privacy}","received_events_url":"https://api.github.com/users/ssanderson/received_events","type":"User","site_admin":false},"body":"@jfkirk ping on these comments because we talked about them today.  This is a one line change that will yield a substantial perf improvement on these calculations.","created_at":"2015-05-11T20:30:55Z","updated_at":"2015-05-11T20:30:55Z","html_url":"https://github.com/quantopian/zipline/pull/571#discussion_r30078401","pull_request_url":"https://api.github.com/repos/quantopian/zipline/pulls/571","_links":{"self":{"href":"https://api.github.com/repos/quantopian/zipline/pulls/comments/30078401"},"html":{"href":"https://github.com/quantopian/zipline/pull/571#discussion_r30078401"},"pull_request":{"href":"https://api.github.com/repos/quantopian/zipline/pulls/571"}}},"pull_request":{"url":"https://api.github.com/repos/quantopian/zipline/pulls/571","id":34015922,"html_url":"https://github.com/quantopian/zipline/pull/571","diff_url":"https://github.com/quantopian/zipline/pull/571.diff","patch_url":"https://github.com/quantopian/zipline/pull/571.patch","issue_url":"https://api.github.com/repos/quantopian/zipline/issues/571","number":571,"state":"open","locked":false,"title":"DO NOT MERGE: Futures trading","user":{"login":"jfkirk","id":10326791,"avatar_url":"https://avatars.githubusercontent.com/u/10326791?v=3","gravatar_id":"","url":"https://api.github.com/users/jfkirk","html_url":"https://github.com/jfkirk","followers_url":"https://api.github.com/users/jfkirk/followers","following_url":"https://api.github.com/users/jfkirk/following{/other_user}","gists_url":"https://api.github.com/users/jfkirk/gists{/gist_id}","starred_url":"https://api.github.com/users/jfkirk/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jfkirk/subscriptions","organizations_url":"https://api.github.com/users/jfkirk/orgs","repos_url":"https://api.github.com/users/jfkirk/repos","events_url":"https://api.github.com/users/jfkirk/events{/privacy}","received_events_url":"https://api.github.com/users/jfkirk/received_events","type":"User","site_admin":false},"body":"** Work in progress **\r\n\r\nPR for review and comparison. Please tear it apart.\r\n\r\nThis branch adds Asset management to Zipline and adds the necessary accounting to allow for trading of Futures.\r\n\r\n**Primary impacts:**\r\n**1. There is now a distinction between an Asset's 'identifier', 'sid', and 'symbol'.**\r\n    * 'identifier': the user-provided unique int or str that allows us to marry-up AssetMetaData and DataSource data\r\n    * 'sid': a unique integer that can be used to identify a specific Asset within a given TradingEnvironment\r\n    * 'symbol': non-unique string name for user look-up and ease-of-use, but is not used internally\r\n    * This distinction has not been completely refactored in to the API – many methods still call for an argument 'sid' where they would actually want an Asset object\r\n**2. Zipline user must provide 'identifiers' or 'asset_metadata' arguments to TradingAlgorithm.__init__ so the asset_finder can be built.**\r\n**3. Zipline algorithms must use Asset objects as arguments to all order*() methods.**\r\n    * The sid(int) and symbol(str) methods can be used to look up an Asset\r\n**4. Zipline algorithms now handle Asset end_dates: on an Asset's end_date, the Asset is liquidated at its last-traded price.**\r\n**5. There is now a distinction between 'value' and 'exposure' in the perf tracker and positions tracker.**\r\n\r\n** In Progress **\r\n1. Documentation (waiting until impacts are finalized)\r\n2. API method argument classes/naming (SID v Asset)","created_at":"2015-04-24T03:20:22Z","updated_at":"2015-05-11T20:30:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"25d06260bf7973f694b4c1247e7dcd649bc26374","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/quantopian/zipline/pulls/571/commits","review_comments_url":"https://api.github.com/repos/quantopian/zipline/pulls/571/comments","review_comment_url":"https://api.github.com/repos/quantopian/zipline/pulls/comments{/number}","comments_url":"https://api.github.com/repos/quantopian/zipline/issues/571/comments","statuses_url":"https://api.github.com/repos/quantopian/zipline/statuses/4c1e652c7ad6111aa6d194f20ac55733f645efc6","head":{"label":"quantopian:futures-trading","ref":"futures-trading","sha":"4c1e652c7ad6111aa6d194f20ac55733f645efc6","user":{"login":"quantopian","id":1393215,"avatar_url":"https://avatars.githubusercontent.com/u/1393215?v=3","gravatar_id":"","url":"https://api.github.com/users/quantopian","html_url":"https://github.com/quantopian","followers_url":"https://api.github.com/users/quantopian/followers","following_url":"https://api.github.com/users/quantopian/following{/other_user}","gists_url":"https://api.github.com/users/quantopian/gists{/gist_id}","starred_url":"https://api.github.com/users/quantopian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quantopian/subscriptions","organizations_url":"https://api.github.com/users/quantopian/orgs","repos_url":"https://api.github.com/users/quantopian/repos","events_url":"https://api.github.com/users/quantopian/events{/privacy}","received_events_url":"https://api.github.com/users/quantopian/received_events","type":"Organization","site_admin":false},"repo":{"id":6297520,"name":"zipline","full_name":"quantopian/zipline","owner":{"login":"quantopian","id":1393215,"avatar_url":"https://avatars.githubusercontent.com/u/1393215?v=3","gravatar_id":"","url":"https://api.github.com/users/quantopian","html_url":"https://github.com/quantopian","followers_url":"https://api.github.com/users/quantopian/followers","following_url":"https://api.github.com/users/quantopian/following{/other_user}","gists_url":"https://api.github.com/users/quantopian/gists{/gist_id}","starred_url":"https://api.github.com/users/quantopian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quantopian/subscriptions","organizations_url":"https://api.github.com/users/quantopian/orgs","repos_url":"https://api.github.com/users/quantopian/repos","events_url":"https://api.github.com/users/quantopian/events{/privacy}","received_events_url":"https://api.github.com/users/quantopian/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/quantopian/zipline","description":"Zipline, a Pythonic Algorithmic Trading Library","fork":false,"url":"https://api.github.com/repos/quantopian/zipline","forks_url":"https://api.github.com/repos/quantopian/zipline/forks","keys_url":"https://api.github.com/repos/quantopian/zipline/keys{/key_id}","collaborators_url":"https://api.github.com/repos/quantopian/zipline/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/quantopian/zipline/teams","hooks_url":"https://api.github.com/repos/quantopian/zipline/hooks","issue_events_url":"https://api.github.com/repos/quantopian/zipline/issues/events{/number}","events_url":"https://api.github.com/repos/quantopian/zipline/events","assignees_url":"https://api.github.com/repos/quantopian/zipline/assignees{/user}","branches_url":"https://api.github.com/repos/quantopian/zipline/branches{/branch}","tags_url":"https://api.github.com/repos/quantopian/zipline/tags","blobs_url":"https://api.github.com/repos/quantopian/zipline/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/quantopian/zipline/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/quantopian/zipline/git/refs{/sha}","trees_url":"https://api.github.com/repos/quantopian/zipline/git/trees{/sha}","statuses_url":"https://api.github.com/repos/quantopian/zipline/statuses/{sha}","languages_url":"https://api.github.com/repos/quantopian/zipline/languages","stargazers_url":"https://api.github.com/repos/quantopian/zipline/stargazers","contributors_url":"https://api.github.com/repos/quantopian/zipline/contributors","subscribers_url":"https://api.github.com/repos/quantopian/zipline/subscribers","subscription_url":"https://api.github.com/repos/quantopian/zipline/subscription","commits_url":"https://api.github.com/repos/quantopian/zipline/commits{/sha}","git_commits_url":"https://api.github.com/repos/quantopian/zipline/git/commits{/sha}","comments_url":"https://api.github.com/repos/quantopian/zipline/comments{/number}","issue_comment_url":"https://api.github.com/repos/quantopian/zipline/issues/comments{/number}","contents_url":"https://api.github.com/repos/quantopian/zipline/contents/{+path}","compare_url":"https://api.github.com/repos/quantopian/zipline/compare/{base}...{head}","merges_url":"https://api.github.com/repos/quantopian/zipline/merges","archive_url":"https://api.github.com/repos/quantopian/zipline/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/quantopian/zipline/downloads","issues_url":"https://api.github.com/repos/quantopian/zipline/issues{/number}","pulls_url":"https://api.github.com/repos/quantopian/zipline/pulls{/number}","milestones_url":"https://api.github.com/repos/quantopian/zipline/milestones{/number}","notifications_url":"https://api.github.com/repos/quantopian/zipline/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/quantopian/zipline/labels{/name}","releases_url":"https://api.github.com/repos/quantopian/zipline/releases{/id}","created_at":"2012-10-19T15:50:29Z","updated_at":"2015-05-11T14:16:38Z","pushed_at":"2015-05-11T20:23:48Z","git_url":"git://github.com/quantopian/zipline.git","ssh_url":"git@github.com:quantopian/zipline.git","clone_url":"https://github.com/quantopian/zipline.git","svn_url":"https://github.com/quantopian/zipline","homepage":"","size":20521,"stargazers_count":2178,"watchers_count":2178,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":558,"mirror_url":null,"open_issues_count":118,"forks":558,"open_issues":118,"watchers":2178,"default_branch":"master"}},"base":{"label":"quantopian:master","ref":"master","sha":"e5a93b6f7e2ffea731595942b81044af2e5415b0","user":{"login":"quantopian","id":1393215,"avatar_url":"https://avatars.githubusercontent.com/u/1393215?v=3","gravatar_id":"","url":"https://api.github.com/users/quantopian","html_url":"https://github.com/quantopian","followers_url":"https://api.github.com/users/quantopian/followers","following_url":"https://api.github.com/users/quantopian/following{/other_user}","gists_url":"https://api.github.com/users/quantopian/gists{/gist_id}","starred_url":"https://api.github.com/users/quantopian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quantopian/subscriptions","organizations_url":"https://api.github.com/users/quantopian/orgs","repos_url":"https://api.github.com/users/quantopian/repos","events_url":"https://api.github.com/users/quantopian/events{/privacy}","received_events_url":"https://api.github.com/users/quantopian/received_events","type":"Organization","site_admin":false},"repo":{"id":6297520,"name":"zipline","full_name":"quantopian/zipline","owner":{"login":"quantopian","id":1393215,"avatar_url":"https://avatars.githubusercontent.com/u/1393215?v=3","gravatar_id":"","url":"https://api.github.com/users/quantopian","html_url":"https://github.com/quantopian","followers_url":"https://api.github.com/users/quantopian/followers","following_url":"https://api.github.com/users/quantopian/following{/other_user}","gists_url":"https://api.github.com/users/quantopian/gists{/gist_id}","starred_url":"https://api.github.com/users/quantopian/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/quantopian/subscriptions","organizations_url":"https://api.github.com/users/quantopian/orgs","repos_url":"https://api.github.com/users/quantopian/repos","events_url":"https://api.github.com/users/quantopian/events{/privacy}","received_events_url":"https://api.github.com/users/quantopian/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/quantopian/zipline","description":"Zipline, a Pythonic Algorithmic Trading Library","fork":false,"url":"https://api.github.com/repos/quantopian/zipline","forks_url":"https://api.github.com/repos/quantopian/zipline/forks","keys_url":"https://api.github.com/repos/quantopian/zipline/keys{/key_id}","collaborators_url":"https://api.github.com/repos/quantopian/zipline/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/quantopian/zipline/teams","hooks_url":"https://api.github.com/repos/quantopian/zipline/hooks","issue_events_url":"https://api.github.com/repos/quantopian/zipline/issues/events{/number}","events_url":"https://api.github.com/repos/quantopian/zipline/events","assignees_url":"https://api.github.com/repos/quantopian/zipline/assignees{/user}","branches_url":"https://api.github.com/repos/quantopian/zipline/branches{/branch}","tags_url":"https://api.github.com/repos/quantopian/zipline/tags","blobs_url":"https://api.github.com/repos/quantopian/zipline/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/quantopian/zipline/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/quantopian/zipline/git/refs{/sha}","trees_url":"https://api.github.com/repos/quantopian/zipline/git/trees{/sha}","statuses_url":"https://api.github.com/repos/quantopian/zipline/statuses/{sha}","languages_url":"https://api.github.com/repos/quantopian/zipline/languages","stargazers_url":"https://api.github.com/repos/quantopian/zipline/stargazers","contributors_url":"https://api.github.com/repos/quantopian/zipline/contributors","subscribers_url":"https://api.github.com/repos/quantopian/zipline/subscribers","subscription_url":"https://api.github.com/repos/quantopian/zipline/subscription","commits_url":"https://api.github.com/repos/quantopian/zipline/commits{/sha}","git_commits_url":"https://api.github.com/repos/quantopian/zipline/git/commits{/sha}","comments_url":"https://api.github.com/repos/quantopian/zipline/comments{/number}","issue_comment_url":"https://api.github.com/repos/quantopian/zipline/issues/comments{/number}","contents_url":"https://api.github.com/repos/quantopian/zipline/contents/{+path}","compare_url":"https://api.github.com/repos/quantopian/zipline/compare/{base}...{head}","merges_url":"https://api.github.com/repos/quantopian/zipline/merges","archive_url":"https://api.github.com/repos/quantopian/zipline/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/quantopian/zipline/downloads","issues_url":"https://api.github.com/repos/quantopian/zipline/issues{/number}","pulls_url":"https://api.github.com/repos/quantopian/zipline/pulls{/number}","milestones_url":"https://api.github.com/repos/quantopian/zipline/milestones{/number}","notifications_url":"https://api.github.com/repos/quantopian/zipline/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/quantopian/zipline/labels{/name}","releases_url":"https://api.github.com/repos/quantopian/zipline/releases{/id}","created_at":"2012-10-19T15:50:29Z","updated_at":"2015-05-11T14:16:38Z","pushed_at":"2015-05-11T20:23:48Z","git_url":"git://github.com/quantopian/zipline.git","ssh_url":"git@github.com:quantopian/zipline.git","clone_url":"https://github.com/quantopian/zipline.git","svn_url":"https://github.com/quantopian/zipline","homepage":"","size":20521,"stargazers_count":2178,"watchers_count":2178,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":558,"mirror_url":null,"open_issues_count":118,"forks":558,"open_issues":118,"watchers":2178,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/quantopian/zipline/pulls/571"},"html":{"href":"https://github.com/quantopian/zipline/pull/571"},"issue":{"href":"https://api.github.com/repos/quantopian/zipline/issues/571"},"comments":{"href":"https://api.github.com/repos/quantopian/zipline/issues/571/comments"},"review_comments":{"href":"https://api.github.com/repos/quantopian/zipline/pulls/571/comments"},"review_comment":{"href":"https://api.github.com/repos/quantopian/zipline/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/quantopian/zipline/pulls/571/commits"},"statuses":{"href":"https://api.github.com/repos/quantopian/zipline/statuses/4c1e652c7ad6111aa6d194f20ac55733f645efc6"}}}}