Spaces:
Sleeping
Sleeping
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() | |