cryman38 commited on
Commit
abb433d
ยท
verified ยท
1 Parent(s): 57ce7cd

Upload 16 files

Browse files
app.py CHANGED
@@ -1,48 +1,34 @@
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"):
@@ -50,76 +36,93 @@ with gr.Blocks(css='style.css') as demo:
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
 
@@ -138,6 +141,7 @@ with gr.Blocks(css='style.css') as demo:
138
  current_age.render()
139
  retirement_age.render()
140
  life_expectancy.render()
 
141
  monthly_income_required.render()
142
  inflation_rate.render()
143
 
@@ -152,16 +156,21 @@ with gr.Blocks(css='style.css') as demo:
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
 
 
1
  import gradio as gr
2
  from interface.rebalancing_interface import (
3
+ main_currency, holdings, cash_amount, cash_ratio,
4
+ input as rebalancing_inputs,
5
+ output as rebalancing_output,
6
+ examples as rebalancing_examples,
7
  update_output as rebalancing_update_output
8
  )
9
  from interface.share_price_trend_interface import (
10
+ stock_codes, period,
11
+ input as share_price_trend_inputs,
12
  output as share_price_trend_output,
13
+ examples as share_price_trend_examples,
14
  update_output as share_price_trend_update_output
15
  )
16
  from interface.dollar_cost_averaging_interface import (
17
+ old_price, old_quantity, new_price, new_quantity,
18
+ input as dollar_cost_averaging_inputs,
19
  output as dollar_cost_averaging_output,
20
+ examples as dollar_cost_averaging_examples,
21
  update_output as dollar_cost_averaging_update_output
22
  )
23
  from interface.retirement_planning_interface import (
24
+ 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,
25
+ input as retirement_planning_inputs,
26
+ output as retirement_output,
27
+ examples as retirement_planning_examples,
 
 
 
28
  update_output as retirement_update_output
29
  )
30
+ from interface.about_interface import render_about_tab
31
+ from modules.utils import clear_buttons, submit_buttons
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
 
33
  with gr.Blocks(css='style.css') as demo:
34
  with gr.Column(elem_id="col-container"):
 
36
  with gr.TabItem("RE-BALANCING"):
37
  with gr.Row():
38
  with gr.Column():
 
39
  with gr.Row():
40
  main_currency.render()
41
+
42
+ with gr.Row():
43
+ holdings.render()
44
+ with gr.Row():
45
  cash_amount.render()
46
  cash_ratio.render()
47
 
48
  # Add buttons and handlers
49
+ clear_button = clear_buttons(
50
+ rebalancing_inputs,
51
  rebalancing_update_output,
52
  rebalancing_output
53
  )
54
+ submit_button = submit_buttons(
55
+ rebalancing_inputs,
56
+ rebalancing_update_output,
57
+ rebalancing_output
58
+ )
59
+ gr.Examples(
60
+ examples=rebalancing_examples,
61
+ cache_examples=False,
62
+ inputs=rebalancing_inputs
63
+ )
64
  with gr.Column():
65
  rebalancing_output.render()
66
 
67
+ # for input_component in rebalancing_inputs:
68
+ # input_component.change(
69
+ # fn=rebalancing_update_output,
70
+ # inputs=rebalancing_inputs,
71
+ # outputs=rebalancing_output
72
+ # )
 
 
 
 
 
73
 
74
  with gr.TabItem("SHARE PRICE TREND"):
75
  with gr.Row():
76
  with gr.Column():
77
+ with gr.Row():
78
+ stock_codes.render()
79
+ with gr.Row():
80
+ period.render()
81
 
82
  # Add buttons and handlers
83
+ submit_button = submit_buttons(
84
  share_price_trend_inputs,
85
  share_price_trend_update_output,
86
  share_price_trend_output
87
  )
88
+ gr.Examples(
89
+ examples=share_price_trend_examples,
90
+ cache_examples=False,
91
+ inputs=share_price_trend_inputs
92
+ )
93
  with gr.Column():
94
  share_price_trend_output.render()
95
 
96
+ # for input_component in share_price_trend_inputs:
97
+ # input_component.change(
98
+ # fn=share_price_trend_update_output,
99
+ # inputs=share_price_trend_inputs,
100
+ # outputs=share_price_trend_output
101
+ # )
102
 
103
  with gr.TabItem("DOLLAR-COST AVERAGING"):
104
  with gr.Row():
105
  with gr.Column():
106
+ # gr.Markdown("FIRST PURCHASE")
107
+ with gr.Row():
108
+ old_price.render()
109
+ old_quantity.render()
110
+ # with gr.Accordion("SECOND PURCHASE", open=True):
111
+ with gr.Row():
112
+ new_price.render()
113
+ new_quantity.render()
114
 
115
  # Add buttons and handlers
116
+ # submit_button = submit_buttons(
117
+ # dollar_cost_averaging_inputs,
118
+ # dollar_cost_averaging_update_output,
119
+ # dollar_cost_averaging_output
120
+ # )
121
+ gr.Examples(
122
+ examples=dollar_cost_averaging_examples,
123
+ cache_examples=False,
124
+ inputs=dollar_cost_averaging_inputs
125
  )
 
126
  with gr.Column():
127
  dollar_cost_averaging_output.render()
128
 
 
141
  current_age.render()
142
  retirement_age.render()
143
  life_expectancy.render()
144
+ with gr.Row():
145
  monthly_income_required.render()
146
  inflation_rate.render()
147
 
 
156
  with gr.Row():
157
  pre_retirement_roi.render()
158
  pre_retirement_dividend_yield.render()
159
+ with gr.Row():
160
  post_retirement_roi.render()
161
  post_retirement_dividend_yield.render()
162
 
163
  # Add buttons and handlers
164
+ # submit_button = submit_buttons(
165
+ # retirement_planning_inputs,
166
+ # retirement_update_output,
167
+ # retirement_output
168
+ # )
169
+ gr.Examples(
170
+ examples=retirement_planning_examples,
171
+ cache_examples=False,
172
+ inputs=retirement_planning_inputs
173
  )
 
174
  with gr.Column():
175
  retirement_output.render()
176
 
interface/about_interface.py CHANGED
@@ -1,6 +1,6 @@
1
  import gradio as gr
2
 
3
- def render():
4
  with gr.TabItem("๐Ÿ’ก HINT"):
5
 
6
  def create_tool_section(tool_name, korean_description, english_description):
 
1
  import gradio as gr
2
 
3
+ def render_about_tab():
4
  with gr.TabItem("๐Ÿ’ก HINT"):
5
 
6
  def create_tool_section(tool_name, korean_description, english_description):
