/// <summary> /// Provides for defering the execution of the <paramref name="source" /> query to a batch of future queries. /// </summary> /// <typeparam name="TEntity">The type of the elements of <paramref name="source" />.</typeparam> /// <param name="source">An <see cref="T:System.Linq.IQueryable`1" /> to add to the batch of future queries.</param> /// <returns>An instance of <see cref="T:EntityFramework.Future.FutureValue`1"/> that contains the result of the query.</returns> /// <seealso cref="T:EntityFramework.Future.FutureValue`1"/> public static FutureValue <TEntity> FutureFirstOrDefault <TEntity>(this IQueryable <TEntity> source) where TEntity : class { if (source == null) { return(new FutureValue <TEntity>(default(TEntity))); } ObjectQuery sourceQuery = source.ToObjectQuery(); if (sourceQuery == null) { throw new ArgumentException("The source query must be of type ObjectQuery or DbQuery.", "source"); } // make sure to only get the first value IQueryable <TEntity> firstQuery = source.Take(1); ObjectQuery <TEntity> objectQuery = firstQuery.ToObjectQuery(); if (objectQuery == null) { throw new ArgumentException("The source query must be of type ObjectQuery or DbQuery.", "source"); } var futureContext = GetFutureContext(sourceQuery); var future = new FutureValue <TEntity>(objectQuery, futureContext.ExecuteFutureQueries); futureContext.AddQuery(future); return(future); }
public GMWBRider(Person person, Annuities annuity) { int growthYears = Math.Max(accumulation, person.retirementDate - DateTime.Now.Year); if (annuity.annuityTime == AnnuityTime.Immediate) { growthYears = 0; } benifitBase = FutureValue.GetFutureValue(annuity.initialAmount, rollUp, growthYears); annualIncome = (benifitBase * minimumPercentage) * (1 - fee); annuity.distributionsBeforeTax = annualIncome; annuity.gmwb = true; annuity.yearsOfPayments = (int)Math.Round(benifitBase / annualIncome); if (annuity.annuityTax == AnnuityTax.Qualified) { annuity.exclusionRatio = annuity.initialAmount / benifitBase; } else { annuity.exclusionRatio = 0; } }
public FutureValue <TResult> GetFutureValue <TResult>() { var future = new FutureValue <TResult>( () => GetCurrentResult <TResult>(0), cancellationToken => GetCurrentResultAsync <TResult>(0, cancellationToken)); return(future); }
/// <summary> /// Provides for defering the execution of the <paramref name="source" /> query to a batch of future queries. /// </summary> /// <typeparam name="TEntity">The type of the elements of <paramref name="source" />.</typeparam> /// <typeparam name="TResult">The type of the result value wrapped in a <see cref="T:EntityFramework.Future.FutureValue`1"/>.</typeparam> /// <param name="source">An <see cref="T:System.Linq.IQueryable`1" /> to add to the batch of future queries.</param> /// <param name="selector">A lambda expression with one of the Min, Max, Count, Sum, Average aggregate functions</param> /// <returns>An instance of <see cref="T:EntityFramework.Future.FutureValue`1" /> that contains the result of the query</returns> public static FutureValue <TResult> FutureValue <TEntity, TResult>(this IQueryable <TEntity> source, Expression <Func <IQueryable <TEntity>, TResult> > selector) where TEntity : class { if (source == null) { return(new FutureValue <TResult>(default(TResult))); } var sourceQuery = source.ToObjectQuery(); if (sourceQuery == null) { // Early return for test scenarios, here so it only slows down the error path if (source is IFutureTestQueryable <TEntity> ) { return(new FutureValue <TResult>(source, null)); } throw new ArgumentException("The source query must be of type ObjectQuery or DbQuery.", "source"); } var methodExpr = selector.Body as MethodCallExpression; if (methodExpr == null || methodExpr.Arguments.Count == 0) { throw new ArgumentException("The body of lambda expression must be a Count, Min, Max, Sum or Average method call", "selector"); } var arguments = new Expression[methodExpr.Arguments.Count]; // the first argument is our source query arguments[0] = source.Expression; // copy the rest of the arguments from method call expression for (int i = 1; i < arguments.Length; i++) { arguments[i] = methodExpr.Arguments[i]; } var expression = Expression.Call(null, methodExpr.Method, arguments); var valueQuery = sourceQuery.CreateQuery(expression, typeof(TResult)); if (valueQuery == null) { throw new ArgumentException("The source query must be of type ObjectQuery or DbQuery.", "source"); } var futureContext = GetFutureContext(sourceQuery); var future = new FutureValue <TResult>(valueQuery, futureContext.ExecuteFutureQueries); futureContext.AddQuery(future); return(future); }
public IActionResult Index(FutureValue model) { if (ModelState.IsValid) { ViewBag.FV = model.CalculateFutureValue(); } else { ViewBag.FV = 0; } return(View(model)); }
public void CanGetFutureEntities() { FutureValue <Parent> futureParent = Repository <Parent> .FutureGet(Guid.NewGuid()); FutureValue <Child> futureChild = Repository <Child> .FutureGet(Guid.NewGuid()); Assert.IsNull(futureChild.Value); //This also kills the database, because we use an in // memory one ,so we ensure that the code is not // executing a second query CurrentContext.DisposeUnitOfWork(); Assert.IsNull(futureParent.Value); }
private void btnCalculator_Click(object sender, EventArgs e) { { double Principal, AnnualRate, InterestEarned; double FutureValue, RatePerPeriod; int NumberOfPeriods, CompoundType; Principal = Double.Parse(txtPrincipal.Text); AnnualRate = Double.Parse(txtInterest.Text) / 100; if (rdoMonthly.Checked) { CompoundType = 12; } else if (rdoQuarterly.Checked) { CompoundType = 4; } else if (rdoSemiannually.Checked) { CompoundType = 2; } else { CompoundType = 1; } NumberOfPeriods = Int32.Parse(txtPeriods.Text); double i = AnnualRate / CompoundType; int n = CompoundType * NumberOfPeriods; RatePerPeriod = AnnualRate / NumberOfPeriods; FutureValue = Principal * Math.Pow(1 + i, n); InterestEarned = FutureValue - Principal; txtInterestEarned.Text = InterestEarned.ToString("C"); txtAmountEarned.Text = FutureValue.ToString("C"); } }
public GLWBRider(Person person, Annuities annuity) { annuity.glwb = true; if (annuity.annuityTime == AnnuityTime.Immediate) { growthYears = 0; benifitBase = annuity.initialAmount; } else { growthYears = Math.Max(accumulation, person.retirementDate - DateTime.Now.Year); benifitBase = FutureValue.GetFutureValue(annuity.initialAmount, rollUp, growthYears); } //Limits should be imposed on the user to not allow glwb if they are out of the range annuities allow try { lifetimeWithdrawlRate = (LifeExpectancy.glwbTable[person.age + growthYears]); } catch (IndexOutOfRangeException exception) { Console.WriteLine(exception); lifetimeWithdrawlRate = 0; } annualIncome = (lifetimeWithdrawlRate * benifitBase) * (1 - fee); annuity.distributionsBeforeTax = annualIncome; if (annuity.annuityTax == AnnuityTax.Qualified) { annuity.exclusionRatio = annuity.initialAmount / benifitBase; } else { annuity.exclusionRatio = 0; } }
//calculates how much money a variable annuity will payout for a given year private List <double> VariableCalc(double carloRate) { List <double> currentYear = new List <double>(); double currentAmount = initialAmount; lumpSumAtRetirement = FutureValue.GetFutureValue(initialAmount, carloRate, yearsToRetirement); currentYear.Add(initialAmount); if (annuityTime == AnnuityTime.Deferred) { for (int j = 0; j < yearsToRetirement; j++) { currentAmount += lumpSumAtRetirement / yearsToRetirement; currentYear.Add(currentAmount); } } distributionsBeforeTax = PaymentCalculator.GetPayments(currentAmount, carloRate, yearsOfPayments); if (glwb) { yearsOfPayments += 100; } for (int j = 0; j < yearsOfPayments; j++) { currentAmount += currentAmount * carloRate; if (gmwb || glwb) { currentAmount -= distributionsBeforeTax; currentAmount = Math.Max((currentAmount - distributionsBeforeTax), (rider.annualIncome)); } else { currentAmount -= distributionsBeforeTax; currentAmount = Math.Max(0, currentAmount); } currentYear.Add(currentAmount); } return(currentYear); }
public void btnCalculate_Click(object sender, EventArgs e) { // declaring variables double Principle, AnnualRate, FutureValue, RateperPeriod, Deposit, Amount; int NumberofPeriods, Compoundtype; // Telling certain variables witch textbox to pull information from try { Principle = Double.Parse(txtPrincipal.Text); errorProvider1.SetError(txtPrincipal, ""); AnnualRate = Double.Parse(txtInterest.Text) / 100; errorProvider1.SetError(txtInterest, ""); Deposit = Double.Parse(txtDeposits.Text); errorProvider1.SetError(txtDeposits, ""); NumberofPeriods = Int32.Parse(txtPeriods.Text); errorProvider1.SetError(txtPeriods, ""); //Checking radio buttons for the compound interest times a year if (rdoMonthly.Checked) { Compoundtype = 12; } else if (rdoQuarterly.Checked) { Compoundtype = 4; } else if (rdoSemiAnnually.Checked) { Compoundtype = 2; } else { Compoundtype = 1; } // making calculations for the interest rate and the interest bumps * the number of years double i = AnnualRate / Compoundtype; int n = Compoundtype * NumberofPeriods; // Making calculation to show the deposit addition amount and the pricipal + interest amount. double d = (Deposit * AnnualRate) * Compoundtype; Amount = Principle * (Math.Pow((1 + AnnualRate), NumberofPeriods) - 1); FutureValue = Amount + (d * NumberofPeriods); // amount goes to specific textbox txtAmountEarned.Text = FutureValue.ToString(); } catch (Exception) { // Error checking with messages to notify user MessageBox.Show("Cannot have alphabetical characters in textbox. Please replace with numbers."); errorProvider1.SetError(txtPrincipal, "Not a number value."); errorProvider1.SetError(txtInterest, "Not a number value."); errorProvider1.SetError(txtDeposits, "Not a number value."); errorProvider1.SetError(txtPeriods, "Not a number value."); } }
public void Deferred() { yearsOfPayments = Math.Min((int)annuityLife, (int)retireLife); lumpSumAtRetirement = FutureValue.GetFutureValue(initialAmount, rate, accumulationYears); }
private void calculateBTN_Click(object sender, EventArgs e) { try { // declaring all variables double Principal, Additions, FutureValue, annualContrib, AnnualAdd; double InterestRate, RatePerPeriod; int YearsToGrow, CompoundType; // Parsing text to digits Principal = Double.Parse(inPrincipalTB.Text); InterestRate = Double.Parse(inInterestRateTB.Text) / 100; Additions = Double.Parse(inAdditionsTB.Text); YearsToGrow = Int32.Parse(inYearsGrowthTB.Text); // establishing Compounding Frequencies CompoundType = 0; AnnualAdd = 0; if (monthlyRB.Checked) { CompoundType = 12; AnnualAdd = Additions; } else if (quarterlyRB.Checked) { CompoundType = 4; AnnualAdd = Additions * 3; } else if (semiannuallyRB.Checked) { CompoundType = 2; AnnualAdd = Additions * 6; } else if (annuallyRB.Checked) { CompoundType = 1; AnnualAdd = Additions * 12; } // establishing i in the Future Value formula double i = InterestRate / CompoundType; //establishing other variables in Future value formuls int n = YearsToGrow; int c = CompoundType; double l = (n * c); double R = AnnualAdd; double y = Math.Pow(1 + i, l); double P = Principal; double Z = (y - 1); // establishing Rateperperiod formula RatePerPeriod = InterestRate / YearsToGrow; //Future value with additional deposits established //converting value to string FutureValue = (P * y) + ((R * Z) / i); outFutureValueTB.Text = FutureValue.ToString("C"); //establishing the annual contribution portion of Future Value Formula annualContrib = Additions * (YearsToGrow * 12); outAdditionsTB.Text = annualContrib.ToString("C"); //outInterestEarnedTB.Text = InterestEarned.ToString("n2"); //inPrincipalTB.Text = Principal.ToString(); //inInterestRateTB.Text = InterestRate.ToString("n2"); //inAdditionsTB.Text = Additions.ToString(); //monthlyContrib = (((Additions * x) - 1)/ i); //FutureValue = (Principal * x) + (monthlyContrib); //InterestEarned = FutureValue - (Principal + monthlyContrib); } catch (Exception) { MessageBox.Show("Some Information was given in the wrong format!"); } }