File size: 7,460 Bytes
cafd04f
57ce7cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5b6f62b
57ce7cd
 
 
 
 
 
 
 
5b6f62b
f798c5a
cafd04f
57ce7cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cafd04f
 
 
cb19f3c
57ce7cd
 
 
 
 
 
 
 
 
 
 
 
 
4d52c82
57ce7cd
 
7acc724
57ce7cd
4d52c82
 
 
57ce7cd
4d52c82
57ce7cd
 
 
 
 
 
4d52c82
57ce7cd
 
 
 
 
 
 
 
 
 
 
4d52c82
57ce7cd
 
7acc724
57ce7cd
 
 
 
 
 
 
 
7acc724
57ce7cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c5ef5f5
57ce7cd
 
7acc724
c5ef5f5
7acc724
23c1e52
7acc724
 
 
23c1e52
c5ef5f5
7acc724
57ce7cd
 
 
 
 
 
 
 
 
3d8e1d1
57ce7cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3d8e1d1
 
c5ef5f5
23c1e52
57ce7cd
c5ef5f5
 
57ce7cd
c5ef5f5
 
23c1e52
dd2235a
c5ef5f5
4d52c82
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
import gradio as gr
from interface.rebalancing_interface import (
    portfolio_rebalancing_inputs, examples, main_currency, holdings, 
    cash_amount, cash_ratio, output as rebalancing_output, 
    update_output as rebalancing_update_output
)
from interface.share_price_trend_interface import (
    share_price_trend_inputs, stock_codes, period, 
    output as share_price_trend_output, 
    update_output as share_price_trend_update_output
)
from interface.dollar_cost_averaging_interface import (
    dollar_cost_averaging_inputs, old_price, old_quantity, 
    new_price, new_quantity, 
    output as dollar_cost_averaging_output, 
    update_output as dollar_cost_averaging_update_output
)
from interface.retirement_planning_interface import (
    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, 
    output as retirement_output, 
    update_output as retirement_update_output
)
from interface.about_interface import render as render_about_tab

# Helper function to add buttons
def add_buttons(inputs, update_fn, output):
    clear_button = gr.ClearButton(value="Clear")
    clear_button.click(
        fn=lambda: [None] * len(inputs),
        inputs=[],
        outputs=inputs
    )
    
    submit_button = gr.Button(value="Run", variant="primary")
    submit_button.click(
        fn=update_fn,
        inputs=inputs,
        outputs=output
    )
    return clear_button, submit_button

with gr.Blocks(css='style.css') as demo:
    with gr.Column(elem_id="col-container"):
        with gr.Tabs():
            with gr.TabItem("RE-BALANCING"):
                with gr.Row():
                    with gr.Column():
                        holdings.render()
                        with gr.Row():        
                            main_currency.render()
                            cash_amount.render()
                            cash_ratio.render()
                        
                        # Add buttons and handlers
                        clear_button, submit_button = add_buttons(
                            portfolio_rebalancing_inputs,
                            rebalancing_update_output,
                            rebalancing_output
                        )

                    with gr.Column():
                        rebalancing_output.render()

                gr.Examples(
                    examples=examples,
                    cache_examples=False,
                    inputs=portfolio_rebalancing_inputs
                )
                for input_component in portfolio_rebalancing_inputs:
                    input_component.change(
                        fn=rebalancing_update_output,
                        inputs=portfolio_rebalancing_inputs,
                        outputs=rebalancing_output
                    )
                                
            with gr.TabItem("SHARE PRICE TREND"):
                with gr.Row():
                    with gr.Column():
                        stock_codes.render()
                        period.render()

                        # Add buttons and handlers
                        clear_button, submit_button = add_buttons(
                            share_price_trend_inputs,
                            share_price_trend_update_output,
                            share_price_trend_output
                        )

                    with gr.Column():
                        share_price_trend_output.render()

                for input_component in share_price_trend_inputs:
                    input_component.change(
                        fn=share_price_trend_update_output,
                        inputs=share_price_trend_inputs,
                        outputs=share_price_trend_output
                    )
                                
            with gr.TabItem("DOLLAR-COST AVERAGING"):
                with gr.Row():
                    with gr.Column():
                        with gr.Accordion("FIRST PURCHASE", open=True):
                            with gr.Row():
                                old_price.render()
                                old_quantity.render()
                        with gr.Accordion("SECOND PURCHASE", open=True):
                            with gr.Row():
                                new_price.render()
                                new_quantity.render()

                        # Add buttons and handlers
                        clear_button, submit_button = add_buttons(
                            dollar_cost_averaging_inputs,
                            dollar_cost_averaging_update_output,
                            dollar_cost_averaging_output
                        )
                    
                    with gr.Column():
                        dollar_cost_averaging_output.render()

                for input_component in dollar_cost_averaging_inputs:
                    input_component.change(
                        fn=dollar_cost_averaging_update_output,
                        inputs=dollar_cost_averaging_inputs,
                        outputs=dollar_cost_averaging_output
                    )
                
            with gr.TabItem("RETIREMENT PLANNING"):
                with gr.Row():
                    with gr.Column():
                        with gr.Accordion("PROFILE", open=True):
                            with gr.Row():
                                current_age.render()
                                retirement_age.render()
                                life_expectancy.render()
                                monthly_income_required.render()
                                inflation_rate.render()
                        
                        with gr.Accordion("SAVINGS", open=True):
                            with gr.Row():
                                current_investment.render()
                                monthly_investment.render()
                                annual_increase_in_monthly_investment.render()
                                reinvest_dividends.render()
                        
                        with gr.Accordion("GROWTH", open=True):
                            with gr.Row():
                                pre_retirement_roi.render()
                                pre_retirement_dividend_yield.render()
                                post_retirement_roi.render()
                                post_retirement_dividend_yield.render()

                        # Add buttons and handlers
                        clear_button, submit_button = add_buttons(
                            retirement_planning_inputs,
                            retirement_update_output,
                            retirement_output
                        )

                    with gr.Column():
                        retirement_output.render()

                for input_component in retirement_planning_inputs:
                    input_component.change(
                        fn=retirement_update_output,
                        inputs=retirement_planning_inputs,
                        outputs=retirement_output
                    )
                    
            render_about_tab()

demo.launch(share=True)