# Tag Info

## Hot answers tagged stochastic-calculus

14

I'm not sure if I correctly understood what you want... However, I could read in the question that you want to simulate Ito Processes and, at the same time, to be able to change its parameters, especially the processes drifts and volatilities. In the comments I've read about the processes being correlated, so, let me try to put everything together in this ...

13

I think it can be quite instructive to see how to integrate a stochastic differential equation (SDE) yourself. Of course there are different ways of doing that (a nice introduction is given in this paper). I chose the Euler-Maruyama method as it is the simplest one and is sufficient for this simple problem. Note that this assumes your SDE to be in Ito-form, ...

13

You could use "PathComponents" property of TemporalData to split the vector-valued temporal data into the list of TemporalData objects and plot those: proc = ItoProcess[{{p[t], -p[t] - q[t]}, {{0}, {1}}}, {{q, p}, {0, 10}}, {t, 0}]; td = RandomFunction[proc, {0., 10., 0.02}, 10]; td["PathComponents"]

9

There are a couple of known bugs at play here. First, in TemporalData the date increment is given as a rational number but some of the underlying date functionality doesn't know how to handle this (e.g. DateList doesn't reliably cannonicalize date lists with fractional components). (*As of 9.0.1*) data = TemporalData[FinancialData["EUR/USD", {{2012, 5, 1}, {...

9

Second trial. The following seems to work. The only restriction so far is that it only works on the first path. I will be looking into that. ClearAll[x, fun1, fun2, ff, gg] μ = 1; σ = 0.3; fun1[x_, t_] := If[ If[x < 0.5, gg = False; If[ff, gg = True]; False, ff = True ] && ff || gg, -x, x ] fun2[x_, t_] := If[ ...

7

Although I have found ItoProcess an excellent tool in nearly all cases, in those situations where a correlation matrix is supplied to it ItoProcess incorrectly uses the Cholesky decomposition of the correlation matrix when it should actually be using the transpose of the Cholesky. Note that I discovered this bug back in December 2012 when I was looking at ...

7

You can set it up as a system of coupled equations : proc = ItoProcess[{\[DifferentialD]x[t] == y[t] \[DifferentialD]t, \[DifferentialD]y[t] == -(g/m y[t] + k/m x[t]) \[DifferentialD]t + Sqrt[2 kb bigT/(m^2 g)] \[DifferentialD]w[t]}, x[t], {{x, y}, {x0, y0}}, {t, 0}, w \[Distributed] ...

7

You can get the state values for every with data["States"], which you can then easily feed into a indicator function. data = RandomFunction[ GeometricBrownianMotionProcess[0.01, .15, 100], {0, 1, .01}, 100]; corridorIndicator[data_, upperBound_, lowerBound_] := Boole[Max@# < upperBound && Min@# > lowerBound] & /@ data corridorIndicator[...

6

The number of players is relatively short, so we can brute-force the problem. There are only 8! = 40,320 different arrangements of players and it is easy enough to generate them all and then filter them: longList = (Sort /@ Partition[#, 2]) & /@ Permutations[Range@8]; Union[longList, SameTest -> (Or @@ Flatten[Outer[Equal, #1, #2, 1]] &)] {{...

6

The first replacement is easy: F[t]*g[x]*F[k] /. u_*F[t_] F[x_] -> DiracDelta[t - x]*u (* DiracDelta[k - t] g[x] *) The second one is a bit more tricky because of the integral involved. In such a case I make all substitutions first, and integrate later: (f1[a] (1 + f2[b]) // Expand) /. f1[x_]*f2[y_] -> DiracDelta[x - y] (* DiracDelta[a - b] ...

5

I'm not an expert on stochastic differential equations but I found the documentation clear enough. Getting the output in terms of a function of your process variable x[t] is easy: SeedRandom[1]; With[{σ = 1, μ = 1, x0 = 100}, proc = ItoProcess[ \[DifferentialD]x[t]/x[t] == σ \[DifferentialD]w[t] + μ \[DifferentialD]t, Log10[x[t]], ...

5

NExpectation[ Max[(S12 + S1)/2 - 100, 0], {S1, S12} \[Distributed] SliceDistribution[ GeometricBrownianMotionProcess[r, sigma, S0], {1/2, 1}], Method -> "MonteCarlo"] or NExpectation[ Max[(S12 + S1)/2 - 100, 0], {S1, S12} \[Distributed] SliceDistribution[ GeometricBrownianMotionProcess[r, sigma, S0], {1/2, 1}], Method -> {"NIntegrate", {...

5

1) Using QueueingNetworkProcess to define such a queuing process With the customer arrival rate arrivalRate and the service rates at each server being serviceRate1, serviceRate2, and serviceRate3, respectively, you can define this queuing process by g = {arrivalRate, 0, 0}; m = {serviceRate1, serviceRate2, serviceRate3}; r = {{0, 1, 0}, {0, 0, 1}, {0, 0, ...

5

Since path is a TemporalData object, you can also make use of its various "Properties" SeedRandom[0] proc = ItoProcess[{\[DifferentialD]x[t] == v[t] \[DifferentialD]t, \[DifferentialD]v[t] == -x[t] ((x[t])^2 - 1) \[DifferentialD]t + Sqrt[2*0.01] \[DifferentialD]w[t]}, {x[t], v[t]}, {{x, v}, {0.9, 0.7}}, t, w \[Distributed] ...

4

Here is a faster way. I've only coded a portion of your problem to provide the flavor. Roll your own GBM GBMPathCompiled = Compile[{{S0, _Real}, {drift, _Real}, {diff, _Real}, {nSteps, _Integer}}, FoldList[(#1 drift Exp[ diff #2]) &, S0, RandomVariate[NormalDistribution[0, 1], nSteps]]]; Let's first visualize the situation Module[{S0 = ...

4

EDITED Alex, I believe this is what you want: StartingWealth = 100; PercentChange = 0.5; WinProbability = .5; NumberOfProcesses = 2; Time = 5; processes = RandomFunction[BinomialProcess[WinProbability], {0, Time}, NumberOfProcesses]; paths = Table[ FoldList[Times, StartingWealth, If[Differences[Last[Transpose[processes["Path", x]]]][[#]] == ...

4

Mathematica V10 introduced the following two functions: - HiddenMarkovProcess - FindHiddenMarkovStates Examples of their usage can be found here and here.

4

Another possibility with built-in functions: (* Define the process *) proc = ItoProcess[\[DifferentialD]s[t] == \[Mu] s[t] \[DifferentialD]t + \[Sigma] s[t] \[DifferentialD]w[t], s[t], {s, s0}, {t, 0}, w \[Distributed] WienerProcess[]] Now the process can be used as: Expectation[z, z \[Distributed] proc[t]] (* E^(t \[Mu]) s0 *) Simplify[Expectation[...

4

Sample CorrelationFunction is a biased estimator. It works better when applied to the whole ensemble of paths instead of calculating it pathwise and taking means. Also, for n=4 the sample is small. m = 10^3; proc1 = OrnsteinUhlenbeckProcess[0, 0.1, 2]; q = RandomFunction[proc1, {0, 10, 0.05}, m]; nc = Table[d1 = q["Path", jj]; CorrelationFunction[d1, ii], {...

4

Using the code as in the OP, slightly modified: proc[μ_, σ_] := ItoProcess[ \[DifferentialD]x[t] == μ \[DifferentialD]t + σ \[DifferentialD]w[t], x[t], {x, 0}, t, w \[Distributed] WienerProcess[] ] paths = RandomFunction[proc[0.5, 1], {0, 10, 0.01}, 100]; Then, we define the function f[x_, t_] = E^(-((-x + x0 + t μ)^2/(2 t σ^2)))/(Sqrt[2 ...

3

Not sure I got your process right and not a very elegant solution : setup the process, do the simulations first, then look at the outcome. First off define your constraints : const[x_, y_] := And[10^-8 <= y <= 10^-3, 0.9*(Uc) <= a1*x^2 - a3*x^4/4 <= 1.1*(Uc)] I am outputting {t, x[t], y[t], Boole[const[x[t], y[t]]]} which contains all the ...

3

Derivation of the Heston model from first principles using ItoProcess[ ] It's pleasantly surprising that something as subtle and useful as the Heston PDE can be easily derived via ItoProcess, once a few hurdles are overcome along the way. It's useful because, although the std Heston derivation is retold intuitively and in detail by Wilmott, by Shaw, by ...

3

Please confirm if this is what you were looking for proc = ItoProcess[{{p[t], -p[t] - q[t]}, {{0}, {1}}, {q[t], p[t]}}, {{q, p}, {0, 10}}, {t, 0}]; data = RandomFunction[proc, {0, 10, 0.02}, 10]; You could do Plot[Through@data["PathFunction", All][t], {t, 0, 10}, Evaluated -> True]

3

If I understand your question : proc = ItoProcess[ {\[DifferentialD]x[t] == y[t] \[DifferentialD]t, \[DifferentialD]y[t] == θ y[t] \[DifferentialD]t + σ \[DifferentialD]w[t]}, {x[t], y[t]}, {{x, y}, {x0, y0}}, {t, 0}, w \[Distributed] WienerProcess[]]; Which you can use as : Mean[proc[t]] (* {((-1 + E^(t θ)) y0 + x0 θ)/θ, E^(t θ) y0} *) ...

3

You need to extract data from path=RandomFunction using part. The following gives {x,v} list: pts = path[[2, 1, 1]] Now you can plot pts in the plane: ListPlot[pts, Frame -> True, FrameLabel -> {"x", "v"}]

2

Just a longer non-optimal alternative. This problem must have way cleaner solutions. I'll give it more thought in my sleep (or not) SetAttributes[{team, matchDay}, Orderless]; players = player /@ Range@8; There are only 7!!==105 possible match days you can build. One could build them up and then just find a combination in which every player plays only ...

2

Then, you must build the logic to handle the partial barriers. There are lots of ways to proceed. I modified the visualization to illustrate how indexing the sample times can be used to restrict the barrier penetration test and select those paths that survive the first barrier. Clear[PartialBarrierTest]; PartialBarrierTest[path_, iSt_, iFn_, U_, L_] := ...

2

Another way to visualize this is in the parametric phase space: ListLinePlot[td[[2, 1]], Frame -> True, AspectRatio -> 1, PlotRange -> All] ---------- Comment reponse ---------- We can check the structure of underlying expression with InputForm and then it is straightforward to use Part to extract the sub-expressions:

2

Change your process definition to: process = RandomFunction[Evaluate[win], {1, timstep}, samplepaths]; and you will avoid the first (zero) step. This is (I suspect) what Andy Ross was saying. The output of the above code (with the process defined as above) is the plot: which has all increasing values because the coefficient of the binomial is 0.99

2

ItoProcess function only construct an object to represent your SDE. This function will not take the partials and solve your SDE. For this reason, you should use ItoProcess whenever you want to simulate paths of a stochastic process. Let's take the example you provided above. Suppose I define xt = Log[St] and take the \[mu] and \[sigma] from the evolution ...

Only top voted, non community-wiki answers of a minimum length are eligible