package com.smppw.common.pojo.enums;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

/**
 * 指标
 * 更多介绍：http://112.74.196.215:8090/pages/viewpage.action?pageId=362530
 */
public enum IndicatorContrastEnum {

    /**
     * 区间收益（%）用净值计算
     */
    IntervalReturn(1, "IntervalReturn", "IntervalReturn", "区间收益", true, true),
    ExcessReturnDynamic(69, "ExcessReturnDynamic", "ExcessReturnRealTimeCalc", "超额区间收益", true, true),
    ExcessReturnDynamicAnnual(69, "ExcessReturnDynamicAnnual", "ExcessReturnRealTimeCalc", "超额年化收益", true, true),
    /**
     * 年化收益（%）（几何）
     */
    AnnualReturn(39, "AnnualReturn", "AnnualReturn", "年化收益率", true, true),
    /**
     * 阿尔法（%）
     */
    Alpha(11, "Alpha", "Alpha", "阿尔法", true, true),
    /**
     * 上行捕获率
     */
    UpCaptureRatio(35, "UpCaptureRatio", "UpCaptureRatio", "上行捕获率", false, false),
    /**
     * 下行捕获率
     */
    DownCaptureRatio(36, "DownCaptureRatio", "DownCaptureRatio", "下行捕获率", false, false),
    /**
     * 上行捕获收益率（%）
     */
    UpCaptureReturn(33, "UpCaptureReturn", "UpCaptureReturn", "上行捕获收益率", true, true),
    /**
     * 下行捕获收益率（%）
     */
    DownCaptureReturn(34, "DownCaptureReturn", "DownCaptureReturn", "下行捕获收益率", true, true),
    /**
     * 夏普比率
     */
    SharpeRatio(18, "SharpeRatio", "SharpeRatio", "夏普比率", false, false),
    /**
     * 索提诺比率
     */
    SortinoRatio(58, "SortinoRatio", "SortinoRatio", "索提诺比率", false, false),
    /**
     * 索提诺比率(MAR)
     */
    SortinoRatioMAR(19, "SortinoRatioMAR", "SortinoRatioMAR", "索提诺比率（MAR）", false, false),
    /**
     * 特雷诺比率
     */
    TreynorRatio(15, "TreynorRatio", "TreynorRatio", "特雷诺比率", false, false),
    /**
     * 欧米伽比率
     */
    Omega(17, "Omega", "Omega", "欧米伽比率", false, false),
    /**
     * 卡帕比率
     */
    Kappa(14, "Kappa", "Kappa", "卡帕比率", false, false),
    /**
     * 卡玛比率
     */
    CalmarRatio(40, "CalmarRatio", "CalmarRatio", "卡玛比率", false, false),
    /**
     * 信息比率
     */
    InformationRatio(38, "InformationRatio", "InformationRatio", "信息比率", false, false),
    /**
     * 詹森指数（%）
     */
    Jensen(16, "Jensen", "Jensen", "詹森指数", true, false),
    /**
     * M2（%）
     */
    M2(49, "M2", "M2", "M2", true, true),
    WinRate(59, "WinRate", "WinRate", "超额胜率", true, false),
//	WinRateMonth(59,"WinRateMonth","WinRate","超额月胜率",true,false),
    /**
     * 超额收益夏普比率
     */
    ExcessReturnSharpeRatio(72, "ExcessReturnSharpeRatio", "ExcessReturnSharpeRatio", "超额夏普比率", false, false),
    /**
     * 年化标准差（%）
     */
    AnnualStdDev(10, "AnnualStdDev", "AnnualStdDev", "年化标准差", true, false),
    /**
     * 贝塔
     */
    Beta(12, "Beta", "Beta", "贝塔", false, false),
    /**
     * 偏度
     */
    Skewness(9, "Skewness", "Skewness", "偏度", false, false),
    /**
     * 峰度
     */
    Kurtosis(6, "Kurtosis", "Kurtosis", "峰度", false, false),
    /**
     * 跟踪误差（%）
     */
    TrackingError(48, "TrackingError", "TrackingError", "跟踪误差", true, false),
    /**
     * 最大回撤（%）
     */
    MaxDrawdown(2, "MaxDrawdown", "MaxDrawdown", "最大回撤", true, false),
    /**
     * 超额收益最大回撤（%）
     */
    ExcessReturnMaxDrawdown(75, "ExcessReturnMaxDrawdown", "ExcessReturnMaxDrawdown", "超额最大回撤", true, false),
    /**
     * 最大回撤修复日期
     */
    MaxDrawdownRecureDate(8, "MaxDrawdownRecureDate", "MaxDrawdownRecureDate", "最大回撤修复日期", false, false),
    /**
     * 最大回撤修复数
     */
    MaxDrawdownRecureIntervalDays(76, "MaxDrawdownRecureIntervalDays", "MaxDrawdownRecureIntervalDays", "最大回撤修复天数", false, false),
    /**
     * 历史VaR（%）
     */
    HistoricalVaR(41, "HistoricalVaR", "HistoricalVaR", "历史VaR", true, false),
    /**
     * 历史CVaR（%）
     */
    HistoricalCVaR(42, "HistoricalCVaR", "HistoricalCVaR", "历史CVaR", true, false),
    /**
     * 下行风险（%）
     */
    DownsideStdDev(21, "DownsideStdDev", "DownsideStdDev", "下行风险", true, false),
    /**
     * 最大回撤波峰日期 added by xjs
     */
    MaxDrawdownPeakDate(63, "MaxDrawdownPeakDate", "MaxDrawdownPeakDate", "最大回撤起始日期", false, false),
    /**
     * 最大回撤波谷日期  added by xjs
     */
    MaxDrawdownValleyDate(64, "MaxDrawdownValleyDate", "MaxDrawdownValleyDate", "最大回撤波谷日期", false, false),
    /**
     * 超额夏普比率 -- 几何算法（超额净值）
     */
    ExcessReturnSharpeRatioExtra(72, "ExcessReturnSharpeRatioExtra", "ExcessReturnSharpeRatioExtra", "超额夏普比率", false, false),
    /**
     * 超额年化标准差
     */
    ExcessReturnAnnualStdDevExtra(71, "ExcessReturnAnnualStdDevExtra", "ExcessReturnAnnualStdDevExtra", "超额年化标准差", true, false),

