use of org.ojalgo.random.Uniform in project ojAlgo-finance by optimatika.
the class StrategyMixer method testStratCombPortfolioMixerRandom.
@Test
@Tag("unstable")
public void testStratCombPortfolioMixerRandom() {
final FinancePortfolio tmpTarget = new SimplePortfolio(QUARTER, QUARTER, QUARTER, QUARTER).normalise();
final Uniform tmpGen = new Uniform();
final FinancePortfolio tmpStrat1 = new SimplePortfolio(tmpGen.doubleValue(), tmpGen.doubleValue(), tmpGen.doubleValue(), tmpGen.doubleValue()).normalise();
final FinancePortfolio tmpStrat2 = new SimplePortfolio(tmpGen.doubleValue(), tmpGen.doubleValue(), tmpGen.doubleValue(), tmpGen.doubleValue()).normalise();
final FinancePortfolio tmpStrat3 = new SimplePortfolio(tmpGen.doubleValue(), tmpGen.doubleValue(), tmpGen.doubleValue(), tmpGen.doubleValue()).normalise();
final PortfolioMixer tmpMixer = new PortfolioMixer(tmpTarget, tmpStrat1, tmpStrat2, tmpStrat3);
final int tmpExpectedNumberOfStrategies = 2;
final List<BigDecimal> tmpStrategyWeights = tmpMixer.mix(tmpExpectedNumberOfStrategies);
int tmpUseCount = 0;
double tmpTotalWeight = 0D;
for (final BigDecimal tmpWeight : tmpStrategyWeights) {
if (tmpWeight.signum() != 0) {
tmpUseCount++;
tmpTotalWeight += tmpWeight.doubleValue();
}
}
TestUtils.assertEquals(tmpExpectedNumberOfStrategies, tmpUseCount);
TestUtils.assertEquals(PrimitiveMath.ONE, tmpTotalWeight, 1E-14 / PrimitiveMath.THREE / PrimitiveMath.HUNDRED);
}
use of org.ojalgo.random.Uniform in project ojAlgo by optimatika.
the class P20050125Case method getProblematic.
public static RationalMatrix getProblematic() {
int DIM = 3;
final RationalMatrix tmpMtrx = RationalMatrix.FACTORY.makeFilled(DIM, DIM * DIM, new Uniform());
return tmpMtrx.multiply(tmpMtrx.transpose());
}
use of org.ojalgo.random.Uniform in project ojAlgo by optimatika.
the class ApproximationCase method testFirstOrderApproximation.
@Test
public void testFirstOrderApproximation() {
final int tmpArity = 9;
final PhysicalStore<Double> tmpLinear = PrimitiveDenseStore.FACTORY.makeFilled(tmpArity, 1, new Uniform(-1, 2));
final PhysicalStore<Double> tmpPoint = PrimitiveDenseStore.FACTORY.makeFilled(tmpArity, 1, new Uniform(-10, 20));
final LinearFunction<Double> tmpOrgFunc = LinearFunction.makePrimitive(tmpLinear);
final FirstOrderApproximation<Double> tmpApprFunc = tmpOrgFunc.toFirstOrderApproximation(tmpPoint);
final PhysicalStore<Double> tmpX = PrimitiveDenseStore.FACTORY.makeFilled(tmpArity, 1, new Uniform(-10, 20));
TestUtils.assertEquals(tmpOrgFunc.invoke(tmpX), tmpApprFunc.invoke(tmpX), new NumberContext(7, 14));
}
use of org.ojalgo.random.Uniform in project ojAlgo by optimatika.
the class BufferArrayTest method testRandomGetSet.
@Test
public void testRandomGetSet() {
final int tmpCount = 5000;
final BasicArray<Double> tmpArray = BufferArray.make(tmpCount);
TestUtils.assertEquals(tmpCount, tmpArray.count());
final Uniform tmpUniform = new Uniform();
for (int i = 0; i < 100; i++) {
final long tmpIndex = Uniform.randomInteger(tmpCount);
final double tmpExpected = tmpUniform.doubleValue();
tmpArray.set(tmpIndex, tmpExpected);
final double tmpActual = tmpArray.doubleValue(tmpIndex);
TestUtils.assertEquals(tmpExpected, tmpActual);
}
}
use of org.ojalgo.random.Uniform in project ojAlgo by optimatika.
the class Password method makeClearText.
public static String makeClearText(final int length) {
final char[] retVal = new char[length];
final Uniform tmpRandom = new Uniform(0, 128);
for (int c = 0; c < length; c++) {
int tmpChar = ASCII.NBSP;
do {
tmpChar = tmpRandom.intValue();
} while (!ASCII.isAlphanumeric(tmpChar));
retVal[c] = (char) tmpChar;
}
return String.valueOf(retVal);
}
Aggregations