Exemplo n.º 1
0
        private System.Func <double, double> getPriceFunction(int index, ResolvedCdsTrade cds, double flactionalSpread, double pointsUpfront, LocalDate valuationDate, NodalCurve creditCurve, CreditDiscountFactors discountFactors, RecoveryRates recoveryRates, ReferenceData refData)
        {
            ResolvedCds cdsProduct                 = cds.Product;
            Currency    currency                   = cdsProduct.Currency;
            StandardId  legalEntityId              = cdsProduct.LegalEntityId;
            Pair <StandardId, Currency>  pair      = Pair.of(legalEntityId, currency);
            ImmutableCreditRatesProvider ratesbase = ImmutableCreditRatesProvider.builder().valuationDate(valuationDate).discountCurves(ImmutableMap.of(currency, discountFactors)).recoveryRateCurves(ImmutableMap.of(legalEntityId, recoveryRates)).build();

            System.Func <double, double> func = (double?x) =>
            {
                NodalCurve tempCreditCurve         = creditCurve.withParameter(index, x.Value);
                ImmutableCreditRatesProvider rates = ratesbase.toBuilder().creditCurves(ImmutableMap.of(pair, LegalEntitySurvivalProbabilities.of(legalEntityId, IsdaCreditDiscountFactors.of(currency, valuationDate, tempCreditCurve)))).build();
                double price = TradePricer.price(cds, rates, flactionalSpread, PriceType.CLEAN, refData);
                return(price - pointsUpfront);
            };
            return(func);
        }
Exemplo n.º 2
0
        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);
                }
            }
        }