pmorissette / bt

bt - flexible backtesting for Python
http://pmorissette.github.io/bt
MIT License
2.25k stars 428 forks source link

Fail to pull transactions for bt run #107

Open richardtbenade opened 7 years ago

richardtbenade commented 7 years ago

Hi There

After running a back test which seems to have run successfully based on the output of running: "res.plot_weights('Portfolio')" image

,I fail to pull transactions for the particular run using: "res.get_transactions(strategy_name='Portfolio').to_records()" This worked fine for earlier runs but seems to fail for this run with error as below. Please advise


TypeErrorTraceback (most recent call last)

in () ----> 1 res.get_transactions(strategy_name='Portfolio').to_records() /usr/local/lib/python2.7/dist-packages/bt/backtest.pyc in get_transactions(self, strategy_name) 432 trades = trades[trades != 0].unstack().dropna() 433 --> 434 res = pd.DataFrame({'price': prc, 'quantity': trades}).dropna( 435 subset=['quantity']) 436 /usr/local/lib/python2.7/dist-packages/pandas/core/frame.pyc in __init__(self, data, index, columns, dtype, copy) 264 dtype=dtype, copy=copy) 265 elif isinstance(data, dict): --> 266 mgr = self._init_dict(data, index, columns, dtype=dtype) 267 elif isinstance(data, ma.MaskedArray): 268 import numpy.ma.mrecords as mrecords /usr/local/lib/python2.7/dist-packages/pandas/core/frame.pyc in _init_dict(self, data, index, columns, dtype) 400 arrays = [data[k] for k in keys] 401 --> 402 return _arrays_to_mgr(arrays, data_names, index, columns, dtype=dtype) 403 404 def _init_ndarray(self, values, index, columns, dtype=None, copy=False): /usr/local/lib/python2.7/dist-packages/pandas/core/frame.pyc in _arrays_to_mgr(arrays, arr_names, index, columns, dtype) 5407 # figure out the index, if necessary 5408 if index is None: -> 5409 index = extract_index(arrays) 5410 else: 5411 index = _ensure_index(index) /usr/local/lib/python2.7/dist-packages/pandas/core/frame.pyc in extract_index(data) 5450 5451 if have_series or have_dicts: -> 5452 index = _union_indexes(indexes) 5453 5454 if have_raw_arrays: /usr/local/lib/python2.7/dist-packages/pandas/indexes/api.pyc in _union_indexes(indexes) 69 else: 70 for other in indexes[1:]: ---> 71 result = result.union(other) 72 return result 73 elif kind == 'array': /usr/local/lib/python2.7/dist-packages/pandas/indexes/multi.pyc in union(self, other) 2119 uniq_tuples = lib.fast_unique_multiple([self._values, other._values]) 2120 return MultiIndex.from_arrays(lzip(*uniq_tuples), sortorder=0, -> 2121 names=result_names) 2122 2123 def intersection(self, other): /usr/local/lib/python2.7/dist-packages/pandas/indexes/multi.pyc in from_arrays(cls, arrays, sortorder, names) 933 from pandas.core.categorical import _factorize_from_iterables 934 --> 935 labels, levels = _factorize_from_iterables(arrays) 936 if names is None: 937 names = [getattr(arr, "name", None) for arr in arrays] /usr/local/lib/python2.7/dist-packages/pandas/core/categorical.pyc in _factorize_from_iterables(iterables) 2066 # For consistency, it should return a list of 2 lists. 2067 return [[], []] -> 2068 return map(list, lzip(*[_factorize_from_iterable(it) for it in iterables])) /usr/local/lib/python2.7/dist-packages/pandas/core/categorical.pyc in _factorize_from_iterable(values) 2038 codes = values.codes 2039 else: -> 2040 cat = Categorical(values, ordered=True) 2041 categories = cat.categories 2042 codes = cat.codes /usr/local/lib/python2.7/dist-packages/pandas/core/categorical.pyc in __init__(self, values, categories, ordered, name, fastpath) 292 # raise, as we don't have a sortable data structure and so 293 # the user should give us one by specifying categories --> 294 raise TypeError("'values' is not ordered, please " 295 "explicitly specify the categories order " 296 "by passing in a categories argument.") TypeError: 'values' is not ordered, please explicitly specify the categories order by passing in a categories argument.
Ivyzxok commented 4 years ago

I got the same problem with you, and don't konw how to solve it