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

ml.util.get_daily_vol --> ValueError: operands could not be broadcast together #505

Open
skylinepro opened this issue Jul 28, 2021 · 2 comments
Labels
question Further information is requested

Comments

@skylinepro
Copy link

skylinepro commented Jul 28, 2021

Hi Guys,

I am having an issue running: daily_vol = ml.util.get_daily_vol(close=data['close'], lookback=50)
ValueError: operands could not be broadcast together with shapes (3231,) (3213,)

Data used:
data.csv

@Jackal08
@PanPip

@nathanleclaire
Copy link
Contributor

nathanleclaire commented Aug 20, 2021

@fmantesso I was hitting this same issue and what was happening in my case was that I had duplicated entries in the index. (I'm using custom code to generate bars)

get_daily_vol didn't like that very much as you can see from the broadcast error (the dupe indices must throw off some of the Timedelta related transforms)

I took a look at your posted CSV and it has the same issue, check it out. Might want to look into fixing that and see if it works when there are no more dupes.

>>> df.loc[df.index[df.index.duplicated(keep=False)]]
                               date_time      open      high       low    close  cum_vol    cum_dollar  cum_ticks         avg       upper       lower   rsi  side
date_time
2012-04-09 11:04:24  2012-04-09 11:04:24   63.2051   63.2051   63.0500   63.080    41453  2.614855e+06         25   64.458952   65.541349   63.376554   7.0   1.0
2012-04-09 11:04:24  2012-04-09 11:04:24   63.0700   63.0700   63.0600   63.060   329800  2.079719e+07          4   64.404091   65.542044   63.266138   7.0   1.0
2012-04-09 11:04:24  2012-04-09 11:04:24   63.2051   63.2051   63.0500   63.080    41453  2.614855e+06         25   64.458952   65.541349   63.376554   7.0   1.0
2012-04-09 11:04:24  2012-04-09 11:04:24   63.0700   63.0700   63.0600   63.060   329800  2.079719e+07          4   64.404091   65.542044   63.266138   7.0   1.0
2012-09-06 11:22:13  2012-09-06 11:22:13   65.2769   65.4400   65.2700   65.350    38388  2.508656e+06         41   64.295314   65.195689   63.394940  82.0  -1.0
2012-09-06 11:22:13  2012-09-06 11:22:13   65.3500   65.3700   65.3500   65.370    84042  5.493826e+06          2   64.337459   65.274899   63.400019  82.0  -1.0
2012-09-06 11:22:13  2012-09-06 11:22:13   65.2769   65.4400   65.2700   65.350    38388  2.508656e+06         41   64.295314   65.195689   63.394940  82.0  -1.0
2012-09-06 11:22:13  2012-09-06 11:22:13   65.3500   65.3700   65.3500   65.370    84042  5.493826e+06          2   64.337459   65.274899   63.400019  82.0  -1.0
2015-01-05 10:07:46  2015-01-05 10:07:46   92.5500   92.5600   92.5500   92.550    29122  2.695241e+06         21   93.742777   94.845069   92.640485  22.0   1.0
2015-01-05 10:07:46  2015-01-05 10:07:46   92.5500   92.5500   92.5500   92.550    45000  4.164750e+06          1   93.696002   94.831991   92.560013  22.0   1.0
2015-01-05 10:07:46  2015-01-05 10:07:46   92.5500   92.5600   92.5500   92.550    29122  2.695241e+06         21   93.742777   94.845069   92.640485  22.0   1.0
2015-01-05 10:07:46  2015-01-05 10:07:46   92.5500   92.5500   92.5500   92.550    45000  4.164750e+06          1   93.696002   94.831991   92.560013  22.0   1.0
2015-08-27 10:22:50  2015-08-27 10:22:50   86.1925   86.3100   86.1800   86.250    31007  2.674354e+06         44   84.345940   86.037670   82.654210  81.0  -1.0
2015-08-27 10:22:50  2015-08-27 10:22:50   86.2501   86.2501   86.2300   86.230    29641  2.555943e+06         20   84.419825   86.168191   82.671459  81.0  -1.0
2015-08-27 10:22:50  2015-08-27 10:22:50   86.1925   86.3100   86.1800   86.250    31007  2.674354e+06         44   84.345940   86.037670   82.654210  81.0  -1.0
2015-08-27 10:22:50  2015-08-27 10:22:50   86.2501   86.2501   86.2300   86.230    29641  2.555943e+06         20   84.419825   86.168191   82.671459  81.0  -1.0
2018-01-11 09:59:08  2018-01-11 09:59:08  117.1200  117.1700  117.1200  117.170    21337  2.500056e+06         34  116.655422  117.139964  116.170881  80.0  -1.0
2018-01-11 09:59:08  2018-01-11 09:59:08  117.1800  117.2000  117.1800  117.200   262870  3.080836e+07          8  116.676778  117.178005  116.175552  81.0  -1.0
...

@PanPip PanPip added the question Further information is requested label Oct 11, 2021
@PanPip
Copy link
Contributor

PanPip commented Oct 11, 2021

Thank you for the help @nathanleclaire!

Hi @fmantesso, does this error appear when you use the method on a dataset with no index duplicates?

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

No branches or pull requests

3 participants