{"action":"created","comment":{"url":"https://api.github.com/repos/quantopian/zipline/pulls/comments/34051015","id":34051015,"diff_hunk":"@@ -0,0 +1,128 @@\n+from pandas import Timedelta\n+\n+from zipline.finance.trading import TradingEnvironment\n+\n+\n+class FutureChain(object):\n+    \"\"\" Allows users to look up future contracts.\n+\n+    Parameters\n+    ----------\n+    trading_algorithm : TradingAlgorithm\n+    root_symbol : str, optional\n+    as_of_date : pandas.Timestamp\n+    \"\"\"\n+\n+    def __init__(self, trading_algorithm, root_symbol='', as_of_date=None):\n+        self.root_symbol = root_symbol.upper()\n+\n+        # If an as_of_date is provided, self._as_of_date uses that\n+        # value, otherwise None. This attribute backs the as_of_date property.\n+        if as_of_date:\n+            self._as_of_date = (TradingEnvironment.instance().normalize_date(\n+                                as_of_date))\n+        else:\n+            self._as_of_date = None\n+\n+        # Maintain a reference to the TradingAlgorithm which holds this\n+        # FutureChain instance, so we can get its datetime.\n+        self._trading_algorithm = trading_algorithm\n+\n+        # Attribute to cache the most up-to-date chain, and the dt when it was\n+        # last updated.\n+        self._current_chain = []\n+        self._last_updated = None\n+\n+        # Get the initial chain, since self._last_updated is None.\n+        self._maybe_update_current_chain()\n+\n+    def __repr__(self):\n+        if self._as_of_date:\n+            return 'FutureChain(root_symbol=\\'%s\\', as_of_date=\\'%s\\')' % (","path":"zipline/assets/futures.py","position":41,"original_position":41,"commit_id":"730d704ae976c5682f6affbca04c5468cdb6138c","original_commit_id":"730d704ae976c5682f6affbca04c5468cdb6138c","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":"Rather than escape the single quotes here, you should just use double quotes around the outer string.\r\n\r\n```\r\nIn [6]: \"This is a string with 'quotes'\"\r\nOut[6]: \"This is a string with 'quotes'\"\r\n```","created_at":"2015-07-07T15:13:10Z","updated_at":"2015-07-07T15:13:10Z","html_url":"https://github.com/quantopian/zipline/pull/637#discussion_r34051015","pull_request_url":"https://api.github.com/repos/quantopian/zipline/pulls/637","_links":{"self":{"href":"https://api.github.com/repos/quantopian/zipline/pulls/comments/34051015"},"html":{"href":"https://github.com/quantopian/zipline/pull/637#discussion_r34051015"},"pull_request":{"href":"https://api.github.com/repos/quantopian/zipline/pulls/637"}}},"pull_request":{"url":"https://api.github.com/repos/quantopian/zipline/pulls/637","id":39378787,"html_url":"https://github.com/quantopian/zipline/pull/637","diff_url":"https://github.com/quantopian/zipline/pull/637.diff","patch_url":"https://github.com/quantopian/zipline/pull/637.patch","issue_url":"https://api.github.com/repos/quantopian/zipline/issues/637","number":637,"state":"open","locked":false,"title":"ENH: Futures API","user":{"login":"yankees714","id":790109,"avatar_url":"https://avatars.githubusercontent.com/u/790109?v=3","gravatar_id":"","url":"https://api.github.com/users/yankees714","html_url":"https://github.com/yankees714","followers_url":"https://api.github.com/users/yankees714/followers","following_url":"https://api.github.com/users/yankees714/following{/other_user}","gists_url":"https://api.github.com/users/yankees714/gists{/gist_id}","starred_url":"https://api.github.com/users/yankees714/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yankees714/subscriptions","organizations_url":"https://api.github.com/users/yankees714/orgs","repos_url":"https://api.github.com/users/yankees714/repos","events_url":"https://api.github.com/users/yankees714/events{/privacy}","received_events_url":"https://api.github.com/users/yankees714/received_events","type":"User","site_admin":false},"body":"Implements a user facing futures API for zipline.\r\n\r\nAdds the `FutureChain` object, which allows users to access future contracts though underlying queries to the AssetFinder. Adds the API function `future_chain`, which returns `FutureChain` objects.","created_at":"2015-07-07T14:52:41Z","updated_at":"2015-07-07T15:13:10Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3106093a77cca063aa3fc98e09dac7075dd27d8d","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/quantopian/zipline/pulls/637/commits","review_comments_url":"https://api.github.com/repos/quantopian/zipline/pulls/637/comments","review_comment_url":"https://api.github.com/repos/quantopian/zipline/pulls/comments{/number}","comments_url":"https://api.github.com/repos/quantopian/zipline/issues/637/comments","statuses_url":"https://api.github.com/repos/quantopian/zipline/statuses/730d704ae976c5682f6affbca04c5468cdb6138c","head":{"label":"quantopian:futures-api","ref":"futures-api","sha":"730d704ae976c5682f6affbca04c5468cdb6138c","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-07-07T14:18:43Z","pushed_at":"2015-07-07T14:52:41Z","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":20701,"stargazers_count":2353,"watchers_count":2353,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":614,"mirror_url":null,"open_issues_count":133,"forks":614,"open_issues":133,"watchers":2353,"default_branch":"master"}},"base":{"label":"quantopian:master","ref":"master","sha":"f46fef1755cfdba452086f1c177d397f371688fb","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-07-07T14:18:43Z","pushed_at":"2015-07-07T14:52:41Z","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":20701,"stargazers_count":2353,"watchers_count":2353,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":614,"mirror_url":null,"open_issues_count":133,"forks":614,"open_issues":133,"watchers":2353,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/quantopian/zipline/pulls/637"},"html":{"href":"https://github.com/quantopian/zipline/pull/637"},"issue":{"href":"https://api.github.com/repos/quantopian/zipline/issues/637"},"comments":{"href":"https://api.github.com/repos/quantopian/zipline/issues/637/comments"},"review_comments":{"href":"https://api.github.com/repos/quantopian/zipline/pulls/637/comments"},"review_comment":{"href":"https://api.github.com/repos/quantopian/zipline/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/quantopian/zipline/pulls/637/commits"},"statuses":{"href":"https://api.github.com/repos/quantopian/zipline/statuses/730d704ae976c5682f6affbca04c5468cdb6138c"}}}}