Kenosis
6/26/2006 6:45:00 PM
Interesting approach but won't this under flow the array bounds on the
first month, ie, i=0 to start and cum_returns[i-1] would end up
mapping, as I recall, to cum_returns[cum_returns.size-1]? You'll need
to correct for this, I think, by skipping the first month or indexing
by i+1 and then stopping the each iteration a month early. (Hope I'm
not smoking crack here :)
Ken
neleai@seznam.cz wrote:
> Tim wrote:
> > I'm at a loss for how to do this and I'm wondering if there is a way
> > without getting too complicated.
> >
> > I'm using Rails 1.8.4, MYSQL 5 and AjaxScaffold.
> >
> > I have accounts and every account has many (variable) months' worth of
> > data. I can easily pull up the account and then pull up the many
> > months of data no problem.
> >
> > Each month has a dollar invested column and a percentage return
> > column. I have created a cumulative return column which is just the
> > following formula
> >
> > @@unit_value = 100
> >
> > def unit_value
> > if mymonthend == inception
> > @@unit_value = 100.to_f
> > else
> > @@unit_value =
> > @@unit_value*(1+Float(read_attribute("before_fee_return")))
> > end
> > end
> >
> >
> >
> > cum_return = cum_return * (1+ percent_return)
> >
> > It's basically a quick formula for showing the account's cumullative
> > performance over time.
> >
>
> I would recompute returns from first month by
> cum_return[0]=1
> months.each {|i| cum_returns[i] = cum_returns[i-1] * (1+
> percent_return[i])}
> and then you can compute return in interval as
> def cum_ret(from,to) cum_returns[to] / cum_returns[from-1] end