Skip to content

Commit

Permalink
scrape_tests4 upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
RodneyFinkel committed May 14, 2024
1 parent 605da2e commit fd7ee75
Show file tree
Hide file tree
Showing 24 changed files with 143 additions and 159 deletions.
Binary file added Figure_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Figure_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Figure_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __pycache__/stock2.cpython-311.pyc
Binary file not shown.
104 changes: 39 additions & 65 deletions metric_graphs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@




ticker_symbol = input('Please select ticker symbol: ')

def get_sp500_stocks(ticker_symbol):
Expand Down Expand Up @@ -49,7 +48,7 @@ def get_stock_price2(ticker):

def get_historical(ticker):
stock = yf.Ticker(ticker)
history = stock.history(start='2019-01-01', end='2024-04-24')
history = stock.history(start='2019-01-01', end='2024-05-04')
return history


Expand Down Expand Up @@ -94,83 +93,58 @@ def add_technical_indicators(data):

def plot_technical_indicators(prices, ticker):

# Set background color to an even darker grey
# plt.style.use('bmh')
plt.rcParams['figure.facecolor'] = '#333333' # Set figure background color
plt.rcParams['axes.facecolor'] = '#333333' # Set axes background color
plt.rcParams['grid.color'] = 'white' # Set gridlines color

fig, ax = plt.subplots(4, 1, figsize=(16, 10), dpi=100)

# Plot 20-day and 50-day moving averages
ax[0].plot(prices.index, prices['Close'], label='Close Price')
ax[0].plot(prices.index, prices['Close'], label='Close Price')
ax[0].plot(prices.index, prices['MA20'], label='20-day MA')
ax[0].plot(prices.index, prices['MA50'], label='50-day MA')
ax[0].fill_between(prices.index, prices['MA20'], prices['MA50'], alpha=0.35, color='gray', label='Moving Averages')
ax[0].set_title(f'{ticker}: Moving Averages')
ax[0].set_xlabel('Date')
ax[0].set_ylabel('Price')
ax[0].plot(prices.index, prices['Close'], label='Close Price', color='white') # Change color to white
ax[0].plot(prices.index, prices['MA20'], label='20-day MA', color='blue') # Change color to blue
ax[0].plot(prices.index, prices['MA50'], label='50-day MA', color='green') # Change color to green
ax[0].fill_between(prices.index, prices['MA20'], prices['MA50'], alpha=0.35, color='#555555', label='Moving Averages') # Change fill color to an even darker grey
ax[0].set_title(f'{ticker}: Moving Averages', color='white') # Set title color to white
ax[0].set_xlabel('Date', color='white') # Set xlabel color to white
ax[0].set_ylabel('Price', color='white') # Set ylabel color to white
ax[0].grid(True, color='black', linestyle='--') # Add gridlines
ax[0].legend()


# Set a dark theme
template = "plotly_dark"

# Create a subplot figure
fig = make_subplots(rows=2, cols=1, shared_xaxes=True, subplot_titles=[
f'{ticker}: Moving Averages',
f'{ticker}: Bollinger Bands'
])

# Plot 20-day and 50-day moving averages
fig.add_trace(go.Scatter(x=prices.index, y=prices['Close'], mode='lines', name='Close Price'), row=1, col=1)
fig.add_trace(go.Scatter(x=prices.index, y=prices['MA20'], mode='lines', name='20-day MA'), row=1, col=1)
fig.add_trace(go.Scatter(x=prices.index, y=prices['MA50'], mode='lines', name='50-day MA'), row=1, col=1)
fig.add_trace(go.Scatter(x=prices.index, y=prices['MA20'], fill='tonexty', fillcolor='rgba(128,128,128,0.3)', name='Moving Averages'), row=1, col=1)

# Plot Bollinger Bands
fig.add_trace(go.Scatter(x=prices.index, y=prices['Close'], mode='lines', name='Close Price'), row=2, col=1)
fig.add_trace(go.Scatter(x=prices.index, y=prices['UpperBand'], mode='lines', name='Upper Band'), row=2, col=1)
fig.add_trace(go.Scatter(x=prices.index, y=prices['LowerBand'], mode='lines', name='Lower Band'), row=2, col=1)
fig.add_trace(go.Scatter(x=prices.index, y=prices['UpperBand'], fill='tonexty', fillcolor='rgba(128,128,128,0.3)', name='Bollinger Bands'), row=2, col=1)

# Update layout for better appearance
fig.update_layout(
title=f'{ticker} Technical Indicators',
xaxis_rangeslider_visible=False,
template=template,
height=800,
showlegend=False,
paper_bgcolor='rgba(0,0,0,0)',
plot_bgcolor='rgba(0,0,0,0)',
)

# Show the figure
fig.show()

# Plot RSI
ax[1].plot(prices.index, prices['RSI'], label='RSI')
ax[1].plot(prices.index, prices['RSI'], label='RSI', color='cyan') # Change color to cyan
ax[1].axhline(y=70, color='r', linestyle='--', label='Overbought')
ax[1].axhline(y=30, color='g', linestyle='--', label='Oversold')
ax[1].set_title(f'{ticker}: RSI')
ax[1].set_xlabel('Date')
ax[1].set_ylabel('RSI')
ax[1].set_title(f'{ticker}: RSI', color='white') # Set title color to white
ax[1].set_xlabel('Date', color='white') # Set xlabel color to white
ax[1].set_ylabel('RSI', color='white') # Set ylabel color to white
ax[1].grid(True, color='black', linestyle='--') # Add gridlines
ax[1].legend()

# Plot MACD
ax[2].plot(prices.index, prices['MACD'], label='MACD')
ax[2].plot(prices.index, prices['signal'], label='Signal')
ax[2].set_title(f'{ticker}: MACD')
ax[2].set_xlabel('Date')
ax[2].set_ylabel('MACD')
ax[2].plot(prices.index, prices['MACD'], label='MACD', color='orange') # Change color to orange
ax[2].plot(prices.index, prices['signal'], label='Signal', color='yellow') # Change color to yellow
ax[2].set_title(f'{ticker}: MACD', color='white') # Set title color to white
ax[2].set_xlabel('Date', color='white') # Set xlabel color to white
ax[2].set_ylabel('MACD', color='white') # Set ylabel color to white
ax[2].grid(True, color='black', linestyle='--') # Add gridlines
ax[2].legend()



# Plot Bollinger Bands
ax[3].plot(prices.index, prices['Close'], label='Close Price')
ax[3].plot(prices.index, prices['UpperBand'], label='Upper Band')
ax[3].plot(prices.index, prices['LowerBand'], label='Lower Band')
ax[3].fill_between(prices.index, prices['LowerBand'], prices['UpperBand'], alpha=0.35, color='gray', label='Bollinger Bands')
ax[3].set_title(f'{ticker}: Bollinger Bands')
ax[3].set_xlabel('Date')
ax[3].set_ylabel('Price')
ax[3].plot(prices.index, prices['Close'], label='Close Price', color='magenta') # Change color to magenta
ax[3].plot(prices.index, prices['UpperBand'], label='Upper Band', color='blue') # Change color to blue
ax[3].plot(prices.index, prices['LowerBand'], label='Lower Band', color='green') # Change color to green
ax[3].fill_between(prices.index, prices['LowerBand'], prices['UpperBand'], alpha=0.35, color='#555555') # Change fill color to an even darker grey
ax[3].set_title(f'{ticker}: Bollinger Bands', color='white') # Set title color to white
ax[3].set_xlabel('Date', color='white') # Set xlabel color to white
ax[3].set_ylabel('Price', color='white') # Set ylabel color to white
ax[3].grid(True, color='black', linestyle='--') # Add gridlines
ax[3].legend()


# Set gridlines color to white
plt.gca().yaxis.grid(color='white')

plt.tight_layout()
plt.show()

Expand Down
18 changes: 9 additions & 9 deletions out/AAPL.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Date,Article sentiment,Article title,link,publisher
2024-05-05T15:13:11.000Z,Nan too long,,,
2024-05-05T15:00:24.000Z,Nan too long,,,
2024-05-05T11:38:35.000Z,Nan too long,,,
None,positive,"40.3% of Warren Buffett's $336 Billion Portfolio Is Invested in Apple. Should You Buy the Stock, Too?",https://finance.yahoo.com/m/7864c818-33f6-33e3-9f27-bc67b5f47d3d/40.3%25-of-warren-buffett%27s.html,Motley Fool
2024-05-05T08:09:22.000Z,Nan too long,,,
None,positive,"Got $5,000? These 3 Growth Stocks Are Near Their 52-Week Lows",https://finance.yahoo.com/m/ed9f9478-e417-3b9c-89c2-e17055c18bce/got-%245%2C000%3F-these-3-growth.html,Motley Fool
None,positive,These 7 Stocks Make Up 84% of Warren Buffett's $336 Billion Stock Portfolio,https://finance.yahoo.com/m/f48fa7f3-f0a1-372a-a949-889c2935e085/these-7-stocks-make-up-84%25-of.html,Motley Fool
2024-05-04T22:29:37.000Z,Nan too long,,,
Date,Article title,link,publisher,Article sentiment
None,"McDonald’s, Apple and Tesla can’t bet on making a fortune in China anymore",https://finance.yahoo.com/m/141e93ad-ddb1-3287-a8e6-368b90290b63/mcdonald%E2%80%99s%2C-apple-and-tesla.html,CNN Business,neutral
None,Is the Apple Vision Pro Headset Worth the Price?,https://finance.yahoo.com/m/83e94fbe-8429-36b8-a1bb-81fc268993cc/is-the-apple-vision-pro.html,Motley Fool,neutral
None,What Warren Buffett Is Selling and Saying,https://finance.yahoo.com/m/2ebdb434-9081-370b-9d3f-0b5b5dd08c14/what-warren-buffett-is.html,Motley Fool,neutral
None,"Meme trade roars back to life, OpenAI's GPT-4o: Market Domination",https://finance.yahoo.com/video/meme-trade-roars-back-life-215638232.html,Yahoo Finance Video,neutral
2024-05-13T21:40:29.000Z,,,,Nan too long
None,iPad Pro vs. MacBook: The Great Apple Laptop Trade-Off,https://finance.yahoo.com/m/2894d96f-6fe5-3b01-a64c-b1096dca1c7c/ipad-pro-vs.-macbook%3A-the.html,The Wall Street Journal,neutral
2024-05-13T20:48:42.000Z,Apple Reportedly Close To Deal With OpenAI To Add AI Features To iPhone,https://finance.yahoo.com/m/5134693b-177f-3676-a745-a6c437241cc7/apple-reportedly-close-to.html,Investor's Business Daily,negative
2024-05-13T20:47:44.000Z,,,,Nan too long
2 changes: 1 addition & 1 deletion out/AAPL.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"Date":"2024-05-05T15:13:11.000Z","Article sentiment":"Nan too long","Article title":null,"link":null,"publisher":null},{"Date":"2024-05-05T15:00:24.000Z","Article sentiment":"Nan too long","Article title":null,"link":null,"publisher":null},{"Date":"2024-05-05T11:38:35.000Z","Article sentiment":"Nan too long","Article title":null,"link":null,"publisher":null},{"Date":"None","Article sentiment":"positive","Article title":"40.3% of Warren Buffett's $336 Billion Portfolio Is Invested in Apple. Should You Buy the Stock, Too?","link":"https:\/\/finance.yahoo.com\/m\/7864c818-33f6-33e3-9f27-bc67b5f47d3d\/40.3%25-of-warren-buffett%27s.html","publisher":"Motley Fool"},{"Date":"2024-05-05T08:09:22.000Z","Article sentiment":"Nan too long","Article title":null,"link":null,"publisher":null},{"Date":"None","Article sentiment":"positive","Article title":"Got $5,000? These 3 Growth Stocks Are Near Their 52-Week Lows","link":"https:\/\/finance.yahoo.com\/m\/ed9f9478-e417-3b9c-89c2-e17055c18bce\/got-%245%2C000%3F-these-3-growth.html","publisher":"Motley Fool"},{"Date":"None","Article sentiment":"positive","Article title":"These 7 Stocks Make Up 84% of Warren Buffett's $336 Billion Stock Portfolio","link":"https:\/\/finance.yahoo.com\/m\/f48fa7f3-f0a1-372a-a949-889c2935e085\/these-7-stocks-make-up-84%25-of.html","publisher":"Motley Fool"},{"Date":"2024-05-04T22:29:37.000Z","Article sentiment":"Nan too long","Article title":null,"link":null,"publisher":null}]
[{"Date":"None","Article title":"McDonald\u2019s, Apple and Tesla can\u2019t bet on making a fortune in China anymore","link":"https:\/\/finance.yahoo.com\/m\/141e93ad-ddb1-3287-a8e6-368b90290b63\/mcdonald%E2%80%99s%2C-apple-and-tesla.html","publisher":"CNN Business","Article sentiment":"neutral"},{"Date":"None","Article title":"Is the Apple Vision Pro Headset Worth the Price?","link":"https:\/\/finance.yahoo.com\/m\/83e94fbe-8429-36b8-a1bb-81fc268993cc\/is-the-apple-vision-pro.html","publisher":"Motley Fool","Article sentiment":"neutral"},{"Date":"None","Article title":"What Warren Buffett Is Selling and Saying","link":"https:\/\/finance.yahoo.com\/m\/2ebdb434-9081-370b-9d3f-0b5b5dd08c14\/what-warren-buffett-is.html","publisher":"Motley Fool","Article sentiment":"neutral"},{"Date":"None","Article title":"Meme trade roars back to life, OpenAI's GPT-4o: Market Domination","link":"https:\/\/finance.yahoo.com\/video\/meme-trade-roars-back-life-215638232.html","publisher":"Yahoo Finance Video","Article sentiment":"neutral"},{"Date":"2024-05-13T21:40:29.000Z","Article title":null,"link":null,"publisher":null,"Article sentiment":"Nan too long"},{"Date":"None","Article title":"iPad Pro vs. MacBook: The Great Apple Laptop Trade-Off","link":"https:\/\/finance.yahoo.com\/m\/2894d96f-6fe5-3b01-a64c-b1096dca1c7c\/ipad-pro-vs.-macbook%3A-the.html","publisher":"The Wall Street Journal","Article sentiment":"neutral"},{"Date":"2024-05-13T20:48:42.000Z","Article title":"Apple Reportedly Close To Deal With OpenAI To Add AI Features To iPhone","link":"https:\/\/finance.yahoo.com\/m\/5134693b-177f-3676-a745-a6c437241cc7\/apple-reportedly-close-to.html","publisher":"Investor's Business Daily","Article sentiment":"negative"},{"Date":"2024-05-13T20:47:44.000Z","Article title":null,"link":null,"publisher":null,"Article sentiment":"Nan too long"}]
9 changes: 9 additions & 0 deletions out/AMZN.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Date,Article title,link,publisher,Article sentiment
None,"Top 4 ""Secret"" Artificial Intelligence (AI) Stocks You Should Know",https://finance.yahoo.com/m/5c6af639-3aa0-3aad-8d44-74819262da42/top-4-%22secret%22-artificial.html,Motley Fool,negative
None,Here's How Amazon Stock Benefits From the Artificial Intelligence (AI) Investing Frenzy,https://finance.yahoo.com/m/41c2613a-c699-3706-9020-70d645363dea/here%27s-how-amazon-stock.html,Motley Fool,negative
None,1 Warren Buffett Stock That Could Go Parabolic in 2024,https://finance.yahoo.com/m/7fb3967d-b096-3360-b798-48c25d3a087a/1-warren-buffett-stock-that.html,Motley Fool,negative
None,1 Stock I Wouldn't Touch With a 10-Foot Pole -- and Here's Why,https://finance.yahoo.com/m/37f5d981-4532-300f-bccc-13c15e7ac1c1/1-stock-i-wouldn%27t-touch-with.html,Motley Fool,negative
None,Amazon Stock Is at an Inflection Point. It's Time to Buy the Stock Like There's No Tomorrow.,https://finance.yahoo.com/m/591e47a8-8cab-3e95-b999-ecd5cea4e20c/amazon-stock-is-at-an.html,Motley Fool,negative
None,40.2% of Warren Buffett's $362 Billion Portfolio Is Invested in 2 Artificial Intelligence (AI) Stocks,https://finance.yahoo.com/m/59364185-3d9a-37c4-963c-a81771928ddf/40.2%25-of-warren-buffett%27s.html,Motley Fool,negative
None,Best Stock to Buy Right Now: Amazon vs. Apple,https://finance.yahoo.com/m/15be9fa0-15ec-3f14-801c-78826b6bf674/best-stock-to-buy-right-now%3A.html,Motley Fool,negative
2024-05-10T23:39:54.000Z,,,,Nan too long
1 change: 1 addition & 0 deletions out/AMZN.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"Date":"None","Article title":"Top 4 \"Secret\" Artificial Intelligence (AI) Stocks You Should Know","link":"https:\/\/finance.yahoo.com\/m\/5c6af639-3aa0-3aad-8d44-74819262da42\/top-4-%22secret%22-artificial.html","publisher":"Motley Fool","Article sentiment":"negative"},{"Date":"None","Article title":"Here's How Amazon Stock Benefits From the Artificial Intelligence (AI) Investing Frenzy","link":"https:\/\/finance.yahoo.com\/m\/41c2613a-c699-3706-9020-70d645363dea\/here%27s-how-amazon-stock.html","publisher":"Motley Fool","Article sentiment":"negative"},{"Date":"None","Article title":"1 Warren Buffett Stock That Could Go Parabolic in 2024","link":"https:\/\/finance.yahoo.com\/m\/7fb3967d-b096-3360-b798-48c25d3a087a\/1-warren-buffett-stock-that.html","publisher":"Motley Fool","Article sentiment":"negative"},{"Date":"None","Article title":"1 Stock I Wouldn't Touch With a 10-Foot Pole -- and Here's Why","link":"https:\/\/finance.yahoo.com\/m\/37f5d981-4532-300f-bccc-13c15e7ac1c1\/1-stock-i-wouldn%27t-touch-with.html","publisher":"Motley Fool","Article sentiment":"negative"},{"Date":"None","Article title":"Amazon Stock Is at an Inflection Point. It's Time to Buy the Stock Like There's No Tomorrow.","link":"https:\/\/finance.yahoo.com\/m\/591e47a8-8cab-3e95-b999-ecd5cea4e20c\/amazon-stock-is-at-an.html","publisher":"Motley Fool","Article sentiment":"negative"},{"Date":"None","Article title":"40.2% of Warren Buffett's $362 Billion Portfolio Is Invested in 2 Artificial Intelligence (AI) Stocks","link":"https:\/\/finance.yahoo.com\/m\/59364185-3d9a-37c4-963c-a81771928ddf\/40.2%25-of-warren-buffett%27s.html","publisher":"Motley Fool","Article sentiment":"negative"},{"Date":"None","Article title":"Best Stock to Buy Right Now: Amazon vs. Apple","link":"https:\/\/finance.yahoo.com\/m\/15be9fa0-15ec-3f14-801c-78826b6bf674\/best-stock-to-buy-right-now%3A.html","publisher":"Motley Fool","Article sentiment":"negative"},{"Date":"2024-05-10T23:39:54.000Z","Article title":null,"link":null,"publisher":null,"Article sentiment":"Nan too long"}]
6 changes: 3 additions & 3 deletions out/GE.csv
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
Date,Article sentiment,Article title,link,publisher
2024-05-13T10:20:06.000Z,Nan too long,,,
2024-05-10T13:24:03.000Z,Nan too long,,,
None,neutral,Spin-Off Stocks Surprise to Start 2nd Quarter,https://finance.yahoo.com/news/spin-off-stocks-surprise-start-213937835.html,GuruFocus.com
2024-05-08T16:57:01.000Z,negative,GE Aerospace Cruises At A 15-Year High — Is GE Stock A Buy?,https://finance.yahoo.com/m/67528bb6-55dd-307c-ba1e-c2b1ae97aa0e/ge-aerospace-cruises-at-a.html,Investor's Business Daily
2024-05-08T16:57:01.000Z,neutral,GE Aerospace Cruises At A 15-Year High — Is GE Stock A Buy?,https://finance.yahoo.com/m/67528bb6-55dd-307c-ba1e-c2b1ae97aa0e/ge-aerospace-cruises-at-a.html,Investor's Business Daily
2024-05-08T10:48:10.000Z,Nan too long,,,
2024-05-07T17:03:54.000Z,Nan too long,,,
None,neutral,"If You'd Invested $10,000 in General Electric Stock 10 Years Ago, Here's How Much You'd Have Today",https://finance.yahoo.com/m/ee99007e-60d3-3b2c-8be7-eb03921cebc7/if-you%27d-invested-%2410%2C000-in.html,Motley Fool
2024-05-06T19:15:25.000Z,Nan too long,,,
None,neutral,Is GE Aerospace Stock Going to $185? 1 Wall Street Analyst Thinks So.,https://finance.yahoo.com/m/431afbdc-b95a-3d87-bcc4-830c8ebaefd1/is-ge-aerospace-stock-going.html,Motley Fool
None,neutral,"GE Aerospace Stock Has 17% Upside, According to 1 Wall Street Analyst",https://finance.yahoo.com/m/c1f49104-cd1d-3355-8bcf-4039d25a829f/ge-aerospace-stock-has-17%25.html,Motley Fool
Loading

0 comments on commit fd7ee75

Please sign in to comment.