    /**
     * 超额最大回撤修复日期
     */
    ExcessReturnMaxDrawdownRecureDateExtra(114, "ExcessReturnMaxDrawdownRecureDateExtra", "ExcessReturnMaxDrawdownRecureDateExtra", "超额最大回撤修复日期", false, false),

    /**
     * 超额最大回撤修复数
     */
    ExcessReturnMaxDrawdownRecureIntervalExtra(115, "ExcessReturnMaxDrawdownRecureIntervalExtra", "ExcessReturnMaxDrawdownRecureIntervalExtra", "超额最大回撤修复天数", false, false),

    FundId(-1, "FundId", "FundId", "基金ID", false, false),
    FundName(-2, "FundName", "FundName", "基金名称", false, false),

    LongestNoNewHighDays(67, "LongestNoNewHighDays", "LongestNoNewHighDays", "最长连续未创新高天数", false, false),

    ProfitLossRatio(5, "ProfitLossRatio", "ProfitLossRatio", "盈利亏损比", false, false),

    ;

    public static List<IndicatorContrastEnum> retList = Arrays.asList(IntervalReturn, ExcessReturnDynamic, AnnualReturn,
            ExcessReturnDynamicAnnual, Alpha, UpCaptureRatio, UpCaptureReturn, DownCaptureRatio, DownCaptureReturn,
            WinRate, ProfitLossRatio);
    public static List<IndicatorContrastEnum> adjustList = Arrays.asList(InformationRatio, SharpeRatio, Jensen, CalmarRatio,
            Kappa, SortinoRatio, SortinoRatioMAR, Omega, TreynorRatio, M2, ExcessReturnSharpeRatioExtra);
    public static List<IndicatorContrastEnum> riskList = Arrays.asList(AnnualStdDev, Beta, Skewness, Kurtosis, TrackingError,
            MaxDrawdown, ExcessReturnMaxDrawdown, MaxDrawdownRecureDate, MaxDrawdownRecureIntervalDays, HistoricalVaR,
            HistoricalCVaR, DownsideStdDev, LongestNoNewHighDays, ExcessReturnAnnualStdDevExtra, ExcessReturnMaxDrawdownRecureDateExtra,
            ExcessReturnMaxDrawdownRecureIntervalExtra, MaxDrawdownPeakDate, MaxDrawdownValleyDate);
    public static List<IndicatorContrastEnum> retList2 = Arrays.asList(IntervalReturn, AnnualReturn,
            Alpha, UpCaptureRatio, UpCaptureReturn, DownCaptureRatio, DownCaptureReturn,
            WinRate, ProfitLossRatio);
    public static List<IndicatorContrastEnum> adjustList2 = Arrays.asList(InformationRatio, SharpeRatio, Jensen, CalmarRatio,
            Kappa, SortinoRatio, SortinoRatioMAR, Omega, TreynorRatio, M2);
    public static List<IndicatorContrastEnum> riskList2 = Arrays.asList(AnnualStdDev, Beta, Skewness, Kurtosis, TrackingError,
            MaxDrawdown, MaxDrawdownRecureDate, MaxDrawdownRecureIntervalDays, HistoricalVaR,
            HistoricalCVaR, DownsideStdDev, LongestNoNewHighDays,
            MaxDrawdownPeakDate, MaxDrawdownValleyDate);
    public static List<IndicatorContrastEnum> needExtraGeo = Arrays.asList(IntervalReturn, AnnualReturn, SharpeRatio, MaxDrawdown, AnnualStdDev, MaxDrawdownRecureDate, MaxDrawdownRecureIntervalDays);
    public static List<String> dataIndicatorList = Arrays.asList(MaxDrawdownPeakDate.toString(), MaxDrawdownValleyDate.toString(),
            MaxDrawdownRecureDate.toString(), ExcessReturnMaxDrawdownRecureDateExtra.toString());
    public static List<String> daysIndicatorList = Arrays.asList(MaxDrawdownRecureIntervalDays.toString(), ExcessReturnMaxDrawdownRecureIntervalExtra.toString(), LongestNoNewHighDays.toString());
    private int id;
    private String label;
    private String indicatorName;
    private String symbol;
    private boolean isPercent;
    private boolean isColor;

