Python.Runtime.PythonException: 'dict' value cannot be converted to Skender.Stock.Indicators.Quote
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
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 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.
@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
@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.
If you have further question, please re-open anytime.