Why Optimal Execution Can Produce a Proportional Trading Rule
Summary
The document connects optimal trading control with the structure of a proportional-integral-derivative controller. It outlines an optimal execution model in which trading speed changes the remaining inventory and cash balance, while price dynamics include permanent and temporary market impact. The trader's objective accounts for terminal proceeds, a penalty on leftover inventory, and a running cost for holding inventory.
The cited framework solves a Hamilton–Jacobi–Bellman problem and represents its value function as a quadratic function of remaining quantity. In common cases, the resulting optimal trading speed is linear in inventory, resembling the proportional component of a PID controller. The answer argues that integral and derivative terms are unnecessary when the control is already optimal for the specified model. This conclusion is model-dependent: the document does not establish that PID terms are unhelpful in every trading problem. A second answer gives a rough indicator script, but it is not supported by a performance evaluation and does not add evidence for optimality.
Key ideas
- An optimal execution model can include trading speed, inventory, cash, market impact, and inventory penalties.
- The cited solution derives trading speed from an HJB value function that is quadratic in remaining inventory.
- In common cases, optimal trading speed is linear in inventory and resembles proportional control.
- The claim that integral and derivative terms are unnecessary applies to the stated optimal-control setup, not necessarily to all trading systems.
- The document includes an unvalidated PID-style indicator example without performance evidence.
Tags
Full text
# Has work been done on PID controllers for optimal trading?
# Has work been done on PID controllers for optimal trading?
Commonly, stochastic control is the basis for optimal trading (either in execution or market-making). Has any research been done (or why not, if none) as to PID controllers for these applications?
## Answer by lehalle (score 4)
https://quant.stackexchange.com/a/83627
I recommend to have a look at the Careta-Jaimungal framework for optimal trading (Cartea, Álvaro, and Sebastian Jaimungal. "Incorporating order-flow into optimal execution" Mathematics and Financial Economics 10 (2016): 339-364.):
- your trading flow, you trading speed, or control is: is $\nu_t$
- the permanent impact via: $dS = b\cdot (\mu_t-\nu_t)\, dt+\sigma \, dW$,
- the temporary impact via: ${\hat S}_t:=S_t-(\psi/2+\kappa \nu_t)$, where $\psi$ is the bid-ask spread.
It means the dynamics of the system to liquidate a position is
- for the remaining quantity: $dQ^\nu=-\nu\, dt$,
- and $dX^\nu={\hat S}_t\nu_t\,dt$ for your cash account.
The value function is $$H_t(v):=\mathbb{E}_t\left( X^v_T + Q^v_T(S_T - \eta(Q^v_T)) - \phi \int_t^T (Q^v_s)^2 ds\right)$$
I let you do the computation (or read the book: L, C-A, and Sophie Laruelle. Market microstructure in practice World Scientific, 2018). You will find the optimal control is $$\nu^*=-{bq + \partial_q h\over 2\kappa}$$ where $h$ is quadratic in $q$, that is the remaining quantity to trade: $$h(t,q):=h_0(t)+ q h_1(t)+q^2 h_2(t).$$
In most cases you will discover that $h_1\equiv 0$, implying that $\nu^*$, the optimal control, is linear in the remaining quantity.
It means that you have the P (Proportional term) of the P.I.D. And since it is optimal (i.e. it is the solution of the HJB), you cannot do better: thus the two other letters (the I for the Integral term and the D for the Derivative term) are useless...
## Answer by cyberspider789 (score 0)
https://quant.stackexchange.com/a/75267
Check the code below for basic logic. You may need to improvise it (may be).Just a quick and dirty work. In case it works, reshare. Enjoy !!
How PID controller works - a crash (fast fast) course ?
- PID controller works on Error to minimise error !! Wow, that is mouthful. Error(e) = SetPoint (SP) - ProcessValue (PV). This is the most basic thing.
- Now there are three terms in PID controller equation which are actually multipliers
- kp - this dictates how much the output change with each unit change if error (repeat error).
- Kd - Tricky part starts from here. Kd is a multiple also but it is multiple of rate of change of error i.e. how much error is changing wrt time -3. Ki - Ki is also multiple but it is multiple of a term which has past memory of error i.e. Ki multiples summation of error.
Now you see...Kp dicatats how much you output changes wrt to difference between setpoint and actual value i.e. proprotional part , Kd dicatact how the rate of change of error affect the output, ki dictate how much error is minimised. Suppose Setpoint and output becomes same then error is zeror, there is no rate of change of error and summation of error is also zero.
//@version=5 indicator("PID Controller", overlay=false)
// Input Variables lookback = input.int(title="Lookback Period", defval=20, minval=1) kp = input.float(title="Kp", defval=0.1, minval=0) kd = input.float(title="Kd", defval=0.1, minval=0) ki = input.float(title="Ki", defval=0.1, minval=0) price_src = input(close, title="Price Source")
// Variables var float error = 0.0 var float error_sum = 0.0 var float error_diff = 0.0 var float pid = 0.0
// Arrays var float[] pid_array = array.new_float(0)
// Loop for i = 0 to 10 // Calculate error and PID error := price_src - ta.sma(price_src, lookback) error_sum := error_sum + error error_diff := error - nz(error[1]) pid := kperror + kierror_sum + kd*error_diff
```
// Add PID value to array
array.push(pid_array, pid)
// Wait for next bar
//bar_wait(0)
```
// Calculate average PID value var pid_sum = 0.0 for i = 0 to array.size(pid_array)-1 pid_sum := pid_sum + array.get(pid_array, i) var float pid_avg = pid_sum / array.size(pid_array)
// Plotting plot(pid_avg, color=color.green, linewidth=1, title="PID")Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.