0

I am trying to create multiple moving averages using TA-lib to loop through different securities.

I have this dataframe:

               AAPL US Equity  MSFT US Equity
date                                      
2018-05-31          186.87           98.84
2018-06-01          190.24          100.79
2018-06-04          191.83          101.67
2018-06-05          193.31          102.19
2018-06-06          193.98          102.49

Require:

 date          AAPL US Equity  MSFT US Equity  AAPL SMA50   AAPL SMA200   MSFT SMA50                                      
 2018-05-31          186.87           98.84     ..            ..                ..
 2018-06-01          190.24          100.79     ..            ..                ..
 2018-06-04          191.83          101.67     ..            ..                ..
 2018-06-05          193.31          102.19     ..            ..                ..
 2018-06-06          193.98          102.49     ..            ..                ..

I have tried this link here which converts the dataframe but this does not work:

 df.apply(lambda c: talib.EMA(c, 2))

1 Answers1

0

df.apply(lambda c: talib.EMA(c, 2))

This applies the function to each of the values of df... What you want to do is probably something like:

data_in_array_form = df['MSFT US Equity'].values
print (talib.EMA(data_in_array_form))
ntg
  • 12,950
  • 7
  • 74
  • 95