private void InitializeSettings() { // Get user requested values shortPressCalculation = GetCalculationFunctionFromString(settings.ShortPressCalculation) ?? Add; longPressCalculation = GetCalculationFunctionFromString(settings.LongPressCalculation) ?? Subtract; if (Int32.TryParse(settings.Increment, out int incrementValue)) { incrementor = incrementValue; } else // Invalid value in Increment field { settings.Increment = "1"; SaveSettings(); } if (Int32.TryParse(settings.InitialValue, out int value)) { initialValue = value; } else // Invalid value in Increment field { settings.InitialValue = "0"; SaveSettings(); } PropagatePlaybackDevices(); }
/// <summary> /// Obtains an instance from a set of targets, columns and rules, resolving the targets. /// <para> /// The targets will typically be trades and positions. /// The columns represent the measures to calculate. /// </para> /// <para> /// The targets will be resolved if they implement <seealso cref="ResolvableCalculationTarget"/>. /// /// </para> /// </summary> /// <param name="rules"> the rules defining how the calculation is performed </param> /// <param name="targets"> the targets for which values of the measures will be calculated </param> /// <param name="columns"> the columns that will be calculated </param> /// <param name="refData"> the reference data to use to resolve the targets </param> /// <returns> the calculation tasks </returns> public static CalculationTasks of <T1>(CalculationRules rules, IList <T1> targets, IList <Column> columns, ReferenceData refData) where T1 : com.opengamma.strata.basics.CalculationTarget { // create columns that are a combination of the column overrides and the defaults // this is done once as it is the same for all targets //JAVA TO C# CONVERTER TODO TASK: Most Java stream collectors are not converted by Java to C# Converter: IList <Column> effectiveColumns = columns.Select(column => column.combineWithDefaults(rules.ReportingCurrency, rules.Parameters)).collect(toImmutableList()); // loop around the targets, then the columns, to build the tasks ImmutableList.Builder <CalculationTask> taskBuilder = ImmutableList.builder(); for (int rowIndex = 0; rowIndex < targets.Count; rowIndex++) { CalculationTarget target = resolveTarget(targets[rowIndex], refData); // find the applicable function, resolving the target if necessary //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: CalculationFunction<?> fn = target instanceof UnresolvableTarget ? UnresolvableTargetCalculationFunction.INSTANCE : rules.getFunctions().getFunction(target); CalculationFunction <object> fn = target is UnresolvableTarget ? UnresolvableTargetCalculationFunction.INSTANCE : rules.Functions.getFunction(target); // create the tasks IList <CalculationTask> targetTasks = createTargetTasks(target, rowIndex, fn, effectiveColumns); taskBuilder.addAll(targetTasks); } // calculation tasks holds the original user-specified columns, not the derived ones return(new CalculationTasks(taskBuilder.build(), columns)); }
private static int CalculateOperationFunction(CalculationFunction calculationFunction, List <int> numbers) { int total = 0; switch (calculationFunction) { case CalculationFunction.add: foreach (var number in numbers) { total += number; } return(total); case CalculationFunction.multiply: total = 1; foreach (var number in numbers) { total = total * number; } return(total); default: return(-1); } }
/// <summary> /// Obtains an instance that will calculate the specified cells. /// <para> /// The cells must all be for the same row index and none of the column indices must overlap. /// /// </para> /// </summary> /// <param name="target"> the target for which the value will be calculated </param> /// <param name="function"> the function that performs the calculation </param> /// <param name="parameters"> the additional parameters </param> /// <param name="cells"> the cells to be calculated by this task </param> /// <returns> the task </returns> public static CalculationTask of <T1>(CalculationTarget target, CalculationFunction <T1> function, CalculationParameters parameters, IList <CalculationTaskCell> cells) where T1 : com.opengamma.strata.basics.CalculationTarget { //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") CalculationFunction<com.opengamma.strata.basics.CalculationTarget> functionCast = (CalculationFunction<com.opengamma.strata.basics.CalculationTarget>) function; CalculationFunction <CalculationTarget> functionCast = (CalculationFunction <CalculationTarget>)function; return(new CalculationTask(target, functionCast, parameters, cells)); }
//JAVA TO C# CONVERTER TODO TASK: There is no .NET equivalent to the Java 'super' constraint: //ORIGINAL LINE: @Override public <T extends com.opengamma.strata.basics.CalculationTarget> java.util.Optional<CalculationFunction<? super T>> findFunction(T target) public Optional <CalculationFunction> findFunction <T>(T target) where T : com.opengamma.strata.basics.CalculationTarget { //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("unchecked") CalculationFunction<? super T> function = (CalculationFunction<? super T>) functions.get(target.getClass()); //JAVA TO C# CONVERTER TODO TASK: There is no .NET equivalent to the Java 'super' constraint: //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: CalculationFunction <object> function = (CalculationFunction <object>)functions.get(target.GetType()); return(Optional.ofNullable(function)); }
private CalculationTask(CalculationTarget target, CalculationFunction <CalculationTarget> function, CalculationParameters parameters, IList <CalculationTaskCell> cells) { JodaBeanUtils.notNull(target, "target"); JodaBeanUtils.notNull(function, "function"); JodaBeanUtils.notNull(parameters, "parameters"); JodaBeanUtils.notEmpty(cells, "cells"); this.target = target; this.function = function; this.parameters = parameters; this.cells = ImmutableList.copyOf(cells); }
/// <summary> /// Creates a new function which invokes the delegate function, passes the result to the derived function /// and returns the combined results. /// </summary> /// <param name="derivedFunction"> a function which calculates one measure using the measure values calculated by the other function </param> /// <param name="delegate"> a function which calculates multiple measures </param> internal DerivedCalculationFunctionWrapper(DerivedCalculationFunction <T, R> derivedFunction, CalculationFunction <T> @delegate) { this.derivedFunction = derivedFunction; this.@delegate = @delegate; ISet <Measure> delegateMeasures = @delegate.supportedMeasures(); //JAVA TO C# CONVERTER TODO TASK: There is no .NET equivalent to the java.util.Collection 'containsAll' method: this.requiredMeasuresSupported = delegateMeasures.containsAll(derivedFunction.requiredMeasures()); this.supportedMeasures_Renamed = requiredMeasuresSupported ? ImmutableSet.builder <Measure>().addAll(delegateMeasures).add(derivedFunction.measure()).build() : delegateMeasures; }
public virtual void oneDerivedFunction() { //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.Map<com.opengamma.strata.calc.Measure, com.opengamma.strata.collect.result.Result<?>> delegateResults = com.google.common.collect.ImmutableMap.of(CASH_FLOWS, com.opengamma.strata.collect.result.Result.success(3), PAR_RATE, com.opengamma.strata.collect.result.Result.success(5)); IDictionary <Measure, Result <object> > delegateResults = ImmutableMap.of(CASH_FLOWS, Result.success(3), PAR_RATE, Result.success(5)); DelegateFn delegateFn = new DelegateFn(delegateResults); DerivedFn derivedFn = new DerivedFn(); CalculationFunctions calculationFunctions = CalculationFunctions.of(delegateFn); CalculationFunctions derivedFunctions = calculationFunctions.composedWith(derivedFn); TestTarget target = new TestTarget(42); //JAVA TO C# CONVERTER TODO TASK: There is no .NET equivalent to the Java 'super' constraint: //ORIGINAL LINE: CalculationFunction<? super TestTarget> function = derivedFunctions.getFunction(target); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: CalculationFunction <object> function = derivedFunctions.getFunction(target); ImmutableSet <Measure> expectedMeasures = ImmutableSet.of(BUCKETED_PV01, CASH_FLOWS, PAR_RATE); assertThat(function.supportedMeasures()).isEqualTo(expectedMeasures); }
/// <summary> /// Test that multiple derived functions for the same target type are correctly combined when one derived function /// depends on another. /// </summary> public virtual void multipleDerivedFunctionsForSameTargetTypeWithDependencyBetweenDerivedFunctions() { //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: //ORIGINAL LINE: java.util.Map<com.opengamma.strata.calc.Measure, com.opengamma.strata.collect.result.Result<?>> delegateResults = com.google.common.collect.ImmutableMap.of(CASH_FLOWS, com.opengamma.strata.collect.result.Result.success(3), PAR_RATE, com.opengamma.strata.collect.result.Result.success(5)); IDictionary <Measure, Result <object> > delegateResults = ImmutableMap.of(CASH_FLOWS, Result.success(3), PAR_RATE, Result.success(5)); DelegateFn delegateFn = new DelegateFn(delegateResults); DerivedFn derivedFn1 = new DerivedFn(); // This depends on the measure calculated by derivedFn1 DerivedFn derivedFn2 = new DerivedFn(PRESENT_VALUE_MULTI_CCY, ImmutableSet.of(BUCKETED_PV01)); CalculationFunctions calculationFunctions = CalculationFunctions.of(delegateFn); // The derived functions must be specified in the correct order. // The function higher up the dependency chain must come second CalculationFunctions derivedFunctions = calculationFunctions.composedWith(derivedFn1, derivedFn2); TestTarget target = new TestTarget(42); //JAVA TO C# CONVERTER TODO TASK: There is no .NET equivalent to the Java 'super' constraint: //ORIGINAL LINE: CalculationFunction<? super TestTarget> function = derivedFunctions.getFunction(target); //JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET: CalculationFunction <object> function = derivedFunctions.getFunction(target); ImmutableSet <Measure> expectedMeasures = ImmutableSet.of(BUCKETED_PV01, CASH_FLOWS, PAR_RATE, PRESENT_VALUE_MULTI_CCY); assertThat(function.supportedMeasures()).isEqualTo(expectedMeasures); }
//------------------------------------------------------------------------- /// <summary> /// Obtains an instance that will calculate the specified cells. /// <para> /// The cells must all be for the same row index and none of the column indices must overlap. /// The result will contain no calculation parameters. /// /// </para> /// </summary> /// <param name="target"> the target for which the value will be calculated </param> /// <param name="function"> the function that performs the calculation </param> /// <param name="cells"> the cells to be calculated by this task </param> /// <returns> the task </returns> public static CalculationTask of <T1>(CalculationTarget target, CalculationFunction <T1> function, params CalculationTaskCell[] cells) where T1 : com.opengamma.strata.basics.CalculationTarget { return(of(target, function, CalculationParameters.empty(), ImmutableList.copyOf(cells))); }
// creates the tasks for a single target private static IList <CalculationTask> createTargetTasks <T1>(CalculationTarget resolvedTarget, int rowIndex, CalculationFunction <T1> function, IList <Column> columns) { // create the cells and group them ListMultimap <CalculationParameters, CalculationTaskCell> grouped = ArrayListMultimap.create(); for (int colIndex = 0; colIndex < columns.Count; colIndex++) { Column column = columns[colIndex]; Measure measure = column.Measure; ReportingCurrency reportingCurrency = column.ReportingCurrency.orElse(ReportingCurrency.NATURAL); CalculationTaskCell cell = CalculationTaskCell.of(rowIndex, colIndex, measure, reportingCurrency); // group to find cells that can be shared, with same mappings and params (minus reporting currency) CalculationParameters @params = column.Parameters.filter(resolvedTarget, measure); grouped.put(@params, cell); } // build tasks ImmutableList.Builder <CalculationTask> taskBuilder = ImmutableList.builder(); foreach (CalculationParameters @params in grouped.Keys) { taskBuilder.add(CalculationTask.of(resolvedTarget, function, @params, grouped.get(@params))); } return(taskBuilder.build()); }