Commit 17d2a2e8 authored by stephen.wang's avatar stephen.wang

Merge remote-tracking branch 'origin/dev-dividend' into dev-dividend

parents bb08707e b2d66be7
...@@ -452,8 +452,6 @@ class PRRSolver(ARCSolver): ...@@ -452,8 +452,6 @@ class PRRSolver(ARCSolver):
model.cons_RR_LE_TRR = Constraint( model.cons_RR_LE_TRR = Constraint(
expr=sum([model.w[i] * RR_LE_TRR[i] for i in model.indices]) >= minRRweightWithinTRR) expr=sum([model.w[i] * RR_LE_TRR[i] for i in model.indices]) >= minRRweightWithinTRR)
# todo trr<指定值
# model.cons_LE_TRR = Constraint(expr=sum([model.w[i] * RR[i] for i in model.indices]) <= TRR)
if TRR < 5: if TRR < 5:
model.cons_RR_in_1_5 = Constraint( model.cons_RR_in_1_5 = Constraint(
expr=sum([model.z[i] * (RR_in_1_5[i] * self.max_count - RR_EQ_5[i]) for i in model.indices]) >= 0) expr=sum([model.z[i] * (RR_in_1_5[i] * self.max_count - RR_EQ_5[i]) for i in model.indices]) >= 0)
......
import pandas as pd import pandas as pd
from py_jftech import autowired from py_jftech import autowired, get_config
from api import DatumType, Datum from api import DatumType, Datum
...@@ -38,10 +38,12 @@ def format_weight(weight: dict, to=1) -> dict: ...@@ -38,10 +38,12 @@ def format_weight(weight: dict, to=1) -> dict:
if weight_series.sum() == to: if weight_series.sum() == to:
return dict(weight_series) return dict(weight_series)
id_sort = sorted(weight_series.to_dict().keys(), key=lambda x: risk_dict.get(int(x))) id_sort = sorted(weight_series.to_dict().keys(), key=lambda x: risk_dict.get(int(x)))
low = get_config('portfolios.solver.mpt.low-weight')
high = get_config('portfolios.solver.mpt.high-weight')[0]
# 低风险 # 低风险
minidx = id_sort[0] minidx = [i for i in id_sort if weight[i] < high][0]
# 高风险 # 高风险
maxidx = id_sort[-1] maxidx = [i for i in id_sort if weight[i] > low][-1]
if weight_series.sum() < to: if weight_series.sum() < to:
weight_series[minidx] += to - weight_series.sum() weight_series[minidx] += to - weight_series.sum()
elif weight_series.sum() > to: elif weight_series.sum() > to:
...@@ -50,4 +52,4 @@ def format_weight(weight: dict, to=1) -> dict: ...@@ -50,4 +52,4 @@ def format_weight(weight: dict, to=1) -> dict:
if __name__ == '__main__': if __name__ == '__main__':
format_weight({"5": 0.35, "6": 0.35, "10": 0.09, "11": 0.16, "22": 0.05}) format_weight({"5": 0.35, "6": 0.35, "10": 0.1, "11": 0.16, "22": 0.05})
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment