public void op_Resize_int_int_whenArgumentOutOfRangeException(int width, int height) { var matrix = new Matrix<string>(1, 1); Assert.Throws<ArgumentOutOfRangeException>(() => matrix.Resize(width, height)); }
public void op_Resize_int_int() { const string expected = "example"; var matrix = new Matrix<string>(1, 1); Assert.Throws<ArgumentOutOfRangeException>(() => matrix[2, 2]); matrix.Resize(3, 3); matrix[2, 2] = expected; var actual = matrix[2, 2]; Assert.Equal(expected, actual); }
/// <summary> /// This method allows to fit the implied volatility using different models. /// </summary> /// <param name="Hdataset"></param> /// <returns></returns> IFunction FitImplVolModel(CallPriceMarketData Hdataset) { int model = 1; switch (model) { case 0: PFunction2D.PFunction2D pf = new PFunction2D.PFunction2D(Hdataset.Maturity, Hdataset.Strike, Hdataset.Volatility); pf.Interpolation = DVPLUtils.EInterpolationType.LEAST_SQUARES; pf.Extrapolation = DVPLUtils.ExtrapolationType.USEMODEL; pf.Parse(null); return pf; case 1: //define a model for fitting the implied volatility Fairmat.Statistics.LinearModel impVol = new Fairmat.Statistics.LinearModel( new Fairmat.Statistics.Predictor[] { delegate(Vector xx) { return 1; }, delegate(Vector xx) { return xx[0]; }, delegate(Vector xx) { return xx[1]; }, delegate(Vector xx) { return System.Math.Pow(xx[0], 2); }, delegate(Vector xx) { return System.Math.Pow(xx[1], 2); }, delegate(Vector xx) { return xx[0] * xx[1]; }, }); // Unroll matrix and coordinate vectors in order to make it suitable // for the Quadratic model implementation. int n = Hdataset.Volatility.R * Hdataset.Volatility.C; Matrix xy = new Matrix(n, 2); Vector z = new Vector(n); int count = 0; for (int x = 0; x < Hdataset.Volatility.R; x++) { for (int y = 0; y < Hdataset.Volatility.C; y++) { if (Hdataset.Volatility[x, y] > 0.01) { xy[count, Range.All] = (new Vector() { Hdataset.Maturity[x],Hdataset.Strike[y] }).T; z[count] = Hdataset.Volatility[x, y]; count++; } } } xy.Resize(count, xy.C); z.Resize(count); impVol.Estimate(xy, z); return impVol; } return null; }
public void op_Resize_Size_whenShrink(int x, int y) { var matrix = new Matrix<string>(3, 3); matrix[2, 2] = "example"; matrix.Resize(new Size(2, 2)); matrix.Resize(new Size(3, 3)); Assert.Null(matrix[2, 2]); }
public void ResizeTest() { IMatrix<int> matrix = new Matrix<int>(10, 10); int number = 0; for (int r = 0; r < matrix.Rows; r++) { for (int c = 0; c < matrix.Columns; c++) { matrix[r, c] = number++; } } int orgRows = matrix.Rows; int orgColumns = matrix.Columns; matrix.Resize(20, 20); Assert.AreEqual(20, matrix.Rows); Assert.AreEqual(20, matrix.Columns); number = 0; for (int r = 0; r < orgRows; r++) { for (int c = 0; c < orgColumns; c++) { Assert.AreEqual(number++, matrix[r, c]); } } matrix.Resize(5, 6); Assert.AreEqual(5, matrix.Rows); Assert.AreEqual(6, matrix.Columns); number = 0; for (int r = 0; r < orgRows; r++) { if (r < matrix.Rows) { for (int c = 0; c < orgColumns; c++) { if (c < matrix.Columns) { Assert.AreEqual(number++, matrix[r, c]); } else { number++; } } } } AssertHelpers.ThrowsException<MatrixException>(() => { matrix.Resize(-1, 50); }); AssertHelpers.ThrowsException<MatrixException>(() => { matrix.Resize(50, -1); }); }