parent
94cb9630a0
commit
0345bf7449
12 changed files with 236 additions and 2 deletions
@ -0,0 +1,17 @@ |
|||||||
|
package com.blockchain.server.yyyf.indicators; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author fengyu |
||||||
|
*/ |
||||||
|
public interface IndicatorsHandler { |
||||||
|
String HANDLER_NAME = "IndicatorsHandler"; |
||||||
|
/** |
||||||
|
* handle indicator |
||||||
|
* |
||||||
|
* @param assessUserId page result id |
||||||
|
* @return indicator result |
||||||
|
* @author fengyu.wang |
||||||
|
* @date 2020-06-03 21:28:18 |
||||||
|
*/ |
||||||
|
Float handleIndicator(String assessUserId); |
||||||
|
} |
@ -0,0 +1,42 @@ |
|||||||
|
package com.blockchain.server.yyyf.indicators.handle; |
||||||
|
|
||||||
|
import com.blockchain.server.yyyf.indicators.IndicatorsHandler; |
||||||
|
import com.blockchain.server.yyyf.indicators.IndicatorsManager; |
||||||
|
import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
import javax.persistence.EntityExistsException; |
||||||
|
import java.math.BigDecimal; |
||||||
|
import java.util.Comparator; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author fengyu |
||||||
|
*/ |
||||||
|
@AllArgsConstructor |
||||||
|
@Component(AnnualGrowthRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) |
||||||
|
public class AnnualGrowthRateIndicatorsHandler implements IndicatorsHandler { |
||||||
|
public static final String HANDLER_NAME = "AnnualGrowthRate"; |
||||||
|
|
||||||
|
private final IndicatorsManager indicatorsManager; |
||||||
|
|
||||||
|
@Override |
||||||
|
public Float handleIndicator(String assessUserId) { |
||||||
|
//TODO should be cached
|
||||||
|
List<AssetsReporter> reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId); |
||||||
|
AssetsReporter lastAssets = reporterList |
||||||
|
.stream() |
||||||
|
.max(Comparator.comparingLong(AssetsReporter::getDays)) |
||||||
|
.orElseThrow(() -> new EntityExistsException("assessUser:" + assessUserId)); |
||||||
|
AssetsReporter firstAssets = reporterList |
||||||
|
.stream() |
||||||
|
.min(Comparator.comparingLong(AssetsReporter::getDays)) |
||||||
|
.orElseThrow(() -> new EntityExistsException("assessUser:" + assessUserId)); |
||||||
|
BigDecimal result = lastAssets.getAssets() |
||||||
|
.divide(firstAssets.getAssets()) |
||||||
|
.pow((int) (360.0 / lastAssets.getDays())) |
||||||
|
.subtract(BigDecimal.valueOf(1)); |
||||||
|
return result.divide(BigDecimal.valueOf(100)).floatValue(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,17 @@ |
|||||||
|
package com.blockchain.server.yyyf.indicators.handle; |
||||||
|
|
||||||
|
import com.blockchain.server.yyyf.indicators.IndicatorsHandler; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author fengyu |
||||||
|
*/ |
||||||
|
@Component(AssetLiabilityRiskRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) |
||||||
|
public class AssetLiabilityRiskRateIndicatorsHandler implements IndicatorsHandler { |
||||||
|
public static final String HANDLER_NAME = "AssetLiabilityRiskRate"; |
||||||
|
|
||||||
|
@Override |
||||||
|
public Float handleIndicator(String assessUserId) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,17 @@ |
|||||||
|
package com.blockchain.server.yyyf.indicators.handle; |
||||||
|
|
||||||
|
import com.blockchain.server.yyyf.indicators.IndicatorsHandler; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author fengyu |
||||||
|
*/ |
||||||
|
@Component(FluctuationRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) |
||||||
|
public class FluctuationRateIndicatorsHandler implements IndicatorsHandler { |
||||||
|
public static final String HANDLER_NAME = "FluctuationRate"; |
||||||
|
|
||||||
|
@Override |
||||||
|
public Float handleIndicator(String assessUserId) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,37 @@ |
|||||||
|
package com.blockchain.server.yyyf.indicators.handle; |
||||||
|
|
||||||
|
import com.blockchain.server.yyyf.indicators.IndicatorsHandler; |
||||||
|
import com.blockchain.server.yyyf.indicators.IndicatorsManager; |
||||||
|
import com.blockchain.server.yyyf.indicators.dto.AssetsReporter; |
||||||
|
import lombok.AllArgsConstructor; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
import javax.persistence.EntityExistsException; |
||||||
|
import java.math.BigDecimal; |
||||||
|
import java.util.Comparator; |
||||||
|
import java.util.List; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author fengyu |
||||||
|
*/ |
||||||
|
@AllArgsConstructor |
||||||
|
@Component(GrowthRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) |
||||||
|
public class GrowthRateIndicatorsHandler implements IndicatorsHandler { |
||||||
|
public static final String HANDLER_NAME = "GrowthRate"; |
||||||
|
|
||||||
|
private final IndicatorsManager indicatorsManager; |
||||||
|
|
||||||
|
@Override |
||||||
|
public Float handleIndicator(String assessUserId) { |
||||||
|
List<AssetsReporter> reporterList = indicatorsManager.getAssetsReporterListByAssessUserId(assessUserId); |
||||||
|
AssetsReporter lastAssets = reporterList |
||||||
|
.stream() |
||||||
|
.max(Comparator.comparingLong(AssetsReporter::getDays)) |
||||||
|
.orElseThrow(() -> new EntityExistsException("assessUser:" + assessUserId)); |
||||||
|
AssetsReporter firstAssets = reporterList |
||||||
|
.stream() |
||||||
|
.min(Comparator.comparingLong(AssetsReporter::getDays)) |
||||||
|
.orElseThrow(() -> new EntityExistsException("assessUser:" + assessUserId)); |
||||||
|
return lastAssets.getAssets().subtract(firstAssets.getAssets()).divide(firstAssets.getAssets()).divide(BigDecimal.valueOf(100)).floatValue(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,17 @@ |
|||||||
|
package com.blockchain.server.yyyf.indicators.handle; |
||||||
|
|
||||||
|
import com.blockchain.server.yyyf.indicators.IndicatorsHandler; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author fengyu |
||||||
|
*/ |
||||||
|
@Component(MaxDrawdownRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) |
||||||
|
public class MaxDrawdownRateIndicatorsHandler implements IndicatorsHandler { |
||||||
|
public static final String HANDLER_NAME = "MaxDrawdownRate"; |
||||||
|
|
||||||
|
@Override |
||||||
|
public Float handleIndicator(String assessUserId) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,17 @@ |
|||||||
|
package com.blockchain.server.yyyf.indicators.handle; |
||||||
|
|
||||||
|
import com.blockchain.server.yyyf.indicators.IndicatorsHandler; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author fengyu |
||||||
|
*/ |
||||||
|
@Component(MaxLossRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) |
||||||
|
public class MaxLossRateIndicatorsHandler implements IndicatorsHandler { |
||||||
|
public static final String HANDLER_NAME = "MaxLossRate"; |
||||||
|
|
||||||
|
@Override |
||||||
|
public Float handleIndicator(String assessUserId) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,17 @@ |
|||||||
|
package com.blockchain.server.yyyf.indicators.handle; |
||||||
|
|
||||||
|
import com.blockchain.server.yyyf.indicators.IndicatorsHandler; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author fengyu |
||||||
|
*/ |
||||||
|
@Component(ProfitLossRateRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) |
||||||
|
public class ProfitLossRateRateIndicatorsHandler implements IndicatorsHandler { |
||||||
|
public static final String HANDLER_NAME = "ProfitLossRate"; |
||||||
|
|
||||||
|
@Override |
||||||
|
public Float handleIndicator(String assessUserId) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,17 @@ |
|||||||
|
package com.blockchain.server.yyyf.indicators.handle; |
||||||
|
|
||||||
|
import com.blockchain.server.yyyf.indicators.IndicatorsHandler; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author fengyu |
||||||
|
*/ |
||||||
|
@Component(ShapeRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) |
||||||
|
public class ShapeRateIndicatorsHandler implements IndicatorsHandler { |
||||||
|
public static final String HANDLER_NAME = "AnnualGrowthRate"; |
||||||
|
|
||||||
|
@Override |
||||||
|
public Float handleIndicator(String assessUserId) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,17 @@ |
|||||||
|
package com.blockchain.server.yyyf.indicators.handle; |
||||||
|
|
||||||
|
import com.blockchain.server.yyyf.indicators.IndicatorsHandler; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author fengyu |
||||||
|
*/ |
||||||
|
@Component(TVPIIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) |
||||||
|
public class TVPIIndicatorsHandler implements IndicatorsHandler { |
||||||
|
public static final String HANDLER_NAME = "TVPI"; |
||||||
|
|
||||||
|
@Override |
||||||
|
public Float handleIndicator(String assessUserId) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,17 @@ |
|||||||
|
package com.blockchain.server.yyyf.indicators.handle; |
||||||
|
|
||||||
|
import com.blockchain.server.yyyf.indicators.IndicatorsHandler; |
||||||
|
import org.springframework.stereotype.Component; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author fengyu |
||||||
|
*/ |
||||||
|
@Component(TotalGrowthRateIndicatorsHandler.HANDLER_NAME + IndicatorsHandler.HANDLER_NAME) |
||||||
|
public class TotalGrowthRateIndicatorsHandler implements IndicatorsHandler { |
||||||
|
public static final String HANDLER_NAME = "TotalGrowthRate"; |
||||||
|
|
||||||
|
@Override |
||||||
|
public Float handleIndicator(String assessUserId) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue