Skip to content

Commit

Permalink
use negative zscore to flip the sign on VaR
Browse files Browse the repository at this point in the history
  • Loading branch information
crhntr committed Sep 3, 2024
1 parent 00d8b89 commit 9e30f9a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion calculate/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion calculate/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}

Expand Down

0 comments on commit 9e30f9a

Please sign in to comment.