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.
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.