From 1c2560a1fa2ee5a755d4fef820383f3eafca1564 Mon Sep 17 00:00:00 2001 From: fawce Date: Mon, 9 Feb 2015 12:23:46 -0500 Subject: [PATCH 1/4] added cutpoint for overriding SecurityList implementation. --- zipline/utils/security_list.py | 45 ++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/zipline/utils/security_list.py b/zipline/utils/security_list.py index 4de9dbaf..417cef43 100644 --- a/zipline/utils/security_list.py +++ b/zipline/utils/security_list.py @@ -14,27 +14,6 @@ def loopback(symbol, *args, **kwargs): return symbol -class SecurityListSet(object): - - def __init__(self, current_date_func, lookup_func=None): - if lookup_func is None: - self.lookup_func = loopback - else: - self.lookup_func = lookup_func - self.current_date_func = current_date_func - self._leveraged_etf = None - - @property - def leveraged_etf_list(self): - if self._leveraged_etf is None: - self._leveraged_etf = SecurityList( - self.lookup_func, - load_from_directory('leveraged_etf_list'), - self.current_date_func - ) - return self._leveraged_etf - - class SecurityList(object): def __init__(self, lookup_func, data, current_date_func): @@ -102,6 +81,30 @@ class SecurityList(object): change_func(sid) +class SecurityListSet(object): + + def __init__(self, current_date_func, lookup_func=None): + # provide a cut point to substitute other security + # list implementations. + self.sl_constructor = SecurityList + if lookup_func is None: + self.lookup_func = loopback + else: + self.lookup_func = lookup_func + self.current_date_func = current_date_func + self._leveraged_etf = None + + @property + def leveraged_etf_list(self): + if self._leveraged_etf is None: + self._leveraged_etf = self.sl_constructor( + self.lookup_func, + load_from_directory('leveraged_etf_list'), + self.current_date_func + ) + return self._leveraged_etf + + def load_from_directory(list_name): """ To resolve the symbol in the LEVERAGED_ETF list, From e3b21835f350c546948ed3205fc767e997e1f970 Mon Sep 17 00:00:00 2001 From: fawce Date: Mon, 9 Feb 2015 12:27:30 -0500 Subject: [PATCH 2/4] name changed to protect the innocent --- zipline/utils/security_list.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zipline/utils/security_list.py b/zipline/utils/security_list.py index 417cef43..716f648f 100644 --- a/zipline/utils/security_list.py +++ b/zipline/utils/security_list.py @@ -86,7 +86,7 @@ class SecurityListSet(object): def __init__(self, current_date_func, lookup_func=None): # provide a cut point to substitute other security # list implementations. - self.sl_constructor = SecurityList + self.security_list_type = SecurityList if lookup_func is None: self.lookup_func = loopback else: @@ -97,7 +97,7 @@ class SecurityListSet(object): @property def leveraged_etf_list(self): if self._leveraged_etf is None: - self._leveraged_etf = self.sl_constructor( + self._leveraged_etf = self.security_list_type( self.lookup_func, load_from_directory('leveraged_etf_list'), self.current_date_func From 67da7ca7a313e83a857679d3d74eb0d19819cb36 Mon Sep 17 00:00:00 2001 From: fawce Date: Mon, 9 Feb 2015 12:54:50 -0500 Subject: [PATCH 3/4] import statement cleanup --- zipline/utils/security_list.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/zipline/utils/security_list.py b/zipline/utils/security_list.py index 716f648f..8ad98585 100644 --- a/zipline/utils/security_list.py +++ b/zipline/utils/security_list.py @@ -1,11 +1,13 @@ -import os.path -import pytz -import pandas as pd from datetime import datetime from os import listdir +import os.path + +import pandas as pd +import pytz +import zipline + DATE_FORMAT = "%Y%m%d" -import zipline zipline_dir = os.path.join(*zipline.__path__) SECURITY_LISTS_DIR = os.path.join(zipline_dir, 'resources', 'security_lists') From 233bf3080d974f8af8a9edaf0d48e4f2b5cc0740 Mon Sep 17 00:00:00 2001 From: fawce Date: Mon, 9 Feb 2015 13:32:01 -0500 Subject: [PATCH 4/4] security list type is a class level property now --- zipline/utils/security_list.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zipline/utils/security_list.py b/zipline/utils/security_list.py index 8ad98585..0cb24a4b 100644 --- a/zipline/utils/security_list.py +++ b/zipline/utils/security_list.py @@ -84,11 +84,11 @@ class SecurityList(object): class SecurityListSet(object): + # provide a cut point to substitute other security + # list implementations. + security_list_type = SecurityList def __init__(self, current_date_func, lookup_func=None): - # provide a cut point to substitute other security - # list implementations. - self.security_list_type = SecurityList if lookup_func is None: self.lookup_func = loopback else: