```Date: Thu, 8 Jul 2010 11:41:12 -0400 Reply-To: Gerhard Hellriegel Sender: "SAS(r) Discussion" From: Gerhard Hellriegel Subject: Re: Optimization of Monte Carlo Code Content-Type: text/plain; charset=ISO-8859-1 I think that most of the time is spent in the loops do p = p0 to 0.99995 by 0.00005 while (s >= g); > do i = 1 to &int ; > x= a + b*rannor(i) ; > v= ((PROBIT(p) + sqrt(r)*x)/sqrt(1-r)); > fx(i) = PROBBNML(CDF('NORMAL',v,0,1),n,k); > end; > s = mean(of fx{*}); > end; sqrt(r) and sqrt(1-r) are constant in that loops and therefor it is unnecessary to call the function in there. You should replace them by a variable (or better 2) like r= &RHO ; sq1=sqrt(r); sq2=sqrt(1-r); .... v= ((PROBIT(p) + sq1*x)/sq2); Maybe there are more ideas, only the first one... Gerhard On Thu, 8 Jul 2010 11:58:22 -0300, =?iso-8859-1?Q? Ricardo_Gon=E7alves_da_Silva?= wrote: >HI, > >The code below do some optimizations using the Mean Monte Carlo method. >However, it�s taking one day to run. >Any hint concerning optimizations? > >data DADOS; >length rating \$2. ; >input rating \$ default frequencia ; >datalines; >A1 0 682 >A2 2 313 >B 10 404 >C 4 12 >D 1 30 >E 6 1 >G 0 10 >H 1 2 >; >run; > >proc sort data= dados ; >by descending rating ; >run; > >%MACRO PLU_TASC_CORR(DADOS, RATING, DEFAULT, FREQUENCIA, RHO, INTERACAO) ; >DATA TRANSF1; >SET &DADOS; >BY DESCENDING &RATING; >RETAIN AC_DEFAULT AC_FREQ; >AC_DEFAULT + &DEFAULT.; >AC_FREQ + &FREQUENCIA.; >RUN; > >PROC SQL; >SELECT COUNT(*) AS TAMANHO_VETOR, >MAX(AC_DEFAULT) AS TOT_DEFAULT, >MAX(AC_FREQ) AS TOT_OBSERVACOES > >INTO: TAMANHO, :TOTDEF, :TOTAL >FROM TRANSF1; >QUIT; >RUN; > >DATA LDP_CORR ; >SET TRANSF1; > >drop a b v i j x g s p r gama ; > >r= &RHO ; >a= 0; >b= 1 ; >%let int= &interacao ; > >array fx{&int} _temporary_ ; >array P_ {5} P50 P75 P90 P95 P99 ; >array E_ {5} ERR50 ERR75 ERR90 ERR95 ERR99 ; > >j=1 ; >p0=0.0008 ; > do gama = 50,75,90,95,99 ; /* Valores de Confiabilidade(gama) */ > g = 1 - (gama/100) ; > n= AC_FREQ ; > k= AC_DEFAULT ; > s= 10; > do p = p0 to 0.99995 by 0.00005 while (s >= g); > do i = 1 to &int ; > x= a + b*rannor(i) ; > v= ((PROBIT(p) + sqrt(r)*x)/sqrt(1-r)); > fx(i) = PROBBNML(CDF('NORMAL',v,0,1),n,k); > end; > s = mean(of fx{*}); > end; > E_(j)=abs(g-s); > P_(j)=p; > p0=p; > j+1; > end; >RUN; > >PROC SORT DATA= LDP_CORR ; >BY &RATING ; >RUN; > >PROC PRINT DATA=LDP_CORR; >VAR RATING DEFAULT FREQUENCIA AC_DEFAULT AC_FREQ P50 P75 P90 P95 P99 ERR50 ERR75 ERR90 ERR95 ERR99 ; >format P50 P75 P90 P95 P99 percent10.2 ; >RUN; >%MEND; >%PLU_TASC_CORR(DADOS, RATING, DEFAULT, FREQUENCIA, 0.12, 10000); > > >Esta mensagem e seus anexos podem conter informa��es confidenciais ou privilegiadas. Se voc� n�o � o destinat�rio dos mesmos voc� n�o est� autorizado a utilizar o material para qualquer fim. Solicitamos que voc� apague a mensagem e avise imediatamente ao remetente. O conte�do desta mensagem e seus anexos n�o representam necessariamente a opini�o e a inten��o da empresa, n�o implicando em qualquer obriga��o ou responsabilidade da parte da mesma. >This message may contain confidential and/or privileged information. If you are not the addressee or authorized to receive this for the addressee, you must not use, copy, disclose or take any action based on this message or any information herein. If you have received this message in error, please advise the sender immediately by reply e-mail and delete this message. The contents of this message and its attachments do not necessarily express the opinion or the intention of the company, and do not implies any legal obligation or responsibilities from this company. ```

Back to: Top of message | Previous page | Main SAS-L page