Now, I'm not totally clear on what you are trying to solve, but I think you are making it unnecessarily complicated by keeping track of every time you buy bitcoins. Really, all you need to do is keep track of the total BTC and the total $.
Here is your first example:
You purchase 10 BTC for $90: BTC = 10, $ = - 90
You purchase 9 BTC for $90: BTC = 19, $ = -180
You purchase 6 BTC for $72: BTC = 25, $ = -252
You purchase 7 BTC for $91: BTC = 32, $ = -343
You sell 5 BTC for $53.59: BTC = 27, $ = -289.41
Here is your second example:
You purchase 10 BTC for $90: BTC = 10, $ = - 90
You purchase 9 BTC for $90: BTC = 19, $ = -180
You purchase 6 BTC for $72: BTC = 25, $ = -252
You purchase 7 BTC for $91: BTC = 32, $ = -343
You purchase 10 BTC for $115: BTC = 42, $ = -458
You sell 5 BTC for $53.59: BTC = 37, $ = -404.41
Why isn't this enough?
I would like to sell them all at the average price to have a more consistant price.
> with my formula I would sell the 5
BTC and evenly deducate it over all bought coins, and the average price WILL NOT CHANGE.
I made some faulty calculations though but last night I finally came to the real deal.
First example:
I purchase 10 BTC for $90: BTC = 10, $ = - 90
I purchase 9 BTC for $90: BTC = 19, $ = -180
I purchase 6 BTC for $72: BTC = 25, $ = -252
I purchase 7 BTC for $91: BTC = 32, $ = -343
--------------------------------------------------------------
I purchased 32 BTC for $343: Average price: $10,71875, $ = -343That would actually equal to all the coins I bought at the average price:
I purchase 10 BTC for $107,1875: BTC = 10, $ = - 107,1875
I purchase 9 BTC for $96,46875: BTC = 19, $ = -203,65625
I purchase 6 BTC for $64,3125: BTC = 25, $ = -267,96875
I purchase 7 BTC for $75,03125: BTC = 32, $ = -343
--------------------------------------------------------------
I purchased 32 BTC for $343: Average price: $10,71875, $ = -343So now I sell 5
BTC:
I purchase 10 BTC for $107,1875: BTC = 10, $ = - 107,1875
I purchase 9 BTC for $96,46875: BTC = 19, $ = -203,65625
I purchase 6 BTC for $64,3125: BTC = 25, $ = -267,96875
I purchase 7 BTC for $75,03125: BTC = 32, $ = -343
--------------------------------------------------------------
I purchased 32 BTC for $343: Average price: $10,71875, $ = -343--------------------------------------------------------------
I sell 5 BTC for $53,59375: BTC = 27, $ = -289.40625
--------------------------------------------------------------
I have 27 BTC left for $289.40625: Average price: $10,71875Now what if I buy another 10 BTC for $11,56?
I purchase 10 BTC for $107,1875: BTC = 10, $ = - 107,1875
I purchase 9 BTC for $96,46875: BTC = 19, $ = -203,65625
I purchase 6 BTC for $64,3125: BTC = 25, $ = -267,96875
I purchase 7 BTC for $75,03125: BTC = 32, $ = -343
--------------------------------------------------------------
I purchased 32 BTC for $343: Average price: $10,71875, $ = -343--------------------------------------------------------------
I sell 5 BTC for $53,59375: BTC = 27, $ = -289.40625
--------------------------------------------------------------
I have 27 BTC left for $289.40625: Average price: $10,71875--------------------------------------------------------------
I purchase 10 BTC for $115,6: BTC = 32, $ = -343
--------------------------------------------------------------
I have 37 BTC for $405,00625: Average price: $10,94611487
Check:In total I bought 42 BTC for $458,6!
In my inventory I have 37 BTC left for a value of: $405,00625
If I add the 5BTC (which was sold) to it, I should get the price I paid for it.
405,00625 + 53,59375 = 458,6!
You were right though, I only made it complicated by deducating it while actually I should only change the price tags.
I'm going to use this method, it's a variant of what you proposed with the calculations in my mind.
Thank you to everyone who posted in this thread.
If you wish that I elaborate any part of the above then don't hassle to post!
- Flowz