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

bug: IndicatorFactory - Unnecessary column level while operating with single column #641

Open
andreas-vester opened this issue Aug 16, 2023 · 3 comments
Labels

Comments

@andreas-vester
Copy link

andreas-vester commented Aug 16, 2023

I am making use of the sample from the documentation (https://vectorbt.dev/api/indicators/factory/#naive-approach), with the exception that my price only consists of one security (column).

from datetime import datetime

import pandas as pd
import vectorbt as vbt

price = pd.DataFrame(
    {"a": [1, 2, 3, 4, 5]},
    index=pd.Index(
        [
            datetime(2020, 1, 1),
            datetime(2020, 1, 2),
            datetime(2020, 1, 3),
            datetime(2020, 1, 4),
            datetime(2020, 1, 5),
        ]
    ),
).astype(float)

MyInd = vbt.IndicatorFactory(
    input_names=["price"],
    param_names=["window"],
    output_names=["ma"],
).from_apply_func(vbt.nb.rolling_mean_nb)

When running the indicator with any kind of window combination, the resulting dataframe will consist of multiple columns. Everything is fine here.

myind1.ma

custom_window    2    3
2020-01-01     NaN  NaN
2020-01-02     1.5  NaN
2020-01-03     2.5  2.0
2020-01-04     3.5  3.0
2020-01-05     4.5  4.0

As soon as I reduce the number of parameters to a single parameter, the output looks a bit different, i.e. there has been added another column level with no name and the value a.

myind2.ma

custom_window    2
                 a
2020-01-01     NaN
2020-01-02     1.5
2020-01-03     2.5
2020-01-04     3.5
2020-01-05     4.5

This might causing issues when further processing these results. I wouldn't expect any difference in the column levels no matter how many columns.

Is there an easy way to avoid this behaviour?

@andreas-vester andreas-vester changed the title bug: IndicatorFactory - Unnecessary column level with only one column bug: IndicatorFactory - Unnecessary column level while operating with single column Aug 16, 2023
@polakowo
Copy link
Owner

You could set drop_redundant=False in vbt.settings.broadcasting to keep "a" in both examples.

@andreas-vester
Copy link
Author

I would rather like to get rid of "a" in both examples. Is this possible?

Copy link

github-actions bot commented Feb 5, 2024

This issue is stale because it has been open for 90 days with no activity.

@github-actions github-actions bot added the stale label Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants