[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: Automatic Invesment by Lichello (AIM)


  • Date: Fri, 18 Dec 2009 03:30:25 -0000
  • From: "ewn87544" <trading4@xxxxxxx>
  • Subject: [amibroker] Re: Automatic Invesment by Lichello (AIM)

PureBytes Links

Trading Reference Links

#TITLE Lichello's Automatic Investment Method (AIM) by Dennis Myers
{************* AIM_v4.TAS    7/17/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 . this is a money managemen
t
  system and you can change the parameters from Lichello's to change
  the slope and shape of the equity curve .e.g. optimize }
{v2}{corrected portfolio contl error and added equity vs time regresion}
{v3}{added graphout of equity curve and regression vs buy/hold}
{v4}{corrected regression for t=0, added reg parm to printout}
{=====================================================================}
{   set up starting variables }
{=====================================================================}
#MAX_QUOTES 100
#output_file AIM.LST
qs=quote_count
pr_all=0;       {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;
time   : array;{create time variable that starts at 0 for linreg2}
  for i=1; i<=qs; i=i+1;
    time[i]=i-1;
{====================================================================}
{    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]);
  end;{ if print switch =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=linreg2(equity,time,0,0);
eqslope=eq_reg[qs]-eq_reg[qs-1];
a=eq_reg[1]
b=eqslope
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',
        '  REGr EQUITY vs T');
writeln('\t\t    from      to    G/L %   %/yr  DRAWDN   % VAR',
        '   G/L %', '     a  +   b*(t-1)');
writeln(ticker,dates[1],dates[qs],format(aimpct,'%8.1f'),
        format(eqslope,'%8.1f'),format(max_dd,'%8.1f'),
        format(eq_var,'%8.1f'),format(bhpct,'%8.1f'),' ',a,' ',b);
{===================================================================}
{   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;


--- In amibroker@xxxxxxxxxxxxxxx, "Vinay Gakkhar." <vgakkhar@xxx> wrote:
>
> Dear Ernie,
> 
> Can you share the TAS script?
> 
> Best regards,
> 
> Vinay
> 
> On Fri, 18 Dec 2009 07:10:49 +0530, ewn87544 <trading4@xxx> wrote:
> 
> >  Has anyone written a script for Amibroker to run the automatic system from the book How to Make $1,000,000 in the Stock Market automatically by Robert Lichello.
> >  This book last version was written in 1992 so if you haven't heard
> > of it don't be surprised. I have an old script from TAS that looks promising but would like to test it in AB.
> > Thanks
> > Ernie
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> 
> 
> --
>




------------------------------------

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to 
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    amibroker-digest@xxxxxxxxxxxxxxx 
    amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/