# SuanShu, a Java numerical and statistical library

com.numericalmethod.suanshu.model.dai2011

## Class Dai2011HMM

• ### Nested Class Summary

Nested Classes
Modifier and Type Class and Description
static class  Dai2011HMM.CalibrationParam
static class  Dai2011HMM.ModelParam
• ### Constructor Summary

Constructors
Constructor and Description
Dai2011HMM(Dai2011HMM.ModelParam model)
Dai2011HMM(Dai2011HMM that)
Copy constructor.
Dai2011HMM(double mu1, double mu2, double lambda1, double lambda2, double sigma)
Constructs a two-state Markov switching Geometric Brownian Motion.
• ### Method Summary

All Methods
Modifier and Type Method and Description
HMMRNG getHMM()
Dai2011HMM getReciprocal()
Gets the reciprocal state switching GBM.
double lambda1()
Gets the transition intensity from bull market to bear market.
double lambda2()
Gets the transition intensity from bear market to bull market.
double mu1()
Gets the drift in the bull market.
double mu2()
Gets the drift in the bear market.
double nextP(double pt, double St, double St1)
Gets the evolution of pt, the conditional probability of being in an uptrend given all information, i.e., $$p_t = P(\alpha_t = 1 | \mathcal{F}_t)$$.
double nextX(double xt, double St, double newSt)
Gets the evolution of xt, logit of the conditional probability from (0, 1) onto $$(-\infty, +\infty)$$, i.e., $$x_t = \log{\frac{p_t}{1-p_t}}$$.
double sigma()
Gets the diffusion volatility.
String toString()
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
• ### Constructor Detail

• #### Dai2011HMM

public Dai2011HMM(double mu1,
double mu2,
double lambda1,
double lambda2,
double sigma)
Constructs a two-state Markov switching Geometric Brownian Motion. $$\frac{dS_t}{S_t} = \mu_i dt + \sigma dW_t,~i = 0, 1.$$
Parameters:
mu1 - bull market return
mu2 - bear market return
lambda1 - bull-to-bear intensity
lambda2 - bear-to-bull intensity
sigma - the volatility, assume to be constant
• #### Dai2011HMM

public Dai2011HMM(Dai2011HMM.ModelParam model)
• #### Dai2011HMM

public Dai2011HMM(Dai2011HMM that)
Copy constructor.
Parameters:
that - a two-state Markov switching GBM instance
• ### Method Detail

• #### lambda1

public double lambda1()
Gets the transition intensity from bull market to bear market.
Returns:
the bull to bear transition intensity
• #### lambda2

public double lambda2()
Gets the transition intensity from bear market to bull market.
Returns:
the bear to bull transition intensity
• #### mu1

public double mu1()
Gets the drift in the bull market.
Returns:
the drift in the bull market
• #### mu2

public double mu2()
Gets the drift in the bear market.
Returns:
the drift in the bear market
• #### sigma

public double sigma()
Gets the diffusion volatility.
Returns:
the volatility
• #### getReciprocal

public Dai2011HMM getReciprocal()
Gets the reciprocal state switching GBM. $$S_t d\frac{1}{S_t} = (\sigma^2 -\mu_i) dt - \sigma dW_t,~i = 1, 2.$$ Note that the indices 0 and 1 are switched.
Returns:
the reciprocal GBM
"eq. 15"
• #### nextP

public double nextP(double pt,
double St,
double St1)
Gets the evolution of pt, the conditional probability of being in an uptrend given all information, i.e., $$p_t = P(\alpha_t = 1 | \mathcal{F}_t)$$.

See (eq.13) in "Optimal Trend Following Trading Rules", M. Dai, 2011. The evolution of $$p_t$$ is $dp_t = g(p_t) dt + \frac{(\mu_1-\mu_2)p_t(1-p_t)}{\sigma^2} d\log{S_t},$ where $g(p_t) = -\lambda_1 p_t + \lambda_2 (1-p_t) - \frac{(\mu_1-\mu_2)p_t(1-p_t)((\mu_1-\mu_2)p_t+\mu_2-\sigma^2/2)}{\sigma^2}.$
In discrete form, it becomes $p_{t+1} = \min{\left(1,\max{\left(0, p_t + g(p_t)dt + \frac{(\mu_1-\mu_2)p_t(1-p_t)}{\sigma^2}\log{S_{t+1}/S_t}\right)}\right)}.$

Parameters:
pt - the previous conditional probability
St - the previous stock price
St1 - the latest stock price
Returns:
the evolved conditional probability
"eqs. 13, 14"
• #### nextX

public double nextX(double xt,
double St,
double newSt)
Gets the evolution of xt, logit of the conditional probability from (0, 1) onto $$(-\infty, +\infty)$$, i.e., $$x_t = \log{\frac{p_t}{1-p_t}}$$.

The evolution of $$x_t$$ can be derived as $dx_t = -(\frac{\mu_1-\mu_2}{\sigma^2} (\mu_1-\frac{\sigma^2}{2}) + \lambda_1 - \lambda_2) dt -(\lambda_1 e^{x_t} - \lambda_2 e^{-x_t} + \frac{(\mu_1-\mu_2)^2}{\sigma^2} \frac{1}{1+e^{x_t}}) dt + \frac{\mu_1-\mu_2}{\sigma^2} d\log{S_t}.$

Parameters:
xt - the previous value
St - the previous stock price
newSt - the latest stock price
Returns:
the evolved value
• #### getHMM

public HMMRNG getHMM()
• #### toString

public String toString()
Overrides:
toString in class Object