public void ValueChangesResults()
        {
            var valueRequirement = new ValueRequirement("Market_Value", new ComputationTargetSpecification(ComputationTargetType.Primitive, BloombergUid));

            var defn = GetViewDefinition();

            using (var remoteClient = Context.ViewProcessor.CreateClient())
            {
                var          liveDataOverrideInjector = remoteClient.LiveDataOverrideInjector;
                const double newValue = 1234.5678;

                ManualResetEvent            mre     = new ManualResetEvent(false);
                IViewComputationResultModel results = null;
                var listener = new EventViewResultListener();
                listener.CycleCompleted += delegate(object sender, CycleCompletedArgs e)
                {
                    results = e.FullResult;
                    mre.Set();
                };
                remoteClient.SetResultListener(listener);
                remoteClient.AttachToViewProcess(defn.UniqueID, ExecutionOptions.RealTime);
                liveDataOverrideInjector.AddValue(valueRequirement, newValue);

                mre.WaitOne();
                var result = results.AllResults.Where(
                    r => valueRequirement.IsSatisfiedBy(r.ComputedValue.Specification)).First();
                Assert.Equal(newValue, (double)result.ComputedValue.Value);
            }
        }
Exemple #2
0
        public void CanCreateAndRunFromView(ViewDefinition vd)
        {
            var snapshotManager = Context.MarketDataSnapshotManager;

            using (var proc = snapshotManager.CreateFromViewDefinition(vd.Name))
            {
                proc.Snapshot.Name = TestUtils.GetUniqueName();
                var uid = Context.MarketDataSnapshotMaster.Add(new MarketDataSnapshotDocument(null, proc.Snapshot)).UniqueId;

                try
                {
                    var snapOptions  = ExecutionOptions.Snapshot(proc.Snapshot.UniqueId);
                    var withSnapshot = GetFirstResult(snapOptions, vd.Name);

                    var options = ExecutionOptions.SingleCycle;
                    IViewComputationResultModel withoutSnapshot = GetFirstResult(options, vd.Name);

                    var withoutCount = CountResults(withoutSnapshot);
                    var withCount    = CountResults(withSnapshot);
                    if (withoutCount != withCount)
                    {
                        var withSpecs    = new HashSet <ValueSpecification>(withSnapshot.AllResults.Select(r => r.ComputedValue.Specification));
                        var withoutSpecs = new HashSet <ValueSpecification>(withoutSnapshot.AllResults.Select(r => r.ComputedValue.Specification));
                        withoutSpecs.SymmetricExceptWith(withSpecs);
                        Assert.True(false, string.Format("Running snapshot of {0} only had {1}, live had {2}", vd.Name, withCount, withoutCount));
                    }

                    Assert.Equal(withoutCount, withCount);
                }
                finally
                {
                    Context.MarketDataSnapshotMaster.Remove(uid);
                }
            }
        }
Exemple #3
0
        private void Update(IViewComputationResultModel results)
        {
            lock (_lastResultsLock)
            {
                CheckDisposed();
                Monitor.PulseAll(_lastResultsLock);

                IEngineResourceReference <IViewCycle> resourceReference =
                    _remoteViewClient.CreateCycleReference(results.ViewCycleId);

                if (resourceReference == null)
                {
                    //The engine has overtaken us.  We'll get another one soon
                    // -- In theory this can live lock if the view is very fast
                    return;
                }
                if (_graphsOutOfDate)
                {
                    _graphsOutOfDate = false; //NOTE: this is safe because our result message are serialized with our compiled notifications
                    InvokeGraphChanged();     //NOTE: we need to delay this until we have a cycle
                }

                var newResults = Pair.Create(resourceReference, results);
                var previous   = Interlocked.Exchange(ref _lastResults, newResults);

                _haveResults.Set();

                if (previous != null)
                {
                    previous.First.Dispose();
                }
            }
        }
        private static bool Matches(IViewComputationResultModel results, DateTimeOffset waitFor)
        {
            if (results.ResultTimestamp < waitFor)
            {
                return(false);
            }

            return(true);
        }
