Spaces:
Build error
Build error
Upload app.py
Browse files
app.py
CHANGED
|
@@ -290,7 +290,7 @@ def cost_averaging(current_avg_price, current_shares, current_price, desired_pri
|
|
| 290 |
# ํ์ฌ ์์ต๋ฅ ๊ณ์ฐ
|
| 291 |
current_return = (current_price - current_avg_price) / current_avg_price * 100
|
| 292 |
# ์๋ก์ด ์์ต๋ฅ ๊ณ์ฐ
|
| 293 |
-
new_return = (
|
| 294 |
return current_return, new_return, additional_investment
|
| 295 |
|
| 296 |
# ์ฌ์ฉ ์
|
|
@@ -299,25 +299,50 @@ def cost_averaging(current_avg_price, current_shares, current_price, desired_pri
|
|
| 299 |
# current_return, new_return, additional_investment = cost_averaging(78.17, 5.930644, 77.11, 75, 10)
|
| 300 |
|
| 301 |
def gradio_cost_averaging(current_avg_price, current_shares, current_price, desired_price, additional_shares):
|
|
|
|
|
|
|
|
|
|
| 302 |
current_return, new_return, additional_investment = cost_averaging(current_avg_price, current_shares, current_price, desired_price, additional_shares)
|
| 303 |
# Creating a styled HTML output similar to the uploaded image
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 315 |
</div>
|
|
|
|
| 316 |
</div>
|
| 317 |
-
<p style='text-align: center; color: #0000FF; font-size: 18px;'>์ด ์ถ๊ฐ ๊ธ์ก: <strong>${additional_investment:.2f}</strong></p>
|
| 318 |
-
</div>
|
| 319 |
"""
|
|
|
|
| 320 |
return result_html
|
|
|
|
| 321 |
pf_dataset_samples = [
|
| 322 |
["458730 krw 571 8,\n368590 krw 80 2", 17172, 0],
|
| 323 |
["SCHD USD 400 8,\nQQQ USD 40 2", 1000000, 25],
|
|
@@ -328,6 +353,9 @@ stock_dataset_samples = [
|
|
| 328 |
["458730,368590", 30],
|
| 329 |
["AAPL,GOOGL,MSFT", 30]
|
| 330 |
]
|
|
|
|
|
|
|
|
|
|
| 331 |
with gr.Blocks(css='style.css') as demo:
|
| 332 |
with gr.Column(elem_id="col-container"):
|
| 333 |
|
|
@@ -364,22 +392,27 @@ with gr.Blocks(css='style.css') as demo:
|
|
| 364 |
compare_button.click(plot_stock_prices, [stock_codes, period], comparison_result)
|
| 365 |
clear_button = gr.ClearButton([stock_codes, period, comparison_result], value="Clear")
|
| 366 |
|
| 367 |
-
with gr.TabItem("Average"):
|
| 368 |
current_avg_price_input = gr.Number(label="Current Average Price", value=78.15)
|
| 369 |
current_shares_input = gr.Number(label="Current Shares", value=6.024272)
|
| 370 |
current_price_input = gr.Number(label="Current Price", value=77.11)
|
| 371 |
desired_price_input = gr.Number(label="Desired Price", value=77.11)
|
| 372 |
additional_shares_input = gr.Number(label="Additional Shares", value=1)
|
| 373 |
-
|
| 374 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 375 |
average_results = gr.HTML() # Changed to HTML for styled output
|
| 376 |
|
| 377 |
-
|
| 378 |
gradio_cost_averaging,
|
| 379 |
inputs=[current_avg_price_input, current_shares_input, current_price_input, desired_price_input, additional_shares_input],
|
| 380 |
outputs=average_results
|
| 381 |
)
|
| 382 |
-
|
| 383 |
|
| 384 |
with gr.TabItem("๐ About"):
|
| 385 |
gr.Markdown("""
|
|
|
|
| 290 |
# ํ์ฌ ์์ต๋ฅ ๊ณ์ฐ
|
| 291 |
current_return = (current_price - current_avg_price) / current_avg_price * 100
|
| 292 |
# ์๋ก์ด ์์ต๋ฅ ๊ณ์ฐ
|
| 293 |
+
new_return = (new_avg_price / current_price - 1) * 100 # ์ถ๊ฐ ๊ธ์ก ๋ฐ ์์ต๋ฅ ๊ฒฐ๊ณผ ๋ฐํ
|
| 294 |
return current_return, new_return, additional_investment
|
| 295 |
|
| 296 |
# ์ฌ์ฉ ์
|
|
|
|
| 299 |
# current_return, new_return, additional_investment = cost_averaging(78.17, 5.930644, 77.11, 75, 10)
|
| 300 |
|
| 301 |
def gradio_cost_averaging(current_avg_price, current_shares, current_price, desired_price, additional_shares):
|
| 302 |
+
with open('portfolio.html', 'r', encoding='utf-8') as file:
|
| 303 |
+
css = file.read()
|
| 304 |
+
|
| 305 |
current_return, new_return, additional_investment = cost_averaging(current_avg_price, current_shares, current_price, desired_price, additional_shares)
|
| 306 |
# Creating a styled HTML output similar to the uploaded image
|
| 307 |
+
|
| 308 |
+
current_buy_sell_class = ""
|
| 309 |
+
if current_return > 0:
|
| 310 |
+
current_buy_sell_class = f"<span style='color: #ff0000; font-weight: bold;'>{current_return:+,.2f}%</span>"
|
| 311 |
+
elif current_return < 0:
|
| 312 |
+
current_buy_sell_class = f"<span style='color: #0000ff; font-weight: bold;'>{current_return:,.2f}%</span>"
|
| 313 |
+
else:
|
| 314 |
+
current_buy_sell_class = f"<span class='buy-sell'><strong>0</strong></span>"
|
| 315 |
+
|
| 316 |
+
new_buy_sell_class = ""
|
| 317 |
+
if new_return > 0:
|
| 318 |
+
new_buy_sell_class = f"<span style='color: #ff0000; font-weight: bold;'>{new_return:+,.2f}%</span>"
|
| 319 |
+
elif current_return < 0:
|
| 320 |
+
new_buy_sell_class = f"<span style='color: #0000ff; font-weight: bold;'>{new_return:,.2f}%</span>"
|
| 321 |
+
else:
|
| 322 |
+
new_buy_sell_class = f"<span class='buy-sell'><strong>0</strong></span>"
|
| 323 |
+
|
| 324 |
+
# Construct the HTML string with the appropriate class
|
| 325 |
+
result_html = css+ f"""
|
| 326 |
+
<div style='font-size:1rem'>
|
| 327 |
+
<div style='display: flex; justify-content: space-around; align-items: center;'>
|
| 328 |
+
<div style='text-align: center;'>
|
| 329 |
+
<p>ํ์ฌ ์์ต๋ฅ (ํ๊ท ๊ตฌ๋งค๊ฐ๊ฒฉ)</p>
|
| 330 |
+
<p>{current_buy_sell_class}</p>
|
| 331 |
+
<p>{current_avg_price:,.2f}</p>
|
| 332 |
+
</div>
|
| 333 |
+
<div>โ</div>
|
| 334 |
+
<div style='text-align: center;'>
|
| 335 |
+
<p>๋ฌผํ๊ธฐ ํ ์์</p>
|
| 336 |
+
<p>{new_buy_sell_class}</p>
|
| 337 |
+
<p>{(current_price * (1 + new_return / 100)):,.2f}</p>
|
| 338 |
+
</div>
|
| 339 |
</div>
|
| 340 |
+
<p style='text-align: center;'>์ด ์ถ๊ฐ ๊ธ์ก: <strong>{additional_investment:,.2f}</strong></p>
|
| 341 |
</div>
|
|
|
|
|
|
|
| 342 |
"""
|
| 343 |
+
|
| 344 |
return result_html
|
| 345 |
+
|
| 346 |
pf_dataset_samples = [
|
| 347 |
["458730 krw 571 8,\n368590 krw 80 2", 17172, 0],
|
| 348 |
["SCHD USD 400 8,\nQQQ USD 40 2", 1000000, 25],
|
|
|
|
| 353 |
["458730,368590", 30],
|
| 354 |
["AAPL,GOOGL,MSFT", 30]
|
| 355 |
]
|
| 356 |
+
average_dataset_samples = [
|
| 357 |
+
[78.15, 6.024272, 77.11, 77.11, 1]
|
| 358 |
+
]
|
| 359 |
with gr.Blocks(css='style.css') as demo:
|
| 360 |
with gr.Column(elem_id="col-container"):
|
| 361 |
|
|
|
|
| 392 |
compare_button.click(plot_stock_prices, [stock_codes, period], comparison_result)
|
| 393 |
clear_button = gr.ClearButton([stock_codes, period, comparison_result], value="Clear")
|
| 394 |
|
| 395 |
+
with gr.TabItem("๐ฆ Average"):
|
| 396 |
current_avg_price_input = gr.Number(label="Current Average Price", value=78.15)
|
| 397 |
current_shares_input = gr.Number(label="Current Shares", value=6.024272)
|
| 398 |
current_price_input = gr.Number(label="Current Price", value=77.11)
|
| 399 |
desired_price_input = gr.Number(label="Desired Price", value=77.11)
|
| 400 |
additional_shares_input = gr.Number(label="Additional Shares", value=1)
|
| 401 |
+
average_dataset = Dataset(components=[current_avg_price_input, current_shares_input, current_price_input, desired_price_input, additional_shares_input], samples=average_dataset_samples, label=None)
|
| 402 |
+
average_dataset.click(
|
| 403 |
+
fn=lambda x: x,
|
| 404 |
+
inputs=average_dataset, # ๋ฐ์ดํฐ์ธํธ ์์ฒด๋ฅผ ์
๋ ฅ์ผ๋ก ์ง์
|
| 405 |
+
outputs=[current_avg_price_input, current_shares_input, current_price_input, desired_price_input, additional_shares_input] # ๊ฒฐ๊ณผ ๋ฉ์์ง ๋ฐ ์
๋ ฅ ํ๋๋ค์ ์ถ๋ ฅ์ผ๋ก ์ค์
|
| 406 |
+
)
|
| 407 |
+
average_button = gr.Button("Calculate Cost Averaging")
|
| 408 |
average_results = gr.HTML() # Changed to HTML for styled output
|
| 409 |
|
| 410 |
+
average_button.click(
|
| 411 |
gradio_cost_averaging,
|
| 412 |
inputs=[current_avg_price_input, current_shares_input, current_price_input, desired_price_input, additional_shares_input],
|
| 413 |
outputs=average_results
|
| 414 |
)
|
| 415 |
+
clear_button = gr.ClearButton([current_avg_price_input, current_shares_input, current_price_input, desired_price_input, additional_shares_input], value="Clear")
|
| 416 |
|
| 417 |
with gr.TabItem("๐ About"):
|
| 418 |
gr.Markdown("""
|