Spaces:
Runtime error
Runtime error
Update app.py
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566import gradio as grimport matplotlib.pyplot as pltimport numpy as npimport timeimport yfinance as yfimport pandas as pdimport matplotlib.pyplot as pltfrom datetime import datetime, timedelta# ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐdef fetch_data():end_date = datetime.now()start_date = end_date - timedelta(days=5 * 365)# ๋ฏธ๊ตญ์ 10๋ ๋ฌผ ๊ตญ์ฑ ์์ต๋ฅ ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐus_interest_rate_data = yf.download('^TNX', start=start_date.strftime('%Y-%m-%d'), end=end_date.strftime('%Y-%m-%d'))us_interest_rate_daily = us_interest_rate_data['Close']# ๋ฐ์ด๋ธ์ค ์ฝ์ธ ๊ฐ๊ฒฉ ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐbnb_data = yf.download('BNB-USD', start=start_date.strftime('%Y-%m-%d'), end=end_date.strftime('%Y-%m-%d'))bnb_daily = bnb_data['Close']return us_interest_rate_daily, bnb_daily# ๋ฐ์ดํฐ ์ ๊ทํdef normalize_data(data):return (data - data.min()) / (data.max() - data.min())# ๋ฐ์ดํฐ ๋ถ์ ๋ฐ ๊ทธ๋ํ ์์ฑdef plot_data(interest_rate_data, bnb_prices):# ๋ฐ์ดํฐ ์ ๊ทํinterest_rate_normalized = normalize_data(interest_rate_data)bnb_normalized = normalize_data(bnb_prices)# ๋ ๋ฐ์ดํฐ์ ์ฐจ์ด ๊ณ์ฐ ๋ฐ ์ ๊ทํdiff_normalized = normalize_data(bnb_normalized - interest_rate_normalized)# ๊ฒ์์ ์ ์ ๊ทธ๋ฆด ๊ตฌ๊ฐ ์ค์ threshold = 0.5plt.figure(figsize=(14, 7))plt.plot(diff_normalized, color='green', label='Normalized Difference (Binance Coin Price - US 10-Year Treasury Yield)')# ๊ฒ์์ ์ ์ ๊ทธ๋ฆด ๊ตฌ๊ฐ ์ค์ plt.axhline(y=threshold, color='black', linestyle='--', label=f'Normalized Value: {threshold}')# ๋ฐฐ๊ฒฝ์ ์ค์ plt.axhspan(0.0, 0.2, color='blue', alpha=0.3)plt.axhspan(0.2, 0.4, color='lightblue', alpha=0.3)plt.axhspan(0.4, 0.5, color='skyblue', alpha=0.3)plt.axhspan(0.5, 0.6, color='yellow', alpha=0.3)plt.axhspan(0.6, 0.8, color='orange', alpha=0.3)plt.axhspan(0.8, 1.0, color='red', alpha=0.3)plt.title('Difference between Binance Coin Price and US 10-Year Treasury Yield')plt.xlabel('Date')plt.ylabel('Normalized Value')plt.legend()plt.grid(True)plt.show()if __name__ == "__main__":interest_rate_data, bnb_prices = fetch_data()plot_data(interest_rate_data, bnb_prices)iface = gr.Interface(fn=live_chart, inputs=[], outputs="plot", live=True, title="Live Sine Wave Chart")iface.launch()1234567891011121314151617181920212223242526272829303132333435363738394041424344import yfinance as yfimport pandas as pdimport matplotlib.pyplot as pltfrom datetime import datetime, timedeltaimport gradio as grdef fetch_data():end_date = datetime.now()start_date = end_date - timedelta(days=5 * 365)us_interest_rate_data = yf.download('^TNX', start=start_date.strftime('%Y-%m-%d'), end=end_date.strftime('%Y-%m-%d'))bnb_data = yf.download('BNB-USD', start=start_date.strftime('%Y-%m-%d'), end=end_date.strftime('%Y-%m-%d'))return us_interest_rate_data['Close'], bnb_data['Close']def normalize_data(data):return (data - data.min()) / (data.max() - data.min())def plot_data(interest_rate_data, bnb_prices):interest_rate_normalized = normalize_data(interest_rate_data)bnb_normalized = normalize_data(bnb_prices)diff_normalized = normalize_data(bnb_normalized - interest_rate_normalized)plt.figure(figsize=(14, 7))plt.plot(diff_normalized, color='green', label='Normalized Difference (BNB Price - US 10-Year Treasury Yield)')plt.axhline(y=0.5, color='black', linestyle='--')plt.axhspan(0.0, 0.2, color='blue', alpha=0.3)plt.axhspan(0.2, 0.4, color='lightblue', alpha=0.3)plt.axhspan(0.4, 0.5, color='skyblue', alpha=0.3)plt.axhspan(0.5, 0.6, color='yellow', alpha=0.3)plt.axhspan(0.6, 0.8, color='orange', alpha=0.3)plt.axhspan(0.8, 1.0, color='red', alpha=0.3)plt.title('Difference between Binance Coin Price and US 10-Year Treasury Yield')plt.xlabel('Date')plt.ylabel('Normalized Value')plt.legend()plt.grid(True)plt.close()return pltdef run_app():interest_rate_data, bnb_prices = fetch_data()return plot_data(interest_rate_data, bnb_prices)iface = gr.Interface(fn=run_app, outputs="plot", title="Financial Data Comparison")iface.launch()
app.py+10-32