Exemple #5
0
 public CycleCompletedCall(IViewComputationResultModel fullResult, IViewDeltaResultModel deltaResult)
 {
     if (fullResult == null && deltaResult == null)
     {
         throw new ArgumentNullException("fullResult", "Both results were null");
     }
     _fullResult  = fullResult;
     _deltaResult = deltaResult;
 }
Exemple #6
0
 public CycleCompletedCall(IViewComputationResultModel fullResult, IViewDeltaResultModel deltaResult)
 {
     if (fullResult == null && deltaResult == null)
     {
         throw new ArgumentNullException("fullResult", "Both results were null");
     }
     _fullResult = fullResult;
     _deltaResult = deltaResult;
 }
        private static T Get <T>(ValueRequirement valueRequirement, IViewComputationResultModel results)
        {
            ComputedValue value;

            if (results.TryGetComputedValue("Default", valueRequirement, out value))
            {
                return((T)value.Value);
            }
            else
            {
                return(default(T));
            }
        }
Exemple #8
0
        public void CanCombineSnapshots()
        {
            ViewDefinition vd = Context.ViewProcessor.ViewDefinitionRepository.GetViewDefinition(@"Demo Equity Option Test View");
            var            snapshotManager = Context.MarketDataSnapshotManager;
            Tuple <ManageableMarketDataSnapshot, ManageableMarketDataSnapshot> snaps;

            using (var proc = snapshotManager.CreateFromViewDefinition(vd.Name))
            {
                var snapshot = proc.Snapshot;
                snaps = Halve(snapshot);

                snaps.Item1.Name = TestUtils.GetUniqueName();
                snaps.Item2.Name = TestUtils.GetUniqueName();

                Context.MarketDataSnapshotMaster.Add(new MarketDataSnapshotDocument(null, snaps.Item1));
                Context.MarketDataSnapshotMaster.Add(new MarketDataSnapshotDocument(null, snaps.Item2));
            }

            try
            {
                var snapOptions  = ExecutionOptions.GetSingleCycle(new CombinedMarketDataSpecification(new UserMarketDataSpecification(snaps.Item2.UniqueId), new UserMarketDataSpecification(snaps.Item1.UniqueId)));
                var withSnapshot = GetFirstResult(snapOptions, vd.Name);

                var options = ExecutionOptions.SingleCycle;
                IViewComputationResultModel withoutSnapshot = GetFirstResult(options, vd.Name);

                var withoutCount = CountResults(withoutSnapshot);
                var withCount    = CountResults(withSnapshot);
                if (withoutCount != withCount)
                {
                    var withSpecs    = new HashSet <ValueSpecification>(withSnapshot.AllResults.Select(r => r.ComputedValue.Specification));
                    var withoutSpecs = new HashSet <ValueSpecification>(withoutSnapshot.AllResults.Select(r => r.ComputedValue.Specification));
                    withoutSpecs.SymmetricExceptWith(withSpecs);
                    Assert.True(false, string.Format("Running snapshot of {0} only had {1}, live had {2}", vd.Name, withCount, withoutCount));
                }

                Assert.Equal(withoutCount, withCount);
            }
            finally
            {
                Context.MarketDataSnapshotMaster.Remove(snaps.Item1.UniqueId);
                Context.MarketDataSnapshotMaster.Remove(snaps.Item2.UniqueId);
            }
        }
