Page 1 of 1
Loop results: output to a file
Posted: Wed Aug 19, 2009 5:36 am
by raphael
I am running a "do" loop which produces results at each iteration; how can I make RATS write the output (which is a series), at each iteration, to a new line or column in the same output file (if possible, an Excel file) ? For example, if I have a loop such as do i = 1, 24, the output file in the end would have 24 lines or columns. Thanks!
Re: Loop results: output to a file
Posted: Wed Aug 19, 2009 7:02 am
by TomDoan
raphael wrote:I am running a "do" loop which produces results at each iteration; how can I make RATS write the output (which is a series), at each iteration, to a new line or column in the same output file (if possible, an Excel file) ? For example, if I have a loop such as do i = 1, 24, the output file in the end would have 24 lines or columns. Thanks!
You can't write an Excel file one column at a time - you have to form it in a single go. From your description, it sounds as if the simplest way to do it is to copy the data into a VECT[SERIES], then output that at the end of the loop.
Code: Select all
dec vect[series] copydata(24)
do i=1,24
...
set copydata(i) = data generated on i
end do i
copy(format=xls,org=columns) / copydata
Re: Loop results: output to a file
Posted: Wed Aug 19, 2009 12:22 pm
by raphael
Thanks that's great. What if the output is a real number instead of a series?
Re: Loop results: output to a file
Posted: Wed Aug 19, 2009 12:40 pm
by TomDoan
The easiest thing there is probably to do DISPLAY(UNIT=COPY) inside the loop. That will create a text file that you can pull into Excel. This is from the example program
betas.prg. It creates a text file betas.lst which has two columns - the ticker symbol on the left and a beta coefficient on the right.
Code: Select all
open copy betas.lst
data(format=rats) / market
do i=1,ntickers
labels 1
# tickers(i)
clear 1
data(format=rats) / 1
linreg(noprint) 1
# constant market
display(unit=copy) tickers(i) @20 ##.##### %beta(2)
end do i
close copy