示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RateBasisCurve"/> class.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="cache">The cache.</param>
        /// <param name="nameSpace">The client namespace</param>
        /// <param name="referenceCurveData">The market data. This must contain both the underlying base curve and the spread curve.
        /// Otherwise the RateBasisInterpolator can not instantiate.</param>
        /// <param name="derivedCurveData">The spread Curve Data</param>
        /// <param name="fixingCalendar">The fixingCalendar.</param>
        /// <param name="rollCalendar">The rollCalendar.</param>
        public ClearedRateCurve(ILogger logger, ICoreCache cache, String nameSpace,
                                Triplet <PricingStructure, PricingStructureValuation, NamedValueSet> referenceCurveData,
                                Triplet <PricingStructure, PricingStructureValuation, NamedValueSet> derivedCurveData, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar)
            : base(derivedCurveData.Third, GenerateHolder(logger, cache, nameSpace, derivedCurveData.Third))
        {
            PricingStructureData = new PricingStructureData(CurveType.Child, AssetClass.Rates, derivedCurveData.Third);
            var curveId = GetRateCurveId();
            //Set the identifier.
            var nvs = derivedCurveData.Third;
            var pricingStructureId = GetRateCurveId();
            var refCurveId         = PropertyHelper.ExtractReferenceCurveUniqueId(nvs);

            ReferenceDiscountingCurveId = refCurveId != null ? new Identifier(refCurveId) : ReferenceDiscountingCurveId = null;
            if (pricingStructureId.PricingStructureType != PricingStructureTypeEnum.ClearedRateCurve)
            {
                return;
            }
            //Set the reference curve
            var baseCurveFpml  = new Pair <PricingStructure, PricingStructureValuation>(referenceCurveData.First, referenceCurveData.Second);
            var baseCurveProps = referenceCurveData.Third;

            BaseDiscountingCurve = (IRateCurve)PricingStructureFactory.Create(logger, cache, nameSpace, fixingCalendar, rollCalendar, baseCurveFpml, baseCurveProps);
            //Get the spread Data
            var spreadCurveFpml = new Pair <PricingStructure, PricingStructureValuation>(derivedCurveData.First, derivedCurveData.Second);
            //Override properties.
            //var optimize = PropertyHelper.ExtractOptimizeBuildFlag(properties);
            var bootstrap    = PropertyHelper.ExtractBootStrapOverrideFlag(nvs);
            var tempFpml     = (YieldCurveValuation)spreadCurveFpml.Second;
            var spreadAssets = tempFpml.inputs;
            //This is to catch it when there are no discount factor points.
            var discountsAbsent = tempFpml.discountFactorCurve?.point == null || tempFpml.discountFactorCurve.point.Length == 0;
            var indexTenor      = curveId.ForecastRateIndex?.indexTenor;

            if (bootstrap || discountsAbsent)
            {
                //There must be a valid quoted asset set in order to bootstrap.
                if (!XsdClassesFieldResolver.QuotedAssetSetIsValid(spreadAssets))
                {
                    return;
                }
                PriceableClearedRateAssets =
                    PriceableAssetFactory.CreatePriceableClearedRateAssetsWithBasisSwaps(logger, cache, nameSpace, indexTenor, spreadAssets, pricingStructureId.BaseDate, fixingCalendar, rollCalendar);
                GetYieldCurveValuation().zeroCurve = null;
                TermCurve termCurve = tempFpml.discountFactorCurve ?? SetConfigurationData();
                DateTime  baseDate  = GetYieldCurveValuation().baseDate.Value;
                termCurve.point = ClearedRateBootstrapper.Bootstrap(PriceableClearedRateAssets, BaseDiscountingCurve, baseDate, termCurve.extrapolationPermitted, termCurve.interpolationMethod, Tolerance);
                SetFpMLData(new Pair <PricingStructure, PricingStructureValuation>(PricingStructure, PricingStructureValuation), false);
                SetInterpolator(termCurve);
            }
            else
            {
                // the discount curve is already built, so don't rebuild
                PriceableClearedRateAssets = PriceableAssetFactory.CreatePriceableClearedRateAssetsWithBasisSwaps(logger, cache, nameSpace, indexTenor, spreadAssets, pricingStructureId.BaseDate, fixingCalendar, rollCalendar);
                //Order the assets.
                PriceableClearedRateAssets = PriceableClearedRateAssets.OrderBy(a => a.GetRiskMaturityDate()).ToList();
                CreatePricingStructure(pricingStructureId, tempFpml.discountFactorCurve, spreadAssets);
                // CreatePricingStructure(pricingStructureId, tempFpml.discountFactorCurve, PriceableAssetFactory.Parse(PriceableClearedRateAssets));
                SetInterpolator(GetYieldCurveValuation().discountFactorCurve);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="CommoditySpreadCurve2"/> class.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="cache">The cache.</param>
        /// <param name="nameSpace">The client namespace</param>
        /// <param name="referenceCurveData">The market data. This must contain both the underlying base curve and the spread curve.
        /// Otherwise the RateBasisInterpolator can not instantiate.</param>
        /// <param name="spreadCurveData">The spread Curve Data</param>
        /// <param name="rollCalendar">The rollCalendar.</param>
        public CommoditySpreadCurve2(ILogger logger, ICoreCache cache, String nameSpace,
                                     Triplet <PricingStructure, PricingStructureValuation, NamedValueSet> referenceCurveData,
                                     Triplet <PricingStructure, PricingStructureValuation, NamedValueSet> spreadCurveData, IBusinessCalendar rollCalendar)
            : base(spreadCurveData.Third, GenerateHolder(logger, cache, nameSpace, spreadCurveData.Third))
        {
            PricingStructureData = new PricingStructureData(CurveType.Child, AssetClass.Rates, spreadCurveData.Third);
            //Set the identifier.
            var nvs = spreadCurveData.Third;
            var pricingStructureId = GetCommodityCurveId();
            var refCurveId         = PropertyHelper.ExtractReferenceCurveUniqueId(nvs);

            ReferenceCurveId = refCurveId != null ? new Identifier(refCurveId) : ReferenceCurveId = null;
            if (pricingStructureId.PricingStructureType != PricingStructureTypeEnum.CommoditySpreadCurve)
            {
                return;
            }
            //Set the reference curve
            var baseCurveFpml  = new Pair <PricingStructure, PricingStructureValuation>(referenceCurveData.First, referenceCurveData.Second);
            var baseCurveProps = referenceCurveData.Third;

            BaseCurve = (ICommodityCurve)PricingStructureFactory.Create(logger, cache, nameSpace, rollCalendar, rollCalendar, baseCurveFpml, baseCurveProps);
            //Get the spread Data
            var spreadCurveFpml = new Pair <PricingStructure, PricingStructureValuation>(spreadCurveData.First, spreadCurveData.Second);
            //Override properties.
            //var optimize = PropertyHelper.ExtractOptimizeBuildFlag(properties);
            var bootstrap    = PropertyHelper.ExtractBootStrapOverrideFlag(nvs);
            var tempFpml     = (FxCurveValuation)spreadCurveFpml.Second;
            var spreadAssets = tempFpml.spotRate;
            //This is to catch it when there are no discount factor points.
            var discountsAbsent = tempFpml.fxForwardCurve == null ||
                                  tempFpml.fxForwardCurve.point == null ||
                                  tempFpml.fxForwardCurve.point.Length == 0;

            if (bootstrap || discountsAbsent)
            {
                //There must be a valid quotedassetset in order to bootstrap.
                if (!XsdClassesFieldResolver.QuotedAssetSetIsValid(spreadAssets))
                {
                    return;
                }
                PriceableCommoditySpreadAssets =
                    PriceableAssetFactory.CreatePriceableCommoditySpreadAssets(logger, cache, nameSpace, pricingStructureId.BaseDate, spreadAssets, rollCalendar);
                Build(logger, cache, nameSpace, rollCalendar, rollCalendar);
            }
            else
            {
                // the discount curve is already built, so don't rebuild
                PriceableCommoditySpreadAssets = PriceableAssetFactory.CreatePriceableCommoditySpreadAssets(logger, cache, nameSpace, pricingStructureId.BaseDate, spreadAssets, rollCalendar);
                //Order the assets.
                PriceableCommoditySpreadAssets = PriceableCommoditySpreadAssets.OrderBy(a => a.GetRiskMaturityDate()).ToList();
                CreatePricingStructure(pricingStructureId, tempFpml.fxForwardCurve, PriceableAssetFactory.Parse(PriceableCommoditySpreadAssets));
                //SetInterpolator(BaseCurve, pricingStructureId.PricingStructureType);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="RateXccySpreadCurve"/> class.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <param name="cache">The cache.</param>
        /// <param name="nameSpace">THe client namespace</param>
        /// <param name="baseCurveData">The market data. This must contain both the underlying base curve and the spread curve.
        /// Otherwise the RateBasisInterpolator can not instantiate.</param>
        /// <param name="referenceFxCurveData">The fxcurve referenced.</param>
        /// <param name="currency2CurveData">The curve data for the non base curve. This is normally the domestic curve i.e. AUD,
        /// as FX is quotes as xccy basis swaps adjust on the non-USD leg.</param>
        /// <param name="spreadCurveData">The spread Curve Data</param>
        /// <param name="fixingCalendar">The fixingCalendar.</param>
        /// <param name="rollCalendar">The rollCalendar.</param>
        public RateXccySpreadCurve(ILogger logger, ICoreCache cache, string nameSpace,
                                   Triplet <PricingStructure, PricingStructureValuation, NamedValueSet> baseCurveData,
                                   Triplet <PricingStructure, PricingStructureValuation, NamedValueSet> referenceFxCurveData,
                                   Triplet <PricingStructure, PricingStructureValuation, NamedValueSet> currency2CurveData,
                                   Triplet <PricingStructure, PricingStructureValuation, NamedValueSet> spreadCurveData, IBusinessCalendar fixingCalendar, IBusinessCalendar rollCalendar)
            : base(logger, cache, nameSpace, spreadCurveData, fixingCalendar, rollCalendar)
        {
            //Set the identifier.
            var nvs = spreadCurveData.Third;
            var pricingStructureId = new RateCurveIdentifier(nvs);

            PricingStructureIdentifier = pricingStructureId;
            var refCurveId = nvs.GetValue <string>(CurveProp.ReferenceCurveUniqueId);

            ReferenceCurveId = refCurveId != null ? new Identifier(refCurveId) : ReferenceCurveId = null;
            if (pricingStructureId.PricingStructureType != PricingStructureTypeEnum.RateXccyCurve)
            {
                return;
            }
            //Set the curve term.
            var cutOverTerm = spreadCurveData.Third.GetValue <string>("CutOverTerm");

            if (cutOverTerm != null)
            {
                CutOverTerm = PeriodHelper.Parse(cutOverTerm);
            }
            //Set the reference curve
            var baseCurveFpML  = new Pair <PricingStructure, PricingStructureValuation>(baseCurveData.First, baseCurveData.Second);
            var baseCurveProps = baseCurveData.Third;

            BaseCurve = (IRateCurve)PricingStructureFactory.Create(logger, cache, nameSpace, fixingCalendar, rollCalendar, baseCurveFpML, baseCurveProps);
            var fxCurveFpML  = new Pair <PricingStructure, PricingStructureValuation>(referenceFxCurveData.First, referenceFxCurveData.Second);
            var fxCurveProps = referenceFxCurveData.Third;

            ReferenceFxCurve = (IFxCurve)PricingStructureFactory.Create(logger, cache, nameSpace, fixingCalendar, rollCalendar, fxCurveFpML, fxCurveProps);
            //Set the reference curve
            var currency2CurveFpML  = new Pair <PricingStructure, PricingStructureValuation>(currency2CurveData.First, currency2CurveData.Second);
            var currency2CurveProps = currency2CurveData.Third;

            Currency2Curve = (RateCurve)PricingStructureFactory.Create(logger, cache, nameSpace, fixingCalendar, rollCalendar, currency2CurveFpML, currency2CurveProps);
            //Get the spread Data
            var spreadCurveFpML  = new Pair <PricingStructure, PricingStructureValuation>(spreadCurveData.First, spreadCurveData.Second);
            var spreadCurveProps = spreadCurveData.Third;

            IsCurrency1RateCurve = spreadCurveProps.GetValue <bool>("Currency1RateCurve");
            //Override properties.
            //var optimize = PropertyHelper.ExtractOptimizeBuildFlag(properties);TODO add this later.
            var bootstrap    = PropertyHelper.ExtractBootStrapOverrideFlag(nvs);
            var tempFpml     = (YieldCurveValuation)spreadCurveFpML.Second;
            var spreadAssets = tempFpml.inputs;
            //This is to catch it when there are no discount factor points.
            var discountsAbsent = tempFpml.discountFactorCurve?.point == null || tempFpml.discountFactorCurve.point.Length == 0;

            if (cache == null)
            {
                bootstrap = false;
            }
            if (bootstrap || discountsAbsent)
            {
                //There must be a valid quoted asset set in order to bootstrap.
                if (!XsdClassesFieldResolver.QuotedAssetSetIsValid(spreadAssets))
                {
                    return;
                }
                PriceableRateSpreadAssets = PriceableAssetFactory.CreatePriceableRateSpreadAssets(logger, cache, nameSpace, pricingStructureId.BaseDate, spreadAssets, fixingCalendar, rollCalendar);
                Build(logger, cache, nameSpace, fixingCalendar, rollCalendar);
            }
            else
            {
                if (cache != null)
                {
                    // the discount curve is already built, so don't rebuild
                    PriceableRateSpreadAssets = PriceableAssetFactory.CreatePriceableRateSpreadAssets(logger, cache, nameSpace, pricingStructureId.BaseDate, spreadAssets, fixingCalendar, rollCalendar);
                    CreatePricingStructure(pricingStructureId, tempFpml.discountFactorCurve, PriceableAssetFactory.Parse(PriceableRateSpreadAssets));
                    SetInterpolator(BaseCurve, pricingStructureId.PricingStructureType);
                }
                else
                {
                    CreatePricingStructure(pricingStructureId, tempFpml.discountFactorCurve, spreadAssets);
                    SetInterpolator(BaseCurve, pricingStructureId.PricingStructureType);
                }
            }
        }
示例#4
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();
                        //    });
                    }
                }
            }
        }