40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
"""现有业务 ORM 到投顾意图输入的适配。"""
|
|||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from decimal import Decimal
|
||
|
|
|
||
|
|
|
||
|
|
def _number(value):
|
||
|
|
return float(value) if isinstance(value, Decimal) else value
|
||
|
|
|
||
|
|
|
||
|
|
def to_fund_performance_row(row) -> dict:
|
||
|
|
return {
|
||
|
|
"period": getattr(row, "period", None),
|
||
|
|
"return_rate": _number(getattr(row, "return_rate", None)),
|
||
|
|
"annual_volatility": _number(getattr(row, "annual_volatility", None)),
|
||
|
|
"max_drawdown": _number(getattr(row, "max_drawdown", None)),
|
||
|
|
"sharpe": _number(getattr(row, "sharpe", None)),
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
def to_holding_input(holding, product) -> dict:
|
||
|
|
return {
|
||
|
|
"product_id": holding.product_id,
|
||
|
|
"product_code": product.product_code,
|
||
|
|
"asset_class": product.product_type,
|
||
|
|
"market_value": holding.current_value or Decimal("0"),
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
def to_product_candidate(product) -> dict:
|
||
|
|
expected_return = product.expected_return or Decimal("0")
|
||
|
|
return {
|
||
|
|
"product_id": product.id,
|
||
|
|
"product_code": product.product_code,
|
||
|
|
"product_name": product.product_name,
|
||
|
|
"asset_class": product.product_type,
|
||
|
|
"risk_level": product.risk_level,
|
||
|
|
"performance_score": float(expected_return),
|
||
|
|
}
|