JerBouma/FinanceDatabase

IndexError in technical analysis of biotech ETFs during coronacrisis sample

Opened this issue · 2 comments

I was exploring the code in the README and encountered an IndexError: index 4 is out of bounds for axis 0 with size 4 when I tried one of the examples. this arises when the number of unique tickers from the bollinger_bands.columns.get_level_values(1).unique() call exceeds the number of subplots available in the grid specified.

for ticker in bollinger_bands.columns.get_level_values(1).unique():
    name = health_care_etfs_in_biotech.loc[health_care_etfs_in_biotech.index == ticker, 'name'].iloc[0]
    
    bollinger_bands.xs(ticker, level=1, axis=1).plot(
        ax=axis[row, column],
        xlabel='',
        title=name,
        legend=False
        )

    column += 1
    if column == 3:
        row += 1
        column = 0

there are a number of ways to do this more elegantly, but I'm thinking that we just break out if row is out of bounds since it's only for illustrative purposes. I've shot a PR in this way but let me know if a different solution is required.

thanks!

Hi @mx700,

I don't quite understand the issue here. The amount of companies found through using the functionality is equal to 12 (FinanceDatabase returns 14 companies but 2 have no data). Therefore, creating a 4x3 grid should always work.

Are you on the latest release of the FinanceDatabase (v2.2.0) and FinanceToolkit (v.1.3.8)? I don't fully understand how you could run into an issue here.

image

Closing this issue as I believe this is currently not a problem. Let me know if you still experience issues.