Spaces:
Runtime error
Runtime error
File size: 1,693 Bytes
f2b2d6a |
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 |
import gradio as gr
import pandas as pd
def calculate_pb_ratio(initial_pb_ratio, book_value_growth_rate, stock_price_growth_rate, years):
pb_ratios = [initial_pb_ratio]
for i in range(1, int(years) + 1): # Convert years to an integer
projected_book_value = pb_ratios[-1] * (1 + book_value_growth_rate)
projected_stock_price = projected_book_value * pb_ratios[-1] * (1 + stock_price_growth_rate)
projected_pb_ratio = projected_stock_price / projected_book_value
pb_ratios.append(projected_pb_ratio)
return pb_ratios
def pb_ratio_valuation(initial_pb_ratio, book_value_growth_rate, stock_price_growth_rate, years):
projected_pb_ratios = calculate_pb_ratio(initial_pb_ratio, book_value_growth_rate, stock_price_growth_rate, years)
results = {"Year": [], "Projected P/B Ratio": []}
for i in range(len(projected_pb_ratios)):
results["Year"].append(i + 1)
results["Projected P/B Ratio"].append(projected_pb_ratios[i])
return pd.DataFrame(results)
# Define the Gradio interface
gr.Interface(
fn=pb_ratio_valuation,
inputs=[
gr.inputs.Slider(minimum=0, maximum=10, default=1.5, label="Initial P/B Ratio"),
gr.inputs.Slider(minimum=0, maximum=0.5, default=0.05, label="Annual Book Value Growth Rate"),
gr.inputs.Slider(minimum=0, maximum=0.5, default=0.08, label="Annual Stock Price Growth Rate"),
gr.inputs.Number(default=10, label="Years")
],
outputs=gr.outputs.Dataframe(type='pandas'), # Use Dataframe as the output with type 'pandas'
title="Price-to-Book (P/B) Ratio Valuation",
description="Calculate projected P/B ratios over the next 10 years.",
).launch()
|