If I have a certain amount of money to invest regularly, how do I calculate the amount to let accumulate in my bank before I make that investment, assuming there is a fee associated with each additional investment?

For example, I might put aside $100 every week to invest into a stock with an expected growth of 9% p.a., but brokerage fees are $10/trade. For how many weeks should I accumulate the $100 before investing, if I can put it in my high-interest bank account at 4% p.a. until then?

Clearly, if the amounts I invest are too small, the fees will add up and make it expensive. On the other hand, if I allow too much money to accumulate in the bank first, I am not making use of the higher expected returns of the investment.

To put the problem precisely, let's define these variables:

  • s = amount put aside every period
  • d = length of period in years (e.g. 1/52 or 1/26)
  • r = annual interest on bank account, indexed monthly
  • g = expected annual growth of the stocks
  • b = brokerage fee per trade
  • n = number of periods to accumulate funds in bank before investing (zero if s should be invested immediately).

My exact questions is:

Given values of s,d,r,g and b, what value of n maximises returns?

Or if this question is too difficult to answer exactly, what simplifications can we make to get a practical solution to this problem? Have I overcomplicated it?

I suppose one could write a computer program to compare different values of n, but I am hoping for a closed-form solution. It seems like the solution to this problem should be well known, but I haven't seen it anywhere.

My progress so far:

edit: I have now posted what was here as part of my own answer.

  • There exist zero-commission start-ups, which may make the question obsolete. One hopes. :-)
    – Peter K.
    May 14, 2014 at 16:43
  • @PeterK. Sounds heavenly. Where I live, you are lucky if you can get $20 brokerage fees. The US stockmarket is much cheapter to trade in.
    – codebeard
    May 14, 2014 at 16:47
  • I would have rather added this as a comment, but where are you getting 4% yields in savings?
    – Triplell89
    May 14, 2014 at 16:51
  • On-line brokers like e-trade and td-ameritrade have fees of around $7 - $12 per trade.
    – Jay
    May 14, 2014 at 19:02
  • You may be able to buy the stock that you are interested in with a dividend reinvestment plan for little or no additional cost. May 18, 2014 at 4:13

3 Answers 3


Okay, I think I managed to find the precise answer to this problem!

It involves solving a non-linear exponential equation, but I also found a good approximate solution using the truncated Taylor series. See below for a spreadsheet you can use.

Finding the future value:

Let's start by defining the growth factors per period, for money in the bank and money invested:

R = (1+r/12)^(12d)

G = (1+g)^d

Now, let S be the amount ready to be invested after n+1 periods; so the first of that money has earned interest for n periods. That is,

S = s (1-R^(n+1)) / (1-R)

The key step to solve the problem was to fix the total number of periods considered. So let's introduce a new variable:

t = the total number of time periods elapsed

So if money is ready to invest every n+1 periods, there will be t/(n+1) separate investments, and the future value of the investments will be:

FV = (S-b) (1-G^t) / (1-G^(n+1))

This formula is exact in the case of integer t and n, and a good approximation when t and n are not integers. Substituting S, we get the version of the formula which explicitly depends on n:

FV = (s (1-R^(n+1)) / (1-R) - b) (1-G^t) / (1-G^(n+1))

Derivative of the future value with respect to n:

Fortunately, only a couple of terms in FV depend on n, so we can find the derivative after some effort:

dFV/dn = G^(n+1) (1-G^t) ln(G) (s (1-R^(n+1))/(1-R)-b) / (1-G^(n+1))^2 - s (1-G^t) R^(n+1) log(R) / ((1-G^(n+1)) (1-R))

Maximising the future value:

Equating the derivative to zero, we can remove the denominator, and assuming t is greater than zero, we can divide by the constant ( 1-G t ):

G^(n+1) ln(G) (s (1-R^(n+1)) - b (1-R)) - s R^(n+1) ln(R) (1-G^(n+1)) = 0

To simplify the equation, we can define some extra constants:

α = (s - b + b R) ln(G)

β = s ln(G/R)

γ = s ln(R)

Then, we can define a function f(n) and write the equation as:

f(n) = α (G/R)^(n+1) - β G^(n+1) - γ

Note that α, β, γ, G, and R are all constant.


From here there are two options:

  1. Use Newton's method or another numerical method for finding the positive root of f(n). This can be done in a number of software packages like MATLAB, Octave, etc, or by using a graphics calculator.

  2. Solve approximately using a truncated Taylor series polynomial. I will use this method here.

Approximating the solution with a Taylor series:

The Taylor series of f(n), centred around n=0, is:

f(n) = ( α (G/R) - β G -γ ) + sum_(k=1)^inf ( α (G/R) ln(G/R)^k - β G ln(G)^k) n^k / k!

Truncating the series to the first three terms, we get a quadratic polynomial (with constant coefficients):

f(n) ~ (α (G/R) - β G - γ) + (α (G/R) ln(G/R) - β G ln(G)) n + 0.5 (&alpha (G/R) ln(G/R)^2 - β G ln(G)^2) n^2

Closed-form approximate solution:

Using R, G, α, β and γ defined above, let c0, c1 and c2 be the coefficients of the truncated Taylor series for f(n):

c_0 = 0.5 (&alpha (G/R) ln(G/R)^2 - β G ln(G)^2)

c_1 = α (G/R) ln(G/R) - β G ln(G)

c_2 = α (G/R) - β G - γ


n ~ √(c_1^2 - 4 c_0 c_2) ) / abs(2 c_0) - c_1 / (2 c_0)

n should be rounded to the nearest whole number. To be certain, check the values above and below n using the formula for FV.


Using the example from the question:

For example, I might put aside $100 every week to invest into a stock with an expected growth of 9% p.a., but brokerage fees are $10/trade. For how many weeks should I accumulate the $100 before investing, if I can put it in my high-interest bank account at 4% p.a. until then?

Using Newton's method to find roots of f(n) above, we get n = 14.004.

Using the closed-form approximate solution, we get n = 14.082.

Checking this against the FV with t = 1680 (evenly divisible by each n + 1 tested):

  • When n = 13, FV = $903,861.85
  • When n = 14, FV = $903,891.13
  • When n = 15, FV = $903,865.89

Therefore, you should wait for n = 14 periods, keeping that money in the bank, investing it together with the money in the next period (so you will make an investment every 14 + 1 = 15 weeks.)


Here's one way to implement the above solution with a spreadsheet. StackExchange doesn't allow tables in their syntax at this time, so I'll show a screenshot of the formulae and columns you can copy and paste:


Spreadsheet formulae

Copy and paste column A:

n (unrounded)
t (periods)

Copy and paste column B:



Spreadsheet results

Remember, n is the number of periods to accumulate money in the bank. So you will want to invest every n+1 weeks; in this case, every 15 weeks.

  • @ChrisDegnen I only get $903891, can you see why your result is so different from mine? The main difference I can see is that your investment return is being compounded monthly but in my solutions I haven't assumed that (whereas banks tend to give you interest only every month, something like shares can be assumed to grow constantly, so I'm assuming 9% is the annualised return).
    – codebeard
    Apr 26, 2019 at 13:39
  • Like yours r = (1 + 0.04/12)^(12/52) - 1 and g = (1 + 0.09/12)^(12/52) - 1 Apr 26, 2019 at 13:54
  • @ChrisDegnen, no that's not like mine. As I tried to explain, you are compounding the investment returns monthly.
    – codebeard
    Apr 26, 2019 at 13:56
  • @ChrisDegnen You are using g = (1 + 0.09/12)^(12/52) - 1. I am not. Please try to understand why our solutions are different before trying to tell me that my answer is wrong.
    – codebeard
    Apr 26, 2019 at 14:07
  • Oh, so your bank rate is a 4% annual nominal rate compounded monthly and your investment rate is a 9% effective annual rate? ... Apr 26, 2019 at 14:09

Wow, this turns out to be a much more difficult problem than I thought from first looking at it.

Let's recast some of the variables to simplify the equations a bit. Let rb be the growth rate of money in your bank for one period. By "growth rate" I mean the amount you will have after one period. So if the interest rate is 3% per year paid monthly, then the interest for one month is 3/12 of 1% = .25%, so after one month you have 1.0025 times as much money as you started with. Similarly, let si be the growth rate of the investment.

Then after you make a deposit the amount you have in the bank is pb = s. After another deposit you've collected interest on the first, so you have pb = s * rb + s. That is, the first deposit with one period's growth plus the second deposit. One more deposit and you have pb = ((s * rb) + s) * rb + s = s + s * rb + s * rb^2. Etc. So after n deposits you have pb = s + s * rb + s * rb^2 + s * rb^3 + ... + s * rb^(n-1). This simplifies to pb = s * (rb^n - 1)/(rb - 1).

Similarly for the amount you would get by depositing to the investment, let's call that pi, except you must also subtract the amount of the broker fee, b.

So you want to make deposits when

pb>pi, or s*(ri^n-1)/(ri-1) - b > s*(rb^n-1)/(rb-1)

Then just solve for n and you're done! Except ... maybe someone who's better at algebra than me could solve that for n, but I don't see how to do it.

Further complicating this is that banks normally pay interest monthly, while stocks go up or down every day. If a calculation said to withdraw after 3.9 months, it might really be better to wait for 4.0 months to collect one additional month's interest.

But let's see if we can approximate. If the growth rates and the number of periods are relatively small, the compounding of growth should also be relatively small. So an approximate solution would be when the difference between the interest rates, times the amount of each deposit, summed over the number of deposits, is greater than the fee. That is, say the investment pays 10% per month more than your bank account (wildly optimistic but just for example), the broker fee is $10, and the amount of each deposit is $200. Then if you delay making the investment by one month you're losing 10% of $200 = $20. This is more than the broker fee, so you should invest immediately. Okay, suppose more realistically that the investment pays 1% more per month than the bank account. Then the first month you're losing 1% of $200 = $2. The second month you have $400 in the bank, so you're losing $4, total loss for two months = $6. The third month you have $600 in the bank so you lose an additional $6, total loss = $12. Etc. So you should transfer the money to the investment about the third month.

Compounding would mean that losses on transferring to the investment are a little higher than this, so you'd want to bias to transferring a little earlier.

Or, you could set up a spreadsheet to do the compounding calculations month by month, and then just look down the column for when the investment total minus the bank total is greater than the broker fee.

Sorry I'm not giving you a definitive answer, but maybe this helps.

  • What is ri here?
    – codebeard
    May 14, 2014 at 16:57
  • You are right that it is not possible to solve for n here algebraically. Using numerical methods, I tested a couple of solutions and found that your equation tended to overestimate n. I appreciate the ideas though :)
    – codebeard
    May 14, 2014 at 17:14
  • Yes, this does overestimate n. That's what I meant by "Compounding would mean that losses on transferring to the investment are a little higher than this" etc. But still, using your stated values above -- 9% vs 4%, $100 per deposit, and $10 broker fee -- I calculate by my method: delta-rate=5% per year=0.42% per month. .42%*$100=$0.42. 1 month->$.42, 2 months->$1.26, 3->$2.46, 4->$4.20, 5->$6.30, 6->$8.82, 7->$11.76, and we're over $10. Actual value using a spreadsheet, n=7 months, where difference is $11.92. So my estimate is off by 16 cents, or less than 2%. ...
    – Jay
    May 14, 2014 at 19:00
  • ... Seems close enough for real-world examples.
    – Jay
    May 14, 2014 at 19:00
  • I meant your first equation, s*(ri^n-1)/(ri-1) - b > s*(rb^n-1)/(rb-1) seems to overestimate n. I wasn't sure if that's what you were referring to in the second half.
    – codebeard
    May 15, 2014 at 0:53

The problem is not difficult to calculate but it is difficult to produce a formula for. For example, if you are putting aside $100 per month, and investing every n saved amounts.

amount put aside every month                s = 100
effective bank rate of 5% to monthly rate   r = (1 + 0.05)^(1/12) - 1
effective stock rate of 10% to monthly      g = (1 + 0.10)^(1/12) - 1
brokerage fee per trade                     b = 65

saved value after n months      a = x[n] = (s ((1 + r)^(n + 1) - 1))/r
invested value after n months       z[n] = (a - b) (1 + g)^n

With a cycle length n = 5 amounts before investing, a schematic looks like so:-

enter image description here

Each investment amount at five month intervals is $439.09, shown by example calculations.

100 (1 + r)^4 + 100 (1 + r)^3 + 100 (1 + r)^2 + 100 (1 + r) + 100 - 65 = 439.09

n = 5
a = x[n - 1] = 504.09

z[0] = 439.09

The schematic shows the investments extending only over 19 months.

The total for investments over 60 months, including the $100 put aside in month 60, is $6769.86, i.e.

For j = 60, 55, 50, 45, 40, 35, 30, 25, 20, 15, 10, 5, 0

If[j < n, x[j], z[j - n + 1]]

final values = 685.05, 658.37, 632.74, 608.11, 584.43, 561.68,
               539.81, 518.79, 498.59, 479.18, 460.52, 442.59, 100

Total = 6769.86

Looking over a range of cycle lengths, all to 60 months, the totals are erratic.

enter image description here

Note, j is taken from the maximum, so for investments over, say, 62 months

j = 62, 57, 52, 47, 42, 37, 32, 27, 22, 17, 12, 7, 2

Extending for 600 months smooths out the curve giving a clear optimum of n = 18. Same n for 6000 months; the curve is now static (although the totals change). Recalculation can be made for different interest rates, periodic amount and brokerage fee.

enter image description here

As mentioned though, producing a formula for the optimal n is not so easy.

An expression for the total at each n can be obtained, e.g. with

max = 60
n   = 5
d   = Quotient[max, n] = 12   (the integer quotient of max and n)
e   = Mod[max, n] = 0

enter image description here

(s ((1 + r)^(e + 1) - 1) -
   ((1 + g)^(e + 1) ((1 + g)^(d n) - 1) (b r + s - (1 + r)^n s))/
    ((1 + g)^n - 1))/r = 6769.86

Applying this to the OP's demo question

For example, I might put aside $100 every week to invest into a stock with an expected growth of 9% p.a., but brokerage fees are $10/trade. For how many weeks should I accumulate the $100 before investing, if I can put it in my high-interest bank account at 4% p.a. until then?

Taking the bank rate as nominal compounded monthly and the stock rate as effective.

enter image description here

The amount invested upon accumulation of each 15 amounts is

((1 + r)^14 + (1 + r)^13 + (1 + r)^12 +
 (1 + r)^11 + (1 + r)^10 + (1 + r)^9 +
 (1 + r)^8  + (1 + r)^7  + (1 + r)^6 +
 (1 + r)^5  + (1 + r)^4  + (1 + r)^3 +
 (1 + r)^2  + (1 + r) + 1) s - b = 1498.09

Not the answer you're looking for? Browse other questions tagged or ask your own question.