File size: 3,717 Bytes
5611820
 
56b86ac
50a132d
 
 
56b86ac
cd3b8a3
50a132d
 
 
56b86ac
761f4a6
 
 
 
 
 
5611820
 
 
56b86ac
50a132d
56b86ac
 
 
 
73a7854
 
56b86ac
 
 
 
 
710fc67
56b86ac
99db7f1
 
56b86ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
761f4a6
 
 
56b86ac
 
50a132d
56b86ac
 
 
 
61b24aa
56b86ac
 
710fc67
56b86ac
3e23bfe
56b86ac
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e613dd9
 
56b86ac
 
3e23bfe
56b86ac
 
761f4a6
 
 
 
e06592f
761f4a6
 
e06592f
761f4a6
 
 
 
 
 
 
 
 
 
56b86ac
761f4a6
 
56b86ac
 
 
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
import gradio as gr

title_conpund = "Uninvested Earnings Calculator"
description_conpound = """
Monthly compound.
"""

title_ETF1 = "Stock Earnings Calculator"
description_ETF1 = """
Daily compound is not included.
"""

title_stock = "Selling price calculator"
description_stock = """
Calculate Selling Price for a target gain percentage 
(after tax deduction (25%) and Trade republic selling fees (1 eur))
"""

def greet(name):
    return "Hello " + name + "!!"


def compound(
    initial_investment,
    # annual_contribution,
    # monthly_contribution,
    yearly_interest_rate,
    investment_length, 
    tax_rate = 0.4# in month
):
    """ "
    initial_investment: euro
    yearly_interest_rate: percentage
    investment_length
    tax_rate
    """
    gross_earnings = initial_investment * (1 + yearly_interest_rate / 12) ** (investment_length / 12 * 12) - initial_investment
    return (gross_earnings * (1-tax_rate))


def ETF_with_price_net_change(
    buy_in_price, sell_price, initial_investment, tax_rate=0.4
):
    shares = initial_investment / buy_in_price
    earnings = shares * (sell_price - buy_in_price)
    stock_change_rate = (sell_price - buy_in_price) / buy_in_price
    net_earnings = earnings * (1 - tax_rate)
    net_earning_rate = net_earnings / initial_investment
    return earnings, net_earnings, net_earning_rate, stock_change_rate


def ETF_with_price_change_rate(
    initial_investment, buy_in_price, price_change_rate, tax_rate=0.4
):
    shares = initial_investment / buy_in_price
    sell_price = buy_in_price * (1 + price_change_rate)
    earnings = shares * (sell_price - buy_in_price)
    net_earnings = earnings * (1 - tax_rate)
    net_earning_rate = net_earnings / initial_investment
    return earnings, net_earnings, net_earning_rate

def stock_sp_calc(buy_in_price, target_gain):
    return ((buy_in_price * target_gain/100) + (0.75*buy_in_price) + 1) / 0.75


iface = gr.Interface(
    fn=compound,
    inputs=[
        gr.Number(label="Initial Investment", precision=2),
        gr.Number(label="Yearly Interest Rate", precision=3, step=0.01),
        gr.Number(label="Investment Length in Months", precision=0),
        gr.Number(0.40, label="Tax Rate", precision=2),
    ],
    outputs=gr.Number(label="Net Earnings", precision=3),
    examples=[[5000, 0.04, 1, 0.4], [5000, 0.04, 12, 0.4]],
    title=title_conpund,
    description = description_conpound
)

iface2 = gr.Interface(
    fn=ETF_with_price_change_rate,
    inputs=[
        gr.Number(label="Initial Investment", precision=2),
        gr.Number(label="Buy-in Price", precision=2, step=0.01),
        gr.Number(label="Price Change Rate", precision=3, step=0.01),
        gr.Number(0.40, label="Tax Rate", precision=2),
    ],
    outputs=[
        gr.Number(label="Earnings before Tax", precision=3),
        gr.Number(label="Net Earnings", precision=3),
        gr.Number(label="Net Earnings Rate", precision=3),
    ],
    examples=[
        [5000, 37.22, 0.10, 0.4],
        [500, 20.68, 0.3465, 0.4],
        [10000, 80, 0.1136, 0.4],
    ],
    title=title_ETF1,
    description = description_ETF1,
)

iface3 = gr.Interface(
    fn=stock_sp_calc,
    inputs=[
        gr.Number(label="Buy-in Price", precision=2, step=0.01),
        gr.Number(label="Target gain (%)", precision=3, step=0.01),
    ],
    outputs=[
        gr.Number(label="Selling price", precision=3),
    ],
    examples=[
        [33.62, 10],
        [440.3, 5],
        [3201.4, 4.5],
    ],
    title=title_stock,
    description = description_stock,
)

app = gr.TabbedInterface(
    interface_list=[iface, iface2, iface3],
    tab_names=["Uninvested earnings", "ETF earnings", "Selling price calculator"],
)

app.launch()