i have a problem with my code and i dont know how solve this?
Show older comments
I have a matrix of monthly returns I call Ynet (193.1) I'd like to build a matrix yields random I call randomR with an average yield of my one line is equal to the value of the row Ynet has.
Ynet example, if (1,1) = 0.23 I need the average randomR (1, :) is equal to 0.23.
Until then I got there, the problem comes from my values of my matrix randomR I need them to be between [-0.25, 0.25] gold mine that is not always the case. Over the size of my matrix randomR must be between 1 and 30 depending on the number of returns I want.
That is where I am:
simulation = -0.2 +0.4 * rand (193.5).;
rowsum = mean (simulation 2);
simulation bsxfun = (@ rdivide, simulation, rowsum);
for i = 1:5
randomR (:, i) = simulation (:, i) * Ynet,.
end
thank you
3 Comments
Walter Roberson
on 5 Apr 2014
The parameter to rand() is the array size to generate, not a floating point number.
vachelard
on 5 Apr 2014
Image Analyst
on 5 Apr 2014
I've read your post 6 times and I can't understand it. Like what does this mean: "I call Ynet (193.1)" What is 193.1? That can't be part of the variable name. We don't know how many more writing errors there might be, so it's best to attach your m-file with the paper clip icon, after you've put in a comment before each line about what that line is supposed to do.
Accepted Answer
More Answers (2)
Walter Roberson
on 5 Apr 2014
mean(simulation, 2)
does not calculate a row sum. You would use sum(simulation, 2) for a row sum
Image Analyst
on 5 Apr 2014
0 votes
Like I said, I can't figure out what you want. You say " I need them (randomR) to be between [-0.25, 0.25] gold mine that is not always the case. Over the size of my matrix randomR must be between 1 and 30". So which is it ? Do you need randomR values to be between -.25 and +.25, OR between 1 and 30?
6 Comments
vachelard
on 5 Apr 2014
Image Analyst
on 6 Apr 2014
Why would it be either 1 or 30 columns wide? The simulation array is 8 columns wide, not 1 or 30, and you're looping over columns of simulation. randomR does not exist yet - you're creating it in the loop - so if course it will have 8 columns, not 1 or 30.
vachelard
on 6 Apr 2014
Image Analyst
on 6 Apr 2014
Sorry, I don't understand that. Does anyone else understand what was said?
vachelard
on 6 Apr 2014
vachelard
on 6 Apr 2014
Categories
Find more on Creating and Concatenating Matrices 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!