Exemple #1
0
        /// <summary>
        /// Parses the string info into an asset.
        /// </summary>
        /// <param name="instrumentId"></param>
        /// <param name="value"></param>
        /// <param name="adjustment"></param>
        /// <returns></returns>
        public static Pair <Asset, BasicAssetValuation> Parse(string instrumentId, decimal value, decimal?adjustment)
        {
            const string rateQuotationType       = PriceableSimpleRateAsset.RateQuotationType;
            const string volatilityQuotationType = PriceableCapRateAsset.VolatilityQuotationType;
            Asset        underlyingAsset;
            decimal      additional = 0.0m;

            if (adjustment != null)
            {
                additional = (decimal)adjustment;
            }
            var listBasicQuotations = new List <BasicQuotation>();
            var properties          = new PriceableAssetProperties(instrumentId);

            switch (properties.AssetType)
            {
            //This is in place to handle volatility curves where the tenor is the expiry.
            case AssetTypesEnum.Period:
            {
                //There is no underlying asset.
                underlyingAsset = null;
                listBasicQuotations.Add(BasicQuotationHelper.Create(instrumentId, value, volatilityQuotationType, "LognormalVolatility"));
                break;
            }

            case AssetTypesEnum.ZeroRate:
            {
                underlyingAsset = new Cash {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.Xibor:
            case AssetTypesEnum.OIS:
            {
                underlyingAsset = new RateIndex {
                    id = instrumentId, term = properties.TermTenor
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.IRSwap:
            case AssetTypesEnum.ClearedIRSwap:
            case AssetTypesEnum.OISSwap:
            case AssetTypesEnum.XccySwap:
            case AssetTypesEnum.SimpleIRSwap:
            case AssetTypesEnum.XccyBasisSwap:
            case AssetTypesEnum.BasisSwap:
            case AssetTypesEnum.ResettableXccyBasisSwap:
            {
                underlyingAsset = new SimpleIRSwap {
                    id = instrumentId, term = properties.TermTenor
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.Caplet:
            case AssetTypesEnum.Floorlet:
            case AssetTypesEnum.BillCaplet:
            case AssetTypesEnum.BillFloorlet:
            {
                underlyingAsset = new SimpleFra
                {
                    id        = instrumentId,
                    startTerm = properties.TermTenor,
                    endTerm   = properties.TermTenor.Sum(properties.ForwardIndex)
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, volatilityQuotationType, "LognormalVolatility"));
                if (adjustment != null)
                {
                    listBasicQuotations.Add(BasicQuotationHelper.Create(additional, "Strike", "DecimalRate"));
                }
                break;
            }

            case AssetTypesEnum.Deposit:
            case AssetTypesEnum.SpreadDeposit:
            case AssetTypesEnum.XccyDepo:
            case AssetTypesEnum.BankBill:
            case AssetTypesEnum.Repo:
            case AssetTypesEnum.RepoSpread:
            {
                underlyingAsset = new Deposit {
                    id = instrumentId, term = properties.TermTenor
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.SimpleFra:
            case AssetTypesEnum.Fra:
            case AssetTypesEnum.BillFra:
            case AssetTypesEnum.SpreadFra:
            {
                underlyingAsset = new SimpleFra
                {
                    id        = instrumentId,
                    startTerm = properties.TermTenor,
                    endTerm   = properties.TermTenor.Sum(properties.ForwardIndex)      //TODO this restricts the perios to be the same!!!
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.Swaption:
            {
                underlyingAsset = new SimpleIRSwap {
                    id = instrumentId, term = properties.TermTenor
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, volatilityQuotationType, "LognormalVolatility"));
                if (adjustment != null)
                {
                    listBasicQuotations.Add(BasicQuotationHelper.Create(additional, "Strike", "DecimalRate"));
                }
                break;
            }

            case AssetTypesEnum.IRFloor:
            case AssetTypesEnum.IRCap:
            {
                underlyingAsset = new SimpleIRSwap {
                    id = instrumentId, term = properties.TermTenor
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, volatilityQuotationType, "LognormalVolatility"));
                if (adjustment != null)
                {
                    listBasicQuotations.Add(BasicQuotationHelper.Create(additional, "Strike", "DecimalRate"));
                }
                break;
            }

            case AssetTypesEnum.IRFutureOption:
            case AssetTypesEnum.IRCallFutureOption:
            case AssetTypesEnum.IRPutFutureOption:
            {
                underlyingAsset = new Future {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, volatilityQuotationType, "LognormalVolatility"));
                if (adjustment != null)
                {
                    listBasicQuotations.Add(BasicQuotationHelper.Create(additional, "Strike", "DecimalRate"));
                }
                break;
            }

            case AssetTypesEnum.IRFuture:
            {
                underlyingAsset = new Future {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DecimalRate"));
                if (adjustment != null)
                {
                    listBasicQuotations.Add(BasicQuotationHelper.Create(additional, "Volatility", "LognormalVolatility"));
                }
                break;
            }

            case AssetTypesEnum.CommodityFuture:
            case AssetTypesEnum.CommodityFutureSpread:
            {
                underlyingAsset = new Future {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.CPIndex:
            {
                underlyingAsset = new RateIndex {
                    id = instrumentId, term = properties.TermTenor
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.SimpleCPISwap:
            case AssetTypesEnum.CPISwap:
            case AssetTypesEnum.ZCCPISwap:
            {
                underlyingAsset = new SimpleIRSwap {
                    id = instrumentId, term = properties.TermTenor
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "DecimalRate"));
                break;
            }

            case AssetTypesEnum.FxSpot:
            case AssetTypesEnum.FxForward:
            {
                underlyingAsset = new FxRateAsset {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "FxRate"));
                break;
            }

            case AssetTypesEnum.Equity:
            case AssetTypesEnum.EquityForward:
            {
                underlyingAsset = new EquityAsset {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "Price"));
                break;
            }

            case AssetTypesEnum.CommoditySpot:
            case AssetTypesEnum.CommodityForward:
            case AssetTypesEnum.CommodityAverageForward:
            case AssetTypesEnum.CommoditySpread:
            {
                underlyingAsset = new Commodity {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "Price"));
                break;
            }

            case AssetTypesEnum.Bond:
            case AssetTypesEnum.BondSpot:
            case AssetTypesEnum.BondForward:
            {
                underlyingAsset = new Bond {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value, rateQuotationType, "DecimalRate"));        //Changed from DirtyPrice.
                break;
            }

            case AssetTypesEnum.Lease:
            {
                underlyingAsset = new Lease {
                    id = instrumentId
                };
                listBasicQuotations.Add(BasicQuotationHelper.Create(value + additional, rateQuotationType, "Price"));
                break;
            }

            default:
                throw new NotSupportedException($"Asset type {properties.AssetType} is not supported");
            }
            var id = underlyingAsset?.id;

            if (underlyingAsset == null)
            {
                id = listBasicQuotations[0].id;
            }
            return(new Pair <Asset, BasicAssetValuation>(underlyingAsset, BasicAssetValuationHelper.Create(id, listBasicQuotations.ToArray())));
        }
        /// <summary>
        /// Gets the instrument config data.
        /// </summary>
        /// <param name="cache">The cache.</param>
        /// <param name="nameSpace">The client namespace</param>
        /// <param name="parts">The AssetId or the parts of the AssetId.</param>
        /// <returns></returns>
        public static Instrument GetInstrumentConfigurationData(ICoreCache cache, string nameSpace, params string[] parts)
        {
            bool simplifiable = true;

            if (parts.Length == 1)
            {
                parts = parts[0].Split('-');
            }
            string     uniqueName;
            var        assetType            = (AssetTypesEnum)Enum.Parse(typeof(AssetTypesEnum), parts[1], true);
            var        swapTypes            = new[] { AssetTypesEnum.IRSwap, AssetTypesEnum.BasisSwap, AssetTypesEnum.XccyBasisSwap, AssetTypesEnum.XccySwap };
            var        fxTypes              = new[] { AssetTypesEnum.FxSpot, AssetTypesEnum.FxForward };
            var        bondTypes            = new[] { AssetTypesEnum.Bond };
            var        commodityTypes       = new[] { AssetTypesEnum.CommoditySpread, AssetTypesEnum.CommodityForward };
            var        equityTypes          = new[] { AssetTypesEnum.Equity, AssetTypesEnum.EquityForward, AssetTypesEnum.EquitySpread };
            var        irfuturesOptionTypes = new[] { AssetTypesEnum.IRFutureOption, AssetTypesEnum.IRCallFutureOption, AssetTypesEnum.IRPutFutureOption };
            var        otherTypes           = new[] { AssetTypesEnum.BondForward, AssetTypesEnum.BondSpot };
            ICoreItem  loadedItem;
            Instrument instrument;
            string     exchangeMIC = null;

            if (swapTypes.Contains(assetType) && parts.Length > 3)
            {
                uniqueName = CreateKey(nameSpace, parts[1], parts[0], parts[2], parts[3]);
            }
            else if (irfuturesOptionTypes.Contains(assetType) && parts.Length > 2)
            {
                uniqueName = CreateKey(nameSpace, AssetTypesEnum.IRFutureOption.ToString(), parts[0], parts[2]);
            }
            else if (commodityTypes.Contains(assetType) && parts.Length > 3)
            {
                uniqueName = CreateKey(nameSpace, parts[1], parts[0], parts[2], parts[3]);
            }
            else if (fxTypes.Contains(assetType))
            {
                return(GetFxInstrumentConfigurationData(cache, nameSpace, parts));
            }
            else if (bondTypes.Contains(assetType) && parts[2].Split('.').Length > 4)
            {
                uniqueName = CreateBondKey(nameSpace, parts[2]);
                var extraData = cache.LoadItem <Bond>(uniqueName);
                var bondType  = extraData.AppProps.GetValue <string>(BondProp.BondType, true);
                uniqueName = CreateKey(nameSpace, parts[1], parts[0], bondType);
                loadedItem = cache.LoadItem <Instrument>(uniqueName);
                instrument = loadedItem.Data as Instrument;
                if (instrument != null)
                {
                    var newInstrument = XmlSerializerHelper.Clone(instrument);
                    ((BondNodeStruct)newInstrument.InstrumentNodeItem).Bond = extraData.Data as Bond;
                    return(newInstrument);
                }
            }
            else if (equityTypes.Contains(assetType))
            {
                var         assetCode   = parts[2].Split('.');
                EquityAsset equityAsset = null;
                if (assetCode.Length == 2)
                {
                    uniqueName = CreateEquityAssetKey(nameSpace, parts[2]);
                    var equity = cache.LoadItem <EquityAsset>(uniqueName);
                    exchangeMIC = equity.AppProps.GetValue <string>(EquityProp.ExchangeMIC, true);
                    equityAsset = equity.Data as EquityAsset;
                }
                if (assetCode.Length == 1)
                {
                    exchangeMIC = assetCode[0];
                }
                uniqueName = CreateEquityExchangeKey(nameSpace, exchangeMIC);
                loadedItem = cache.LoadItem <ExchangeConfigData>(uniqueName);
                if (assetType == AssetTypesEnum.Equity && loadedItem.Data is ExchangeConfigData exchange)
                {
                    instrument = new Instrument();
                    var equityNode = new EquityNodeStruct
                    {
                        Equity         = equityAsset,
                        Exchange       = exchange.ExchangeData,
                        SettlementDate = exchange.SettlementDate
                    };
                    instrument.AssetType          = parts[1];
                    instrument.InstrumentNodeItem = equityNode;
                    instrument.Currency           = CurrencyHelper.Parse(parts[0]);
                    instrument.ExtraItem          = equityNode.Exchange.MIC;
                    return(instrument);
                }
                if (parts.Length > 3)
                {
                    uniqueName = CreateKey(nameSpace, parts[1], parts[0], exchangeMIC, parts[3]);
                }
                else
                {
                    uniqueName   = CreateKey(nameSpace, parts[1], parts[0], exchangeMIC);
                    simplifiable = false;
                }
            }
            else if (otherTypes.Contains(assetType) && parts.Length > 3)
            {
                //This is to simplify the configuration data and no bond forward is required
                uniqueName = CreateKey(nameSpace, parts[1], parts[0], parts[2], parts[3]);
            }
            //Default Area that sweeps all the standard keys structures.
            else if (parts.Length > 2)
            {
                uniqueName = CreateKey(nameSpace, parts[1], parts[0], parts[2]);
            }
            else
            {
                uniqueName   = CreateKey(nameSpace, parts[1], parts[0]);
                simplifiable = false;
            }
            loadedItem = cache.LoadItem <Instrument>(uniqueName);
            if (loadedItem == null && simplifiable)
            {
                if (swapTypes.Contains(assetType) && parts.Length > 3)
                {
                    //This handles the special case of IRSwaps, where the underlying maturity should use the default.
                    uniqueName = CreateKey(nameSpace, parts[1], parts[0], "Default", parts[3]);
                }
                else if (commodityTypes.Contains(assetType) && parts.Length > 3)
                {
                    uniqueName = CreateKey(nameSpace, parts[1], parts[0], parts[2]);
                }
                else if (equityTypes.Contains(assetType) && parts.Length > 3)
                {
                    //Orion.V5r3.Configuration.Instrument.EquityForward.AUD-EquityForward.AU.0D
                    uniqueName = CreateKey(nameSpace, parts[1], parts[0], exchangeMIC);
                }
                else if (otherTypes.Contains(assetType))
                {
                    //This is to simplify the configuration data and no bond forward is required
                    uniqueName = CreateKey(nameSpace, AssetTypesEnum.Bond.ToString(), parts[0], parts[2]);
                }
                else
                {
                    uniqueName = CreateKey(nameSpace, parts[1], parts[0]);
                }
                loadedItem = cache.LoadItem <Instrument>(uniqueName);
            }
            instrument = loadedItem?.Data as Instrument;
            return(instrument);
        }
Exemple #3
0
        /// <summary>
        /// Parses the string info into an asset.
        /// </summary>
        /// <param name="instrumentId"></param>
        /// <returns></returns>
        public static Asset Parse(string instrumentId)
        {
            Asset underlyingAsset;
            var   properties = new PriceableAssetProperties(instrumentId);

            switch (properties.AssetType)
            {
            case AssetTypesEnum.ZeroRate:
            {
                var zeroRate = new Cash {
                    id = instrumentId
                };
                underlyingAsset = zeroRate;
                break;
            }

            case AssetTypesEnum.Xibor:
            case AssetTypesEnum.OIS:
            {
                var rateIndex = new RateIndex {
                    id = instrumentId, term = properties.TermTenor
                };
                underlyingAsset = rateIndex;
                break;
            }

            case AssetTypesEnum.IRSwap:
            case AssetTypesEnum.ClearedIRSwap:
            case AssetTypesEnum.OISSwap:
            case AssetTypesEnum.XccySwap:
            case AssetTypesEnum.SimpleIRSwap:
            case AssetTypesEnum.XccyBasisSwap:
            case AssetTypesEnum.BasisSwap:
            case AssetTypesEnum.ResettableXccyBasisSwap:
            {
                var simpleIRSwap = new SimpleIRSwap {
                    id = instrumentId, term = properties.TermTenor
                };
                underlyingAsset = simpleIRSwap;
                break;
            }

            case AssetTypesEnum.Deposit:
            case AssetTypesEnum.SpreadDeposit:
            case AssetTypesEnum.XccyDepo:
            case AssetTypesEnum.BankBill:
            case AssetTypesEnum.Repo:
            case AssetTypesEnum.RepoSpread:
            {
                var deposit = new Deposit {
                    id = instrumentId, term = properties.TermTenor
                };
                underlyingAsset = deposit;
                break;
            }

            case AssetTypesEnum.SimpleFra:
            case AssetTypesEnum.Fra:
            case AssetTypesEnum.BillFra:
            case AssetTypesEnum.SpreadFra:
            {
                var simpleFra = new SimpleFra {
                    id = instrumentId, startTerm = properties.TermTenor
                };
                if (properties.ForwardIndex == null)
                {
                    throw new ArgumentException("ForwardIndex must be set in the instrumentId " + instrumentId,
                                                nameof(instrumentId));
                }
                simpleFra.endTerm = simpleFra.startTerm.Sum(properties.ForwardIndex);
                underlyingAsset   = simpleFra;
                break;
            }

            case AssetTypesEnum.IRFloor:
            case AssetTypesEnum.IRCap:
            {
                var simpleIRCap = new SimpleIRSwap {
                    id = instrumentId, term = properties.TermTenor
                };
                underlyingAsset = simpleIRCap;
                break;
            }

            case AssetTypesEnum.IRFutureOption:
            case AssetTypesEnum.IRFuture:
            {
                var future = new Future {
                    id = instrumentId
                };
                underlyingAsset = future;
                break;
            }

            case AssetTypesEnum.CommodityFuture:
            case AssetTypesEnum.CommodityFutureSpread:
            {
                var future = new Future {
                    id = instrumentId
                };
                underlyingAsset = future;
                break;
            }

            case AssetTypesEnum.CPIndex:
            {
                var rateIndex = new RateIndex {
                    id = instrumentId, term = properties.TermTenor
                };
                underlyingAsset = rateIndex;
                break;
            }

            case AssetTypesEnum.SimpleCPISwap:
            case AssetTypesEnum.CPISwap:
            case AssetTypesEnum.ZCCPISwap:
            {
                var simpleIRSwap = new SimpleIRSwap {
                    id = instrumentId, term = properties.TermTenor
                };
                underlyingAsset = simpleIRSwap;
                break;
            }

            case AssetTypesEnum.Equity:
            case AssetTypesEnum.EquityForward:
            {
                //  var tenor = results[2];
                var equityAsset = new EquityAsset {
                    id = instrumentId
                };
                underlyingAsset = equityAsset;
                break;
            }

            case AssetTypesEnum.FxSpot:
            case AssetTypesEnum.FxForward:
            {
                //  var tenor = results[2];
                var fxRateAsset = new FxRateAsset {
                    id = instrumentId
                };
                underlyingAsset = fxRateAsset;
                break;
            }

            case AssetTypesEnum.CommoditySpot:
            case AssetTypesEnum.CommodityForward:
            case AssetTypesEnum.CommodityAverageForward:
            case AssetTypesEnum.CommoditySpread:
            {
                var commodityAsset = new Commodity {
                    id = instrumentId
                };
                underlyingAsset = commodityAsset;
                break;
            }

            case AssetTypesEnum.Bond:
            case AssetTypesEnum.BondSpot:
            case AssetTypesEnum.BondForward:
            {
                var bond = new Bond {
                    id = instrumentId
                };
                underlyingAsset = bond;
                break;
            }

            default:
                throw new NotSupportedException($"Asset type {properties.AssetType} is not supported");
            }
            return(underlyingAsset);
        }