This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sent = list() | |
| for i in tot_val: | |
| sent.append(get_sent(i)) | |
| tick_df['sentiment'] = sent | |
| tick_df.head(20) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_sent(val): | |
| agg = 0 | |
| for i in val: | |
| if i == 'positive': | |
| agg = agg + 1 | |
| elif i == 'negative': | |
| agg = agg - 1 | |
| if agg > 0: | |
| return('positive') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def detect(news): | |
| tot_val = list() | |
| for n in news: | |
| if len(n) == 0: | |
| tot_val.append(['neutral']) | |
| else: | |
| inputs = tokenizer(n, return_tensors="pt", padding=True) | |
| outputs = finbert(**inputs)[0] | |
| val = list() | |
| for idx, sent in enumerate(n): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| news = list() | |
| for i, tick in enumerate(tick_df['tick']): | |
| url = "https://www.tickertape.in/stocks/" + tick + "/news?checklist=basic&ref=stock-overview_overview-sections&type=news" | |
| headlines = get_data(url) | |
| news.append(headlines) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_data(url): | |
| req = Request(url=url,headers={"User-Agent": "Chrome"}) | |
| response = urlopen(req).read() | |
| html = BeautifulSoup(response,"html.parser") | |
| news_table = html.find(class_ = 'latest-news-holder') | |
| news = list() | |
| for name_box in news_table.find_all('p', class_='shave-root'): | |
| news.append(name_box.text.strip()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| url = "https://www.tickertape.in/stocks" | |
| tick_df = get_ticks(url) | |
| tick_df.head() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_ticks(url): | |
| req = Request(url=url,headers={"User-Agent": "Chrome"}) | |
| response = urlopen(req) | |
| html = BeautifulSoup(response,"html.parser") | |
| ticks_table = html.find(class_ = 'page') | |
| ticks = list() | |
| stocks = list() | |
| for name_box in ticks_table.find_all('a', href = True): | |
| stocks.append(name_box.text.strip()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from bs4 import BeautifulSoup | |
| import pandas as pd | |
| from urllib.request import urlopen, Request |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from sklearn.metrics import accuracy_score | |
| print(accuracy_score(y, sent_val)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sent_val = list() | |
| for x in X: | |
| inputs = tokenizer(x, return_tensors="pt", padding=True) | |
| outputs = finbert(**inputs)[0] | |
| val = labels[np.argmax(outputs.detach().numpy())] | |
| print(x, '----', val) | |
| print('#######################################################') | |
| sent_val.append(val) |
NewerOlder