The literal meaning of pip (on trading terms) is ‘point in percentage’, and it is the smallest standardised move that a currency quote can change by. Every currency or stock has different pip, so, some stocks may have a minimum pip of 0.01 and some others 0.00001 and so on... It is important for some calculations related with market direction to be able to compare the increase or decrease of pips. Even some market indicators use the minimum pip change of the value for it’s calculation... the problem is that pips are float values and due to Python concept of floats, it seems impossible to me to find a way to get the pip change. I found some threats related to the problem of getting the exact value of a float, like this: Limiting floats to two decimal points So I assume it won’t be possible to get a code working properly on this issue. My questions is: is there any way to do it? Maybe an external package or database containing that info? or am I wrong and it can be coded?
Asked
Active
Viewed 172 times
0
-
You could use decimals instead of floats: https://docs.python.org/3/library/decimal.html – slothrop Aug 18 '22 at 12:03
-
Thank you @slothrop, that could be a solution... however I've observed that when I download the data into dataframe, it is automatically casted as float,... I guess that a conversion wouldn't do the job – Aurepilous Aug 18 '22 at 12:21
-
Here's one way you can solve that: load it as a string then convert it. https://stackoverflow.com/a/66969597/765091. Or another way (maybe better since it doesn't go via a string in the dataframe): https://stackoverflow.com/a/38114744/765091 – slothrop Aug 18 '22 at 12:27
-
The problem is that once the data has ben download as float, the pip value info is lost. Any conversion converts a float, so the decimal positions are huge – Aurepilous Aug 18 '22 at 14:42
-
How do you download the data, and in what format? – slothrop Aug 18 '22 at 14:58
-
I use many sources: meta trader with the mt5 package and yahoo finance, from yfinance package. In both cases I retrieve the data as dataframe – Aurepilous Aug 18 '22 at 16:57
-
Are you able to get the data as a CSV? If so, then you can try converting the CSV to a dataframe which has decimals (and not floats) from the start, along the lines of this answer: https://stackoverflow.com/a/38114744/765091 – slothrop Aug 18 '22 at 17:08