How can i simulate equity prices with parfor?
8 views (last 30 days)
Show older comments
Hi everybody. Now I am learning parfor. Before I use parfor, I had a simulation of equity price with "gbm" and "simBySolution", which gave me what I want. however, when I changed my previous "for" loop to "parfor" loop, the simulation gives no output. Part of my codes are as follows.
parfor v = 1:8;
StoPrice = gbm(StoPriDrift/365,SSigma(v)/365,'StartState',100);
sstoprice = simBySolution(StoPrice,nPeriods-1,'DeltaTime',dt,'nTrials',1);
end
I got the StoPrice from the gbm process. However, I did not get anything from the simBySolution. I will appreciate if someone can help me with this. Thanks Best, Julie
0 Comments
Accepted Answer
Edric Ellis
on 13 Nov 2017
To get output from a parfor loop, you need to write to an output variable in either a "sliced" or "reduction" manner. For a "sliced" variable, this essentially means each iteration of the parfor loop writes to an element of the output array indexed by the loop variable. So, you might be able to do the following:
parfor v = 1:8;
StoPrice = gbm(StoPriDrift/365,SSigma(v)/365,'StartState',100);
sstoprice{v} = simBySolution(StoPrice,nPeriods-1,'DeltaTime',dt,'nTrials',1);
end
After this loop, sstoprice will be a cell array with a single entry per iteration of the loop. (You can use any type of array for the output - it doesn't have to be a cell - I picked that simply because I have no idea with the size of the output of simBySolution is going to be...)
0 Comments
More Answers (0)
See Also
Categories
Find more on Parallel for-Loops (parfor) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!