Value at risk with 10 day subsamples

For questions regarding programming in the EViews programming language.

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

Tau
Posts: 6
Joined: Tue Mar 10, 2015 9:09 am

Value at risk with 10 day subsamples

Postby Tau » Tue Mar 10, 2015 9:20 am

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

trubador
Did you use forum search?
Posts: 1520
Joined: Thu Nov 20, 2008 12:04 pm

Re: Value at risk with 10 day subsamples

Postby trubador » Tue Mar 10, 2015 12:19 pm

There are many ways to do what you want. Below is just one of them:

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)
You can now work with the series ysum in a newly created page tendays without changing the original page.

Tau
Posts: 6
Joined: Tue Mar 10, 2015 9:09 am

Re: Value at risk with 10 day subsamples

Postby Tau » Tue Mar 10, 2015 3:07 pm

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

trubador
Did you use forum search?
Posts: 1520
Joined: Thu Nov 20, 2008 12:04 pm

Re: Value at risk with 10 day subsamples

Postby trubador » Wed Mar 11, 2015 12:31 am

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.

Tau
Posts: 6
Joined: Tue Mar 10, 2015 9:09 am

Re: Value at risk with 10 day subsamples

Postby Tau » Wed Mar 11, 2015 2:51 am

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

trubador
Did you use forum search?
Posts: 1520
Joined: Thu Nov 20, 2008 12:04 pm

Re: Value at risk with 10 day subsamples

Postby trubador » Wed Mar 11, 2015 2:56 am

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.

Tau
Posts: 6
Joined: Tue Mar 10, 2015 9:09 am

Re: Value at risk with 10 day subsamples

Postby Tau » Wed Mar 11, 2015 4:59 am

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

Tau
Posts: 6
Joined: Tue Mar 10, 2015 9:09 am

Re: Value at risk with 10 day subsamples

Postby Tau » Wed Mar 11, 2015 9:38 pm

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

trubador
Did you use forum search?
Posts: 1520
Joined: Thu Nov 20, 2008 12:04 pm

Re: Value at risk with 10 day subsamples

Postby trubador » Thu Mar 12, 2015 1:27 am

In the beginning define r10 as a matrix instead:

Code: Select all

matrix(300,60) r10
Then you can assign values to the columns as well:

Code: Select all

r10(!i,!j) = ...

Tau
Posts: 6
Joined: Tue Mar 10, 2015 9:09 am

Re: Value at risk with 10 day subsamples

Postby Tau » Thu Mar 12, 2015 1:43 am

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


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests