public void TestServiceConnection()
        {          
            var issues = "T";
            var identifierType = "MLPTicker";
            var criteriaType = "Term";
            var criteriaValue = string.Empty;

            var liveAsOfDate = DateTime.Today.AddDays(30);
            var moniker = new Moniker
               {
                   Close = Moniker.sStatic,
                   Source = Moniker.sOfficial,
                   Date = liveAsOfDate == DateTime.FromOADate(0) ? null : (DateTime?)liveAsOfDate,
                   Name = String.Format("{0}|{1}|{2}|{3}", issues.Trim(), identifierType.Trim(),
                   string.IsNullOrWhiteSpace(criteriaType) ? String.Empty : criteriaType.Trim().ToLower(),
                   string.IsNullOrWhiteSpace(criteriaValue) ? String.Empty : criteriaValue.Trim().ToLower()),
                   Type = "bondlist"
               };

            var symwcfClient = setupServiceClient();
            var symObject = symwcfClient.GetSingleObject(moniker.ToString());

            GenericTable result = symObject.Xml.DeserializeObject<GenericTable>();
            
            ((IClientChannel)symwcfClient).Close();
        }
 public GenericPrice Calculate(string curveName, DateTime valueDate, DateTime startDate, DateTime endDate)
 {
     SLog.log.DebugFormat("Calculating curve point on curve {0} at {1}: from {2} to {3}", curveName, valueDate, startDate, endDate);
     var curveMoniker = new Moniker
     {
         Close = "mlp",
         Date = valueDate,
         Name = curveName,
         Source = "mlp",
         Type = typeof(DiscountCurve).Name
     };
     var discountCurve = SObjectManager.Instance().LoadSObject<DiscountCurve>(curveMoniker);
     if(discountCurve != null)
     {
         KnownCurve knownCurve = KnownCurveHelpers.RecognizeCurveCode(curveName);
         double rate = double.NaN;
         switch(knownCurve)
         {
             case KnownCurve.USD3mLibor:
             case KnownCurve.USD3mLiborOISD:
                 rate = aaParSwapWrapper.CalculateUSD3mLiborSwapRate(discountCurve.AsDoubleArray(), startDate, valueDate, endDate, "USA_FI");
                 break;
             case KnownCurve.USDFedFunds:
                 rate = aaParSwapWrapper.CalculateUSDOISSwapRate(discountCurve.AsDoubleArray(), startDate, valueDate, endDate, "USA_FI");
                 break;
             case KnownCurve.EUR6mEuribor:
             case KnownCurve.EUR6mEuriborOISD:
                 rate = aaParSwapWrapper.CalculateEUR6mEuriborSwapRate(discountCurve.AsDoubleArray(), startDate, valueDate, endDate, "FR_FI");
                 break;
             case KnownCurve.EUREonia:
                 rate = aaParSwapWrapper.CalculateEUROISSwapRate(discountCurve.AsDoubleArray(), startDate, valueDate, endDate, "FR_FI");
                 break;
             case KnownCurve.GBP6mLibor:
             case KnownCurve.GBP6mLiborOISD:
                 rate = aaParSwapWrapper.CalculateGBP6mLiborSwapRate(discountCurve.AsDoubleArray(), startDate, valueDate, endDate, "LN_FI");
                 break;
             case KnownCurve.GBPSonia:
                 rate = aaParSwapWrapper.CalculateGBPOISSwapRate(discountCurve.AsDoubleArray(), startDate, valueDate, endDate, "LN_FI");
                 break;
             case KnownCurve.NotSet:
                 SLog.log.ErrorFormat("Curve point calculation not supported for {0}", curveName);
                 return null;
         }                
         if (!double.IsNaN(rate))
         {
             return new GenericPrice { Price = rate };
         }
     }
     else
     {
         SLog.log.WarnFormat("Error calculating curve point - discount curve {0} not found", curveName);
     }
     return null;
 }
        public void ShouldGetSingleSecurityMetadata()
        {
            var instrument = "T 0.375 02/15/2016"; 

            var liveAsOfDate = DateTime.Today.AddDays(30);
            var moniker = new Moniker
            {
                Close = Moniker.sStatic,
                Source = Moniker.sOfficial,
                Date = null,
                Name = instrument.Trim(),
                Type = "bondstatic"
            };

            var symwcfClient = setupServiceClient();
            var symObject = symwcfClient.GetSingleObject(moniker.ToString());

            var result = symObject.Xml.DeserializeObject<BondStatic>();

            ((IClientChannel)symwcfClient).Close();
        }
