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

ValueError: Length of values (2401) does not match length of index (2400) #22

Open
dshetyo opened this issue May 28, 2022 · 1 comment

Comments

@dshetyo
Copy link

dshetyo commented May 28, 2022

Trying to run this simple code an getting following error

df = yf.download('TATAMOTORS.NS' , start='2022-04-01', end='2022-05-20', interval='5m')
df['date'] = df.index
df.index = range(len(df))
df.columns = df.columns.str.lower()
r = Renko(df)
r.set_brick_size(auto=True, atr_interval=2)
r.build()

r.plot()

Verifed that

df.index.size is 2401
len(df) is 2401

ValueError Traceback (most recent call last)
/tmp/ipykernel_1319/1050412922.py in
1 r = Renko(df)
----> 2 r.set_brick_size(auto=True, atr_interval=2)
3 r.build()
4
5 r.plot()

/local/home/dshetyo/python-venvs/python3.7_venv/lib/python3.7/site-packages/TAcharts/indicators/renko.py in set_brick_size(self, brick_size, auto, atr_interval)
44 raise ValueError("ATR interval is longer than historical data.")
45
---> 46 self.brick_size = self._optimize_brick_size(auto, brick_size, atr_interval)
47 return self.brick_size
48

/local/home/dshetyo/python-venvs/python3.7_venv/lib/python3.7/site-packages/TAcharts/indicators/renko.py in _optimize_brick_size(self, auto, brick_size, atr_interval)
52 if auto and not brick_size:
53 average_true_range = atr(
---> 54 self.df["high"], self.df["low"], self.df["close"], n=atr_interval
55 )
56 brick_size = np.median(average_true_range)

/local/home/dshetyo/python-venvs/python3.7_venv/lib/python3.7/site-packages/TAcharts/indicators/atr.py in atr(high, low, close, n)
15 """ Returns the average true range from candlestick data """
16
---> 17 prev_close = np.insert(close[:-1], 0, 0)
18 # True range is largest of the following:
19 # a. Current high - current low

<array_function internals> in insert(*args, **kwargs)

/local/home/dshetyo/python-venvs/python3.7_venv/lib64/python3.7/site-packages/numpy/lib/function_base.py in insert(arr, obj, values, axis)
4728 new[tuple(slobj)] = arr[tuple(slobj2)]
4729 if wrap:
-> 4730 return wrap(new)
4731 return new
4732 elif indices.size == 0 and not isinstance(obj, np.ndarray):

/local/home/dshetyo/python-venvs/python3.7_venv/lib64/python3.7/site-packages/pandas/core/generic.py in array_wrap(self, result, context)
2023 # error: Argument 1 to "NDFrame" has incompatible type "ndarray";
2024 # expected "BlockManager"
-> 2025 return self._constructor(res, **d).finalize( # type: ignore[arg-type]
2026 self, method="array_wrap"
2027 )

/local/home/dshetyo/python-venvs/python3.7_venv/lib64/python3.7/site-packages/pandas/core/series.py in init(self, data, index, dtype, name, copy, fastpath)
428 index = ibase.default_index(len(data))
429 elif is_list_like(data):
--> 430 com.require_length_match(data, index)
431
432 # create/copy the manager

/local/home/dshetyo/python-venvs/python3.7_venv/lib64/python3.7/site-packages/pandas/core/common.py in require_length_match(data, index)
530 if len(data) != len(index):
531 raise ValueError(
--> 532 "Length of values "
533 f"({len(data)}) "
534 "does not match length of index "

ValueError: Length of values (2401) does not match length of index (2400)

@dshetyo
Copy link
Author

dshetyo commented May 28, 2022

This is related to #14 which was never resolved

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

1 participant