hwang1 commited on
Commit
4594ff4
·
verified ·
1 Parent(s): 361f6d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -32
app.py CHANGED
@@ -1,66 +1,44 @@
1
- import gradio as gr
2
- import matplotlib.pyplot as plt
3
- import numpy as np
4
- import time
5
-
6
  import yfinance as yf
7
  import pandas as pd
8
  import matplotlib.pyplot as plt
9
  from datetime import datetime, timedelta
 
10
 
11
- # 데이터 가져오기
12
  def fetch_data():
13
  end_date = datetime.now()
14
  start_date = end_date - timedelta(days=5 * 365)
15
- # 미국의 10년물 국채 수익률 데이터 가져오기
16
  us_interest_rate_data = yf.download('^TNX', start=start_date.strftime('%Y-%m-%d'), end=end_date.strftime('%Y-%m-%d'))
17
- us_interest_rate_daily = us_interest_rate_data['Close']
18
-
19
- # 바이낸스 코인 가격 데이터 가져오기
20
  bnb_data = yf.download('BNB-USD', start=start_date.strftime('%Y-%m-%d'), end=end_date.strftime('%Y-%m-%d'))
21
- bnb_daily = bnb_data['Close']
22
-
23
- return us_interest_rate_daily, bnb_daily
24
 
25
- # 데이터 정규화
26
  def normalize_data(data):
27
  return (data - data.min()) / (data.max() - data.min())
28
 
29
- # 데이터 분석 및 그래프 생성
30
  def plot_data(interest_rate_data, bnb_prices):
31
- # 데이터 정규화
32
  interest_rate_normalized = normalize_data(interest_rate_data)
33
  bnb_normalized = normalize_data(bnb_prices)
34
-
35
- # 두 데이터의 차이 계산 및 정규화
36
  diff_normalized = normalize_data(bnb_normalized - interest_rate_normalized)
37
 
38
- # 검은색 선을 그릴 구간 설정
39
- threshold = 0.5
40
  plt.figure(figsize=(14, 7))
41
- plt.plot(diff_normalized, color='green', label='Normalized Difference (Binance Coin Price - US 10-Year Treasury Yield)')
42
-
43
- # 검은색 선을 그릴 구간 설정
44
- plt.axhline(y=threshold, color='black', linestyle='--', label=f'Normalized Value: {threshold}')
45
-
46
- # 배경색 설정
47
  plt.axhspan(0.0, 0.2, color='blue', alpha=0.3)
48
  plt.axhspan(0.2, 0.4, color='lightblue', alpha=0.3)
49
  plt.axhspan(0.4, 0.5, color='skyblue', alpha=0.3)
50
  plt.axhspan(0.5, 0.6, color='yellow', alpha=0.3)
51
  plt.axhspan(0.6, 0.8, color='orange', alpha=0.3)
52
  plt.axhspan(0.8, 1.0, color='red', alpha=0.3)
53
-
54
  plt.title('Difference between Binance Coin Price and US 10-Year Treasury Yield')
55
  plt.xlabel('Date')
56
  plt.ylabel('Normalized Value')
57
  plt.legend()
58
  plt.grid(True)
59
- plt.show()
 
60
 
61
- if __name__ == "__main__":
62
  interest_rate_data, bnb_prices = fetch_data()
63
- plot_data(interest_rate_data, bnb_prices)
64
 
65
- iface = gr.Interface(fn=live_chart, inputs=[], outputs="plot", live=True, title="Live Sine Wave Chart")
66
- iface.launch()
 
 
 
 
 
 
1
  import yfinance as yf
2
  import pandas as pd
3
  import matplotlib.pyplot as plt
4
  from datetime import datetime, timedelta
5
+ import gradio as gr
6
 
 
7
  def fetch_data():
8
  end_date = datetime.now()
9
  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'))
 
 
 
11
  bnb_data = yf.download('BNB-USD', start=start_date.strftime('%Y-%m-%d'), end=end_date.strftime('%Y-%m-%d'))
12
+ return us_interest_rate_data['Close'], bnb_data['Close']
 
 
13
 
 
14
  def normalize_data(data):
15
  return (data - data.min()) / (data.max() - data.min())
16
 
 
17
  def plot_data(interest_rate_data, bnb_prices):
 
18
  interest_rate_normalized = normalize_data(interest_rate_data)
19
  bnb_normalized = normalize_data(bnb_prices)
 
 
20
  diff_normalized = normalize_data(bnb_normalized - interest_rate_normalized)
21
 
 
 
22
  plt.figure(figsize=(14, 7))
23
+ plt.plot(diff_normalized, color='green', label='Normalized Difference (BNB Price - US 10-Year Treasury Yield)')
24
+ plt.axhline(y=0.5, color='black', linestyle='--')
 
 
 
 
25
  plt.axhspan(0.0, 0.2, color='blue', alpha=0.3)
26
  plt.axhspan(0.2, 0.4, color='lightblue', alpha=0.3)
27
  plt.axhspan(0.4, 0.5, color='skyblue', alpha=0.3)
28
  plt.axhspan(0.5, 0.6, color='yellow', alpha=0.3)
29
  plt.axhspan(0.6, 0.8, color='orange', alpha=0.3)
30
  plt.axhspan(0.8, 1.0, color='red', alpha=0.3)
 
31
  plt.title('Difference between Binance Coin Price and US 10-Year Treasury Yield')
32
  plt.xlabel('Date')
33
  plt.ylabel('Normalized Value')
34
  plt.legend()
35
  plt.grid(True)
36
+ plt.close()
37
+ return plt
38
 
39
+ def run_app():
40
  interest_rate_data, bnb_prices = fetch_data()
41
+ return plot_data(interest_rate_data, bnb_prices)
42
 
43
+ iface = gr.Interface(fn=run_app, outputs="plot", title="Financial Data Comparison")
44
+ iface.launch()