Beispiel #4
0
        //----------------------------------------------------------------------------------------
        public static BondStatic GetBondStatic(string bondID)
        //----------------------------------------------------------------------------------------
        {
            Log_.InfoFormat("Getting bond static for {0}", bondID);

            if (bondStaticCache.ContainsKey(bondID))
                return bondStaticCache[bondID];


            BondStatic instrumentStatic = new BondStatic();
            int MAX_RETRIES = 5;
            int retries = 0;
            for (retries = 0; retries < MAX_RETRIES; ++retries)
            {
                try
                {
                    var moniker = new Moniker
                    {
                        Close = Moniker.sStatic,
                        Source = Moniker.sOfficial,
                        Date = null,
                        Name = bondID.Trim(),
                        Type = "bondstatic"
                    };

                    var symmetryServiceClient = GetSymmetryServiceClient();
                    var resultObj = symmetryServiceClient.GetSingleObject(moniker.ToString());
                    instrumentStatic = resultObj.Xml.DeserializeObject<BondStatic>();
                    break;
                }
                catch (Exception e)
                {
                    Log_.WarnFormat("Attempt" + retries.ToString() + " - Error in setting static for " +bondID + ": " + e.Message);
                    Thread.Sleep(200); // Wait for 2 seconds first before trying again
                }
            }

            if (retries == MAX_RETRIES)
            {
                throw new TimeoutException("Max retries reach " + MAX_RETRIES + ". Giving up on pulling bond static");
            }

            // Set cache
            bondStaticCache[bondID] = instrumentStatic;

            return instrumentStatic;
        }
Beispiel #5
0
        //----------------------------------------------------------------------------------------
        public static List<string> GetAllSecurities(string issues, string criteriaType, DateTime asOfDate)
        //----------------------------------------------------------------------------------------
        {
            try
            {
                //var issues = "T";
                var identifierType = "MLPTicker";
                //var criteriaType = "Term";
                var criteriaValue = string.Empty;

                var moniker = new Moniker
                {
                    Close = Moniker.sStatic,
                    Source = Moniker.sOfficial,
                    Date = asOfDate == DateTime.FromOADate(0) ? null : (DateTime?) asOfDate,
                    Name = String.Format("{0}|{1}|{2}|{3}", issues.Trim(), identifierType.Trim(),
                        string.IsNullOrWhiteSpace(criteriaType) ? String.Empty : criteriaType.Trim().ToLower(),
                        string.IsNullOrWhiteSpace(criteriaValue) ? String.Empty : criteriaValue.Trim().ToLower()),
                    Type = "bondlist"
                };

                // go to symmetry service
                //var symmetryServiceClient = new SymmetryServiceClient();
                var resultObj = symmetryServiceClient.GetSingleObject(moniker.ToString());
                GenericTable result = resultObj.Xml.DeserializeObject<GenericTable>();


                var allBondMatrix = result.Table.AsStringArray();

                List<string> bonds = new List<string>();

                for (int i = 0; i < allBondMatrix.GetLength(0); i++)
                {
                    bonds.Add( allBondMatrix[i, 0]);
                }
                return bonds;
            }
            catch (Exception e)
            {
                Log_.ErrorFormat("Error found in loading all issues : {0}", e.Message);
                throw e;
            }
        }
