From 9e30f9a2a95c2d42c2e039e0938fbe94317b4af3 Mon Sep 17 00:00:00 2001 From: Chrstopher Hunter <8398225+crhntr@users.noreply.github.com> Date: Mon, 2 Sep 2024 22:31:20 -0700 Subject: [PATCH] use negative zscore to flip the sign on VaR --- calculate/stats.go | 2 +- calculate/stats_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/calculate/stats.go b/calculate/stats.go index d80ce88..5265e59 100644 --- a/calculate/stats.go +++ b/calculate/stats.go @@ -73,7 +73,7 @@ func ValueAtRisk(values []float64, portfolioValue, confidenceLevel, periodsPerYe Sigma: 1.0, } zScore := normal.Quantile(confidenceLevel) - return portfolioValue * zScore * AnnualizeRisk(stat.PopStdDev(values, nil), periodsPerYear) + return portfolioValue * -zScore * AnnualizeRisk(stat.PopStdDev(values, nil), periodsPerYear) } func negativeValues(out, in []float64) []float64 { diff --git a/calculate/stats_test.go b/calculate/stats_test.go index 6b8fc7c..7d1a8a3 100644 --- a/calculate/stats_test.go +++ b/calculate/stats_test.go @@ -86,7 +86,7 @@ func TestMetrics(t *testing.T) { confidenceLevel = 0.95 ) result := ValueAtRisk(portfolio, portfolioValue, confidenceLevel, PeriodsPerYear) - assert.InDelta(t, 2148.94, result, 0.01) + assert.InDelta(t, -2148.94, result, 0.01) }) }