Baisub Lee commited on
Commit
86ea38c
·
1 Parent(s): 8b16f78

added graph

Browse files
Files changed (2) hide show
  1. app.py +12 -4
  2. requirements.txt +1 -0
app.py CHANGED
@@ -1,6 +1,7 @@
1
  import yfinance as yf
2
  import pandas as pd
3
  import gradio as gr
 
4
 
5
  def fetch_and_rebalance(etfs_str, period, rebalance_threshold_percentage):
6
  etfs = [etf.strip() for etf in etfs_str.split(",")]
@@ -69,16 +70,23 @@ def fetch_and_rebalance(etfs_str, period, rebalance_threshold_percentage):
69
  return "No data was appended."
70
  final_value = df_rebalance["Total Value"].iloc[-1]
71
  total_return = (final_value - initial_investment) / initial_investment * 100
72
- return f"Final Value: {final_value}, Total Return: {total_return}%"
 
 
 
 
 
 
 
73
 
74
  interface = gr.Interface(
75
  fn=fetch_and_rebalance,
76
  inputs=[
77
  gr.Textbox(lines=1, placeholder="ETFs (comma separated)", value="TQQQ,JEPI"),
78
- gr.Textbox(lines=1, placeholder="Period", value="1y"),
79
- gr.Slider(minimum=0.0, maximum=1.0, value=0.05, label="Rebalance Threshold Percentage")
80
  ],
81
- outputs="text"
82
  )
83
 
84
  interface.launch()
 
1
  import yfinance as yf
2
  import pandas as pd
3
  import gradio as gr
4
+ import plotly.graph_objs as go
5
 
6
  def fetch_and_rebalance(etfs_str, period, rebalance_threshold_percentage):
7
  etfs = [etf.strip() for etf in etfs_str.split(",")]
 
70
  return "No data was appended."
71
  final_value = df_rebalance["Total Value"].iloc[-1]
72
  total_return = (final_value - initial_investment) / initial_investment * 100
73
+
74
+ # Create the plot
75
+ fig = go.Figure()
76
+ for etf in etfs:
77
+ fig.add_trace(go.Scatter(x=df_rebalance["Date"], y=df_rebalance[f"{etf} Value"], mode='lines', name=etf))
78
+ fig.update_layout(title='ETF Valuations Over Time', xaxis_title='Date', yaxis_title='Value')
79
+
80
+ return f"Final Value: {final_value}, Total Return: {total_return}%", fig
81
 
82
  interface = gr.Interface(
83
  fn=fetch_and_rebalance,
84
  inputs=[
85
  gr.Textbox(lines=1, placeholder="ETFs (comma separated)", value="TQQQ,JEPI"),
86
+ gr.Textbox(lines=1, placeholder="Period", value="ytd"),
87
+ gr.Slider(minimum=0.0, maximum=1.0, value=0.10, label="Rebalance Threshold Percentage")
88
  ],
89
+ outputs=["text", "plot"]
90
  )
91
 
92
  interface.launch()
requirements.txt CHANGED
@@ -3,3 +3,4 @@ pandas==1.3.3
3
  gradio==3.1
4
  httpx==0.23.0
5
  httpcore==0.15.0
 
 
3
  gradio==3.1
4
  httpx==0.23.0
5
  httpcore==0.15.0
6
+ plotly==5.6.0