# how to optimise discount from revenue taking into account number of sales for each discount

I've been working on a problem which I can't seem to get my head round at the moment. I have a dataset lets say is like the following:

user_id discount_offered price_pre_discount price_after_discount actual_discount profit
3720917 10 1000 900 100 450
9283908 10 1000 950 50 475
3488334 0 1000 1000 0 500

so we can see that even with discount offered the actual discount may only have a weaker than expected correlation. This can be because the discount may only apply to certain items or shipping may not be included in certain deals etc.

Basically what I want to do is to optimise the discount offered to maximise profit, in this particular fake data i made further up the post, 10% discount would be optimal because although the profit was lower, it pushed more sales.

It seems to me like this should be possible to solve via some sort of optimisation problem but I'm not sure how to do it or if it is even possible? Like some type of gradient descent maybe? But then how can I extract the optimal value of discount?

I also looked into using the pulp package but it seems its more just theoretical if I input the algebraic formula for revenue and then solve for discount, with a constraint it can't be negative discount, but then that doesn't take into affect the volume of sales and I can't figure out how to incorporate it?

Any tips or nudges in the right direction would be awesome and I'm happy to answer questions as best as I can... I'm not so sure I fully understand the problem myself so might not have explained it great!