---
title: "Exercises for continuous time stochastic processes"
output: html_document
---

## Exercise 1:

Investigate via simulation the following statements (try with many realisations
and possibly time intervals of different lengths):

- Once a Wiener process is larger than 0 it never returns to negative values again.
- A Wiener process never passes below -10.
- A Wiener process crosses (the value) 0 an infinite number of times.

## Exercise 2:

Simulate the process given by the SDE $dX_t = (4 - X_t) dt + 0.5 dW_t$.

Does this process drift towards a specific value? If so, which?

## Exercise 3:

Simulate the process given by the SDE $dX_t = -3X_t dt+ X_tdW_t$ from $t_0 = 0$ to T=1 with initial value $X_0=10$. 
- What happens?
- Try to explain the behaviour.
- What happens if you set the end time to T=10?

## Exercise 4:

Simulate one realization of the process given by the SDE $dX_t = 0.5 dt + dW_t$
from $t_0 = 0$ to T = 10 with initial value $X_0=1$, and save the result as `sim` and
extract the time series data as `sim_ts`:
```{r}
## fsim <- expression(...)
## gsim <- expression(...)
## sim <- snssde1d(drift = ..., diffusion = ..., M = 1, t0 = 0, T = 10, x0 = 1)
## sim_ts <- sim$X
```

Now we will consider `sim_ts` as our data. Estimate the parameters of two competing models and compare their parameter estimates and AIC values:

- Model 1: $dX_t = \theta_1 dt + \theta_2 dW_t$.
- Model 2: $dX_t = (\theta_1 + \theta_2 X_t) dt + \theta_3X_t^\theta_4 dW_t$.

```{r}
## f1 <- expression(...)
## g1 <- expression(...)
## fit1 <- fitsde(sim_ts, drift = ..., diffusion = ..., start = list(theta1 = 0.5, theta2 = 1))
## coef(fit1)
## AIC(fit1)
## f2 <- expression(...)
## g2 <- expression(...)
## fit2 <- fitsde(sim_ts, drift = ..., diffusion = ..., start = list(theta1 = 0.5, theta2 = 0, theta3 = 1, theta4 = 0))
## coef(fit2)
## AIC(fit2)
```

Try to redo the procedure a few times: Simulate a new dataset, estimate the parameters of both models and look at the parameters and AIC values.
