title: Python function for MA and MACD has "ValueError: negative dimensions are not allowed"
body: <p>I am trying to analyze historical data in csv using pandas.I found from <a href="https://www.quantopian.com/posts/technical-analysis-indicators-without-talib-code" rel="nofollow">Quantopian</a> that without talib (fail to install), we can use the functions code to analyze.  However, when I anlayze using MA an MACD function, I encounter 
  1. MA not calculate correctly
  2. MACD part has  "ValueError: negative dimensions are not allowed"
  which part should I corrected it?</p>
  
  <p>My code is as following:</p>
  
  <pre><code>import numpy  
  import pandas as pd
  
  #Moving Average  
  def MA(df, n):  
      MA = pd.Series(pd.rolling_mean(df['Close'], n), name = 'MA_' + str(n))  
      df = df.join(MA)  
      return df
  
  #MACD, MACD Signal and MACD difference  
  def MACD(df, n_fast, n_slow):  
      EMAfast = pd.Series(pd.ewma(df['Close'], span = n_fast, min_periods = n_slow - 1))  
      EMAslow = pd.Series(pd.ewma(df['Close'], span = n_slow, min_periods = n_slow - 1))  
      MACD = pd.Series(EMAfast - EMAslow, name = 'MACD_' + str(n_fast) + '_' + str(n_slow))  
      MACDsign = pd.Series(pd.ewma(MACD, span = 9, min_periods = 8), name = 'MACDsign_' + str(n_fast) + '_' + str(n_slow))  
      MACDdiff = pd.Series(MACD - MACDsign, name = 'MACDdiff_' + str(n_fast) + '_' + str(n_slow))  
      df = df.join(MACD)  
      df = df.join(MACDsign)  
      df = df.join(MACDdiff)  
      return df
  
  
  data = pd.read_csv("NAIM.csv", index_col='Stock', usecols =[0,6])
  
  print data.head(3)
  vol = data['Close']
  print vol
  print MA(data,5)
  print MACD(data,12,26)
  </code></pre>
  
  <p>the csv file is as below:</p>
  
  <pre><code>Stock,Date,Time,Open,High,Low,Close,Volume
  NAIM,2015-01-02,00:00:00,2.9,3.0,2.9,3.0,46900
  NAIM,2015-01-05,00:00:00,2.95,3.05,2.92,3.05,225900
  NAIM,2015-01-06,00:00:00,2.95,2.96,2.9,2.9,682000
  NAIM,2015-01-07,00:00:00,2.88,2.95,2.88,2.9,160900
            .
            .
            .
  NAIM,2016-01-06,00:00:00,2.48,2.61,2.47,2.6,3260900
  NAIM,2016-01-07,00:00:00,2.64,2.74,2.6,2.65,3906100
  NAIM,2016-01-08,00:00:00,2.65,2.71,2.62,2.64,1875000
  NAIM,2016-01-11,00:00:00,2.65,2.7,2.65,2.68,1089400
  NAIM,2016-01-12,00:00:00,2.68,2.71,2.65,2.69,965200
  NAIM,2016-01-13,00:00:00,2.69,2.74,2.69,2.73,2091500
  NAIM,2016-01-14,00:00:00,2.71,2.71,2.66,2.66,1206000
  NAIM,2016-01-15,00:00:00,2.66,2.67,2.62,2.62,738600
  </code></pre>
  
  <p>My python shell shown the output:</p>
  
  <p><a href="http://i.stack.imgur.com/VVpQM.jpg" rel="nofollow">Output from Python Shell after run the script</a></p>