    private IndicatorContrastEnum(int id, String symbol, String label, String indicatorName, boolean isPercent, boolean isColor) {
        this.id = id;
        this.label = label;
        this.indicatorName = indicatorName;
        this.symbol = symbol;
        this.isPercent = isPercent;
        this.isColor = isColor;
    }

    private IndicatorContrastEnum(int id) {
        this.id = id;
    }

    public static IndicatorContrastEnum getIndicator(int id) {
        return Stream.of(IndicatorContrastEnum.values()).filter(e -> e.id == id).findFirst().orElse(null);
    }

    /**
     * 根据 symbol 获取 isPercent，为null时返回false
     *
     * @param label 名称
     * @return /
     */
    public static boolean isPercent(String label) {
        IndicatorContrastEnum anEnum = Stream.of(IndicatorContrastEnum.values())
                .filter(e -> e.label.equals(label)).findFirst().orElse(null);
        return anEnum != null && anEnum.getIsPercent();
    }

    public boolean isColor() {
        return isColor;
    }

    public void setColor(boolean color) {
        isColor = color;
    }

    public boolean getIsPercent() {
        return isPercent;
    }

    public void setIsPercent(boolean isPercent) {
        this.isPercent = isPercent;
    }

    public String getSymbol() {
        return symbol;
    }

    public void setSymbol(String symbol) {
        symbol = symbol;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    public String getIndicatorName() {
        return indicatorName;
    }

    public void setIndicatorName(String indicatorName) {
        this.indicatorName = indicatorName;
    }

    public int getId() {
        return id;
    }
}
