cryman38 commited on
Commit
57ce7cd
·
verified ·
1 Parent(s): d3eedf0

Upload 16 files

Browse files
app.py CHANGED
@@ -1,87 +1,128 @@
1
  import gradio as gr
2
- from interface.rebalancing_interface import examples, rebalancing_inputs, output as rebalancing_output, update_output as rebalancing_update_output
3
- from interface.share_price_trend_interface import share_price_trend_inputs, output as share_price_trend_output, update_output as share_price_trend_update_output
4
- from interface.dollar_cost_averaging_interface import dollar_cost_averaging_inputs, output as dollar_cost_averaging_output, update_output as dollar_cost_averaging_update_output, markdown1 as dollar_cost_averaging_markdown1, old_price, old_quantity, markdown2 as dollar_cost_averaging_markdown2, new_price, new_quantity
 
 
 
 
 
 
 
 
 
 
 
 
 
5
  from interface.retirement_planning_interface import (
6
- current_age, retirement_age, life_expectancy, monthly_income_required, inflation_rate, current_investment, monthly_investment, annual_increase_in_monthly_investment, reinvest_dividends, pre_retirement_roi, pre_retirement_dividend_yield, post_retirement_roi, post_retirement_dividend_yield, output as retirement_output, update_output as retirement_update_output
 
 
 
 
 
 
 
7
  )
8
  from interface.about_interface import render as render_about_tab
9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  with gr.Blocks(css='style.css') as demo:
11
  with gr.Column(elem_id="col-container"):
12
  with gr.Tabs():
13
  with gr.TabItem("RE-BALANCING"):
14
- with gr.Row(): # Use Row to place inputs and output side by side
15
- with gr.Column(): # Column for inputs
16
- for input_component in rebalancing_inputs:
17
- input_component.render()
18
- # Add the ClearButton below the inputs
19
- clear_button = gr.ClearButton(value="Clear")
20
- clear_button.click(
21
- fn=lambda: [None] * len(rebalancing_inputs),
22
- inputs=[],
23
- outputs=rebalancing_inputs
24
- )
25
-
26
- # Add the Submit Button below the ClearButton
27
- submit_button = gr.Button(value="Run", variant="primary")
28
- submit_button.click(
29
- fn=rebalancing_update_output,
30
- inputs=rebalancing_inputs,
31
- outputs=rebalancing_output
32
  )
33
- with gr.Column(): # Column for output
 
34
  rebalancing_output.render()
35
-
36
- # Add examples
37
  gr.Examples(
38
  examples=examples,
39
  cache_examples=False,
40
- inputs=rebalancing_inputs
41
  )
42
- with gr.TabItem("SHARE PRICE TREND"):
43
- with gr.Row(): # Use Row to place inputs and output side by side
44
- with gr.Column(): # Column for inputs
45
- for input_component in share_price_trend_inputs:
46
- input_component.render()
47
- # Add the ClearButton below the inputs
48
- clear_button = gr.ClearButton(value="Clear")
49
- clear_button.click(
50
- fn=lambda: [None] * len(share_price_trend_inputs),
51
- inputs=[],
52
- outputs=share_price_trend_inputs
53
- )
54
 
55
- # Add the Submit Button below the ClearButton
56
- submit_button = gr.Button(value="Run", variant="primary")
57
- submit_button.click(
58
- fn=share_price_trend_update_output,
59
- inputs=share_price_trend_inputs,
60
- outputs=share_price_trend_output
 
 
 
 
 
61
  )
62
- with gr.Column(): # Column for output
 
63
  share_price_trend_output.render()
64
-
 
 
 
 
 
 
 
65
  with gr.TabItem("DOLLAR-COST AVERAGING"):
66
- with gr.Row(): # Use Row to place inputs and output side by side
67
- with gr.Column(): # Column for inputs
68
- dollar_cost_averaging_markdown1.render()
69
- old_price.render()
70
- old_quantity.render()
71
- dollar_cost_averaging_markdown2.render()
72
- new_price.render()
73
- new_quantity.render()
74
- # Add the ClearButton below the inputs
75
- clear_button = gr.ClearButton(value="Clear")
76
- clear_button.click(
77
- fn=lambda: [None] * len(dollar_cost_averaging_inputs),
78
- inputs=[],
79
- outputs=dollar_cost_averaging_inputs
 
 
80
  )
81
- with gr.Column(): # Column for output
 
82
  dollar_cost_averaging_output.render()
83
 
84
- # Add change event handlers for cost averaging inputs
85
  for input_component in dollar_cost_averaging_inputs:
86
  input_component.change(
87
  fn=dollar_cost_averaging_update_output,
@@ -90,65 +131,44 @@ with gr.Blocks(css='style.css') as demo:
90
  )
91
 
92
  with gr.TabItem("RETIREMENT PLANNING"):
93
- with gr.Row(): # Use Row to place inputs and output side by side
94
- with gr.Column(): # Column for inputs
95
-
96
- gr.Markdown("### Profile")
97
- with gr.Row():
98
- current_age.render()
99
- retirement_age.render()
100
- life_expectancy.render()
101
- monthly_income_required.render()
102
- inflation_rate.render()
103
-
104
- gr.Markdown("### Savings")
105
- with gr.Row():
106
- current_investment.render()
107
- monthly_investment.render()
108
- annual_increase_in_monthly_investment.render() # 추가된 입력
109
- reinvest_dividends.render()
110
 
111
- gr.Markdown("### Growth")
112
- with gr.Row():
113
- pre_retirement_roi.render()
114
- pre_retirement_dividend_yield.render()
115
- # retirement_markdown.render()
116
- post_retirement_roi.render()
117
- post_retirement_dividend_yield.render()
 
 
 
 
 
 
 
 
 
 
 
 
 
118
 
119
-
120
- # # Add the ClearButton below the inputs
121
- # clear_button = gr.ClearButton(value="Clear")
122
- # clear_button.click(
123
- # fn=lambda: [None] * len([
124
- # current_age, retirement_age, life_expectancy, monthly_income_required, inflation_rate, current_investment, monthly_investment, annual_increase_in_monthly_investment, reinvest_dividends, pre_retirement_roi, pre_retirement_dividend_yield, post_retirement_roi, post_retirement_dividend_yield
125
- # ]),
126
- # inputs=[],
127
- # outputs=[
128
- # current_age, retirement_age, life_expectancy, monthly_income_required, inflation_rate, current_investment, monthly_investment, annual_increase_in_monthly_investment, reinvest_dividends, pre_retirement_roi, pre_retirement_dividend_yield, post_retirement_roi, post_retirement_dividend_yield
129
- # ]
130
- # )
131
- # # Add the Submit Button below the ClearButton
132
- # submit_button = gr.Button(value="Run", variant="primary")
133
- # submit_button.click(
134
- # fn=retirement_update_output,
135
- # inputs=[
136
- # current_age, retirement_age, life_expectancy, monthly_income_required, inflation_rate, current_investment, monthly_investment, annual_increase_in_monthly_investment, reinvest_dividends, pre_retirement_roi, pre_retirement_dividend_yield, post_retirement_roi, post_retirement_dividend_yield
137
- # ],
138
- # outputs=retirement_output
139
- # )
140
  with gr.Column():
141
  retirement_output.render()
142
 
143
- # Add change event handlers for retirement planning inputs
144
- for input_component in [
145
- current_age, retirement_age, life_expectancy, monthly_income_required, inflation_rate, current_investment, monthly_investment, annual_increase_in_monthly_investment, reinvest_dividends, pre_retirement_roi, pre_retirement_dividend_yield, post_retirement_roi, post_retirement_dividend_yield
146
- ]:
147
  input_component.change(
148
  fn=retirement_update_output,
149
- inputs=[
150
- current_age, retirement_age, life_expectancy, monthly_income_required, inflation_rate, current_investment, monthly_investment, annual_increase_in_monthly_investment, reinvest_dividends, pre_retirement_roi, pre_retirement_dividend_yield, post_retirement_roi, post_retirement_dividend_yield
151
- ],
152
  outputs=retirement_output
153
  )
154
 
 
1
  import gradio as gr
2
+ from interface.rebalancing_interface import (
3
+ portfolio_rebalancing_inputs, examples, main_currency, holdings,
4
+ cash_amount, cash_ratio, output as rebalancing_output,
5
+ update_output as rebalancing_update_output
6
+ )
7
+ from interface.share_price_trend_interface import (
8
+ share_price_trend_inputs, stock_codes, period,
9
+ output as share_price_trend_output,
10
+ update_output as share_price_trend_update_output
11
+ )
12
+ from interface.dollar_cost_averaging_interface import (
13
+ dollar_cost_averaging_inputs, old_price, old_quantity,
14
+ new_price, new_quantity,
15
+ output as dollar_cost_averaging_output,
16
+ update_output as dollar_cost_averaging_update_output
17
+ )
18
  from interface.retirement_planning_interface import (
19
+ retirement_planning_inputs, current_age, retirement_age,
20
+ life_expectancy, monthly_income_required, inflation_rate,
21
+ current_investment, monthly_investment,
22
+ annual_increase_in_monthly_investment, reinvest_dividends,
23
+ pre_retirement_roi, pre_retirement_dividend_yield,
24
+ post_retirement_roi, post_retirement_dividend_yield,
25
+ output as retirement_output,
26
+ update_output as retirement_update_output
27
  )
28
  from interface.about_interface import render as render_about_tab
29
 
30
+ # Helper function to add buttons
31
+ def add_buttons(inputs, update_fn, output):
32
+ clear_button = gr.ClearButton(value="Clear")
33
+ clear_button.click(
34
+ fn=lambda: [None] * len(inputs),
35
+ inputs=[],
36
+ outputs=inputs
37
+ )
38
+
39
+ submit_button = gr.Button(value="Run", variant="primary")
40
+ submit_button.click(
41
+ fn=update_fn,
42
+ inputs=inputs,
43
+ outputs=output
44
+ )
45
+ return clear_button, submit_button
46
+
47
  with gr.Blocks(css='style.css') as demo:
48
  with gr.Column(elem_id="col-container"):
49
  with gr.Tabs():
50
  with gr.TabItem("RE-BALANCING"):
51
+ with gr.Row():
52
+ with gr.Column():
53
+ holdings.render()
54
+ with gr.Row():
55
+ main_currency.render()
56
+ cash_amount.render()
57
+ cash_ratio.render()
58
+
59
+ # Add buttons and handlers
60
+ clear_button, submit_button = add_buttons(
61
+ portfolio_rebalancing_inputs,
62
+ rebalancing_update_output,
63
+ rebalancing_output
 
 
 
 
 
64
  )
65
+
66
+ with gr.Column():
67
  rebalancing_output.render()
68
+
 
69
  gr.Examples(
70
  examples=examples,
71
  cache_examples=False,
72
+ inputs=portfolio_rebalancing_inputs
73
  )
74
+ for input_component in portfolio_rebalancing_inputs:
75
+ input_component.change(
76
+ fn=rebalancing_update_output,
77
+ inputs=portfolio_rebalancing_inputs,
78
+ outputs=rebalancing_output
79
+ )
 
 
 
 
 
 
80
 
81
+ with gr.TabItem("SHARE PRICE TREND"):
82
+ with gr.Row():
83
+ with gr.Column():
84
+ stock_codes.render()
85
+ period.render()
86
+
87
+ # Add buttons and handlers
88
+ clear_button, submit_button = add_buttons(
89
+ share_price_trend_inputs,
90
+ share_price_trend_update_output,
91
+ share_price_trend_output
92
  )
93
+
94
+ with gr.Column():
95
  share_price_trend_output.render()
96
+
97
+ for input_component in share_price_trend_inputs:
98
+ input_component.change(
99
+ fn=share_price_trend_update_output,
100
+ inputs=share_price_trend_inputs,
101
+ outputs=share_price_trend_output
102
+ )
103
+
104
  with gr.TabItem("DOLLAR-COST AVERAGING"):
105
+ with gr.Row():
106
+ with gr.Column():
107
+ with gr.Accordion("FIRST PURCHASE", open=True):
108
+ with gr.Row():
109
+ old_price.render()
110
+ old_quantity.render()
111
+ with gr.Accordion("SECOND PURCHASE", open=True):
112
+ with gr.Row():
113
+ new_price.render()
114
+ new_quantity.render()
115
+
116
+ # Add buttons and handlers
117
+ clear_button, submit_button = add_buttons(
118
+ dollar_cost_averaging_inputs,
119
+ dollar_cost_averaging_update_output,
120
+ dollar_cost_averaging_output
121
  )
122
+
123
+ with gr.Column():
124
  dollar_cost_averaging_output.render()
125
 
 
126
  for input_component in dollar_cost_averaging_inputs:
127
  input_component.change(
128
  fn=dollar_cost_averaging_update_output,
 
131
  )
