コード例 #1
0
 private void BaseCurveCallback(ICoreItem baseCurveItem)
 {
     try
     {
         // check for server shutdown
         if (GetState() != BasicServerState.Running)
         {
             return;
         }
         // refresh all curves
         // - update market data
         // - regenerate curves
         DateTime dtNow = DateTime.Now;
         // Curve identifiers
         var nameSpace  = baseCurveItem.AppProps.GetValue <string>(EnvironmentProp.NameSpace, true);
         var marketName = baseCurveItem.AppProps.GetValue <string>(CurveProp.Market, true);
         var curveType  = baseCurveItem.AppProps.GetValue <string>(CurveProp.PricingStructureType, true);
         var curveName  = baseCurveItem.AppProps.GetValue <string>(CurveProp.CurveName, true);
         //    });
         //}
         var curveGenRequest = new OrdinaryCurveGenRequest
         {
             RequestId   = Guid.NewGuid().ToString(),
             RequesterId = new UserIdentity
             {
                 Name        = IntClient.Target.ClientInfo.Name,
                 DisplayName = "Curve Generation Server"
             },
             BaseDate               = dtNow.Date,
             NameSpace              = nameSpace,
             SaveMarketData         = false,
             UseSavedMarketData     = true,
             ForceGenerateEODCurves = false,
             CurveSelector          = new[] { new CurveSelection
                                              {
                                                  NameSpace  = nameSpace,
                                                  MarketName = marketName,
                                                  CurveType  = curveType,
                                                  CurveName  = curveName
                                              } }
         };
         IWorkContext context = new WorkContext(Logger, IntClient.Target, "DEV");
         using (var workflow = new WFGenerateOrdinaryCurve())
         {
             workflow.Initialise(context);
             WorkflowOutput <HandlerResponse> output = workflow.Execute(curveGenRequest);
             WorkflowHelper.ThrowErrors(output.Errors);
         }
     }
     catch (Exception excp)
     {
         Logger.LogDebug("Base curve generation failed with exception: {0}", excp.GetType().Name);
         Logger.Log(excp);
     }
 }
コード例 #2
0
 protected override void OnFirstCallback()
 {
     base.OnFirstCallback();
     // initialise workflow
     _workflow.Initialise(_workContext);
     // subscribe to curve definitions
     _curveSubs = IntClient.Target.Subscribe <QuotedAssetSet>(
         Expr.BoolAND(
             Expr.IsEQU(CurveProp.Function, FunctionProp.QuotedAssetSet.ToString()),
             Expr.IsEQU(CurveProp.Market, CurveConst.QR_LIVE),
             Expr.IsNull(CurveProp.MarketDate)),
         (subscription, item) =>
     {
         MainThreadQueue?.Dispatch(item, BaseCurveCallback);
     }, null);
 }
