c# sql I need a way to calculate moving averages from a table with stock prices
Posted on 2013-01-15
I have a table of stock price with date, symbol, close and I need moving averages.
For instance, on 1/1/2012 I will need the 20 day, 10 day, and 5 day moving average. I was originally going to just do individual sql calls for each, but I was thinking that would be really slow. I'd rather read all the values in first then calculate values, but I am not sure the best way.
Also, when I say 20 day moving average, I need the last 20 values, not the calendar days. There will be no values on the weekends and holidays.
I am not sure how to structure this, but I would like to be able to make a call like:
GetMovingAverage("IBM", 20 (day), 1/1/2012)
GetMovingAverage("IBM", 10 (day), 1/1/2012)
GetMovingAverage("GOOG", 20 (day), 2/2/2010)