|
@@ -20,11 +20,10 @@ import com.smppw.analysis.application.service.position.PositionLoadFactory;
|
|
import com.smppw.analysis.domain.entity.FutureDailyPriceDO;
|
|
import com.smppw.analysis.domain.entity.FutureDailyPriceDO;
|
|
import com.smppw.analysis.domain.gateway.CacheFactory;
|
|
import com.smppw.analysis.domain.gateway.CacheFactory;
|
|
import com.smppw.analysis.infrastructure.config.AnalysisProperty;
|
|
import com.smppw.analysis.infrastructure.config.AnalysisProperty;
|
|
|
|
+import com.smppw.analysis.infrastructure.exception.APIException;
|
|
import com.smppw.analysis.infrastructure.persistence.BaseUnderlyingMapper;
|
|
import com.smppw.analysis.infrastructure.persistence.BaseUnderlyingMapper;
|
|
import com.smppw.analysis.infrastructure.persistence.IndexesTradeDateDoMapper;
|
|
import com.smppw.analysis.infrastructure.persistence.IndexesTradeDateDoMapper;
|
|
-import com.smppw.common.exception.APIException;
|
|
|
|
import com.smppw.common.pojo.FundFuturesOption;
|
|
import com.smppw.common.pojo.FundFuturesOption;
|
|
-import com.smppw.common.pojo.ValueLabelDo;
|
|
|
|
import com.smppw.common.pojo.ValueLabelVO;
|
|
import com.smppw.common.pojo.ValueLabelVO;
|
|
import com.smppw.utils.BigDecimalUtils;
|
|
import com.smppw.utils.BigDecimalUtils;
|
|
import org.apache.commons.math3.linear.Array2DRowRealMatrix;
|
|
import org.apache.commons.math3.linear.Array2DRowRealMatrix;
|
|
@@ -72,10 +71,10 @@ public class MarginalRiskContributionBizHandler extends AbstractBizHandler<Margi
|
|
if (CollUtil.isEmpty(positionInfos)) {
|
|
if (CollUtil.isEmpty(positionInfos)) {
|
|
return resultList;
|
|
return resultList;
|
|
}
|
|
}
|
|
- List<ValueLabelDo> breedNameList = this.baseUnderlyingMapper.getOptionTypeList();
|
|
|
|
|
|
+ List<ValueLabelVO> breedNameList = this.baseUnderlyingMapper.getOptionTypeList();
|
|
// 区分金融期货和商品期货,单独取数
|
|
// 区分金融期货和商品期货,单独取数
|
|
- Map<ValueLabelDo, List<String>> financeRefMap = MapUtil.newHashMap();
|
|
|
|
- Map<ValueLabelDo, List<String>> commodityRefMap = MapUtil.newHashMap();
|
|
|
|
|
|
+ Map<ValueLabelVO, List<String>> financeRefMap = MapUtil.newHashMap();
|
|
|
|
+ Map<ValueLabelVO, List<String>> commodityRefMap = MapUtil.newHashMap();
|
|
this.distRef(breedNameList, positionInfos, financeRefMap, commodityRefMap);
|
|
this.distRef(breedNameList, positionInfos, financeRefMap, commodityRefMap);
|
|
// 按日期分组
|
|
// 按日期分组
|
|
Map<String, List<FundPositionDetail>> positionMap = positionInfos.stream().collect(Collectors.groupingBy(FundPositionDetail::getDate));
|
|
Map<String, List<FundPositionDetail>> positionMap = positionInfos.stream().collect(Collectors.groupingBy(FundPositionDetail::getDate));
|
|
@@ -95,7 +94,7 @@ public class MarginalRiskContributionBizHandler extends AbstractBizHandler<Margi
|
|
// 所有品种的近31个交易日日收益率
|
|
// 所有品种的近31个交易日日收益率
|
|
List<FutureDailyRet> dataList = dateRetMap.get(k);
|
|
List<FutureDailyRet> dataList = dateRetMap.get(k);
|
|
// 得到计算风险贡献的数据,计算风险贡献
|
|
// 得到计算风险贡献的数据,计算风险贡献
|
|
- List<ValueLabelDo> breeds = ListUtil.list(true);
|
|
|
|
|
|
+ List<ValueLabelVO> breeds = ListUtil.list(true);
|
|
List<Double> weightList = ListUtil.list(true);
|
|
List<Double> weightList = ListUtil.list(true);
|
|
double[][] retsMatrix = new double[breedNameList.size()][dateList.size() - 1];
|
|
double[][] retsMatrix = new double[breedNameList.size()][dateList.size() - 1];
|
|
this.getMatrixData(breedNameList, v, dateList, financeRefMap, commodityRefMap, dataList, breeds, weightList, retsMatrix);
|
|
this.getMatrixData(breedNameList, v, dateList, financeRefMap, commodityRefMap, dataList, breeds, weightList, retsMatrix);
|
|
@@ -115,7 +114,7 @@ public class MarginalRiskContributionBizHandler extends AbstractBizHandler<Margi
|
|
.sorted(Comparator.reverseOrder()).limit(31).sorted().collect(Collectors.toList());
|
|
.sorted(Comparator.reverseOrder()).limit(31).sorted().collect(Collectors.toList());
|
|
}
|
|
}
|
|
|
|
|
|
- private MarginalRiskContributionVO calcRiskContAndBuildVo(String k, List<ValueLabelDo> breeds, List<Double> weightList, double[][] retsMatrix) {
|
|
|
|
|
|
+ private MarginalRiskContributionVO calcRiskContAndBuildVo(String k, List<ValueLabelVO> breeds, List<Double> weightList, double[][] retsMatrix) {
|
|
int size = weightList.size();
|
|
int size = weightList.size();
|
|
double[][] covList = this.getCovByRet(retsMatrix);
|
|
double[][] covList = this.getCovByRet(retsMatrix);
|
|
double[] realWeightList = new double[size];
|
|
double[] realWeightList = new double[size];
|
|
@@ -129,7 +128,7 @@ public class MarginalRiskContributionBizHandler extends AbstractBizHandler<Margi
|
|
|
|
|
|
List<MarginalRiskContribution> breedRiskContList = ListUtil.list(false);
|
|
List<MarginalRiskContribution> breedRiskContList = ListUtil.list(false);
|
|
for (int i = 0; i < breeds.size(); i++) {
|
|
for (int i = 0; i < breeds.size(); i++) {
|
|
- ValueLabelDo breed = breeds.get(i);
|
|
|
|
|
|
+ ValueLabelVO breed = breeds.get(i);
|
|
String breedValue = breed.getValue();
|
|
String breedValue = breed.getValue();
|
|
ValueLabelVO asset;
|
|
ValueLabelVO asset;
|
|
if (PositionConstants.BOND_BREEDS.contains(breedValue)) {
|
|
if (PositionConstants.BOND_BREEDS.contains(breedValue)) {
|
|
@@ -155,11 +154,11 @@ public class MarginalRiskContributionBizHandler extends AbstractBizHandler<Margi
|
|
return vo;
|
|
return vo;
|
|
}
|
|
}
|
|
|
|
|
|
- private void getMatrixData(List<ValueLabelDo> breedNameList, List<FundPositionDetail> v, List<String> dateList,
|
|
|
|
- Map<ValueLabelDo, List<String>> financeRefMap, Map<ValueLabelDo, List<String>> commodityRefMap,
|
|
|
|
- List<FutureDailyRet> dataList, List<ValueLabelDo> breeds, List<Double> weightList, double[][] retsMatrix) {
|
|
|
|
|
|
+ private void getMatrixData(List<ValueLabelVO> breedNameList, List<FundPositionDetail> v, List<String> dateList,
|
|
|
|
+ Map<ValueLabelVO, List<String>> financeRefMap, Map<ValueLabelVO, List<String>> commodityRefMap,
|
|
|
|
+ List<FutureDailyRet> dataList, List<ValueLabelVO> breeds, List<Double> weightList, double[][] retsMatrix) {
|
|
for (int i = 0; i < breedNameList.size(); i++) {
|
|
for (int i = 0; i < breedNameList.size(); i++) {
|
|
- ValueLabelDo breed = breedNameList.get(i);
|
|
|
|
|
|
+ ValueLabelVO breed = breedNameList.get(i);
|
|
List<String> refIds = ListUtil.list(false);
|
|
List<String> refIds = ListUtil.list(false);
|
|
List<String> finance = financeRefMap.getOrDefault(breed, ListUtil.empty());
|
|
List<String> finance = financeRefMap.getOrDefault(breed, ListUtil.empty());
|
|
if (CollUtil.isNotEmpty(finance)) {
|
|
if (CollUtil.isNotEmpty(finance)) {
|
|
@@ -204,7 +203,7 @@ public class MarginalRiskContributionBizHandler extends AbstractBizHandler<Margi
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private List<FutureDailyRet> getFutureDailyRets(String k, List<String> dateList, String firstDate, Map<ValueLabelDo, List<String>> financeRefMap, Map<ValueLabelDo, List<String>> commodityRefMap) {
|
|
|
|
|
|
+ private List<FutureDailyRet> getFutureDailyRets(String k, List<String> dateList, String firstDate, Map<ValueLabelVO, List<String>> financeRefMap, Map<ValueLabelVO, List<String>> commodityRefMap) {
|
|
List<FutureDailyRet> dataList = ListUtil.list(false);
|
|
List<FutureDailyRet> dataList = ListUtil.list(false);
|
|
List<String> financeRefIds = financeRefMap.values().stream().flatMap(Collection::stream).distinct().collect(Collectors.toList());
|
|
List<String> financeRefIds = financeRefMap.values().stream().flatMap(Collection::stream).distinct().collect(Collectors.toList());
|
|
List<String> commodityRefIds = commodityRefMap.values().stream().flatMap(Collection::stream).distinct().collect(Collectors.toList());
|
|
List<String> commodityRefIds = commodityRefMap.values().stream().flatMap(Collection::stream).distinct().collect(Collectors.toList());
|
|
@@ -245,7 +244,7 @@ public class MarginalRiskContributionBizHandler extends AbstractBizHandler<Margi
|
|
return dataList;
|
|
return dataList;
|
|
}
|
|
}
|
|
|
|
|
|
- private void distRef(List<ValueLabelDo> breedNameList, List<FundPositionDetail> v, Map<ValueLabelDo, List<String>> financeRefMap, Map<ValueLabelDo, List<String>> commodityRefMap) {
|
|
|
|
|
|
+ private void distRef(List<ValueLabelVO> breedNameList, List<FundPositionDetail> v, Map<ValueLabelVO, List<String>> financeRefMap, Map<ValueLabelVO, List<String>> commodityRefMap) {
|
|
// 遍历品种获取各品种下的合约
|
|
// 遍历品种获取各品种下的合约
|
|
breedNameList.forEach(breed -> {
|
|
breedNameList.forEach(breed -> {
|
|
String breedValue = breed.getValue();
|
|
String breedValue = breed.getValue();
|