from ta.utils import dropna from ta.volatility import BollingerBands from ta.trend import EMAIndicator from ta.trend import SMAIndicator from ta.trend import MACD from ta.momentum import RSIIndicator from db.model import * from download import * from db.dao.equity_dao import StocksDao import traceback if __name__ == '__main__': exchange='HEX' dao = StocksDao() equity_ref_df = dao.get_all_stocks(exchange) eod_df = dao.get_all_stocks_prices(exchange) # Calac data last_entry_df = dao.get_all_stocks_prices_max_entry_date(exchange) last_entry_dict = dict(zip(last_entry_df['equity_id'].tolist(), last_entry_df['last_entry'].tolist())) for idx1, row1 in equity_ref_df.iterrows(): equity_id = row1['equity_id'] ticker = row1['local_code'] try: insert_list = list() # get all the prices for equity ticker_eod_df = eod_df[eod_df['equity_id'] == equity_id] ticker_eod_df = ticker_eod_df.sort_values(by=['trading_date']) df = dropna(ticker_eod_df)
from db.model import * from download import * from db.dao.equity_dao import StocksDao import traceback import PyDSWS import datetime as dt from constants import * if __name__ == '__main__': exchange = NASDAQ # start_date = '20160101' start_date = (dt.datetime.now() - dt.timedelta(days=5)).strftime('%Y%m%d') end_date = dt.date.today().strftime('%Y%m%d') dao = StocksDao() equity_ref_df = dao.get_all_stocks(exchange) conn = PyDSWS.Datastream(username='******', password='******') for idx1, row1 in equity_ref_df.iterrows(): ticker = row1['ds_code'] equity_id = row1['equity_id'] try: insert_list = list() data = conn.get_data(tickers=ticker, fields=['RECMED', 'RECNO', 'RECCON'], start=start_date, end=end_date) data.fillna(0, inplace=True) data_df = data[ticker]
from db.model import * from download import * from db.dao.equity_dao import StocksDao import traceback if __name__ == '__main__': exchange = 'SGX' trade_date = '2021-05-25' dao = StocksDao() stock_info_df = dao.get_stock_info_by_date(exchange, trade_date) stock_info_df['range'] = ( (stock_info_df['adj_close'] - stock_info_df['ema_200']) / stock_info_df['ema_200']) * 100 report_df = stock_info_df[(stock_info_df['range'] <= 10) & (stock_info_df['anr_med'] <= 3.0)] report_df['reco'] = report_df['rsi_14'].apply(lambda x: 'HOT-BUYS' if x <= 40 else 'COLD-BUY') report_df = report_df.sort_values( by=['reco', 'anr_med', 'anr_count', 'range'], ascending=False) report_df.to_csv('reco_{}_{}.csv'.format(exchange, trade_date)) print(report_df) print('Done')