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

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