Spaces:
Runtime error
Runtime error
Update app.py
Browse files123451234561178915101718191121222312132514151629173118193435202138392241424344454623242526272829305331323334355936373861394063414265664344import gradio as grimport matplotlib.pyplot as pltimport numpy as npimport time
import yfinance as yfimport pandas as pdimport matplotlib.pyplot as pltfrom datetime import datetime, timedeltaimport gradio as gr
# ๋ฐ์ดํฐ ๊ฐ์ ธ์ค๊ธฐ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 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) # ๊ฒ์์ ์ ์ ๊ทธ๋ฆด ๊ตฌ๊ฐ ์ค์ threshold = 0.5 plt.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.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.show() plt.close() return plt
if __name__ == "__main__":def run_app(): interest_rate_data, bnb_prices = fetch_data() plot_data(interest_rate_data, bnb_prices) return 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()iface = gr.Interface(fn=run_app, outputs="plot", title="Financial Data Comparison")iface.launch()app.py+10-32