Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advice on format of loading data from csv #301

Open
Pmica opened this issue Sep 5, 2023 · 2 comments
Open

Advice on format of loading data from csv #301

Pmica opened this issue Sep 5, 2023 · 2 comments

Comments

@Pmica
Copy link

Pmica commented Sep 5, 2023

Has anyone tried to load strategy returns data from csv successfully. How have you done this, what format/ structure should it take. I haven’t successfully managed to do it without an error

@Pmica
Copy link
Author

Pmica commented Sep 6, 2023

I get the following error:


TypeError Traceback (most recent call last)
Cell In[30], line 1
----> 1 qs.plots.snapshot(df, title='Performance', show=True)

File ~\AppData\Local\anaconda3\Lib\site-packages\quantstats_plotting\wrappers.py:90, in snapshot(returns, grayscale, figsize, title, fontname, lw, mode, subtitle, savefig, show, log_scale, *kwargs)
88 returns = returns.mean(axis=1)
89 title = title + " (daily equal-weighted
)"
---> 90 returns.columns = strategy_colname
92 colors = _GRAYSCALE_COLORS if grayscale else _FLATUI_COLORS
93 returns = _utils.make_portfolio(returns.dropna(), 1, mode).pct_change().fillna(0)

File ~\AppData\Local\anaconda3\Lib\site-packages\pandas\core\generic.py:6002, in NDFrame.setattr(self, name, value)
6000 try:
6001 object.getattribute(self, name)
-> 6002 return object.setattr(self, name, value)
6003 except AttributeError:
6004 pass

File ~\AppData\Local\anaconda3\Lib\site-packages\pandas_libs\properties.pyx:69, in pandas._libs.properties.AxisProperty.set()

File ~\AppData\Local\anaconda3\Lib\site-packages\pandas\core\generic.py:729, in NDFrame._set_axis(self, axis, labels)
723 @Final
724 def _set_axis(self, axis: AxisInt, labels: AnyArrayLike | list) -> None:
725 """
726 This is called from the cython code when we set the index attribute
727 directly, e.g. series.index = [1, 2, 3].
728 """
--> 729 labels = ensure_index(labels)
730 self._mgr.set_axis(axis, labels)
731 self._clear_item_cache()

File ~\AppData\Local\anaconda3\Lib\site-packages\pandas\core\indexes\base.py:7128, in ensure_index(index_like, copy)
7126 return Index(index_like, copy=copy, tupleize_cols=False)
7127 else:
-> 7128 return Index(index_like, copy=copy)

File ~\AppData\Local\anaconda3\Lib\site-packages\pandas\core\indexes\base.py:516, in Index.new(cls, data, dtype, copy, name, tupleize_cols)
513 data = com.asarray_tuplesafe(data, dtype=_dtype_obj)
515 elif is_scalar(data):
--> 516 raise cls._raise_scalar_data_error(data)
517 elif hasattr(data, "array"):
518 return Index(np.asarray(data), dtype=dtype, copy=copy, name=name)

File ~\AppData\Local\anaconda3\Lib\site-packages\pandas\core\indexes\base.py:5066, in Index._raise_scalar_data_error(cls, data)
5061 @Final
5062 @classmethod
5063 def _raise_scalar_data_error(cls, data):
5064 # We return the TypeError so that we can raise it from the constructor
5065 # in order to keep mypy happy
-> 5066 raise TypeError(
5067 f"{cls.name}(...) must be called with a collection of some "
5068 f"kind, {repr(data)} was passed"
5069 )

TypeError: Index(...) must be called with a collection of some kind, 'Strategy' was passed

@git-shogg
Copy link
Contributor

Hi @Pmica, have a look at #313 (similar question regarding csv returns import), let me know if that helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants