Investment algorithm. How can I create a function that helps users find the amount that they need to invest?

Heres the problem:

Everytime you invest in a binary option you have 60% chances of winning and 40% chances of loosing. You start with a budget of $1000 and everytime you win, you win 1.3x. So if you invest $10 you will win $13.

So as an example:

  • Round 1: Start with $1000 and invest $10. Now you have $990. Result: you win. You win $13, now you have a budget of $1003.
  • Round 2: Start with $1003 and invest $10. Now you have $993. Result: you win. You win $13, now you have a budget of $1006.
  • Round 3: Start with $1006 and invest $10. Now you have $996. Result: you win. You win $13, now you have a budget of $1009.
  • Round 4: Start with $1009 and invest $10. Now you have $999. Result: you win. You win $13, now you have a budget of $1012.
  • Round 5: Start with $1012 and invest $10. Now you have $1002. Result: you lose. You don´t earn anything and lose what you invested, now you have a budget of $1002 and in the next round you need to invest an amount that makes you have a budget of $1012 (the highest historical budget).
  • Round 6: Start with $1002 and invest $X. Now you have ($1002 – $X). Result: you lose. You don´t earn anything and lose what you invested, now you have a budget of ($1002 – $X) and in the next round you need to invest an amount that makes you have a budget of $1012 (the highest historical budget).
  • Round 7: Start with ($1002 – $X) and invest $Y. Now you have ($1002 – $X – $Y). Result: you lose. You don´t earn anything and lose what you invested, now you have a budget of ($1002 – $X – $Y) and in the next round you need to invest an amount that makes you have a budget of $1012 (the highest historical budget).
  • Round 8: Start with ($1002 – $X – $Y ) and invest $Z. Now you have ($1002 – $X – $Y – $Z). Result: you win. You win $W, now you have a budget of $1012 again.
  • Round 9: Start with $1012 and invest $10. Now you have $1002. Result: you win. You win $13, now you have a budget of $1015.
  • Round 10: Start with $1015 and invest $10. Now you have $1005. Result: you win. You win $13, now you have a budget of $1018.

As you can see, when you are winning you keep investing only $10 but when you loose you need to find a number that its 1.3x gives you as a result the highest historical budget.

I need to create a function in Javascript like this calculateInvestment(currentBudget, historicalHighestBudget) and it should return the amount that the user needs to invest in order to reach the historicalHighestBudget. Taking into account the profit which is 1.3x.

For example if the function were like this calculateInvestment(1000, 1003) the function should return 10. This is the case in round one.

Thanks in advance.