1

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

Kali_89
  • 617
  • 2
  • 7
  • 21
  • Can't this be reduced to an algabraic equation? Once there it is trival to design a more efficient algorithm is it not? – KingCronus Apr 16 '13 at 12:03
  • So your problem can be reduced to choosing if the price, as generated with your algorithm, is `cost - 0.01`, `cost` or `cost + 0.01`? – Carsten Apr 16 '13 at 12:26
  • What kind of function is the `price -> margin` dependency? You want to find a zero of that function (approximately), so if the function is smooth, Newton-Raphson would do fine (at least if you have a reasonable starting point), you could always use the secant method, that's usually also better than bisection. – Daniel Fischer Apr 16 '13 at 12:27
  • @KingCronus @Daniel-Fischer Thanks for the response, unfortunately there's not a smooth linear relationship between price and margin i.e. there are discontinuities in the `price -> margin` graph. – Kali_89 Apr 16 '13 at 13:44
  • @Carsten At this point, yes, though we will want to be able to change so that the price will fall between `cost + x - 0.01`, `cost + x` and `cost + x + 0.01` – Kali_89 Apr 16 '13 at 13:46

0 Answers0