I've got a problem for you Access/SQL gurus out there...
I am using Access 2000.
This problem involves Table1 with these columns: date, ticker, close. This table is updated daily with the closing prices of various stocks.
I am trying to develop a query that prompts me for a date (we can assume that the date entered will be valid, in all respects) and then proceeds to give me the 3 day moving average for each ticker in Table1.
The 3 day moving average is calculated as follows: for Day 4, it would be: (Day 4's closing price + Day 3's closing price + Day 2's closing price)/3.
The 3 day moving average for the next day (Day 5) would be: (Day 5's closing price + Day 4's closing price + Day 3's closing price)/3.
I don't think this can be done with operations performed on dates, since stocks don't trade on Saturdays, Sundays nor on some holidays and thus don't have prices on those days. I believe a better approach would be to use the TOP function or something similar to get the last 3 records for each ticker. But I can't figure out how to do this correctly.
So, ideally the output would look something like this:
InputtedDate Ticker1 Ticker1MovingAverage
InputtedDate Ticker2 Ticker2MovingAverage
InputtedDate Ticker3 Ticker3MovingAverage
etc...
Thanks in advance for any help,
maxie3
I am using Access 2000.
This problem involves Table1 with these columns: date, ticker, close. This table is updated daily with the closing prices of various stocks.
I am trying to develop a query that prompts me for a date (we can assume that the date entered will be valid, in all respects) and then proceeds to give me the 3 day moving average for each ticker in Table1.
The 3 day moving average is calculated as follows: for Day 4, it would be: (Day 4's closing price + Day 3's closing price + Day 2's closing price)/3.
The 3 day moving average for the next day (Day 5) would be: (Day 5's closing price + Day 4's closing price + Day 3's closing price)/3.
I don't think this can be done with operations performed on dates, since stocks don't trade on Saturdays, Sundays nor on some holidays and thus don't have prices on those days. I believe a better approach would be to use the TOP function or something similar to get the last 3 records for each ticker. But I can't figure out how to do this correctly.
So, ideally the output would look something like this:
InputtedDate Ticker1 Ticker1MovingAverage
InputtedDate Ticker2 Ticker2MovingAverage
InputtedDate Ticker3 Ticker3MovingAverage
etc...
Thanks in advance for any help,
maxie3