Beispiel #6
0
        //----------------------------------------------------------------------------------------
        public static GenericPrice GetHistoryPrice( string inst, 
                                                    DateTime asof, 
                                                    string closeSnap, 
                                                    string source  )
        //----------------------------------------------------------------------------------------
        {
            
            try
            {
                var moniker = new Moniker
                {
                    Type = "genericprice",
                    Close = closeSnap,
                    Source = source,
                    Date = asof,
                    Name = inst.ToLower().Trim()
                };

                // go to symmetry service
                //var symmetryServiceClient = new SymmetryServiceClient();
                var resultObj = symmetryServiceClient.GetSingleObject(moniker.ToString());
                GenericPrice result = null;
                if (!string.IsNullOrEmpty(resultObj.Xml))
                    result = resultObj.Xml.DeserializeObject<GenericPrice>();
                return result;
            }
            catch (Exception)
            {
                Log_.ErrorFormat("Can't find {0}, for {1} {2} at {3}", inst, source, closeSnap, asof.ToString() );
            }

            return null;

        }
        public GenericTable Calculate(Moniker moniker, DateTime? valueDate)
        {
            string[] tokens = moniker.Name.Split('|');
            if(tokens.Length != 4)
            {
                return null;
            }

            string markets = tokens[0];
            string ids = tokens[1];
            string criteriaType = tokens[2];
            string criteriaValue = tokens[3];

            if(string.IsNullOrWhiteSpace(markets) || string.IsNullOrWhiteSpace(ids))
            {
                return null;
            }
            
            SLog.log.DebugFormat("Calculating bond list for markets {0}", markets);
            try
            {
                using (var dc = SymmetryDataSource.ReadOnly())
                {
                    var lists = new List<List<object>>();
                    string[] marketTokens = markets.Split(',');

                    foreach(var market in marketTokens)
                    {
                        var mkt = market.Trim().ToUpper();
                        if(mkt == "T")
                        {
                            mkt = "UST";
                        }
                        if (mkt == "USTPRIN")
                        {
                            mkt = "USTSTR";
                        }
                        if(!string.IsNullOrWhiteSpace(mkt))
                        {
                            bool firstCall = true;
                            var sw = Stopwatch.StartNew();
                            foreach(var bond in FIBondHelpers.GetBondsByMarket(mkt, dc))
                            {
                                if (firstCall)
                                {
                                    SLog.log.DebugFormat("## GetBondsByMarket results for {0} back in {1} ms.", mkt, sw.ElapsedMilliseconds);
                                    firstCall = false;
                                }

                                // work out inclusions first
                                if(!ShouldInclude(bond, valueDate, criteriaType, criteriaValue))
                                {
                                    continue;
                                }

                                string id = String.Empty;
                                IdentifierType idType = IdentifierType.SymmetryCode;
                                switch(ids.ToUpper())
                                {
                                    case "ISIN":
                                        idType = IdentifierType.ISIN;
                                        break;
                                    case "CUSIP":
                                        idType = IdentifierType.CUSIP;
                                        break;
                                    case "BLOOMBERG":
                                        idType = IdentifierType.Bloomberg;
                                        break;
                                    case "MLPTICKER":
                                        idType = IdentifierType.MLPCode;
                                        break;
                                    case "FIID":
                                        id = bond.FIID.ToString();
                                        break;
                                }
                                //var sw2 = Stopwatch.StartNew();
                                var allIds = FIHelpers.GetAllIdentifiers(bond.FI, dc);
                                //SLog.log.DebugFormat("## Get all IDs took {0} ms.", sw2.ElapsedMilliseconds);
                                if (allIds.ContainsKey(idType))
                                {
                                    id = allIds[idType];
                                }
                                if (!string.IsNullOrWhiteSpace(id))
                                {
                                    lists.Add(new List<object> { id });
                                }
                            }
                        }
                    }

                    return new GenericTable { Table = new FinCADTable(lists) };
                }
            } catch(Exception ex)
            {
                SLog.log.Error("Error calculating bond list for markets " + markets, ex);
            }
            return null;
        }
Beispiel #8
0
 public static Moniker FromString(string moniker, ThrowBehavior behavior = ThrowBehavior.Throw)
 {
     try
     {
         if (!string.IsNullOrWhiteSpace(moniker) && moniker.Contains(sSeparator))
         {
             string[] tokens = moniker.Trim().ToLower().Split(sSeparator);
             if (tokens.Length != 5)
             {
                 if (behavior == ThrowBehavior.DontThrow)
                 {
                     return null;
                 }
                 throw new Exception("Unable to parse moniker " + moniker);
             }
             var newMoniker = new Moniker
             {
                 Type = tokens[0].Trim(),
                 Name = tokens[1].Trim(),
                 Source = tokens[2].Trim(),
                 Close = tokens[3].Trim(),
                 Date = null
             };
             if (!string.IsNullOrWhiteSpace(tokens[4]))
             {
                 if (tokens[4] == sLatest)
                 {
                     newMoniker.Date = null;
                 }
                 else
                 {
                     DateTime valueDate;
                     if (!DateTime.TryParseExact(tokens[4], "yyyyMMdd", CultureInfo.InvariantCulture, DateTimeStyles.None, out valueDate))
                     {
                         if (behavior == ThrowBehavior.DontThrow)
                         {
                             return null;
                         }
                         throw new Exception("Unable to parse date in moniker " + moniker);
                     }
                     newMoniker.Date = valueDate;
                 }
                 return newMoniker;
             }
         }
     } catch(Exception ex)
     {
         Exceptions.Rethrow("Error parsing moniker " + moniker, behavior, ex);
     }
     return null;
 }