Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NameError: name 'ema' is not defined #8

Open
akitxu opened this issue Apr 16, 2022 · 0 comments
Open

NameError: name 'ema' is not defined #8

akitxu opened this issue Apr 16, 2022 · 0 comments

Comments

@akitxu
Copy link

akitxu commented Apr 16, 2022

Dear all. When executing the function that calculates the MACD, it gives me the following error show on the titlle.

`import pandas as pd
import yfinance as yf

def macd(data, period_long=26, period_short=12, period_signal=9, column='Close'):
remove_cols = []
if not 'ema' + str(period_long) in data.columns:
data = ema(data, period_long)
remove_cols.append('ema' + str(period_long))

if not 'ema' + str(period_short) in data.columns:
    data = ema(data, period_short)
    remove_cols.append('ema' + str(period_short))

data['macd_val'] = data['ema' + str(period_short)] - data['ema' + str(period_long)]
data['macd_signal_line'] = data['macd_val'].ewm(ignore_na=False, min_periods=0, com=period_signal, adjust=True).mean()

data = data.drop(remove_cols, axis=1)
    
return data

data = yf.download('AAPL', start= '2016-1-4', end = '2021-12-30')

data = macd(data, period_long=26, period_short=12, period_signal=9, column='Close')
data

NameError Traceback (most recent call last)
/tmp/ipykernel_12947/116451859.py in
21 data = yf.download('AAPL', start= '2016-1-4', end = '2021-12-30')
22
---> 23 data = macd(data, period_long=26, period_short=12, period_signal=9, column='Close')
24 data

/tmp/ipykernel_12947/116451859.py in macd(data, period_long, period_short, period_signal, column)
5 remove_cols = []
6 if not 'ema' + str(period_long) in data.columns:
----> 7 data = ema(data, period_long)
8 remove_cols.append('ema' + str(period_long))
9

NameError: name 'ema' is not defined`

I don't understand this error. I will appreciate clarification

I don't understand this error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant