How to calculate the average price of shares

What formula is used to determine the average purchase price of your shares?

To calculate the average price of shares you own, use this formula:
Average Price = (Total Amount Invested) รท (Total Number of Shares Bought)
This is useful if you have bought shares at different prices over time.