`Index(['dt', 'open', 'high', 'low', 'close', 'volumn', 'trading_dt', 'stock'], dtype='object')
KeyError Traceback (most recent call last)
D:\Anaconda\envs\py36\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
2645 try:
-> 2646 return self._engine.get_loc(key)
2647 except KeyError:
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'high'
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last)
<ipython-input-98-ce3fa983de61> in <module>
----> 1 ch_3 = ta_pd_v2(ch)
<ipython-input-77-d2409a027e53> in ta_pd_v2(df)
8 df1["close-1"] = df1["close"].shift(1)
9
---> 10 df.ta.strategy(name='all')
11 return df1
D:\Anaconda\envs\py36\lib\site-packages\pandas_ta\core.py in strategy(self, **kwargs)
367 if name is None or name == "" or not isinstance(name, str): # Extra check
368 name = "all"
--> 369 self._all(**kwargs) if name == "all" else None
370
371
D:\Anaconda\envs\py36\lib\site-packages\pandas_ta\core.py in _all(self, **kwargs)
343 for kind in indicators:
344 fn = getattr(self, kind)
--> 345 fn(append=append, **kwargs)
346 print(f"[+] {kind}") if verbose else None
347
D:\Anaconda\envs\py36\lib\site-packages\pandas_ta\core.py in _wrapper(*class_methods, **method_kwargs)
22 def _wrapper(*class_methods, **method_kwargs):
23 cm = class_methods[0]
---> 24 result = method(cm, **method_kwargs)
25
26 cm._add_prefix_suffix(result, **method_kwargs)
D:\Anaconda\envs\py36\lib\site-packages\pandas_ta\core.py in aberration(self, high, low, close, length, atr_length, offset, **kwargs)
1067 @finalize
1068 def aberration(self, high=None, low=None, close=None, length=None, atr_length=None, offset=None, **kwargs):
-> 1069 high = self._get_column(high, 'high')
1070 low = self._get_column(low, 'low')
1071 close = self._get_column(close, 'close')
D:\Anaconda\envs\py36\lib\site-packages\pandas_ta\core.py in _get_column(self, series, default)
229 # Apply default if no series nor a default.
230 elif series is None or default is None:
--> 231 return df[self.adjusted] if self.adjusted is not None else df[default]
232 # Ok. So it's a str.
233 elif isinstance(series, str):
D:\Anaconda\envs\py36\lib\site-packages\pandas\core\frame.py in __getitem__(self, key)
2798 if self.columns.nlevels > 1:
2799 return self._getitem_multilevel(key)
-> 2800 indexer = self.columns.get_loc(key)
2801 if is_integer(indexer):
2802 indexer = [indexer]
D:\Anaconda\envs\py36\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
2646 return self._engine.get_loc(key)
2647 except KeyError:
-> 2648 return self._engine.get_loc(self._maybe_cast_indexer(key))
2649 indexer = self.get_indexer([key], method=method, tolerance=tolerance)
2650 if indexer.ndim > 1 or indexer.size > 1:
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'high'`
So, I used the customised feature generation script but run into error for certain features:
`def ta_pd_v2(df):
df1 = df.copy()
df1.columns = map(str.lower, df1.columns)
df1["open-1"] = df1["open"].shift(1)
df1["high-1"] = df1["high"].shift(1)
df1["low-1"] = df1["low"].shift(1)
df1["close-1"] = df1["close"].shift(1)
df1 = df1.ta.strategy(name='all')
return df1
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
D:\Anaconda\envs\py36\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
2645 try:
-> 2646 return self._engine.get_loc(key)
2647 except KeyError:
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'volume'
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last)
<ipython-input-28-5d947df895f7> in <module>
----> 1 ch.ta.strategy(name='all')
D:\Anaconda\envs\py36\lib\site-packages\pandas_ta\core.py in strategy(self, **kwargs)
367 if name is None or name == "" or not isinstance(name, str): # Extra check
368 name = "all"
--> 369 self._all(**kwargs) if name == "all" else None
370
371
D:\Anaconda\envs\py36\lib\site-packages\pandas_ta\core.py in _all(self, **kwargs)
343 for kind in indicators:
344 fn = getattr(self, kind)
--> 345 fn(append=append, **kwargs)
346 print(f"[+] {kind}") if verbose else None
347
D:\Anaconda\envs\py36\lib\site-packages\pandas_ta\core.py in _wrapper(*class_methods, **method_kwargs)
22 def _wrapper(*class_methods, **method_kwargs):
23 cm = class_methods[0]
---> 24 result = method(cm, **method_kwargs)
25
26 cm._add_prefix_suffix(result, **method_kwargs)
D:\Anaconda\envs\py36\lib\site-packages\pandas_ta\core.py in ad(self, high, low, close, volume, open_, signed, offset, **kwargs)
1161 low = self._get_column(low, 'low')
1162 close = self._get_column(close, 'close')
-> 1163 volume = self._get_column(volume, 'volume')
1164
1165 result = ad(high=high, low=low, close=close, volume=volume, open_=open_, signed=signed, offset=offset, **kwargs)
D:\Anaconda\envs\py36\lib\site-packages\pandas_ta\core.py in _get_column(self, series, default)
229 # Apply default if no series nor a default.
230 elif series is None or default is None:
--> 231 return df[self.adjusted] if self.adjusted is not None else df[default]
232 # Ok. So it's a str.
233 elif isinstance(series, str):
D:\Anaconda\envs\py36\lib\site-packages\pandas\core\frame.py in __getitem__(self, key)
2798 if self.columns.nlevels > 1:
2799 return self._getitem_multilevel(key)
-> 2800 indexer = self.columns.get_loc(key)
2801 if is_integer(indexer):
2802 indexer = [indexer]
D:\Anaconda\envs\py36\lib\site-packages\pandas\core\indexes\base.py in get_loc(self, key, method, tolerance)
2646 return self._engine.get_loc(key)
2647 except KeyError:
-> 2648 return self._engine.get_loc(self._maybe_cast_indexer(key))
2649 indexer = self.get_indexer([key], method=method, tolerance=tolerance)
2650 if indexer.ndim > 1 or indexer.size > 1:
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas\_libs\index.pyx in pandas._libs.index.IndexEngine.get_loc()
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'volume'
`
import traceback
def ta_pd(df):
df1 = df.copy()
indicators = pd.DataFrame().ta.indicators(as_list=True)
append = True
df1.columns = map(str.lower, df1.columns)
df1["open-1"] = df1["open"].shift(1)
df1["high-1"] = df1["high"].shift(1)
df1["low-1"] = df1["low"].shift(1)
df1["close-1"] = df1["close"].shift(1)
#print(len(indicators), "will be added.")
for kind in indicators:
try:
print(kind)
df1.ta(kind=kind, append=append)
except Exception as e:
print("\nError with indicator:", kind)
print("") # print(".", end="")
indicators2 = ["log_return", "percent_return", "trend_return"]
for kind in indicators2:
try:
print(kind)
df1.ta(kind=kind, append=append, cumulative=True)
except Exception as e:
print("\nError with indicator:", kind)
print("") # print(".", end="")
df1.drop(columns = ['dt', 'open', 'high', 'low', 'close', 'volumn', 'trading_dt', 'stock', 'open-1', 'high-1', 'low-1', 'close-1',
return df1
`
ad
Error with indicator: ad
adosc
Error with indicator: adosc