I'm trying to design an algorithm that will find a price for me given a set of rules.
Current Situation
We currently set the 'price' of all products to £0.01 and set a 'line_crossed' property to false. We calculate the margin at £0.01 and, while it remains negative, double the price (increase at 2^n
). Once the margin becomes positive we set 'line_crossed' to true and switch to a different formula.
That formula keeps a track of the last price used and the current price and will move in the right direction (up if the margin is negative and down if the margin is positive) by half of the absolute value of the difference between the current and last price. It keeps doing this until the margin lies between -0.01 and 0.01.
Basically an exponential rise with a discontinuity followed by a convergence to the required price.
On a list of 20,000+ products this algorithm took a maximum of 28 'iterations' until it found the break even price for all the products.
Desired Situation
I have toyed with the idea of using a binary search and some of the information we have about the product (cost) to inform a sensible starting price. However, at the moment I'm favouring the idea of using a variant of the above algorithm except instead of always using half of the absolute difference between the last and current price, use a weighted version depending on distance from 0 margin. (At the moment, if we were at £8 on the way up and the break even price was £8.01 we'd go up to £16 and then work our way down to £8.01 in a number of steps).
Any ideas? It feels like it's an already solved problem but I don't know the solution.
Thanks,
Matt