52 lines
1.6 KiB
C#
52 lines
1.6 KiB
C#
using System;
|
|
using System.Linq;
|
|
using EvoCalculator.Core.FinanceFormulas;
|
|
using EvoCalculator.Core.Models.Calculation.Models.Prepared;
|
|
using TridentGoalSeek;
|
|
|
|
namespace EvoCalculator.Core.Calculation.Columns
|
|
{
|
|
public class SumColumn : BaseColumnWithXIRR, IGoalSeekAlgorithm
|
|
{
|
|
private readonly PreparedValues _preparedValues;
|
|
private readonly PercentPaymentColumn _percentPaymentColumn;
|
|
|
|
public SumColumn(int count, DateTempColumn dateTempColumn
|
|
, PreparedValues preparedValues
|
|
, PercentPaymentColumn percentPaymentColumn) : base(count, dateTempColumn)
|
|
{
|
|
this._preparedValues = preparedValues;
|
|
this._percentPaymentColumn = percentPaymentColumn;
|
|
}
|
|
|
|
public void ComputeValues()
|
|
{
|
|
Values[0] = -this._preparedValues.BaseCost;
|
|
Values[1] = this._preparedValues.FirstPaymentSum;
|
|
|
|
for (var i = 3; i < Values.Length - 1; i++)
|
|
{
|
|
Values[i] = Values[2] * _percentPaymentColumn.Values[i] / 100;
|
|
}
|
|
|
|
Values[^1] = _preparedValues.LastPaymentSum;
|
|
}
|
|
|
|
public decimal Calculate(decimal inputVariable)
|
|
{
|
|
Values[2] = Convert.ToDouble(inputVariable);
|
|
this.ComputeValues();
|
|
var XIRR = new XIRR(Flows);
|
|
IRR = XIRR.GetResult();
|
|
|
|
return Convert.ToDecimal(IRR);
|
|
}
|
|
|
|
public void ComputeValues(decimal requiredIRR)
|
|
{
|
|
var goalSeek = new GoalSeek(this);
|
|
goalSeek.SeekResult(requiredIRR,
|
|
new GoalSeekOptions(initialTineSpacing: 10000));
|
|
}
|
|
}
|
|
} |