On Feb 25, 2011, at 1:52 PM, JORGE ESPINOSA wrote:

>>  i've already solved many examples and they look very well. 

I'm glad to hear it.



> I have to solve a nonlinear black scholes equation (the nonlinearity is in 
> the 
> convection term)
> 
> My equation in tex is:
> 
> \frac{\partial V}{\partial t}+rs\frac{\partial V}{\partial s}
> +\frac{1}{2}\sigma^2a^2\frac{\partial^2 V}{\partial s^2}[1+exp{r(T-
> t)}a^2s^2\frac{\partial^2 V}{\partial s^2}]-rV=0
> 
> With other notation:
> 
> V_t+rsV_{s}+\frac{1}{2}\sigma^2a^2V_{ss}[1+exp{r(T-t)}a^2s^2V_{ss}]-rV=0
> 
> a, \sigma are constants.
> 
> with the same final condition that the linear Black Scholes equation.
> 
> ¿Do you think that this equation is solvable with Fipy? 

Yes, although the current release may not do a good job of it, particularly 
respecting boundary conditions.

You can *always* write everything out explicitly

TransientTerm() 
+ r * s * V.getGrad() 
+ ((sigma**2 * a**2 / 2.) * V.getFaceGrad().getDivergence() * (1. + exp(r * (T 
- t)) * a**2 * s**2 + V.getFaceGrad().getDivergence())
- r * V == 0

however this will have poor numerical performance and FiPy will not do the 
right thing with your boundary conditions.


I don't have time to work through it in detail, but remember that as much as 
possible you want to arrange terms into implicit forms like

\frac{\partial}{\partial s} [D \frac{\partial V}{\partial s}]
which is a DiffustionTerm

\frac{\partial}{\partial s} [u V]
which is a ConvectionTerm

and 

sV
which is a ImplicitSourceTerm



You can get a term like rsV_{s} by doing the chain rule on 

\frac{\partial}{\partial s}[r s V]

and subtracting off the parts you don't want, i.e.,

rs \frac{\partial V}{\partial s} = \frac{\partial}{\partial s}[r s V] - rV

or 

ConvectionTerm(coeff=rs) - ImplicitSourceTerm(coeff=r)



\frac{1}{2}\sigma^2a^2\frac{\partial^2 V}{\partial s^2}

is easy because \sigma and a are constants, so you can rewrite this as

\frac{\partial}{\partial s}[\frac{1}{2}\sigma^2a^2 \frac{\partial V}{\partial 
s}]

which is a 

DiffusionTerm(coeff=sigma**2 * a**2 / 2.)




\frac{1}{2}\sigma^2a^2\frac{\partial^2 V}{\partial 
s^2}exp{r(T-t)}a^2s^2\frac{\partial^2 V}{\partial s^2}

is trickier because FiPy doesn't have anything like (\frac{\partial^2 
V}{\partial s^2})^2 in it, but I'd be inclined to run the chain rule on 

\frac{\partial}{\partial 
s}[\frac{1}{2}\sigma^2a^4s^2\exp{r(T-t)}\frac{\partial^2 V}{\partial s^2} 
\frac{\partial V}{\partial s}]

and see what you had left over.

That term can be written as 

DiffusionTerm(coeff=sigma**2 * a**4 * s**2 * exp(r*(T - t)) * 
V.getFaceGrad().getDivergence())

the remainder are hopefully going to be some combination of ConvectionTerm and 
ImplicitSourceTerm, perhaps with explicit forms of higher-order derivatives. 
That's not ideal, but probably the best you can do.


The problem with V.getFaceGrad().getDivergence() is that it won't see any of 
your boundary conditions.



In the development trunk/ of FiPy, which we will hopefully be releasing soon, 
I'd be inclined to cast this as two equations

\frac{\partial V}{\partial t}+rs\frac{\partial V}{\partial 
s}+\frac{1}{2}\sigma^2a^2\Lambda[1+exp{r(T-t)}a^2s^2\Lambda]-rV=0

and

\Lambda = \frac{\partial^2 V}{\partial s^2}

and to solve them in coupled form. This would then be

eq1 = (TransientTerm(var=V) 
+ ConvectionTerm(coeff=r*s, var=V) 
+ ImplicitSourceTerm(coeff=sigma**2 * a**2 * (1 - exp(r * (T - t)) * a**2 * 
s**2 * Lambda), var=Lambda)
- ImplicitSourceTerm(coeff=2*r, var=V) == 0)

eq2 = (ImplicitSourceTerm(var=Lambda) == DiffusionTerm(var=V))

coupled_eq = eq1 & eq2

coupled_eq.solve(...)


We also have a new model for boundary conditions that will be seen by 
V.getFaceGrad().getDivergence(), but I still think the coupled form is going to 
be clearer and have fewer "weird" terms.


Daniel Wheeler and I are off to two different conferences next week, so I don't 
know how much further we'll be able to offer until after that.

Reply via email to