Crypto-Signal
Crypto-Signal copied to clipboard
ValueError: Shape of passed values is (2, X), indices imply (2, Y)
I was getting this error:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "app.py", line 94, in run
self.behaviour.run(self.market_data, self.settings['output_mode'])
File "/app/behaviour.py", line 66, in run
new_result = self._test_strategies(market_data, output_mode)
File "/app/behaviour.py", line 161, in _test_strategies
new_result[exchange][market_pair]
File "/app/behaviour.py", line 356, in _get_crossover_results
'result': crossover_dispatcher[crossover](**dispatcher_args),
File "/app/analyzers/crossover.py", line 44, in analyze
combined_data = pandas.concat([new_key_indicator, new_crossed_indicator], axis=1)
File "/usr/local/lib/python3.6/site-packages/pandas/core/reshape/concat.py", line 213, in concat
return op.get_result()
File "/usr/local/lib/python3.6/site-packages/pandas/core/reshape/concat.py", line 408, in get_result
copy=self.copy)
File "/usr/local/lib/python3.6/site-packages/pandas/core/internals.py", line 5207, in concatenate_block_managers
return BlockManager(blocks, axes)
File "/usr/local/lib/python3.6/site-packages/pandas/core/internals.py", line 3033, in __init__
self._verify_integrity()
File "/usr/local/lib/python3.6/site-packages/pandas/core/internals.py", line 3244, in _verify_integrity
construction_error(tot_items, block.shape[1:], self.axes)
File "/usr/local/lib/python3.6/site-packages/pandas/core/internals.py", line 4608, in construction_error
passed, implied))
ValueError: Shape of passed values is (2, 145), indices imply (2, 142)
I've modified crossover.py to correct the error but I don't know if it's the proper way:
""" Crossover analysis indicator
"""
import numpy
import pandas
from talib import abstract
from analyzers.utils import IndicatorUtils
class CrossOver(IndicatorUtils):
def analyze(self, key_indicator, key_signal, key_indicator_index,
crossed_indicator, crossed_signal, crossed_indicator_index):
""" Tests for key_indicator crossing over the crossed_indicator.
Args:
key_indicator (pandas.DataFrame): A dataframe containing the results of the analysis
for the selected key indicator.
key_signal (str): The name of the key indicator.
key_indicator_index (int): The configuration index of the key indicator to use.
crossed_indicator (pandas.DataFrame): A dataframe containing the results of the
analysis for the selected indicator to test for a cross.
crossed_signal (str): The name of the indicator expecting to be crossed.
crossed_indicator_index (int): The configuration index of the crossed indicator to use.
Returns:
pandas.DataFrame: A dataframe containing the indicators and hot/cold values.
"""
key_indicator_name = '{}_{}'.format(key_signal, key_indicator_index)
new_key_indicator = key_indicator.copy(deep=True)
for column in new_key_indicator:
column_indexed_name = '{}_{}'.format(column, key_indicator_index)
new_key_indicator.rename(columns={column: column_indexed_name}, inplace=True)
length = new_key_indicator.shape()
crossed_indicator_name = '{}_{}'.format(crossed_signal, crossed_indicator_index)
new_crossed_indicator = crossed_indicator[:length[1]].copy(deep=True)
for column in new_crossed_indicator:
column_indexed_name = '{}_{}'.format(column, crossed_indicator_index)
new_crossed_indicator.rename(columns={column: column_indexed_name}, inplace=True)
combined_data = pandas.concat([new_key_indicator, new_crossed_indicator], axis=1)
combined_data.dropna(how='any', inplace=True)
combined_data['is_hot'] = combined_data[key_indicator_name] > combined_data[crossed_indicator_name]
combined_data['is_cold'] = combined_data[key_indicator_name] < combined_data[crossed_indicator_name]
return combined_data
I do not recommend the use of this indicator, it is better to use "ma_crossover" which is simpler to configure and use.
Just to know, what is your use case of this indicator?
Humm ok, I was looking in the config doc... I want to set an alert when MA 50 cross MA 120 and another one using ichimoku.