Example #1
0
        /// <summary>
        /// Tests building a tree of requirements using market data functions.
        /// </summary>
        public virtual void buildDependencyTree()
        {
            MarketDataNode expected = rootNode(observableNode(new TestIdA(this, "1")), valueNode(new TestIdB(this, "2"), valueNode(new TestIdB(this, "4"), observableNode(new TestIdA(this, "5"))), timeSeriesNode(new TestIdA(this, "3"))), timeSeriesNode(new TestIdA(this, "6")));

            // The requirements for the data directly used by the calculations
            MarketDataRequirements requirements = MarketDataRequirements.builder().addValues(new TestIdA(this, "1"), new TestIdB(this, "2")).addTimeSeries(new TestIdA(this, "6")).build();

            // Requirements for each item in the tree - used to initialize the functions
            MarketDataRequirements id2Reqs = MarketDataRequirements.builder().addTimeSeries(new TestIdA(this, "3")).addValues(new TestIdB(this, "4")).build();

            MarketDataRequirements id4Reqs = MarketDataRequirements.builder().addValues(new TestIdA(this, "5")).build();

            ImmutableMap <TestIdB, MarketDataRequirements> reqsMap = ImmutableMap.of(new TestIdB(this, "2"), id2Reqs, new TestIdB(this, "4"), id4Reqs);

            TestMarketDataFunctionA builderA = new TestMarketDataFunctionA();
            TestMarketDataFunctionB builderB = new TestMarketDataFunctionB(reqsMap);

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.google.common.collect.ImmutableMap<Class, MarketDataFunction<?, ?>> functions = com.google.common.collect.ImmutableMap.of(TestIdA.class, builderA, TestIdB.class, builderB);
            ImmutableMap <Type, MarketDataFunction <object, ?> > functions = ImmutableMap.of(typeof(TestIdA), builderA, typeof(TestIdB), builderB);

            MarketDataNode root = MarketDataNode.buildDependencyTree(requirements, BuiltScenarioMarketData.empty(), MarketDataConfig.empty(), functions);

            assertThat(root).isEqualTo(expected);
        }
Example #2
0
        /// <summary>
        /// Tests that supplied data is in a leaf node and the functions aren't asked for dependencies for supplied data.
        /// </summary>
        public virtual void noDependenciesForSuppliedData()
        {
            MarketDataNode expected1 = rootNode(valueNode(new TestIdB(this, "1"), observableNode(new TestIdA(this, "2"))), valueNode(new TestIdB(this, "3"), valueNode(new TestIdB(this, "4"))));

            MarketDataRequirements requirements = MarketDataRequirements.builder().addValues(new TestIdB(this, "1"), new TestIdB(this, "3")).build();

            MarketDataRequirements id1Reqs = MarketDataRequirements.builder().addValues(new TestIdA(this, "2")).build();

            MarketDataRequirements id3Reqs = MarketDataRequirements.builder().addValues(new TestIdB(this, "4")).build();

            ImmutableMap <TestIdB, MarketDataRequirements> reqsMap = ImmutableMap.of(new TestIdB(this, "1"), id1Reqs, new TestIdB(this, "3"), id3Reqs);

            TestMarketDataFunctionB builder = new TestMarketDataFunctionB(reqsMap);

//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.google.common.collect.ImmutableMap<Class, MarketDataFunction<?, ?>> functions = com.google.common.collect.ImmutableMap.of(TestIdB.class, builder);
            ImmutableMap <Type, MarketDataFunction <object, ?> > functions = ImmutableMap.of(typeof(TestIdB), builder);

            MarketDataNode root1 = MarketDataNode.buildDependencyTree(requirements, BuiltScenarioMarketData.empty(), MarketDataConfig.empty(), functions);

            assertThat(root1).isEqualTo(expected1);

            BuiltScenarioMarketData suppliedData = BuiltScenarioMarketData.builder(date(2011, 3, 8)).addValue(new TestIdB(this, "1"), new TestMarketDataB()).addValue(new TestIdB(this, "3"), new TestMarketDataB()).build();

            MarketDataNode root2 = MarketDataNode.buildDependencyTree(requirements, suppliedData, MarketDataConfig.empty(), functions);

            MarketDataNode expected2 = rootNode(valueNode(new TestIdB(this, "1")), valueNode(new TestIdB(this, "3")));

            assertThat(root2).isEqualTo(expected2);
        }
Example #3
0
        /// <summary>
        /// Test a node with no children is added when there is no market data function for an ID.
        /// </summary>
        public virtual void noMarketDataBuilder()
        {
            MarketDataNode expected = rootNode(valueNode(new TestIdC("1")), valueNode(new TestIdB(this, "2"), valueNode(new TestIdC("3"))));

            MarketDataRequirements requirements = MarketDataRequirements.builder().addValues(new TestIdC("1"), new TestIdB(this, "2")).build();

            MarketDataRequirements id2Reqs = MarketDataRequirements.builder().addValues(new TestIdC("3")).build();

            TestMarketDataFunctionB builder = new TestMarketDataFunctionB(ImmutableMap.of(new TestIdB(this, "2"), id2Reqs));
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: com.google.common.collect.ImmutableMap<Class, MarketDataFunction<?, ?>> functions = com.google.common.collect.ImmutableMap.of(TestIdB.class, builder);
            ImmutableMap <Type, MarketDataFunction <object, ?> > functions = ImmutableMap.of(typeof(TestIdB), builder);
            // Build the tree without providing a market data function to handle TestId3
            MarketDataNode root = MarketDataNode.buildDependencyTree(requirements, BuiltScenarioMarketData.empty(), MarketDataConfig.empty(), functions);

            assertThat(root).isEqualTo(expected);
        }
Example #4
0
        /// <summary>
        /// Tests removing the leaf dependencies from the tree to decide which market data can be built.
        /// </summary>
        public virtual void withLeavesRemoved()
        {
            MarketDataNode root = rootNode(observableNode(new TestIdA(this, "1")), valueNode(new TestIdB(this, "2"), valueNode(new TestIdB(this, "3")), observableNode(new TestIdA(this, "4")), valueNode(new TestIdB(this, "5"), timeSeriesNode(new TestIdA(this, "6")))), valueNode(new TestIdB(this, "7")));

            Pair <MarketDataNode, MarketDataRequirements> pair1 = root.withLeavesRemoved();

            MarketDataRequirements expectedReqs1 = MarketDataRequirements.builder().addValues(new TestIdA(this, "1")).addValues(new TestIdB(this, "3")).addValues(new TestIdA(this, "4")).addTimeSeries(new TestIdA(this, "6")).addValues(new TestIdB(this, "7")).build();

            MarketDataNode expectedTree1 = rootNode(valueNode(new TestIdB(this, "2"), valueNode(new TestIdB(this, "5"))));

            MarketDataNode         tree1 = pair1.First;
            MarketDataRequirements reqs1 = pair1.Second;

            assertThat(tree1).isEqualTo(expectedTree1);
            assertThat(expectedReqs1).isEqualTo(reqs1);

            Pair <MarketDataNode, MarketDataRequirements> pair2 = tree1.withLeavesRemoved();

            MarketDataRequirements expectedReqs2 = MarketDataRequirements.builder().addValues(new TestIdB(this, "5")).build();

            MarketDataNode expectedTree2 = rootNode(valueNode(new TestIdB(this, "2")));

            MarketDataNode         tree2 = pair2.First;
            MarketDataRequirements reqs2 = pair2.Second;

            assertThat(tree2).isEqualTo(expectedTree2);
            assertThat(expectedReqs2).isEqualTo(reqs2);

            Pair <MarketDataNode, MarketDataRequirements> pair3 = tree2.withLeavesRemoved();

            MarketDataRequirements expectedReqs3 = MarketDataRequirements.builder().addValues(new TestIdB(this, "2")).build();

            MarketDataNode         tree3 = pair3.First;
            MarketDataRequirements reqs3 = pair3.Second;

            assertThat(tree3.Leaf).True;
            assertThat(expectedReqs3).isEqualTo(reqs3);
        }
Example #5
0
        /// <summary>
        /// Builds a tree representing the dependencies between items of market data and returns the root node.
        /// </summary>
        /// <param name="requirements">  IDs of the market data that must be provided </param>
        /// <param name="suppliedData">  data supplied by the user </param>
        /// <param name="marketDataConfig">  configuration specifying how market data values should be built </param>
        /// <param name="functions">  functions for market data, keyed by the type of market data ID they handle </param>
        /// <returns> the root node of the market data dependency tree </returns>
        internal static MarketDataNode buildDependencyTree <T1>(MarketDataRequirements requirements, ScenarioMarketData suppliedData, MarketDataConfig marketDataConfig, IDictionary <T1> functions)
        {
            DependencyTreeBuilder treeBuilder = DependencyTreeBuilder.of(suppliedData, requirements, marketDataConfig, functions);

            return(MarketDataNode.root(treeBuilder.dependencyNodes()));
        }
Example #6
0
 private static MarketDataNode timeSeriesNode(ObservableId id)
 {
     return(MarketDataNode.leaf(id, MarketDataNode.DataType.TIME_SERIES));
 }
Example #7
0
 private static MarketDataNode observableNode(ObservableId id)
 {
     return(MarketDataNode.leaf(id, MarketDataNode.DataType.SINGLE_VALUE));
 }
Example #8
0
 private static MarketDataNode valueNode <T1>(MarketDataId <T1> id, params MarketDataNode[] children)
 {
     return(MarketDataNode.child(id, MarketDataNode.DataType.SINGLE_VALUE, Arrays.asList(children)));
 }
Example #9
0
 //-------------------------------------------------------------------------
 private static MarketDataNode rootNode(params MarketDataNode[] children)
 {
     return(MarketDataNode.root(Arrays.asList(children)));
 }