Dollar cost averaging (DCA) does exceptionally well at diversifying the average price an investor pays for a stock by breaking down the purchases over time, instead of making one lump sum investment that may be poorly timed.

Let’s look at a real life example of how dollar cost averaging could work using the SPDR S&P Biotech ETF whose ticker is XBI. For this example, we will assume the investor wants to invest $1,000 per month by buying the ETF over a six month period at the beginning of the month.

Examining the historical chart of XBI in the first half of 2017 shows how the price jumps around, making it hard for an investor to know when is the right time to get in. DCA takes the emotion out of this guessing game by making regularly timed purchases with a fixed amount of money.

This approach ensures that the investor’s money is actively invested in the market instead of sitting in cash with no positive return while we nervously try to pick the right time to buy.

Most investors worry they’ll regret buying shares, because the price could fall. Imagine how bad you would feel if you saved up your $1,000 per month in January through March and then decided in March to buy $3,000 worth of ETF at $72.58 when XBI was at its high price. Just a few weeks later the price dipped to $68.00, which would be painful for any investor to watch and may even discourage you from investing again.

Instead you would have been much better off to put your investment plan on autopilot and stick to your plan to buy the ETF on the first of each month regardless of what is going on in the market. Investing in this way ensures that your money is regularly invested and in so doing, provides you with a diversified average price over time.

Essentially, you’ll buy more shares when prices are low, and fewer shares when the prices are high, which ultimately will smooth out the purchase price.

 So what would your average price per share actually look like? Let’s use our formula to calculate the harmonic mean to find out. To start, we first look up the price of XBI on the first day of each month in 2017.

Next, using this information we are able to calculate your average price per share. You are investing over six months, so the number in the numerator of our equation is six. You also have the six different prices you bought the ETF for over the same number of months, which you put into the denominator of the equation. You can now determine what  the average price-per-share  is using the harmonic mean equation.

Let’s make sure your calculation is correct by double checking what we have actually done. You know that you’ve invested $6,000 in the first six months of 2017, but now you need to determine how many shares you’ve purchased. This is a bit cumbersome to calculate and it’s the reason why it is simpler to use the harmonic mean equation shown above, but we will show you the calculation here for the sake of completeness. (We’ll also assume it’s possible to buy fractional shares to avoid mathematical or rounding errors in our calculation.)

So your average price per share is $6,000 divided by the total number of shares we bought, which is 89.19 or $6,000 / 89.14 = $67.27 per share. Using the harmonic mean formula saves you the hassle of needing to first calculate how many shares we bought each month before you can calculate your average price per share over the total six month period.

In order to effectively apply a dollar cost averaging strategy, it may be helpful to consider a brokerage firm that allows investors to purchase fractional shares. New brokerage companies like Stash allow investors to purchase fractional shares of ETFs, avoiding the issue of not having enough cash to purchase a full share.