Maintaining running values between paginator pages

T

Tim

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.

The problem is each time I go to a new page, the cumulative return is
reset to 100. I want it to pick up where the last page left off. I
thought about putting the final cum return in a session variable but
that won't work if the user skips a page or goes back a page.

Is there any way to do this? Do I need to pass every month and every
cum return to a session variable array and look up the values every
time? Is that the only way to do it?

Right now I'm cheating by forcing all the data to show up on a page
but two things are wrong with this: 1) some accounts have hundreds of
months' worth of data; 2) for accounts with a lot of data it takes too
long to load a page.

Thanks in advance
 
N

neleai

Tim said:
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 = cum_returns[i-1] * (1+
percent_return)}
and then you can compute return in interval as
def cum_ret(from,to) cum_returns[to] / cum_returns[from-1] end
 
K

Kenosis

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

Tim said:
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 = cum_returns[i-1] * (1+
percent_return)}
and then you can compute return in interval as
def cum_ret(from,to) cum_returns[to] / cum_returns[from-1] end
 
T

Tim

Thanks for the tip. It's helping me begin to think "in Ruby" which is
really a new way tothink problems out.

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 = cum_returns[i-1] * (1+
percent_return)}
and then you can compute return in interval as
def cum_ret(from,to) cum_returns[to] / cum_returns[from-1] end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top