Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -32,7 +32,7 @@ class Investment_Simulator:
|
|
| 32 |
self.history = []
|
| 33 |
self.portfolio_history = []
|
| 34 |
|
| 35 |
-
def get_price(ticker):
|
| 36 |
try:
|
| 37 |
data = yf.Ticker(ticker)
|
| 38 |
todays_data = data.history(period='1d', interval='1m')
|
|
@@ -41,7 +41,7 @@ class Investment_Simulator:
|
|
| 41 |
except:
|
| 42 |
return None
|
| 43 |
|
| 44 |
-
def compute_portfolio_value():
|
| 45 |
total_stock_value = 0.0
|
| 46 |
for ticker, qty in self.portfolio["stocks"].items():
|
| 47 |
price = get_price(ticker)
|
|
@@ -49,12 +49,12 @@ class Investment_Simulator:
|
|
| 49 |
total_stock_value += qty * price
|
| 50 |
return self.portfolio["cash"] + total_stock_value
|
| 51 |
|
| 52 |
-
def update_portfolio_history():
|
| 53 |
now = datetime.now()
|
| 54 |
total_value = compute_portfolio_value()
|
| 55 |
self.portfolio_history.append((now, total_value))
|
| 56 |
|
| 57 |
-
def plot_portfolio_value():
|
| 58 |
if not self.portfolio_history:
|
| 59 |
return None
|
| 60 |
df = pd.DataFrame(self.portfolio_history, columns=["Time", "Value"])
|
|
@@ -62,7 +62,7 @@ class Investment_Simulator:
|
|
| 62 |
fig.update_layout(xaxis_rangeslider_visible=True)
|
| 63 |
return fig
|
| 64 |
|
| 65 |
-
def process_input(user_input):
|
| 66 |
#global self.portfolio, self.history
|
| 67 |
user_input = user_input.lower()
|
| 68 |
|
|
@@ -131,7 +131,7 @@ class Investment_Simulator:
|
|
| 131 |
except Exception as e:
|
| 132 |
return f"⚠️ Error: {e}"
|
| 133 |
|
| 134 |
-
def run_all(text):
|
| 135 |
response = process_input(text)
|
| 136 |
fig = plot_portfolio_value()
|
| 137 |
return response, fig
|
|
|
|
| 32 |
self.history = []
|
| 33 |
self.portfolio_history = []
|
| 34 |
|
| 35 |
+
def get_price(self, ticker):
|
| 36 |
try:
|
| 37 |
data = yf.Ticker(ticker)
|
| 38 |
todays_data = data.history(period='1d', interval='1m')
|
|
|
|
| 41 |
except:
|
| 42 |
return None
|
| 43 |
|
| 44 |
+
def compute_portfolio_value(self):
|
| 45 |
total_stock_value = 0.0
|
| 46 |
for ticker, qty in self.portfolio["stocks"].items():
|
| 47 |
price = get_price(ticker)
|
|
|
|
| 49 |
total_stock_value += qty * price
|
| 50 |
return self.portfolio["cash"] + total_stock_value
|
| 51 |
|
| 52 |
+
def update_portfolio_history(self):
|
| 53 |
now = datetime.now()
|
| 54 |
total_value = compute_portfolio_value()
|
| 55 |
self.portfolio_history.append((now, total_value))
|
| 56 |
|
| 57 |
+
def plot_portfolio_value(self):
|
| 58 |
if not self.portfolio_history:
|
| 59 |
return None
|
| 60 |
df = pd.DataFrame(self.portfolio_history, columns=["Time", "Value"])
|
|
|
|
| 62 |
fig.update_layout(xaxis_rangeslider_visible=True)
|
| 63 |
return fig
|
| 64 |
|
| 65 |
+
def process_input(self, user_input):
|
| 66 |
#global self.portfolio, self.history
|
| 67 |
user_input = user_input.lower()
|
| 68 |
|
|
|
|
| 131 |
except Exception as e:
|
| 132 |
return f"⚠️ Error: {e}"
|
| 133 |
|
| 134 |
+
def run_all(self, text):
|
| 135 |
response = process_input(text)
|
| 136 |
fig = plot_portfolio_value()
|
| 137 |
return response, fig
|