Пример #1
0
        public CoveragesDto SaveCoverage(CoveragesDto coverage)
        {
            using (var db = new GapInsuranceDBModel())
            {
                Coverages dbCoverage;

                if (coverage.Id > 0)
                {
                    dbCoverage = db.Coverages.FirstOrDefault(x => x.Id == coverage.Id);

                    if (dbCoverage == null)
                    {
                        throw new KeyNotFoundException("Coverage doesn't exists");
                    }
                }
                else
                {
                    dbCoverage = new Coverages();
                    db.Coverages.Add(dbCoverage);
                }

                dbCoverage.Name = coverage.Name;

                db.SaveChanges();

                return(Mapper.Map <Coverages, CoveragesDto>(dbCoverage));
            }
        }
Пример #2
0
        private void GenerateSchedule(DateTime asOf, DateTime startDate, DateTime endDate, DayCount dayCount, DayRule dayRule, CurveTenor tenor, StubPlacement stub = StubPlacement.NullStub)
        {
            // This only works for short stubs atm, although NullStub will generate a long stub

            DateTime AdjStart = DateHandling.AdjustDate(startDate, dayRule);
            DateTime AdjEnd   = DateHandling.AdjustDate(endDate, dayRule);

            string tenorString = EnumToStr.CurveTenor(tenor);
            string TenorLetter = DateHandling.GetTenorLetterFromTenor(tenorString);
            double TenorNumber = DateHandling.GetTenorNumberFromTenor(tenorString);


            int periods = CalculatePeriods(startDate, endDate, tenor);

            // Create estimate of how long the schedule should be
            //double YearsUpper = DateHandling.Cvg(AdjStart, AdjEnd, dayCount);
            //double YearLower = DateHandling.Cvg(AsOf, AdjStart, dayCount);


            // Will be sorted at end (when coverages are also calculated)
            UnAdjStartDates.Add(StartDate);
            UnAdjEndDates.Add(EndDate);
            AdjStartDates.Add(AdjStart);
            AdjEndDates.Add(AdjEnd);

            //if (StrToEnum.ConvertTenorLetter(TenorLetter) == Tenor.M)
            //{
            //    periods = periodsInMonths / (int)TenorNumber;

            //    //WholePeriods = periodsInMonths / (int) TenorNumber;
            //    //double tempPeriods = YearsUpper * 12 / TenorNumber;
            //    //WholePeriods = (int)Math.Truncate(tempPeriods);
            //}
            //else if (StrToEnum.ConvertTenorLetter(TenorLetter) == Tenor.Y)
            //{
            //    periods = periodsInMonths / (12 * (int)TenorNumber);

            //    //WholePeriods = (int) Math.Truncate(YearsUpper);
            //}
            //else
            //{
            //    throw new ArgumentException("Can only roll out swap calender for month and year tenors");
            //}

            if (stub == StubPlacement.Beginning)
            {
                periods += 1 * 12 / (int)Math.Round(TenorNumber);
                for (int i = 1; i < periods; i++)
                {
                    UnAdjEndDates.Add(DateHandling.AddTenorAdjust(UnAdjEndDates[i - 1], "-" + tenorString));
                    AdjEndDates.Add(DateHandling.AdjustDate(UnAdjEndDates[i], DayRule));
                    UnAdjStartDates.Add(UnAdjEndDates[i]);
                    AdjStartDates.Add(DateHandling.AdjustDate(UnAdjStartDates[i], DayRule));
                }
            }
            else if (stub == StubPlacement.End)
            {
                periods += 1 * 12 / (int)Math.Round(TenorNumber);
                for (int i = 1; i < periods; i++)
                {
                    UnAdjStartDates.Add(DateHandling.AddTenorAdjust(UnAdjStartDates[i - 1], tenorString));
                    AdjStartDates.Add(DateHandling.AdjustDate(UnAdjStartDates[i], DayRule));
                    UnAdjEndDates.Add(UnAdjStartDates[i]);
                    AdjEndDates.Add(DateHandling.AdjustDate(UnAdjEndDates[i], DayRule));
                }
            }
            else if (stub == StubPlacement.NullStub)
            {
                for (int i = 1; i < periods; i++)
                {
                    UnAdjEndDates.Add(DateHandling.AddTenorAdjust(UnAdjEndDates[i - 1], "-" + tenorString));
                    AdjEndDates.Add(DateHandling.AdjustDate(UnAdjEndDates[i], DayRule));
                    UnAdjStartDates.Add(UnAdjEndDates[i]);
                    AdjStartDates.Add(DateHandling.AdjustDate(UnAdjStartDates[i], DayRule));
                }
            }
            // Sort dates according to date
            UnAdjStartDates.Sort(new Comparison <DateTime>((x, y) => x.CompareTo(y)));
            UnAdjEndDates.Sort(new Comparison <DateTime>((x, y) => x.CompareTo(y)));
            AdjStartDates.Sort(new Comparison <DateTime>((x, y) => x.CompareTo(y)));
            AdjEndDates.Sort(new Comparison <DateTime>((x, y) => x.CompareTo(y)));


            for (int i = 0; i < AdjStartDates.Count; i++)
            {
                Coverages.Add(DateHandling.Cvg(AdjStartDates[i], AdjEndDates[i], DayCount));
            }
        }
Пример #3
0
        static void Main(string[] args)
        {
            // Configure API key authorization: app_id
            Configuration.Default.ApiKey.Add("X-AYLIEN-NewsAPI-Application-ID", "{{current_app_id}}");

            // Configure API key authorization: app_key
            Configuration.Default.ApiKey.Add("X-AYLIEN-NewsAPI-Application-Key", "{{current_app_key}}");

            var apiInstance = new DefaultApi();

            var id = new List <long?>()
            {
                54121
            };
            var notId = new List <long?>()
            {
                21451
            };
            var title    = "startup AND (raise OR raised OR raising OR raises)";
            var body     = "startup";
            var text     = "startup company";
            var language = new List <string>()
            {
                "en", "it"
            };
            var notLanguage = new List <string>()
            {
                "es", "pt"
            };
            var publishedAtStart    = "NOW-10DAYS";
            var publishedAtEnd      = "NOW";
            var categoriesTaxonomy  = "iab-qag";
            var categoriesConfident = true;
            var categoriesId        = new List <string>()
            {
                "IAB15"
            };
            var notCategoriesId = new List <string>()
            {
                "IAB2-3"
            };
            var categoriesLevel = new List <int?>()
            {
                1
            };
            var notCategoriesLevel = new List <int?>()
            {
                2
            };
            var entitiesTitleText = new List <string>()
            {
                "GNU/Linux", "Microsoft"
            };
            var notEntitiesTitleText = new List <string>()
            {
                "Windows"
            };
            var entitiesTitleType = new List <string>()
            {
                "Organization", "Software"
            };
            var notEntitiesTitleType = new List <string>()
            {
                "Person", "Agent"
            };
            var entitiesTitleLinksDbpedia = new List <string>()
            {
                "http://dbpedia.org/resource/Donald_Trump"
            };
            var notEntitiesTitleLinksDbpedia = new List <string>()
            {
                "http://dbpedia.org/resource/Linux"
            };
            var entitiesBodyText = new List <string>()
            {
                "GNU/Linux", "Apple"
            };
            var notEntitiesBodyText = new List <string>()
            {
                "Windows"
            };
            var entitiesBodyType = new List <string>()
            {
                "Person", "Agent"
            };
            var notEntitiesBodyType = new List <string>()
            {
                "Organization", "Software"
            };
            var entitiesBodyLinksDbpedia = new List <string>()
            {
                "http://dbpedia.org/resource/Windows"
            };
            var notEntitiesBodyLinksDbpedia = new List <string>()
            {
                "http://dbpedia.org/resource/Linux"
            };
            var sentimentTitlePolarity      = "positive";
            var notSentimentTitlePolarity   = "negative";
            var sentimentBodyPolarity       = "neutral";
            var notSentimentBodyPolarity    = "negative";
            var mediaImagesCountMin         = 2;
            var mediaImagesCountMax         = 10;
            var mediaImagesWidthMin         = 640;
            var mediaImagesWidthMax         = 1024;
            var mediaImagesHeightMin        = 480;
            var mediaImagesHeightMax        = 800;
            var mediaImagesContentLengthMin = 25411;
            var mediaImagesContentLengthMax = 369541;
            var mediaImagesFormat           = new List <string>()
            {
                "JPEG", "BMP", "GIF"
            };
            var notMediaImagesFormat = new List <string>()
            {
                "PNG", "TIFF"
            };
            var mediaVideosCountMin = 1;
            var mediaVideosCountMax = 4;
            var authorId            = new List <int?>()
            {
                2154
            };
            var notAuthorId = new List <int?>()
            {
                5412
            };
            var authorName    = "John Doe";
            var notAuthorName = "Mike Wally";
            var sourceId      = new List <int?>()
            {
                1467
            };
            var notSourceId = new List <int?>()
            {
                1524
            };
            var sourceName = new List <string>()
            {
                "BBC"
            };
            var notSourceName = new List <string>()
            {
                "Fox News"
            };
            var sourceDomain = new List <string>()
            {
                "bbc.co.uk"
            };
            var notSourceDomain = new List <string>()
            {
                "foxnews.com"
            };
            var sourceLocationsCountry = new List <string>()
            {
                "US", "IE"
            };
            var notSourceLocationsCountry = new List <string>()
            {
                "NG"
            };
            var sourceLocationsState = new List <string>()
            {
                "California"
            };
            var notSourceLocationsState = new List <string>()
            {
                "Arizona"
            };
            var sourceLocationsCity = new List <string>()
            {
                "Los Angeles"
            };
            var notSourceLocationsCity = new List <string>()
            {
                "New York City"
            };
            var sourceScopesCountry = new List <string>()
            {
                "NG", "IE"
            };
            var notSourceScopesCountry = new List <string>()
            {
                "US", "IR"
            };
            var sourceScopesState = new List <string>()
            {
                "Co Dublin"
            };
            var notSourceScopesState = new List <string>()
            {
                "Co Wicklow"
            };
            var sourceScopesCity = new List <string>()
            {
                "Dublin City"
            };
            var notSourceScopesCity = new List <string>()
            {
                "Cork"
            };
            var sourceScopesLevel = new List <string>()
            {
                "local"
            };
            var notSourceScopesLevel = new List <string>()
            {
                "national"
            };
            var sourceLinksInCountMin      = 5000;
            var sourceLinksInCountMax      = 10000;
            var sourceRankingsAlexaRankMin = 1;
            var sourceRankingsAlexaRankMax = 2000;
            var sourceRankingsAlexaCountry = new List <string>()
            {
                "IE"
            };
            var socialSharesCountFacebookMin   = 3521;
            var socialSharesCountFacebookMax   = 5841;
            var socialSharesCountGooglePlusMin = 251;
            var socialSharesCountGooglePlusMax = 6521;
            var socialSharesCountLinkedinMin   = 4125;
            var socialSharesCountLinkedinMax   = 15214;
            var socialSharesCountRedditMin     = 1584;
            var socialSharesCountRedditMax     = 95412;
            var cluster          = true;
            var clusterAlgorithm = "kmeans";
            var _return          = new List <string>()
            {
                "id", "title", "entities"
            };
            var storyId          = 789;
            var storyUrl         = "https://techcrunch.com/2016/04/07/aylien-launches-news-analysis-api-powered-by-its-deep-learning-tech/";
            var storyTitle       = "Aylien launches news analysis API powered by its deep learning tech";
            var storyBody        = "Text analysis startup Aylien...";
            var storyPublishedAt = DateTime.Now;
            var storyLanguage    = "auto";
            var perPage          = 10;

            try
            {
                // List coverages
                Coverages result = apiInstance.ListCoverages(
                    id: id,
                    notId: notId,
                    title: title,
                    body: body,
                    text: text,
                    language: language,
                    notLanguage: notLanguage,
                    publishedAtStart: publishedAtStart,
                    publishedAtEnd: publishedAtEnd,
                    categoriesTaxonomy: categoriesTaxonomy,
                    categoriesConfident: categoriesConfident,
                    categoriesId: categoriesId,
                    notCategoriesId: notCategoriesId,
                    categoriesLevel: categoriesLevel,
                    notCategoriesLevel: notCategoriesLevel,
                    entitiesTitleText: entitiesTitleText,
                    notEntitiesTitleText: notEntitiesTitleText,
                    entitiesTitleType: entitiesTitleType,
                    notEntitiesTitleType: notEntitiesTitleType,
                    entitiesTitleLinksDbpedia: entitiesTitleLinksDbpedia,
                    notEntitiesTitleLinksDbpedia: notEntitiesTitleLinksDbpedia,
                    entitiesBodyText: entitiesBodyText,
                    notEntitiesBodyText: notEntitiesBodyText,
                    entitiesBodyType: entitiesBodyType,
                    notEntitiesBodyType: notEntitiesBodyType,
                    entitiesBodyLinksDbpedia: entitiesBodyLinksDbpedia,
                    notEntitiesBodyLinksDbpedia: notEntitiesBodyLinksDbpedia,
                    sentimentTitlePolarity: sentimentTitlePolarity,
                    notSentimentTitlePolarity: notSentimentTitlePolarity,
                    sentimentBodyPolarity: sentimentBodyPolarity,
                    notSentimentBodyPolarity: notSentimentBodyPolarity,
                    mediaImagesCountMin: mediaImagesCountMin,
                    mediaImagesCountMax: mediaImagesCountMax,
                    mediaImagesWidthMin: mediaImagesWidthMin,
                    mediaImagesWidthMax: mediaImagesWidthMax,
                    mediaImagesHeightMin: mediaImagesHeightMin,
                    mediaImagesHeightMax: mediaImagesHeightMax,
                    mediaImagesContentLengthMin: mediaImagesContentLengthMin,
                    mediaImagesContentLengthMax: mediaImagesContentLengthMax,
                    mediaImagesFormat: mediaImagesFormat,
                    notMediaImagesFormat: notMediaImagesFormat,
                    mediaVideosCountMin: mediaVideosCountMin,
                    mediaVideosCountMax: mediaVideosCountMax,
                    authorId: authorId,
                    notAuthorId: notAuthorId,
                    authorName: authorName,
                    notAuthorName: notAuthorName,
                    sourceId: sourceId,
                    notSourceId: notSourceId,
                    sourceName: sourceName,
                    notSourceName: notSourceName,
                    sourceDomain: sourceDomain,
                    notSourceDomain: notSourceDomain,
                    sourceLocationsCountry: sourceLocationsCountry,
                    notSourceLocationsCountry: notSourceLocationsCountry,
                    sourceLocationsState: sourceLocationsState,
                    notSourceLocationsState: notSourceLocationsState,
                    sourceLocationsCity: sourceLocationsCity,
                    notSourceLocationsCity: notSourceLocationsCity,
                    sourceScopesCountry: sourceScopesCountry,
                    notSourceScopesCountry: notSourceScopesCountry,
                    sourceScopesState: sourceScopesState,
                    notSourceScopesState: notSourceScopesState,
                    sourceScopesCity: sourceScopesCity,
                    notSourceScopesCity: notSourceScopesCity,
                    sourceScopesLevel: sourceScopesLevel,
                    notSourceScopesLevel: notSourceScopesLevel,
                    sourceLinksInCountMin: sourceLinksInCountMin,
                    sourceLinksInCountMax: sourceLinksInCountMax,
                    sourceRankingsAlexaRankMin: sourceRankingsAlexaRankMin,
                    sourceRankingsAlexaRankMax: sourceRankingsAlexaRankMax,
                    sourceRankingsAlexaCountry: sourceRankingsAlexaCountry,
                    socialSharesCountFacebookMin: socialSharesCountFacebookMin,
                    socialSharesCountFacebookMax: socialSharesCountFacebookMax,
                    socialSharesCountGooglePlusMin: socialSharesCountGooglePlusMin,
                    socialSharesCountGooglePlusMax: socialSharesCountGooglePlusMax,
                    socialSharesCountLinkedinMin: socialSharesCountLinkedinMin,
                    socialSharesCountLinkedinMax: socialSharesCountLinkedinMax,
                    socialSharesCountRedditMin: socialSharesCountRedditMin,
                    socialSharesCountRedditMax: socialSharesCountRedditMax,
                    cluster: cluster,
                    clusterAlgorithm: clusterAlgorithm,
                    _return: _return,
                    storyId: storyId,
                    storyUrl: storyUrl,
                    storyTitle: storyTitle,
                    storyBody: storyBody,
                    storyPublishedAt: storyPublishedAt,
                    storyLanguage: storyLanguage,
                    perPage: perPage
                    );
                Debug.WriteLine(result);
            }
            catch (Exception e)
            {
                Debug.Print("Exception when calling DefaultApi.ListCoverages: " + e.Message);
            }
        }
