Esempio n. 1
0
        private (double M1, double M2) M(Vector <double> pricesVector, Vector <double> weightsVector, NumericMatrix <double> correlationMatrix, Vector <double> volatilityVector)
        {
            Vector <double> pricesWeightsVector = pricesVector * weightsVector;
            double          m1 = pricesWeightsVector.Sum();

            NumericMatrix <double> volatilityMatrix = new NumericMatrix <double>(volatilityVector.Length, volatilityVector.Length, 0, 0);

            for (int i = 0; i < volatilityVector.Length; i++)
            {
                for (int j = 0; j < volatilityVector.Length; j++)
                {
                    volatilityMatrix[i, j] = volatilityVector[i] * volatilityVector[j] * correlationMatrix[i, j] * _t;
                }
            }

            NumericMatrix <double> expMatrix = volatilityMatrix.Exp();

            double m2 = 0;

            for (int row = 0; row < expMatrix.Rows; row++)
            {
                m2 += (pricesWeightsVector * expMatrix.getRow(row)).Sum() * weightsVector[row] * pricesVector[row];
            }

            return(m1, m2);
        }