Unfortunately we don’t have a built-in autocorrelation function in Stan so you would have to write the code. My hunch is that this has probably come up before though, so you may be able to search for an example where someone has already efficiently coded it up in a Stan program. It’s something we should probably consider adding to the language though.
Do you need the result as part of the log density? If not, then it’s much more efficient to do these kinds of transforms in the generated quantities block.
We’ve been talking for a long time about adding the FFT code with derivatives to make it possible to do efficient autocorrelations, but we’re still hung up on how to represent imaginary numbers. If we only exposed an autorcorrelation function, that problem would go away.