예제 #1
0
        /// <summary>
        /// Creates an identifier for an ETD option instrument.
        /// <para>
        /// This takes into account the expiry of the underlying instrument. If the underlying expiry
        /// is the same as the expiry of the option, the identifier is the same as the normal one.
        /// Otherwise, the underlying expiry is added after the option expiry. For example:
        /// {@code 'OG-ETD~O-ECAG-OGBS-201706-P1.50-U201709'}.
        ///
        /// </para>
        /// </summary>
        /// <param name="exchangeId">  the MIC code of the exchange where the instruments are traded </param>
        /// <param name="contractCode">  the code supplied by the exchange for use in clearing and margining, such as in SPAN </param>
        /// <param name="expiryMonth">  the month of expiry </param>
        /// <param name="variant">  the variant of the ETD, such as 'Monthly', 'Weekly, 'Daily' or 'Flex' </param>
        /// <param name="version">  the non-negative version, zero by default </param>
        /// <param name="putCall">  the Put/Call flag </param>
        /// <param name="strikePrice">  the strike price </param>
        /// <param name="underlyingExpiryMonth">  the expiry of the underlying instrument, such as a future, may be null </param>
        /// <returns> the identifier </returns>
        public static SecurityId optionId(ExchangeId exchangeId, EtdContractCode contractCode, YearMonth expiryMonth, EtdVariant variant, int version, PutCall putCall, double strikePrice, YearMonth underlyingExpiryMonth)
        {
            ArgChecker.notNull(exchangeId, "exchangeId");
            ArgChecker.notNull(contractCode, "contractCode");
            ArgChecker.notNull(expiryMonth, "expiryMonth");
            ArgChecker.notNull(variant, "variant");
            ArgChecker.notNull(putCall, "putCall");

            string putCallStr  = putCall == PutCall.PUT ? "P" : "C";
            string versionCode = version > 0 ? "V" + version + SEPARATOR : "";

            NumberFormat f = NumberFormat.getIntegerInstance(Locale.ENGLISH);

            f.GroupingUsed          = false;
            f.MaximumFractionDigits = 8;
            string strikeStr = f.format(strikePrice).replace('-', 'M');

            string underlying = "";

            if (underlyingExpiryMonth != null && !underlyingExpiryMonth.Equals(expiryMonth))
            {
                underlying = SEPARATOR + "U" + underlyingExpiryMonth.format(YM_FORMAT);
            }

            string id = (new StringBuilder(40)).Append(OPT_PREFIX).Append(exchangeId).Append(SEPARATOR).Append(contractCode).Append(SEPARATOR).Append(expiryMonth.format(YM_FORMAT)).Append(variant.Code).Append(SEPARATOR).Append(versionCode).Append(putCallStr).Append(strikeStr).Append(underlying).ToString();

            return(SecurityId.of(ETD_SCHEME, id));
        }
예제 #2
0
        private bool ExistsExecutedRecurringTransactionLine(List <TransactionLine> lines, YearMonth yearMonth)
        {
            var test = lines.Where(x => x is ExecutedRecurringTransactionLine);

            return(lines
                   .Where(x => x is ExecutedRecurringTransactionLine)
                   .Any(x => x.Description == Description && yearMonth.Equals(x.TransactionDate)));
        }
예제 #3
0
        public void Equals_DifferentCalendars()
        {
            CalendarSystem calendar   = CalendarSystem.Julian;
            YearMonth      yearMonth1 = new YearMonth(2011, 1, calendar);
            YearMonth      yearMonth2 = new YearMonth(2011, 1, CalendarSystem.Iso);

            Assert.AreNotEqual(yearMonth1, yearMonth2);
            Assert.AreNotEqual(yearMonth1.GetHashCode(), yearMonth2.GetHashCode());
            Assert.IsFalse(yearMonth1 == yearMonth2);
            Assert.IsTrue(yearMonth1 != yearMonth2);
            Assert.IsFalse(yearMonth1.Equals(yearMonth2)); // IEquatable implementation
        }
예제 #4
0
        public void Equals_DifferentToOtherType()
        {
            YearMonth date = new YearMonth(2011, 1);

            Assert.IsFalse(date.Equals(Instant.FromUnixTimeTicks(0)));
        }
예제 #5
0
        public void ProcessLines(List <TransactionLine> statements)
        {
            YearMonth initialYearMonth = statements.Min(x => x.TransactionDate).ToYearMonth();
            YearMonth finalYearMonth   = statements.Max(x => x.TransactionDate).ToYearMonth();

            List <TransactionLine> singleLineStatements = statements
                                                          .Where(x => !(x is MultiCategoryTransactionLine))
                                                          .ToList();

            List <TransactionLine> explodedStatements = statements
                                                        .Where(x => x is MultiCategoryTransactionLine)
                                                        .Select(x => (MultiCategoryTransactionLine)x)
                                                        .SelectMany(x => x.Lines.ToList())
                                                        .Select(x => (TransactionLine)x)
                                                        .ToList();

            explodedStatements.AddRange(singleLineStatements);

            for (YearMonth yearMonth = initialYearMonth; yearMonth <= finalYearMonth; yearMonth = yearMonth.NextMonth())
            {
                budgetPerMonth.Add(yearMonth, new List <MontlyBudget>());

                foreach (MontlyBudget budget in budgets)
                {
                    List <TransactionLine> monthStatements = explodedStatements.Where(x => yearMonth.Equals(x.TransactionDate)).ToList();

                    MontlyBudget currentBudget = budget.Process(monthStatements);
                    budgetPerMonth[yearMonth].Add(currentBudget);
                    currentBudget.IncludeLine(statements, yearMonth);
                }
            }
        }