home *** CD-ROM | disk | FTP | other *** search
- {************* AIM_v3.TAS 7/16/92 by Dennis Meyers ******************}
- {}
- { This program computes and plots the net equity of the stocks input using
- the AIM algorithm described in Robert Lichello's book "How To Make
- $1,000,000 In The Stock Market Automatically" . You must change the
- variables int_rate and period to suit your run . }
- {}
- {=====================================================================}
- { set up starting variables }
- {=====================================================================}
- #MAX_QUOTES 100
- #OUTPUT_FILE 'AIM.LST'
- qs=quote_count
- pr_all=1 {print switch 1= print all calc daily-- 0=no print}
- start=10000.0;
- int_rate=0.0525;{change interest rate to whatever you get}
- period='M'; {period can be D=daily, W=weekly, M=monthly }
- wk_yr=365.0/7.0 ;
- max_dd=0.0;
- eq_var : number;
- diff=0.0;
- mkt_order=0.0;
- min_order=100.0;{note: Lichello, p265 changes this to 5% x stock_val }
- min_pct=0.02; {in order for p146 to give same results this should be}
- {2% x stock_val. the bigger the minimum the more the }
- {stock has to move before you buy or sell..egads another}
- {variable to experiment with}
- if period = 'D' then dy_int=int_rate/252.0; {apprx 252 trading days per year
- }
- if period = 'W' then dy_int=int_rate/wk_yr;
- if period = 'M' then dy_int=int_rate/12;
- {=====================================================================}
- { set up arrays and array starting values }
- {=====================================================================}
- equity : array;
- eq_reg : array;
- shares : array;
- del_shr : array;
- buy_hold : array;
- {====================================================================}
- { start aim calculations }
- {====================================================================}
- save_pct=0.1;
- stk_pct=0.5;
- pcmul=1.0;
- stock_val=start*stk_pct;
- safe=save_pct*stock_val;
- cash=start*(1-stk_pct);
- pcntl=pcmul*stock_val;
- port_val=start;
- equity[1]=start;
- shares[1]=stock_val/c[1];
- del_shr[1]=0.0;
- if pr_all=1 then {if print switch=1 then print all daily calculations}
- BEGIN
- WRITELN(' DATE DJI STK_VL SAFE CASH',
- ' SHRCHG SHARES PCNTRL ADVICE ORDER PVALUE')
- WRITELN(dates[1],c[1],stock_val,safe,cash,del_shr[1],shares[1],
- pcntl,diff,mkt_order,equity[1]);
- for i=2; i<=qs; i=i+1;
- BEGIN
- cash=cash - del_shr[i-1]*c[i-1];
- cash=cash + dy_int*cash
- stock_val=c[i]*shares[i-1];
- safe=save_pct*stock_val;
- port_val=stock_val + cash;
- equity[i]=port_val;
- diff=pcntl-stock_val;
- abdiff=diff
- if diff < 0 then abdiff=-diff;
- mkt_order=0.0
- shares[i]=shares[i-1]
- del_shr[i]=0.0
- {min_order=min_pct*stock_val} {use only if using lichello's %min method}
- if abdiff > safe then
- mkt_order=abdiff-safe;
- if mkt_order > min_order then
- begin
- if diff < 0 then mkt_order=-mkt_order;
- del_shr[i]=mkt_order/c[i];
- shares[i]=shares[i-1]+del_shr[i];
- if mkt_order > 0 then pcntl=pcntl + (stk_pct*mkt_order);
- end; {mkt_order <> 0 loop}
- if pr_all=1 then {if print switch=1 then print all daily calculations}
- WRITELN(dates[i],c[i],stock_val,safe,cash,del_shr[i],shares[i],
- pcntl,diff,mkt_order,equity[i]);
- end; { i for loop end}
- {=========================================================================}
- { compute slope(%/yr), maximum drawdown(%), and variance about slope }
- {=========================================================================}
- buy_hold[1]=start;
- eq_reg=linreg(equity,0,0);
- eqslope=slope(eq_reg);
- if period = 'D' then eqslope=100*eqslope*252.0/start
- if period = 'W' then eqslope=100*eqslope*wk_yr/start
- if period = 'M' then eqslope=100*eqslope*12/start
- {}
- { find maximum drawdown}
- {}
- maxeq=start
- for i = 2; i <= qs; i = i+1;
- begin
- buy_hold[i]=start*(1+((c[i]-c[1])/c[1]));
- if equity[i] > maxeq then maxeq=equity[i];
- if equity[i] < maxeq then dd=maxeq-equity[i];
- if dd > max_dd then max_dd=dd;
- end; {i for loop end}
- max_dd=100*max_dd/start;
- {}
- { compute variance from trend line }
- {}
- n=0.0;
- x=0.0;
- x2=0.0;
- eq_var=0.0;
- for i = 1; i <= qs; i = i+1;
- begin
- n=n+1;
- x=x + equity[i]-eq_reg[i];
- x2=x2 + x*x ;
- end; { i for loop end}
- if n > 0 then
- begin
- eq_var=(x2-x*x)/n;
- if eq_var > 0 then eq_var=100*(eq_var^0.5)/start;
- end; {if n>0}
- {===================================================================}
- { printout these results }
- {===================================================================}
- bhpct=100*(c[qs]-c[1])/c[1] ;
- aimpct=100*(equity[qs]-equity[1])/equity[1]
- writeln('\t\t\t\t\t\t AIM SLOPE MAX %',' ',' BUYHOLD');
- writeln('\t\t from to G/L % %/yr DRAWDN % VAR',' G/L %');
- writeln(ticker,dates[1],dates[qs],aimpct,eqslope,max_dd,eq_var,bhpct);
- {===================================================================}
- { graphout the equity curve and regresion }
- {===================================================================}
- opengraph(2);
- graph(equity,format(aimpct,'aim g/l pct %6.2f'),
- eq_reg,format(eqslope,'equity slope pct/yr %6.2f'),
- eq_reg,format(max_dd,'maximum drawdown pct %6.2f'),
- buy_hold,'buy_hold g/l');
- graph(c,format(bhpct,'closing prices--buy_hold g/l pct %6.2f'));
- closegraph();
- {===================================================================}
- { program end }
- {===================================================================}
- return;
-