#===============================================================================
# Generate the transition density of a stochastic perturbed Lotka-Volterra
# preditor-prey model, with state-dependent volatility:
# dX = (1.5X-0.4*X*Y)dt +sqrt(0.05*X)dWt
# dY = (-1.5Y+0.4*X*Y-0.2*Y^2)dt +sqrt(0.10*Y)dBt
#-------------------------------------------------------------------------------
# Remove any existing coefficients
GQD.remove()
# Define the X dimesnion coefficients
a10 = function(t){1.5}
a11 = function(t){-0.4}
c10 = function(t){0.05}
# Define the Y dimension coefficients
b01 = function(t){-1.5}
b11 = function(t){0.4}
b02 = function(t){-0.2}
f01 = function(t){0.1}
# Approximate the transition density
res = BiGQD.density(5,5,seq(3,8,length=25),seq(2,6,length=25),0,10,1/100)
#------------------------------------------------------------------------------
# Visuallize the density
#------------------------------------------------------------------------------
par(ask=FALSE)
# Load simulated trajectory of the joint expectation:
data(SDEsim3)
attach(SDEsim3)
# We will simulate some trajectories (crudely) as well:
N=1000; delt= 1/100 # 1000 trajectories
X1=rep(5,N) # Initial values for each trajectory
X2=rep(5,N)
for(i in 1:1001)
{
# Applly Euler-Murayama scheme to the LV-model
X1=pmax(X1+(a10(d)*X1+a11(d)*X1*X2)*delt+sqrt(c10(d)*X1)*rnorm(N,sd=sqrt(delt)),0)
X2=pmax(X2+(b01(d)*X2+b11(d)*X1*X2+b02(d)*X2^2)*delt+sqrt(f01(d)*X2)*rnorm(N,sd=sqrt(delt)),0)
# Now illustrate the density:
filled.contour(res$Xt,res$Yt,res$density[,,i],
main=paste0('Transition Density \n (t = ',res$time[i],')'),
color.palette=colorRampPalette(c('white','green','blue','red'))
,xlab='Prey',ylab='Preditor',plot.axes=
{
# Add simulated trajectories
points(X2~X1,pch=20,col='grey47',cex=0.01)
# Add trajectory of simulated expectation
lines(my~mx,col='grey57')
# Show the predicted expectation from BiGQD.density()
points(res$cumulants[5,i]~res$cumulants[1,i],bg='white',pch=21,cex=1.5)
axis(1);axis(2);
# Add a legend
legend('topright',lty=c('solid',NA,NA),col=c('grey57','grey47','black'),
pch=c(NA,20,21),legend=c('Simulated Expectation','Simulated Trajectories'
,'Predicted Expectation'))
})
}
#===============================================================================
Run the code above in your browser using DataLab