Is this an efficient way to compute a moving average?
<p>I've some <code>{open|high|low|close}</code> market data. I want to compute a Simple Moving Average from the <code>close</code> value of each row.</p>

<p>I've had a look around and couldn't find a simple way to do this. I've computed it via the below method. I want to know if there is a better way:</p>

<pre><code>data = get_data_period_symbol('1h', 'EURUSD')

empty_list = np.zeros(len(data))

data['SMA10'] = empty_list
ma = 10

for i in range(ma-1, len(data)):
    vals = data['&lt;CLOSE&gt;'][i-(ma-1):i+1].tolist()
    mean = np.average(vals)
    index = data.index[i]
    data.set_value(index, 'SMA10', mean)
</code></pre>

<p>Pandas provides all the tools you'll need for this kind of thing. 
Assuming you have your data indexed by time:</p>

<pre><code>data['SMA10'] = data['&lt;close&gt;'].rolling(window=10).mean()
</code></pre>

<p>Voila. </p>

<p>Edit:
I suppose just note the newer api usage. Quoting from the <a href="http://pandas.pydata.org/pandas-docs/stable/computation.html#rolling-windows" rel="nofollow">Pandas docs</a>:</p>

<blockquote>
  <p>Warning Prior to version 0.18.0, pd.rolling_<em>, pd.expanding_</em>, and pd.ewm* were module level functions and are now deprecated. These are replaced by using the Rolling, Expanding and EWM. objects and a corresponding method call.</p>
</blockquote>

python pandas dataframe moving-average