Financial Econometrics, 2014
Computer Handout 5: Monte Carlo and scripts
Working with scripts
Today we shall cover working with scripts. Until last week we selected and executed commands from gretl’s graphical interface. First, this usually took a lot of work (clicking). Next, some things (like Monte
Carlo simulations) cannot be done this way. In Class 5 we shall write all the commands that we would like to be executed in a native gretl’s programming language and we shall put them into a single file, called script. Then the entire file may be run at a one go and – if you instruct gretl to do so – the outputs will be saved. While it may look complicated, this class will not require any programming skills. Once you understand what a given script does, you will (at most) have to change some values
(sample size, parameters) and next save and re-run the script. And then analyze the results using the same tools we used before.
Download: mcmc.inp, bivariateGaussian.inp, NewboldDavies.inp, HAC.inp, adf.inp, KPSS.inp, ScalingFactor.inp, apple.csv and PensionScheme.inp and save all the files to your desktop. Open gretl.
This script conducts our first Monte Carlo experiment from Lectures 3-4.
Run the `mcmc.inp’ script. How to run the script?
File -> Script files -> User file...
In the window on the right hand side select `Desktop'. Highlight the required script by clicking on it.
Alternatively: double-click the script on your desktop and it will open, along with another gretl instance. To run the script click on the `Run' icon (the one with two sprockets):
Look on the ols outputs, generated by gretl. What happens if you change the slope parameter from 2.0 to 0.5? What happens if you increase the sample size to 5000? We did not set the seed - if you run the experiment again, will you get the same results?
This script generates pseudo-random draws from bivariate Gaussian distribution with arbitrary variance-covariance matrix S. It implements the randomization algorithm presented in Lectures 3-4.
The script used the fact that Cholesky matrix is a matrix valued counterpart of a square root.
Run the script. Click `OK' to dismiss the window that asks you if you want to overwrite the data. Look at the summary, printed in the gretl output window. What happens with sample covariances as sample size increases?
For cov5 variable run:
Variable -> Estimated density plot (Gaussian kernel)
Repeat the same for cov5000 variable. How are the two distributions different? Why are they differrent? (Hint: What are the sample sizes in both cases?)
This script implements the Newbold-Davies experiment from Lectures 3-4. It estimates slope parameters (denoted as b’s), ols standard deviations (s’s) and the corresponding t-statistics (t’s) for cases A and B from the lecture.
Run the script. This script appends all the computed statistics to NewboldDavies.gdt file - that is what the following line does:
# store the results store NewboldDavies.gdt b_A b_B s_A s_B t_A t_B p_A p_B
As I am trying to make your life easy, I have also used the following command that immediately loads the results to the main gretl window:
# open results open NewboldDavies.gdt
So once you run the script, you will have all the results immediately accessible. But sometimes you will need to access results manually (this is what I will further understand by `opening results'). The way to do this is as follows. Select:
File -> Open data -> User file...
In the tab on the left hand side of the gretl window select your university folder, in the central part of the screen double-click on `Documents'.
Next double-click gretl.
In the next tab you will have an access to all the saved gretl output files, including NewboldDavies.gdt.
Now if you wanted to open this data set, simply click it and select `Open'. In example, on my laptop the gretl outputs are saved in:…