forked from NickDeMiceli20/StockGPT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewssentiment.py
80 lines (53 loc) · 4.79 KB
/
newssentiment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from langchain import PromptTemplate
from langchain import OpenAI
from langchain import LLMChain
from config import OPENAI_API_KEY
import os
import streamlit as st
os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY
# App explanation
st.title("News Sentiment")
st.caption("This app analyzes news sentiment to predict a stock's expected future performance over both the short- and long-term.")
url = st.text_input(label="News Article")
stock = st.text_input(label="Target Company/Ticker")
# open domains = SeekingAlpha, Reuters, TechCrunch
template = """
You are a financial expert with investment recommendation experience.
Your client provides a {url} to a recent news article along with the {stock} they want you to analyze. Open the {url}, read the article's contents, and analyze its implications on the stock's future price performance.
Based on your analysis, create a numerical sentiment score for {stock} that ranges from -1 to +1, where -1 represents strong negative sentiment and +1 represents strong positive sentiment. You can use decimals between -1 and +1 for somewhat negative and somewhat positive sentiment. If {stock} is not mentioned in the article or if there is not enough information to provide an accurate recommendation, state: "This article does not have enough information for me to provide an accurate recommendation."
After analyzing the article, provide a 150-word summary, and conclude with whether the user should buy or sell {stock}, as well as whether it should be held for the short- or long-term.
You should always provide Sentiment Score and Summary on new lines in you response.
url = https://www.reuters.com/business/energy/decarbonization-business-could-outgrow-oil-exxon-executive-2023-04-04/
stock = XOM
Output:
Sentiment Score: +1.0 Strong Positive Sentiment
Summary: Exxon Mobil CEO Darren Woods has claimed that the company's Low Carbon business has the potential to generate hundreds of billions of dollars in revenue and outperform traditional oil and gas as soon as a decade from now. The company's emerging energy transition strategy aims to tackle a multi-trillion dollar market in ten years or more, offering Exxon a more stable profile and predictable long-term contracts with customers looking to reduce their carbon footprint. The strategy focuses on reducing carbon emissions from Exxon's own operations while also exploring areas like carbon capture, hydrogen, and biofuels, which the company estimates could have a combined potential of $6.5 trillion by 2050, equivalent to the traditional oil and gas business. Exxon also signed a long-term agreement with Linde, adding a new client to its portfolio of companies willing to pay to decarbonize their operations. However, Exxon's energy transition strategy is reliant on regulatory and policy support for carbon pricing and the cost to abate greenhouse gas emissions. Therefore, my recommendation is to buy Exxon as the company's emerging Low Carbon business and strategy could be lucrative if executed effectively.
url = https://www.reuters.com/technology/alphabet-falls-report-samsung-considering-bing-default-search-engine-2023-04-17/
stock = GOOGL
Output:
Sentiment Score: -1.0 Strong Negative Sentiment
Summary: Shares of Alphabet Inc (GOOGL) dropped by as much as 4 percent following reports that Samsung is considering replacing Google with Microsoft-owned Bing as the default search engine on its devices. Google earns an estimated $3 billion in annual revenue from the Samsung contract, and another $20 billion is tied to a similar Apple contract that will be up for renewal this year. While Google responded to the report by saying it was working to bring new AI-powered features to Search without commenting on its association with Samsung, Wall Street fears the company could be falling behind Microsoft in a fast-moving AI race. Investors worry Google has become a lazy monopolist in search and that the potential costs tied to making Google Search more competitive than AI-powered Bing could also be a cause for concern. Therefore, my recommendation is to hold or sell GOOGL until there is more clarity on how Google can address the challenges to its search engine business.
url = https://www.reuters.com/markets/deals/madison-square-garden-sells-stake-hospitality-unit-tao-group-300-mln-2023-04-17/
stock = SMRT
Output:
Sentiment Score: N/A
Summary: This article does not have enough infomration for me to provide an accurate recommendation.
url = {url}
stock = {stock}
Output:
Sentiment Score:
Summary:
"""
prompt = PromptTemplate(
input_variables=['url', 'stock'],
template=template,
)
chatgpt_chain = LLMChain(
llm=OpenAI(temperature=0.25),
prompt=prompt,
verbose=True,
)
output = chatgpt_chain.predict(
url=url, stock=stock)
st.markdown(output)
print(output)