public clsLoan LoanAsOf(DateTime dt) { clsLoan newLoan = new clsLoan(this.iPropertyID, this.iTitleHolderEntityID, this.iCoBorrowerEntityID, this.iAcquisitionTitleCompanyEntityID, this.iLenderEntityID, this.dtOrigination, this.dtMaturity, this.dRate, this.dPenaltyRate, this.iLoanID); if (this.cfCashflows.Count != 0) { foreach (clsCashflow cf in this.cfCashflows) { if (cf.RecordDate() <= dt) { if (cf.PayDate() <= dt) { if (cf.Actual()) { newLoan.AddCashflow(cf); } else if (cf.DeleteDate() > dt) { newLoan.AddCashflow(new clsCashflow(cf.PayDate(), cf.RecordDate(), DateTime.MaxValue, cf.LoanID(), cf.Amount(), true, cf.TypeID())); } } else if ((cf.PayDate() > dt) && (cf.DeleteDate() > dt)) { newLoan.AddCashflow(new clsCashflow(cf.PayDate(), cf.RecordDate(), DateTime.MaxValue, cf.LoanID(), cf.Amount(), false, cf.TypeID())); } } } } return(newLoan); }
public double DispositionAmount(bool actual, bool current) { // actual = 0 if not sold // !actual && current = 0 if sale closed; otherwise most recent record date for either (prin + int + addl) or (dispo) // !actual && !current = 0 if cancelled or sale closed; otherwise original est double dCost = 0; if (this.cfCashflows.Count == 0) { return(0); } else { if (actual) { foreach (clsCashflow cf in this.cfCashflows) { if ((cf.PayDate() <= System.DateTime.Today) && (cf.Actual()) && ((cf.TypeID() == clsCashflow.Type.Principal) || (cf.TypeID() == clsCashflow.Type.InterestHard) || (cf.TypeID() == clsCashflow.Type.InterestAdditional))) { dCost += cf.Amount(); } } } else if (current) { foreach (clsCashflow cf in this.cfCashflows) { if ((cf.DeleteDate().Year == DateTime.MaxValue.Year) && ((cf.TypeID() == clsCashflow.Type.Principal) || (cf.TypeID() == clsCashflow.Type.InterestHard) || (cf.TypeID() == clsCashflow.Type.InterestAdditional) || (cf.TypeID() == clsCashflow.Type.NetDispositionProj))) { dCost += cf.Amount(); } } } else //!current , i.e. original estimate { DateTime dtFirstDispRecord = this.FindDate(clsCashflow.Type.NetDispositionProj, true, false); clsLoan l = this.LoanAsOf(dtFirstDispRecord); foreach (clsCashflow cf in l.cfCashflows) { if (cf.TypeID() == clsCashflow.Type.NetDispositionProj) { dCost = cf.Amount(); } } } return(dCost); } }
public double ImpliedAdditionalInterest() { DateTime dtProjDisp = this.FindDate(clsCashflow.Type.NetDispositionProj, false, true); if (dtProjDisp == DateTime.MinValue) { return(0); } else { clsLoan l = this.LoanAsOf(dtProjDisp); return(l.DispositionAmount(true, true) - l.AccruedInterest(dtProjDisp) - l.Balance(dtProjDisp)); } }
public double AcquisitionCost(bool original) { // returns the loan balance as of the origination date of the loan (projected or past) // if (original), uses the first record date found; if (!original) uses the loan origination date if (original) { // take the loan as of the first record date clsLoan l = this.LoanAsOf(this.FindDate(clsCashflow.Type.AcquisitionPrice, true, false)); // calc balance as of the first pay date for the as of loan return(l.Balance(l.FindDate(clsCashflow.Type.AcquisitionPrice, true, true))); } else { clsLoan l = this.LoanAsOf(this.dtOrigination); return(l.Balance(this.dtOrigination)); } }
public double ProjectedHardInterest() { // if there is a principal repayment scheduled, use its scheduled pay date to take loan as of and then accrued to that date // if not, check for a projected disposition // if neither, return 0 DateTime dtSale = this.FindDate(clsCashflow.Type.Principal, false, true); if (dtSale == DateTime.MinValue) { dtSale = this.FindDate(clsCashflow.Type.NetDispositionProj, false, true); } if (dtSale == DateTime.MinValue) { return(0); } else { clsLoan l = this.LoanAsOf(dtSale); return(l.AccruedInterest(dtSale)); } }
public double IRR(bool original) { double dPrevValue; double dCurrentValue; double dPrevIRR; double dCurrentIRR; int i = 0; double dTolerance = 0.0001; int iMaxIterations = 100; dPrevIRR = 0.05; dCurrentIRR = 0.20; if (this.cfCashflows.Count == 0) { return(double.NaN); } if (!original) { // GOTTA CHECK FOR WHETHER IT"S BEEN SOLD ALREADY dPrevValue = this._NPV(dPrevIRR); dCurrentValue = this._NPV(dCurrentIRR); while ((i < iMaxIterations) && (Math.Abs(dPrevIRR - dCurrentIRR) > dTolerance)) { double dNewR = (dPrevValue * dCurrentIRR - dCurrentValue * dPrevIRR) / (dPrevValue - dCurrentValue); dPrevIRR = dCurrentIRR; dPrevValue = dCurrentValue; dCurrentIRR = dNewR; dCurrentValue = this._NPV(dCurrentIRR); i++; } if (i >= iMaxIterations) { return(double.NaN); } else { return(dCurrentIRR); } } else { clsLoan l = this.LoanAsOf(this.FindDate(clsCashflow.Type.NetDispositionProj, true, false)); dPrevValue = l._NPV(dPrevIRR); dCurrentValue = l._NPV(dCurrentIRR); while ((i < iMaxIterations) && (Math.Abs(dPrevIRR - dCurrentIRR) > dTolerance)) { double dNewR = (dPrevValue * dCurrentIRR - dCurrentValue * dPrevIRR) / (dPrevValue - dCurrentValue); dPrevIRR = dCurrentIRR; dPrevValue = dCurrentValue; dCurrentIRR = dNewR; dCurrentValue = l._NPV(dCurrentIRR); i++; } if (i >= iMaxIterations) { return(double.NaN); } else { return(dCurrentIRR); } } }