I have a correlation matrix, which I want to display in the following format:
- 2 decimal places (e.g., -0.56)
- number signs "+" and "-" (e.g., +0.76 or -0.34)
I've tried many different things, but I had no success so far... The code I'm using to generate the data is:
randomWalk[x_] := Accumulate[Prepend[RandomVariate[NormalDistribution[0, 1], x], 0]]
exchange = Table[Subscript[asset, i] = randomWalk[500], {i, 1, 5}];
Now the code I'm using to generate the correlation matrix:
N[Correlation[Transpose[exchange][[1 ;; 500, All]]], 2]//MatrixForm
However, the numbers generated are displayed with $MachinePrecision
, and not 2 decimal places (although I've used N[#,2]
). I've tried another code:
MatrixForm[Round[Correlation[Transpose[exchange][[1 ;; 500, All]]], 0.01]]
In this case I get the correlation matrix with 2 decimal places, but it's still missing the "+" signal before the number. So I've tried this last code:
NumberForm[Round[Correlation[Transpose[exchange][[1 ;; 500, All]]], 0.01],NumberSigns -> {"-", "+"}]//MatrixForm
In this last case I get the numbers correctly formatted, but I'm not able to put them in MatrixForm
. Can someone give me a hint to solve this?