commit
message
[SLN] formula added and tested
author
Ben Vogt <[email protected]>
date
2017-06-27 02:17:15
stats
8 file(s) changed,
84 insertions(+),
7 deletions(-)
files
DOCS.md
TODO.md
dist/Formulas/AllFormulas.js
dist/Formulas/Financial.js
src/Formulas/AllFormulas.ts
src/Formulas/Financial.ts
tests/Formulas/FinancialTest.ts
tests/SheetFormulaTest.ts
1diff --git a/DOCS.md b/DOCS.md
2index 7725e02..62111bc 100644
3--- a/DOCS.md
4+++ b/DOCS.md
5@@ -448,6 +448,17 @@
6 @returns {number}
7 @constructor
8 ```
9+
10+### SLN
11+
12+```
13+ Returns the straight-line depreciation of an asset for one period. The amount of the depreciation is constant during the depreciation period.
14+@param cost - The initial cost of the asset.
15+@param salvage - The value of an asset at the end of the depreciation.
16+@param life - The depreciation period determining the number of periods in the deprecation of the asset.
17+@returns {number}
18+@constructor
19+```
20 ## Info
21
22
23diff --git a/TODO.md b/TODO.md
24index d572dd7..1679a09 100644
25--- a/TODO.md
26+++ b/TODO.md
27@@ -153,5 +153,4 @@ For example 64 tbs to a qt.
28 * PV
29 * RATE
30 * RECEIVED
31-* SLN
32 * YIELD
33diff --git a/dist/Formulas/AllFormulas.js b/dist/Formulas/AllFormulas.js
34index 0b47e18..725c4e3 100644
35--- a/dist/Formulas/AllFormulas.js
36+++ b/dist/Formulas/AllFormulas.js
37@@ -111,6 +111,7 @@ exports.DOLLARDE = Financial_1.DOLLARDE;
38 exports.DOLLARFR = Financial_1.DOLLARFR;
39 exports.EFFECT = Financial_1.EFFECT;
40 exports.SYD = Financial_1.SYD;
41+exports.SLN = Financial_1.SLN;
42 var Statistical_1 = require("./Statistical");
43 exports.AVERAGE = Statistical_1.AVERAGE;
44 exports.AVERAGEA = Statistical_1.AVERAGEA;
45diff --git a/dist/Formulas/Financial.js b/dist/Formulas/Financial.js
46index ce37ff2..ff726c0 100644
47--- a/dist/Formulas/Financial.js
48+++ b/dist/Formulas/Financial.js
49@@ -443,3 +443,23 @@ var SYD = function (cost, salvage, life, period) {
50 return (cost - salvage) * (life - period + 1) * 2 / (life * (life + 1));
51 };
52 exports.SYD = SYD;
53+/**
54+ * Returns the straight-line depreciation of an asset for one period. The amount of the depreciation is constant during
55+ * the depreciation period.
56+ * @param cost - The initial cost of the asset.
57+ * @param salvage - The value of an asset at the end of the depreciation.
58+ * @param life - The depreciation period determining the number of periods in the deprecation of the asset.
59+ * @returns {number}
60+ * @constructor
61+ */
62+var SLN = function (cost, salvage, life) {
63+ ArgsChecker_1.ArgsChecker.checkLength(arguments, 3, "SYD");
64+ cost = TypeConverter_1.TypeConverter.firstValueAsNumber(cost);
65+ salvage = TypeConverter_1.TypeConverter.firstValueAsNumber(salvage);
66+ life = TypeConverter_1.TypeConverter.firstValueAsNumber(life);
67+ if (life === 0) {
68+ throw new Errors_1.DivZeroError("Function SLN parameter 3 cannot be zero.");
69+ }
70+ return (cost - salvage) / life;
71+};
72+exports.SLN = SLN;
73diff --git a/src/Formulas/AllFormulas.ts b/src/Formulas/AllFormulas.ts
74index a7fd134..a38810e 100644
75--- a/src/Formulas/AllFormulas.ts
76+++ b/src/Formulas/AllFormulas.ts
77@@ -114,7 +114,8 @@ import {
78 DOLLARDE,
79 DOLLARFR,
80 EFFECT,
81- SYD
82+ SYD,
83+ SLN
84 } from "./Financial";
85 import {
86 AVERAGE,
87@@ -367,5 +368,6 @@ export {
88 KURT,
89 INTERCEPT,
90 FORECAST,
91- SYD
92+ SYD,
93+ SLN
94 }
95\ No newline at end of file
96diff --git a/src/Formulas/Financial.ts b/src/Formulas/Financial.ts
97index ec27be0..87b9f9f 100644
98--- a/src/Formulas/Financial.ts
99+++ b/src/Formulas/Financial.ts
100@@ -455,6 +455,28 @@ var SYD = function (cost, salvage, life, period) {
101 return (cost - salvage) * (life - period + 1) * 2 / (life * (life + 1));
102 };
103
104+
105+/**
106+ * Returns the straight-line depreciation of an asset for one period. The amount of the depreciation is constant during
107+ * the depreciation period.
108+ * @param cost - The initial cost of the asset.
109+ * @param salvage - The value of an asset at the end of the depreciation.
110+ * @param life - The depreciation period determining the number of periods in the deprecation of the asset.
111+ * @returns {number}
112+ * @constructor
113+ */
114+var SLN = function (cost, salvage, life) {
115+ ArgsChecker.checkLength(arguments, 3, "SYD");
116+ cost = TypeConverter.firstValueAsNumber(cost);
117+ salvage = TypeConverter.firstValueAsNumber(salvage);
118+ life = TypeConverter.firstValueAsNumber(life);
119+ if (life === 0) {
120+ throw new DivZeroError("Function SLN parameter 3 cannot be zero.");
121+ }
122+ return (cost - salvage) / life;
123+};
124+
125+
126 export {
127 ACCRINT,
128 CUMPRINC,
129@@ -466,5 +488,6 @@ export {
130 DOLLARFR,
131 EFFECT,
132 PMT,
133- SYD
134+ SYD,
135+ SLN
136 }
137\ No newline at end of file
138diff --git a/tests/Formulas/FinancialTest.ts b/tests/Formulas/FinancialTest.ts
139index a4f90cc..b4fce60 100644
140--- a/tests/Formulas/FinancialTest.ts
141+++ b/tests/Formulas/FinancialTest.ts
142@@ -9,7 +9,8 @@ import {
143 DOLLARFR,
144 EFFECT,
145 PMT,
146- SYD
147+ SYD,
148+ SLN
149 } from "../../src/Formulas/Financial";
150 import {
151 DATE
152@@ -288,4 +289,20 @@ test("SYD", function() {
153 catchAndAssertEquals(function() {
154 SYD.apply(this, [10, 10, 10, 10, 10]);
155 }, ERRORS.NA_ERROR);
156-});
157\ No newline at end of file
158+});
159+
160+
161+test("SLN", function() {
162+ assertEquals(SLN(100, 22, 10), 7.80);
163+ assertEquals(SLN(22.99, 1, 1), 21.99);
164+ assertEquals(SLN(22.99, 1, -1), -21.99);
165+ catchAndAssertEquals(function() {
166+ SLN(39, 22, 0);
167+ }, ERRORS.DIV_ZERO_ERROR);
168+ catchAndAssertEquals(function() {
169+ SLN.apply(this, [10, 10]);
170+ }, ERRORS.NA_ERROR);
171+ catchAndAssertEquals(function() {
172+ SLN.apply(this, [10, 10, 10, 10]);
173+ }, ERRORS.NA_ERROR);
174+});
175diff --git a/tests/SheetFormulaTest.ts b/tests/SheetFormulaTest.ts
176index 301b23d..3fb0a7c 100644
177--- a/tests/SheetFormulaTest.ts
178+++ b/tests/SheetFormulaTest.ts
179@@ -727,6 +727,10 @@ test("Sheet SYD", function(){
180 assertFormulaEquals('=SYD(100, 22, 10, 3)', 11.345454545454546);
181 });
182
183+test("Sheet SLN", function(){
184+ assertFormulaEquals('=SLN(100, 22, 10)', 7.80);
185+});
186+
187
188 test("Sheet *", function(){
189 assertFormulaEquals('= 10 * 10', 100);