Exemplo n.º 1
0
        public void DeserializeDividend()
        {
            var serializer = new RestClientSerializer();

            var actionId = Guid.NewGuid();
            var stockId  = Guid.NewGuid();

            var json = "{\"id\":\"" + actionId + "\","
                       + "\"stock\":\"" + stockId + "\","
                       + "\"type\":\"dividend\","
                       + "\"actionDate\":\"2000-01-10\","
                       + "\"description\":\"description\","
                       + "\"paymentDate\":\"2000-02-01\","
                       + "\"amount\":12.00,"
                       + "\"percentFranked\":1.00,"
                       + "\"drpPrice\":13.00}";

            var transaction = serializer.Deserialize <CorporateAction>(json);

            var expected = new Dividend()
            {
                Id             = actionId,
                Stock          = stockId,
                ActionDate     = new Date(2000, 01, 10),
                Description    = "description",
                PaymentDate    = new Date(2000, 02, 01),
                Amount         = 12.00m,
                PercentFranked = 1.00m,
                DrpPrice       = 13.00m
            };

            transaction.Should().BeEquivalentTo(expected);
        }
Exemplo n.º 2
0
 public NullSynchronizer(IAlgorithm algorithm, Dividend dividend)
 {
     _algorithm        = algorithm;
     _dividend         = dividend;
     _symbol           = dividend.Symbol;
     _timeSliceFactory = new TimeSliceFactory(TimeZones.NewYork);
 }
Exemplo n.º 3
0
    public static MiniFloat operator /(MiniFloat Dividend, MiniFloat Divisor)
    {
        MiniFloat m = Dividend.Copy();
        MiniFloat n = Divisor.Copy();

        m.Mantissa = '1' + m.Mantissa;
        n.Mantissa = '1' + n.Mantissa;

        Binary newMantissa = m.Mantissa / n.Mantissa;

        /* Sub exponents */
        int e = (Convert.ToInt32(m.Exponent.BaseChange()) - INTBIAS) -
                (Convert.ToInt32(n.Exponent.BaseChange()) - INTBIAS);
        Binary newExponent = new Binary(Binary.BaseChange(e + INTBIAS, 10, 2));

        char newSignbit = NewSignbit(m.Signbit, n.Signbit);

        MiniFloat result = new MiniFloat(newSignbit, newExponent, newMantissa);

        /* Remove leading */
        result.Mantissa.Body = result.Mantissa.Body.Substring(1);

        while (result.Mantissa.Length < 3)
        {
            result.Mantissa += '0';
        }

        return(result);
    }
