I've diagnosed the problem with the function, though I'm not sure what is the proper way to fix it. Here is the breakdown:
The Expected utility matrix riskyExpReward has incompatible dimentions with the loop. This happens only in the case of high sigma, because the dimentions of the matrix are independent of the sigma, while stepsOut variable depends on it:
Then, when the values are filled inside a for loop, stepsOut is used:
for (j in (lowerCalcLim+1):upperCalcLim){riskyExpReward[k,j]=sum(pmax(riskyExpReward[k+1,(j-stepsOut):(j+stepsOut)],safeReturns)*f)*dy}
In case of a sample set of parameters, where:
n = 21numY = 60000sigma = 10
During the loop, when:
j = 44001
(j+stepsOut) = 600001, which is 1 more than the number of rows of riskyExpReward.
Let me know how would you fix it. From my basic understanding, I'd think that if stepsOut is dependent on sigma, so should be the output matrix. Otherwise, there can always be a case where the dimentions won't line up.
I've diagnosed the problem with the function, though I'm not sure what is the proper way to fix it. Here is the breakdown:
The Expected utility matrix
riskyExpReward
has incompatible dimentions with the loop. This happens only in the case of high sigma, because the dimentions of the matrix are independent of the sigma, whilestepsOut
variable depends on it:riskyExpReward <- matrix(rep(0,n*numY),ncol = numY)
stepsOut <- ceiling(8*sigma/dy)
Then, when the values are filled inside a for loop,
stepsOut
is used:for (j in (lowerCalcLim+1):upperCalcLim){
riskyExpReward[k,j]=sum(pmax(riskyExpReward[k+1,(j-stepsOut):(j+stepsOut)],safeReturns)*f)*dy
}
In case of a sample set of parameters, where:
n = 21
numY = 60000
sigma = 10
During the loop, when:
j = 44001
(j+stepsOut) = 600001, which is 1 more than the number of rows ofriskyExpReward
.Let me know how would you fix it. From my basic understanding, I'd think that if
stepsOut
is dependent onsigma
, so should be the output matrix. Otherwise, there can always be a case where the dimentions won't line up.