Monte Carlo

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt

jimmy1899
Posts: 2
Joined: Mon Apr 12, 2010 1:16 pm

Monte Carlo

Postby jimmy1899 » Mon Apr 12, 2010 1:29 pm

Hello,

I have had a look at the Monte Carlo examples. I think I will store the simulation results into a matrix.

However I would have liked to learn how to program some kind of recursive algorithm with EViews.

What's a good way to program such a model : Y(t) = a*Y(t-1)+b+nrnd ?

Thanks for you help !
Jimmy

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13318
Joined: Tue Sep 16, 2008 5:38 pm

Re: Monte Carlo

Postby EViews Gareth » Mon Apr 12, 2010 1:40 pm

You'll need to seed Y_1 at some value, after that it is relatively simple:

Code: Select all

'seed Y_1
smpl @first @first
series y = nrnd

'calculate the rest of the values
smpl @first+1 @last
y = a*y(-1) + b + nrnd
Follow us on Twitter @IHSEViews

jimmy1899
Posts: 2
Joined: Mon Apr 12, 2010 1:16 pm

Re: Monte Carlo

Postby jimmy1899 » Mon Apr 12, 2010 3:00 pm

Thank you very much Gareth

"smpl @first @first" and "smpl @first+1 @last" are delimiters

To set the first element to 5, I could also have written

Code: Select all

smpl @first @first
series y = 5


This looks pretty easy indeed :mrgreen:

Thanks !

kzmh78
Posts: 15
Joined: Mon Nov 08, 2010 9:27 am

Re: Monte Carlo

Postby kzmh78 » Fri Mar 22, 2013 3:13 am

Hello,

When monte carlo program generate a sequence of random numbers,
almost of examples had used a Nornal disitrubution,mean is 0, and variance is 1(using command @rnorm or nrnd).

However, I want to use a nornal disitrubution,mean is 2, and variance is 3.

Does EViews have any commands?

startz
Non-normality and collinearity are NOT problems!
Posts: 3775
Joined: Wed Sep 17, 2008 2:25 pm

Re: Monte Carlo

Postby startz » Fri Mar 22, 2013 6:48 am

Code: Select all

2+sqr(3)*nrnd

mvilla29
Posts: 3
Joined: Thu Apr 11, 2013 12:45 pm

Re: Monte Carlo

Postby mvilla29 » Thu Apr 11, 2013 12:54 pm

Hi
I'm triyin to generate a random number serie, distribited logistic with mean 85.22 and Standard Deviation 18.44, with 260 observations but I don´t know how to do this. I want to to do a Montecarlo experiment with 10.000 iteration like this but I don't know how to do this. Can you help me, please?

Thks!

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13318
Joined: Tue Sep 16, 2008 5:38 pm

Re: Monte Carlo

Postby EViews Gareth » Thu Apr 11, 2013 1:07 pm

The @rlogistic function creates random variables from the logistic distribution.
Follow us on Twitter @IHSEViews

mvilla29
Posts: 3
Joined: Thu Apr 11, 2013 12:45 pm

Re: Monte Carlo

Postby mvilla29 » Thu Apr 11, 2013 1:50 pm

EViews Gareth wrote:The @rlogistic function creates random variables from the logistic distribution.


Ok, but, how can i asign a mean of 85.22 and a standard deviation of 18.4?

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13318
Joined: Tue Sep 16, 2008 5:38 pm

Re: Monte Carlo

Postby EViews Gareth » Thu Apr 11, 2013 2:12 pm

To generate a series with mean X and scale parameter Y, you would do:

Code: Select all

series z = x + y*@rlogistic
Follow us on Twitter @IHSEViews

mvilla29
Posts: 3
Joined: Thu Apr 11, 2013 12:45 pm

Re: Monte Carlo

Postby mvilla29 » Thu Apr 11, 2013 2:17 pm

Thank you Gareth!!

startz
Non-normality and collinearity are NOT problems!
Posts: 3775
Joined: Wed Sep 17, 2008 2:25 pm

Re: Monte Carlo

Postby startz » Thu Apr 11, 2013 2:56 pm

EViews Gareth wrote:To generate a series with mean X and scale parameter Y, you would do:

Code: Select all

series z = x + y*@rlogistic

Actually, not quite. The standard deviation of the logistic isn't 1.0. So the scale doesn't give you the standard deviation.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13318
Joined: Tue Sep 16, 2008 5:38 pm

Re: Monte Carlo

Postby EViews Gareth » Thu Apr 11, 2013 2:58 pm

I didn't say anything about std dev. :wink:
Follow us on Twitter @IHSEViews

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13318
Joined: Tue Sep 16, 2008 5:38 pm

Re: Monte Carlo

Postby EViews Gareth » Thu Apr 11, 2013 3:05 pm

A quick bit of Google-fu indicates that to get a mean of m and standard deviation of s, you'd do:

Code: Select all

series y = m + s*@sqrt(3/(16*@atan(1)^2))*@rlogistic
Follow us on Twitter @IHSEViews


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 53 guests