Exemplo n.º 4
0
 public ActionResult CreateDividend(Dividend dividend)
 {
     try
     {
         using (var db = new ApplicationDbContext())
         {
             var d = db.Dividends.Where(a => a.Id == dividend.Id).FirstOrDefault();
             if (d == null)
             {
                 db.Dividends.Add(dividend);
             }
             else
             {
                 d.StockId      = dividend.StockId;
                 d.Year         = dividend.Year;
                 d.DividendType = dividend.DividendType;
                 d.Among        = dividend.Among;
             }
             db.SaveChanges();
             return(Json("done"));
         }
     }
     catch (Exception ex)
     {
         return(Json(ex.Message));
     }
 }
        public void HasBeenApplied()
        {
            var mockRepository = new MockRepository(MockBehavior.Strict);

            var stock = new Stock(Guid.NewGuid());

            stock.List("ABC", "ABC Pty Ltd", new Date(1974, 01, 01), false, AssetCategory.AustralianStocks);

            var dividend = new Dividend(Guid.NewGuid(), stock, new Date(2020, 01, 01), "Test Dividend", new Date(2020, 02, 01), 100.00m, 100.0m, 0.00m);

            var transaction = new IncomeReceived()
            {
                Id                    = Guid.NewGuid(),
                Date                  = new Date(2020, 02, 01),
                Stock                 = stock,
                Comment               = "Test Dividend",
                RecordDate            = new Date(2020, 01, 01),
                FrankedAmount         = 10.00m,
                UnfrankedAmount       = 20.00m,
                FrankingCredits       = 30.00m,
                Interest              = 40.00m,
                TaxDeferred           = 0.00m,
                CreateCashTransaction = false,
                DrpCashBalance        = 0.00m
            };
            var transactions = mockRepository.Create <IPortfolioTransactionList>();

            transactions.Setup(x => x.ForHolding(stock.Id, dividend.PaymentDate)).Returns(new IPortfolioTransaction[] { transaction });

            var result = dividend.HasBeenApplied(transactions.Object);

            result.Should().BeTrue();

            mockRepository.Verify();
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Shares,Amount,Date,TickerId")] Dividend dividend)
        {
            if (id != dividend.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(dividend);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DividendExists(dividend.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["TickerId"] = new SelectList(_context.Tickers, "Id", "Symbol", dividend.TickerId);
            return(View(dividend));
        }
        public void HasBeenAppliedNoIncomeAtRecordDate()
        {
            var mockRepository = new MockRepository(MockBehavior.Strict);

            var stock = new Stock(Guid.NewGuid());

            stock.List("ABC", "ABC Pty Ltd", new Date(1974, 01, 01), false, AssetCategory.AustralianStocks);

            var dividend = new Dividend(Guid.NewGuid(), stock, new Date(2020, 01, 01), "Test Dividend", new Date(2020, 02, 01), 100.00m, 100.0m, 0.00m);

            var transaction = new ReturnOfCapital()
            {
                Id                    = Guid.NewGuid(),
                Date                  = new Date(2020, 02, 01),
                Stock                 = stock,
                Comment               = "Test Return Of Capital",
                RecordDate            = new Date(2020, 01, 01),
                Amount                = 2.00m,
                CreateCashTransaction = false
            };
            var transactions = mockRepository.Create <IPortfolioTransactionList>();

            transactions.Setup(x => x.ForHolding(stock.Id, dividend.PaymentDate)).Returns(new IPortfolioTransaction[] { transaction });

            var result = dividend.HasBeenApplied(transactions.Object);

            result.Should().BeFalse();

            mockRepository.Verify();
        }
        public void DrpRoundDown()
        {
            var mockRepository = new MockRepository(MockBehavior.Strict);

            var stock = new Stock(Guid.NewGuid());

            stock.List("ABC", "ABC Pty Ltd", new Date(1974, 01, 01), false, AssetCategory.AustralianStocks);
            stock.ChangeDividendRules(new Date(1974, 01, 01), 0.30m, RoundingRule.Round, true, DrpMethod.RoundDown);

            var stockResolver = mockRepository.Create <IStockResolver>();

            stockResolver.Setup(x => x.GetStock(stock.Id)).Returns(stock);

            var dividend = new Dividend(Guid.NewGuid(), stock, new Date(2020, 01, 01), "Test Dividend", new Date(2020, 02, 01), 1.15065m, 1.00m, 2.30m);

            var holding = mockRepository.Create <IReadOnlyHolding>();

            holding.Setup(x => x.Properties[dividend.Date]).Returns(new HoldingProperties(100, 1000.00m, 1000.00m));
            holding.Setup(x => x.Settings).Returns(new HoldingSettings(true));

            var result = dividend.GetTransactionList(holding.Object, stockResolver.Object).ToList();

            result.Should().SatisfyRespectively(
                first =>
            {
                first.Should().BeOfType <IncomeReceived>();

                if (first is IncomeReceived income)
                {
                    income.Date.Should().Be(dividend.PaymentDate);
                    income.Stock.Should().Be(dividend.Stock);
                    income.Comment.Should().Be("Test Dividend");
                    income.RecordDate.Should().Be(dividend.Date);
                    income.FrankedAmount.Should().Be(115.07m);
                    income.UnfrankedAmount.Should().Be(0.00m);
                    income.FrankingCredits.Should().Be(49.31m);
                    income.Interest.Should().Be(0.00m);
                    income.TaxDeferred.Should().Be(0.00m);
                    income.CreateCashTransaction.Should().BeFalse();
                    income.DrpCashBalance.Should().Be(0.00m);
                }
            },
                second =>
            {
                second.Should().BeOfType <OpeningBalance>();

                if (second is OpeningBalance openingBalance)
                {
                    openingBalance.Date.Should().Be(dividend.PaymentDate);
                    openingBalance.Stock.Should().Be(dividend.Stock);
                    openingBalance.Comment.Should().Be("DRP $2.30");
                    openingBalance.Units.Should().Be(50);
                    openingBalance.CostBase.Should().Be(115.07m);
                    openingBalance.AquisitionDate.Should().Be(dividend.PaymentDate);
                }
            }
                );

            mockRepository.Verify();
        }
Exemplo n.º 9
0
        private static void ApproveXBRL5_taskMgr(Dividend approved_dvd)
        {
            Task_Detail_21 td21 = new Task_Detail_21(approved_dvd);

            td21.TaskName.Value = "XBRL approval";
            td21.InsertTask21_to_DB();
        }
Exemplo n.º 10
0
        /// <summary>
        /// Create New Dividend
        /// </summary>
        /// <returns>Approved Dividend in [Dividend_Control_Approved]</returns>
        private static Dividend ApproveXBRL2_CreateNewDividend(XBRL_event_info xei, Security sec)
        {
            Dividend XBRL_dvd = new Dividend();

            XBRL_dvd.Init_from_XBRL(xei, sec);
            XBRL_dvd.LastModifiedBy.Value = "StevenXBRL-" + Utility.CurrentUser;

            //insert temp dividend into [Dividend_Control]
            if (!XBRL_dvd.Insert_to_DB(DividendTable_option.Dividend_Control))
            {
                MessageBox.Show("Helper_XBRL error 0: can't save into [Dividend_Control]");
                return(null);
            }

            //Get DividendIndex from saved dividend in [Dividend_Control]
            Dividend appr_dvd = Helper_Dividend.GetDividend_dvdID(XBRL_dvd.DividendID.Value, DividendTable_option.Dividend_Control);

            if (appr_dvd != null)
            {
                Helper_XBRL_approval.ApproveXBRL3_AddFees(appr_dvd);
                appr_dvd.Insert_to_DB(DividendTable_option.Dividend_Control_Approved);
            }
            else
            {
                MessageBox.Show("Helper_XBRL error 1: can't save into [Dividend_Control_Approved]");
                return(null);
            }

            return(appr_dvd);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Deal with cancellation XBRL
        /// </summary>
        private static Dividend ApproveXBRL1_cancellation_XBRL(Dividend existing_dvd, XBRL_SavedFile xsf)
        {
            if (existing_dvd == null)
            {
                MessageBox.Show("No Dividend created for this cancellation XBRL");
                if (xsf != null)
                {
                    xsf.processState.Value = 2;
                }
            }
            else
            {
                Helper_Dividend.CancelDivdiend(existing_dvd);//cancel existing dividend
                MessageBox.Show("Dividend " + existing_dvd.DividendIndex + " is cancelled");
                if (xsf != null)
                {
                    xsf.processState.Value = 1;
                }
            }

            if (xsf != null)
            {
                xsf.Update_to_DB();
            }
            return(existing_dvd);
        }
        /// <summary>
        /// Check for dividends and returns them
        /// </summary>
        /// <param name="eventArgs">The new tradable day event arguments</param>
        /// <returns>New Dividend event if any</returns>
        public IEnumerable <BaseData> GetEvents(NewTradableDateEventArgs eventArgs)
        {
            if (_config.Symbol == eventArgs.Symbol &&
                _mapFile.HasData(eventArgs.Date))
            {
                if (_priceFactorRatio != null)
                {
                    var close = AuxiliaryDataEnumerator.GetRawClose(
                        eventArgs.LastBaseData?.Price ?? 0,
                        _config);
                    var baseData = Dividend.Create(
                        _config.Symbol,
                        eventArgs.Date,
                        close,
                        _priceFactorRatio.Value
                        );
                    // let the config know about it for normalization
                    _config.SumOfDividends += baseData.Distribution;
                    _priceFactorRatio       = null;

                    yield return(baseData);
                }

                // check the factor file to see if we have a dividend event tomorrow
                decimal priceFactorRatio;
                if (_factorFile.HasDividendEventOnNextTradingDay(eventArgs.Date, out priceFactorRatio))
                {
                    _priceFactorRatio = priceFactorRatio;
                }
            }
        }
        private void AddDividend(object o)
        {
            if (CurrentUser.Equals(User.Default()))
            {
                System.Windows.MessageBox.Show("There is no valid user selected");
                return;
            }

            // create a new dividend
            Dividend dividend = new Dividend
            {
                ISIN           = SelectedShare.ISIN,
                Amount         = Amount,
                Value          = Dividend,
                DayOfPayment   = DividendPayDate,
                DateRangeStart = DateRangeStart,
                DateRangeEnd   = DateRangeEnd,
                UserName       = CurrentUser.ToString()
            };

            // add the order to the matching share
            DataBaseHelper.AddDividendToDB(dividend);

            Amount           = 0;
            Dividend         = 0.0;
            DividendPerShare = 0;
            DividendReturn   = 0;
        }
Exemplo n.º 14
0
        public void DividendRoundTrip()
        {
            var dividend = new Dividend
            {
                DataType       = MarketDataType.Auxiliary,
                Distribution   = 0.5m,
                ReferencePrice = decimal.MaxValue - 10000m,

                Symbol = Symbols.AAPL,
                Time   = DateTime.UtcNow,
                Value  = 0.5m
            };

            var serializedDividend = dividend.ProtobufSerialize();

            using (var stream = new MemoryStream(serializedDividend))
            {
                var result = (Dividend)Serializer.Deserialize <IEnumerable <BaseData> >(stream).First();

                Assert.AreEqual(dividend.DataType, result.DataType);
                Assert.AreEqual(dividend.Distribution, result.Distribution);
                Assert.AreEqual(dividend.ReferencePrice, result.ReferencePrice);
                Assert.AreEqual(dividend.Time, result.Time);
                Assert.AreEqual(dividend.EndTime, result.EndTime);
                Assert.AreEqual(dividend.Value, result.Value);
            }
        }
Exemplo n.º 15
0
        public void GeneratesCorrectSplitsAndDividends()
        {
            var reference          = new DateTime(2018, 01, 01);
            var file               = GetTestFactorFile("SPY", reference);
            var exchangeHours      = MarketHoursDatabase.FromDataFolder().GetExchangeHours(QuantConnect.Market.USA, Symbols.SPY, SecurityType.Equity);
            var splitsAndDividends = file.GetSplitsAndDividends(Symbols.SPY, exchangeHours);

            var dividend     = (Dividend)splitsAndDividends.Single(d => d.Time == reference.AddDays(-6));
            var distribution = Dividend.ComputeDistribution(100m, .9m / 1m, 2);

            Assert.AreEqual(distribution, dividend.Distribution);

            dividend     = (Dividend)splitsAndDividends.Single(d => d.Time == reference.AddDays(-13));
            distribution = Math.Round(Dividend.ComputeDistribution(100m, .8m / .9m, 2), 2);
            Assert.AreEqual(distribution, dividend.Distribution);

            var split       = (Split)splitsAndDividends.Single(d => d.Time == reference.AddDays(-20));
            var splitFactor = .5m;

            Assert.AreEqual(splitFactor, split.SplitFactor);

            split       = (Split)splitsAndDividends.Single(d => d.Time == reference.AddDays(-89));
            splitFactor = .5m;
            Assert.AreEqual(splitFactor, split.SplitFactor);

            dividend     = splitsAndDividends.OfType <Dividend>().Single(d => d.Time == reference.AddDays(-363));
            distribution = Dividend.ComputeDistribution(100m, .7m / .8m, 2);
            Assert.AreEqual(distribution, dividend.Distribution);

            split       = splitsAndDividends.OfType <Split>().Single(d => d.Time == reference.AddDays(-363));
            splitFactor = .5m;
            Assert.AreEqual(splitFactor, split.SplitFactor);
        }
Exemplo n.º 16
0
        protected sealed override void Calculate()
        {
            switch (BaseType)
            {
            case BaseValueType.Double: {
                _SetDouble(Dividend.GetDouble() / Divisor.GetDouble());
                break;
            }

            case BaseValueType.Single: {
                _SetSingle(Dividend.GetSingle() / Divisor.GetSingle());
                break;
            }

            case BaseValueType.Int64: {
                _SetInt64(Dividend.GetInt64() / Divisor.GetInt64());
                break;
            }

            case BaseValueType.Int32:
            default: {
                _SetInt32(Dividend.GetInt32() / Divisor.GetInt32());
                break;
            }
            }
        }
Exemplo n.º 17
0
        /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^Hss Entity Framework Auto Generated Code^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/

        public decimal Get_WHrate(Dividend dvd)
        {
            if (dvd == null)
            {
                return(-1);
            }

            if (this.BO_COR.Value.Equals("JP", StringComparison.OrdinalIgnoreCase))
            {
                if (this.BO_EntityType.Value.Equals("IND", StringComparison.OrdinalIgnoreCase))
                {
                    if (dvd.DTCPosition_ModelNumber.Value == 59 ||
                        dvd.DTCPosition_ModelNumber.Value == 58 ||
                        dvd.DTCPosition_ModelNumber.Value == 40)
                    {
                        return(0.20315m);
                    }
                    if (dvd.DTCPosition_ModelNumber.Value == 10)
                    {
                        return(0.10147m);
                    }
                }
            }

            if (dvd.Country.Value.Equals("Japan", StringComparison.OrdinalIgnoreCase))
            {
                if (this.BO_EntityType.Value.Equals("TXE", StringComparison.OrdinalIgnoreCase))
                {
                    return(0.2042m);
                }
            }

            return(dvd.StatutoryRate.Value - this.ReclaimRate.Value);
        }
Exemplo n.º 18
0
        /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^Hss Entity Framework Auto Generated Code^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/

        public void Init_from_Dividend(Dividend dvd)
        {
            if (dvd == null)
            {
                return;
            }

            this.dividend_index.Value  = dvd.DividendIndex;
            this.record_date_adr.Value = dvd.RecordDate_ADR.Value;
            this.pay_date_adr.Value    = dvd.PayDate_ADR.Value;
            this.record_date_ord.Value = dvd.RecordDate_ORD.Value;
            this.pay_date_ord.Value    = dvd.PayDate_ORD.Value;
            this.dividend.Value        = dvd.ToXML_ESP2();

            /*************************Mock up values for Igor***************************************/
            DateTime dt_now = DateTime.Now;
            Random   rd     = new Random();

            this.deadline_quick_refund.Value = dt_now.AddDays(rd.Next(60));
            this.deadline_long_form.Value    = dt_now.AddDays(rd.Next(60));
            this.deadline_at_source.Value    = dt_now.AddDays(rd.Next(60));
            /*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*/

            this.esp_model_id.Value = 1;//hard code for now
        }
Exemplo n.º 19
0
        /// <summary>
        /// Applies the dividend to this factor file row.
        /// This dividend date must be on or before the factor
        /// file row date
        /// </summary>
        /// <param name="dividend">The dividend to apply with reference price and distribution specified</param>
        /// <param name="exchangeHours">Exchange hours used for resolving the previous trading day</param>
        /// <returns>A new factor file row that applies the dividend to this row's factors</returns>
        public CorporateFactorRow Apply(Dividend dividend, SecurityExchangeHours exchangeHours)
        {
            if (dividend.ReferencePrice == 0m)
            {
                throw new ArgumentException("Unable to apply dividend with reference price of zero.");
            }

            var previousTradingDay = exchangeHours.GetPreviousTradingDay(dividend.Time);

            // this instance must be chronologically at or in front of the dividend
            // this is because the factors are defined working from current to past
            if (Date < previousTradingDay)
            {
                throw new ArgumentException(Invariant(
                                                $"Factor file row date '{Date:yyy-MM-dd}' is before dividend previous trading date '{previousTradingDay.Date:yyyy-MM-dd}'."
                                                ));
            }

            // pfi - new price factor pf(i+1) - this price factor D - distribution C - previous close
            // pfi = pf(i+1) * (C-D)/C
            var priceFactor = PriceFactor * (dividend.ReferencePrice - dividend.Distribution) / dividend.ReferencePrice;

            return(new CorporateFactorRow(
                       previousTradingDay,
                       priceFactor,
                       SplitFactor,
                       dividend.ReferencePrice
                       ));
        }
Exemplo n.º 20
0
        /// <summary>
        /// Initialize name attributes
        /// </summary>
        private void Cal_initAttr_eventInfo(Dividend dvd)
        {
            this.AnnouncementIdentifier = this.dvdCust.Election_Version.Value + 1;

            List <DividendXBRL> dxList = dvd.Get_dividendXBRL_list();

            if (dxList.Count > 0)
            {
                string refNo = dxList[0].XBRL_ReferenceNumber.Value;
                foreach (DividendXBRL dx in dxList)
                {
                    if (dx.Depositary.Value.Equals(this.dvdCust.Depositary.Value, StringComparison.OrdinalIgnoreCase))
                    {
                        refNo = dx.XBRL_ReferenceNumber.Value;
                    }
                }
                this.eventInfo.UniqueUniversalEventIdentifier = refNo;
            }

            this.eventInfo.ADRBase                   = dvd.ADR_Ratio_ADR.Value;
            this.eventInfo.OrdinaryShare             = dvd.ADR_Ratio_ORD.Value;
            this.eventInfo.SECURITY_IDENTIFIER_CUSIP = dvd.CUSIP.Value;
            this.eventInfo.ISSUER_NAME               = dvd.Issue.Value;
            this.eventInfo.ADR_RECORD_DATE           = dvd.RecordDate_ADR.Value;
        }
Exemplo n.º 21
0
        /// <summary>
        /// Calculate ORD values based on ADR ratio
        /// </summary>
        private void SubCal_ORD(Dividend dvd)
        {
            if (dvd == null)
            {
                return;
            }
            if (dvd.ADR_Ratio_ADR.Value == 0)
            {
                return;
            }

            decimal ratio = dvd.ADR_Ratio_ORD.Value / dvd.ADR_Ratio_ADR.Value;

            foreach (Election_item ele in this.DTC_participant_dic.Values)
            {
                ele.ORDQuantity = ele.ADRQuantity * ratio;
            }
            foreach (Election_item ele in this.RSH_dic.Values)
            {
                ele.ORDQuantity = ele.ADRQuantity * ratio;
            }
            foreach (Election_item ele in this.summary.totalEle_dic.Values)
            {
                ele.ORDQuantity = ele.ADRQuantity * ratio;
            }

            foreach (Custodian_ele cele in this.custodianEle_dic.Values)
            {
                foreach (Election_item ele in cele.cust_dic.Values)
                {
                    ele.ORDQuantity = ele.ADRQuantity * ratio;
                }
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// initialize dictionary values from [Dividend_Detail]
        /// </summary>
        private void SubCal_read_detail(HashSet <decimal> WHrate_hs, Dividend dvd)
        {
            List <Dividend_Detail_simpleEF> dd_list = dvd.Get_dvdDetail_list(null);

            foreach (Dividend_Detail_simpleEF detail in dd_list)
            {
                if (!this.Check_DD_forEle(detail, dvd))
                {
                    continue;
                }

                decimal dd_WHRate = detail.Get_WHrate(dvd) * 100;//convert to percentage
                if (!WHrate_hs.Contains(dd_WHRate))
                {
                    continue;
                }

                decimal ADR_shares = detail.RecordDatePosition.Value;

                if (!detail.DTC_Number.Value.StartsWith("RSH", StringComparison.OrdinalIgnoreCase))
                {
                    this.DTC_participant_dic[dd_WHRate].ADRQuantity += ADR_shares;
                }
                this.summary.totalEle_dic[dd_WHRate].ADRQuantity += ADR_shares;
                this.custodianEle_dic[detail.CustodianID.Value].cust_dic[dd_WHRate].ADRQuantity += ADR_shares;
            }
        }
Exemplo n.º 23
0
        private void SubCal_read_RSH(HashSet <decimal> WHrate_hs, Dividend dvd)
        {
            List <RSH_log> rshList = dvd.Get_RSH_list();

            foreach (RSH_log rl in rshList)
            {
                decimal rsh_WHRate  = -1;
                string  GT_findings = rl.GlobeTax_Findings.Value;

                if (!decimal.TryParse(GT_findings, out rsh_WHRate))
                {
                    continue;
                }
                else
                {
                    rsh_WHRate = rsh_WHRate * 100; //convert to percentage
                }
                if (!WHrate_hs.Contains(rsh_WHRate))
                {
                    continue;
                }

                this.RSH_dic[rsh_WHRate].ADRQuantity += rl.Shares.Value;
            }
        }
Exemplo n.º 24
0
        public void AppliesDividend()
        {
            var factorFileBeforeDividend = GetFactorFile_AAPL2018_05_08();
            var factorFileAfterDividend  = GetFactorFile_AAPL2018_05_11();
            var exchangeHours            = MarketHoursDatabase.FromDataFolder().GetExchangeHours(QuantConnect.Market.USA, Symbols.SPY, SecurityType.Equity);

            var dividend = new Dividend(Symbols.AAPL, new DateTime(2018, 05, 11), 0.73m, 190.03m);
            var actual   = factorFileBeforeDividend.Apply(new List <BaseData> {
                dividend
            }, exchangeHours);

            Assert.AreEqual(factorFileAfterDividend.Count(), actual.Count());
            Assert.True(actual.First().Date == new DateTime(1998, 01, 02),
                        $"Factor file first row changed from 1998-01-02 to {actual.First().Date:yyyy-MM-dd} after applying new event");


            foreach (var item in factorFileAfterDividend.Reverse().Zip(actual.Reverse(), (a, e) => new{ actual = a, expected = e }))
            {
                var expected  = (CorporateFactorRow)item.expected;
                var actualRow = (CorporateFactorRow)item.actual;
                Log.Trace($"expected: {item.expected} actual: {item.actual}  diff: {100* (1 - actualRow.PriceFactor/expected.PriceFactor):0.0000}%");
                Assert.AreEqual(item.expected.Date, item.actual.Date);
                Assert.AreEqual(expected.ReferencePrice, actualRow.ReferencePrice);
                Assert.AreEqual(expected.SplitFactor, actualRow.SplitFactor);

                var delta = (double)expected.PriceFactor * 1e-5;
                Assert.AreEqual((double)expected.PriceFactor, (double)actualRow.PriceFactor, delta);
            }
        }
Exemplo n.º 25
0
        private static Dividend ApproveXBRL0_find_existingDividend(XBRL_event_info xei)
        {
            if (xei == null)
            {
                return(null);
            }

            Dividend existingDVD = Helper_Dividend.GetDividend_XBRL_refNum(xei.XBRL_ReferenceNumber);

            if (existingDVD == null)
            {
                List <Dividend> list = Helper_Dividend.Get_DividendList_CR(xei.CUSIP, xei.RecordDate_ADR);
                foreach (Dividend dvd in list)
                {
                    if (dvd.GetStatus() == HssUtility.General.HssStatus.Cancel)
                    {
                        continue;
                    }
                    else
                    {
                        existingDVD = dvd; break;
                    }
                }
            }

            return(existingDVD);
        }
Exemplo n.º 26
0
        public ActionResult Create(Dividend dividend)
        {
            GetViewDropDownData();

            var div = db.Dividends.Where(f => f.PayDate == dividend.PayDate && f.InstrumentCode == dividend.InstrumentCode && f.ShareType == dividend.ShareType && f.CashDividend == dividend.CashDividend).SingleOrDefault();


            if (div != null)
            {
                ModelState.AddModelError("Code", "Dividend  already exist for the selected Symbol on that date.");
            }
            else
            {
                //ModelValidation(financialduedate);
            }

            if (ModelState.IsValid)
            {
                try
                {
                    db.Dividends.Add(dividend);
                    db.SaveChanges();
                    TempData["Message"] = "Dividend Added Successfully.";
                    return(RedirectToAction("Index", new { Symbols = dividend.InstrumentCode }));
                }
                catch (Exception exp)
                {
                    log.Error(exp);
                    ViewData["Message"] = "Error Adding Corporate Action code.";
                    ModelState.AddModelError("Error", "An error has occured please contact Administrator");
                    return(View(dividend));
                }
            }
            return(View(dividend));
        }
        public void DividendToResponse()
        {
            var mockRepository = new MockRepository(MockBehavior.Strict);

            var stock = mockRepository.Create <IReadOnlyStock>();

            stock.SetupGet(x => x.Id).Returns(Guid.NewGuid());

            var dividend = new Dividend(Guid.NewGuid(), stock.Object, new Date(2001, 01, 01), "Test", new Date(2001, 01, 15), 10.30m, 0.30m, 1.45m);

            var response = dividend.ToResponse();

            response.Should().BeEquivalentTo(new
            {
                Id             = dividend.Id,
                Type           = RestApi.CorporateActions.CorporateActionType.Dividend,
                Stock          = dividend.Stock.Id,
                ActionDate     = dividend.Date,
                Description    = dividend.Description,
                PaymentDate    = dividend.PaymentDate,
                Amount         = dividend.DividendAmount,
                PercentFranked = dividend.PercentFranked,
                DrpPrice       = dividend.DrpPrice
            });
        }
Exemplo n.º 28
0
        protected override void Execute(CodeActivityContext context)
        {
            int quotient  = Dividend.Get(context) / Divisor.Get(context);
            int remainder = Dividend.Get(context) % Divisor.Get(context);

            Result.Set(context, quotient);
            Remainder.Set(context, remainder);
        }
Exemplo n.º 29
0
        public void AppliesDividendWithPreviousTradingDateEqualToRowDate()
        {
            var row      = new FactorFileRow(new DateTime(2018, 08, 23), 1m, 2m, 123m);
            var dividend = new Dividend(Symbols.SPY, row.Date.AddDays(1), 1m, 123m);
            var updated  = row.Apply(dividend, SecurityExchangeHours.AlwaysOpen(TimeZones.NewYork));

            Assert.AreEqual("20180823,0.9918699,2,123", updated.ToCsv());
        }
Exemplo n.º 30
0
 public Task_Detail_21(Dividend dvd)
 {
     if (dvd != null)
     {
         this.dvdIndex = dvd.DividendIndex;
         this.currDvd  = dvd;
     }
     this.CreateDividend();
 }
Exemplo n.º 31
0
 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Dividend obj) {
   return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
 }