Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlite3 - significant digits #34

Open
BuildWithData opened this issue Apr 14, 2024 · 8 comments
Open

sqlite3 - significant digits #34

BuildWithData opened this issue Apr 14, 2024 · 8 comments
Assignees
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed

Comments

@BuildWithData
Copy link
Owner

BuildWithData commented Apr 14, 2024

for some reason sqlite fails to round to 2 decimal digits sometimes, for example:

    select * from inflows_btc_bxfill
    
    +------------+-------------------+
    |  ref_date  |       TOTAL       |
    +------------+-------------------+
    | 2024-01-11 | 13796.2           |
    | 2024-01-12 | 4023.2            |
    | 2024-01-15 |                   |
    | 2024-01-16 | -1947.1           |
    | 2024-01-17 | 9256.8            |
    | 2024-01-18 | -4514.5           |
    | 2024-01-19 | -545.900000000002 |
    | 2024-01-22 | -2350.3           |

but it seems this is kinda random, for example inflows_btc_bfill is created with data from inflows_btc but:

  select total from inflows_btc_bfill where ref_date = '2024-03-22'

  +---------+
  |  TOTAL  |
  +---------+
  | -310.93 |
  +---------+

  select total from inflows_btc where ref_date = '2024-03-22'

  +-------------------+
  |       TOTAL       |
  +-------------------+
  | -310.929999999999 |
  +-------------------+

but what is weirder is that rounding is done in both cases:

out["TOTAL"] = out.iloc[:, :-1].sum(axis=1).round(2)

out = (extracted.iloc[:, 1:] - extracted.iloc[:, 1:].shift(1)).round(2)

@BuildWithData BuildWithData added bug Something isn't working help wanted Extra attention is needed good first issue Good for newcomers labels Apr 14, 2024
@kaestro
Copy link

kaestro commented Apr 15, 2024

You mean you've stored datum in 2 decimal digits, but it sometimes fails to gives out the result as you've expected?

ex) you've stored 2024-01-19: -545.90 but it returned that value?

It might be caused from computer's float num storing system. so it's recommended you use rounding method to get the result you want.

@BuildWithData
Copy link
Owner Author

hey @kaestro, thanks for your feedback.

I agree but the thing is that numbers are rounded as you can see from the examples I have just added in the description.

What's your take ?
Wanna give it a try and fix this ?

@kaestro
Copy link

kaestro commented Apr 16, 2024

@BuildWithData

If I'm understood fine, you mean that you tried to store -310.93 into sqlite by sql query, but when trying to make a test it's giving out error for it's returning -310.929999... Am I right?

I think it's of concern on sqlite's settings if you want to fix it for you it would still store the decimals inaccurate form.

If you don't want to change the sqlite's settings, I think just rounding after you've got the output from sqlite would simply be okay

@BuildWithData
Copy link
Owner Author

@kaestro yeah you understood correctly

your second solution is not fixing the problem at the root and the thing is that people usually connect to the db and run queries, so I wanna see the expected number of digits in the table right there

we gotta go with the sqlite's settings then, can you help me with this ?

@kaestro
Copy link

kaestro commented Apr 18, 2024

@BuildWithData

Am I correct to understand that you're gonna give me an admin access to your sqlite server so that I can try to change the settings? Or Is there any way that I can change it as a code?

If I may, though I don't have enough experience with these kinda things, I would love to

@BuildWithData
Copy link
Owner Author

@kaestro you do not need any admin access, it's simpler than that. The idea of this whole project is to let anyone track BTC ETFs but in a don't trust verify way if we can say that.

All you gotta do is download and setup the repo on your local machine like shown here, grab the historical data here and then you are ready to start fixing this issue

any question/doubt, just write here :)

@kaestro
Copy link

kaestro commented Apr 18, 2024

@BuildWithData

Thank you for your support and giving me an offer. I'll start in 3 days

@BuildWithData
Copy link
Owner Author

it looks like we gotta define .sqliterc as they say here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants