Dear everyone,
im trying to calculate Value at risk 10 day ahead. i have a series of 3000 daily observation from which i have to create a new series by summing 10 daily returns non overlapping, so from 1 to 10, from 11 to 20 and so on. i dont know how to write it in eviews. the problem is that after calculating it the first time(putting the results in a vector for example) i have to move the series of the daily return by 1 and recalculate the series of the 10day return again and so on for all observations. Could anyone help me with a program file?
Thanx everyone
Value at risk with 10 day subsamples
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
Re: Value at risk with 10 day subsamples
There are many ways to do what you want. Below is just one of them:
You can now work with the series ysum in a newly created page tendays without changing the original page.
Code: Select all
series ysum
!step = 10
!last = @dtoo(y.@last)
for !i=1 to !last step !step
smpl @first+!i-1 @first+!i+!step-2
ysum = @sum(y)
next
smpl @all
pagecopy(page=tendays)
pagecontract if ysum<>ysum(-1) or ysum(!step-1) = @first(ysum)Re: Value at risk with 10 day subsamples
I think i didn't explain very well what i need to calculate. i need that ysum has as first value the sum from 1 to 10, as second value the sum from 11 to 20, which means that is a series of 300 values, derived from 3000 daily returns. i need to use this series in garch model to forecast 1 step ahead.
once that i've done it for this first series i need to move the daily return series by one and then repeat all procedure, calculating the sum of 10 returns, estimating garch e forecast 1 step ahed.
How can i do all this?
Thanx
once that i've done it for this first series i need to move the daily return series by one and then repeat all procedure, calculating the sum of 10 returns, estimating garch e forecast 1 step ahed.
How can i do all this?
Thanx
Re: Value at risk with 10 day subsamples
ysum is exactly the series you want. And I just showed you one way to compute it. You can now automate the whole process via using EViews' programming features. An introduction to EViews programming is a good place to start.
Re: Value at risk with 10 day subsamples
I have already seen almost every post of programming in eviews, but i can't build the right code to compute all the procedure. It must be something like a double for loop with the first loop that moves the daily return series by 1 and with step=1, and the second for loop is the one that you showed me with step=10 which makes the 10day return series. I'm not an expert user of eviews so i cant do it me self. could someone help me with this?
Thnx
Thnx
Re: Value at risk with 10 day subsamples
I understand, but you should really give it a try and provide us something to work with. Otherwise, that "someone" would be doing the job for you. And that is not help.
Re: Value at risk with 10 day subsamples
You're perfectly right. what i have done until now is the code below. i cant find the way to make them work together.
This first code is the one that i use to calculate 10 day returns, which i save in a vector and then in a series. i need to move the for loop by one in order to calculate the next 10day return series, and i don't knwo how to do it. once i have calcutaed all possible 10 day series i have to use them in another code for the garch model.
'procedure for calculating 10 day return
smpl @all
'set window size
!window = 10
'set step size
!step = 10
'get size of workfile
!length = @obsrange
vector(300) r10
'calculate number of rolls
!nrolls = @floor((!length-!window)/!step)
'variable keeping track of how many rolls we've done
!j=0
series ser = 1
%start = @otod(@ifirst(ser))
%end = @otod(@ilast(ser))
'move sample !step obs at a time
for !i = 1 to !length-!window+1-!step step !step
!j=!j+1
'set sample for estimation period
%first = @otod(@dtoo(%start)+!i-1)
%last = @otod(@dtoo(%start)+!i+!window-2)
smpl {%first} {%last}
r10(!j) = @sum(r)
next
smpl @first @last
mtos(r10,r10s)
smpl @all
the next code that i use is this one. it has to calculate garch models for each of the series of 10 day returns. but it doesn'work.
'garch model for 10day returns
!window= 100
for !i = 1 to 200
smpl @first+!i @first+!i+!window-1
equation eq{!i}.arch(1,1) r10s{!i} c
smpl @first+!i+!window-1 @first+!i+!window-1+1
eq{!i}.forecast(f=na) tmp_g{!i} tmp_se{!i} tmp_var{!i}
!i=!i+1
next
i need to make the two codes move together, please help!!!
thnx
This first code is the one that i use to calculate 10 day returns, which i save in a vector and then in a series. i need to move the for loop by one in order to calculate the next 10day return series, and i don't knwo how to do it. once i have calcutaed all possible 10 day series i have to use them in another code for the garch model.
'procedure for calculating 10 day return
smpl @all
'set window size
!window = 10
'set step size
!step = 10
'get size of workfile
!length = @obsrange
vector(300) r10
'calculate number of rolls
!nrolls = @floor((!length-!window)/!step)
'variable keeping track of how many rolls we've done
!j=0
series ser = 1
%start = @otod(@ifirst(ser))
%end = @otod(@ilast(ser))
'move sample !step obs at a time
for !i = 1 to !length-!window+1-!step step !step
!j=!j+1
'set sample for estimation period
%first = @otod(@dtoo(%start)+!i-1)
%last = @otod(@dtoo(%start)+!i+!window-2)
smpl {%first} {%last}
r10(!j) = @sum(r)
next
smpl @first @last
mtos(r10,r10s)
smpl @all
the next code that i use is this one. it has to calculate garch models for each of the series of 10 day returns. but it doesn'work.
'garch model for 10day returns
!window= 100
for !i = 1 to 200
smpl @first+!i @first+!i+!window-1
equation eq{!i}.arch(1,1) r10s{!i} c
smpl @first+!i+!window-1 @first+!i+!window-1+1
eq{!i}.forecast(f=na) tmp_g{!i} tmp_se{!i} tmp_var{!i}
!i=!i+1
next
i need to make the two codes move together, please help!!!
thnx
Re: Value at risk with 10 day subsamples
Dear Eviews members, could anyone help me with another issue? in the code below i calculate only 1 series of 10 day returns, how can i build a matrix which has as a second column the r10(!i+1)?
'procedure for calculating 10 day return
smpl @all
'set window size
!window = 10
'set step size
!step = 10
'get size of workfile
!length = @obsrange
vector(300) r10
'calculate number of rolls
!nrolls = @floor((!length-!window)/!step)
'variable keeping track of how many rolls we've done
!j=0
series ser = 1
%start = @otod(@ifirst(ser))
%end = @otod(@ilast(ser))
'move sample !step obs at a time
for !i = 1 to !length-!window+1-!step step !step
!j=!j+1
'set sample for estimation period
%first = @otod(@dtoo(%start)+!i-1)
%last = @otod(@dtoo(%start)+!i+!window-2)
smpl {%first} {%last}
r10(!j) = @sum(r)
next
Thanx in advance
'procedure for calculating 10 day return
smpl @all
'set window size
!window = 10
'set step size
!step = 10
'get size of workfile
!length = @obsrange
vector(300) r10
'calculate number of rolls
!nrolls = @floor((!length-!window)/!step)
'variable keeping track of how many rolls we've done
!j=0
series ser = 1
%start = @otod(@ifirst(ser))
%end = @otod(@ilast(ser))
'move sample !step obs at a time
for !i = 1 to !length-!window+1-!step step !step
!j=!j+1
'set sample for estimation period
%first = @otod(@dtoo(%start)+!i-1)
%last = @otod(@dtoo(%start)+!i+!window-2)
smpl {%first} {%last}
r10(!j) = @sum(r)
next
Thanx in advance
Re: Value at risk with 10 day subsamples
In the beginning define r10 as a matrix instead:
Then you can assign values to the columns as well:
Code: Select all
matrix(300,60) r10Code: Select all
r10(!i,!j) = ...Re: Value at risk with 10 day subsamples
Thank you very much.. i'Ve tried this code below, but it doesnt assign any value to the second column..why?
'procedure for calculating 10 day return
smpl @all
'set window size
!window = 10
'set step size
!step = 10
'get size of workfile
!length = @obsrange
matrix(3000,300) r10
'calculate number of rolls
!nrolls = @floor((!length-!window)/!step)
'variable keeping track of how many rolls we've done
!j=0
series ser = 1
%start = @otod(@ifirst(ser))
%end = @otod(@ilast(ser))
'move sample !step obs at a time
for !n = 1 to 3000
for !i = !n to !length-!window+1-!step step !step
!j=!j+1
'set sample for estimation period
%first = @otod(@dtoo(%start)+!i-1)
%last = @otod(@dtoo(%start)+!i+!window-2)
smpl {%first} {%last}
r10(!n,!j) = @sum(r)
next
next
'procedure for calculating 10 day return
smpl @all
'set window size
!window = 10
'set step size
!step = 10
'get size of workfile
!length = @obsrange
matrix(3000,300) r10
'calculate number of rolls
!nrolls = @floor((!length-!window)/!step)
'variable keeping track of how many rolls we've done
!j=0
series ser = 1
%start = @otod(@ifirst(ser))
%end = @otod(@ilast(ser))
'move sample !step obs at a time
for !n = 1 to 3000
for !i = !n to !length-!window+1-!step step !step
!j=!j+1
'set sample for estimation period
%first = @otod(@dtoo(%start)+!i-1)
%last = @otod(@dtoo(%start)+!i+!window-2)
smpl {%first} {%last}
r10(!n,!j) = @sum(r)
next
next
Who is online
Users browsing this forum: No registered users and 1 guest
