示例#1
0
        public string CreateFraTradeValuation(ILogger logger, ICoreCache cache,
                                              IRateCurve forwardCurve, IRateCurve discountCurve,
                                              IBusinessCalendar fixingCalendar, IBusinessCalendar paymentCalendar,
                                              FraInputRange fraInputRange, string[] metrics,
                                              NamedValueSet properties, String nameSpace)
        {
            //get the balues reqired from the property bag.
            var valuationId       = new ValuationReportIdentifier(properties);
            var baseParty         = properties.GetString("BaseParty", true);
            var reportingCurrency = properties.GetString("ReportingCurrency", true);

            properties.Set("Function", "ValuationReport");
            properties.Set("Domain", "Orion.ValuationReport");
            //TODO add other properties
            //var fra = Cache.GetTrade(fraId);
            var fra = ProductFactory.GetFpMLFra(fraInputRange);
            //Get the curves and store.
            var marketFactory = new MarketFactory();
            var uniqueCurves  = new List <IRateCurve>();
            //var forwardCurve = (RateCurve)ObjectCacheHelper.GetPricingStructureFromSerialisable(fraInputRange.ForwardCurveId);
            //var discountCurve = (RateCurve)ObjectCacheHelper.GetPricingStructureFromSerialisable(fraInputRange.DiscountingCurveId);
            var market        = CreateMarket(discountCurve, forwardCurve);
            var agreement     = new FraPricer(logger, cache, null, null, fra, nameSpace);
            var modelData     = CreateInstrumentModelData(metrics, fraInputRange.ValuationDate, market, reportingCurrency);
            var asetValuation = agreement.Calculate(modelData);

            //  Add forward yield curve to the market environment ...
            //
            //var forwardCurve = (IRateCurve)ObjectCacheHelper.GetPricingStructureFromSerialisable(fraInputRange.ForwardCurveId);
            uniqueCurves.Add(forwardCurve);
            //  ... if discount curve is not the same as forward curve - add a discount curve too.
            //
            //if (fraInputRange.ForwardCurveId != fraInputRange.DiscountingCurveId)
            //{
            //    var discountingCurve = (IRateCurve)ObjectCacheHelper.GetPricingStructureFromSerialisable(fraInputRange.DiscountingCurveId);
            //    uniqueCurves.Add(discountingCurve);
            //}
            //TODO Add the FX curve if the reporting currency is different.
            foreach (var rateCurve in uniqueCurves)
            {
                // Add all unique curves into market
                //
                Pair <PricingStructure, PricingStructureValuation> pair = rateCurve.GetFpMLData();
                marketFactory.AddPricingStructure(pair);
            }
            var valuation = new Valuation();

            //  create ValuationReport and add it to in-memory collection.
            //
            valuation.CreateFraValuationReport(cache, nameSpace, valuationId.UniqueIdentifier, baseParty, fra, marketFactory.Create(), asetValuation, properties);
            return(valuationId.UniqueIdentifier);
        }
        private void ValueStripMenuItemClick(object sender, EventArgs e)
        {
            var itemToValue = treeNavigation.SelectedNode?.Tag as ICoreItem;

            if (itemToValue == null)
            {
                return;
            }
            var   schema = itemToValue.AppProps.GetValue <string>(TradeProp.Schema, true);
            Trade trade;

            if (schema == FpML5R3NameSpaces.ConfirmationSchema)
            {
                var xml    = itemToValue.Text; //XmlSerializerHelper.SerializeToString(itemToValue.Data);
                var newxml = xml.Replace("FpML-5/confirmation", "FpML-5/reporting");
                trade = XmlSerializerHelper.DeserializeFromString <Trade>(newxml);
            }
            else
            {
                trade = XmlSerializerHelper.DeserializeFromString <Trade>(itemToValue.Text);
            }
            if (trade != null)
            {
                // the item
                var properties        = itemToValue.AppProps;
                var party1            = properties.GetValue <string>(TradeProp.Party1, true);
                var baseParty         = comboBoxParty.Text == party1 ? "Party1" : "Party2";
                var nameSpace         = properties.GetValue <string>(EnvironmentProp.NameSpace, true);
                var valuationDate     = dateTimePickerValuation.Value;
                var market            = comboBoxMarket.Items[comboBoxMarket.SelectedIndex].ToString();
                var reportingCurrency = comboBoxCurrency.Items[comboBoxCurrency.SelectedIndex].ToString();
                //Predefined metrics
                var metrics = new List <string> {
                    "NPV", "Delta0", "Delta1", "LocalCurrencyNPV", "NFV"
                };
                var requestedMetrics = listBoxMetrics.SelectedItems;
                foreach (var metric in requestedMetrics)
                {
                    if (!metrics.Contains(metric.ToString()))
                    {
                        metrics.Add(metric.ToString());
                    }
                }
                var uniqueTradeId = itemToValue.Name;
                var product       = trade.Item;
                try
                {
                    _loggerRef.Target.LogDebug("Valuing the trade: ." + uniqueTradeId);
                    var pricer = new TradePricer(_loggerRef.Target, _client, nameSpace, null, trade, itemToValue.AppProps);
                    //Get the market
                    var marketEnviroment     = CurveEngine.GetMarket(_loggerRef.Target, _client, nameSpace, product, market, reportingCurrency, false);
                    var controller           = TradePricer.CreateInstrumentModelData(metrics, valuationDate, marketEnviroment, reportingCurrency, baseParty);
                    var assetValuationReport = pricer.Price(controller, ValuationReportType.Full);
                    _loggerRef.Target.LogDebug("Valued the trade: ." + uniqueTradeId);
                    var id = uniqueTradeId.Split('.')[uniqueTradeId.Split('.').Length - 1];
                    //Build the val report properties
                    var valProperties = properties.Clone();
                    //Trade type
                    var tradeType = ProductTypeHelper.TradeTypeHelper(product);
                    valProperties.Set(ValueProp.PortfolioId, tradeType + "." + id);
                    valProperties.Set(ValueProp.BaseParty, baseParty);
                    valProperties.Set(ValueProp.MarketName, market);
                    valProperties.Set(ValueProp.CalculationDateTime, valuationDate);
                    valProperties.Set(TradeProp.UniqueIdentifier, null);
                    //The unique identifier for the valuation report
                    var valuationIdentifier = new ValuationReportIdentifier(valProperties);
                    _client.SaveObject(assetValuationReport, nameSpace + "." + valuationIdentifier.UniqueIdentifier, valProperties);
                    _loggerRef.Target.LogDebug("Valued and saved results for the trade: {0}", uniqueTradeId);
                }
                catch (Exception excp)
                {
                    MessageBox.Show(excp.ToString(), Resources.CoreViewerForm_ValueStripMenuItemClick_Value_failed, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }