ENH: Added dynamic name functionality to record() API function.

Added the ability to pass *args before the **kwargs so that positional
arguments of the form name, value can be recorded.
This commit is contained in:
Delaney Granizo-Mackenzie
2014-06-30 14:09:09 -04:00
committed by Scott Sanderson
parent 75b415ac48
commit c3169f60cd
3 changed files with 20 additions and 3 deletions
+11 -3
View File
@@ -21,7 +21,7 @@ import numpy as np
from datetime import datetime
from itertools import groupby
from itertools import groupby, chain
from six.moves import filter
from six import iteritems, exec_
from operator import attrgetter
@@ -467,11 +467,19 @@ class TradingAlgorithm(object):
'kwargs': kwargs}
@api_method
def record(self, **kwargs):
def record(self, *args, **kwargs):
"""
Track and record local variable (i.e. attributes) each day.
"""
for name, value in kwargs.items():
# Make 2 objects both referencing the same iterator
args = [iter(args)] * 2
# Zip generates list entries by calling `next` on each iterator it
# receives. In this case the two iterators are the same object, so the
# call to next on args[0] will also advance args[1], resulting in zip
# returning (a,b) (c,d) (e,f) rather than (a,a) (b,b) (c,c) etc.
positionals = zip(*args)
for name, value in chain(positionals, iteritems(kwargs)):
self._recorded_vars[name] = value
@api_method