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 5 months 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