|
@@ -1,5 +1,6 @@
|
|
|
package com.smppw.analysis.application.service.info;
|
|
|
|
|
|
+import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.collection.ListUtil;
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
@@ -11,22 +12,39 @@ import com.smppw.analysis.domain.dto.performance.IndicatorParams;
|
|
|
import com.smppw.analysis.domain.manager.performance.Performance;
|
|
|
import com.smppw.analysis.domain.manager.performance.PerformanceConstants;
|
|
|
import com.smppw.analysis.domain.manager.performance.PerformanceFactory;
|
|
|
+import com.smppw.analysis.domain.service.BaseIndicatorServiceV2;
|
|
|
import com.smppw.analysis.domain.service.BaseInfoService;
|
|
|
-import com.smppw.common.pojo.enums.Indicator;
|
|
|
+import com.smppw.analysis.domain.service.NavService;
|
|
|
+import com.smppw.common.pojo.IStrategy;
|
|
|
+import com.smppw.common.pojo.NewSubStrategy;
|
|
|
+import com.smppw.common.pojo.dto.DateValue;
|
|
|
+import com.smppw.common.pojo.dto.calc.IndicatorCalcPropertyDto;
|
|
|
+import com.smppw.common.pojo.dto.calc.IndicatorCalcTimeRangeDto;
|
|
|
+import com.smppw.common.pojo.enums.*;
|
|
|
+import com.smppw.core.IndicatorService;
|
|
|
+import com.smppw.utils.CalcUtils;
|
|
|
+import com.smppw.utils.NavUtil;
|
|
|
+import com.smppw.utils.StrategyHandleUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.TreeMap;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class FundInfoService {
|
|
|
+ private final NavService navService;
|
|
|
private final PerformanceFactory factory;
|
|
|
private final BaseInfoService baseInfoService;
|
|
|
+ private final BaseIndicatorServiceV2 baseIndicatorServiceV2;
|
|
|
|
|
|
- public FundInfoService(PerformanceFactory factory, BaseInfoService baseInfoService) {
|
|
|
+ public FundInfoService(NavService navService, PerformanceFactory factory,
|
|
|
+ BaseInfoService baseInfoService, BaseIndicatorServiceV2 baseIndicatorServiceV2) {
|
|
|
this.factory = factory;
|
|
|
+ this.navService = navService;
|
|
|
this.baseInfoService = baseInfoService;
|
|
|
+ this.baseIndicatorServiceV2 = baseIndicatorServiceV2;
|
|
|
}
|
|
|
|
|
|
public PrivatelyFundHeadInfoVO headInfo(HeadInfoReq params) {
|
|
@@ -84,30 +102,81 @@ public class FundInfoService {
|
|
|
return vo;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 私募基金相似产品,计算相关性时代码可以优化(参考基金相关性)
|
|
|
+ *
|
|
|
+ * @param req /
|
|
|
+ * @return /
|
|
|
+ */
|
|
|
public List<FundSimilarVO> getFundSimilarList(FundSimilarReq req) {
|
|
|
List<String> refIds = ListUtil.toLinkedList(req.getRefId());
|
|
|
+ IStrategy strategy = StrategyHandleUtils.getStrategy(req.getStrategy());
|
|
|
+ Map<String, List<DateValue>> secNavMap = this.navService.getSecIdDateValueNavListMapByDb(refIds,
|
|
|
+ null, null, Visibility.Both, NavType.CumulativeNav, MapUtil.empty());
|
|
|
+ List<IndicatorCalcTimeRangeDto> secTimeRanges = IndicatorService.getInstance().getSecTimeRange(req.getRefId(), Frequency.Monthly, secNavMap);
|
|
|
+ String startDate = null;
|
|
|
+ String endDate = null;
|
|
|
+ if (CollUtil.isNotEmpty(secTimeRanges)) {
|
|
|
+ for (IndicatorCalcTimeRangeDto secTimeRange : secTimeRanges) {
|
|
|
+ if (TimeRange.Last1Year == secTimeRange.getTimeRange()) {
|
|
|
+ startDate = secTimeRange.getStartDate();
|
|
|
+ endDate = secTimeRange.getEndDate();
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
FundSimilarParams params = req.convert();
|
|
|
+ params.setStartDate(startDate);
|
|
|
List<FundSimilarDo> dataList = this.baseInfoService.getFundSimilarList(params);
|
|
|
List<String> fundIds = dataList.stream().map(FundSimilarDo::getFundId).collect(Collectors.toList());
|
|
|
if (CollUtil.isNotEmpty(fundIds)) {
|
|
|
refIds.addAll(fundIds);
|
|
|
}
|
|
|
-// Map<String, List<IndicatorCalcPropertyDto>> multiSecRetListNew = this.baseIndicatorServiceV2.getMultiSecRetListNew(
|
|
|
-// secIds, ListUtil.empty(), Frequency.Monthly, Frequency.Daily, startDate, endDate, false, Consts.BENCHMARK,
|
|
|
-// params.getRaiseType(), Strategy.All, Visibility.Visible, NavType.CumulativeNav);
|
|
|
-// List<Map<String, Object>> initRetList = NavUtil.handleNextStepNew(secIds, ListUtil.empty(), multiSecRetListNew, false);
|
|
|
-// Map<String, Map<String, Double>> retMap = RateConvertorUtils.transfer2TwoDimensionMap(initRetList, "fund_id", "end_date", "ret_range");
|
|
|
-// Double[][] corArr = CalcUtils.getCorrelationMatrix(retMap, ListUtil.toList(params.getRefId()), secIds);
|
|
|
-// for (FundSimilarDo map : dataList) {
|
|
|
-// FundSimilarVO similarVO = BeanUtil.copyProperties(map, FundSimilarVO.class);
|
|
|
-// int i = fundIds.indexOf(map.getFundId()) + 1; // 因为第一个基金是当前基金,所以需要 + 1 来取该基金与当前基金的相关性
|
|
|
-// similarVO.setSimilar(corArr[0][i]);
|
|
|
-// similarVO.setStrategy(StrategyHandleUtils.getStrategy(map.getStrategy()).getStrategyNameDesc());
|
|
|
-// similarVO.setSubStrategy(this.getStrategyName(map.getSubStrategy()));
|
|
|
-// similarVO.setThirdStrategy(this.getStrategyName(map.getThirdStrategy()));
|
|
|
-// resultList.add(similarVO);
|
|
|
-// }
|
|
|
-// resultList.stream().filter(e -> e.getSimilar() != null && e.getSimilar() >= Double.parseDouble(params.getThreshold())).collect(Collectors.toList());
|
|
|
- return null;
|
|
|
+ Map<String, List<DateValue>> allNavMap = this.navService.getSecIdDateValueNavListMapByDb(refIds,
|
|
|
+ startDate, endDate, Visibility.Both, NavType.CumulativeNav, MapUtil.empty());
|
|
|
+ Map<String, List<IndicatorCalcPropertyDto>> multiSecRetListNew = this.baseIndicatorServiceV2.getMultiSecRetListNew(
|
|
|
+ refIds, ListUtil.empty(), Frequency.Monthly, Frequency.Daily, startDate, endDate, false, params.getBenchmarkId(),
|
|
|
+ params.getRaiseType(), strategy, Visibility.Both, NavType.CumulativeNav, allNavMap);
|
|
|
+ List<Map<String, Object>> initRetList = NavUtil.handleNextStepNew(refIds, ListUtil.empty(), multiSecRetListNew, false);
|
|
|
+ Map<String, Map<String, Double>> retMap = this.transfer2TwoDimensionMap(initRetList);
|
|
|
+ Double[][] corArr = CalcUtils.getCorrelationMatrix(retMap, ListUtil.toList(params.getRefId()), refIds);
|
|
|
+ List<FundSimilarVO> resultList = ListUtil.list(true);
|
|
|
+ for (FundSimilarDo map : dataList) {
|
|
|
+ FundSimilarVO similarVO = BeanUtil.copyProperties(map, FundSimilarVO.class);
|
|
|
+ int i = fundIds.indexOf(map.getFundId()) + 1; // 因为第一个基金是当前基金,所以需要 + 1 来取该基金与当前基金的相关性
|
|
|
+ similarVO.setSimilar(corArr[0][i]);
|
|
|
+ similarVO.setStrategy(StrategyHandleUtils.getStrategy(map.getStrategy()).getStrategyNameDesc());
|
|
|
+ similarVO.setSubStrategy(this.getStrategyName(map.getSubStrategy()));
|
|
|
+ similarVO.setThirdStrategy(this.getStrategyName(map.getThirdStrategy()));
|
|
|
+ resultList.add(similarVO);
|
|
|
+ }
|
|
|
+ return resultList.stream().filter(e -> e.getSimilar() != null && e.getSimilar() >= Double.parseDouble(params.getThreshold())).collect(Collectors.toList());
|
|
|
+ }
|
|
|
+
|
|
|
+ private String getStrategyName(String strategyKey) {
|
|
|
+ IStrategy strategy = StrategyHandleUtils.getStrategy(strategyKey);
|
|
|
+ if (strategy == null || strategy == NewSubStrategy.OtherStrategy || strategy.getStrategyId() == -1) {
|
|
|
+ return "--";
|
|
|
+ }
|
|
|
+ return strategy.getStrategyNameDesc();
|
|
|
+ }
|
|
|
+
|
|
|
+ private Map<String, Map<String, Double>> transfer2TwoDimensionMap(List<Map<String, Object>> initRetList) {
|
|
|
+ Map<String, Map<String, Double>> map = new TreeMap<>();
|
|
|
+ for (Map<String, Object> unit : initRetList) {
|
|
|
+ if (unit != null) {
|
|
|
+ String id = unit.get("fund_id").toString();
|
|
|
+ if (!map.containsKey(id)) {
|
|
|
+ map.put(id, new TreeMap<>());
|
|
|
+ }
|
|
|
+ Object t = unit.get("ret_range");
|
|
|
+ if (t == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ map.get(id).put(unit.get("end_date").toString(), Double.valueOf(unit.get("ret_range").toString()));
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return map;
|
|
|
}
|
|
|
}
|