calculate data in datatable itself

  • Thread starter Thread starter Franko
  • Start date Start date
F

Franko

Hi,
I have a datatable loaded with stock prices. Each row contains the
prices of the stock for a day. i want to create a new column and
calculate a 10 daymoving average of closing prices in it. How do i do
it on the dataset itself. is there a way to count the data in the last
10 rows and update another row dynamically.
 
Hi Franko,

Do-able, but somewhat complicated.

I assume you have a date for each row. You can write a routine that loops
through the rows of the table in date order, calculating the average only if
the date is within the last 10 days from Now (and this will require some
'date flattening' to remove the time element so you don't miss a date or get
one more than you need). Then add a new row with the information, but leave
the date blank in that row so that suc a row is never used in subsequent
calculations.

It is made more complicated by the fact that you probably have different
stocks in the same table, so you now need a double loop - one on each stock
symbol and calculation its 10 days, then the next stock symbol, etc. Then,
of course, you need to update the backend. I've done things like this but
it's not easy.

HTH,

Bernie Yaeger
 
Hi Franko,

As Bernie suggested - there is no automated way.
You should do it using loops, DataViews and stuff.like that.
 
Back
Top