Rolling Beta Estimates
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
Rolling Beta Estimates
Hi,
I have to estimate Betas for 1200 companies over 20 years. I know how to estimate rolling beta estimates for a single stock but can I estimate the rolling beta coefficients for all the 1200 stocks in Eviews. I earlier used the below code to estimate rolling betas for individual stocks.
!window = 60
!step = 1
!length = @obsrange
equation eq1
!nrolls = @round((!length-!window)/!step)
matrix(6,!nrolls) coefmat
!j=0
for !i = 1 to !length-!window+1-!step step !step
!j=!j+1
smpl @first+!i-1 @first+!i+!window-2
eq1.arch(1,1,options) sr269 c mrp
colplace(coefmat,eq1.@coefs,!j)
next
show coefmat
I have to estimate Betas for 1200 companies over 20 years. I know how to estimate rolling beta estimates for a single stock but can I estimate the rolling beta coefficients for all the 1200 stocks in Eviews. I earlier used the below code to estimate rolling betas for individual stocks.
!window = 60
!step = 1
!length = @obsrange
equation eq1
!nrolls = @round((!length-!window)/!step)
matrix(6,!nrolls) coefmat
!j=0
for !i = 1 to !length-!window+1-!step step !step
!j=!j+1
smpl @first+!i-1 @first+!i+!window-2
eq1.arch(1,1,options) sr269 c mrp
colplace(coefmat,eq1.@coefs,!j)
next
show coefmat
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Rolling Beta Estimates
Put your code inside a for loop that loops through the 1200
Re: Rolling Beta Estimates
Thanks. for the reply. I am new to Eviews programming and don't know how to use the for loops. Can you please help me with a demo?
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Rolling Beta Estimates
Sure, here's an example of a for loop:
You might also want to read through the programming guide:
http://forums.eviews.com/viewtopic.php?f=5&t=1638
Code: Select all
for !i = 1 to !length-!window+1-!step step !step
!j=!j+1
smpl @first+!i-1 @first+!i+!window-2
eq1.arch(1,1,options) sr269 c mrp
colplace(coefmat,eq1.@coefs,!j)
next
You might also want to read through the programming guide:
http://forums.eviews.com/viewtopic.php?f=5&t=1638
Re: Rolling Beta Estimates
I tried the following but is only giving me the coefficient estimates for the first company.
for !i=1 to 1200 //declaring the series i=1 to 1200, I have named stock returns as SR1 to SR1200
!window = 36
!step = 1
!length = @obsrange
equation eq1 //
!nrolls = @round((!length-!window)/!step)
matrix(2,!nrolls) coefmat
!j=0
for !i = 1 to !length-!window+1-!step step !step
!j=!j+1
smpl @first+!i-1 @first+!i+!window-2
equation eq1.ls(options) sr1 c mrp //Problem with this
colplace(coefmat,eq1.@coefs,!j) //should I be using equation eq1 or eq(!1)
next
show coefmat
next
I am stuck with this code. Please help me out with this.
for !i=1 to 1200 //declaring the series i=1 to 1200, I have named stock returns as SR1 to SR1200
!window = 36
!step = 1
!length = @obsrange
equation eq1 //
!nrolls = @round((!length-!window)/!step)
matrix(2,!nrolls) coefmat
!j=0
for !i = 1 to !length-!window+1-!step step !step
!j=!j+1
smpl @first+!i-1 @first+!i+!window-2
equation eq1.ls(options) sr1 c mrp //Problem with this
colplace(coefmat,eq1.@coefs,!j) //should I be using equation eq1 or eq(!1)
next
show coefmat
next
I am stuck with this code. Please help me out with this.
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Rolling Beta Estimates
One obvious problem is that you're using !i for two different things.
Also in your equation you probably want Sr!i (or whatever your looping variable is), not sr1
Also in your equation you probably want Sr!i (or whatever your looping variable is), not sr1
Re: Rolling Beta Estimates
I have tried the following code but it is still not working. I have attached a test file with stock returns of 3 stocks and the market risk premium. Can you please help me with making the required corrections to the code?
for !i=1 to 3
!window = 36
!step = 1
!length = @obsrange
equation eq1
!nrolls = @round((!length-!window)/!step)
matrix(2,!nrolls) coefmat
!j=0
for !j = 1 to !length-!window+1-!step step !step
!j=!j+1
smpl @first+!j-1 @first+!j+!window-2
equation eq1.ls(options) sr!i c mrp
colplace(coefmat,eq1.@coefs,!j)
next
show coefmat
next
for !i=1 to 3
!window = 36
!step = 1
!length = @obsrange
equation eq1
!nrolls = @round((!length-!window)/!step)
matrix(2,!nrolls) coefmat
!j=0
for !j = 1 to !length-!window+1-!step step !step
!j=!j+1
smpl @first+!j-1 @first+!j+!window-2
equation eq1.ls(options) sr!i c mrp
colplace(coefmat,eq1.@coefs,!j)
next
show coefmat
next
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Rolling Beta Estimates
You're storing the estimates into the same place each time, writing over themselves.
Try this:
Try this:
Code: Select all
for !i=1 to 3
!window = 36
!step = 1
!length = @obsrange
equation eq1
!nrolls = @round((!length-!window)/!step)
matrix(2,!nrolls) coefmat!i
!j=0
for !j = 1 to !length-!window+1-!step step !step
!j=!j+1
smpl @first+!j-1 @first+!j+!window-2
equation eq1.ls(options) sr!i c mrp
colplace(coefmat!i,eq1.@coefs,!j)
next
next
Re: Rolling Beta Estimates
When I estimate the rolling regression using this code, it only estimates the coefficient at one roll and gives zero values for estimates of the coefficients at the second roll and so on over the different windows for the period. Please help me with the solution to the issue. Also can you please guide me on how to copy/view all the coefficients for the different stocks in one window?
for !i=1 to 3
!window = 36
!step = 1
!length = @obsrange
equation eq1
!nrolls = @round((!length-!window)/!step)
matrix(2,!nrolls) coefmat!i
!j=0
for !j = 1 to !length-!window+1-!step step !step
!j=!j+1
smpl @first+!j-1 @first+!j+!window-2
equation eq1.ls(options) sr!i c mrp
colplace(coefmat!i,eq1.@coefs,!j)
next
next
for !i=1 to 3
!window = 36
!step = 1
!length = @obsrange
equation eq1
!nrolls = @round((!length-!window)/!step)
matrix(2,!nrolls) coefmat!i
!j=0
for !j = 1 to !length-!window+1-!step step !step
!j=!j+1
smpl @first+!j-1 @first+!j+!window-2
equation eq1.ls(options) sr!i c mrp
colplace(coefmat!i,eq1.@coefs,!j)
next
next
Re: Rolling Beta Estimates
Dear Gareth,
Thanks for your valuable help. I have corrected the model as below and now it is estimating coefficients as required. I need your help with one more thing and that is how can I retrieve estimated coefficients for all the stocks in one group view or can directly store them into one output file such as excel?
for !i=1 to 3
!window = 36
!step = 1
!length = @obsrange
equation eq1
!nrolls = @round((!length-!window)/!step)
matrix(2,!nrolls) coefmat!i
!j=0
for !j = 1 to !length-!window+1-!step step !step
smpl @first+!j-1 @first+!j+!window-2
equation eq1.ls(options) sr!i c mrp
colplace(coefmat!i,eq1.@coefs,!j)
next
next
Thanks for your valuable help. I have corrected the model as below and now it is estimating coefficients as required. I need your help with one more thing and that is how can I retrieve estimated coefficients for all the stocks in one group view or can directly store them into one output file such as excel?
for !i=1 to 3
!window = 36
!step = 1
!length = @obsrange
equation eq1
!nrolls = @round((!length-!window)/!step)
matrix(2,!nrolls) coefmat!i
!j=0
for !j = 1 to !length-!window+1-!step step !step
smpl @first+!j-1 @first+!j+!window-2
equation eq1.ls(options) sr!i c mrp
colplace(coefmat!i,eq1.@coefs,!j)
next
next
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Rolling Beta Estimates
You'll have to create a big master matrix then insert each individual matrix into the big one (in whatever way you want). You can use matplace to place the individual ones inside the master.
Re: Rolling Beta Estimates
Thanks Gareth. Can you please share the code structure for the Master Matrix as my skills are quite limited in creating such a matrix?
-
EViews Gareth
- Fe ddaethom, fe welon, fe amcangyfrifon
- Posts: 13604
- Joined: Tue Sep 16, 2008 5:38 pm
Re: Rolling Beta Estimates
Same idea as when you're building up the coefmats.
Declare it outside the loop (right at the top of your program):
where rows, columns are the size of the master matrix (determined by the number of coefficients, number of rolls and number of series).
The exact shape of the matrix, and exactly where you put each coefficient matrix inside it is up to you.
Declare it outside the loop (right at the top of your program):
Code: Select all
matrix(rows,columns) mastermat
The exact shape of the matrix, and exactly where you put each coefficient matrix inside it is up to you.
Re: Rolling Beta Estimates
Thanks Gareth. can you please help me do it for the following three stocks. do i have to do this for all the 1200 stocks individually or can I declare it in advance?
for !i=1 to 3
!window = 36
!step = 1
!length = @obsrange
equation eq1
!nrolls = @round((!length-!window)/!step)
matrix(6,!nrolls) mastermat
matrix(6,!nrolls) coefmat!i
!j=0
for !j = 1 to !length-!window+1-!step step !step
smpl @first+!j @first+!j+!window-1
equation eq1.ls(options) r!i c mrp(-2) mrp(-1) mrp mrp(1) mrp(2)
colplace(coefmat!i,eq1.@coefs,!j)
matplace(mastermat, coefmat1, 1,1)
matplace(mastermat, coefmat2, 7, 1)
matplace(mastermat, coefmat3, 13, 1)
next
next
for !i=1 to 3
!window = 36
!step = 1
!length = @obsrange
equation eq1
!nrolls = @round((!length-!window)/!step)
matrix(6,!nrolls) mastermat
matrix(6,!nrolls) coefmat!i
!j=0
for !j = 1 to !length-!window+1-!step step !step
smpl @first+!j @first+!j+!window-1
equation eq1.ls(options) r!i c mrp(-2) mrp(-1) mrp mrp(1) mrp(2)
colplace(coefmat!i,eq1.@coefs,!j)
matplace(mastermat, coefmat1, 1,1)
matplace(mastermat, coefmat2, 7, 1)
matplace(mastermat, coefmat3, 13, 1)
next
next
- Attachments
-
- rollregcorrectprog.prg
- (328 Bytes) Downloaded 352 times
-
- 3 stock sample.wf1
- (17.32 KiB) Downloaded 259 times
Who is online
Users browsing this forum: No registered users and 2 guests