132
 
133
  with gr.TabItem("RETIREMENT PLANNING"):
134
+ with gr.Row():
135
+ with gr.Column():
136
+ with gr.Accordion("PROFILE", open=True):
137
+ with gr.Row():
138
+ current_age.render()
139
+ retirement_age.render()
140
+ life_expectancy.render()
141
+ monthly_income_required.render()
142
+ inflation_rate.render()
 
 
 
 
 
 
 
 
143
 
144
+ with gr.Accordion("SAVINGS", open=True):
145
+ with gr.Row():
146
+ current_investment.render()
147
+ monthly_investment.render()
148
+ annual_increase_in_monthly_investment.render()
149
+ reinvest_dividends.render()
150
+
151
+ with gr.Accordion("GROWTH", open=True):
152
+ with gr.Row():
153
+ pre_retirement_roi.render()
154
+ pre_retirement_dividend_yield.render()
155
+ post_retirement_roi.render()
156
+ post_retirement_dividend_yield.render()
157
+
158
+ # Add buttons and handlers
159
+ clear_button, submit_button = add_buttons(
160
+ retirement_planning_inputs,
161
+ retirement_update_output,
162
+ retirement_output
163
+ )
164
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
165
  with gr.Column():
166
  retirement_output.render()
167
 
168
+ for input_component in retirement_planning_inputs:
 
 
 
169
  input_component.change(
170
  fn=retirement_update_output,
171
+ inputs=retirement_planning_inputs,
 
 
172
  outputs=retirement_output
173
  )
174
 
interface/rebalancing_interface.py CHANGED
@@ -11,27 +11,36 @@ currency_codes = get_currency_codes()
11
  examples = [
12
  ["KRW", "458730 KRW 580 8,\n368590 KRW 80 2", 507977, 0],
13
  ["KRW", "SCHD USD 500 8,\nQQQ USD 200 2", 0, 15]
14
- ]
15
-
16
- rebalancing_inputs = [
17
- gr.Dropdown(label="Main Currency", choices=currency_codes, value="KRW", info="Assets converted to main currency."),
18
- gr.Textbox(label="Holdings", lines=2, info="Format: [ ticker currency quantity weight, ... ]", placeholder="e.g., SCHD USD 500 8, QQQ USD 200 2"),
19
- gr.Number(label="Cash", value="", info="MAIN CURRENCY CASH"),
20
- gr.Slider(label="Cash Ratio (%)", minimum=0, maximum=100, step=1)
21
  ]
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  output = gr.HTML()
24
 
25
  # Define the update function
26
  def update_output(main_currency, holdings, cash_amount, cash_ratio):
27
  return rebalancing_interface_fn(main_currency, holdings, cash_amount, cash_ratio)
28
-
29
- # portfolio_rebalancing_interface = gr.Interface(
30
- # fn=portfolio_rebalancing_interface_fn,
31
- # inputs=portfolio_inputs,
32
- # outputs=gr.HTML(),
33
- # examples=examples,
34
- # cache_examples=False,
35
- # live=False
36
- # )
37
-
 
11
  examples = [
12
  ["KRW", "458730 KRW 580 8,\n368590 KRW 80 2", 507977, 0],
13
  ["KRW", "SCHD USD 500 8,\nQQQ USD 200 2", 0, 15]
 
 
 
 
 
 
 
14
  ]
15
 
16
+ # Define Gradio components
17
+ main_currency = gr.Dropdown(
18
+ label="Main Currency",
19
+ choices=currency_codes,
20
+ value="KRW",
21
+ info="Assets converted to main currency."
22
+ )
23
+ holdings = gr.Textbox(
24
+ label="Holdings",
25
+ lines=2,
26
+ info="Format: [ ticker currency quantity weight, ... ]",
27
+ placeholder="e.g., SCHD USD 500 8, QQQ USD 200 2"
28
+ )
29
+ cash_amount = gr.Number(
30
+ label="Cash",
31
+ value="",
32
+ info="MAIN CURRENCY CASH"
33
+ )
34
+ cash_ratio = gr.Slider(
35
+ label="Cash Ratio (%)",
36
+ minimum=0,
37
+ maximum=100,
38
+ step=1
39
+ )
40
+
41
+ portfolio_rebalancing_inputs = [main_currency, holdings, cash_amount, cash_ratio]
42
  output = gr.HTML()