interface/dollar_cost_averaging_interface.py CHANGED
@@ -6,15 +6,17 @@ def dollar_cost_averaging_interface_fn(old_avg_price, old_quantity, new_price, n
6
  css = load_css()
7
  return css + result
8
 
 
 
 
 
9
  # Define the inputs
10
- markdown1 = gr.Markdown("### First Purchase")
11
  old_price = gr.Textbox(label="Old Price", value="")
12
  old_quantity = gr.Textbox(label="Quantity", value="")
13
- markdown2 = gr.Markdown("### Second Purchase")
14
  new_price = gr.Textbox(label="New Price", value="")
15
  new_quantity = gr.Textbox(label="Quantity", value="")
16
 
17
- dollar_cost_averaging_inputs = [old_price, old_quantity, new_price, new_quantity]
18
  output = gr.HTML()
19
 
20
  # Define the update function
 
6
  css = load_css()
7
  return css + result
8
 
9
+ examples = [
10
+ [7857, 7000, 5708, 7000],
11
+ [1000, 9000, 560, 20000]
12
+ ]
13
  # Define the inputs
 
14
  old_price = gr.Textbox(label="Old Price", value="")
15
  old_quantity = gr.Textbox(label="Quantity", value="")
 
16
  new_price = gr.Textbox(label="New Price", value="")
17
  new_quantity = gr.Textbox(label="Quantity", value="")
18
 
19
+ input = [old_price, old_quantity, new_price, new_quantity]
20
  output = gr.HTML()
21
 
22
  # Define the update function
interface/rebalancing_interface.py CHANGED
@@ -18,18 +18,18 @@ 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 (%)",
@@ -38,7 +38,7 @@ cash_ratio = gr.Slider(
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
 
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 (%)",
 
38
  step=1
39
  )
40
 
41
+ input = [main_currency, holdings, cash_amount, cash_ratio]
42
  output = gr.HTML()
43
 
44
  # Define the update function
interface/retirement_planning_interface.py CHANGED
@@ -11,6 +11,13 @@ def retirement_planning_interface_fn(
11
  css = load_css()
12
  return css + result
13
 
 
 
 
 
 
 
 
14
  # Define the input components
15
  current_age = gr.Slider(label="Current Age (15-60 Years)", value=15, minimum=15, maximum=60, step=1)
16
  retirement_age = gr.Slider(label="Retirement Age (Upto 70 Years)", value=55, minimum=15, maximum=70, step=1)
@@ -26,7 +33,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
- 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
 
11
  css = load_css()
12
  return css + result
13
 
14
+ # Define examples for retirement planning
15
+ examples = [
16
+ [38, 55, 85, 2000000, 3.0, 10000000, 500000, 50000, True, 8, 3.3, 8, 3.3],
17
+ [15, 45, 90, 3000000, 3.0, 15000000, 700000, 70000, False, 8.0, 3.0, 7.0, 3.0],
18
+ [50, 55, 95, 3000000, 4.0, 1000000000, 0, 0, True, 6.0, 3.5, 5.5, 3.2]
19
+ ]
20
+
21
  # Define the input components
22
  current_age = gr.Slider(label="Current Age (15-60 Years)", value=15, minimum=15, maximum=60, step=1)
23
  retirement_age = gr.Slider(label="Retirement Age (Upto 70 Years)", value=55, minimum=15, maximum=70, step=1)
 
33
  post_retirement_roi = gr.Number(label="Expected Return On Investment (Post-retirement) (%)", value=8)
34
  post_retirement_dividend_yield = gr.Number(label="Expected Dividend Yield (Post-retirement) (%)", value=3.3)
35
 
36
+ input = [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]
37
  output = gr.HTML()
38
 
39
  # Define the update function
interface/share_price_trend_interface.py CHANGED
@@ -8,10 +8,15 @@ def share_price_trend_interface_fn(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
  )
@@ -21,7 +26,7 @@ period = gr.Number(
21
  )
22
 
23
  # Define output component
24
- share_price_trend_inputs = [stock_codes, period]
25
  output = gr.HTML()
26
 
27
  # Define the update function
 
8
  css = load_css()
9
  return css + result
10
 
11
+ examples = [
12
+ ["AAPL,GOOGL,MSFT", 90],
13
+ ["SCHD,QQQ", 365]
14
+ ]
15
+
16
  # Define Gradio components for inputs
17
  stock_codes = gr.Textbox(
18
  label="Stock Codes",
19
+ # info="Enter stock codes separated by comma.",
20
  placeholder="e.g., AAPL,GOOGL,MSFT",
21
  value="SCHD,QQQ"
22
  )
 
26
  )
27
 
28
  # Define output component
29
+ input = [stock_codes, period]
30
  output = gr.HTML()
31
 
32
  # Define the update function
modules/rebalancing.py CHANGED
@@ -93,7 +93,6 @@ def get_portfolio_rebalancing_info(portfolio, target_weights, main_currency_cash
93
  <div style="font-size: 1.5rem; margin-top: 1.5rem; margin-bottom: 1.5rem;">Market Value</div>
94
  <span style='font-size: 1.5rem; font-weight: bold; color: #1678fb'>{currency_symbol}{total_value:,.0f}</span>
95
  As of {current_time}
96
- <hr style="margin: 1.5rem 0;">
97
  </div>
98
  </div>
99
  </div>
 
93
  <div style="font-size: 1.5rem; margin-top: 1.5rem; margin-bottom: 1.5rem;">Market Value</div>
94
  <span style='font-size: 1.5rem; font-weight: bold; color: #1678fb'>{currency_symbol}{total_value:,.0f}</span>
95
  As of {current_time}
 
96
  </div>
97
  </div>
98
  </div>
modules/utils.py CHANGED
@@ -1,5 +1,6 @@
1
  import ssl
2
  import logging
 
3
 
4
  # ๋กœ๊ทธ ์„ค์ •
5
  #logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@@ -33,3 +34,22 @@ def get_currency_symbol(currency_code):
33
 
34
  def get_currency_codes():
35
  return list(currency_symbols.keys())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import ssl
2
  import logging
3
+ import gradio as gr
4
 
5
  # ๋กœ๊ทธ ์„ค์ •
6
  #logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
 
34
 
35
  def get_currency_codes():
36
  return list(currency_symbols.keys())
37
+
38
+ # Helper function to add buttons
39
+ def clear_buttons(inputs, update_fn, output):
40
+ clear_button = gr.ClearButton(value="Clear")
41
+ clear_button.click(
42
+ fn=lambda: [None] * len(inputs),
43
+ inputs=[],
44
+ outputs=inputs
45
+ )
46
+ return clear_button
47
+
48
+ def submit_buttons(inputs, update_fn, output):
49
+ submit_button = gr.Button(value="Run", variant="primary")
50
+ submit_button.click(
51
+ fn=update_fn,
52
+ inputs=inputs,
53
+ outputs=output
54
+ )
55
+ return submit_button
style.css CHANGED
@@ -9,6 +9,8 @@
9
  @import url('https://fonts.googleapis.com/css2?family=Patrick+Hand&display=swap');
10
  @import url('https://fonts.googleapis.com/css2?family=Baloo+Bhai+2:wght@400;700&display=swap');
11
  @import url('https://fonts.googleapis.com/css2?family=Poor+Story&display=swap');
 
 
12
 
13
  #col-container {
14
  margin: 0 auto;
@@ -187,9 +189,11 @@
187
  .table-container tr:hover td {
188
  background: #e7f9ef;
189
  color: #000;
 
 
190
  /* border: 1px solid #4caf50;
191
- transform: scale(1.02);
192
- transition: all 0.3s ease; */
193
  }
194
 
195
  /* ์–ด๋‘์šด ํ…Œ๋งˆ ์ ์šฉ */
@@ -222,10 +226,3 @@
222
  transition: all 0.3s ease; */
223
  }
224
  }
225
-
226
- /* ์ถ”๊ฐ€์ ์ธ ๋งˆ์šฐ์Šค์˜ค๋ฒ„ ํšจ๊ณผ */
227
- /* .table-container tr:hover td {
228
- text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
229
- cursor: pointer;
230
- } */
231
-
 
9
  @import url('https://fonts.googleapis.com/css2?family=Patrick+Hand&display=swap');
10
  @import url('https://fonts.googleapis.com/css2?family=Baloo+Bhai+2:wght@400;700&display=swap');
11
  @import url('https://fonts.googleapis.com/css2?family=Poor+Story&display=swap');
12
+ @import url("https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@400;600&display=swap");
13
+
14
 
15
  #col-container {
16
  margin: 0 auto;
 
189
  .table-container tr:hover td {
190
  background: #e7f9ef;
191
  color: #000;
192
+ text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.2);
193
+ cursor: pointer;
194
  /* border: 1px solid #4caf50;
195
+ transform: scale(1.02);*/
196
+ transition: all 0.3s ease;
197
  }
198
 
199
  /* ์–ด๋‘์šด ํ…Œ๋งˆ ์ ์šฉ */
 
226
  transition: all 0.3s ease; */
227
  }
228
  }