facioquo / stock-indicators-python

Stock Indicators for Python. Maintained by @LeeDongGeon1996
https://python.StockIndicators.dev
Apache License 2.0
221 stars 37 forks source link

What´s the right way to create the iterable "quotes" list from a dataframe? #228

Closed August1328 closed 2 years ago

August1328 commented 2 years ago

I use another python TA module and wanted to compare it with this module, but I am already having problems at the beginning.

I can download historical quotes from IBKR into a dataframe "hist_quotes". The df looks like this:

date open high low close volume 954 2022-05-07 01:54:00 3.26 3.27 3.250 3.2599 7600.0 955 2022-05-07 01:55:00 3.26 3.26 3.250 3.2600 3900.0 956 2022-05-07 01:56:00 3.26 3.26 3.250 3.2500 300.0 957 2022-05-07 01:57:00 3.25 3.26 3.230 3.2300 17900.0 958 2022-05-07 01:58:00 3.25 3.27 3.245 3.2600 12500.0 ...

The quotes parameter has be of type "Iterable[Quote]", so I converted the df to a list: quotes = hist_quotes.values.tolist()

and then call the indicator results = indicators.get_kvo(quotes, 34,55,13)

which breaks off with an error:

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

The content of "quotes" looks like this and it is iterable:

[[Timestamp('2022-05-06 10:00:00'), 3.23, 3.63, 3.23, 3.61, 98300.0], [Timestamp('2022-05-06 10:01:00'), 3.61, 3.63, 3.55, 3.62, 68900.0], [Timestamp('2022-05-06 10:02:00'), 3.62, 3.63, 3.51, 3.51, 65400.0], ....

I read every post available on this topic on stackoverflow and also tried different ways to create the quotes -- df.to_records(), df.to_dict(), iter(), ... but everything failed.

So, I am a little stuck... I guess the solution is rather simple, could someone show please help me with the right way? What am I missing?

LeeDongGeon1996 commented 2 years ago

@August1328 Hi, thank you for using our library. I guess you are passing just a list form of dataframe, but the library has its own Quote class. You have to pass the Iterable(ex. list) of Quote instances.

This comment may be helpful to you:

August1328 commented 2 years ago

Thanks, I missed this comment due to the different subject.

The calculation works fine now.

LeeDongGeon1996 commented 2 years ago

Good to hear that! If you have further questions, please let us know anytime :)

DaveSkender commented 5 months ago

[!TIP] For a working example using price quotes from a pandas.DataFrame, see our Replit of the Williams Fractal indicator. If you're having general trouble getting setup, see our QuickStart guide.

See also: