mirror of
https://github.com/metafy-social/python-scripts.git
synced 2025-01-18 07:17:03 +00:00
tests
This commit is contained in:
parent
05bd8134f2
commit
e621542883
|
@ -2,18 +2,32 @@ import pandas as pd
|
|||
import yfinance as yf
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
ticker = input('Stock Symbol: ')
|
||||
start_date = input('Start Date (YYYY-MM-DD): ')
|
||||
end_date = input('End Date (YYYY-MM-DD): ')
|
||||
def get_df(ticker, start_date, end_date):
|
||||
stock = yf.Ticker(ticker)
|
||||
df = stock.history(start=start_date, end=end_date)
|
||||
return df
|
||||
|
||||
def plot(df, ticker):
|
||||
plt.figure(figsize=(14, 8))
|
||||
plt.plot(df['Close'])
|
||||
plt.title(f'{ticker} Stock Price')
|
||||
plt.xlabel('Date')
|
||||
plt.ylabel('Price (USD)')
|
||||
plt.grid()
|
||||
plt.show()
|
||||
|
||||
def user_input():
|
||||
ticker = input('Stock Symbol: ')
|
||||
start_date = input('Start Date (YYYY-MM-DD): ')
|
||||
end_date = input('End Date (YYYY-MM-DD): ')
|
||||
return ticker, start_date, end_date
|
||||
|
||||
def stock_visualizer():
|
||||
ticker, start_date, end_date = user_input()
|
||||
df = get_df(ticker, start_date, end_date)
|
||||
plot(df, ticker)
|
||||
|
||||
|
||||
|
||||
stock = yf.Ticker(ticker)
|
||||
df = stock.history(start=start_date, end=end_date)
|
||||
|
||||
plt.figure(figsize=(14, 8))
|
||||
plt.plot(df['Close'])
|
||||
plt.title(f'{ticker} Stock Price')
|
||||
plt.xlabel('Date')
|
||||
plt.ylabel('Price (USD)')
|
||||
plt.grid()
|
||||
plt.show()
|
||||
|
||||
|
|
18
scripts/StockVisualizer/tests/tests.py
Normal file
18
scripts/StockVisualizer/tests/tests.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
import yfinance as yf
|
||||
from stock import (
|
||||
get_df,
|
||||
plot,
|
||||
user_input,
|
||||
stock_visualizer
|
||||
)
|
||||
|
||||
def test_df():
|
||||
stock = yf.Ticker("MSFT")
|
||||
assert (get_df(stock, "2023-01-01", "2023-02-01") != None)
|
||||
|
||||
def test_plot():
|
||||
stock = yf.Ticker("MSFT")
|
||||
df = get_df(stock, "2023-01-01", "2023-02-01")
|
||||
assert(plot(df, stock) != None)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user