Data fundamentals question for averaging percentages

21 Views Asked by At

So I have a script which records buying and selling transactions from a table, for each transaction it records the % difference so something like this (Table 'A'):

|    date    |  time | price | transaction_type | id
| 2023-02-11 | 17:40 |   10  |      'buy'       | 1234-564-gtfA
| 2023-03-11 | 17:45 |   15  |      'sell'      | 1234-564-gtfA
| 2023-02-11 | 17:40 |   20  |      'buy'       | 1234-564-gtfB
| 2023-03-11 | 17:45 |   22  |      'sell'      | 1234-564-gtfB
| 2023-02-11 | 17:40 |   10  |      'buy'       | 1234-564-gtfC
| 2023-03-11 | 17:45 |   17  |      'sell'      | 1234-564-gtfC

it would record in another table (Table 'B'):

|    date    |  time | perc_diff | id
| 2023-03-11 | 17:45 |     50    | 1234-564-gtfA
| 2023-03-11 | 17:45 |     10    | 1234-564-gtfB
| 2023-03-11 | 17:45 |     70    | 1234-564-gtfC

So when I'm creating aggregate statistics originally I was just averaging over the perc_diff column to get the "total" average % change but when instead using the raw transaction numbers. I.e. summing the sells then subtracting the buys, dividing by the total_sale it's a completely different number. 35% for using the raw transactions, 43% averaging the perc_diff column.

I know that this makes sense like intuitively but I can't figure out why it doesn't work.

Anyone good at math want to explain it to me like I'm the dummy that I am?