Page 1 of 1

Need help to translate a system into eviews

Posted: Sat Dec 27, 2008 6:48 am
by Peptoid
Hello,
I need help to translate a model (which will be used to perform stochastic simulation) into eviews. I have never used eviews before so I encounter some problems to translate the mathematical system into the eviews’ language. I did some research in the user manual but I haven’t been able to find some function (in particular the expectation function and sign function). I uploaded the system as pictures file because I don’t know how to use certain math symbols on the forum (maybe with the code function but it was easier to do some print screen).

Here they are:
Image
Image

I will be very thankfull if someone could devote some of his/her time to help me.

Re: Need help to translate a system into eviews

Posted: Sun Dec 28, 2008 6:18 am
by trubador
Your equations look like those of heterogenous agent models. There are lots of unknowns in your system of equations. However, since you want to conduct a simulation analysis instead of estimation, it may be possible to build your system in EViews. You should write a program and define the necessary steps in it. You do not need a special function for the expectation operator, since it only helps you get rid of disturbance term and simplifies your notation. Sign function can easily be defined in terms of if conditions. Before going any further, you should decide which parameters will be simulated and which ones will be exogenous. It will be helpful if you provide additional information on your model and variables in the system of equations...

Re: Need help to translate a system into eviews

Posted: Sun Dec 28, 2008 7:24 am
by Peptoid
First of all, thank you very much for your answer. I have uploaded a .htm file with more details on the model.

Here is the link: http://eviewsmodel.site.voila.fr/model.htm

I hope that is enough information. If needed, I can give more details.

Re: Need help to translate a system into eviews

Posted: Tue Dec 30, 2008 10:05 am
by trubador
Based on the information you provided I have written a program code below. You can find my explanations wherever needed in the code. Please note that the program is not fully efficient, yet it is effective. My intention was to express your system of equations in EViews' terms. It takes around 15 minutes to carry out 1000 repetitions for 14 variables with 100 observations per each. Of course the elapsed time depends on the hardware configuration you have. All in all, the code can be improved further with the help of moderators and/or other members of the forum. Although you can change parameters and/or inputs to suit your needs, please check the code carefully before using it.

Code: Select all

%name = "sim" 'assign a name to your workfile !n = 100 'number of observations !s = 1000 'number of repetitions for simulation wfcreate(wf={%name}) u !n 'creates a workfile according to specifications above tic 'reset the timer 'fixed parameters (calibration is needed here!) !psi = 0.8 'speed of adjustment !beta = 0.2 'degree of extrapolation !gamma = 0.1 'intensity of revision !mu = 0.5 'risk aversion !rf = 0.03 '??? some sort of discount rate I guess!! !r = 0.02 '??? some sort of discount rate I guess!! 'initial values of the variables smpl @first @first series st = 0 series sf = 0 series pf_a = 0 series pc_a = 0 series wf = 0.5 series wc = 0.5 for %i e p sig sign for %j f c series {%i}{%j} = 0 next next 'define matrices to store the simulation results matrix(!n,!s) sfm matrix(!n,!s) stm matrix(!n,!s) wfm matrix(!n,!s) wcm matrix(!n,!s) erf matrix(!n,!s) ert 'normally distributed errors with mean = 0, standard deviation = 1 nrnd(erf) 'for fundamental exchange rate nrnd(ert) 'for market exchange rate for !k = 1 to !s for !j = 1 to !n-1 smpl @first+!j @first+!j 'adjust the sample in order to calculate the equations by observation sf = sf(-1) + 0.1*erf(!j+1,!k) 'fundamental exchange rate st = st(-1) + wf(-1)*ef(-1) + wc(-1)*ec(-1) + 0.1*ert(!j+1,!k) 'market exchange rate ef = -!psi*(st-sf) 'forecasting rule for fundamentalists ec = !beta*(st-st(-1)) 'forecasting rule for chartists 'profit rules for fundamentalists and chartists for %i f c sign{%i} = ((1+!rf)*(st(-1)+e{%i})-(1+!r)*st(-1)) if sign{%i}(!j+1) >0 then p{%i} = (st*(1+!rf) - st(-1)*(1+!r)) else if sign{%i}(!j+1) = 0 then p{%i} = 0 else p{%i} = -(st*(1+!rf) - st(-1)*(1+!r)) endif endif sig{%i} = (e{%i}(-1)-st)^2 'measure of risk for fundamentalists and chartists (I believe something is missing here! A lag structure might be needed, please check it!) p{%i}_a = p{%i} - !mu*sig{%i} 'adjusted profit rules next 'population fractions for %i f c w{%i} = exp(!gamma*p{%i}_a)/(exp(!gamma*pf_a) + exp(!gamma*pc_a)) next next smpl @all 'convert series to be simulated into a column vector stom(sf,sfv{!k}) stom(st,stv{!k}) stom(wf,wfv{!k}) stom(wc,wcv{!k}) 'place each vector into its result matrix colplace(sfm,sfv{!k},!k) colplace(stm,stv{!k},!k) colplace(wfm,wfv{!k},!k) colplace(wcm,wcv{!k},!k) 'delete vectors in order to save space delete sfv{!k} stv{!k} wfv{!k} wcv{!k} next scalar elapsed = @toc/60 'see the elapsed time in minutes