Пример #4
0
        // Ideally, this should be a derived class on SwapSchedule, since an
        // OIS schedule (in this context) is either a short period, or 1Y schedule with
        // a stub in the end. For our purpose, we just define a derived the class
        // that only works for our purpose (i.e. it's not general.)

        public OisSchedule(DateTime asOf, string startTenor, string endTenor, string settlementLag, DayCount dayCount, DayRule dayRule)
            : base(asOf, startTenor, endTenor, dayCount, dayRule)
        {
            Tenor startTenorEnum = GetLetterFromTenor(startTenor);
            Tenor endTenorEnum   = GetLetterFromTenor(endTenor);

            UnAdjStartDates.Add(StartDate);
            AdjStartDates.Add(StartDate);

            // Just to make sure we compare with both "1Y" and "12M" (because i'm lazy in correcting for DayCount)
            if (CompareTenors(endTenor, "1Y") == false && CompareTenors(endTenor, "12M") == false)
            {
                // Simple OIS swap
                double cvg = DateHandling.Cvg(StartDate, EndDate, dayCount);
                UnAdjEndDates.Add(EndDate);
                AdjEndDates.Add(DateHandling.AdjustDate(EndDate));
                Coverages.Add(cvg);
                return;
            }
            else
            {
                int months = 0;

                // 1Y periods + stub
                int periods, years;

                if (endTenorEnum == Tenor.Y)
                {
                    periods = GetNumberFromTenor(endTenor);
                    years   = periods;
                }
                else if (endTenorEnum == Tenor.M)
                {
                    years = (int)Math.Truncate(GetNumberFromTenor(endTenor) / 12.0);

                    if (GetNumberFromTenor(endTenor) % 12 == 0)
                    {
                        months  = 0;
                        periods = years;
                    }
                    else
                    {
                        months  = GetNumberFromTenor(endTenor) - 12 * years;
                        periods = years + 1;
                    }
                }
                else
                {
                    throw new InvalidOperationException("OIS Schedule only works for Y,M endTenors");
                }

                UnAdjEndDates.Add(DateHandling.AddTenorAdjust(StartDate, "1Y"));
                AdjEndDates.Add(DateHandling.AdjustDate(UnAdjEndDates[0], DayRule.N));
                Coverages.Add(DateHandling.Cvg(AdjStartDates[0], AdjEndDates[0], DayCount));

                // Generate Schedule
                // We start from 1 since first days are filled out
                // We only end here if we have more than 1 period
                for (int j = 1; j <= periods; j++)
                {
                    if (periods > years && periods == j + 1) // In case we have tenor like "18M" and have to create a stub periods
                    {
                        string excessTenor = months.ToString() + "M";
                        UnAdjStartDates.Add(DateHandling.AddTenorAdjust(UnAdjStartDates[j - 1], "1Y", dayRule));
                        AdjStartDates.Add(DateHandling.AdjustDate(UnAdjStartDates[j], dayRule));
                        UnAdjEndDates.Add(DateHandling.AddTenorAdjust(UnAdjEndDates[j - 1], excessTenor, dayRule));
                        AdjEndDates.Add(DateHandling.AdjustDate(UnAdjEndDates[j], dayRule));
                        Coverages.Add(DateHandling.Cvg(AdjStartDates[j], AdjEndDates[j], DayCount));
                    }
                    else
                    {
                        if (j < periods)
                        {
                            UnAdjStartDates.Add(DateHandling.AddTenorAdjust(UnAdjStartDates[j - 1], "1Y", dayRule));
                            AdjStartDates.Add(DateHandling.AdjustDate(UnAdjStartDates[j], dayRule));
                            UnAdjEndDates.Add(DateHandling.AddTenorAdjust(UnAdjEndDates[j - 1], "1Y", dayRule));
                            AdjEndDates.Add(DateHandling.AdjustDate(UnAdjEndDates[j], dayRule));
                            Coverages.Add(DateHandling.Cvg(AdjStartDates[j], AdjEndDates[j], DayCount));
                        }
                    }
                }
            }
        }