Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -49,13 +49,13 @@ def fetch_polymarket_data(search_term="S&P"):
|
|
49 |
# Function to fetch Yahoo Finance data and calculate drift/volatility
|
50 |
def fetch_yahoo_data(ticker):
|
51 |
try:
|
52 |
-
stock = yf.download(ticker, period="1y", progress=False)
|
53 |
if stock.empty:
|
54 |
return None, None, None
|
55 |
-
daily_returns = stock["
|
56 |
mu = daily_returns.mean() * 252 # Annualized drift
|
57 |
sigma = daily_returns.std() * np.sqrt(252) # Annualized volatility
|
58 |
-
last_price = stock["
|
59 |
return mu, sigma, last_price
|
60 |
except Exception:
|
61 |
return None, None, None
|
@@ -115,7 +115,7 @@ def run_simulation(investment, ticker, horizon, num_sims, risk_factor):
|
|
115 |
|
116 |
# Prepare summary text
|
117 |
summary = f"Market Data (Yahoo Finance):\n"
|
118 |
-
summary += f"- Drift (μ): {mu:.4f}\n"
|
119 |
summary += f"- Volatility (σ): {sigma:.4f}\n\n"
|
120 |
if pm_data:
|
121 |
summary += f"Polymarket Data:\n- Question: {pm_data['question']}\n"
|
@@ -134,7 +134,7 @@ def run_simulation(investment, ticker, horizon, num_sims, risk_factor):
|
|
134 |
# Gradio UI
|
135 |
with gr.Blocks(title="Investment Simulation Platform") as demo:
|
136 |
gr.Markdown("# Investment Decision Simulation Platform")
|
137 |
-
gr.Markdown("Simulate investment outcomes using Yahoo Finance data and Polymarket probabilities.")
|
138 |
|
139 |
with gr.Row():
|
140 |
with gr.Column():
|
|
|
49 |
# Function to fetch Yahoo Finance data and calculate drift/volatility
|
50 |
def fetch_yahoo_data(ticker):
|
51 |
try:
|
52 |
+
stock = yf.download(ticker, period="1y", auto_adjust=False, progress=False)
|
53 |
if stock.empty:
|
54 |
return None, None, None
|
55 |
+
daily_returns = stock["Close"].pct_change().dropna() # Use raw Close prices
|
56 |
mu = daily_returns.mean() * 252 # Annualized drift
|
57 |
sigma = daily_returns.std() * np.sqrt(252) # Annualized volatility
|
58 |
+
last_price = stock["Close"][-1] # Use most recent unadjusted Close
|
59 |
return mu, sigma, last_price
|
60 |
except Exception:
|
61 |
return None, None, None
|
|
|
115 |
|
116 |
# Prepare summary text
|
117 |
summary = f"Market Data (Yahoo Finance):\n"
|
118 |
+
summary += f"- Drift (μ): {mu:.4f} (based on unadjusted Close)\n"
|
119 |
summary += f"- Volatility (σ): {sigma:.4f}\n\n"
|
120 |
if pm_data:
|
121 |
summary += f"Polymarket Data:\n- Question: {pm_data['question']}\n"
|
|
|
134 |
# Gradio UI
|
135 |
with gr.Blocks(title="Investment Simulation Platform") as demo:
|
136 |
gr.Markdown("# Investment Decision Simulation Platform")
|
137 |
+
gr.Markdown("Simulate investment outcomes using Yahoo Finance data (unadjusted) and Polymarket probabilities.")
|
138 |
|
139 |
with gr.Row():
|
140 |
with gr.Column():
|