New York, NY
Trading Experience: Beginner
Platform: Vanguard 401k
Broker/Data: Yahoo Finance
Favorite Futures: Mutual funds
Posts: 1,046 since Jul 2012
Thanks: 718 given,
2,147
received

You need to distinguish between symbolic and numerical differentiation here. There's 3 different approaches depending on what you're trying to do:
If you're trying to find the analytical form of the first derivative, f' and solve the root for it, and you know the analytic formula of f at compiletime, you can solve f'=0 by hand and hardcode that into your program. Or you can find f' and then get quadratic convergence on the minimum with NewtonRaphson.
If you know the analytic form of f at runtime, there's different ways to perform symbolic differentiation, and chain rulebased approaches are popular, e.g. in backpropagation literature for neural networks.
If you don't know the analytic formula of f either at compiletime or runtime, you can still use NewtonRaphson but approximate f' numerically with any finite difference method (secant, forward difference, backward difference, central difference), then converge on f'=0 iteratively.
