# FxPaul

Math in finance or vice versa

## Stochastic process

As Wikipedia suggests, a stochastic process is a random process, the counterpart to a deterministic process. For our simple tasks all we need is a time series, i.e. for each moment of time we have only one random value, or price: $P(t)$. The process has a definite starting point $P(0)$ but its further evolution has some degree of uncertainty described by probability distribution.

A lot of types of stochastic processes has been studied in mathematical literature. In this article I use only Itō processes as they provide quite good approximation of price dynamics.

Itō process

An Itō process is a stochastic process which can be expressed as the sum of an integral with respect to Brownian motion and an integral with respect to time: $X_t=X_0 + \int_0^t\mu_s\,ds +\int_0^t\sigma_s\,dB_s.$
or written as a full differential: $dX_t = \mu_t\,dt + \sigma_t\,dB_t$
where $\mu_t=\mu(x,t)$ is a drift component and $\sigma_t=\sigma(x,t)$ is a diffusion component of the process.

The simplest model of price evolution is – so called – Geometric Brownian motion (GBM). This process is represented by: $dX_t = \mu_t X_t\,dt + \sigma_t X_t\,dB_t$

The good point of GBM is that $X_t$ is a log-normally distributed random variable and hence provides a “good enough” approximation of asset price evolution.

## Strategy definition

Let’s define trading strategy as a set of rules that give a recommended position size for each price evolution. Thus we can denote a strategy function as $S(X_t, t).$ We use purely technical approach, so no fundamental data like news, economical indicator etc.

Let’s construct optimization target for given strategy. There are few possible targets to optimize but our primary goals are PnL (profit and loss) and equity curve.
PnL function is built quite easily as a sum of all position changes multiplied by price, i.e. in continuous case it is with assumption of zero position before and after trades: $M(\tau) = - \int_0^{\tau} {X_t\,dS_t} = - \int_0^{\tau} {X_t S_t'\,dt}$
This integral could be re-written as stochastic differential equation: $dM_t = -X_t\,dS_t$
Assuming that the strategy cannot look into future, $S_t$ could be represented as an integral kernel: $S_t = \int_{-\infty}^{X_t} {s(X_{\tau})\,dX_{\tau}}$
or $dS_t = s(X_t)\,dX_t$
Therefore, PnL function is: $dM_t = - s(X_t) X_t\,dX_t$

As curve fitting is evil and we don’t want to stuck with strategy working only during optimization period, we should target for optimization expected value and variance of PnL function. This requires an estimation of either price probability distribution or equivalently price drift/diffusion. This is another ultimate task itself. It will be covered sometimes later.

For now let’s assume that we’ve got such estimation and knowns are probability distribution, $\mu,\,\sigma.$ Therefore, expected PnL could be defined by means of path integrals. In order to calculate the value one should add up, or integrate, over all possible paths of price histories in between the initial and final states of the strategy: $E[M] = \sum_{all\,paths} P[path] M(path)$
where $P[path]$ is a probability of given path.

Generally speaking, it is a path integral in quantum mechanics. Monte Carlo methods could give good approximation of path integral. This is the topic for further articles.