I'm relatively new to Stan, but have been really impressed with it. Thank you so much for making this excellent work available under a permissive open source license. I have been using command Stan 2.9.
Now my question: Is there a nice way to estimate derivatives in a Stan model?
Specifically, I have a financial portfolio valuation v = E[ f(x) ], and need to compute the derivative of v with respect to certain parameters of the distribution. (The vector x are basically prices and the function f is a payoff function that is continuous and piece-wise smooth.) There are two flavors of how to do this: First, the "path-wise" method looks at the prices x(t) as a function of the parameters t, and differentiates d(f(x(t))/dt using the chain rule (and takes its expectation). The other main flavor parameterizes the probability distribution p(x;t) with t, and computes
dv/dt = E[ f(x) d(log p(x;t))/dt ]
where the "score" or "likelihood ratio" (the derivative of the log likelihood) also requires a derivative.
Since Stan has automatic differentiation built in, can I access those to implement one of these methods in Stan without hand-coding derivatives into my Stan code? Is there an elegant way to express this? Any pointers to examples?
Thanks in advance for any help you can provide.
Gary