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

[amibroker] Re: compound interest



PureBytes Links

Trading Reference Links

Sid, Bill -

Was wandering by, and though this might help.  There's an easier way 
to do this that doesn't require looping.  Here's an Irate() 
function  -

function Irate(interest_rate)
{
	// This gets the log of the daily rate
	logbarfactor = log(1 + interest_rate / 100) / 252;

	// Force the first bar to 0
	logvect = IIf(BarIndex() == 0, 0, logbarfactor);

	// Sum the log of the daily gain factors and 
        // convert back to get equity
	return(exp(Cum(logvect)));
}

// Test with an APR of 5%
vect = Irate(5);

Filter = 1;
AddColumn(BarIndex(), "INDEX");
AddColumn(vect, "EQ", 8.4);


--- In amibroker@xxxxxxxxxxxxxxx, "BillBarack" <wbarack@xxxx> wrote:
> Sidney,
> 
> Here is some code I wrote a while ago (before looping) in VBScript 
> that should do the job for you.
> 
> Bill
> 
> -------------
> 
> SetBarsRequired( 10000, 10000 );
> EnableScript("VBscript");
> Price1 = ((H+L)/2);
> //Put your percentage in The Annual Percentage line ... 8% = .08,  
> 20% = .20
> <%
> Price1 = AFL.Var("Price1")
> 
> myArray = AFL.Var("Close")
> 
> AnnualPercentage = .15
> Per = (1+AnnualPercentage)^(7/(5*365))-1
> Summ = 0
> HiIndex = Ubound(Price1)
> 
> for i=0 to HiIndex
>      Summ = Summ + 1
> Next
> 
> Price1(0)=1
> 
> for i=1 to Summ-1
> 'Price1(i) = 1+i
>      Price1(i)=Price1(0)*(1+per)^i
> Next
> 
> AFL.Var("Price1") = Price1
> 'AFL.Var("Summ") = Summ
> %>
> 
> Plot(Price1,"15%",4,4);  
> 
> 
> --- In amibroker@xxxxxxxxxxxxxxx, Sidney Kaiser <s9kaiser@xxxx> 
wrote:
> > No nibbles on help for this so far.
> > 
> > It seems to me that the time periods have to be bar by bar to 
> generate the 
> > interest curve so here is my current attempt which always returns 
a 
> single 
> > value, 1.
> > 
> > Where should I go from here?
> > Sid
> > 
> > // Compound Interest
> > 
> > 
> > interest_rate = 5;     // %
> > //P = 1;     // principal amount
> > r = interest_rate/100;
> > //t = 10;    // years
> > //tbar = t/260;
> > 
> > A[0] = 1; /*Initialize the first element here*/
> > t[0] = 0;
> > 
> > for(i = 1; i<BarCount; i++)
> > {
> >     A[i] = A[i-1]*exp(r*t[i]/260);
> > }
> > //A = P * exp(r*t);
> > 
> > Plot(A, "Compound Interest", colorBlack, styleLine);  
> > 
> > 
> > ---
> > Outgoing mail is certified Virus Free.
> > Checked by AVG anti-virus system (http://www.grisoft.com).
> > Version: 6.0.545 / Virus Database: 339 - Release Date: 11/27/2003


------------------------ Yahoo! Groups Sponsor ---------------------~-->
Buy Ink Cartridges or Refill Kits for your HP, Epson, Canon or Lexmark
Printer at MyInks.com. Free s/h on orders $50 or more to the US & Canada.
http://www.c1tracking.com/l.asp?cid=5511
http://us.click.yahoo.com/mOAaAA/3exGAA/qnsNAA/GHeqlB/TM
---------------------------------------------------------------------~->

Send BUG REPORTS to bugs@xxxxxxxxxxxxx
Send SUGGESTIONS to suggest@xxxxxxxxxxxxx
-----------------------------------------
Post AmiQuote-related messages ONLY to: amiquote@xxxxxxxxxxxxxxx 
(Web page: http://groups.yahoo.com/group/amiquote/messages/)
--------------------------------------------
Check group FAQ at: http://groups.yahoo.com/group/amibroker/files/groupfaq.html 

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