0
from nsepy import get_history
import datetime as date
import pdb
import talib

watchlist = ['ACC', 'VEDL']

for name in watchlist:

    df = get_history(symbol=name, start=date(2020,1,1), end=date.today())


    if df.empty:
        continue

    df['MA50'] = talib.MA(df['Close'], timeperiod=50, matype=0) 
    df['MA200'] = talib.MA(df['Close'], timeperiod=200, matype=0)

    MA50 = df.iloc[-1]['MA50']
    MA200 = df.iloc[-1]['MA200']

    if (MA50 > MA200):
        print(name, 'BUY')

    elif (MA50 < MA200):
        Print(name, 'SELL')

    else:
        print(name, 'IGNORE')
2
  • A more popular way to abbreviate the module is import datetime as dt. Its also popular to just import the classes you want, like from datetime import date (that's how the module's doc does it). Commented Aug 29, 2021 at 4:38
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. Commented Aug 31, 2021 at 10:49

1 Answer 1

2

Regarding:

import datetime as date

This imports the datetime module, renaming it date in the current context.

However, that module has a date class inside it, with a constructor for a date, which is probably what you wanted. Ditto for the today() member function.

Both of these are part of the datetime.date class, not part of the datetime module (renamed as date).

It's likely you want to do this instead:

from datetime import date

This will bring the date class into you current context, rather than the datetime module renamed as date.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.