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

Pandas MultiIndex on axis 0 #730

Open
sergejlazuk opened this issue Jul 8, 2024 · 1 comment
Open

Pandas MultiIndex on axis 0 #730

sergejlazuk opened this issue Jul 8, 2024 · 1 comment

Comments

@sergejlazuk
Copy link

sergejlazuk commented Jul 8, 2024

MultiIndex on columns (axis1) is supported well - inputs get matched on column indexes, e.g. prices and signals frames are alligned. However, rows MultiIndex (axis0) is not working as expected: when I try to use prices and signals DataFrames with rows MultiIndex (e.g. levels “Ticker“ and „Timestamp“ instead of just „Timestamp“) I get an error: „Broadcasting index is not allowed when index_from =strict“.
It works if one sorts the DataFrames beforehand, e.g.

df_prices=df_prices.sort_index()
df_signals=df_signals.sort_index()

Would be nice if row MultiIndexes would be treated same as columns MultiIndexes - inputs alligned by row index (and broadcasted to same shape if needed).

And then, when plotting results with MultiIndex rows, would be nice to have all index levels shown hierarchically on x-axis, e.g. like this:

import plotly.graph_objs as go
fig = go.Figure()
fig.add_trace(go.Scatter(x=[df.index.get_level_values('asset'),df.index.get_level_values('DT')], y=df['fwd']))
fig.show()
rowsMultiIndex

Currently vbt plot produces this (Indexes collapsed into single label):
asset_values

pf.value().vbt.plot()

rowsMultiIndexNow

@polakowo
Copy link
Owner

polakowo commented Jul 20, 2024

Currently, index is assumed to be time and thus sorted. But it's an interesting idea, thank you for your suggestion. I've put it to the features-wanted list.

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