Re: Need help to translate a system into eviews

Posted: Wed Dec 31, 2008 2:58 am
by Peptoid
I am very grateful for the time you took to help me. I performed a simulation with the default parameters and it seems to be what I need.

However, I encounter a problem when I try to perform a simulation with a value for gamma (intensity of revision) superior (or equal) to 1. Here is the error message:
Image
Do you have any idea how to solve this ?

I also have questions about the specification of one variable.
In equation (3.7), the risk is specified as follow:
Image

And in your code, it specified as:

Code: Select all

sig{%i} = (e{%i}-st)^2 'measure of risk for fundamentalists and chartists (I believe something is missing here! A lag structure might be needed, please check it!)
And you mention that a lag structure might be needed. So I was wondering, would it be correct to specify this equation in eviews as follow:

Code: Select all

sig{%i} = (e{%i}(-1)-st)^2 'measure of risk for fundamentalists and chartists
Actually, Image represent the expectation of agent i realized in time t-1 about the exchange rate in t. Is it possible to translate such a thing in eviews ?


Again, thank you very much for your help.

Re: Need help to translate a system into eviews

Posted: Wed Dec 31, 2008 4:37 am
by trubador
You can rewrite the equation for risk variable exactly the way you did. In order to save space, I did not write it here again. Rather, I edited it in my previous post. With the lag structure I meant a specification up to certain lags. More specifically, the risk variable may be calculated as the sum of squares of the last 5 or 10 errors. But that is just an idea and does not matter if the original model does not say so.

I see that you ran the program with gamma = 5, and so did I. However, I did not encounter any problems and was able to compute all variables successfully. Division by zero means that the denominator is equal to zero, which seems possible only with very large negative values of adjusted profit rule. I do not have any idea what may have caused the problem. Please run it again and let me know if the problem continues...

Re: Need help to translate a system into eviews

Posted: Wed Dec 31, 2008 5:45 am
by Peptoid
I ran other tests and the problem seems to appear when I use a large number of observations. In my previous simulation I used 10000 observations (with 1000 repetitions) and it displayed the error message but when I use 100 observations (like you did), it doesn't. I ran other simulations and for more than 200 observations (still with 1000 repetitions), it displays the error message.
Is it possible to solve this or do I have to stick with "only" 200 observations ?

Re: Need help to translate a system into eviews

Posted: Wed Dec 31, 2008 6:25 am
by trubador
Again, I did the same exercises and have not received any error messages. Since the code works well with a small data set, the problem may be caused by hardware or software capabilities. When you use 10,000 observations with 1,000 repetitions, each simulated variable will be stored into a matrix that ultimately have 10 million observations. This may create a technical problem. You may ask for help from our moderators.

Regarding your simulation exercise; I do not think that you have to work with 10,000 observations, which more or less equal to 40 years of daily exchange rate data. You do not need that amount of data to reduce the error variance. You can create the same effect with increasing the number of repetitions. Anyway, you can limit the size of your data to 1,000 or even less observation per variable and try to increase the number of repetitions if you like. Of course, we should first figure out what the problem is...

Re: Need help to translate a system into eviews

Posted: Wed Dec 31, 2008 6:47 am
by Peptoid
Ok, I will try to do more testing to figure out what the problem is. Anyway, I want to thank you again for all your help. You really helped me and I am very grateful.

Re: Need help to translate a system into eviews

Posted: Wed Dec 31, 2008 9:55 am
by Peptoid
I ran other simulations and when I use your default parameters (except 5 for gamma), there is no error message. But when I use different value for psi and beta, there is the error message.

Here is what I used:

Code: Select all

%name = "sim" 'assign a name to your workfile !n = 1000 'number of observations !s = 1000 'number of repetitions for simulation wfcreate(wf={%name}) u !n 'creates a workfile according to specifications above tic 'reset the timer 'fixed parameters (calibration is needed here!) !psi = 0.2 'speed of adjustment !beta = 0.9 'degree of extrapolation !gamma = 5 'intensity of revision !mu = 1 'risk aversion !rf = 0.03 '??? some sort of discount rate I guess!! !r = 0.02 '??? some sort of discount rate I guess!!
I think the problem is related to the value of beta because when I try to perform a simulation with a value for beta greater than 0.8, the error message appears. And the greater the value, the sooner it appears.

Can you tell me if you have also the error message by using these values ? Thank you.

Re: Need help to translate a system into eviews

Posted: Thu Jan 01, 2009 3:21 am
by trubador
The problem seems to arise from "division by zero" indeed. Parameters in your model are highly interconnected and therefore lots of feedbacks exist in your equations. At some point, some parameters (e.g. pf_a, the adjusted profit rule) take very large negative values and lead @exp function to become so small that the computer's mathematical system cannot differentiate its value from zero. In this case, value of wf (the population fractions) ultimately converges to 0/0 and generates the error. Hence, you should gather more information on the domain of your fixed parameters or you can find a feasible parameter space with trial and error. I believe reducing the number of observations (and increase the number of repetitions to offset it) you work with will also help you minimize the occurance of this problem, since it will prevent the values from diverging.