Serving the Quantitative Finance Community

 
User avatar
arunseshadri
Topic Author
Posts: 0
Joined: August 6th, 2007, 11:24 pm

Matlab Code Help. for Random Number Generators and Histogram

October 15th, 2007, 12:55 am

Hi, I am new to Matlab and I am trying to generate a Random Numbers using Box Muller or something similar. I am able to generate the list of 1000, 1000 random numbers using rand (1000,100). I need to take the last element of each of these coloumns and then generate a list of these 1000 entries. Use the frequency of these 1000 numbers and then plot those frequency on a Histogram I was indeed successful in generating the random numbers but I am having difficulty with creating a list from these random numbers. Could someone please help. It would be nice if I can get some code that I can experiment with. I have looked at a few tutorials but I am still not there yet. Cheers
 
User avatar
arunseshadri
Topic Author
Posts: 0
Joined: August 6th, 2007, 11:24 pm

Matlab Code Help. for Random Number Generators and Histogram

October 15th, 2007, 3:07 am

I have the following code in Matlabx=rand(1000,100) % Generates Random number for 1000 x 100y=((1:1000)*10) % define the values that we want to extract from the matrix.lst=x(y) % This is the list of numbers at time T.Not sure how to create a Normal Graph of this range with Gaussian Distribution.also I am not sure if this is a normalized random number generator.
 
User avatar
james88
Posts: 0
Joined: September 24th, 2007, 7:02 am

Matlab Code Help. for Random Number Generators and Histogram

October 15th, 2007, 6:25 am

tryrd = rand(1000,1000);last_col = rd(:,end); % last columninterval = linspace(0, 1, 100); % get binshist(last_col, interval);QuoteOriginally posted by: arunseshadriHi, I am new to Matlab and I am trying to generate a Random Numbers using Box Muller or something similar. I am able to generate the list of 1000, 1000 random numbers using rand (1000,100). I need to take the last element of each of these coloumns and then generate a list of these 1000 entries. Use the frequency of these 1000 numbers and then plot those frequency on a Histogram I was indeed successful in generating the random numbers but I am having difficulty with creating a list from these random numbers. Could someone please help. It would be nice if I can get some code that I can experiment with. I have looked at a few tutorials but I am still not there yet. Cheers
Last edited by james88 on October 14th, 2007, 10:00 pm, edited 1 time in total.
 
User avatar
arunseshadri
Topic Author
Posts: 0
Joined: August 6th, 2007, 11:24 pm

Matlab Code Help. for Random Number Generators and Histogram

October 15th, 2007, 11:38 am

I have random numbers that I have generated using the rand function. Mean = 0 and Sigma is 1. I need to simulate around 100 steps for wiener process. I need around 1000 Paths to simulate. Once the distributions are created I need to distribute over the interval 0 and 1. I tried to create the rand numbers using: rand(1000,100) -- This generates 1000 x 100 numbers. I need to create
 
User avatar
TraderJoe
Posts: 1
Joined: February 1st, 2005, 11:21 pm

Matlab Code Help. for Random Number Generators and Histogram

December 30th, 2007, 2:11 am

The thing I like about Matlab, is it generates random numbers in so many ways ...Quotebeta - Beta random numbers binornd - Binomial random numbers chi2rnd - Chi-square random numbers copularnd - Copula random numbers evrnd - Extreme value random numbers exprnd - Exponential random numbers frnd - F random numbers gamrnd - Gamma random numbers geornd - Geometric random numbers gevrnd - Generalized extreme value random numbers gprnd - Generalized Pareto random numbers hygernd - Hypergeometric random numbers iwishrnd - Inverse Wishart random numbers johnsrnd - Johnson system random numbers lhsdesign - Latin hypercube sample lhsnorm - Latin hypercube sample from normal distribution lognrnd - Lognormal random numbers mhsample - Metropolis-Hastings sample mnrnd - Multinomial random numbers mvnrnd - Multivariate normal random numbers mvtrnd - Multivariate t random numbers nbinrnd - Negative binomial random numbers ncfrnd - Noncentral F random numbers nctrnd - Noncentral t random numbers ncx2rnd - Noncentral chi-square random numbers normrnd - Normal random numbers pearsrnd - Pearson system random numbers poissrnd - Poisson random numbers randg - Gamma random numbers random - Random numbers random (gmdistribution) - Random numbers from Gaussian mixture distribution random (piecewisedistribution) - Random numbers from piecewise distribution randsample - Random sample randtool - Interactive random number generation raylrnd - Rayleigh random numbers slicesample - Slice sampler trnd - Student's t random numbers unidrnd - Discrete uniform random numbers unifrnd - Continuous uniform random numbers wblrnd - Weibull random numbers wishrnd - Wishart random numbers
Last edited by TraderJoe on December 29th, 2007, 11:00 pm, edited 1 time in total.
 
