Sep-29-2020, 03:42 PM
(This post was last modified: Sep-29-2020, 03:42 PM by sambanerjee.)
Sorry missed the imports and the initializations -- here you go
import import_ipynb import talib import numpy import yfinance as yf import datetime as dt import time from datetime import datetime, timedelta import sqlite3 import pandas as pd import numpy as np conn = sqlite3.connect('Strategy_RSI_MACD_Data.db') c = conn.cursor() c.execute("select DISTINCT Symbol from StockData") tickers = c.fetchall() for row in tickers: c.execute("select [Adj Close] from StockData where Symbol = ? ", (row)) AdjClose = c.fetchall() df_ta = pd.DataFrame(data = AdjClose, dtype=numpy.float64) df_ta = df_ta.apply(lambda c: talib.RSI(c, timeperiod = 14)) for index, item in df_ta.iterrows(): try: c.execute('''UPDATE StockData SET RSI = ? where Symbol = ? ''', (item.values, row)) except Exception as e: print('Update Error: ' + str(e)) print('Updated' + str(row)) conn.commit() print ("Number of rows updated: {}".format(c.rowcount))