stock-indicators-python icon indicating copy to clipboard operation
stock-indicators-python copied to clipboard

Python.Runtime.PythonException: 'dict' value cannot be converted to Skender.Stock.Indicators.Quote

Open Ugroon opened this issue 1 year ago • 3 comments

What happened?

Python.Runtime.PythonException: 'dict' value cannot be converted to Skender.Stock.Indicators.Quote

The above exception was the direct cause of the following exception:

System.ArgumentException: 'dict' value cannot be converted to Skender.Stock.Indicators.Quote in method Void Add(Skender.Stock.Indicators.Quote) ---> Python.Runtime.PythonException: 'dict' value cannot be converted to Skender.Stock.Indicators.Quote --- End of inner exception stack trace ---

The above exception was the direct cause of the following exception:

System.AggregateException: One or more errors occurred. ('dict' value cannot be converted to Skender.Stock.Indicators.Quote in method Void Add(Skender.Stock.Indicators.Quote)) ---> System.ArgumentException: 'dict' value cannot be converted to Skender.Stock.Indicators.Quote in method Void Add(Skender.Stock.Indicators.Quote) ---> Python.Runtime.PythonException: 'dict' value cannot be converted to Skender.Stock.Indicators.Quote --- End of inner exception stack trace --- --- End of inner exception stack trace ---

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "C:\Users\Administrator\e.py", line 29, in results = indicators.get_zig_zag(quotes, EndType.CLOSE, 3) File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\stock_indicators\indicators\zig_zag.py", line 39, in get_zig_zag results = CsIndicator.GetZigZag[Quote](CsList(Quote, quotes), end_type.cs_value, File "C:\Users\Administrator\AppData\Local\Programs\Python\Python310\lib\site-packages\stock_indicators_cstypes\list.py", line 35, in new deque(map(cs_list.Add, sequence), maxlen=0) TypeError: No method matches given arguments for List`1.Add: (<class 'dict'>)

Code usage

import pandas as pd
import matplotlib.pyplot as plt
from stock_indicators import indicators
from stock_indicators import EndType

def load_historical_data(filename):
    data = pd.read_csv(filename)
    data['timestamp'] = pd.to_datetime(data['timestamp'])
    quotes = []

    for index, row in data.iterrows():
        quotes.append({
            'timestamp': row['timestamp'],
            'close': row['close'],
            'high': row['high'],
            'low': row['low']
        })
    return quotes

quotes = load_historical_data('Price.csv')
results = indicators.get_zig_zag(quotes, EndType.CLOSE, 3)
results_df = pd.DataFrame(results)
print(results_df)

plt.figure(figsize=(14, 7))
plt.plot(results_df['timestamp'], results_df['zigzag'], label='ZigZag', color='red')
plt.plot([q['timestamp'] for q in quotes], [q['close'] for q in quotes], label='Close Price', color='blue', alpha=0.5)

plt.title('ZigZag Indicator with Close Prices')
plt.xlabel('Date')
plt.ylabel('Price')
plt.xticks(rotation=45)
plt.legend()
plt.grid()
plt.tight_layout()

plt.savefig('zigzag_plot.png')
plt.close()

Log output

No response

Ugroon avatar Sep 01 '24 19:09 Ugroon

@Ugroon can you attach the Price.csv file associated with this error? There's likely some unexpected data being imported from it. Being able to see it will help us understand the problem and find the right solution.

DaveSkender avatar Sep 02 '24 02:09 DaveSkender

@Ugroon It's the wrapper of C# library, so the type matters. That means quotes must be a iterable of Quote, which is subclass of Skender.Stock.Indicators.Quote. Please refer to here: https://python.stockindicators.dev/guide/#historical-quotes

from stock_indicators.indicators.common.quote import Quote

LeeDongGeon1996 avatar Sep 05 '24 15:09 LeeDongGeon1996

@Ugroon we'll assume you've resolved the problem and close this issue if we don't hear back from you soon. Let us know how it's going.

DaveSkender avatar Sep 06 '24 23:09 DaveSkender

If you have further question, please re-open anytime.

LeeDongGeon1996 avatar Nov 10 '24 14:11 LeeDongGeon1996