Based on what we have known on Interest protocol’s interest rate model, we found that we can improve its borrow rate model by introducing PID controller,(the deposit rate is based on the borrow rate and the protocol fee rate). The core design of the borrow rate model is that when s value is small, we want to raise both borrow rate to encourage users to pay their loans and deposit rate to encourage users to deposit USDC (both way will help to increase s value). Thus, the core design of new borrow rate model will also raise borrow rate when s value is small.

First of all, we need to understand what is PID controller: In brief, PID is an adjusting algorithm when we want to change a parameter W to its optimal value W0 by adjusting another parameter Y.

The formula is :

e(t) = W0 - W(t), it means the difference between W’s target value (or optimal value) and W’s value at time t.

Y(t) = Y(t-1) +u(t), it means we should adjust Y(t) to the sum of u(t) (calculated as above) and Y(t-1)

For more information about PID controller, please see PID controller - Wikipedia

Introducing PID in our borrow rate model:

u(t) = P(t) + I(t) + D(t)

e(t) = S0 -S

P(t) = Kp * e(t)

I(t) = I(t-1) + Ki * e(t)

D(t) = Kd * ( e(t) -e(t-1) )

IR(t) = IR(t-1) + u(t)

S(t)is the s value at time t;

S0 is our target s value;

Kp、Ki、Kd are three parameters in PID’s formula;

IR(t) is the borrow rate at time t;

Tuning process:

In our first borrow rate model (three-line piecewise function), we apparently want s value to be above 0.4, so we can simply set S0 as 0.4 (S0 can be other number, and it also can be dynamic, here is just an example to show a simply way to value Kp、Ki、Kd)

To find optimal value for Kp、Ki、Kd (the process is called tunning), we are going to use Ziegler-nichols method (again, other methods can be used here).

For more information about Ziegler-nichols method, please see Ziegler–Nichols method - Wikipedia

Ziegler-nichols method process:

To complete the simulation in Ziegler-nichols method, we need a relationship betweer S(t) and IR(t), because in our PID example we want to affect S(t) by adjusting IR(t).

A simple way to set the simulation model:

When IR(t) is 0, S(t)should be 0, because no one would like to deposit.

When IR(t) is large enough, let’s say 0.5, S(t) should be 1,because none would like to carry the loans.

So we can have a simple simulation model:

S(t) = S(t-1) + ΔIR * 2 + whitenoise, ΔIR = IR(t-1) -IR(t-2)

IMPORTANT: the simulation model is very important in the process of finding best value for Ks, the actual simulation model can be very complicated and it should be based on testnet data if possible. Here is just a very basic linear simulation model used to show the process of tunning.

We set S(0) as 0.2 and IR(0) as 0.1. By following the third step of the graph above, we find the Kmax as 0.2 and f0 as 0.1, and thus we have Kp = 0.12, Ki = 0.024, Kd = 0.15 by using classic PID in the table(Ku =0.2 and Tu=10 inour case):

The graph of S(t) when we set Kp=0.2,Ki=0,Kd=0 and find sustained oscillation.

The graph of S(t) with Kp = 0.12, Ki = 0.024, Kd = 0.15

The graph of IR(t) with Kp = 0.12, Ki = 0.024, Kd = 0.15: