looping overlaying graph
looping overlaying graph
Hi
I'm new to RATS so my question is probably pretty basic. Nonetheless I would be really grateful of any help.
I want to do 4 graphs of overlapping stock index and return.
In the following code I get 16 graphs. I know I can pick out the right ones, but learning how to do the right coding would be really great.
dofor i = USA China Denmark Romania
dofor y = RETURNUSA RETURNchi RETURNden RETURNrom
GRAPH(STYLE=LINE,OVERLAY=LINE,HEADER="Stock index and return",KEY=BELOW) 2
# y
# i
end dofor i
end dofor y
Hope you can help
I'm new to RATS so my question is probably pretty basic. Nonetheless I would be really grateful of any help.
I want to do 4 graphs of overlapping stock index and return.
In the following code I get 16 graphs. I know I can pick out the right ones, but learning how to do the right coding would be really great.
dofor i = USA China Denmark Romania
dofor y = RETURNUSA RETURNchi RETURNden RETURNrom
GRAPH(STYLE=LINE,OVERLAY=LINE,HEADER="Stock index and return",KEY=BELOW) 2
# y
# i
end dofor i
end dofor y
Hope you can help
Re: looping overlaying graph
If it's just 4, you might want to just to 4 graph instructions:
GRAPH(STYLE=LINE,OVERLAY=LINE,HEADER="Stock index and return",KEY=BELOW) 2
# usa
# returnusa
GRAPH(STYLE=LINE,OVERLAY=LINE,HEADER="Stock index and return",KEY=BELOW) 2
# china
# returnchi
etc.
Because the return series don't quite match the root names for the index (it would be a bit simpler if you did "returnchina" to match with "china" for instance), you would have to do an extra step to match the two up in order to use a loop. For instance,
GRAPH(STYLE=LINE,OVERLAY=LINE,HEADER="Stock index and return",KEY=BELOW) 2
# usa
# returnusa
GRAPH(STYLE=LINE,OVERLAY=LINE,HEADER="Stock index and return",KEY=BELOW) 2
# china
# returnchi
etc.
Because the return series don't quite match the root names for the index (it would be a bit simpler if you did "returnchina" to match with "china" for instance), you would have to do an extra step to match the two up in order to use a loop. For instance,
Code: Select all
dec hash[string] rname
compute rname("usa")="returnusa"
compute rname("china")="returnchi"
compute rname("denmark")="returnden"
compute rname("romania")="returnrom"
*
dofor i = USA China Denmark Romania
GRAPH(STYLE=LINE,OVERLAY=LINE,HEADER="Stock index and return",KEY=BELOW) 2
# i
# %s(rname(%l(i))
end doforRe: looping overlaying graph
Thank you very much! Worked perfectly