43
 
44
  # Define the update function
45
  def update_output(main_currency, holdings, cash_amount, cash_ratio):
46
  return rebalancing_interface_fn(main_currency, holdings, cash_amount, cash_ratio)
 
 
 
 
 
 
 
 
 
 
interface/retirement_planning_interface.py CHANGED
@@ -26,6 +26,7 @@ pre_retirement_dividend_yield = gr.Number(label="Expected Dividend Yield (Pre-re
26
  post_retirement_roi = gr.Number(label="Expected Return On Investment (Post-retirement) (%)", value=8)
27
  post_retirement_dividend_yield = gr.Number(label="Expected Dividend Yield (Post-retirement) (%)", value=3.3)
28
 
 
29
  output = gr.HTML()
30
 
31
  # Define the update function
 
26
  post_retirement_roi = gr.Number(label="Expected Return On Investment (Post-retirement) (%)", value=8)
27
  post_retirement_dividend_yield = gr.Number(label="Expected Dividend Yield (Post-retirement) (%)", value=3.3)
28
 
29
+ retirement_planning_inputs = [current_age, retirement_age, life_expectancy, monthly_income_required, inflation_rate, current_investment, monthly_investment, annual_increase_in_monthly_investment, reinvest_dividends, pre_retirement_roi, pre_retirement_dividend_yield, post_retirement_roi, post_retirement_dividend_yield]
30
  output = gr.HTML()
31
 
32
  # Define the update function
interface/share_price_trend_interface.py CHANGED
@@ -2,26 +2,28 @@ import gradio as gr
2
  from modules.utils import load_css
3
  from modules.share_price_trend import share_price_trend
4
 
5
- # Define the interface for the Compare tab
6
  def share_price_trend_interface_fn(stock_codes, period):
7
  result = share_price_trend(stock_codes, period)
8
  css = load_css()
9
  return css + result
10
 
11
- share_price_trend_inputs = [
12
- gr.Textbox(label="Stock Codes", info="Enter stock codes separated by comma.", placeholder="e.g., AAPL,GOOGL,MSFT", value="SCHD,QQQ"),
13
- gr.Number(label="input # of days below", value="90")
14
- ]
 
 
 
 
 
 
 
15
 
16
- output=gr.HTML()
 
 
17
 
18
  # Define the update function
19
  def update_output(stock_codes, period):
20
  return share_price_trend_interface_fn(stock_codes, period)
21
-
22
- # compare_stock_prices_interface = gr.Interface(
23
- # fn=compare_stock_prices_interface_fn,
24
- # inputs=compare_inputs,
25
- # outputs=gr.HTML(),
26
- # live=False
27
- # )
 
2
  from modules.utils import load_css
3
  from modules.share_price_trend import share_price_trend
4
 
5
+ # Define the function that processes the inputs and returns the result
6
  def share_price_trend_interface_fn(stock_codes, period):
7
  result = share_price_trend(stock_codes, period)
8
  css = load_css()
9
  return css + result
10
 
11
+ # Define Gradio components for inputs
12
+ stock_codes = gr.Textbox(
13
+ label="Stock Codes",
14
+ info="Enter stock codes separated by comma.",
15
+ placeholder="e.g., AAPL,GOOGL,MSFT",
16
+ value="SCHD,QQQ"
17
+ )
18
+ period = gr.Number(
19
+ label="Number of Days",
20
+ value=90
21
+ )
22
 
23
+ # Define output component
24
+ share_price_trend_inputs = [stock_codes, period]
25
+ output = gr.HTML()
26
 
27
  # Define the update function
28
  def update_output(stock_codes, period):
29
  return share_price_trend_interface_fn(stock_codes, period)
 
 
 
 
 
 
 
style.css CHANGED
@@ -13,8 +13,8 @@
13
  #col-container {
14
  margin: 0 auto;
15
  max-width: 100%;
16
- font-family: 'Montserrat', 'ui-sans-serif', 'system-ui', 'sans-serif';
17
- /* text-transform: uppercase; 모든 텍스트를 대문자로 변환합니다 */
18
 
19
  }
20
 
 
13
  #col-container {
14
  margin: 0 auto;
15
  max-width: 100%;
16
+ font-family: 'Patrick Hand', 'ui-sans-serif', 'system-ui', 'sans-serif';
17
+ text-transform: uppercase;
18
 
19
  }
20