예제 #1
0
        private double doOverallPnLCalculation(double percentile)
        {
            Matrix portfolioVolatility = weights.Multiply(volatilityMatrix.Multiply(weights.Transpose()));

            if ((1 != portfolioVolatility.numRows) || (1 != portfolioVolatility.numColumns))
            {
                throw new CovarianceVaRCalculator_Exception("Bad configuration!");
            }

            return(Math.Sqrt(portfolioVolatility[0, 0]) * GaussianInverseCDF.doInverse(percentile) * lastTotalSum);
        }
예제 #2
0
        private SortedDictionary <string, Tuple <double, double> > diaggregatePnL(SortedDictionary <string, Security> secData, double percentile)
        {
            SortedDictionary <string, Tuple <double, double> > result = new SortedDictionary <string, Tuple <double, double> >();
            int i = 0;

            foreach (KeyValuePair <string, Security> sd in secData)
            {
                double individualVaR        = weights[0, i] * Math.Sqrt(volatilityMatrix[i, i]) * GaussianInverseCDF.doInverse(percentile) * lastTotalSum;
                Tuple <double, double> VaRs = new Tuple <double, double>(lastCalculatedVaR * weights[0, i], individualVaR);
                result.Add(sd.Key, VaRs);
                i++;
            }

            if (1 < allowDebugOutput)
            {
                foreach (KeyValuePair <string, Tuple <double, double> > r in result)
                {
                    Console.WriteLine("VaR for {0}: {1} (if it was on its own: {2})", r.Key, r.Value.Item1, r.Value.Item2);
                }
            }
            return(result);
        }