2

I have been struggling for a half hour to post my question but always getting the same error:

Your post appears to contain code that is not properly formatted as code. Please indent all code by 4 spaces using the code toolbar button or the CTRL+K keyboard shortcut. For more editing help, click the [?] toolbar icon.

I have done my best to put code blocks where appropriate but the error persists. Would really appreciate any help!

Full text of my question

I am a Mathematica novice. For an operations research application, I am trying to work with the following wealth process in Mathematica, $$ d W_t = (\rho W_t + P_t) dt\ , $$ where $P_t$ is a stream of payoffs that itself follows a geometric Brownian motion: $$ d P_t = \mu P_t dt + \sigma P_t dZ_t\ . $$ Unfortunately, I cannot represent this problem as a standard Ito process and thus take advantage of Mathematica's rich in-built features. Just as in that case, I would like to be able to perform simulations, compute expected values of functions of terminal wealth, etc.

Here is what I've tried so far to compute, for example, the expected value.

WealthEvolve := Simplify[
  DSolve[{
    W'[t] == (\[Rho] W[t] + P[t]),
    W[0] == w - k
    },
   W[t],
   t
   ]]

FinalWealth[t_] := W[t] /. WealthEvolve[[1]]

This gives the expected output

E^(t \[Rho]) (-k + w + 
   Inactive[Integrate][E^(-\[Rho] K[1]) P[K[1]], {K[1], 0, t}])

If I now go ahead and evaluate

Simplify[
 Activate[
  FinalWealth[t] /. 
   P -> Mean[GeometricBrownianMotionProcess[\[Mu], \[Sigma], p]]
  ]]

It does not evaluate, even though the expression looks correct.

E^(t \[Rho]) (-k + w + \!\(
\*SubsuperscriptBox[\(\[Integral]\), \(0\), \(t\)]\(\(
\*SuperscriptBox[\(E\), \(\(-\[Rho]\)\ K[1]\)]\ \(Mean[
        GeometricBrownianMotionProcess[\[Mu], \[Sigma], p]]\)[
       K[1]]\) \[DifferentialD]K[1]\)\))

Does anyone have any insight as to why?

I am also stuck when it comes to simulations. My intuition tells me that I for any $t$, I need to need to sample from LogNormalDistribution and then evaluate the following integral for that $t$, but I am not sure how to do this. I would be grateful for any insight!

5
  • 1
    I'm not sure why the site is giving you trouble, as your formatting looks fine here. Can you give it a try using code fences (see last paragraph) with triple backticks?
    – rm -rf Mod
    Apr 24 at 18:21
  • @rm-rf Thanks for your response. I tried with code fences (updated question text as above) to no avail. I even signed in in incognito mode in case it had something to do with my browser but that didn't help either.
    – Anthony
    Apr 25 at 7:19
  • I guess the only way for someone on the mod team to replicate this error is to try and post it themselves? It is strange that it posts on here no problem but not on the main site.
    – Anthony
    Apr 25 at 7:24
  • @Anthony, I suggest you post the question anyway, but remove parts of the question that seem problematic (try removing one paragraph after another until it works). I can then edit your question and fill in other text from here.
    – Domen
    Apr 25 at 7:30
  • @Domen the question is live at mathematica.stackexchange.com/q/284225/7984 Thanks for your help! Interestingly enough, even after taking all the code out, it returned the same error. I was only able to post the question when I took the math out as well. I wonder if that was the issue - that the algorithm was thinking that my math was code somehow?
    – Anthony
    Apr 25 at 9:47

0

You must log in to answer this question.

Browse other questions tagged .