Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import yfinance as yf
- import pandas as pd
- import datetime
- from datetime import date
- import numpy as np
- import matplotlib.pyplot as plt
- from dateutil.relativedelta import relativedelta
- import os
- from readable_table import print_info
- from readable_table import print_table
- #for-use-function
- #grahp colors (rgba 1,1,1 ratio)
- colors = [(0.2, 1, 0.2, 1)]
- def save_pic(pricegraph):
- pricefig = pricegraph.get_figure()
- pricefig.savefig('image1'+'.png')
- print('Save รูป Graph ราคา')
- return
- #declare-basic-function
- def delete_graph_pic(files):
- if os.path.exists(files):
- os.remove(files)
- return
- else:
- print(files, "does not exist")
- def get_stock_price_history_and_plot_graph(ticker, range, timeframe):
- try:
- thisday = date.today()
- if (timeframe.lower() == "y"):
- start = thisday - relativedelta(years=int(range))
- _ticker = yf.download((ticker.lower()+'.bk'), start, thisday)
- pricegraph = _ticker['Adj Close'].plot(color=colors)
- save_pic(pricegraph)
- return
- elif(timeframe.lower() == "m"):
- start = thisday - relativedelta(months=int(range))
- _ticker = yf.download((ticker.lower()+'.bk'), start, thisday)
- pricegraph = _ticker['Adj Close'].plot(color=colors)
- save_pic(pricegraph)
- return
- elif(timeframe.lower() == "d"):
- start = thisday - relativedelta(days=int(range))
- _ticker = yf.download((ticker.lower()+'.bk'), start, thisday)
- pricegraph = _ticker['Adj Close'].plot(color=colors)
- save_pic(pricegraph)
- return
- except ValueError:
- print('Error Some Shit in Data data_visualization : get_stock_price_history_and_plot_graph')
- return
- def get_Stock(ticker, range, timeframe):
- get_stock_price_history_and_plot_graph(ticker, range, timeframe)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement