I'm trying to write a script that will analyze all of the buys and sells I have made for each cryptocurrency I own, and then tell me the average cost for a coin so I know the cost at which it is profitable to sell.
If all I had done was buy coins, it would be a simple matter of adding up my purchases and then dividing by the number of coins I hold. But, I did a lot of selling as well as buying. I am having a hard time wrapping my head around how to account for the selling. For the sake of giving a simple example, let's say I have the following transaction history for a particular coin:
Date Transaction Type Units Price in BTC Total Transaction size Aug 5 Buy 23 .002222 0.051106 BTC Aug 6 Sell 11 .002227 0.024497 BTC Aug 7 Buy 47 .022391 1.052377 BTC
Obviously after that activity I will have 59 coins left. But, what is the average cost that I paid for those 59 coins? I think this might be called the "cost basis" but it's unclear whether I'm using that term correctly.
There are two ways that I can see to do this:
Option A - divide net amount spent by net coins remaining
average = ( (0.051106 − 0.024497 + 1.052377) / 59 ) = 0.018287898
Option B - divide total transaction sizes by total unit volume
average = ( (0.051106 + 0.024497 + 1.052377) / 81 ) = 0.013925679
Which of these formulas is correct?
Note: I know there are other ways of calculating the cost basis, such as FIFO. In this case, I thought that using a weighted average was the best and simplest way to determine whether or not it'd be profitable to sell a particular coin at the current market price. I am not using the calculations for tax filing or anything like that. I just want to know my current break-even point for each coin.