The Relationship between news and stocks 9
2022. 7. 26. 00:36ㆍProject/뉴스기사로 인한 주가 등락 예측
728x90
반응형
코드
시장 활성화 시간을 13시 30분 -> 18시로 조정
import datetime
from datetime import time
from datetime import timedelta
for i in tqdm(range(len(news))):
if len(df.loc[(df["stock_id"] == news.loc[i][0]) & (df["date"] == news.loc[i][2].date())]) == 0:
for j in range(1, 7):
if len(df.loc[(df["stock_id"] == news.loc[i][0]) & (df["date"] == (news.loc[i][2] + timedelta(days=j)).date())]) == 0:
continue
news.loc[i, 'label'] = int(df.loc[(df["stock_id"] == news.loc[i][0]) & (df["date"] == (news.loc[i][2] + timedelta(days=j)).date())]['label2'])
continue
if news.loc[i][2].weekday() == 4 and news.loc[i][2].time() > datetime.time(18,0):
for j in range(1, 7):
if len(df.loc[(df["stock_id"] == news.loc[i][0]) & (df["date"] == (news.loc[i][2] + timedelta(days=j)).date())]) == 0:
continue
news.loc[i, 'label'] = int(df.loc[(df["stock_id"] == news.loc[i][0]) & (df["date"] == (news.loc[i][2] + timedelta(days=j)).date())]['label2'])
elif news.loc[i][2].weekday() == 4 and news.loc[i][2].time() <= datetime.time(18,0):
news.loc[i, 'label'] = int(df.loc[(df["stock_id"] == news.loc[i][0]) & (df["date"] == news.loc[i][2].date())]['label1'])
else:
if news.loc[i][2].time() > datetime.time(18):
news.loc[i, 'label'] = int(df.loc[(df["stock_id"] == news.loc[i][0]) & (df["date"] == news.loc[i][2].date())]['label2'])
elif news.loc[i][2].time() <= datetime.time(18):
news.loc[i, 'label'] = int(df.loc[(df["stock_id"] == news.loc[i][0]) & (df["date"] == news.loc[i][2].date())]['label1'])
728x90
반응형
'Project > 뉴스기사로 인한 주가 등락 예측' 카테고리의 다른 글
The Relationship between news and stocks 11 (0) | 2022.07.28 |
---|---|
The Relationship between news and stocks 10 (0) | 2022.07.26 |
The Relationship between news and stocks 8 (0) | 2022.07.22 |
The Relationship between news and stocks 7 (0) | 2022.07.22 |
The Relationship between news and stocks 6 (0) | 2022.07.22 |