User avatar
jnwickremasinghe
Posts: 0
Joined: November 28th, 2007, 4:42 pm

Matlab Code Help. for Random Number Generators and Histogram

February 8th, 2008, 9:16 pm

arunseshadri - make sure you use normrnd(), rather than rand(), if you're simulating a Wiener process! rand() gives you a uniform distribution, while you actually need a normal distribution. Run this code to see the difference:%uniform distuniform=rand(10000,1);hist(uniform,50)%normal dist:normal=normrnd(0,1,10000,1);hist(normal,50)
 
User avatar
jnwickremasinghe
Posts: 0
Joined: November 28th, 2007, 4:42 pm

Matlab Code Help. for Random Number Generators and Histogram

February 8th, 2008, 9:29 pm

Additonal question - can you explain why you need to do this?'I need to take the last element of each of these coloumns and then generate a list of these 1000 entries. Use the frequency of these 1000 numbers and then plot those frequency on a Histogram 'why the last element of each column? How do you plan on generating the list (conceptually)?
 
User avatar
arunseshadri
Topic Author
Posts: 0
Joined: August 6th, 2007, 11:24 pm

Matlab Code Help. for Random Number Generators and Histogram

February 21st, 2008, 3:10 am

I was looking at time t=1 which is the end point what numbers I am getting. So if I get the last coloumn I know what final values were and then based on those Values I can create a distribution and see if they follow the bell curve shape or are they very different. When you run the rand function I think you get a matrix of say 100,100 and then you look at the last coloumn on each row and create a list and this list will have all the values you need. I needed this for one of the simulation of Wiener process that I ended up doing slightly differently.
Last edited by arunseshadri on February 20th, 2008, 11:00 pm, edited 1 time in total.
 
User avatar
Firas1994
Posts: 0
Joined: October 29th, 2008, 1:12 am

Matlab Code Help. for Random Number Generators and Histogram

November 6th, 2008, 1:39 am

hi, please im new in matlab how can i use the command rand to generate a randomvariable thx
 
User avatar
gozzi84
Posts: 0
Joined: April 26th, 2008, 8:24 am

Matlab Code Help. for Random Number Generators and Histogram

November 6th, 2008, 6:59 am

I really don't know how to get -1, but probably this could help you:p=0.3; % probabilityNRepl=10; % number of random variables you want to generateU=rand(NRepl,1) % generate random number from a uniform distribution on the unit interval.X=(U<p) % generate a series of logical 0 or 1
Last edited by gozzi84 on November 5th, 2008, 11:00 pm, edited 1 time in total.
 
User avatar
Firas1994
Posts: 0
Joined: October 29th, 2008, 1:12 am

Matlab Code Help. for Random Number Generators and Histogram

November 6th, 2008, 9:09 am

thx but how can i have -1
 
User avatar
msperlin
Posts: 5
Joined: July 10th, 2006, 6:21 pm

Matlab Code Help. for Random Number Generators and Histogram

November 6th, 2008, 9:13 am

double post
Last edited by msperlin on November 5th, 2008, 11:00 pm, edited 1 time in total.
 
User avatar
bostonquant
Posts: 0
Joined: March 26th, 2006, 7:46 pm

Matlab Code Help. for Random Number Generators and Histogram

November 6th, 2008, 9:19 am

Last edited by bostonquant on November 5th, 2008, 11:00 pm, edited 1 time in total.
 
User avatar
bostonquant
Posts: 0
Joined: March 26th, 2006, 7:46 pm

Matlab Code Help. for Random Number Generators and Histogram

November 6th, 2008, 9:20 am

QuoteOriginally posted by: Firas1994hi, please im new in matlab how can i use the command rand to generate a randomvariable thxSimulate a bernoulli and then shift it.
 
User avatar
Firas1994
Posts: 0
Joined: October 29th, 2008, 1:12 am

Matlab Code Help. for Random Number Generators and Histogram

November 6th, 2008, 10:25 am

thx but how can i shift it