 EdisonCruise
Topic Author
Posts: 117
Joined: September 15th, 2012, 4:22 am

### How to solve this ODE?

The following ODE is obtained from the Ornstein-Uhlenbeck process. I read it from the paper Optimal Mean Reversion Trading with Transaction Costs and Stop-Loss Exit.
$$\frac{\sigma^2}{2} \frac{d^2u(x)}{dx^2}+\mu(\theta-x) \frac{du(x)}{dx}=ru(x)$$
The paper does not provide the boundary conditions and I cannot find a clear explaination in its references. However, the paper just provides its solution
$$F(x)=\int_{0}^{\infty} u^{\frac{r}{\mu}-1}e^{\sqrt{\frac{2 \mu}{\sigma^2}}(x-\theta)u-\frac{u^2}{2}}du$$
$$G(x)=\int_{0}^{\infty} u^{\frac{r}{\mu}-1}e^{\sqrt{\frac{2 \mu}{\sigma^2}}(\theta-x)u-\frac{u^2}{2}}du$$

For this ODE, I have two questions:
(1) What are the boundary conditions to get the above two integration equations?
(2) the above two integrations are improper integraions. I have tryied to used the Matlab integral function to calculate them numerically, but for some parameters matlab raises the max interval warning. Is there routine/code can calculate these integration accurately?

Thank you. Alan
Posts: 10323
Joined: December 19th, 2001, 4:01 am
Location: California
Contact:

### Re: How to solve this ODE?

(1) Looking at the paper, esp. (3.5), pretty sure  F and G should be ODE solutions that (along with their derivatives) vanish at $-\infty$ and $+\infty$ respectively. (See Borodin & Salminen Handbook, pg 19). For $\mu > 0$ they clearly vanish appropriately. Below I check that they are ODE solutions. General theory says any solns with these properties, up to multiplicative constants, are unique.
(2) Not a Matlab user -- but, as long as $r/\mu > 0$, shouldn't be a problem. Suggest you practice with $\int_0^1 u^{a-1} \, du$ until you can do that one correctly numerically, for arbitrary small $a > 0$. Then, perhaps break up the ones you want into (0,1) and (1,infty).

Checking that (F,G) are ODE solutions. Write the ODE as $\mathcal{A} \, u(x) = 0$. Then, some algebra will show something like:

$\mathcal{A} \, F(x) = -\mu \int_0^{\infty} \frac{\partial}{\partial u} \left\{ u^{r/\mu} \, e^{\sqrt{\mu} \, x \, u - u^2/2} \right\} \, du = 0$, since $r/\mu > 0$, and

where I take $\theta=0$, $\sigma^2=2$ for simplicity.  I may have some typo's -- left to you to correct. Same idea works for G. Cuchulainn
Posts: 62913
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: How to solve this ODE?

I see what you are doing but I do not see what the rationale is or what the compelling reason is for (3.3) and (3.4) is. These are elegant 'closed' solutions to (3.1) but at the end of they must be solved numerically. No free lunch.

My first reactions
(1) Differential equations on $\mathbb{R}$ don't have boundary conditions but rather asymptotic values at $(-\infty, \infty)$. But in a computer some kind of domain truncation/transformation is needed and then some kind of 'approximate' boundary conditions. One example is $y = 1/(1 + e^{-x})$ that transforms (3.1) into

$\frac{1}{2}\sigma^2 y(1-y)\frac{\partial }{\partial y}(y(1-y)\frac{\partial u}{\partial y}) + ...$ on $(0,1)$  (A)

So you know have a degenerate DE and it reduces on ${0,1}$  to $ru = 0$. It can be made rigorous using Fichera theory.

(2) Those integrals look horrendous, numerically. My first reaction would be (instead) to solve  (A) using some kind of solver.

But maybe it is a hard requirement that the forms (3.3) and (3.4) are necessary for he rest of the paper..?
I would be interested in knowing the relative value of this alternative solution.

BTW The approach I sketched works very well for time-dependent problems, so it should work in the elliptic case as well.

//
Then we are back to the timeless question

https://forum.wilmott.com/viewtopic.php?f=19&t=23637
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl Alan
Posts: 10323
Joined: December 19th, 2001, 4:01 am
Location: California
Contact:

### Re: How to solve this ODE?

Not sure who 'you' is, but, as I said, the integrals should not be a problem. If you can integrate x^{a-1}, you can integrate these. EdisonCruise
Topic Author
Posts: 117
Joined: September 15th, 2012, 4:22 am

### Re: How to solve this ODE?

Thank you all for your suggestions. Following Alan’s suggestions to split the integration limits, I can do the integration by a change of variable method to go around the singularity point. However, I am still not sure on the below two questions:
(1)    Boundary conditions
It seems that as $x\rightarrow -\infty$, $F(x)\rightarrow 0$ (when x=-1e8), but as $x \rightarrow +\infty$, $F(x)\rightarrow+\infty$.
I have attached the figure for F(x) and G(x), with parameters $\sigma=0.5,\theta=0,\kappa=0.5,r=0.1$.  (2)    Variational inequalities
Actually I want to solve the variational inequalities by finite difference method below. It is equation (3.17) in the paper Optimal Mean Reversion Trading with Transaction Costs and Stop-Loss Exit.
$$min[rV(x)-\frac{\sigma^2}{2} \frac{d^2V(x)}{dx^2}-\mu(\theta-x) \frac{dV(x)}{dx}, V(x)-(x-c)]=0$$
Again, I am not sure what boundary conditions should be used.
I have tried to use the Projected SOR method to solve this equation, as in the examples given in the book Finite Difference Methods in Financial Engineering by Daniel J. Duffy. The boundary conditions I have tried:
(a)    Right boundary: $x-c$. Left boundary: vanishing the second derivative of V(x)
(b)    Vanishing the second derivative of V(x) on the left and right boundary.
But both do not work. The solution is sensitive to the initial guess and tend to converge to $x-c$.
Maybe my implementation of PSOR is not correct, but I hope to make sure my boundary conditions appropriate. Cuchulainn
Posts: 62913
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: How to solve this ODE?