コード例 #3
0
        public void ProcessItems()
        {
            int count = Interlocked.Decrement(ref _queuedCalls);

            // exit if there are more callbacks following us
            //if (count % 10000 == 0)
            _loggerRef.Target.LogDebug("ProcessItems: Queued calls remaining: {0}", count);
            if (count != 0)
            {
                return;
            }
            ICoreItem item = null;

            _queuedItems.Locked(queue =>
            {
                if (queue.Count > 0)
                {
                    item = queue.Dequeue();
                }
            });
            while (item != null)
            {
                var qas = item.Data as QuotedAssetSet;
                if (qas != null)
                {
                    // 1. Get the property values that uniquely identify the curves to refresh.
                    // This is the process for the workflow request. Alternatively, a direct build of the curve can occur.
                    //
                    var nameSpace          = item.AppProps.GetValue <string>(EnvironmentProp.NameSpace);
                    var market             = item.AppProps.GetValue <string>(CurveProp.Market);//For real time use Market and not MarketAndDate
                    var curveType          = item.AppProps.GetValue <string>(CurveProp.PricingStructureType);
                    var curveName          = item.AppProps.GetValue <string>(CurveProp.CurveName);
                    var configIdentifier   = FunctionProp.Configuration + ".PricingStructures." + market + "." + curveType + "." + curveName;
                    var identifier         = FunctionProp.Market + "." + market + "." + curveType + "." + curveName;
                    List <ICoreItem> items = null;
                    // 2.Check if the dependent curves should be refreshed
                    //
                    if (chkBoxDependentCurves.Checked)
                    {
                        //Find all the QAS's where the ReferenceCurveName is equal to the curveType.curveName!
                        var requestProperties = new NamedValueSet();
                        requestProperties.Set(EnvironmentProp.NameSpace, NameSpace);
                        requestProperties.Set(CurveProp.Market, market);
                        requestProperties.Set(EnvironmentProp.Function, FunctionProp.Configuration);
                        requestProperties.Set(CurveProp.ReferenceCurveName, curveType + '.' + curveName);
                        IExpression queryExpr = Expr.BoolAND(requestProperties);
                        _loggerRef.Target.LogDebug("Dependent curve property request set at {0}", DateTime.Now.ToLongTimeString());
                        items = _cache.LoadItems <Market>(queryExpr);
                    }
                    // 3. If the build is a local build then use the curve engine.
                    //
                    if (!chkBoxWorkflow.Checked)
                    {
                        _loggerRef.Target.LogDebug("Request to build base curve {0} locally at : {1}", identifier,
                                                   DateTime.Now.ToLongTimeString());
                        var curve = CurveEngine.RefreshPricingStructureFromConfiguration(_loggerRef.Target, _cache, nameSpace, configIdentifier, identifier, qas, DateTime.Now, DateTime.Now);
                        _loggerRef.Target.LogDebug("Built the base curve {0} locally at : {1}", curve,
                                                   DateTime.Now.ToLongTimeString());
                        if (items != null)
                        {
                            foreach (var dataItem in items)
                            {
                                var spreadCurve = dataItem.Data as Market;
                                if (spreadCurve == null)
                                {
                                    continue;
                                }
                                //var bootstrap = dataItem.AppProps.GetValue<bool>(CurveProp.BootStrap, false);
                                //if (!bootstrap) { dataItem.AppProps.Set(CurveProp.BootStrap, true); }
                                try
                                {
                                    var curveId = spreadCurve.id;
                                    if (String.IsNullOrEmpty(curveId))
                                    {
                                        curveId = spreadCurve.Items[0].id;
                                        //use yieldCurve.id, CurveGen 1.X compatible
                                    }
                                    dataItem.AppProps.Set(CurveProp.BaseDate, DateTime.Now);
                                    dataItem.AppProps.Set(CurveProp.BuildDateTime, DateTime.Now);
                                    var marketData =
                                        new Pair <PricingStructure, PricingStructureValuation>(spreadCurve.Items[0],
                                                                                               spreadCurve.Items1[0]);
                                    var ps = PricingStructureFactory.Create(_loggerRef.Target, _cache, nameSpace, null, null,
                                                                            marketData, dataItem.AppProps);
                                    if (ps != null)
                                    {
                                        CurveEngine.SaveCurve(_cache, nameSpace, ps);
                                    }
                                    _loggerRef.Target.LogDebug("Built the spread curve {0} locally at : {1}",
                                                               curveId,
                                                               DateTime.Now.ToLongTimeString());
                                }
                                catch (Exception e)
                                {
                                    _loggerRef.Target.LogDebug(e.ToString());
                                }
                            }
                        }
                    }
                    else
                    {
                        // 4. Set the parameters for the work request.
                        //
                        var curveGenRequest = new OrdinaryCurveGenRequest
                        {
                            NameSpace   = nameSpace,
                            BaseDate    = DateTime.Now,
                            RequestId   = Guid.NewGuid().ToString(),
                            RequesterId = new UserIdentity
                            {
                                Name        = _cache.ClientInfo.Name,
                                DisplayName = _cache.ClientInfo.UserFullName
                                              //Name = _clientRef.Target.ClientInfo.Name,
                                              //DisplayName = _clientRef.Target.ClientInfo.UserFullName
                            },
                            UseSavedMarketData     = true,
                            ForceGenerateEODCurves = true
                        };
                        // 5. Set the base curve in the curve selection for the work request.
                        //
                        var curveSelector = new List <CurveSelection>
                        {
                            new CurveSelection
                            {
                                NameSpace  = nameSpace,
                                MarketName = market,
                                CurveType  = curveType,
                                CurveName  = curveName
                            }
                        };
                        // 6.Include all other dependent curvenames i.e. spread curves.
                        //
                        if (items != null)
                        {
                            curveSelector.AddRange(from childCurve in items
                                                   let spreadCurveType =
                                                       childCurve.AppProps.GetValue <string>(
                                                           CurveProp.PricingStructureType)
                                                       let spreadCurveName =
                                                           childCurve.AppProps.GetValue <string>(CurveProp.CurveName)
                                                           select new CurveSelection
                            {
                                NameSpace  = nameSpace,
                                MarketName = market,
                                CurveType  = spreadCurveType,
                                CurveName  = spreadCurveName
                            });
                        }
                        curveGenRequest.CurveSelector = curveSelector.ToArray();
                        // 7. Set the actual work request.
                        //
                        IWorkContext context = new WorkContext(_loggerRef.Target, _cache, "DEV");
                        //IWorkContext context = new WorkContext(_loggerRef.Target, _clientRef.Target, "DEV");
                        _loggerRef.Target.LogDebug("WorkContext set at {0}", DateTime.Now.ToLongTimeString());
                        using (var workflow = new WFGenerateOrdinaryCurve())
                        {
                            workflow.Initialise(context);
                            WorkflowOutput <HandlerResponse> output = workflow.Execute(curveGenRequest);
                            WorkflowHelper.ThrowErrors(output.Errors);
                            foreach (var error in output.Errors)
                            {
                                _loggerRef.Target.LogInfo("WorkFlow error: {0} at {1}", error.Message, DateTime.Now.ToLongTimeString());
                            }
                        }
                        _loggerRef.Target.LogDebug("WorkFlow executed at {0}", DateTime.Now.ToLongTimeString());
                        //item = null;
                        //_queuedItems.Locked(queue =>
                        //    {
                        //        if (queue.Count > 0)
                        //            item = queue.Dequeue();
                        //    });
                    }
                }
            }
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: zhangz/Highlander.Net
        public void ProcessItems()
        {
            int count = Interlocked.Decrement(ref _queuedCalls);

            // exit if there are more callbacks following us
            if (count % 10000 == 0)
            {
                _loggerRef.Target.LogDebug("ProcessItems: Queued calls remaining: {0}", count);
            }
            if (count != 0)
            {
                return;
            }
            ICoreItem item = null;

            _queuedItems.Locked(queue =>
            {
                if (queue.Count > 0)
                {
                    item = queue.Dequeue();
                }
            });
            while (item != null)
            {
                if (item.Data is QuotedAssetSet)
                {
                    var nameSpace       = item.AppProps.GetValue <string>(EnvironmentProp.NameSpace);
                    var marketName      = item.AppProps.GetValue <string>(CurveProp.MarketAndDate);
                    var curveType       = item.AppProps.GetValue <string>(CurveProp.PricingStructureType);
                    var curveName       = item.AppProps.GetValue <string>(CurveProp.CurveName);
                    var curveGenRequest = new OrdinaryCurveGenRequest
                    {
                        NameSpace   = nameSpace,
                        BaseDate    = DateTime.Now,
                        RequestId   = Guid.NewGuid().ToString(),
                        RequesterId = new UserIdentity
                        {
                            Name        = _clientRef.Target.ClientInfo.Name,
                            DisplayName = _clientRef.Target.ClientInfo.UserFullName
                        },
                        UseSavedMarketData     = true,
                        ForceGenerateEODCurves = true,
                        CurveSelector          = new[] { new CurveSelection
                                                         {
                                                             NameSpace  = nameSpace,
                                                             MarketName = marketName,
                                                             CurveType  = curveType,
                                                             CurveName  = curveName
                                                         } }
                    };
                    IWorkContext context = new WorkContext(_loggerRef.Target, _clientRef.Target, "DEV");
                    using (var workflow = new WFGenerateOrdinaryCurve())
                    {
                        workflow.Initialise(context);
                        WorkflowOutput <HandlerResponse> output = workflow.Execute(curveGenRequest);
                        WorkflowHelper.ThrowErrors(output.Errors);
                    }
                    item = null;
                    _queuedItems.Locked(queue =>
                    {
                        if (queue.Count > 0)
                        {
                            item = queue.Dequeue();
                        }
                    });
                }
            }
        }