Modified cumprod using bsxfun?
4 views (last 30 days)
Show older comments
I am trying to generate Monte Carlo simulations whereby my sample paths are cumulative products. However, I want each iteration step to be allowed to be incremented/decremented only by multiples of a specified minimum value.
The simplest example I can think of to illustrate this is to simulate roulette betting from the casino's perspective. This is the fastest vectorized example I can think of if there was no restriction on the minimum increments:
% Inputs
initialCapital = 1e6;
betFraction = 0.0015;
numBets = 1000;
numSamplePaths = 1000;
winProbability = 37/38;
winAmount = 1;
loseAmount = 30;
% Simulation
spins = sign(rand(numBets, numSamplePaths) - 1 + winProbability);
profitFactor = spins;
profitFactor(spins>=0) = 1 + winAmount*betFraction*spins(spins>=0);
profitFactor(spins<0) = 1 + loseAmount*betFraction*spins(spins<0);
accumulatedCapital = cumprod(profitFactor) * initialCapital;
However, in a realistic situation, the bet sizes must be multiples of a fixed value, let's say it's $1 - so all of my elements in the accumulatedCapital array should be integers. Note that this is different from saying that:
accumulatedCapital = floor(cumprod(profitFactor) * initialCapital);
Of course, the easiest way is simply to use a loop twice over:
if spin(n) >= 0
accumulatedCapital(n) = ...
accumulatedCapital(n-1) + ...
winAmount*floor(betFraction(n)*accumulatedCapital(n-1))
elseif spin(n) < 0
accumulatedCapital(n) = ...
accumulatedCapital(n-1) - ...
loseAmount*floor(betFraction(n)*accumulatedCapital(n-1))
but this is much slower. Any of you can suggest some vectorized wizardry to solve this? Thanks!
0 Comments
Answers (0)
See Also
Categories
Find more on Linear Algebra 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!