1
$\begingroup$

Apologies if this is not the appropriate place to post this - this my very first contribution to Quantitative Finance Stack Exchange. I was hoping someone could help me with the following issue. I am using yuima to model a 3-dimensional diffusion process:

model <- setModel(drift = c("((-1)/(2-x1))-1/2","0","0"),                    
                  diffusion = matrix(c("1","0","0","0","1","0","0","0","1"), 3, 3),
                  solve.variable = c("x1","x2","x3"))

and then to simulate it and plot it:

sampling <- setSampling(Initial = 0, Terminal = 10, n = 1000)
yuima <- setYuima(model = model, sampling = sampling)
simulation <- simulate(yuima,xinit = 1)
plot(simulation)

which seems to work. However: this generates a plot of each time-series x1, x2, and x3 over time when in reality what I am really trying to visualise is how the three-dimensional path (with polar coordinates x1, x2, and x3) would look like.

Unless there is a version of plot3D or similar in yuima (I have googled it with no luck), what would really help me would be if there was a way of converting the (three) time-series simulation into a matrix or a list, in which case I am pretty sure I would be able to get the desired plot.

Any help will be much appreaciated. All the best.

Edit: the answer I've selected solved my issue, but for future reference these are the contents of simulate:

    > print(str(simulate))
Formal class 'standardGeneric' [package "methods"] with 8 slots
  ..@ .Data     :function (object, nsim = 1, seed = NULL, xinit, true.parameter, space.discretized = FALSE, increment.W = NULL, increment.L = NULL, 
    method = "euler", hurst, methodfGn = "WoodChan", sampling = sampling, subsampling = subsampling, ...)  
  ..@ generic   : chr "simulate"
  .. ..- attr(*, "package")= chr "yuima"
  ..@ package   : chr "yuima"
  ..@ group     : list()
  ..@ valueClass: chr(0) 
  ..@ signature : chr [1:13] "object" "nsim" "seed" "xinit" ...
  ..@ default   : NULL
  ..@ skeleton  : language (function (object, nsim = 1, seed = NULL, xinit, true.parameter, space.discretized = FALSE, increment.W = NULL, i| __truncated__ ...
NULL
$\endgroup$
5
  • $\begingroup$ Hi: You should show the contents of simulate by doing print(str(simulate)). hopefully it's not too big. given that, myself or someone else can show you how to make a matrix or a data.frame out of x,y and z. $\endgroup$
    – mark leeds
    May 13 at 3:25
  • $\begingroup$ Hi Mark, I've edited the question as you suggested just in case it helps anyone in the future! $\endgroup$
    – jmg
    May 14 at 0:47
  • $\begingroup$ Thanks JMG. Unfortunately, I don't use S4 much so I'm not clear on how one would know from the str output that the component was zoo.data and a list with those 3 components. that Pleb accessed. Maybe another step is then required and Pleb can possibly comment on that for future readers. $\endgroup$
    – mark leeds
    May 14 at 13:45
  • $\begingroup$ @markleeds The simulation object is an S4 class containing attributes/fields/slots. In order to get the slots from the simulation object you write str(simulation). You will observe that simulation is a class called yuima.data and contains an attribute called data. Within this attribute, you can observe another attribute called zoo.data that contains a list of three time-series objects called "Series 1", "Series 2", "Series 3". I guessed this was the output data, since the only other data the class contained, was the original data. Also, you can access attributes via @. $\endgroup$
    – Pleb
    May 14 at 19:51
  • 1
    $\begingroup$ Thanks Pleb. It's much appreciated and useful. $\endgroup$
    – mark leeds
    May 16 at 1:34
0
$\begingroup$

You can recover the simulations from the Yuima simulation object via the field calls:

Ser1 <- simulation@data@zoo.data$"Series 1"
Ser2 <- simulation@data@zoo.data$"Series 2"
Ser3 <- simulation@data@zoo.data$"Series 3"

And then convert the above into a matrix using cbind:

Sims_to_matrix <- cbind(Ser1, Ser2, Ser3)

Now, you can use your favorite 3d plotting tool (eg. Plotly), to get what you desire. You could also construct your own fancy line-graphs using ggplot2. I hope this helps!

$\endgroup$
1
  • 1
    $\begingroup$ Thank you very much, that solves my problem! $\endgroup$
    – jmg
    May 14 at 0:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.