Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import pandas as pd
|
3 |
+
|
4 |
+
def calculate_pb_ratio(initial_pb_ratio, book_value_growth_rate, stock_price_growth_rate, years):
|
5 |
+
pb_ratios = [initial_pb_ratio]
|
6 |
+
for i in range(1, int(years) + 1): # Convert years to an integer
|
7 |
+
projected_book_value = pb_ratios[-1] * (1 + book_value_growth_rate)
|
8 |
+
projected_stock_price = projected_book_value * pb_ratios[-1] * (1 + stock_price_growth_rate)
|
9 |
+
projected_pb_ratio = projected_stock_price / projected_book_value
|
10 |
+
pb_ratios.append(projected_pb_ratio)
|
11 |
+
return pb_ratios
|
12 |
+
|
13 |
+
def pb_ratio_valuation(initial_pb_ratio, book_value_growth_rate, stock_price_growth_rate, years):
|
14 |
+
projected_pb_ratios = calculate_pb_ratio(initial_pb_ratio, book_value_growth_rate, stock_price_growth_rate, years)
|
15 |
+
results = {"Year": [], "Projected P/B Ratio": []}
|
16 |
+
for i in range(len(projected_pb_ratios)):
|
17 |
+
results["Year"].append(i + 1)
|
18 |
+
results["Projected P/B Ratio"].append(projected_pb_ratios[i])
|
19 |
+
return pd.DataFrame(results)
|
20 |
+
|
21 |
+
# Define the Gradio interface
|
22 |
+
gr.Interface(
|
23 |
+
fn=pb_ratio_valuation,
|
24 |
+
inputs=[
|
25 |
+
gr.inputs.Slider(minimum=0, maximum=10, default=1.5, label="Initial P/B Ratio"),
|
26 |
+
gr.inputs.Slider(minimum=0, maximum=0.5, default=0.05, label="Annual Book Value Growth Rate"),
|
27 |
+
gr.inputs.Slider(minimum=0, maximum=0.5, default=0.08, label="Annual Stock Price Growth Rate"),
|
28 |
+
gr.inputs.Number(default=10, label="Years")
|
29 |
+
],
|
30 |
+
outputs=gr.outputs.Dataframe(type='pandas'), # Use Dataframe as the output with type 'pandas'
|
31 |
+
title="Price-to-Book (P/B) Ratio Valuation",
|
32 |
+
description="Calculate projected P/B ratios over the next 10 years.",
|
33 |
+
).launch()
|