@@ -828,6 +828,9 @@ function calc_moment_target(::LoHiOrderMoment{<:Any, Nothing, Nothing, <:Any}, :
828828 x:: VecNum )
829829 return Statistics. mean (x)
830830end
831+ function calc_prediction_moment_target (:: LoHiOrderMoment , X:: VecNum )
832+ return Statistics. mean (X)
833+ end
831834"""
832835 calc_moment_target(r::LoHiOrderMoment{<:Any, <:StatsBase.AbstractWeights, Nothing, <:Any},
833836 ::Any, x::VecNum)
@@ -854,6 +857,11 @@ function calc_moment_target(r::LoHiOrderMoment{<:Any, <:StatsBase.AbstractWeight
854857 <: Any }, :: Any , x:: VecNum )
855858 return Statistics. mean (x, r. w)
856859end
860+ function calc_prediction_moment_target (r:: LoHiOrderMoment {<: Any ,
861+ <: StatsBase.AbstractWeights ,
862+ Nothing, <: Any }, X:: VecNum )
863+ return Statistics. mean (X, r. w)
864+ end
857865"""
858866 calc_moment_target(r::LoHiOrderMoment{<:Any, <:Any, <:VecNum, <:Any},
859867 w::VecNum, ::Any)
@@ -932,6 +940,10 @@ Compute the target value for moment calculations when the risk measure provides
932940function calc_moment_target (r:: LoHiOrderMoment{<:Any, <:Any, <:Number, <:Any} , :: Any , :: Any )
933941 return r. mu
934942end
943+ function calc_prediction_moment_target (r:: LoHiOrderMoment{<:Any, <:Any, <:Number, <:Any} ,
944+ :: Any )
945+ return r. mu
946+ end
935947"""
936948 calc_deviations_vec(r::LoHiOrderMoment, w::VecNum,
937949 X::MatNum; fees::Option{<:Fees} = nothing)
@@ -968,23 +980,39 @@ function calc_deviations_vec(r::LoHiOrderMoment, w::VecNum, X::MatNum,
968980 tgt = calc_moment_target (r, w, x)
969981 return x .- tgt
970982end
983+ function calc_prediction_deviations_vec (r:: LoHiOrderMoment , X:: VecNum )
984+ return X .- calc_prediction_moment_target (r, X)
985+ end
971986function (r:: LowOrderMoment{<:Any, <:Any, <:Any, <:FirstLowerMoment} )(w:: VecNum , X:: MatNum ,
972987 fees:: Option{<:Fees} = nothing )
973988 val = min .(calc_deviations_vec (r, w, X, fees), zero (eltype (X)))
974989 return isnothing (r. w) ? - Statistics. mean (val) : - Statistics. mean (val, r. w)
975990end
991+ function (r:: LowOrderMoment{<:Any, <:Any, <:Any, <:FirstLowerMoment} )(X:: VecNum )
992+ val = min .(calc_prediction_deviations_vec (r, X), zero (eltype (X)))
993+ return isnothing (r. w) ? - Statistics. mean (val) : - Statistics. mean (val, r. w)
994+ end
976995function (r:: LowOrderMoment{<:Any, <:Any, <:Any, <:MeanAbsoluteDeviation} )(w:: VecNum ,
977996 X:: MatNum ,
978997 fees:: Option{<:Fees} = nothing )
979998 val = abs .(calc_deviations_vec (r, w, X, fees))
980999 return isnothing (r. w) ? Statistics. mean (val) : Statistics. mean (val, r. w)
9811000end
1001+ function (r:: LowOrderMoment{<:Any, <:Any, <:Any, <:MeanAbsoluteDeviation} )(X:: VecNum )
1002+ val = abs .(calc_prediction_deviations_vec (r, X))
1003+ return isnothing (r. w) ? - Statistics. mean (val) : - Statistics. mean (val, r. w)
1004+ end
9821005function (r:: HighOrderMoment{<:Any, <:Any, <:Any, <:ThirdLowerMoment} )(w:: VecNum , X:: MatNum ,
9831006 fees:: Option{<:Fees} = nothing )
9841007 val = min .(calc_deviations_vec (r, w, X, fees), zero (eltype (X)))
9851008 val .= val .^ 3
9861009 return isnothing (r. w) ? - Statistics. mean (val) : - Statistics. mean (val, r. w)
9871010end
1011+ function (r:: HighOrderMoment{<:Any, <:Any, <:Any, <:ThirdLowerMoment} )(X:: VecNum )
1012+ val = min .(calc_prediction_deviations_vec (r, X), zero (eltype (X)))
1013+ val .= val .^ 3
1014+ return isnothing (r. w) ? - Statistics. mean (val) : - Statistics. mean (val, r. w)
1015+ end
9881016function (r:: HighOrderMoment {<: Any , <: Any , <: Any ,
9891017 <: StandardisedHighOrderMoment{<:Any, <:ThirdLowerMoment} })(w:: VecNum ,
9901018 X:: MatNum ,
@@ -995,48 +1023,86 @@ function (r::HighOrderMoment{<:Any, <:Any, <:Any,
9951023 res = isnothing (r. w) ? - Statistics. mean (val) : - Statistics. mean (val, r. w)
9961024 return res / (sigma * sqrt (sigma))
9971025end
1026+ function (r:: HighOrderMoment {<: Any , <: Any , <: Any ,
1027+ <: StandardisedHighOrderMoment{<:Any, <:ThirdLowerMoment} })(X:: VecNum )
1028+ val = min .(calc_prediction_deviations_vec (r, X), zero (eltype (X)))
1029+ sigma = Statistics. var (r. alg. ve, val; mean = zero (eltype (val)))
1030+ val .= val .^ 3
1031+ res = isnothing (r. w) ? - Statistics. mean (val) : - Statistics. mean (val, r. w)
1032+ return res / (sigma * sqrt (sigma))
1033+ end
9981034function (r:: LowOrderMoment {<: Any , <: Any , <: Any ,
9991035 <: SecondMoment{<:Any, <:Semi, <:SOCRiskExpr} })(w:: VecNum ,
10001036 X:: MatNum ,
10011037 fees:: Option{<:Fees} = nothing )
10021038 val = min .(calc_deviations_vec (r, w, X, fees), zero (eltype (X)))
10031039 return Statistics. std (r. alg. ve, val; mean = zero (eltype (val)))
10041040end
1041+ function (r:: LowOrderMoment {<: Any , <: Any , <: Any ,
1042+ <: SecondMoment{<:Any, <:Semi, <:SOCRiskExpr} })(X:: VecNum )
1043+ val = min .(calc_prediction_deviations_vec (r, X), zero (eltype (X)))
1044+ return Statistics. std (r. alg. ve, val; mean = zero (eltype (val)))
1045+ end
10051046function (r:: LowOrderMoment {<: Any , <: Any , <: Any ,
10061047 <: SecondMoment{<:Any, <:Semi, <:QuadSecondMomentFormulations} })(w:: VecNum ,
10071048 X:: MatNum ,
10081049 fees:: Option{<:Fees} = nothing )
10091050 val = min .(calc_deviations_vec (r, w, X, fees), zero (eltype (X)))
10101051 return Statistics. var (r. alg. ve, val; mean = zero (eltype (val)))
10111052end
1053+ function (r:: LowOrderMoment {<: Any , <: Any , <: Any ,
1054+ <: SecondMoment{<:Any, <:Semi, <:QuadSecondMomentFormulations} })(X:: VecNum )
1055+ val = min .(calc_prediction_deviations_vec (r, X), zero (eltype (X)))
1056+ return Statistics. var (r. alg. ve, val; mean = zero (eltype (val)))
1057+ end
10121058function (r:: LowOrderMoment {<: Any , <: Any , <: Any ,
10131059 <: SecondMoment{<:Any, <:Full, <:SOCRiskExpr} })(w:: VecNum ,
10141060 X:: MatNum ,
10151061 fees:: Option{<:Fees} = nothing )
10161062 val = calc_deviations_vec (r, w, X, fees)
10171063 return Statistics. std (r. alg. ve, val; mean = zero (eltype (val)))
10181064end
1065+ function (r:: LowOrderMoment {<: Any , <: Any , <: Any ,
1066+ <: SecondMoment{<:Any, <:Full, <:SOCRiskExpr} })(X:: VecNum )
1067+ val = calc_prediction_deviations_vec (r, X)
1068+ return Statistics. std (r. alg. ve, val; mean = zero (eltype (val)))
1069+ end
10191070function (r:: LowOrderMoment {<: Any , <: Any , <: Any ,
10201071 <: SecondMoment{<:Any, <:Full, <:QuadSecondMomentFormulations} })(w:: VecNum ,
10211072 X:: MatNum ,
10221073 fees:: Option{<:Fees} = nothing )
10231074 val = calc_deviations_vec (r, w, X, fees)
10241075 return Statistics. var (r. alg. ve, val; mean = zero (eltype (val)))
10251076end
1077+ function (r:: LowOrderMoment {<: Any , <: Any , <: Any ,
1078+ <: SecondMoment{<:Any, <:Full, <:QuadSecondMomentFormulations} })(X:: VecNum )
1079+ val = calc_prediction_deviations_vec (r, X)
1080+ return Statistics. var (r. alg. ve, val; mean = zero (eltype (val)))
1081+ end
10261082function (r:: HighOrderMoment{<:Any, <:Any, <:Any, <:FourthMoment{<:Semi}} )(w:: VecNum ,
10271083 X:: MatNum ,
10281084 fees:: Option{<:Fees} = nothing )
10291085 val = min .(calc_deviations_vec (r, w, X, fees), zero (eltype (X)))
10301086 val .= val .^ 4
10311087 return isnothing (r. w) ? Statistics. mean (val) : Statistics. mean (val, r. w)
10321088end
1089+ function (r:: HighOrderMoment{<:Any, <:Any, <:Any, <:FourthMoment{<:Semi}} )(X:: VecNum )
1090+ val = min .(calc_prediction_deviations_vec (r, X), zero (eltype (X)))
1091+ val .= val .^ 4
1092+ return isnothing (r. w) ? Statistics. mean (val) : Statistics. mean (val, r. w)
1093+ end
10331094function (r:: HighOrderMoment{<:Any, <:Any, <:Any, <:FourthMoment{<:Full}} )(w:: VecNum ,
10341095 X:: MatNum ,
10351096 fees:: Option{<:Fees} = nothing )
10361097 val = calc_deviations_vec (r, w, X, fees)
10371098 val .= val .^ 4
10381099 return isnothing (r. w) ? Statistics. mean (val) : Statistics. mean (val, r. w)
10391100end
1101+ function (r:: HighOrderMoment{<:Any, <:Any, <:Any, <:FourthMoment{<:Full}} )(X:: VecNum )
1102+ val = calc_prediction_deviations_vec (r, X)
1103+ val .= val .^ 4
1104+ return isnothing (r. w) ? Statistics. mean (val) : Statistics. mean (val, r. w)
1105+ end
10401106function (r:: HighOrderMoment {<: Any , <: Any , <: Any ,
10411107 <: StandardisedHighOrderMoment{<:Any, <:FourthMoment{<:Semi}} })(w:: VecNum ,
10421108 X:: MatNum ,
@@ -1048,10 +1114,8 @@ function (r::HighOrderMoment{<:Any, <:Any, <:Any,
10481114 return res / sigma^ 2
10491115end
10501116function (r:: HighOrderMoment {<: Any , <: Any , <: Any ,
1051- <: StandardisedHighOrderMoment{<:Any, <:FourthMoment{<:Full}} })(w:: VecNum ,
1052- X:: MatNum ,
1053- fees:: Option{<:Fees} = nothing )
1054- val = calc_deviations_vec (r, w, X, fees)
1117+ <: StandardisedHighOrderMoment{<:Any, <:FourthMoment{<:Full}} })(X:: VecNum )
1118+ val = calc_prediction_deviations_vec (r, X)
10551119 sigma = Statistics. var (r. alg. ve, val; mean = zero (eltype (val)))
10561120 val .= val .^ 4
10571121 res = isnothing (r. w) ? Statistics. mean (val) : Statistics. mean (val, r. w)
0 commit comments