private List <string> CreateTestWeightsProvider(Context context, WeightsType weightsType, int returnsCount = 1000) { var correlationMatrix = context.Factory.CreateNArray(new double[, ] { { 1.0, 0.84, -0.42 }, { 0.84, 1.0, 0.14 }, { -0.42, 0.14, 1.0 } }); correlationMatrix = CorrelationHelper.NearestCorrelationMatrix(correlationMatrix); int weightsCount; NArray weightsMatrix; if (weightsType == WeightsType.Returns) { weightsCount = returnsCount; weightsMatrix = CalculateSyntheticReturns(correlationMatrix, weightsCount); } else { weightsCount = correlationMatrix.RowCount; weightsMatrix = NMath.CholeskyDecomposition(correlationMatrix); } var weights = context.Data.AddCalibrationParametersProvider (new WeightsProvider(weightsCount)); var identifiers = Enumerable.Range(1, weightsMatrix.ColumnCount) .Select(i => string.Format("TestFactor{0}", i)).ToList(); for (int i = 0; i < weightsMatrix.ColumnCount; ++i) { weights.AddValue(identifiers[i], weightsMatrix.Column(i)); } return(identifiers); }
private List<string> CreateTestWeightsProvider(Context context, WeightsType weightsType, int returnsCount = 1000) { var correlationMatrix = context.Factory.CreateNArray(new double[,] { { 1.0, 0.84, -0.42}, { 0.84, 1.0, 0.14}, { -0.42, 0.14, 1.0} }); correlationMatrix = CorrelationHelper.NearestCorrelationMatrix(correlationMatrix); int weightsCount; NArray weightsMatrix; if (weightsType == WeightsType.Returns) { weightsCount = returnsCount; weightsMatrix = CalculateSyntheticReturns(correlationMatrix, weightsCount); } else { weightsCount = correlationMatrix.RowCount; weightsMatrix = NMath.CholeskyDecomposition(correlationMatrix); } var weights = context.Data.AddCalibrationParametersProvider (new WeightsProvider(weightsCount)); var identifiers = Enumerable.Range(1, weightsMatrix.ColumnCount) .Select(i => string.Format("TestFactor{0}", i)).ToList(); for (int i = 0; i < weightsMatrix.ColumnCount; ++i) { weights.AddValue(identifiers[i], weightsMatrix.Column(i)); } return identifiers; }