i have a problem with my code and i dont know how solve this?

1 view (last 30 days)
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
vachelard
vachelard on 5 Apr 2014
yes of courses it is writing an error. but even with this i do not get good results
Image Analyst
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.

Sign in to comment.

Accepted Answer

vachelard
vachelard on 5 Apr 2014
here are the two files my code and my data. I'm sorry, I try to explain the best ... but really thank you for your help In my code the variable a b c d are just to check if my yields often exceed 0.15 because it does not require the ideal is that they are between -0.07 and 0.07 about most of the time

More Answers (2)

Walter Roberson
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
  2 Comments
vachelard
vachelard on 5 Apr 2014
I want the average of the line is equal to the value of my reference matrix. but if it works for the sum I can calculate for the average.
vachelard
vachelard on 5 Apr 2014
My goal if possible is that the numbers in my random matrices does not greatly exceed the maximum and minimum my target matrix

Sign in to comment.


Image Analyst
Image Analyst on 5 Apr 2014
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
vachelard on 6 Apr 2014
my goal is to create 3 sizes of random matrices: one with dimensions 193 by 5, where the numbers generated inside are between -0.15 and 0.15. Another one with dimensions 193 by 10, where the numbers generated are also between -0.15 and 0.15. And a third one that is 193 by 15, where the numbers generated are between -0.15 and 0.15. The constraint of these 3 matrixes is that the average, row by row, should be equal to the value of the corresponding row of the first column of the matrix that I called Rhedgefund (which is in the file named data_groupe(noname).) example: if I take the 193x10 matrix, I want the average of line i to be equal to the value of the first column of row i in the matrix Rhedgefund. Thank you
vachelard
vachelard on 6 Apr 2014
if I normalize my yields certainly they will not be totally random but I can distribute it to the desired range or not?

Sign in to comment.

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!