home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1993 #2 / Image.iso / finance / tas515dm.zip / EXAMPLES.ZIP / AIM.TAS < prev    next >
Text File  |  1992-07-16  |  6KB  |  149 lines

  1. {************* AIM_v3.TAS    7/16/92  by Dennis Meyers ******************}
  2. {}
  3. { This program computes and plots the net equity of the stocks input using
  4.   the AIM algorithm described in Robert Lichello's book "How To Make
  5.   $1,000,000 In The Stock Market Automatically" .  You must change the
  6.   variables int_rate and period to suit your run .                       }
  7. {}
  8. {=====================================================================}
  9. {   set up starting variables }
  10. {=====================================================================}
  11. #MAX_QUOTES 100
  12. #OUTPUT_FILE 'AIM.LST'
  13. qs=quote_count
  14. pr_all=1        {print switch 1= print all calc daily-- 0=no print}
  15. start=10000.0;
  16. int_rate=0.0525;{change interest rate to whatever you get}
  17. period='M';     {period can be D=daily, W=weekly, M=monthly }
  18. wk_yr=365.0/7.0 ;
  19. max_dd=0.0;
  20. eq_var : number;
  21. diff=0.0;
  22. mkt_order=0.0;
  23. min_order=100.0;{note: Lichello, p265 changes this to 5% x stock_val  }
  24. min_pct=0.02;   {in order for p146 to give same results this should be}
  25.                 {2% x stock_val. the bigger the minimum the more the  }
  26.                 {stock has to move before you buy or sell..egads another}
  27.                 {variable to experiment with}
  28. if period = 'D' then dy_int=int_rate/252.0; {apprx 252 trading days per year
  29. }
  30. if period = 'W' then dy_int=int_rate/wk_yr;
  31. if period = 'M' then dy_int=int_rate/12;
  32. {=====================================================================}
  33. {    set up arrays  and array starting values  }
  34. {=====================================================================}
  35. equity : array;
  36. eq_reg : array;
  37. shares : array;
  38. del_shr : array;
  39. buy_hold : array;
  40. {====================================================================}
  41. {    start aim calculations  }
  42. {====================================================================}
  43. save_pct=0.1;
  44. stk_pct=0.5;
  45. pcmul=1.0;
  46. stock_val=start*stk_pct;
  47. safe=save_pct*stock_val;
  48. cash=start*(1-stk_pct);
  49. pcntl=pcmul*stock_val;
  50. port_val=start;
  51. equity[1]=start;
  52. shares[1]=stock_val/c[1];
  53. del_shr[1]=0.0;
  54.   if pr_all=1 then  {if print switch=1 then print all daily calculations}
  55.     BEGIN
  56.     WRITELN('    DATE     DJI  STK_VL    SAFE    CASH',
  57.             '  SHRCHG  SHARES  PCNTRL  ADVICE   ORDER  PVALUE')
  58.     WRITELN(dates[1],c[1],stock_val,safe,cash,del_shr[1],shares[1],
  59.             pcntl,diff,mkt_order,equity[1]);
  60. for i=2; i<=qs; i=i+1;
  61. BEGIN
  62.   cash=cash - del_shr[i-1]*c[i-1];
  63.   cash=cash + dy_int*cash
  64.   stock_val=c[i]*shares[i-1];
  65.   safe=save_pct*stock_val;
  66.   port_val=stock_val + cash;
  67.   equity[i]=port_val;
  68.   diff=pcntl-stock_val;
  69.   abdiff=diff
  70.   if diff < 0 then abdiff=-diff;
  71.   mkt_order=0.0
  72.   shares[i]=shares[i-1]
  73.   del_shr[i]=0.0
  74.   {min_order=min_pct*stock_val} {use only if using lichello's %min method}
  75.   if abdiff > safe then
  76.     mkt_order=abdiff-safe;
  77.   if mkt_order > min_order then
  78.   begin
  79.     if diff < 0 then mkt_order=-mkt_order;
  80.     del_shr[i]=mkt_order/c[i];
  81.     shares[i]=shares[i-1]+del_shr[i];
  82.     if mkt_order > 0 then  pcntl=pcntl + (stk_pct*mkt_order);
  83.   end;  {mkt_order <> 0 loop}
  84.   if pr_all=1 then  {if print switch=1 then print all daily calculations}
  85.     WRITELN(dates[i],c[i],stock_val,safe,cash,del_shr[i],shares[i],
  86.             pcntl,diff,mkt_order,equity[i]);
  87. end; { i for loop end}
  88. {=========================================================================}
  89. {  compute slope(%/yr), maximum drawdown(%), and variance about slope     }
  90. {=========================================================================}
  91. buy_hold[1]=start;
  92. eq_reg=linreg(equity,0,0);
  93. eqslope=slope(eq_reg);
  94. if period = 'D' then  eqslope=100*eqslope*252.0/start
  95. if period = 'W' then  eqslope=100*eqslope*wk_yr/start
  96. if period = 'M' then  eqslope=100*eqslope*12/start
  97. {}
  98. {  find maximum drawdown}
  99. {}
  100. maxeq=start
  101. for i = 2; i <= qs; i = i+1;
  102.   begin
  103.   buy_hold[i]=start*(1+((c[i]-c[1])/c[1]));
  104.   if equity[i] > maxeq  then maxeq=equity[i];
  105.   if equity[i] < maxeq then  dd=maxeq-equity[i];
  106.   if dd > max_dd then max_dd=dd;
  107. end; {i for loop end}
  108. max_dd=100*max_dd/start;
  109. {}
  110. {  compute variance from trend line  }
  111. {}
  112. n=0.0;
  113. x=0.0;
  114. x2=0.0;
  115. eq_var=0.0;
  116. for i = 1; i <= qs; i = i+1;
  117.   begin
  118.   n=n+1;
  119.   x=x + equity[i]-eq_reg[i];
  120.   x2=x2 + x*x ;
  121. end; { i for loop end}
  122. if n > 0 then
  123. begin
  124.   eq_var=(x2-x*x)/n;
  125.   if eq_var > 0 then eq_var=100*(eq_var^0.5)/start;
  126. end; {if n>0}
  127. {===================================================================}
  128. {    printout these results  }
  129. {===================================================================}
  130. bhpct=100*(c[qs]-c[1])/c[1] ;
  131. aimpct=100*(equity[qs]-equity[1])/equity[1]
  132. writeln('\t\t\t\t\t\t     AIM   SLOPE   MAX %','        ',' BUYHOLD');
  133. writeln('\t\t    from      to    G/L %   %/yr  DRAWDN   % VAR','   G/L %');
  134. writeln(ticker,dates[1],dates[qs],aimpct,eqslope,max_dd,eq_var,bhpct);
  135. {===================================================================}
  136. {   graphout the equity curve and regresion }
  137. {===================================================================}
  138. opengraph(2);
  139. graph(equity,format(aimpct,'aim g/l pct %6.2f'),
  140.         eq_reg,format(eqslope,'equity slope pct/yr %6.2f'),
  141.         eq_reg,format(max_dd,'maximum drawdown pct %6.2f'),
  142.         buy_hold,'buy_hold g/l');
  143. graph(c,format(bhpct,'closing prices--buy_hold g/l pct %6.2f'));
  144. closegraph();
  145. {===================================================================}
  146. {   program end  }
  147. {===================================================================}
  148. return;
  149.