      program betasave
      include 'us.txt'
      character*32 name
c  this will spit out 5  years worth of data, and also aggregate sort of
       call udopen(3)
      open(10,file='ibmdaily.dat')
      open(11,file='ibm5daily.dat')
      open(12,file='ibm10daily.dat')
      open(13,file='ibm20daily.dat')
c  write out index
      istart=indxdt(19941231)
      iend=ndays
      write(10,990) 'Date','IBMRET1','EWRETD','VWRETD'
      write(11,990) 'Date','IBMRET5','EWRETD','VWRETD'
      write(12,990) 'Date','IBMRET10','EWRETD','VWRETD'
      write(13,990) 'Date','IBMRET20','EWRETD','VWRETD'
 990  format(a8,3(1x,a12))
 991  format(i8,3(1x,f12.8))

      call usgetper(1,12490,all,*9500)
      r5 = 0.0
      r10=0.0
      r20=0.0
      ewr5 = 0.0
      ewr10=0.0
      ewr20=0.0
      vwr5 = 0.0
      vwr10=0.0
      vwr20=0.0
      i5=0
      i10=0
      i20=0

      do 5 i=istart,iend
      if(ret(i).le.-1.0) ret(i)=0.0

      r5=(1.0+r5)*(1.0+ret(i))-1.0
      r10=(1.0+r10)*(1.0+ret(i))-1.0
      r20=(1.0+r20)*(1.0+ret(i))-1.0

      ewr5=(1.0+ewr5)*(1.0+ewretd(i))-1.0
      ewr10=(1.0+ewr10)*(1.0+ewretd(i))-1.0
      ewr20=(1.0+ewr20)*(1.0+ewretd(i))-1.0

      vwr5=(1.0+vwr5)*(1.0+vwretd(i))-1.0
      vwr10=(1.0+vwr10)*(1.0+vwretd(i))-1.0
      vwr20=(1.0+vwr20)*(1.0+vwretd(i))-1.0

      i5=i5+1
      i10=i10+1
      i20=i20+1

      write(10,991)caldt(i),ret(i),ewretd(i),vwretd(i)    

      if(i5.ge.5) then
        write(11,991) caldt(i),r5,ewr5,vwr5    
        r5=0.0
        ewr5=0.0
        vwr5=0.0
        i5=0
      endif

      if(i10.ge.10) then
        write(12,991) caldt(i),r10,ewr10,vwr10    
        r10=0.0
        ewr10=0.0
        vwr10=0.0
        i10=0
      endif

      if(i20.ge.20) then
        write(13,991) caldt(i),r20,ewr20,vwr20    
        r20=0.0
        ewr20=0.0
        vwr20=0.0
        i20=0
      endif
   
 99   format(i6,2(1x,f12.8))
  5   continue

 9500 call exit
      stop
      end