Exemple #9
0
        public void ViewResultsMatchDefinition(ViewDefinition viewDefinition)
        {
            using (var remoteViewClient = Context.ViewProcessor.CreateClient())
            {
                ICompiledViewDefinition     compiledViewDefinition     = null;
                IViewComputationResultModel viewComputationResultModel = null;
                var resultsReady = new ManualResetEvent(false);

                var listener = new EventViewResultListener();
                listener.ViewDefinitionCompiled += delegate(object sender, ViewDefinitionCompiledArgs e)
                {
                    compiledViewDefinition = e.CompiledViewDefinition;
                };
                listener.CycleCompleted += delegate(object sender, CycleCompletedArgs e)
                {
                    viewComputationResultModel = e.FullResult;
                    resultsReady.Set();
                };
                remoteViewClient.SetResultListener(listener);

                remoteViewClient.AttachToViewProcess(viewDefinition.UniqueID, ExecutionOptions.RealTime);

                if (!resultsReady.WaitOne(TimeSpan.FromMinutes(2)))
                {
                    throw new TimeoutException("Failed to get results for " + viewDefinition.Name + " client " + remoteViewClient.GetUniqueId());
                }

                Assert.NotNull(compiledViewDefinition);

                foreach (var viewResultEntry in viewComputationResultModel.AllResults)
                {
                    Assert.NotNull(viewResultEntry.ComputedValue.Value);
                    AssertDefinitionContains(viewDefinition, viewResultEntry);
                }

                var countActualValues = viewComputationResultModel.AllResults.Count();

                var countMaxExpectedValues = CountMaxExpectedValues(compiledViewDefinition);

                Console.Out.WriteLine("{0} {1} {2}", viewDefinition.Name, countActualValues, countMaxExpectedValues);
                Assert.InRange(countActualValues, 1, countMaxExpectedValues);
            }
        }
Exemple #10
0
 private static int CountResults(IViewComputationResultModel results)
 {
     return(results.AllResults.Count());
 }
        private Dictionary <YieldCurveKey, Tuple <YieldCurve, InterpolatedYieldCurveSpecificationWithSecurities, NodalDoublesCurve> > GetYieldCurves(IViewCycle cycle, IViewComputationResultModel results)
        {
            var ret = new Dictionary <YieldCurveKey, Tuple <YieldCurve, InterpolatedYieldCurveSpecificationWithSecurities, NodalDoublesCurve> >();

            foreach (var kvp in _specs)
            {
                YieldCurveKey key = kvp.Key;
                Dictionary <string, ValueRequirement> specs = kvp.Value;

                var curve        = Get <YieldCurve>(specs[ValueRequirementNames.YieldCurve], results);
                var spec         = Get <InterpolatedYieldCurveSpecificationWithSecurities>(specs[ValueRequirementNames.YieldCurveSpec], results);
                var interpolated = Get <NodalDoublesCurve>(specs[ValueRequirementNames.YieldCurveInterpolated], results);

                if (curve == null || spec == null || interpolated == null)
                {
                    ret.Add(key, null);
                }
                else
                {
                    ret.Add(key, new Tuple <YieldCurve, InterpolatedYieldCurveSpecificationWithSecurities, NodalDoublesCurve>(curve, spec, interpolated));
                }
            }
            return(ret);
        }
Exemple #12
0
 public CycleCompletedArgs(IViewComputationResultModel fullResult, IViewDeltaResultModel deltaResult)
 {
     _fullResult = fullResult;
     _deltaResult = deltaResult;
 }
Exemple #13
0
 void IViewResultListener.CycleCompleted(IViewComputationResultModel fullResult, IViewDeltaResultModel deltaResult)
 {
     InvokeCycleCompleted(new CycleCompletedArgs(fullResult, deltaResult));
 }
 void IViewResultListener.CycleCompleted(IViewComputationResultModel fullResult, IViewDeltaResultModel deltaResult)
 {
     InvokeCycleCompleted(new CycleCompletedArgs(fullResult, deltaResult));
 }
 public CycleCompletedArgs(IViewComputationResultModel fullResult, IViewDeltaResultModel deltaResult)
 {
     _fullResult  = fullResult;
     _deltaResult = deltaResult;
 }
 private static int CountResults(IViewComputationResultModel results)
 {
     return results.AllResults.Count();
 }