I am building a stock portfolio tracking application, and I am having some difficulties wrapping my head around something very basic (maybe I'm just tired)
How does selling a stock affect the cost basis / average price of the remaining stock?
Example
I buy 10 shares at an average price of $1
averagePrice: 1,
costBasis: 10,
quantity: 10,
I then sell 5 of these shares at market price of $5
averagePrice: ???
costBasis: ???
quantity: 5
The only value that I know for certain is the quantity, I have heard different brokers use different methods for calculating this cost basis.
Can someone help me fill in the values? I apologise if this is really dumb.