bootstrapping
Posted: Sun Apr 25, 2010 12:43 am
As part of a project to test the efficacy of alternative trading rules, I'm need to save results from 500 draws of a bootstrap for subsequent use. In the following code (based on BOOTSIMP.PRG), the COPY command saves results only for the final draw. I've tried placing the COPY command inside and outside the DO loop, to no avail. If anyone has a helpful suggestion, I'd certainly be most grateful if they would pass it on to me. Kind regards.
*
* BOOTSIMP.PRG
* Bootstrapping with an AR(1) model.
*
all 4697
open data f:/Gerry/KLSE_returns.xls
data(format=xls,org=obs) / price returns
*
stats returns
*
*Estimate AR(1) model for returns; obtain resids and coeffs.
*
linreg returns
# constant returns{1}
set uhat = %resids
compute B1 = %beta(1)
compute B2 = %beta(2)
*
* For the bootstrap, make 500 draws from the residuals,
* which, together with coeffs, will produce 500 series of returns and price.
* Save the bootstrapped series in Excel file.
compute ndraws = 500
*
open copy returnstar.xls
/*
do draws=1,ndraws
boot entries 1 4697
set ustar1 1 4697 = uhat(entries(t))
set r_star1 = B1 + B2*returns{1} + ustar1
*/
do i=1,ndraws
set ustar = uhat(fix(%uniform(1,4698)))
set r_star = B1 + B2*returns{1} + ustar
* Transform bootstrapped returns series back into price level equivalents.
smpl 1 1 ; set p_star = 505.92
smpl 2 4697 ; set p_star = (1+r_star)*p_star{1}
end do i
*print 1 4697 r_star p_star
copy(format=xls,org=col) 1 4697 r_star p_star price
*
* BOOTSIMP.PRG
* Bootstrapping with an AR(1) model.
*
all 4697
open data f:/Gerry/KLSE_returns.xls
data(format=xls,org=obs) / price returns
*
stats returns
*
*Estimate AR(1) model for returns; obtain resids and coeffs.
*
linreg returns
# constant returns{1}
set uhat = %resids
compute B1 = %beta(1)
compute B2 = %beta(2)
*
* For the bootstrap, make 500 draws from the residuals,
* which, together with coeffs, will produce 500 series of returns and price.
* Save the bootstrapped series in Excel file.
compute ndraws = 500
*
open copy returnstar.xls
/*
do draws=1,ndraws
boot entries 1 4697
set ustar1 1 4697 = uhat(entries(t))
set r_star1 = B1 + B2*returns{1} + ustar1
*/
do i=1,ndraws
set ustar = uhat(fix(%uniform(1,4698)))
set r_star = B1 + B2*returns{1} + ustar
* Transform bootstrapped returns series back into price level equivalents.
smpl 1 1 ; set p_star = 505.92
smpl 2 4697 ; set p_star = (1+r_star)*p_star{1}
end do i
*print 1 4697 r_star p_star
copy(format=xls,org=col) 1 4697 r_star p_star price