Parameter estimation for Stochastic differential equation I have a process $X(t)$ defined on some finite time horizon $[0,T]$ and I know that my process satisfies the following SDE: 
$dX(t)=X_t \mu dt + X_t \sigma dB_t$.
where $B$ is a standard Brownian motion. In particular I'm assuming that both the drift and volatility are constant over time.
Question:
Given data points $x_{t_1}, \ldots x_{t_n}$ that are realizations of the random variable $X(t)$ at times $t_1 \ldots t_n$, how do I estimate the drift and volatility parameters $\mu, \sigma$ ? I'm interested in a method that is relatively easy to implement. 
I would also like to know if there already exist libraries in say Python that might help for this task. 
What would be a method for estimating $\mu$ and $\sigma$ if they change over time? (I.e. they are are time dependent) 
 A: For geometric Brownian motion we have (by solving the SDE)
$$\log X_{t_i}=\log X_{t_{i-1}}+\tilde\mu(t_i-t_{i-1})+\sigma(B_{t_i}-B_{t_{i-1}}),\quad i=1,..,n$$
where $\tilde\mu=\mu-\frac{\sigma^2}{2}$.
Hence the conditional distribution of $X_{t_i}$ given $X_{t_{i-1}}$ is log-normal with mean equal to $\log X_{t_{i-1}}+\tilde\mu(t_i-t_{i-1})$ and variance $\sigma^2 (t_i-t_{i-1})$.
Suppose that $X_0=x_0$ is fixed (the calculations are very similar if $X_0$ is itself lognormal, just add another term), the log of the joint density of the vector $(X_{t_1},...,X_{t_n})$ at $x_1,...,x_n$ takes the following form:
$$\log p(x_1,...,x_n)=-\sum_{i=1}^n\log x_i-\frac{n}{2}\log 2\pi\sigma^2-\frac{1}{2}\sum_{i=1}^n\log\Delta t_i-\frac{1}{2}\sum_{i=1}^n\frac{(\log x_i-\log x_{i-1}-\tilde\mu\Delta t_i)^2}{\sigma^2\Delta t_i},$$
where we introduced $\Delta t_i=t_i-t_{i-1}$.
Differentiating this wrt. $\mu$, we obtain
$$\partial_{\tilde\mu}\log p=\frac{1}{\sigma^2}\Big(\log x_n-\log x_0-\tilde\mu(t_n-t_0)\Big)=0\quad\Longrightarrow\quad\tilde\mu=\frac{\log x_n-\log x_0}{t_n-t_0},$$
and by using this, we can also solve the other equation:
$$\partial_{\sigma^2}\log p=\frac{1}{2\sigma^2}\Big(\frac{1}{\sigma^2}\sum_{i=1}^n\frac{(\log x_i-\log x_{i-1}-\tilde\mu\Delta t_i)^2}{\Delta t_i}-n\Big)=0$$
$$\quad\Longrightarrow\quad\sigma^2=\frac{1}{n}\sum_{i=1}^n\frac{(\log x_i-\log x_{i-1}-\tilde\mu\Delta t_i)^2}{\Delta t_i}.$$
A: I'm not so familiar with this formulation of the problem, but a common practice in engineering is the method based on Allan Variance. You basically assume the high frequency noise to be the volatility while the low frequency is the drift and identify btoh from the slopes on the chart..
As for the case when they are not constant it would be necessary to make some assumptions on how they vary over time. Either by giving them specific time functions with parameters to be estimated or possibly assuming that they are themselves performing soem kind of random (possibly Brownian) motion, in which case some technique like an Extended Kalman Filter or a Particle Filter could be envisaged. 
