rename: flow

This commit is contained in:
Chika 2020-10-13 15:57:10 +03:00
parent 67169eeec5
commit 822206a4a1
6 changed files with 64 additions and 65 deletions

View File

@ -57,7 +57,7 @@
<e p="IFinanceFormula.cs" t="Include" />
</e>
<e p="Models" t="Include">
<e p="FlowValues.cs" t="Include" />
<e p="Flow.cs" t="Include" />
<e p="Request" t="Include" />
<e p="Response" t="Include" />
</e>

View File

@ -14,17 +14,12 @@
</component>
<component name="ChangeListManager">
<list default="true" id="2c3b0650-5589-43d4-b4b7-2979612bb30f" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/EvoCalculator.Core.Calculation/FinanceFormulas/XIRR.cs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/EvoCalculator.Core.Calculation/FinanceFormulas/XNPV.cs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/EvoCalculator.Core.Models/Calculation/Interfaces/IFinanceFormula.cs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/EvoCalculator.Core.Models/Calculation/Models/FlowValues.cs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/EvoCalculator.Core.Tests/Calculation/Suite/FinanceFormulasTests.cs" afterDir="false" />
<change afterPath="$PROJECT_DIR$/EvoCalculator.Core.sln.DotSettings.user" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/.idea.EvoCalculator.Core/.idea/contentModel.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.EvoCalculator.Core/.idea/contentModel.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/.idea.EvoCalculator.Core/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.EvoCalculator.Core/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/EvoCalculator.Core.Calculation/EvoCalculator.Core.Calculation.csproj" beforeDir="false" afterPath="$PROJECT_DIR$/EvoCalculator.Core.Calculation/EvoCalculator.Core.Calculation.csproj" afterDir="false" />
<change beforePath="$PROJECT_DIR$/EvoCalculator.Core.Models/EvoCalculator.Core.Models.csproj" beforeDir="false" afterPath="$PROJECT_DIR$/EvoCalculator.Core.Models/EvoCalculator.Core.Models.csproj" afterDir="false" />
<change beforePath="$PROJECT_DIR$/EvoCalculator.Core.Tests/EvoCalculator.Core.Tests.csproj" beforeDir="false" afterPath="$PROJECT_DIR$/EvoCalculator.Core.Tests/EvoCalculator.Core.Tests.csproj" afterDir="false" />
<change beforePath="$PROJECT_DIR$/EvoCalculator.Core.Calculation/FinanceFormulas/XIRR.cs" beforeDir="false" afterPath="$PROJECT_DIR$/EvoCalculator.Core.Calculation/FinanceFormulas/XIRR.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/EvoCalculator.Core.Calculation/FinanceFormulas/XNPV.cs" beforeDir="false" afterPath="$PROJECT_DIR$/EvoCalculator.Core.Calculation/FinanceFormulas/XNPV.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/EvoCalculator.Core.Models/Calculation/Models/FlowValues.cs" beforeDir="false" afterPath="$PROJECT_DIR$/EvoCalculator.Core.Models/Calculation/Models/Flow.cs" afterDir="false" />
<change beforePath="$PROJECT_DIR$/EvoCalculator.Core.Tests/Calculation/Suite/FinanceFormulasTests.cs" beforeDir="false" afterPath="$PROJECT_DIR$/EvoCalculator.Core.Tests/Calculation/Suite/FinanceFormulasTests.cs" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -57,9 +52,9 @@
<option value="$PROJECT_DIR$/EvoCalculator.Core.Models/Calculation/IFinanceFormula.cs" />
<option value="$PROJECT_DIR$/EvoCalculator.Core.Models/Calculation/Interfaces/IFinanceFormula.cs" />
<option value="$PROJECT_DIR$/EvoCalculator.Core.Models/Calculation/Models/FlowValues.cs" />
<option value="$PROJECT_DIR$/EvoCalculator.Core.Calculation/FinanceFormulas/XIRR.cs" />
<option value="$PROJECT_DIR$/EvoCalculator.Core.Calculation/FinanceFormulas/XNPV.cs" />
<option value="$PROJECT_DIR$/EvoCalculator.Core.Tests/Calculation/Suite/FinanceFormulasTests.cs" />
<option value="$PROJECT_DIR$/EvoCalculator.Core.Calculation/FinanceFormulas/XIRR.cs" />
</list>
</option>
</component>
@ -78,7 +73,7 @@
<property name="RunOnceActivity.OpenProjectViewOnStart" value="true" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="nodejs_package_manager_path" value="npm" />
<property name="settings.editor.selected.configurable" value="reference.settingsdialog.IDE.editor.colors" />
<property name="settings.editor.selected.configurable" value="editor.preferences.smartKeys_rider" />
<property name="vue.rearranger.settings.migration" value="true" />
</component>
<component name="RunManager" selected=".NET Launch Settings Profile.EvoCalculator.Core">
@ -122,7 +117,7 @@
<option name="presentableId" value="Default" />
<updated>1602504351800</updated>
<workItem from="1602504354370" duration="6573000" />
<workItem from="1602584653395" duration="7652000" />
<workItem from="1602584653395" duration="8574000" />
</task>
<servers />
</component>
@ -248,10 +243,10 @@
<screen x="0" y="0" width="2560" height="1400" />
</state>
<state x="1078" y="410" key="RollbackChangesDialog/0.0.2560.1400/2560.0.1920.1040@0.0.2560.1400" timestamp="1602585122733" />
<state x="781" y="345" key="SettingsEditor" timestamp="1602587357897">
<state x="781" y="345" key="SettingsEditor" timestamp="1602593091446">
<screen x="0" y="0" width="2560" height="1400" />
</state>
<state x="781" y="345" key="SettingsEditor/0.0.2560.1400/2560.0.1920.1040@0.0.2560.1400" timestamp="1602587357897" />
<state x="781" y="345" key="SettingsEditor/0.0.2560.1400/2560.0.1920.1040@0.0.2560.1400" timestamp="1602593091446" />
<state width="498" height="446" key="SwitcherDM" timestamp="1602586590437">
<screen x="0" y="0" width="2560" height="1400" />
</state>
@ -260,10 +255,14 @@
<screen x="0" y="0" width="2560" height="1400" />
</state>
<state x="92" y="92" width="2376" height="1216" key="VCS.FileHistoryDialog/0.0.2560.1400/2560.0.1920.1040@0.0.2560.1400" timestamp="1602585129305" />
<state x="872" y="433" key="Vcs.Push.Dialog.v2" timestamp="1602509069261">
<state x="872" y="433" key="Vcs.Push.Dialog.v2" timestamp="1602592995737">
<screen x="0" y="0" width="2560" height="1400" />
</state>
<state x="872" y="433" key="Vcs.Push.Dialog.v2/0.0.2560.1400/2560.0.1920.1040@0.0.2560.1400" timestamp="1602509069261" />
<state x="872" y="433" key="Vcs.Push.Dialog.v2/0.0.2560.1400/2560.0.1920.1040@0.0.2560.1400" timestamp="1602592995737" />
<state x="930" y="299" width="700" height="801" key="find.popup" timestamp="1602593714122">
<screen x="0" y="0" width="2560" height="1400" />
</state>
<state x="930" y="299" width="700" height="801" key="find.popup/0.0.2560.1400/2560.0.1920.1040@0.0.2560.1400" timestamp="1602593714122" />
<state x="943" y="315" width="672" height="678" key="search.everywhere.popup" timestamp="1602590571064">
<screen x="0" y="0" width="2560" height="1400" />
</state>

View File

@ -6,17 +6,17 @@ namespace EvoCalculator.Core.Calculation.FinanceFormulas
{
public class XIRR : IFinanceFormula<double>
{
private FlowValue[] _values;
private Flow[] _flows;
private double _guess = 0.1;
public XIRR(FlowValue[] values)
public XIRR(Flow[] flows)
{
_values = values;
_flows = flows;
}
public XIRR(FlowValue[] values, double guess)
public XIRR(Flow[] flows, double guess)
{
_values = values;
_flows = flows;
_guess = guess;
}
@ -24,8 +24,8 @@ namespace EvoCalculator.Core.Calculation.FinanceFormulas
{
var x1 = 0.0;
var x2 = _guess;
var f1 = new XNPV(_values, x1).GetResult();
var f2 = new XNPV(_values, x2).GetResult();
var f1 = new XNPV(_flows, x1).GetResult();
var f2 = new XNPV(_flows, x2).GetResult();
for (var i = 0; i < 100; i++)
{
@ -33,18 +33,18 @@ namespace EvoCalculator.Core.Calculation.FinanceFormulas
if (Math.Abs(f1) < Math.Abs(f2))
{
x1 += 1.6 * (x1 - x2);
f1 = new XNPV(_values, x1).GetResult();
f1 = new XNPV(_flows, x1).GetResult();
}
else
{
x2 += 1.6 * (x2 - x1);
f2 = new XNPV(_values, x2).GetResult();
f2 = new XNPV(_flows, x2).GetResult();
}
}
if (f1 * f2 > 0.0) return 0;
var f = new XNPV(_values, x1).GetResult();
var f = new XNPV(_flows, x1).GetResult();
var dx = 0.0;
var rtb = 0.0;
if (f < 0.0)
@ -62,7 +62,7 @@ namespace EvoCalculator.Core.Calculation.FinanceFormulas
{
dx *= 0.5;
var xMid = rtb + dx;
var fMid = new XNPV(_values, xMid).GetResult();
var fMid = new XNPV(_flows, xMid).GetResult();
if (fMid <= 0.0) rtb = xMid;
if (Math.Abs(fMid) < 1.0e-6 || Math.Abs(dx) < 1.0e-6) return xMid;
}

View File

@ -7,20 +7,20 @@ namespace EvoCalculator.Core.Calculation.FinanceFormulas
{
public class XNPV : IFinanceFormula<double>
{
private FlowValue[] _values;
private Flow[] _flows;
private double _rate;
public XNPV(FlowValue[] values, double rate)
public XNPV(Flow[] flows, double rate)
{
_values = values;
_flows = flows;
_rate = rate;
}
public double GetResult()
{
var firstDate = _values[0].Date;
return _values.Sum(flowValue =>
flowValue.Flow / Math.Pow(1 + _rate, (flowValue.Date - firstDate).TotalDays / 365));
var firstDate = _flows[0].Date;
return _flows.Sum(flow =>
flow.Value / Math.Pow(1 + _rate, (flow.Date - firstDate).TotalDays / 365));
}
}
}

View File

@ -2,9 +2,9 @@
namespace EvoCalculator.Core.Models.Calculation.Models
{
public class FlowValue
public class Flow
{
public DateTime Date;
public double Flow;
public double Value;
}
}

View File

@ -11,72 +11,72 @@ namespace EvoCalculator.Core.Tests.Calculation.Suite
{
private readonly ITestOutputHelper output;
readonly FlowValue[] _flowValues =
readonly Flow[] _flows =
{
new FlowValue
new Flow
{
Date = new DateTime(2020, 09, 01),
Flow = -6500000
Value = -6500000
},
new FlowValue
new Flow
{
Date = new DateTime(2020, 09, 01),
Flow = 608944.445718643
Value = 608944.445718643
},
new FlowValue
new Flow
{
Date = new DateTime(2020, 10, 01),
Flow = 608944.445718643
Value = 608944.445718643
},
new FlowValue
new Flow
{
Date = new DateTime(2020, 11, 01),
Flow = 608944.445718643
Value = 608944.445718643
},
new FlowValue
new Flow
{
Date = new DateTime(2020, 12, 01),
Flow = 608944.445718643
Value = 608944.445718643
},
new FlowValue
new Flow
{
Date = new DateTime(2021, 1, 01),
Flow = 608944.445718643
Value = 608944.445718643
},
new FlowValue
new Flow
{
Date = new DateTime(2021, 2, 01),
Flow = 608944.445718643
Value = 608944.445718643
},
new FlowValue
new Flow
{
Date = new DateTime(2021, 3, 01),
Flow = 608944.445718643
Value = 608944.445718643
},
new FlowValue
new Flow
{
Date = new DateTime(2021, 4, 01),
Flow = 608944.445718643
Value = 608944.445718643
},
new FlowValue
new Flow
{
Date = new DateTime(2021, 5, 01),
Flow = 608944.445718643
Value = 608944.445718643
},
new FlowValue
new Flow
{
Date = new DateTime(2021, 6, 01),
Flow = 608944.445718643
Value = 608944.445718643
},
new FlowValue
new Flow
{
Date = new DateTime(2021, 7, 01),
Flow = 608944.445718643
Value = 608944.445718643
},
new FlowValue
new Flow
{
Date = new DateTime(2021, 8, 01),
Flow = 608944.445718643
Value = 608944.445718643
},
};
@ -88,7 +88,7 @@ namespace EvoCalculator.Core.Tests.Calculation.Suite
[Fact]
public void XNPVTest()
{
var XNPV = new XNPV(_flowValues.Skip(1).ToArray(), 0.3);
var XNPV = new XNPV(_flows.Skip(1).ToArray(), 0.3);
var res = XNPV.GetResult();
output.WriteLine(res.ToString());
Assert.InRange(res, 6490000, 6590000);
@ -97,7 +97,7 @@ namespace EvoCalculator.Core.Tests.Calculation.Suite
[Fact]
public void XIRRTest()
{
var XIRR = new XIRR(_flowValues);
var XIRR = new XIRR(_flows);
var res = XIRR.GetResult();
output.WriteLine(res.ToString());
Assert.InRange(res, 0.29, 0.31);