Treatments often come with thresholds, e.g. we are given statins if our cholesterol is above a certain threshold. But which statin administration threshold maximizes our quality of life adjusted years? More generally, which threshold would optimize the average expected outcome? Regression discontinuity approaches are used to measure the local average treatment effect (LATE) and more recently also the treatment effect derivative (TED). Here we show how they can be used to optimize the threshold itself using linear methods related to Newton’s method as well as Gaussian process regressions. Phrasing the problem as optimization allows for a range of distinct estimators, including one that is unlikely to produce harm.