Not sure who 'you' is, but, as I said, the integrals should not be a problem. If you can integrate x^{a-1}, you can integrate these.
'You' is Leung and Li.

My point is not so much the actual mechanical integration but the amount of effort it take to work out (3.3), (3.4) compared to my approach. Why do we take this approach? Maybe a Plan B does no harm.
It's an aside I suppose, but my question remains unanswered.
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl Cuchulainn
Posts: 62913
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: How to solve this ODE?

EdisonCruise,
I can't say much about $F(x)$ but if the problem is well-posed one would expect the solution to be zero at edges? Is the formula correct?

Some remarks on the other things:

1. PSOR should work (it could be slow) but a (necessary?) condition is that the fd matrix $A$ be positive definite. This property could be compromised due to causes.

2. Is $A$  positive definite? Is there convection-dominance?
3. I guess you do some kind of domain truncation and then BC are $\frac {\partial^2 u}{\partial x^2} = 0$?
4. Do the BCs in 3 compromise positive-definiteness?
5. As a sanity clause, you could try this optimisation using an algorithm other than PSOR (in Matlab, Python)? This is a standard example in Quadratic Programming.

6. Images not displayed correctly?
7. PSOR works for non-symmetric matrices but ideally diagonally dominant, the later being realised on page 129 of my FDM book.

I can offer some possible solutions, but let's first pinpoint the problem.
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl Alan
Posts: 10323
Joined: December 19th, 2001, 4:01 am
Location: California
Contact:

### Re: How to solve this ODE?

Thank you all for your suggestions. Following Alan’s suggestions to split the integration limits, I can do the integration by a change of variable method to go around the singularity point. However, I am still not sure on the below two questions:
(1)    Boundary conditions
It seems that as $x\rightarrow -\infty$, $F(x)\rightarrow 0$ (when x=-1e8), but as $x \rightarrow +\infty$, $F(x)\rightarrow+\infty$.
(2)    Variational inequalities
Actually I want to solve the variational inequalities by finite difference method below. It is equation (3.17) in the paper Optimal Mean Reversion Trading with Transaction Costs and Stop-Loss Exit.
$$min[rV(x)-\frac{\sigma^2}{2} \frac{d^2V(x)}{dx^2}-\mu(\theta-x) \frac{dV(x)}{dx}, V(x)-(x-c)]=0$$
Again, I am not sure what boundary conditions should be used.
(1) F(x) is behaving just like it's supposed to.

(2) The authors give you an explicit solution in their Th 4.2. Suggest you code it up. (4.2) shows the solution is proportional to F(x) for $x \le b^*$ and is continuous at $x = b^*$. You might want to investigate if it 'smooth pastes'. Maybe you don't need to know that for numerics -- I don't know. Personally, would just use the given solution.  Anyway, can you solve for the perpetual American put value numerically? This problem is analogous. What bc do you need for that? EdisonCruise
Topic Author
Posts: 117
Joined: September 15th, 2012, 4:22 am

### Re: How to solve this ODE?

Thank you so much for your suggestions. I think I can solve this ODE numerically with
(1) A psuedo time term is added to the equation as below:
$$min[rV(x)-\frac{\sigma^2}{2} \frac{d^2V(x)}{dx^2}-\mu(\theta-x) \frac{dV(x)}{dx}+\frac{dV(x)}{dt}, V(x)-(x-c)]=0$$
(2) boundary conditions: $\frac {\partial^2 u}{\partial x^2} = 0$ on both sides
(3) numerical schemes: 2nd order central difference for $x$ derivatives and a runge-kutta type explicit scheme for temporal integration. In each time step after integration, $x-c$ is compared with the value to get the minimum.

This method seems to converge with arbitrary initial conditions and  it takes about 2e4 time steps.
I have to get this numerical solution, because it will be used for more complicated problems. However,  I am still curious on two issues:
(1) Does the paper obtain the closed-form solution with  $\frac {\partial^2 u}{\partial x^2} = 0$  as the boudary conditions?
(2) It seems that adding a psuedo time can work for this problem and the same numerical scheme seems applicable to price American type option. This method seems to be simpler than the PSOR method, which needs  a sub-iteration in each time step, or other free boundary method. Is there any disvatange of this method compared with PSOR? Maybe it is too slow to converge in this case I think. Cuchulainn
Posts: 62913
Joined: July 16th, 2004, 7:38 am
Location: Amsterdam
Contact:

### Re: How to solve this ODE?

I was investigating this issue of fictitious time here

https://forum.wilmott.com/viewtopic.php?f=8&t=101205&start=90

Tue Mar 17, 2020 9:45 am

At the least, we need to prove asymptotic convergence. Friedman 1992 pde book discusses it in chapter 6.

RK4 is probably OK but maybe adaptive schemes for stiff ODEs might be more efficient ($dt = 10^{-4}$ is kind of big.)
Step over the gap, not into it. Watch the space between platform and train.
http://www.datasimfinancial.com
http://www.datasim.nl  