## When life gives you lemons, act optimally

### Intro

You're 9 years-old and you need to start saving up to pay for college, how are you going to do that?

Well, you can't get a job, so you'll have to be smarter - maybe you can start a lemonade stand?

A lemonade stand is actually a complicated business, as it turns out.

So, you mix some lemon juice, some sugar, and some water and you setup a small stand in your front yard.

Now, the question is: how much will you charge?

This is actually a hard problem. But you're young, and you don't know any better, so you decide to charge $1.00 per cup. It's a nice even number, so why not?

Your business kicks off in a flash, leaving you dizzied with the results: 32 customers on the first day!

Not too bad for a just a kid, and you only have ~67,000 more customers to go to pay your way through Harvard.

The next day you have around 24 customers, a little less than yesterday, but still pretty good. You start to wonder if maybe you have the right price for your lemonade though. The next day you decide to raise your price to $2.00, that way you'll make even more money than the day before! But only 12 people bought the lemonade this time, what gives?

You sit down and draw a small graph: price on the X-axis and number of customers on the Y-axis. You then plot your points and draw a straight line through it.

You reason that if you charge $1.50 - then around 18 people will buy the lemonade, and you decide to experiment. The next day, you charge $1.50 and 15 people buy it.

You add another point to your graph. This time, you can't draw a straight line through it.

So you have a few options.

- You can draw a curvy line, but how would you draw it?
- You could draw a straight line and fit it best, but it wouldn't touch all the points

Most questions about pricing were about this very problem. What's the best way to draw the **demand curve**?
There's a very good reason this was the problem - data was sparse.

We only had sales data to go on - we didn't have the plethora of data we have available today (that AristanderAI takes advantage of).

As it turns out - the best generalization we have for the demand curve revolves around the sigmoid curve and reference prices:

But, what would the problem look like if we did have that data? How could we improve?

### Smarter Pricing with Bayesian Optimization

As it turns out, no one buys lemonade in the winter. Instead, you decide to sell hot chocolate. Let's try to be smarter about our pricing.

But we don't know our product very well - in fact, we've never sold it before and have no idea how consumers will respond to it.

So this time, we'll use Bayesian optimization to approach our problem.

First, we set some boundaries: it costs us 50 cents to make the hot chocolate, and we reason that no one will want to spend more than $5.00 to buy one and that most people will only want prices at 25 cent intervals.

Next, we fit our model. Because we have no data points, our model shows us equal uncertainty across all prices.

We pick a price at random from the uncertainty region - so we assume the model is correct in predicting uncertainty around each point.

In this case, we picked $3.50 - on our first day we get 15 customers. We now add our point to our model and draw a new price, eventually revealing the true demand curve (while lowering the amount of money lost from price testing).

### Removing Demand Forecasting

Predicting how many people (and what type) will show up to our hot chocolate stand is a hard problem. It's a lot harder, actually, then just predicting if a given person standing in front of you will actually purchase the hot chocolate.

Let's pretend that each person stands in front of our hot chocolate stand - and then makes a decision to purchase the hot chocolate or not. In this case, we fit the model to predict a binary outcome: purchase or not. What we end up with is a model that can do personalized pricing AND aggregate pricing. The mode that the model operates in simply depends on when the pricing occurs: at point of purchase (or whenever the consumer is exposed to the price), or at the start of each day (where the model acts as an average across all people).

To find the optimal price, we fit a curve using the output of the model over all prices and pick the price that meets our objectives best (for example, revenue vs margin).

Typically, a demand forecasting element is included into this type of pricing, or even dependent on it, as logistics is a major part of pricing for most companies (and non toy problems).

### Resources

Thompson Samping for Dynamic Pricing

Analytics for an Online Retailer: Demand Forecasting and Price Optimization