Upload app.py
Browse files
app.py
CHANGED
@@ -24,8 +24,8 @@ class StockCodeNotFoundError(Exception):
|
|
24 |
class CurrencyConversionError(Exception):
|
25 |
pass
|
26 |
|
27 |
-
def parse_input(text,
|
28 |
-
logger.info(f"Parsing input: {text} with cash amount: {
|
29 |
try:
|
30 |
lines = text.strip().split(',')
|
31 |
stock_inputs = []
|
@@ -42,6 +42,11 @@ def parse_input(text, cash_amount, cash_ratio):
|
|
42 |
else:
|
43 |
raise ValueError("Invalid input format.")
|
44 |
|
|
|
|
|
|
|
|
|
|
|
45 |
krw_cash = {'amount': cash_amount, 'target_weight': cash_ratio / 100.0}
|
46 |
|
47 |
cash_ratio = krw_cash['target_weight']
|
@@ -168,10 +173,9 @@ def get_portfolio_rebalancing_info(portfolio, target_weights, krw_cash):
|
|
168 |
logger.info("Portfolio rebalancing information calculated")
|
169 |
return result_message
|
170 |
|
171 |
-
def rebalance_portfolio(input_text,
|
172 |
try:
|
173 |
-
|
174 |
-
stock_inputs, krw_cash = parse_input(input_text, cash_amount, cash_ratio)
|
175 |
portfolio, target_weights, krw_cash = build_portfolio(stock_inputs, krw_cash)
|
176 |
result_message = get_portfolio_rebalancing_info(portfolio, target_weights, krw_cash)
|
177 |
return result_message
|
@@ -187,29 +191,7 @@ interface = gr.Interface(
|
|
187 |
gr.Slider(minimum=0, maximum=100, step=1, value=33, label="ํ๊ธ ๋น์จ (%)")
|
188 |
],
|
189 |
outputs="text",
|
190 |
-
title=f"Re-Balancing Analysis | Your Portfolio Holdings as of {current_date}"
|
191 |
-
# description=(
|
192 |
-
# "๊ธฐ๋ณธ ํตํ: KRW\n\n"
|
193 |
-
# "๋ฆฌ๋ฐธ๋ฐ์ฑ์ 1์ฃผ ๋จ์๋ก ๊ณ์ฐ๋ฉ๋๋ค.\n\n"
|
194 |
-
# "ํฌํธํด๋ฆฌ์ค ๋ฐ์ดํฐ๋ฅผ ๋ค์ ํ์์ผ๋ก ์
๋ ฅํ์ธ์:\n"
|
195 |
-
# " - ์ฃผ์์ ๊ฒฝ์ฐ: ํตํ ํฐ์ปค ๋ณด์ ์๋ ๋ชฉํ๋น์ค\n"
|
196 |
-
# " - ์ถ๊ฐ ํฌ์๊ธ์ ์
๋ ฅํ์ธ์\n"
|
197 |
-
# " - ์ฌ๋ผ์ด๋๋ฅผ ์ฌ์ฉํ์ฌ ๋ชฉํํ๊ธ๋น์จ (%)์ ์
๋ ฅํ์ธ์\n\n"
|
198 |
-
# " - ์ฌ๋ฌ ์ข
๋ชฉ์ ์ผํ๋ก ๊ตฌ๋ถํ์ฌ ์
๋ ฅํ ์ ์์ต๋๋ค.\n"
|
199 |
-
# " - ์๋๊ณผ ๋น์ค์ ๋ํด ์ฌ์น ์ฐ์ฐ์ ์ฌ์ฉํ ์ ์์ต๋๋ค.\n\n"
|
200 |
-
# "์์:\n"
|
201 |
-
# " - usd schd 545 8, usd qqq 22 2\n\n"
|
202 |
-
# " - ๋ณด์ ์ฃผ์: SCHD 545์ฃผ, QQQ 22์ฃผ\n"
|
203 |
-
# " - ๋ชฉํ๋น์ค: SCHD:QQQ = 8:2\n\n"
|
204 |
-
# "์ฌ์น ์ฐ์ฐ ์์:\n"
|
205 |
-
# " - krw 458730 530+50 8/2, krw 368590 79*2 2+1\n\n"
|
206 |
-
# "์ถ๋ ฅ ํ์:\n\n"
|
207 |
-
# " - ์ข
๋ชฉ์ฝ๋ @ํ์ฌ๊ฐ\n\n"
|
208 |
-
# " - ํ๊ฐ๊ธ์ก [ํ์ฌ๋น์ค%]\n\n"
|
209 |
-
# " - [๋ชฉํ๋น์ค%] ์ ๊ท์๋\n\n"
|
210 |
-
# " - ์ ์ฒด ํ๊ฐ๊ธ์ก"
|
211 |
-
# )
|
212 |
-
|
213 |
)
|
214 |
|
215 |
if __name__ == "__main__":
|
|
|
24 |
class CurrencyConversionError(Exception):
|
25 |
pass
|
26 |
|
27 |
+
def parse_input(text, cash_amount_expr, cash_ratio):
|
28 |
+
logger.info(f"Parsing input: {text} with cash amount expression: {cash_amount_expr} and cash ratio: {cash_ratio}")
|
29 |
try:
|
30 |
lines = text.strip().split(',')
|
31 |
stock_inputs = []
|
|
|
42 |
else:
|
43 |
raise ValueError("Invalid input format.")
|
44 |
|
45 |
+
if cash_amount_expr.strip():
|
46 |
+
cash_amount = math.floor(eval(cash_amount_expr.replace(' ', '')))
|
47 |
+
else:
|
48 |
+
cash_amount = 0
|
49 |
+
|
50 |
krw_cash = {'amount': cash_amount, 'target_weight': cash_ratio / 100.0}
|
51 |
|
52 |
cash_ratio = krw_cash['target_weight']
|
|
|
173 |
logger.info("Portfolio rebalancing information calculated")
|
174 |
return result_message
|
175 |
|
176 |
+
def rebalance_portfolio(input_text, cash_amount_expr, cash_ratio):
|
177 |
try:
|
178 |
+
stock_inputs, krw_cash = parse_input(input_text, cash_amount_expr, cash_ratio)
|
|
|
179 |
portfolio, target_weights, krw_cash = build_portfolio(stock_inputs, krw_cash)
|
180 |
result_message = get_portfolio_rebalancing_info(portfolio, target_weights, krw_cash)
|
181 |
return result_message
|
|
|
191 |
gr.Slider(minimum=0, maximum=100, step=1, value=33, label="ํ๊ธ ๋น์จ (%)")
|
192 |
],
|
193 |
outputs="text",
|
194 |
+
title=f"Re-Balancing Analysis | Your Portfolio Holdings as of {current_date}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
195 |
)
|
196 |
|
197 |
if __name__ == "__main__":
|