public override CompileResult Execute(IEnumerable <FunctionArgument> arguments, ParsingContext context) { ValidateArguments(arguments, 3); var Nper = ArgToDecimal(arguments, 0); var pmt = ArgToDecimal(arguments, 1); var Pv = ArgToDecimal(arguments, 2); double Fv = 0; if (arguments.Count() > 3) { Fv = ArgToDecimal(arguments, 3); } DueDate dueDate = 0; if (arguments.Count() > 4) { var temp = ArgToDecimal(arguments, 0); if (temp == 0) { dueDate = DueDate.BegOfPeriod; } else { dueDate = DueDate.EndOfPeriod; } } double guess = 0.1; if (arguments.Count() > 5) { guess = ArgToDecimal(arguments, 5); } return(CreateResult(Microsoft.VisualBasic.Financial.Rate(Nper, pmt, Pv, Fv, dueDate, guess), DataType.Decimal)); }
public StringModel ToStringModel <BLModel, StringModel>() { Mapper.CreateMap <OrderExport, StringOrderExport>() .ForAllMembers(item => item.ToString().CutDownTo(50)); var stringModel = Mapper.Map <OrderExport, StringOrderExport>(this); stringModel.UnitCost = UnitCost.DecimalToString(2); stringModel.ExportDate = ExportDate.DateTimeToString(); stringModel.ItemDescription = ItemDescription.CutDownTo(50); stringModel.LeadTime = LeadTime.DecimalToString(2); stringModel.EstimateOfDemand = EstimateOfDemand.DecimalToString(2); stringModel.Returnable = Returnable.CutDownTo(1); stringModel.Stocked = Stocked.CutDownTo(1); stringModel.Hazardous = Hazardous.CutDownTo(1); stringModel.DueDate = DueDate.DateTimeToString(); Mapper.CreateMap <StringOrderExport, StringModel>(); var stringModelRet = Mapper.Map <StringOrderExport, StringModel>(stringModel); return(stringModelRet); }
/// <summary> /// Clear textboxes /// </summary> protected void ClearTextBoxes() { NameText.Text = ""; StartDate.ClearSelection(); DueDate.ClearSelection(); CompleteBox.Text = ""; }
public void Common_methods() { Global.Driver.wait(5); //Click on the Owners tab Ownertab.Click(); //Click MyRequest tab MyRequesttab.Click(); // CLick AddRequest tab AddRequesttab.Click(); // CLick Duedate tab DueDate.Click(); //send keys Description Description.SendKeys(ExcelLib.ReadData(3, "TestData")); //click savebutton SaveButton.Click(); //click owner again Ownertab2.Click(); //My Request again MyRequesttab2.Click(); //Enter the value in the search bar SearchBar.SendKeys("Added for verification"); Global.Driver.wait(5); //Click on the search button SearchButton.Click(); }
/// <summary> /// see Payment /// </summary> public double PaymentInternal(double rate, short numberPeriods, double presentValue, double futureValue, DueDate due) { double auxiliaryRate1; if (numberPeriods == 0) { throw new ArgumentException("Invalid Argument Value", "numberPeriods"); } if (rate == 0) { return((-futureValue - presentValue) / numberPeriods); } if (due != DueDate.EndOfPeriod) { auxiliaryRate1 = 1 + rate; } else { auxiliaryRate1 = 1; } var auxiliaryRate2 = (double)Math.Pow((double)(rate + 1), numberPeriods); return((-futureValue - presentValue * auxiliaryRate2) / (auxiliaryRate1 * (auxiliaryRate2 - 1)) * rate); }
public override int GetHashCode() { unchecked { int hash = 17; hash = hash * 23 + (AccountNumber == null ? 0 : AccountNumber.GetHashCode()); hash = hash * 23 + (BillToAddressId == default(int) ? 0 : BillToAddressId.GetHashCode()); hash = hash * 23 + (Comment == null ? 0 : Comment.GetHashCode()); hash = hash * 23 + (CreditCardApprovalCode == null ? 0 : CreditCardApprovalCode.GetHashCode()); hash = hash * 23 + (CreditCardId == null ? 0 : CreditCardId.GetHashCode()); hash = hash * 23 + (CurrencyRateId == null ? 0 : CurrencyRateId.GetHashCode()); hash = hash * 23 + (CustomerId == default(int) ? 0 : CustomerId.GetHashCode()); hash = hash * 23 + (DueDate == default(DateTime) ? 0 : DueDate.GetHashCode()); hash = hash * 23 + (Freight == default(decimal) ? 0 : Freight.GetHashCode()); hash = hash * 23 + (ModifiedDate == default(DateTime) ? 0 : ModifiedDate.GetHashCode()); hash = hash * 23 + (OnlineOrderFlag == default(bool) ? 0 : OnlineOrderFlag.GetHashCode()); hash = hash * 23 + (OrderDate == default(DateTime) ? 0 : OrderDate.GetHashCode()); hash = hash * 23 + (PurchaseOrderNumber == null ? 0 : PurchaseOrderNumber.GetHashCode()); hash = hash * 23 + (RevisionNumber == default(byte) ? 0 : RevisionNumber.GetHashCode()); hash = hash * 23 + (Rowguid == default(Guid) ? 0 : Rowguid.GetHashCode()); hash = hash * 23 + (SalesOrderNumber == null ? 0 : SalesOrderNumber.GetHashCode()); hash = hash * 23 + (SalesPersonId == null ? 0 : SalesPersonId.GetHashCode()); hash = hash * 23 + (ShipDate == null ? 0 : ShipDate.GetHashCode()); hash = hash * 23 + (ShipMethodId == default(int) ? 0 : ShipMethodId.GetHashCode()); hash = hash * 23 + (ShipToAddressId == default(int) ? 0 : ShipToAddressId.GetHashCode()); hash = hash * 23 + (Status == default(byte) ? 0 : Status.GetHashCode()); hash = hash * 23 + (SubTotal == default(decimal) ? 0 : SubTotal.GetHashCode()); hash = hash * 23 + (TaxAmt == default(decimal) ? 0 : TaxAmt.GetHashCode()); hash = hash * 23 + (TerritoryId == null ? 0 : TerritoryId.GetHashCode()); hash = hash * 23 + (TotalDue == default(decimal) ? 0 : TotalDue.GetHashCode()); return(hash); } }
// Calculate number of periods (algorithm from kspread). public static double NPer(double Rate, double Pmt, double PV, [Optional][DefaultValue(0.0)] double FV, [Optional][DefaultValue(DueDate.EndOfPeriod)] DueDate Due) { if (Rate <= 0.0) { throw new ArgumentException(S._("VB_InvalidNPer")); } double type; if (Due == DueDate.EndOfPeriod) { type = 0.0; } else { type = 1.0; } double d = Pmt * (1.0 + Rate * type) - FV * Rate; double d2 = PV * Rate + Pmt * (1.0 + Rate * type); double res = d / d2; if (res <= 0.0) { throw new ArgumentException(S._("VB_InvalidNPer")); } return(Math.Log(res) / Math.Log(1.0 + Rate)); }
public override CompileResult Execute(IEnumerable <FunctionArgument> arguments, ParsingContext context) { ValidateArguments(arguments, 3); var rate = ArgToDecimal(arguments, 0); var Nper = ArgToDecimal(arguments, 1); var Pv = ArgToDecimal(arguments, 2); if (Pv > 0) { Pv = -1 * Pv; } double Fv = 0; if (arguments.Count() > 3) { Fv = ArgToDecimal(arguments, 3); } DueDate dueDate = 0; if (arguments.Count() > 4) { var temp = ArgToDecimal(arguments, 0); if (temp == 0) { dueDate = DueDate.BegOfPeriod; } else { dueDate = DueDate.EndOfPeriod; } } return(CreateResult(Microsoft.VisualBasic.Financial.Pmt(rate, Nper, Pv, Fv, dueDate), DataType.Decimal)); }
protected override string GetQuery(CodeActivityContext context) { long recordId = TableRecordID.Get(context); string title = Title.Get(context); DateTime dueDate = DueDate.Get(context); string statusId = StatusID.Get(context); string titleStr = string.Empty; if (!string.IsNullOrWhiteSpace(title)) { titleStr = string.Format("title: {0}", title.ToQueryValue()); } string dueDateStr = string.Empty; if (dueDate != null && dueDate != DateTime.MinValue) { dueDateStr = string.Format("due_date: {0}", dueDate.ToQueryValue()); } string statusStr = string.Empty; if (!string.IsNullOrWhiteSpace(statusId)) { statusStr = string.Format("statusId: \"{0}\"", statusId); } return(string.Format(UpdateTableRecordQuery, recordId, titleStr, dueDateStr, statusStr)); }
public void Set_complete_by_date_should_update_db() { // Given var addedDate = new DateTime(2021, 11, 1); var newCompleteByDate = new DateTime(3022, 7, 29); using (new TransactionScope()) { var itemId = InsertLearningLogItem( GenericDelegateId, addedDate, GenericLearningResourceReferenceId ); // When service.SetCompleteByDate(itemId, newCompleteByDate); var modifiedItem = service.GetLearningLogItem(itemId); // Then using (new AssertionScope()) { modifiedItem !.DueDate.Should().Be(newCompleteByDate); } } }
public AssignTaskCommand(Guid assignedTo, DueDate dueOn, string task) : base(Guid.NewGuid()) { AssignedTo = assignedTo; DueOn = dueOn; Task = task; }
protected override string GetQuery(CodeActivityContext context) { string tableId = TableID.Get(context); DateTime dueDate = DueDate.Get(context); string title = Title.Get(context); if (dueDate == null || dueDate == DateTime.MinValue) { dueDate = DateTime.Now.AddMonths(1); } var dict = DictionaryFields.Get(context); if (dict == null || dict.Count == 0) { var dataRow = DataRowFields.Get(context); var tempDict = dataRow.ToDictionary(); if (tempDict != null) { dict = tempDict; } } if (string.IsNullOrWhiteSpace(title) && dict?.Count > 0) { title = dict.First().Value.ToString(); } return(BuildQuery(tableId, title, dict, dueDate)); }
public override string ToString() { // TODO ArBy global culture, datetime format var formattedIssueDate = IssueDate.ToString("yyyy-MM-dd"); var formattedDueDate = DueDate.ToString("yyyy-MM-dd"); var formattedRedemptionDate = RedemptionDate != null?RedemptionDate.Value.ToString("yyyy-MM-dd") : "n/a"; return("Invoice(" + $"serial={Serial}, " + $"id={Id}, " + $"isPayed={IsPayed.ToString()}, " + $"issueDate={formattedIssueDate}, " + $"dueDate={formattedDueDate}, " + $"redemptionDate={formattedRedemptionDate}, " + $"supplier={Supplier}, " + $"receiver={Receiver}, " + $"total={Total.ToString(CultureInfo.InvariantCulture)}, " + $"subtotal={Subtotal.ToString(CultureInfo.InvariantCulture)}, " + $"discount={Discount.ToString(CultureInfo.InvariantCulture)}, " + $"payed={Payed.ToString(CultureInfo.InvariantCulture)}, " + $"due={Due.ToString(CultureInfo.InvariantCulture)}, " + $"items=[{string.Join(", ", Items)}], " + $"payments=[{string.Join(", ", Payments)}]" + ")"); }
public override bool Equals(object obj) { if (obj == null) { return(false); } if (obj == this) { return(true); } return(obj is InvoicePaymentRequest other && ((Uid == null && other.Uid == null) || (Uid?.Equals(other.Uid) == true)) && ((RequestMethod == null && other.RequestMethod == null) || (RequestMethod?.Equals(other.RequestMethod) == true)) && ((RequestType == null && other.RequestType == null) || (RequestType?.Equals(other.RequestType) == true)) && ((DueDate == null && other.DueDate == null) || (DueDate?.Equals(other.DueDate) == true)) && ((FixedAmountRequestedMoney == null && other.FixedAmountRequestedMoney == null) || (FixedAmountRequestedMoney?.Equals(other.FixedAmountRequestedMoney) == true)) && ((PercentageRequested == null && other.PercentageRequested == null) || (PercentageRequested?.Equals(other.PercentageRequested) == true)) && ((TippingEnabled == null && other.TippingEnabled == null) || (TippingEnabled?.Equals(other.TippingEnabled) == true)) && ((AutomaticPaymentSource == null && other.AutomaticPaymentSource == null) || (AutomaticPaymentSource?.Equals(other.AutomaticPaymentSource) == true)) && ((CardId == null && other.CardId == null) || (CardId?.Equals(other.CardId) == true)) && ((Reminders == null && other.Reminders == null) || (Reminders?.Equals(other.Reminders) == true)) && ((ComputedAmountMoney == null && other.ComputedAmountMoney == null) || (ComputedAmountMoney?.Equals(other.ComputedAmountMoney) == true)) && ((TotalCompletedAmountMoney == null && other.TotalCompletedAmountMoney == null) || (TotalCompletedAmountMoney?.Equals(other.TotalCompletedAmountMoney) == true)) && ((RoundingAdjustmentIncludedMoney == null && other.RoundingAdjustmentIncludedMoney == null) || (RoundingAdjustmentIncludedMoney?.Equals(other.RoundingAdjustmentIncludedMoney) == true))); }
public override string ToString() { return(" " + DueDate.ToString("dd/MM/yyyy") + " - " + Amount.ToString("F2", CultureInfo.InvariantCulture)); }
private void writeToBidLog(string path) { if (!IsFileLocked(path)) { var wb = new XLWorkbook(path); var ws = wb.Worksheet("Bid Log"); var nextRow = ws.Row(10); while (nextRow.Cell(1).Value.ToString() != "" && (string)nextRow.Cell(2).Value.ToString() != "") { nextRow = nextRow.RowBelow(); } nextRow.Cell(1).Value = BidNumber; nextRow.Cell(2).Value = ProjectName; nextRow.Cell(3).Value = Location; nextRow.Cell(4).Value = Client; nextRow.Cell(5).Value = Salesperson; nextRow.Cell(6).Value = Estimator; nextRow.Cell(7).Value = DueDate.ToShortDateString(); nextRow.Cell(11).Value = RequiresScope ? "Yes" : "No"; nextRow.Cell(12).Value = TechnicalRequired ? "Yes" : "No"; wb.Save(); } else { MessageBox.Show("Bid log is open elsewhere. Please close and try again."); } }
protected override string GetQuery(CodeActivityContext context) { var card = CardID.Get(context); var assignees = AssigneeIDs.Get(context); var dueDate = DueDate.Get(context); var labels = LabelIDs.Get(context); var title = Title.Get(context); var cardFields = new List <string>(); if (assignees?.Length > 0) { cardFields.Add(string.Format("assignee_ids: {0}", assignees.ToQueryValue())); } if (dueDate != null && dueDate != DateTime.MinValue) { cardFields.Add(string.Format("due_date: {0}", dueDate.ToQueryValue())); } if (labels?.Length > 0) { cardFields.Add(string.Format("label_ids: {0}", labels.ToQueryValue())); } if (!string.IsNullOrWhiteSpace(title)) { cardFields.Add(string.Format("title: {0}", title.ToQueryValue())); } var paramsStr = string.Join(" ", cardFields); return(string.Format(UpdateCardQuery, card, paramsStr)); }
public XElement GenerateModRq(bool?ClearExpenseLines = null) { XElement xElement = new XElement(nameof(Bill) + "Mod"); xElement.Add(TxnID?.ToQBXML(nameof(TxnID))); xElement.Add(TimeCreated?.ToQBXML(nameof(TimeCreated))); xElement.Add(TimeModified?.ToQBXML(nameof(TimeModified))); xElement.Add(EditSequence?.ToQBXML(nameof(EditSequence))); xElement.Add(TxnNumber?.ToQBXML(nameof(TxnNumber))); xElement.Add(VendorRef?.ToQBXML(nameof(VendorRef))); xElement.Add(VendorAddress?.ToQBXML(nameof(VendorAddress))); xElement.Add(APAccountRef?.ToQBXML(nameof(APAccountRef))); xElement.Add(TxnDate?.ToQBXML(nameof(TxnDate))); xElement.Add(DueDate?.ToQBXML(nameof(DueDate))); xElement.Add(AmountDue?.ToQBXML(nameof(AmountDue))); xElement.Add(CurrencyRef?.ToQBXML(nameof(CurrencyRef))); xElement.Add(ExchangeRate?.ToQBXML(nameof(ExchangeRate))); xElement.Add(AmountDueInHomeCurrency?.ToQBXML(nameof(AmountDueInHomeCurrency))); xElement.Add(RefNumber?.ToQBXML(nameof(RefNumber))); xElement.Add(TermsRef?.ToQBXML(nameof(TermsRef))); xElement.Add(Memo?.ToQBXML(nameof(Memo))); xElement.Add(IsTaxIncluded?.ToQBXML(nameof(IsTaxIncluded))); xElement.Add(SalesTaxCodeRef?.ToQBXML(nameof(SalesTaxCodeRef))); xElement.Add(IsPaid?.ToQBXML(nameof(IsPaid))); xElement.Add(ExternalGUID?.ToQBXML(nameof(ExternalGUID))); xElement.Add(LinkedTxnList?.ToQBXML(nameof(LinkedTxnList))); xElement.Add(ExpenseLineList?.ToQBXML(nameof(ExpenseLineList))); xElement.Add(ItemLineList?.ToQBXML(nameof(ItemLineList))); xElement.Add(OpenAmount?.ToQBXML(nameof(OpenAmount))); xElement.Add(DataExtList?.ToQBXML(nameof(DataExtList))); return(xElement); }
public override bool IsValid(params ILegalPerson[] persons) { var offeror = persons.FirstOrDefault(); var offeree = persons.Skip(1).Take(1).FirstOrDefault(); if (!(offeror is UnitedStatesLifeInsCo) || !(offeree is Wilson)) { AddReasonEntry("incorrect person given"); return(false); } //policy is such that you add the grace period to the due date then from //that add the 31 days and up to that you get reinstated without written approval var duePlusGrace = DueDate.Add(ExtendedGracePeriod); var duePlusGraceAnd31 = duePlusGrace.Add(WrittenApprovalNotRequired); var r = duePlusGraceAnd31 > DateOfPayment; if (!r) { AddReasonEntry($"due date plus extended grace period {duePlusGrace.ToShortDateString()}"); AddReasonEntry($"the additional 31 days before written notice { duePlusGraceAnd31.ToShortDateString()}"); } return(r); }
protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext) { SPSecurity.RunWithElevatedPrivileges(delegate() { using (SPSite sitecollection = new SPSite(Url)) { using (SPWeb web = sitecollection.OpenWeb()) { SPList list = web.Lists["Aufgaben"]; SPListItem listitem = list.Items.GetItemById(TaskID); if (listitem != null) { if (Status.ToString() != string.Empty) { listitem["Status"] = Status.ToString(); } if (Quelle.ToString() != string.Empty) { listitem["Aufgabenquelle"] = Quelle.ToString(); } if (DueDate.ToString() != string.Empty) { listitem["DueDate"] = DueDate; } listitem["WorkflowID"] = WorkflowID; listitem.Update(); } } } }); return(base.Execute(executionContext)); }
internal void SendRequest() { //Populate excel file ExcelLib.PopulateInCollection(Config.Keys_Resource.ExcelPath, "ListRental"); Thread.Sleep(1000); //calling the common methods Common_methods(); Thread.Sleep(500); //Select properties page PropertiesPage.Click(); Thread.Sleep(1000); //Clicking on Send a Request button SendaRequest.Click(); Thread.Sleep(1000); //Clicking on save button DueDate.Click(); Thread.Sleep(1000); //Enter Request Description RequestDesc.SendKeys(ExcelLib.ReadData(2, "Description")); Driver.wait(2000); //Clicking on Send a Request Save button RequestSave.Click(); Thread.Sleep(1000); }
public TaskDocument(Id id, object verson, Id assignedTo, DueDate dueOn, string task) { this.id = id; this.verson = verson; _assignedTo = assignedTo; _dueOn = dueOn; _task = task; }
[InlineData(0.008, 4, 12, 3000, 0, 7, -18.0688452224006, -18.068845222400633)] // type <> 0 and type <> 1 public void IPmt(double Rate, double Per, double NPer, double PV, double FV, DueDate Due, double expectedOld, double expectedNew) { if (PlatformDetection.IsAlpine) { // some tests fail due to precision return; } AreEqual(expectedOld, expectedNew, Financial.IPmt(Rate, Per, NPer, PV, FV, Due)); }
// Return the number of days until this note is due in the user's timezone public int DaysUntilDue() { DateTime dueDateLocal = DueDate.ToLocalTime(User).Date; DateTime todayLocal = DateTime.UtcNow.ToLocalTime(User).Date; TimeSpan span = dueDateLocal.Subtract(todayLocal); int days = (int)span.TotalDays; return(days < 0 ? 0 : days); }
public override bool ProcessTransition(string fromColumn, ICard penultimateAction, ICard mostRecentAction) { LastSkip = SystemTime.Now.Invoke().Date; ColumnID = (int)ColumnType.colSkip; DueDate = DueDate.AddDays(FrequencyID); SkipCount += 1; return(true); }
[InlineData(12, -3000.0, 300, 0, DueDate.EndOfPeriod, 0.1, -1.98502387722876, -1.9850238772287565)] // pmt > pv public void Rate(double NPer, double Pmt, double PV, double FV, DueDate Due, double Guess, double expectedOld, double expectedNew) { if (PlatformDetection.IsAlpine) { // some tests fail due to precision return; } AreEqual(expectedOld, expectedNew, Financial.Rate(NPer, Pmt, PV, FV, Due, Guess)); }
/// <summary> /// Format this task to be displayed to the console. /// I had to make this because Console.WriteLine doesn't like when you give it a dynamic width for the columns /// </summary> /// <param name="tab1">The length of the name column</param> /// <param name="tab2">The length of the due date column</param> /// <param name="tab3">The length of the completion status column</param> /// <param name="tab4">The length of the description column</param> /// <returns>The formatted string for display</returns> public string FormatForDisplay(int tab1, int tab2, int tab3, int tab4) { string complete = (_complete ? "Complete" : "Incomplete"); return(new string(' ', tab1 - _name.Length) + _name + new string(' ', tab2 - DueDate.ToShortDateString().Length) + DueDate.ToShortDateString() + new string(' ', tab3 - complete.Length) + complete + new string(' ', tab4 - _desc.Length) + _desc); }
// Calculate rate. public static double Rate(double NPer, double Pmt, double PV, [Optional][DefaultValue(0.0)] double FV, [Optional][DefaultValue(DueDate.EndOfPeriod)] DueDate Due, [Optional][DefaultValue(0.1)] double Guess) { double rate, rate2, temp, temp2, swap; if (NPer <= 0.0) { throw new ArgumentException(S._("VB_InvalidRate")); } rate = Guess; temp = RateInternal(NPer, Pmt, PV, FV, Due, rate); if (temp > 0.0) { rate2 = rate / 2; } else { rate2 = rate * 2; } temp2 = RateInternal(NPer, Pmt, PV, FV, Due, rate2); for (int iter = 0; iter < 40; ++iter) { if (temp == temp2) { if (rate2 > rate) { rate -= 1.0e-5; } else { rate += 1.0e-5; } temp = RateInternal(NPer, Pmt, PV, FV, Due, rate); if (temp == temp2) { throw new ArgumentException (S._("VB_CouldntCalculateRate")); } } rate = rate2 - ((rate2 - rate) * temp2) / (temp2 - temp); temp = RateInternal(NPer, Pmt, PV, FV, Due, rate); if (Math.Abs(temp) < 1.0e-8) { return(rate); } swap = rate; rate = rate2; rate2 = swap; swap = temp; temp = temp2; temp2 = swap; } throw new ArgumentException(S._("VB_CouldntCalculateRate")); }
public void DateTimeAssignment_FullDayEvent_Success() { var date = new DateTime(2018, 2, 5, 0, 0, 0, DateTimeKind.Utc); var dueDate = new DueDate(date, true); Assert.Equal("2018-02-05", dueDate.StringDate); Assert.True(dueDate.IsFullDay); }
public void DateTimeAssignment_FloatingDueDateWithTimezoneEvent_Success() { var date = new DateTime(2018, 2, 5, 0, 0, 0, DateTimeKind.Utc); var dueDate = new DueDate(date, false, "Asia/Jakarta"); Assert.Equal("2018-02-05T00:00:00Z", dueDate.StringDate); Assert.False(dueDate.IsFullDay); }
/// <summary> ///获取某个指定还款档期的还款信息 /// </summary> /// <param name="paymentNumber">指定要计算的还款档期序号</param> /// <param name="rate">利率</param> /// <param name="paymentCount">还款总期数</param> /// <param name="totalAmount">贷款总费用</param> /// <param name="dueDate">还款在每期的开始还是结尾时间,缺省为每期的结尾时间(大部分商业都是用结尾时间)</param> /// <returns>每期还款的额度</returns> /// <remarks>参数rate和参数paymentCount是呼应的。即如果paymentCount按照月计数,那么rate就必须指定为月利率; /// 如果paymentCount按照年计数,那么rate就必须指定为年利率。</remarks> public static Payment GetPayment(double rate, double totalAmount, int paymentCount, int paymentNumber, DueDate dueDate = DueDate.EndOfPeriod) { double principal = totalAmount / paymentCount; double remainAmountPercent = 1 - ((double)paymentNumber - 1) / (double)paymentCount; double interest = totalAmount * remainAmountPercent * rate; Payment payment = new Payment(); payment.Number = paymentNumber; payment.Interest = interest; payment.Principal = principal; return payment; }
/// <summary> ///获取某个指定还款档期的还款信息 /// </summary> /// <param name="paymentNumber">指定要计算的还款档期序号</param> /// <param name="rate">利率</param> /// <param name="paymentCount">还款总期数</param> /// <param name="totalAmount">贷款总费用</param> /// <param name="dueDate">还款在每期的开始还是结尾时间,缺省为每期的结尾时间(大部分商业都是用结尾时间)</param> /// <returns>每期还款的额度</returns> /// <remarks>参数rate和参数paymentCount是呼应的。即如果paymentCount按照月计数,那么rate就必须指定为月利率; /// 如果paymentCount按照年计数,那么rate就必须指定为年利率。</remarks> public static Payment GetPayment(double rate, double totalAmount, int paymentCount, int paymentNumber, DueDate dueDate = DueDate.EndOfPeriod) { double amount = -Financial.Pmt(rate, paymentCount, totalAmount, 0, dueDate); double principal = -Financial.PPmt(rate, paymentNumber, paymentCount, totalAmount, 0, dueDate); double interest = amount - principal; Payment payment = new Payment(); payment.Number = paymentNumber; payment.Interest = interest; payment.Principal = principal; return payment; }
private static double FV_Internal(double Rate, double NPer, double Pmt, double PV = 0.0, DueDate Due = 0) { double num; if (Rate == 0.0) { return (-PV - (Pmt * NPer)); } if (Due != DueDate.EndOfPeriod) { num = 1.0 + Rate; } else { num = 1.0; } double x = 1.0 + Rate; double num2 = Math.Pow(x, NPer); return ((-PV * num2) - (((Pmt / Rate) * num) * (num2 - 1.0))); }
/// <summary> /// 获取还款日程信息 /// </summary> /// <param name="paymentNumber">指定要计算的还款档期序号</param> /// <param name="rate">利率</param> /// <param name="paymentCount">还款总期数</param> /// <param name="totalAmount">贷款总费用</param> /// <param name="dueDate">还款在每期的开始还是结尾时间,缺省为每期的结尾时间(大部分商业都是用结尾时间)</param> /// <param name="getPaymentFunc">生成每期贷款的方法</param> /// <returns>每期还款的额度</returns> /// <remarks>参数rate和参数paymentCount是呼应的。即如果paymentCount按照月计数,那么rate就必须指定为月利率; /// 如果paymentCount按照年计数,那么rate就必须指定为年利率。</remarks> public static List<Payment> GetPaymentSchedule(double rate, double totalAmount, int paymentCount, PaymentTermTypes paymentCircle, DateTime loanStartDate, DueDate dueDate, Funcs<double, double, int, int, DueDate, Payment> getPaymentFunc) { //贷款还款日期的时间精度仅仅控制到日,不对时分秒控制 loanStartDate = loanStartDate.Date; List<Payment> paymentSchedule = new List<Payment>(); double totalNeedPayPrinclepal = 0; DateTime lastPaymentDate = DateTime.MinValue; for (int i = 0; i < paymentCount; i++) { int paymentNumber = i + 1; Payment payment = getPaymentFunc(rate, totalAmount, paymentCount, paymentNumber, dueDate); totalNeedPayPrinclepal += payment.Principal; payment.TotalPrincipal = totalNeedPayPrinclepal; payment.PrincipalBalance = totalAmount - totalNeedPayPrinclepal; if (lastPaymentDate == DateTime.MinValue) { if (dueDate == DueDate.BegOfPeriod) { lastPaymentDate = loanStartDate; } else { lastPaymentDate = LoanHelper.GetNextPaymentDate(loanStartDate, paymentCircle); } } else { lastPaymentDate = LoanHelper.GetNextPaymentDate(lastPaymentDate, paymentCircle); } payment.PaymentDate = lastPaymentDate; paymentSchedule.Add(payment); } return paymentSchedule; }
public static double NPer(double Rate, double Pmt, double PV, double FV, DueDate Due) {}
public static double Rate(double NPer, double Pmt, double PV, double FV = 0.0, DueDate Due = 0, double Guess = 0.1) { double num2; if (NPer <= 0.0) { throw new ArgumentException(Utils.GetResourceString("Rate_NPerMustBeGTZero")); } double rate = Guess; double num4 = LEvalRate(rate, NPer, Pmt, PV, FV, Due); if (num4 > 0.0) { num2 = rate / 2.0; } else { num2 = rate * 2.0; } double num5 = LEvalRate(num2, NPer, Pmt, PV, FV, Due); int num6 = 0; while (true) { if (num5 == num4) { if (num2 > rate) { rate -= 1E-05; } else { rate -= -1E-05; } num4 = LEvalRate(rate, NPer, Pmt, PV, FV, Due); if (num5 == num4) { throw new ArgumentException(Utils.GetResourceString("Financial_CalcDivByZero")); } } rate = num2 - (((num2 - rate) * num5) / (num5 - num4)); num4 = LEvalRate(rate, NPer, Pmt, PV, FV, Due); if (Math.Abs(num4) < 1E-07) { return rate; } double num3 = num4; num4 = num5; num5 = num3; num3 = rate; rate = num2; num2 = num3; num6++; if (num6 > 0x27) { throw new ArgumentException(Utils.GetResourceString("Financial_CannotCalculateRate")); } } }
public static double Pmt(double Rate, double NPer, double PV, double FV = 0.0, DueDate Due = 0) { return PMT_Internal(Rate, NPer, PV, FV, Due); }
public static double NPer(double Rate, double Pmt, double PV, double FV = 0.0, DueDate Due = 0) { double num; if (Rate <= -1.0) { throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue1", new string[] { "Rate" })); } if (Rate == 0.0) { if (Pmt == 0.0) { throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue1", new string[] { "Pmt" })); } return (-(PV + FV) / Pmt); } if (Due != DueDate.EndOfPeriod) { num = (Pmt * (1.0 + Rate)) / Rate; } else { num = Pmt / Rate; } double d = -FV + num; double num4 = PV + num; if ((d < 0.0) && (num4 < 0.0)) { d = -1.0 * d; num4 = -1.0 * num4; } else if ((d <= 0.0) || (num4 <= 0.0)) { throw new ArgumentException(Utils.GetResourceString("Financial_CannotCalculateNPer")); } double num2 = Rate + 1.0; return ((Math.Log(d) - Math.Log(num4)) / Math.Log(num2)); }
private static double PMT_Internal(double Rate, double NPer, double PV, double FV = 0.0, DueDate Due = 0) { double num; if (NPer == 0.0) { throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue1", new string[] { "NPer" })); } if (Rate == 0.0) { return ((-FV - PV) / NPer); } if (Due != DueDate.EndOfPeriod) { num = 1.0 + Rate; } else { num = 1.0; } double x = Rate + 1.0; double num2 = Math.Pow(x, NPer); return (((-FV - (PV * num2)) / (num * (num2 - 1.0))) * Rate); }
public static double IPmt(double Rate, double Per, double NPer, double PV, double FV, DueDate Due) {}
public static double PV(double Rate, double NPer, double Pmt, double FV = 0.0, DueDate Due = 0) { double num; if (Rate == 0.0) { return (-FV - (Pmt * NPer)); } if (Due != DueDate.EndOfPeriod) { num = 1.0 + Rate; } else { num = 1.0; } double x = 1.0 + Rate; double num2 = Math.Pow(x, NPer); return (-(FV + ((Pmt * num) * ((num2 - 1.0) / Rate))) / num2); }
public static double PPmt(double Rate, double Per, double NPer, double PV, double FV = 0.0, DueDate Due = 0) { if ((Per <= 0.0) || (Per >= (NPer + 1.0))) { throw new ArgumentException(Utils.GetResourceString("PPMT_PerGT0AndLTNPer", new string[] { "Per" })); } double num2 = PMT_Internal(Rate, NPer, PV, FV, Due); double num = IPmt(Rate, Per, NPer, PV, FV, Due); return (num2 - num); }
public static double Rate(double NPer, double Pmt, double PV, double FV, DueDate Due, double Guess) {}
private static double LEvalRate(double Rate, double NPer, double Pmt, double PV, double dFv, DueDate Due) { double num2; if (Rate == 0.0) { return ((PV + (Pmt * NPer)) + dFv); } double x = Rate + 1.0; double num = Math.Pow(x, NPer); if (Due != DueDate.EndOfPeriod) { num2 = 1.0 + Rate; } else { num2 = 1.0; } return (((PV * num) + (((Pmt * num2) * (num - 1.0)) / Rate)) + dFv); }
public static double FV(double Rate, double NPer, double Pmt, double PV = 0.0, DueDate Due = 0) { return FV_Internal(Rate, NPer, Pmt, PV, Due); }
/// <summary> /// 获取还款日程信息 /// </summary> /// <param name="paymentNumber">指定要计算的还款档期序号</param> /// <param name="rate">利率</param> /// <param name="paymentCount">还款总期数</param> /// <param name="totalAmount">贷款总费用</param> /// <param name="dueDate">还款在每期的开始还是结尾时间,缺省为每期的结尾时间(大部分商业都是用结尾时间)</param> /// <returns>每期还款的额度</returns> /// <remarks>参数rate和参数paymentCount是呼应的。即如果paymentCount按照月计数,那么rate就必须指定为月利率; /// 如果paymentCount按照年计数,那么rate就必须指定为年利率。</remarks> public static List<Payment> GetPaymentSchedule(double rate, double totalAmount, int paymentCount, PaymentTermTypes paymentCircle, DateTime loanStartDate, DueDate dueDate = DueDate.EndOfPeriod) { return LoanHelper.GetPaymentSchedule(rate, totalAmount, paymentCount, paymentCircle, loanStartDate, dueDate, GetPayment); }
public static double IPmt(double Rate, double Per, double NPer, double PV, double FV = 0.0, DueDate Due = 0) { double num; if (Due != DueDate.EndOfPeriod) { num = 2.0; } else { num = 1.0; } if ((Per <= 0.0) || (Per >= (NPer + 1.0))) { throw new ArgumentException(Utils.GetResourceString("Argument_InvalidValue1", new string[] { "Per" })); } if ((Due != DueDate.EndOfPeriod) && (Per == 1.0)) { return 0.0; } double pmt = PMT_Internal(Rate, NPer, PV, FV, Due); if (Due != DueDate.EndOfPeriod) { PV += pmt; } return (FV_Internal(Rate, Per - num, pmt, PV, DueDate.EndOfPeriod) * Rate); }
private static double RateInternal(double NPer, double Pmt, double PV, double FV, DueDate Due, double Rate) { double tempRate, rate1, endRate; if(Rate == 0.0) { return PV + Pmt * NPer + FV; } tempRate = Math.Pow(Rate + 1.0, NPer); rate1 = Rate + 1.0; if(Due == DueDate.EndOfPeriod) { endRate = 1.0; } else { endRate = rate1; } return PV * tempRate + Pmt * endRate * (tempRate - 1.0) / Rate + FV; }
/// <summary> /// 获取每期还款的额度 /// </summary> /// <param name="rate">利率</param> /// <param name="paymentCount">还款总期数</param> /// <param name="totalAmount">贷款总费用</param> /// <param name="dueDate">还款在每期的开始还是结尾时间,缺省为每期的结尾时间(大部分商业都是用结尾时间)</param> /// <returns>每期还款的额度</returns> /// <remarks>参数rate和参数paymentCount是呼应的。即如果paymentCount按照月计数,那么rate就必须指定为月利率; /// 如果paymentCount按照年计数,那么rate就必须指定为年利率。</remarks> public static double GetPaymentAmount(double rate, double totalAmount, int paymentCount, DueDate dueDate = DueDate.EndOfPeriod) { return -Financial.Pmt(rate, paymentCount, totalAmount, 0, dueDate); }