Martingales in both discrete and continuous setting I am wondering, polynomials like
$S_n^4-6n S_n^2+3n^2+2n$ for $$S_n=\sum_{i=1}^n{X_i}$$ where $$\mathbb{P}(X_i=1)=\mathbb{P}(X_i=-1)=\frac{1}{2}$$ is a martingale (under the conventional filtration). While $$B_t^4-6t B_t^2+3t^2$$ for Brownian motion $B_t$ is also a martingale. 
Note the difference between the two, and the similarity!
What's the general conclusion about the polynomials of $S_n$ and $n$, also about $B_t$ and $t$, to make them into martingales?
Thanks.
 A: One knows that $P(S_n,n)$ is a martingale if and only if $P(s+1,n+1)+P(s-1,n+1)=2P(s,n)$ and
that $Q(B_t,t)$ is a martingale if and only if $2\partial_tQ(x,t)+\partial^2_{xx}Q(x,t)=0$.
Assume that $P(S_n,n)$ is a martingale and, for a given $d$ and for every $h>0$, let 
$$
Q_h(x,t)=h^{d}P(x/\sqrt{h},t/h),
$$ 
in the sense that one evaluates $P(s,n)$ at the integer parts $s$ and $n$ of $x/\sqrt{h}$ and $t/h$. 
If $Q_h\to Q$ when $h\to0$, writing $\partial_t$ and $\partial^2_{xx}$ as limits of finite differences of orders $1$ and $2$, one sees that $2\partial_tQ+\partial^2_{xx}Q=0$, hence $Q(B_t,t)$ is a martingale.
Example: $P(s,n)=s^2-n$. For $d=1$, $Q_h(x,t)=x^2-t$ hence $Q(x,t)=x^2-t$.
Other example:
$P(s,n)=s^4-6ns^2+3n^2+2n$. For $d=2$, $Q_h(x,t)=x^4-6tx^2+3t^2+2ht$ hence $Q(x,t)=x^4-6tx^2+3t^2$.
In the other direction, to deduce a martingale in $S_n$ and $n$ from a martingale in $B_t$ and $t$, one should probably replace each monomial by a sum of its first derivative. This means something like replacing $q(t)=3t^2$ by $\displaystyle\sum_{k=1}^n(\partial_tq)(k)=3n^2+3n$ but I did not look into the details.

Edit (Thanks to The Bridge for a comment on the part of this answer above this line) 
Recall that a natural way to build in one strike a full family of martingales that are polynomial functions of $(B_t,t)$ is to consider so-called exponential martingales. For every parameter $u$,
$$
M^u_t=\exp(uB_t-u^2t/2)
$$ 
is a martingale hence every "coefficient" of its expansion as a series of multiples of $u^i$ for nonnegative integers $i$ is also a martingale. This yields the well known fact that 
$$1,\ B_t,\ B^2_t-t,\ B^3_t-3tB_t,\ B^4_t-6tB_t^2+3t^2,
$$
etc., are all martingales. One recognizes the sequence of Hermite polynomials $H_n(B_t,t)$, a fact which is not very surprising since these polynomials may be defined precisely through the expansion of $\exp(ux-u^2t/2)$. 
So far, so good. But what could be an analogue of this for standard random walks? The exponential martingale becomes 
$$
D^u_n=\exp(uS_n-(\ln\cosh(u))n)
$$
and the rest is simultaneously straightforward (in theory) and somewhat messy (in practice): one should expand $\ln\cosh(u)$ along increasing powers of $u$ (warning, here comes the family of Bernoulli numbers), then deduce from this the expansion of $D^u_n$ along increasing powers of $u$, and finally collect the resulting sequence of martingales polynomial in $(S_n,n)$.
Let us see what happens in practice. Keeping only two terms in the expansion of $\ln\cosh(u)$ yields $\ln\cosh(u)=\frac12u^2-\frac1{12}u^4+O(u^6)$ hence 
$$
\exp(-(\ln\cosh(u))n)=1-\frac12u^2n+\frac1{24}u^4(2n+3n^2)+O(u^6).
$$
Multiplying this by
$$
\exp(uS_n)=1+uS_n+\frac12u^2S_n^2+\frac16u^3S_n^3+\frac1{24}u^4S_n^4+\frac1{120}u^5S_n^5+O(u^6),
$$
and looking for the coefficients of the terms $u^i$ in this expansion yields the martingales 
$$
1,\ S_n,\ S_n^2-n,\ S_n^3-3nS_n,
$$
and
$$
S_n^4-6nS_n^2+2n+3n^2,\
S_n^5-10nS_n^3+5(2n+3n^2)S_n.
$$
Thus, in $M_t^u$, $B_t$ scales like $1/u$ and $t$ like $1/u^2$ hence Hermite polynomials are homogeneous when one replaces $t$ by $B_t^2$. The analogues of Hermite polynomials for $(S_n,n)$, from degree $4$ on, are not homogeneous in the sense of this dimensional analysis where $n$ is like $S_n^2$. Ultimately, this is simply because in $D_n^u$ one has to compensate $uS_n$ by $(\ln\cosh(u))n$, which is not homogeneous in $u^2n$.
Note that this argument of non homogeneity carries through to continuous time processes. For instance, the exponential martingales for the standard Poisson process $(N_t)_t$ are
$$
\exp(uN_t-(\mathrm{e}^u-1)t),
$$
and the rest of the argument is valid once one has noted that $\mathrm{e}^u-1$ is not a power of $u$.
