ybelkada HF Staff commited on
Commit
08283c1
·
verified ·
1 Parent(s): 6935932

Harbor format: 14 coding_additions tasks (part 9)

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. .gitattributes +2 -0
  2. tasks/tasksmith-a7e859277e7a/environment/source/pyproject.toml +64 -0
  3. tasks/tasksmith-a7e859277e7a/instruction.md +25 -0
  4. tasks/tasksmith-a7e859277e7a/solution/reference/benchmarks/benchmarks.py +31 -0
  5. tasks/tasksmith-a7e859277e7a/solution/reference/numpy_financial/_financial.py +1041 -0
  6. tasks/tasksmith-a7e859277e7a/solution/solve.sh +6 -0
  7. tasks/tasksmith-a7e859277e7a/task.toml +226 -0
  8. tasks/tasksmith-a7e859277e7a/tests/Dockerfile +10 -0
  9. tasks/tasksmith-a7e859277e7a/tests/contract.json +1 -0
  10. tasks/tasksmith-a7e859277e7a/tests/grade.py +196 -0
  11. tasks/tasksmith-a7e859277e7a/tests/source/.github/CODE_OF_CONDUCT.md +9 -0
  12. tasks/tasksmith-a7e859277e7a/tests/source/.github/ISSUE_TEMPLATE/bug-report.yml +63 -0
  13. tasks/tasksmith-a7e859277e7a/tests/source/.github/ISSUE_TEMPLATE/config.yml +7 -0
  14. tasks/tasksmith-a7e859277e7a/tests/source/.github/ISSUE_TEMPLATE/documentation.yml +23 -0
  15. tasks/tasksmith-a7e859277e7a/tests/source/.github/ISSUE_TEMPLATE/feature-request.yml +22 -0
  16. tasks/tasksmith-a7e859277e7a/tests/source/.github/workflows/lint.yml +53 -0
  17. tasks/tasksmith-a7e859277e7a/tests/source/.github/workflows/publish_docs_to_pages.yml +76 -0
  18. tasks/tasksmith-a7e859277e7a/tests/source/.github/workflows/pythonpackage.yml +25 -0
  19. tasks/tasksmith-a7e859277e7a/tests/source/.gitignore +113 -0
  20. tasks/tasksmith-a7e859277e7a/tests/source/Dockerfile +8 -0
  21. tasks/tasksmith-a7e859277e7a/tests/source/LICENSE.txt +30 -0
  22. tasks/tasksmith-a7e859277e7a/tests/source/README.md +21 -0
  23. tasks/tasksmith-a7e859277e7a/tests/source/asv.conf.json +193 -0
  24. tasks/tasksmith-a7e859277e7a/tests/source/benchmarks/__init__.py +0 -0
  25. tasks/tasksmith-a7e859277e7a/tests/source/benchmarks/benchmarks.py +49 -0
  26. tasks/tasksmith-a7e859277e7a/tests/source/doc/Makefile +20 -0
  27. tasks/tasksmith-a7e859277e7a/tests/source/doc/make.bat +35 -0
  28. tasks/tasksmith-a7e859277e7a/tests/source/doc/source/_static/numpy_financial_favicon.png +3 -0
  29. tasks/tasksmith-a7e859277e7a/tests/source/doc/source/_static/numpy_financial_logov.svg +12 -0
  30. tasks/tasksmith-a7e859277e7a/tests/source/doc/source/conf.py +67 -0
  31. tasks/tasksmith-a7e859277e7a/tests/source/doc/source/dev/building_with_poetry.md +67 -0
  32. tasks/tasksmith-a7e859277e7a/tests/source/doc/source/dev/getting_the_code.md +43 -0
  33. tasks/tasksmith-a7e859277e7a/tests/source/doc/source/dev/running_the_benchmarks.md +55 -0
  34. tasks/tasksmith-a7e859277e7a/tests/source/doc/source/fv.rst +8 -0
  35. tasks/tasksmith-a7e859277e7a/tests/source/doc/source/generate_rst_function_files.py +27 -0
  36. tasks/tasksmith-a7e859277e7a/tests/source/doc/source/index.rst +79 -0
  37. tasks/tasksmith-a7e859277e7a/tests/source/doc/source/ipmt.rst +8 -0
  38. tasks/tasksmith-a7e859277e7a/tests/source/doc/source/irr.rst +8 -0
  39. tasks/tasksmith-a7e859277e7a/tests/source/doc/source/mirr.rst +8 -0
  40. tasks/tasksmith-a7e859277e7a/tests/source/doc/source/nper.rst +8 -0
  41. tasks/tasksmith-a7e859277e7a/tests/source/doc/source/npv.rst +8 -0
  42. tasks/tasksmith-a7e859277e7a/tests/source/doc/source/pmt.rst +8 -0
  43. tasks/tasksmith-a7e859277e7a/tests/source/doc/source/ppmt.rst +8 -0
  44. tasks/tasksmith-a7e859277e7a/tests/source/doc/source/pv.rst +8 -0
  45. tasks/tasksmith-a7e859277e7a/tests/source/doc/source/rate.rst +8 -0
  46. tasks/tasksmith-a7e859277e7a/tests/source/doc/source/release-notes.rst +20 -0
  47. tasks/tasksmith-a7e859277e7a/tests/source/docweb/README.txt +3 -0
  48. tasks/tasksmith-a7e859277e7a/tests/source/docweb/css/home.css +128 -0
  49. tasks/tasksmith-a7e859277e7a/tests/source/docweb/images/numpy_financial_favicon.png +3 -0
  50. tasks/tasksmith-a7e859277e7a/tests/source/docweb/images/numpy_financial_logoh.svg +11 -0
.gitattributes CHANGED
@@ -144,3 +144,5 @@ tasks/tasksmith-87860368c397/tests/source/tests/pdfs/issue-982-example.pdf filte
144
  tasks/tasksmith-87860368c397/tests/source/tests/pdfs/pdffill-demo.pdf filter=lfs diff=lfs merge=lfs -text
145
  tasks/tasksmith-87860368c397/tests/source/tests/pdfs/pr-136-example.pdf filter=lfs diff=lfs merge=lfs -text
146
  tasks/tasksmith-87860368c397/tests/source/tests/pdfs/table-curves-example.pdf filter=lfs diff=lfs merge=lfs -text
 
 
 
144
  tasks/tasksmith-87860368c397/tests/source/tests/pdfs/pdffill-demo.pdf filter=lfs diff=lfs merge=lfs -text
145
  tasks/tasksmith-87860368c397/tests/source/tests/pdfs/pr-136-example.pdf filter=lfs diff=lfs merge=lfs -text
146
  tasks/tasksmith-87860368c397/tests/source/tests/pdfs/table-curves-example.pdf filter=lfs diff=lfs merge=lfs -text
147
+ tasks/tasksmith-ca08ab4caec6/environment/source/etc/NYSE-Historical-Closings.pdf filter=lfs diff=lfs merge=lfs -text
148
+ tasks/tasksmith-ca08ab4caec6/tests/source/etc/NYSE-Historical-Closings.pdf filter=lfs diff=lfs merge=lfs -text
tasks/tasksmith-a7e859277e7a/environment/source/pyproject.toml ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [build-system]
2
+ requires = ["poetry-core"]
3
+ build-backend = "poetry.core.masonry.api"
4
+
5
+
6
+ [tool.poetry]
7
+ name = "numpy-financial"
8
+ version = "2.0.0"
9
+ description = "Simple financial functions"
10
+ license = "BSD-3-Clause"
11
+ authors = ["Travis E. Oliphant et al."]
12
+ maintainers = ["Numpy Financial Developers <numpy-discussion@python.org>"]
13
+ readme = "README.md"
14
+ homepage = "https://numpy.org/numpy-financial/latest/"
15
+ repository = "https://github.com/numpy/numpy-financial"
16
+ documentation = "https://numpy.org/numpy-financial/latest/#functions"
17
+ classifiers = [
18
+ "Development Status :: 5 - Production/Stable",
19
+ "Intended Audience :: Developers",
20
+ "Intended Audience :: Financial and Insurance Industry",
21
+ "License :: OSI Approved :: BSD License",
22
+ "Programming Language :: Python",
23
+ "Programming Language :: Python :: 3",
24
+ "Programming Language :: Python :: 3.10",
25
+ "Programming Language :: Python :: 3.11",
26
+ "Programming Language :: Python :: 3.12",
27
+ "Programming Language :: Python :: 3 :: Only",
28
+ "Topic :: Software Development",
29
+ "Topic :: Office/Business :: Financial :: Accounting",
30
+ "Topic :: Office/Business :: Financial :: Investment",
31
+ "Topic :: Office/Business :: Financial :: Spreadsheet",
32
+ "Operating System :: Microsoft :: Windows",
33
+ "Operating System :: POSIX",
34
+ "Operating System :: Unix",
35
+ "Operating System :: MacOS",
36
+ ]
37
+ packages = [{include = "numpy_financial"}]
38
+
39
+ [tool.poetry.dependencies]
40
+ python = "^3.10"
41
+ numpy = "^1.23"
42
+ numba = "^0.59.1"
43
+
44
+ [tool.poetry.group.test.dependencies]
45
+ pytest = "^8.0"
46
+ hypothesis = {extras = ["numpy"], version = "^6.99.11"}
47
+ pytest-xdist = {extras = ["psutil"], version = "^3.5.0"}
48
+
49
+
50
+ [tool.poetry.group.docs.dependencies]
51
+ sphinx = "^7.0"
52
+ numpydoc = "^1.5"
53
+ pydata-sphinx-theme = "^0.14.3"
54
+ myst-parser = "^2.0.0"
55
+
56
+
57
+
58
+ [tool.poetry.group.lint.dependencies]
59
+ ruff = "^0.3"
60
+
61
+
62
+ [tool.poetry.group.bench.dependencies]
63
+ asv = "^0.6"
64
+
tasks/tasksmith-a7e859277e7a/instruction.md ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Rework `npf.npv(rate, values)` to support broadcasting over multiple rates and cashflow series.
2
+
3
+ **New behavior:**
4
+
5
+ - When `rate` is a 1-D array of length *R* and `values` is a 2-D array of shape *(C, T)*, `npv` must return an array of shape *(R, C)* where entry `[i, j]` is the NPV of cashflow row `j` discounted at `rates[i]`.
6
+ - When either argument is a scalar / 1-D cashflow (single series), the result should be squeezed: a scalar when only one rate and one cashflow, a 1-D array otherwise.
7
+ - A `rate` whose array representation has `ndim > 1` (e.g. a 2-D list or a 3-D array) must raise `ValueError`.
8
+ - A `values` input whose array representation has `ndim > 2` (e.g. a 3-D list or array) must raise `ValueError`.
9
+ - When `rate` is exactly `-1` (integer or float), the function must return `nan` instead of raising an error.
10
+
11
+ **Preserved behavior:**
12
+ `npv(scalar_rate, 1d_cashflow)` continues to return a scalar with the same formula:
13
+ `sum(values[t] / (1 + rate)**t for t in range(T))`.
14
+
15
+ **Example:**
16
+ ```python
17
+ rates = [0.00, 0.05, 0.10]
18
+ cashflows = [[-4_000, 500, 800], [-5_000, 600, 900]]
19
+ npf.npv(rates, cashflows)
20
+ # array([[-2700. , -3500. ],
21
+ # [-2798.19, -3612.24],
22
+ # [-2884.3 , -3710.74]])
23
+ ```
24
+
25
+ Work in `/workspace`. Submit your fix in Python source files under `numpy_financial`, `benchmarks/benchmarks.py`. Preserve the other public behavior. The environment is offline; dependencies are preinstalled. Grading runs the relevant repository tests in a fresh environment, using your submitted source files.
tasks/tasksmith-a7e859277e7a/solution/reference/benchmarks/benchmarks.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+
3
+ import numpy_financial as npf
4
+
5
+
6
+ class Npv2D:
7
+
8
+ param_names = ["n_cashflows", "cashflow_lengths", "rates_lengths"]
9
+ params = [
10
+ (1, 10, 100),
11
+ (1, 10, 100),
12
+ (1, 10, 100),
13
+ ]
14
+
15
+ def __init__(self):
16
+ self.rates = None
17
+ self.cashflows = None
18
+
19
+ def setup(self, n_cashflows, cashflow_lengths, rates_lengths):
20
+ rng = np.random.default_rng(0)
21
+ cf_shape = (n_cashflows, cashflow_lengths)
22
+ self.cashflows = rng.standard_normal(cf_shape)
23
+ self.rates = rng.standard_normal(rates_lengths)
24
+
25
+ def time_for_loop(self, n_cashflows, cashflow_lengths, rates_lengths):
26
+ for rate in self.rates:
27
+ for cashflow in self.cashflows:
28
+ npf.npv(rate, cashflow)
29
+
30
+ def time_broadcast(self, n_cashflows, cashflow_lengths, rates_lengths):
31
+ npf.npv(self.rates, self.cashflows)
tasks/tasksmith-a7e859277e7a/solution/reference/numpy_financial/_financial.py ADDED
@@ -0,0 +1,1041 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Some simple financial calculations.
2
+
3
+ patterned after spreadsheet computations.
4
+
5
+ There is some complexity in each function
6
+ so that the functions behave like ufuncs with
7
+ broadcasting and being able to be called with scalars
8
+ or arrays (or other sequences).
9
+
10
+ Functions support the :class:`decimal.Decimal` type unless
11
+ otherwise stated.
12
+ """
13
+
14
+ from decimal import Decimal
15
+
16
+ import numba as nb
17
+ import numpy as np
18
+
19
+ __all__ = ['fv', 'pmt', 'nper', 'ipmt', 'ppmt', 'pv', 'rate',
20
+ 'irr', 'npv', 'mirr',
21
+ 'NoRealSolutionError', 'IterationsExceededError']
22
+
23
+ _when_to_num = {'end': 0, 'begin': 1,
24
+ 'e': 0, 'b': 1,
25
+ 0: 0, 1: 1,
26
+ 'beginning': 1,
27
+ 'start': 1,
28
+ 'finish': 0}
29
+
30
+
31
+ class NoRealSolutionError(Exception):
32
+ """No real solution to the problem."""
33
+
34
+
35
+ class IterationsExceededError(Exception):
36
+ """Maximum number of iterations reached."""
37
+
38
+
39
+ def _get_output_array_shape(*arrays):
40
+ return tuple(array.shape[0] for array in arrays)
41
+
42
+
43
+ def _ufunc_like(array):
44
+ try:
45
+ # If size of array is one, return scalar
46
+ return array.item()
47
+ except ValueError:
48
+ # Otherwise, return entire array
49
+ return array.squeeze()
50
+
51
+
52
+ def _convert_when(when):
53
+ # Test to see if when has already been converted to ndarray
54
+ # This will happen if one function calls another, for example ppmt
55
+ if isinstance(when, np.ndarray):
56
+ return when
57
+ try:
58
+ return _when_to_num[when]
59
+ except (KeyError, TypeError):
60
+ return [_when_to_num[x] for x in when]
61
+
62
+
63
+ def fv(rate, nper, pmt, pv, when='end'):
64
+ """Compute the future value.
65
+
66
+ Given:
67
+ * a present value, `pv`
68
+ * an interest `rate` compounded once per period, of which
69
+ there are
70
+ * `nper` total
71
+ * a (fixed) payment, `pmt`, paid either
72
+ * at the beginning (`when` = {'begin', 1}) or the end
73
+ (`when` = {'end', 0}) of each period
74
+
75
+ Return:
76
+ the value at the end of the `nper` periods
77
+
78
+ Parameters
79
+ ----------
80
+ rate : scalar or array_like of shape(M, )
81
+ Rate of interest as decimal (not per cent) per period
82
+ nper : scalar or array_like of shape(M, )
83
+ Number of compounding periods
84
+ pmt : scalar or array_like of shape(M, )
85
+ Payment
86
+ pv : scalar or array_like of shape(M, )
87
+ Present value
88
+ when : {{'begin', 1}, {'end', 0}}, {string, int}, optional
89
+ When payments are due ('begin' (1) or 'end' (0)).
90
+ Defaults to {'end', 0}.
91
+
92
+ Returns
93
+ -------
94
+ out : ndarray
95
+ Future values. If all input is scalar, returns a scalar float. If
96
+ any input is array_like, returns future values for each input element.
97
+ If multiple inputs are array_like, they all must have the same shape.
98
+
99
+ Notes
100
+ -----
101
+ The future value is computed by solving the equation::
102
+
103
+ fv +
104
+ pv*(1+rate)**nper +
105
+ pmt*(1 + rate*when)/rate*((1 + rate)**nper - 1) == 0
106
+
107
+ or, when ``rate == 0``::
108
+
109
+ fv + pv + pmt * nper == 0
110
+
111
+ References
112
+ ----------
113
+ .. [WRW] Wheeler, D. A., E. Rathke, and R. Weir (Eds.) (2009, May).
114
+ Open Document Format for Office Applications (OpenDocument)v1.2,
115
+ Part 2: Recalculated Formula (OpenFormula) Format - Annotated Version,
116
+ Pre-Draft 12. Organization for the Advancement of Structured Information
117
+ Standards (OASIS). Billerica, MA, USA. [ODT Document].
118
+ Available:
119
+ http://www.oasis-open.org/committees/documents.php?wg_abbrev=office-formula
120
+ OpenDocument-formula-20090508.odt
121
+
122
+ Examples
123
+ --------
124
+ >>> import numpy as np
125
+ >>> import numpy_financial as npf
126
+
127
+ What is the future value after 10 years of saving $100 now, with
128
+ an additional monthly savings of $100. Assume the interest rate is
129
+ 5% (annually) compounded monthly?
130
+
131
+ >>> npf.fv(0.05/12, 10*12, -100, -100)
132
+ 15692.92889433575
133
+
134
+ By convention, the negative sign represents cash flow out (i.e. money not
135
+ available today). Thus, saving $100 a month at 5% annual interest leads
136
+ to $15,692.93 available to spend in 10 years.
137
+
138
+ If any input is array_like, returns an array of equal shape. Let's
139
+ compare different interest rates from the example above.
140
+
141
+ >>> a = np.array((0.05, 0.06, 0.07))/12
142
+ >>> npf.fv(a, 10*12, -100, -100)
143
+ array([15692.92889434, 16569.87435405, 17509.44688102])
144
+
145
+ """
146
+ when = _convert_when(when)
147
+ rate, nper, pmt, pv, when = np.broadcast_arrays(rate, nper, pmt, pv, when)
148
+
149
+ fv_array = np.empty_like(rate)
150
+ zero = rate == 0
151
+ nonzero = ~zero
152
+
153
+ fv_array[zero] = -(pv[zero] + pmt[zero] * nper[zero])
154
+
155
+ rate_nonzero = rate[nonzero]
156
+ temp = (1 + rate_nonzero) ** nper[nonzero]
157
+ fv_array[nonzero] = (
158
+ - pv[nonzero] * temp
159
+ - pmt[nonzero] * (1 + rate_nonzero * when[nonzero]) / rate_nonzero
160
+ * (temp - 1)
161
+ )
162
+
163
+ if np.ndim(fv_array) == 0:
164
+ # Follow the ufunc convention of returning scalars for scalar
165
+ # and 0d array inputs.
166
+ return fv_array.item(0)
167
+ return fv_array
168
+
169
+
170
+ def pmt(rate, nper, pv, fv=0, when='end'):
171
+ """Compute the payment against loan principal plus interest.
172
+
173
+ Given:
174
+ * a present value, `pv` (e.g., an amount borrowed)
175
+ * a future value, `fv` (e.g., 0)
176
+ * an interest `rate` compounded once per period, of which
177
+ there are
178
+ * `nper` total
179
+ * and (optional) specification of whether payment is made
180
+ at the beginning (`when` = {'begin', 1}) or the end
181
+ (`when` = {'end', 0}) of each period
182
+
183
+ Return:
184
+ the (fixed) periodic payment.
185
+
186
+ Parameters
187
+ ----------
188
+ rate : array_like
189
+ Rate of interest (per period)
190
+ nper : array_like
191
+ Number of compounding periods
192
+ pv : array_like
193
+ Present value
194
+ fv : array_like, optional
195
+ Future value (default = 0)
196
+ when : {{'begin', 1}, {'end', 0}}, {string, int}
197
+ When payments are due ('begin' (1) or 'end' (0))
198
+
199
+ Returns
200
+ -------
201
+ out : ndarray
202
+ Payment against loan plus interest. If all input is scalar, returns a
203
+ scalar float. If any input is array_like, returns payment for each
204
+ input element. If multiple inputs are array_like, they all must have
205
+ the same shape.
206
+
207
+ Notes
208
+ -----
209
+ The payment is computed by solving the equation::
210
+
211
+ fv +
212
+ pv*(1 + rate)**nper +
213
+ pmt*(1 + rate*when)/rate*((1 + rate)**nper - 1) == 0
214
+
215
+ or, when ``rate == 0``::
216
+
217
+ fv + pv + pmt * nper == 0
218
+
219
+ for ``pmt``.
220
+
221
+ Note that computing a monthly mortgage payment is only
222
+ one use for this function. For example, pmt returns the
223
+ periodic deposit one must make to achieve a specified
224
+ future balance given an initial deposit, a fixed,
225
+ periodically compounded interest rate, and the total
226
+ number of periods.
227
+
228
+ References
229
+ ----------
230
+ .. [WRW] Wheeler, D. A., E. Rathke, and R. Weir (Eds.) (2009, May).
231
+ Open Document Format for Office Applications (OpenDocument)v1.2,
232
+ Part 2: Recalculated Formula (OpenFormula) Format - Annotated Version,
233
+ Pre-Draft 12. Organization for the Advancement of Structured Information
234
+ Standards (OASIS). Billerica, MA, USA. [ODT Document].
235
+ Available:
236
+ http://www.oasis-open.org/committees/documents.php
237
+ ?wg_abbrev=office-formulaOpenDocument-formula-20090508.odt
238
+
239
+ Examples
240
+ --------
241
+ >>> import numpy_financial as npf
242
+
243
+ What is the monthly payment needed to pay off a $200,000 loan in 15
244
+ years at an annual interest rate of 7.5%?
245
+
246
+ >>> npf.pmt(0.075/12, 12*15, 200000)
247
+ -1854.0247200054619
248
+
249
+ In order to pay-off (i.e., have a future-value of 0) the $200,000 obtained
250
+ today, a monthly payment of $1,854.02 would be required. Note that this
251
+ example illustrates usage of `fv` having a default value of 0.
252
+
253
+ """
254
+ when = _convert_when(when)
255
+ (rate, nper, pv, fv, when) = map(np.array, [rate, nper, pv, fv, when])
256
+ temp = (1 + rate) ** nper
257
+ mask = (rate == 0)
258
+ masked_rate = np.where(mask, 1, rate)
259
+ fact = np.where(mask != 0, nper,
260
+ (1 + masked_rate * when) * (temp - 1) / masked_rate)
261
+ return -(fv + pv * temp) / fact
262
+
263
+
264
+ def nper(rate, pmt, pv, fv=0, when='end'):
265
+ """Compute the number of periodic payments.
266
+
267
+ :class:`decimal.Decimal` type is not supported.
268
+
269
+ Parameters
270
+ ----------
271
+ rate : array_like
272
+ Rate of interest (per period)
273
+ pmt : array_like
274
+ Payment
275
+ pv : array_like
276
+ Present value
277
+ fv : array_like, optional
278
+ Future value
279
+ when : {{'begin', 1}, {'end', 0}}, {string, int}, optional
280
+ When payments are due ('begin' (1) or 'end' (0))
281
+
282
+ Notes
283
+ -----
284
+ The number of periods ``nper`` is computed by solving the equation::
285
+
286
+ fv + pv*(1+rate)**nper + pmt*(1+rate*when)/rate*((1+rate)**nper-1) = 0
287
+
288
+ but if ``rate = 0`` then::
289
+
290
+ fv + pv + pmt*nper = 0
291
+
292
+ Examples
293
+ --------
294
+ >>> import numpy as np
295
+ >>> import numpy_financial as npf
296
+
297
+ If you only had $150/month to pay towards the loan, how long would it take
298
+ to pay-off a loan of $8,000 at 7% annual interest?
299
+
300
+ >>> print(np.round(npf.nper(0.07/12, -150, 8000), 5))
301
+ 64.07335
302
+
303
+ So, over 64 months would be required to pay off the loan.
304
+
305
+ The same analysis could be done with several different interest rates
306
+ and/or payments and/or total amounts to produce an entire table.
307
+
308
+ >>> npf.nper(*(np.ogrid[0.07/12: 0.08/12: 0.01/12,
309
+ ... -150 : -99 : 50 ,
310
+ ... 8000 : 9001 : 1000]))
311
+ array([[[ 64.07334877, 74.06368256],
312
+ [108.07548412, 127.99022654]],
313
+ <BLANKLINE>
314
+ [[ 66.12443902, 76.87897353],
315
+ [114.70165583, 137.90124779]]])
316
+ """
317
+ when = _convert_when(when)
318
+ rate, pmt, pv, fv, when = np.broadcast_arrays(rate, pmt, pv, fv, when)
319
+ nper_array = np.empty_like(rate, dtype=np.float64)
320
+
321
+ zero = rate == 0
322
+ nonzero = ~zero
323
+
324
+ with np.errstate(divide='ignore'):
325
+ # Infinite numbers of payments are okay, so ignore the
326
+ # potential divide by zero.
327
+ nper_array[zero] = -(fv[zero] + pv[zero]) / pmt[zero]
328
+
329
+ nonzero_rate = rate[nonzero]
330
+ z = pmt[nonzero] * (1 + nonzero_rate * when[nonzero]) / nonzero_rate
331
+ nper_array[nonzero] = (
332
+ np.log((-fv[nonzero] + z) / (pv[nonzero] + z))
333
+ / np.log(1 + nonzero_rate)
334
+ )
335
+
336
+ return nper_array
337
+
338
+
339
+ def _value_like(arr, value):
340
+ entry = arr.item(0)
341
+ if isinstance(entry, Decimal):
342
+ return Decimal(value)
343
+ return np.array(value, dtype=arr.dtype).item(0)
344
+
345
+
346
+ def ipmt(rate, per, nper, pv, fv=0, when='end'):
347
+ """Compute the interest portion of a payment.
348
+
349
+ Parameters
350
+ ----------
351
+ rate : scalar or array_like of shape(M, )
352
+ Rate of interest as decimal (not per cent) per period
353
+ per : scalar or array_like of shape(M, )
354
+ Interest paid against the loan changes during the life or the loan.
355
+ The `per` is the payment period to calculate the interest amount.
356
+ nper : scalar or array_like of shape(M, )
357
+ Number of compounding periods
358
+ pv : scalar or array_like of shape(M, )
359
+ Present value
360
+ fv : scalar or array_like of shape(M, ), optional
361
+ Future value
362
+ when : {{'begin', 1}, {'end', 0}}, {string, int}, optional
363
+ When payments are due ('begin' (1) or 'end' (0)).
364
+ Defaults to {'end', 0}.
365
+
366
+ Returns
367
+ -------
368
+ out : ndarray
369
+ Interest portion of payment. If all input is scalar, returns a scalar
370
+ float. If any input is array_like, returns interest payment for each
371
+ input element. If multiple inputs are array_like, they all must have
372
+ the same shape.
373
+
374
+ See Also
375
+ --------
376
+ ppmt, pmt, pv
377
+
378
+ Notes
379
+ -----
380
+ The total payment is made up of payment against principal plus interest.
381
+
382
+ ``pmt = ppmt + ipmt``
383
+
384
+ Examples
385
+ --------
386
+ >>> import numpy as np
387
+ >>> import numpy_financial as npf
388
+
389
+ What is the amortization schedule for a 1 year loan of $2500 at
390
+ 8.24% interest per year compounded monthly?
391
+
392
+ >>> principal = 2500.00
393
+
394
+ The 'per' variable represents the periods of the loan. Remember that
395
+ financial equations start the period count at 1!
396
+
397
+ >>> per = np.arange(1*12) + 1
398
+ >>> ipmt = npf.ipmt(0.0824/12, per, 1*12, principal)
399
+ >>> ppmt = npf.ppmt(0.0824/12, per, 1*12, principal)
400
+
401
+ Each element of the sum of the 'ipmt' and 'ppmt' arrays should equal
402
+ 'pmt'.
403
+
404
+ >>> pmt = npf.pmt(0.0824/12, 1*12, principal)
405
+ >>> np.allclose(ipmt + ppmt, pmt)
406
+ True
407
+
408
+ >>> fmt = '{0:2d} {1:8.2f} {2:8.2f} {3:8.2f}'
409
+ >>> for payment in per:
410
+ ... index = payment - 1
411
+ ... principal = principal + ppmt[index]
412
+ ... print(fmt.format(payment, ppmt[index], ipmt[index], principal))
413
+ 1 -200.58 -17.17 2299.42
414
+ 2 -201.96 -15.79 2097.46
415
+ 3 -203.35 -14.40 1894.11
416
+ 4 -204.74 -13.01 1689.37
417
+ 5 -206.15 -11.60 1483.22
418
+ 6 -207.56 -10.18 1275.66
419
+ 7 -208.99 -8.76 1066.67
420
+ 8 -210.42 -7.32 856.25
421
+ 9 -211.87 -5.88 644.38
422
+ 10 -213.32 -4.42 431.05
423
+ 11 -214.79 -2.96 216.26
424
+ 12 -216.26 -1.49 -0.00
425
+
426
+ >>> interestpd = np.sum(ipmt)
427
+ >>> np.round(interestpd, 2)
428
+ -112.98
429
+
430
+ """
431
+ when = _convert_when(when)
432
+ rate, per, nper, pv, fv, when = np.broadcast_arrays(rate, per, nper,
433
+ pv, fv, when)
434
+
435
+ total_pmt = pmt(rate, nper, pv, fv, when)
436
+ ipmt_array = np.array(_rbl(rate, per, total_pmt, pv, when) * rate)
437
+
438
+ # Payments start at the first period, so payments before that
439
+ # don't make any sense.
440
+ ipmt_array[per < 1] = _value_like(ipmt_array, np.nan)
441
+ # If payments occur at the beginning of a period and this is the
442
+ # first period, then no interest has accrued.
443
+ per1_and_begin = (when == 1) & (per == 1)
444
+ ipmt_array[per1_and_begin] = _value_like(ipmt_array, 0)
445
+ # If paying at the beginning we need to discount by one period.
446
+ per_gt_1_and_begin = (when == 1) & (per > 1)
447
+ ipmt_array[per_gt_1_and_begin] = (
448
+ ipmt_array[per_gt_1_and_begin] / (1 + rate[per_gt_1_and_begin])
449
+ )
450
+
451
+ if np.ndim(ipmt_array) == 0:
452
+ # Follow the ufunc convention of returning scalars for scalar
453
+ # and 0d array inputs.
454
+ return ipmt_array.item(0)
455
+ return ipmt_array
456
+
457
+
458
+ def _rbl(rate, per, pmt, pv, when):
459
+ """Remaining balance on loan.
460
+
461
+ This function is here to simply have a different name for the 'fv'
462
+ function to not interfere with the 'fv' keyword argument within the 'ipmt'
463
+ function. It is the 'remaining balance on loan' which might be useful as
464
+ it's own function, but is easily calculated with the 'fv' function.
465
+ """
466
+ return fv(rate, (per - 1), pmt, pv, when)
467
+
468
+
469
+ def ppmt(rate, per, nper, pv, fv=0, when='end'):
470
+ """Compute the payment against loan principle.
471
+
472
+ Parameters
473
+ ----------
474
+ rate : array_like
475
+ Rate of interest (per period)
476
+ per : array_like, int
477
+ Amount paid against the loan changes. The `per` is the period of
478
+ interest.
479
+ nper : array_like
480
+ Number of compounding periods
481
+ pv : array_like
482
+ Present value
483
+ fv : array_like, optional
484
+ Future value
485
+ when : {{'begin', 1}, {'end', 0}}, {string, int}
486
+ When payments are due ('begin' (1) or 'end' (0))
487
+
488
+ See Also
489
+ --------
490
+ pmt, pv, ipmt
491
+
492
+ """
493
+ total = pmt(rate, nper, pv, fv, when)
494
+ return total - ipmt(rate, per, nper, pv, fv, when)
495
+
496
+
497
+ def pv(rate, nper, pmt, fv=0, when='end'):
498
+ """Compute the present value.
499
+
500
+ Given:
501
+ * a future value, `fv`
502
+ * an interest `rate` compounded once per period, of which
503
+ there are
504
+ * `nper` total
505
+ * a (fixed) payment, `pmt`, paid either
506
+ * at the beginning (`when` = {'begin', 1}) or the end
507
+ (`when` = {'end', 0}) of each period
508
+
509
+ Return:
510
+ the value now
511
+
512
+ Parameters
513
+ ----------
514
+ rate : array_like
515
+ Rate of interest (per period)
516
+ nper : array_like
517
+ Number of compounding periods
518
+ pmt : array_like
519
+ Payment
520
+ fv : array_like, optional
521
+ Future value
522
+ when : {{'begin', 1}, {'end', 0}}, {string, int}, optional
523
+ When payments are due ('begin' (1) or 'end' (0))
524
+
525
+ Returns
526
+ -------
527
+ out : ndarray, float
528
+ Present value of a series of payments or investments.
529
+
530
+ Notes
531
+ -----
532
+ The present value is computed by solving the equation::
533
+
534
+ fv +
535
+ pv*(1 + rate)**nper +
536
+ pmt*(1 + rate*when)/rate*((1 + rate)**nper - 1) = 0
537
+
538
+ or, when ``rate = 0``::
539
+
540
+ fv + pv + pmt * nper = 0
541
+
542
+ for `pv`, which is then returned.
543
+
544
+ References
545
+ ----------
546
+ .. [WRW] Wheeler, D. A., E. Rathke, and R. Weir (Eds.) (2009, May).
547
+ Open Document Format for Office Applications (OpenDocument)v1.2,
548
+ Part 2: Recalculated Formula (OpenFormula) Format - Annotated Version,
549
+ Pre-Draft 12. Organization for the Advancement of Structured Information
550
+ Standards (OASIS). Billerica, MA, USA. [ODT Document].
551
+ Available:
552
+ http://www.oasis-open.org/committees/documents.php?wg_abbrev=office-formula
553
+ OpenDocument-formula-20090508.odt
554
+
555
+ Examples
556
+ --------
557
+ >>> import numpy as np
558
+ >>> import numpy_financial as npf
559
+
560
+ What is the present value (e.g., the initial investment)
561
+ of an investment that needs to total $15692.93
562
+ after 10 years of saving $100 every month? Assume the
563
+ interest rate is 5% (annually) compounded monthly.
564
+
565
+ >>> npf.pv(0.05/12, 10*12, -100, 15692.93)
566
+ -100.00067131625819
567
+
568
+ By convention, the negative sign represents cash flow out
569
+ (i.e., money not available today). Thus, to end up with
570
+ $15,692.93 in 10 years saving $100 a month at 5% annual
571
+ interest, one's initial deposit should also be $100.
572
+
573
+ If any input is array_like, ``pv`` returns an array of equal shape.
574
+ Let's compare different interest rates in the example above:
575
+
576
+ >>> a = np.array((0.05, 0.04, 0.03))/12
577
+ >>> npf.pv(a, 10*12, -100, 15692.93)
578
+ array([ -100.00067132, -649.26771385, -1273.78633713])
579
+
580
+ So, to end up with the same $15692.93 under the same $100 per month
581
+ "savings plan," for annual interest rates of 4% and 3%, one would
582
+ need initial investments of $649.27 and $1273.79, respectively.
583
+
584
+ """
585
+ when = _convert_when(when)
586
+ (rate, nper, pmt, fv, when) = map(np.asarray, [rate, nper, pmt, fv, when])
587
+ temp = (1 + rate) ** nper
588
+ fact = np.where(rate == 0, nper, (1 + rate * when) * (temp - 1) / rate)
589
+ return -(fv + pmt * fact) / temp
590
+
591
+
592
+ # Computed with Sage
593
+ # (y + (r + 1)^n*x + p*((r + 1)^n - 1)*(r*w + 1)/r)/(n*(r + 1)^(n - 1)*x -
594
+ # p*((r + 1)^n - 1)*(r*w + 1)/r^2 + n*p*(r + 1)^(n - 1)*(r*w + 1)/r +
595
+ # p*((r + 1)^n - 1)*w/r)
596
+
597
+
598
+ def _g_div_gp(r, n, p, x, y, w):
599
+ # Evaluate g(r_n)/g'(r_n), where g =
600
+ # fv + pv*(1+rate)**nper + pmt*(1+rate*when)/rate * ((1+rate)**nper - 1)
601
+ t1 = (r + 1) ** n
602
+ t2 = (r + 1) ** (n - 1)
603
+ g = y + t1 * x + p * (t1 - 1) * (r * w + 1) / r
604
+ gp = (n * t2 * x
605
+ - p * (t1 - 1) * (r * w + 1) / (r ** 2)
606
+ + n * p * t2 * (r * w + 1) / r
607
+ + p * (t1 - 1) * w / r)
608
+ return g / gp
609
+
610
+
611
+ # Use Newton's iteration until the change is less than 1e-6
612
+ # for all values or a maximum of 100 iterations is reached.
613
+ # Newton's rule is
614
+ # r_{n+1} = r_{n} - g(r_n)/g'(r_n)
615
+ # where
616
+ # g(r) is the formula
617
+ # g'(r) is the derivative with respect to r.
618
+ def rate(
619
+ nper,
620
+ pmt,
621
+ pv,
622
+ fv,
623
+ when='end',
624
+ guess=None,
625
+ tol=None,
626
+ maxiter=100,
627
+ *,
628
+ raise_exceptions=False):
629
+ """Compute the rate of interest per period.
630
+
631
+ Parameters
632
+ ----------
633
+ nper : array_like
634
+ Number of compounding periods
635
+ pmt : array_like
636
+ Payment
637
+ pv : array_like
638
+ Present value
639
+ fv : array_like
640
+ Future value
641
+ when : {{'begin', 1}, {'end', 0}}, {string, int}, optional
642
+ When payments are due ('begin' (1) or 'end' (0))
643
+ guess : Number, optional
644
+ Starting guess for solving the rate of interest, default 0.1
645
+ tol : Number, optional
646
+ Required tolerance for the solution, default 1e-6
647
+ maxiter : int, optional
648
+ Maximum iterations in finding the solution
649
+ raise_exceptions: bool, optional
650
+ Flag to raise an exception when at least one of the rates
651
+ cannot be computed due to having reached the maximum number of
652
+ iterations (IterationsExceededException). Set to False as default,
653
+ thus returning NaNs for those rates.
654
+
655
+ Notes
656
+ -----
657
+ The rate of interest is computed by iteratively solving the
658
+ (non-linear) equation::
659
+
660
+ fv + pv*(1+rate)**nper + pmt*(1+rate*when)/rate * ((1+rate)**nper - 1) = 0
661
+
662
+ for ``rate``.
663
+
664
+ References
665
+ ----------
666
+ Wheeler, D. A., E. Rathke, and R. Weir (Eds.) (2009, May). Open Document
667
+ Format for Office Applications (OpenDocument)v1.2, Part 2: Recalculated
668
+ Formula (OpenFormula) Format - Annotated Version, Pre-Draft 12.
669
+ Organization for the Advancement of Structured Information Standards
670
+ (OASIS). Billerica, MA, USA. [ODT Document]. Available:
671
+ http://www.oasis-open.org/committees/documents.php?wg_abbrev=office-formula
672
+ OpenDocument-formula-20090508.odt
673
+
674
+ """
675
+ when = _convert_when(when)
676
+ default_type = Decimal if isinstance(pmt, Decimal) else float
677
+
678
+ # Handle casting defaults to Decimal if/when pmt is a Decimal and
679
+ # guess and/or tol are not given default values
680
+ if guess is None:
681
+ guess = default_type('0.1')
682
+
683
+ if tol is None:
684
+ tol = default_type('1e-6')
685
+
686
+ (nper, pmt, pv, fv, when) = map(np.asarray, [nper, pmt, pv, fv, when])
687
+
688
+ rn = guess
689
+ iterator = 0
690
+ close = False
691
+ while (iterator < maxiter) and not np.all(close):
692
+ rnp1 = rn - _g_div_gp(rn, nper, pmt, pv, fv, when)
693
+ diff = abs(rnp1 - rn)
694
+ close = diff < tol
695
+ iterator += 1
696
+ rn = rnp1
697
+
698
+ if not np.all(close):
699
+ if np.isscalar(rn):
700
+ if raise_exceptions:
701
+ raise IterationsExceededError('Maximum number of iterations exceeded.')
702
+ return default_type(np.nan)
703
+ else:
704
+ # Return nan's in array of the same shape as rn
705
+ # where the solution is not close to tol.
706
+ if raise_exceptions:
707
+ raise IterationsExceededError(f'Maximum iterations exceeded in '
708
+ f'{len(close) - close.sum()} rate(s).')
709
+ rn[~close] = np.nan
710
+ return rn
711
+
712
+
713
+ def irr(values, *, guess=None, tol=1e-12, maxiter=100, raise_exceptions=False):
714
+ r"""Return the Internal Rate of Return (IRR).
715
+
716
+ This is the "average" periodically compounded rate of return
717
+ that gives a net present value of 0.0; for a more complete explanation,
718
+ see Notes below.
719
+
720
+ :class:`decimal.Decimal` type is not supported.
721
+
722
+ Parameters
723
+ ----------
724
+ values : array_like, shape(N,)
725
+ Input cash flows per time period. By convention, net "deposits"
726
+ are negative and net "withdrawals" are positive. Thus, for
727
+ example, at least the first element of `values`, which represents
728
+ the initial investment, will typically be negative.
729
+ guess : float, optional
730
+ Initial guess of the IRR for the iterative solver. If no guess is
731
+ given an heuristic is used to estimate the guess through the ratio of
732
+ positive to negative cash lows
733
+ tol : float, optional
734
+ Required tolerance to accept solution. Default is 1e-12.
735
+ maxiter : int, optional
736
+ Maximum iterations to perform in finding a solution. Default is 100.
737
+ raise_exceptions: bool, optional
738
+ Flag to raise an exception when the irr cannot be computed due to
739
+ either having all cashflows of the same sign (NoRealSolutionException) or
740
+ having reached the maximum number of iterations (IterationsExceededException).
741
+ Set to False as default, thus returning NaNs in the two previous
742
+ cases.
743
+
744
+ Returns
745
+ -------
746
+ out : float
747
+ Internal Rate of Return for periodic input values.
748
+
749
+ Notes
750
+ -----
751
+ The IRR is perhaps best understood through an example (illustrated
752
+ using np.irr in the Examples section below). Suppose one invests 100
753
+ units and then makes the following withdrawals at regular (fixed)
754
+ intervals: 39, 59, 55, 20. Assuming the ending value is 0, one's 100
755
+ unit investment yields 173 units; however, due to the combination of
756
+ compounding and the periodic withdrawals, the "average" rate of return
757
+ is neither simply 0.73/4 nor (1.73)^0.25-1. Rather, it is the solution
758
+ (for :math:`r`) of the equation:
759
+
760
+ .. math:: -100 + \\frac{39}{1+r} + \\frac{59}{(1+r)^2}
761
+ + \\frac{55}{(1+r)^3} + \\frac{20}{(1+r)^4} = 0
762
+
763
+ In general, for `values` :math:`= [v_0, v_1, ... v_M]`,
764
+ irr is the solution of the equation: [G]_
765
+
766
+ .. math:: \\sum_{t=0}^M{\\frac{v_t}{(1+irr)^{t}}} = 0
767
+
768
+ References
769
+ ----------
770
+ .. [G] L. J. Gitman, "Principles of Managerial Finance, Brief," 3rd ed.,
771
+ Addison-Wesley, 2003, pg. 348.
772
+
773
+ Examples
774
+ --------
775
+ >>> import numpy_financial as npf
776
+
777
+ >>> round(npf.irr([-100, 39, 59, 55, 20]), 5)
778
+ 0.28095
779
+ >>> round(npf.irr([-100, 0, 0, 74]), 5)
780
+ -0.0955
781
+ >>> round(npf.irr([-100, 100, 0, -7]), 5)
782
+ -0.0833
783
+ >>> round(npf.irr([-100, 100, 0, 7]), 5)
784
+ 0.06206
785
+ >>> round(npf.irr([-5, 10.5, 1, -8, 1]), 5)
786
+ 0.0886
787
+
788
+ """
789
+ values = np.atleast_1d(values)
790
+ if values.ndim != 1:
791
+ raise ValueError("Cashflows must be a rank-1 array")
792
+
793
+ # If all values are of the same sign no solution exists
794
+ # we don't perform any further calculations and exit early
795
+ same_sign = np.all(values > 0) if values[0] > 0 else np.all(values < 0)
796
+ if same_sign:
797
+ if raise_exceptions:
798
+ raise NoRealSolutionError('No real solution exists for IRR since all '
799
+ 'cashflows are of the same sign.')
800
+ return np.nan
801
+
802
+ # If no value is passed for `guess`, then make a heuristic estimate
803
+ if guess is None:
804
+ positive_cashflow = values > 0
805
+ inflow = values.sum(where=positive_cashflow)
806
+ outflow = -values.sum(where=~positive_cashflow)
807
+ guess = inflow / outflow - 1
808
+
809
+ # We aim to solve eirr such that NPV is exactly zero. This can be framed as
810
+ # simply finding the closest root of a polynomial to a given initial guess
811
+ # as follows:
812
+ # V0 V1 V2 V3
813
+ # NPV = ---------- + ---------- + ---------- + ---------- + ... = 0
814
+ # (1+eirr)^0 (1+eirr)^1 (1+eirr)^2 (1+eirr)^3
815
+ #
816
+ # by letting g = (1+eirr), we substitute to get
817
+ #
818
+ # NPV = V0 * 1/g^0 + V1 * 1/g^1 + V2 * 1/x^2 + V3 * 1/g^3 + ... = 0
819
+ #
820
+ # Multiplying by g^N this becomes
821
+ #
822
+ # V0 * g^N + V1 * g^{N-1} + V2 * g^{N-2} + V3 * g^{N-3} + ... = 0
823
+ #
824
+ # which we solve using Newton-Raphson and then reverse out the solution
825
+ # as eirr = g - 1 (if we are close enough to a solution)
826
+ npv_ = np.polynomial.Polynomial(values[::-1])
827
+ d_npv = npv_.deriv()
828
+ g = 1 + guess
829
+
830
+ for _ in range(maxiter):
831
+ delta = npv_(g) / d_npv(g)
832
+ if abs(delta) < tol:
833
+ return g - 1
834
+ g -= delta
835
+
836
+ if raise_exceptions:
837
+ raise IterationsExceededError('Maximum number of iterations exceeded.')
838
+
839
+ return np.nan
840
+
841
+
842
+ @nb.njit
843
+ def _npv_native(rates, values, out):
844
+ for i in range(rates.shape[0]):
845
+ for j in range(values.shape[0]):
846
+ acc = 0.0
847
+ for t in range(values.shape[1]):
848
+ if rates[i] == -1.0:
849
+ acc = np.nan
850
+ break
851
+ else:
852
+ acc += values[j, t] / ((1.0 + rates[i]) ** t)
853
+ out[i, j] = acc
854
+
855
+
856
+ def npv(rate, values):
857
+ r"""Return the NPV (Net Present Value) of a cash flow series.
858
+
859
+ Parameters
860
+ ----------
861
+ rate : scalar or array_like shape(K, )
862
+ The discount rate.
863
+ values : array_like, shape(M, ) or shape(M, N)
864
+ The values of the time series of cash flows. The (fixed) time
865
+ interval between cash flow "events" must be the same as that for
866
+ which `rate` is given (i.e., if `rate` is per year, then precisely
867
+ a year is understood to elapse between each cash flow event). By
868
+ convention, investments or "deposits" are negative, income or
869
+ "withdrawals" are positive; `values` must begin with the initial
870
+ investment, thus `values[0]` will typically be negative.
871
+
872
+ Returns
873
+ -------
874
+ out : float or array shape(K, M)
875
+ The NPV of the input cash flow series `values` at the discount
876
+ `rate`. `out` follows the ufunc convention of returning scalars
877
+ instead of single element arrays.
878
+
879
+ Warnings
880
+ --------
881
+ ``npv`` considers a series of cashflows starting in the present (t = 0).
882
+ NPV can also be defined with a series of future cashflows, paid at the
883
+ end, rather than the start, of each period. If future cashflows are used,
884
+ the first cashflow `values[0]` must be zeroed and added to the net
885
+ present value of the future cashflows. This is demonstrated in the
886
+ examples.
887
+
888
+ Notes
889
+ -----
890
+ Returns the result of: [G]_
891
+
892
+ .. math :: \\sum_{t=0}^{M-1}{\\frac{values_t}{(1+rate)^{t}}}
893
+
894
+ References
895
+ ----------
896
+ .. [G] L. J. Gitman, "Principles of Managerial Finance, Brief," 3rd ed.,
897
+ Addison-Wesley, 2003, pg. 346.
898
+
899
+ Examples
900
+ --------
901
+ >>> import numpy as np
902
+ >>> import numpy_financial as npf
903
+
904
+ Consider a potential project with an initial investment of $40 000 and
905
+ projected cashflows of $5 000, $8 000, $12 000 and $30 000 at the end of
906
+ each period discounted at a rate of 8% per period. To find the project's
907
+ net present value:
908
+
909
+ >>> rate, cashflows = 0.08, [-40_000, 5_000, 8_000, 12_000, 30_000]
910
+ >>> np.round(npf.npv(rate, cashflows), 5)
911
+ 3065.22267
912
+
913
+ It may be preferable to split the projected cashflow into an initial
914
+ investment and expected future cashflows. In this case, the value of
915
+ the initial cashflow is zero and the initial investment is later added
916
+ to the future cashflows net present value:
917
+
918
+ >>> initial_cashflow = cashflows[0]
919
+ >>> cashflows[0] = 0
920
+ >>> np.round(npf.npv(rate, cashflows) + initial_cashflow, 5)
921
+ 3065.22267
922
+
923
+ The NPV calculation may be applied to several ``rates`` and ``cashflows``
924
+ simulatneously. This produces an array of shape ``(len(rates), len(cashflows))``.
925
+ >>> rates = [0.00, 0.05, 0.10]
926
+ >>> cashflows = [[-4_000, 500, 800], [-5_000, 600, 900]]
927
+ >>> npf.npv(rates, cashflows).round(2)
928
+ array([[-2700. , -3500. ],
929
+ [-2798.19, -3612.24],
930
+ [-2884.3 , -3710.74]])
931
+
932
+ """
933
+ values_inner = np.atleast_2d(values)
934
+ rate_inner = np.atleast_1d(rate)
935
+
936
+ if rate_inner.ndim != 1:
937
+ msg = "invalid shape for rates. Rate must be either a scalar or 1d array"
938
+ raise ValueError(msg)
939
+
940
+ if values_inner.ndim != 2:
941
+ msg = "invalid shape for values. Values must be either a 1d or 2d array"
942
+ raise ValueError(msg)
943
+
944
+ output_shape = _get_output_array_shape(rate_inner, values_inner)
945
+ out = np.empty(output_shape)
946
+ _npv_native(rate_inner, values_inner, out)
947
+ return _ufunc_like(out)
948
+
949
+
950
+ def mirr(values, finance_rate, reinvest_rate, *, raise_exceptions=False):
951
+ r"""
952
+ Return the Modified Internal Rate of Return (MIRR).
953
+
954
+ MIRR is a financial metric that takes into account both the cost of
955
+ the investment and the return on reinvested cash flows. It is useful
956
+ for evaluating the profitability of an investment with multiple cash
957
+ inflows and outflows.
958
+
959
+ Parameters
960
+ ----------
961
+ values : array_like
962
+ Cash flows, where the first value is considered a sunk cost at time zero.
963
+ It must contain at least one positive and one negative value.
964
+ finance_rate : scalar
965
+ Interest rate paid on the cash flows.
966
+ reinvest_rate : scalar
967
+ Interest rate received on the cash flows upon reinvestment.
968
+ raise_exceptions: bool, optional
969
+ Flag to raise an exception when the MIRR cannot be computed due to
970
+ having all cash flows of the same sign (NoRealSolutionException).
971
+ Set to False as default,thus returning NaNs in the previous case.
972
+
973
+ Returns
974
+ -------
975
+ out : float
976
+ Modified internal rate of return
977
+
978
+ Notes
979
+ -----
980
+ The MIRR formula is as follows:
981
+
982
+ .. math::
983
+
984
+ MIRR =
985
+ \\left( \\frac{{FV_{positive}}}{{PV_{negative}}} \\right)^{\\frac{{1}}{{n-1}}}
986
+ * (1+r) - 1
987
+
988
+ where:
989
+ - \(FV_{positive}\) is the future value of positive cash flows,
990
+ - \(PV_{negative}\) is the present value of negative cash flows,
991
+ - \(n\) is the number of periods.
992
+ - \(r\) is the reinvestment rate.
993
+
994
+ Examples
995
+ --------
996
+ >>> import numpy_financial as npf
997
+
998
+ Consider a project with an initial investment of -$100
999
+ and projected cash flows of $50, -$60, and $70 at the end of each period.
1000
+ The project has a finance rate of 10% and a reinvestment rate of 12%.
1001
+
1002
+ >>> npf.mirr([-100, 50, -60, 70], 0.10, 0.12)
1003
+ -0.03909366594356467
1004
+
1005
+ Now, let's consider the scenario where all cash flows are negative.
1006
+
1007
+ >>> npf.mirr([-100, -50, -60, -70], 0.10, 0.12)
1008
+ nan
1009
+
1010
+ Finally, let's explore the situation where all cash flows are positive,
1011
+ and the `raise_exceptions` parameter is set to True.
1012
+
1013
+ >>> npf.mirr([
1014
+ ... 100, 50, 60, 70],
1015
+ ... 0.10, 0.12,
1016
+ ... raise_exceptions=True
1017
+ ... ) #doctest: +NORMALIZE_WHITESPACE
1018
+ Traceback (most recent call last):
1019
+ ...
1020
+ numpy_financial._financial.NoRealSolutionError:
1021
+ No real solution exists for MIRR since all cashflows are of the same sign.
1022
+ """
1023
+ values = np.asarray(values)
1024
+ n = values.size
1025
+
1026
+ # Without this explicit cast the 1/(n - 1) computation below
1027
+ # becomes a float, which causes TypeError when using Decimal
1028
+ # values.
1029
+ if isinstance(finance_rate, Decimal):
1030
+ n = Decimal(n)
1031
+
1032
+ pos = values > 0
1033
+ neg = values < 0
1034
+ if not (pos.any() and neg.any()):
1035
+ if raise_exceptions:
1036
+ raise NoRealSolutionError('No real solution exists for MIRR since'
1037
+ ' all cashflows are of the same sign.')
1038
+ return np.nan
1039
+ numer = np.abs(npv(reinvest_rate, values * pos))
1040
+ denom = np.abs(npv(finance_rate, values * neg))
1041
+ return (numer / denom) ** (1 / (n - 1)) * (1 + reinvest_rate) - 1
tasks/tasksmith-a7e859277e7a/solution/solve.sh ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ #!/bin/sh
2
+ set -eu
3
+ mkdir -p -- /workspace/benchmarks
4
+ cp /solution/reference/benchmarks/benchmarks.py /workspace/benchmarks/benchmarks.py
5
+ mkdir -p -- /workspace/numpy_financial
6
+ cp /solution/reference/numpy_financial/_financial.py /workspace/numpy_financial/_financial.py
tasks/tasksmith-a7e859277e7a/task.toml ADDED
@@ -0,0 +1,226 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ schema_version = "1.3"
2
+
3
+ [task]
4
+ name = "repo2rlenv/tasksmith-a7e859277e7a"
5
+
6
+ [metadata.repo2env]
7
+ recipe = "tasksmith"
8
+ recipe_version = "1"
9
+ source_url = "https://github.com/numpy/numpy-financial/pull/108"
10
+ source_head = "6b54195dadf216a7cb0e90238bdc4be042b06b1c"
11
+ source_base = "68960080799bad56c7c563497048051f97717f30"
12
+ workspace_strategy = "head_minus_source_patch"
13
+ source_diff_sha256 = "484414d0104267015b5bc89907d8cfe83ef316867ed2f0ac5958bf730a7fcdad"
14
+ acceptance_profile = "practical-generation-v1"
15
+ upstream_test_policy = "retain"
16
+ reward_kinds = [
17
+ "test_execution",
18
+ ]
19
+ quality_status = "exported"
20
+ fail_to_pass_count = 9
21
+ pass_to_pass_count = 3
22
+ tracked_files = [
23
+ "environment/Dockerfile",
24
+ "environment/source/.github/CODE_OF_CONDUCT.md",
25
+ "environment/source/.github/ISSUE_TEMPLATE/bug-report.yml",
26
+ "environment/source/.github/ISSUE_TEMPLATE/config.yml",
27
+ "environment/source/.github/ISSUE_TEMPLATE/documentation.yml",
28
+ "environment/source/.github/ISSUE_TEMPLATE/feature-request.yml",
29
+ "environment/source/.github/workflows/lint.yml",
30
+ "environment/source/.github/workflows/publish_docs_to_pages.yml",
31
+ "environment/source/.github/workflows/pythonpackage.yml",
32
+ "environment/source/Dockerfile",
33
+ "environment/source/LICENSE.txt",
34
+ "environment/source/README.md",
35
+ "environment/source/benchmarks/__init__.py",
36
+ "environment/source/benchmarks/benchmarks.py",
37
+ "environment/source/doc/Makefile",
38
+ "environment/source/doc/make.bat",
39
+ "environment/source/doc/source/_static/numpy_financial_favicon.png",
40
+ "environment/source/doc/source/_static/numpy_financial_logov.svg",
41
+ "environment/source/doc/source/conf.py",
42
+ "environment/source/doc/source/dev/building_with_poetry.md",
43
+ "environment/source/doc/source/dev/getting_the_code.md",
44
+ "environment/source/doc/source/dev/running_the_benchmarks.md",
45
+ "environment/source/doc/source/fv.rst",
46
+ "environment/source/doc/source/generate_rst_function_files.py",
47
+ "environment/source/doc/source/index.rst",
48
+ "environment/source/doc/source/ipmt.rst",
49
+ "environment/source/doc/source/irr.rst",
50
+ "environment/source/doc/source/mirr.rst",
51
+ "environment/source/doc/source/nper.rst",
52
+ "environment/source/doc/source/npv.rst",
53
+ "environment/source/doc/source/pmt.rst",
54
+ "environment/source/doc/source/ppmt.rst",
55
+ "environment/source/doc/source/pv.rst",
56
+ "environment/source/doc/source/rate.rst",
57
+ "environment/source/doc/source/release-notes.rst",
58
+ "environment/source/docweb/README.txt",
59
+ "environment/source/docweb/css/home.css",
60
+ "environment/source/docweb/images/numpy_financial_favicon.png",
61
+ "environment/source/docweb/images/numpy_financial_logoh.svg",
62
+ "environment/source/docweb/index.html",
63
+ "environment/source/numpy_financial/__init__.py",
64
+ "environment/source/numpy_financial/_financial.py",
65
+ "environment/source/pyproject.toml",
66
+ "solution/reference/benchmarks/benchmarks.py",
67
+ "solution/reference/numpy_financial/_financial.py",
68
+ "solution/solve.sh",
69
+ "tests/Dockerfile",
70
+ "tests/contract.json",
71
+ "tests/grade.py",
72
+ "tests/source/.github/CODE_OF_CONDUCT.md",
73
+ "tests/source/.github/ISSUE_TEMPLATE/bug-report.yml",
74
+ "tests/source/.github/ISSUE_TEMPLATE/config.yml",
75
+ "tests/source/.github/ISSUE_TEMPLATE/documentation.yml",
76
+ "tests/source/.github/ISSUE_TEMPLATE/feature-request.yml",
77
+ "tests/source/.github/workflows/lint.yml",
78
+ "tests/source/.github/workflows/publish_docs_to_pages.yml",
79
+ "tests/source/.github/workflows/pythonpackage.yml",
80
+ "tests/source/.gitignore",
81
+ "tests/source/Dockerfile",
82
+ "tests/source/LICENSE.txt",
83
+ "tests/source/README.md",
84
+ "tests/source/asv.conf.json",
85
+ "tests/source/benchmarks/__init__.py",
86
+ "tests/source/benchmarks/benchmarks.py",
87
+ "tests/source/doc/Makefile",
88
+ "tests/source/doc/make.bat",
89
+ "tests/source/doc/source/_static/numpy_financial_favicon.png",
90
+ "tests/source/doc/source/_static/numpy_financial_logov.svg",
91
+ "tests/source/doc/source/conf.py",
92
+ "tests/source/doc/source/dev/building_with_poetry.md",
93
+ "tests/source/doc/source/dev/getting_the_code.md",
94
+ "tests/source/doc/source/dev/running_the_benchmarks.md",
95
+ "tests/source/doc/source/fv.rst",
96
+ "tests/source/doc/source/generate_rst_function_files.py",
97
+ "tests/source/doc/source/index.rst",
98
+ "tests/source/doc/source/ipmt.rst",
99
+ "tests/source/doc/source/irr.rst",
100
+ "tests/source/doc/source/mirr.rst",
101
+ "tests/source/doc/source/nper.rst",
102
+ "tests/source/doc/source/npv.rst",
103
+ "tests/source/doc/source/pmt.rst",
104
+ "tests/source/doc/source/ppmt.rst",
105
+ "tests/source/doc/source/pv.rst",
106
+ "tests/source/doc/source/rate.rst",
107
+ "tests/source/doc/source/release-notes.rst",
108
+ "tests/source/docweb/README.txt",
109
+ "tests/source/docweb/css/home.css",
110
+ "tests/source/docweb/images/numpy_financial_favicon.png",
111
+ "tests/source/docweb/images/numpy_financial_logoh.svg",
112
+ "tests/source/docweb/index.html",
113
+ "tests/source/numpy_financial/__init__.py",
114
+ "tests/source/numpy_financial/_financial.py",
115
+ "tests/source/pyproject.toml",
116
+ "tests/source/tests/__init__.py",
117
+ "tests/source/tests/tasksmith_behavior.py",
118
+ "tests/source/tests/test_financial.py",
119
+ "tests/test.sh",
120
+ "tests/test_driver.py",
121
+ "tests/test_results.py",
122
+ ]
123
+ executable_files = [
124
+ "solution/solve.sh",
125
+ "tests/test.sh",
126
+ ]
127
+ bundle_hash = "sha256:5555bab1d34b5856c8d7248c1f7705f8b87d03c21f5ddd9aaa522e4b3cc98fe7"
128
+
129
+ [metadata.repo2env.evaluation]
130
+ schema_version = "1"
131
+ status = "verified"
132
+ stage = "complete"
133
+ reason_codes = [
134
+ "quality_verified",
135
+ ]
136
+ detail = "Reviewed controls, semantic probes and blind rollout passed the quality profile."
137
+ checked_at = "2026-11-20T08:51:20.293964Z"
138
+ provenance = "unknown"
139
+ subject_bundle_hash = "sha256:5555bab1d34b5856c8d7248c1f7705f8b87d03c21f5ddd9aaa522e4b3cc98fe7"
140
+ profile = "evidence-review-v2"
141
+ source_task_path = "/Users/ben/.t3/projects/harness-adapters-data/runs/apex-agents-gap/phase2/batch/candidates/abec33f28a9f/candidates/a7e859277e7a/quality/revisions/r0/tasksmith-a7e859277e7a"
142
+ source_task_toml_sha256 = "e7d7e762aae6e7f50bf52ad35a3415d97b7b90173749755e7b9f013038b8918f"
143
+
144
+ [[metadata.repo2env.evaluation.evidence]]
145
+ kind = "quality_result"
146
+ path = "/Users/ben/.t3/projects/harness-adapters-data/runs/apex-agents-gap/phase2/batch/candidates/abec33f28a9f/candidates/a7e859277e7a/quality/result.json"
147
+ sha256 = "9c9daf5f84e1215481be46b3d906594d52a87c7c955091f8e1a1471189957fbf"
148
+ subject_bundle_hash = "sha256:5555bab1d34b5856c8d7248c1f7705f8b87d03c21f5ddd9aaa522e4b3cc98fe7"
149
+
150
+ [[metadata.repo2env.evaluation.evidence]]
151
+ kind = "baseline"
152
+ path = "/Users/ben/.t3/projects/harness-adapters-data/runs/apex-agents-gap/phase2/batch/candidates/abec33f28a9f/candidates/a7e859277e7a/quality/trials/r0-baseline/tsbatch-195cc094e760-abec33f28a9f-q-a7e85927-r0-baseline/tasksmith-a7e859277e7a__PhjDxM2/result.json"
153
+ sha256 = "316ab4334889c85afcf1ce2cc2438d1aa78e5d30427286206369bfbd001ee0f4"
154
+ subject_bundle_hash = "sha256:5555bab1d34b5856c8d7248c1f7705f8b87d03c21f5ddd9aaa522e4b3cc98fe7"
155
+ harbor_task_checksum = "23d7489f6910f577e46d7b27371c8fed06f8138172cc75315b03e6f2a086ed21"
156
+
157
+ [[metadata.repo2env.evaluation.evidence]]
158
+ kind = "oracle"
159
+ path = "/Users/ben/.t3/projects/harness-adapters-data/runs/apex-agents-gap/phase2/batch/candidates/abec33f28a9f/candidates/a7e859277e7a/quality/trials/r0-oracle/tsbatch-195cc094e760-abec33f28a9f-q-a7e85927-r0-oracle/tasksmith-a7e859277e7a__b3oEZJF/result.json"
160
+ sha256 = "28b08ef41fe31d18c572fc389d4cfd62c5697e3c4d9ab7acb8df461193a02380"
161
+ subject_bundle_hash = "sha256:5555bab1d34b5856c8d7248c1f7705f8b87d03c21f5ddd9aaa522e4b3cc98fe7"
162
+ harbor_task_checksum = "23d7489f6910f577e46d7b27371c8fed06f8138172cc75315b03e6f2a086ed21"
163
+
164
+ [[metadata.repo2env.evaluation.evidence]]
165
+ kind = "probe"
166
+ path = "/Users/ben/.t3/projects/harness-adapters-data/runs/apex-agents-gap/phase2/batch/candidates/abec33f28a9f/candidates/a7e859277e7a/quality/trials/r0-probe0/tsbatch-195cc094e760-abec33f28a9f-q-a7e85927-r0-probe0/tasksmith-a7e859277e7a__XA3QBFN/result.json"
167
+ sha256 = "465fe1b6f8885bb3ec3f569b793c6f807cfd9c57049bb2c064b0c3ae5346d6cf"
168
+ subject_bundle_hash = "sha256:17e651606673a8cbcd967907d56b5ecf6b13343c1cbe64ec93f361a3e87568fa"
169
+ harbor_task_checksum = "f36345ed8cf96a20703e4e72fe4f49b948dbae0d8d9d83ee5e3bcc6393a6789d"
170
+
171
+ [[metadata.repo2env.evaluation.evidence]]
172
+ kind = "probe"
173
+ path = "/Users/ben/.t3/projects/harness-adapters-data/runs/apex-agents-gap/phase2/batch/candidates/abec33f28a9f/candidates/a7e859277e7a/quality/trials/r0-probe1/tsbatch-195cc094e760-abec33f28a9f-q-a7e85927-r0-probe1/tasksmith-a7e859277e7a__DyGRRoP/result.json"
174
+ sha256 = "a668473c46dcbf0412e4a274ca80301f995c4c0d37b5e5ea2b0a891c8194ecef"
175
+ subject_bundle_hash = "sha256:02e509deecac50d60168c13cb2195a966ed5bda9303aeb8d3a0dc94300964571"
176
+ harbor_task_checksum = "baacfaffd5bab7a849cb8f2c5fdb3ded6f8bf708058171b3568d1e094924634e"
177
+
178
+ [[metadata.repo2env.evaluation.evidence]]
179
+ kind = "rollout"
180
+ path = "/Users/ben/.t3/projects/harness-adapters-data/runs/apex-agents-gap/phase2/batch/candidates/abec33f28a9f/candidates/a7e859277e7a/quality/trials/r0-rollout/tsbatch-195cc094e760-abec33f28a9f-q-a7e85927-r0-rollout/tasksmith-a7e859277e7a__RyeHJuX/result.json"
181
+ sha256 = "0439947b3add72f8781322759173cee583335a01d336c78d683f2df3631ed05f"
182
+ subject_bundle_hash = "sha256:5555bab1d34b5856c8d7248c1f7705f8b87d03c21f5ddd9aaa522e4b3cc98fe7"
183
+ harbor_task_checksum = "23d7489f6910f577e46d7b27371c8fed06f8138172cc75315b03e6f2a086ed21"
184
+
185
+ [metadata.repo2env.quality_requirements]
186
+ probe_focus = [
187
+ "general",
188
+ ]
189
+
190
+ [environment]
191
+ cpus = 1
192
+ memory_mb = 2048
193
+ build_timeout_sec = 600
194
+ network_mode = "no-network"
195
+
196
+ [agent]
197
+ timeout_sec = 600
198
+ user = "learner"
199
+ network_mode = "no-network"
200
+
201
+ [verifier]
202
+ timeout_sec = 210
203
+ user = "root"
204
+ network_mode = "no-network"
205
+ environment_mode = "separate"
206
+
207
+ [verifier.environment]
208
+ network_mode = "no-network"
209
+ cpus = 2
210
+ memory_mb = 2048
211
+
212
+ [[artifacts]]
213
+ source = "/workspace/numpy_financial"
214
+ exclude = [
215
+ "__pycache__",
216
+ "*.pyc",
217
+ ".pytest_cache",
218
+ ]
219
+
220
+ [[artifacts]]
221
+ source = "/workspace/benchmarks/benchmarks.py"
222
+ exclude = [
223
+ "__pycache__",
224
+ "*.pyc",
225
+ ".pytest_cache",
226
+ ]
tasks/tasksmith-a7e859277e7a/tests/Dockerfile ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.12-slim
2
+ WORKDIR /workspace
3
+ RUN python -m pip install --no-cache-dir poetry-core==1.9.1 numba==0.68.1 llvmlite==0.50.0 numpy==2.5.5 pytest==8.3.5 'hypothesis[numpy]==6.99.11' 'pytest-xdist[psutil]==3.5.0'
4
+ COPY source /workspace
5
+ RUN python -m pip install --no-cache-dir -e .
6
+ ENV PYTHONDONTWRITEBYTECODE=1 PYTEST_DISABLE_PLUGIN_AUTOLOAD=1
7
+ ENV HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1 HF_DATASETS_OFFLINE=1
8
+ RUN useradd -m -u 1001 grader
9
+ COPY grade.py test_driver.py test_results.py contract.json test.sh /tests/
10
+ RUN chmod 755 /tests && chmod 644 /tests/*
tasks/tasksmith-a7e859277e7a/tests/contract.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"expected_passes": ["tests.tasksmith_behavior::test_npv_broadcasting_shape_and_values", "tests.tasksmith_behavior::test_npv_multiple_rates_single_cashflow_returns_1d", "tests.test_financial.TestNpv::test_fuzz", "tests.test_financial.TestNpv::test_invalid_cashflows_shape[cf0]", "tests.test_financial.TestNpv::test_invalid_cashflows_shape[cf1]", "tests.test_financial.TestNpv::test_invalid_rates_shape[rates0]", "tests.test_financial.TestNpv::test_invalid_rates_shape[rates1]", "tests.test_financial.TestNpv::test_rate_of_negative_one_returns_nan[-1.0]", "tests.test_financial.TestNpv::test_rate_of_negative_one_returns_nan[-1]", "tests.tasksmith_behavior::test_npv_scalar_rate_1d_cashflow_returns_scalar", "tests.tasksmith_behavior::test_npv_single_rate_multiple_cashflows_returns_1d", "tests.test_financial.TestNpv::test_npv"], "immutable_assets": {}, "optional_files": [], "pytest_args": [], "submitted_files": ["benchmarks/benchmarks.py", "numpy_financial/__init__.py", "numpy_financial/_financial.py"], "submitted_roots": ["numpy_financial"], "test_paths": ["tests/test_financial.py::TestNpv", "tests/tasksmith_behavior.py"], "timeout_sec": 180}
tasks/tasksmith-a7e859277e7a/tests/grade.py ADDED
@@ -0,0 +1,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Standalone trusted entry point; copied into each separate verifier image.
2
+
3
+ No Repo2RLEnv installation is needed to grade an exported task. Submitted Python
4
+ runs as an unprivileged user; this parent owns the result parser and reward file.
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import hashlib
10
+ import importlib.util
11
+ import json
12
+ import os
13
+ import signal
14
+ import stat
15
+ import subprocess
16
+ import sys
17
+ import tempfile
18
+ from pathlib import Path
19
+
20
+
21
+ def child_environment(temporary: str) -> dict[str, str]:
22
+ """Preserve prepared runtime assets without inheriting controller credentials."""
23
+ return {
24
+ **{
25
+ key: os.environ[key]
26
+ for key in (
27
+ "LD_LIBRARY_PATH",
28
+ "CUDA_VISIBLE_DEVICES",
29
+ "NVIDIA_VISIBLE_DEVICES",
30
+ "NVIDIA_DRIVER_CAPABILITIES",
31
+ "NCCL_SOCKET_IFNAME",
32
+ "GLOO_SOCKET_IFNAME",
33
+ "HF_HOME",
34
+ "HF_HUB_CACHE",
35
+ "HF_HUB_OFFLINE",
36
+ "TRANSFORMERS_OFFLINE",
37
+ "HF_DATASETS_OFFLINE",
38
+ )
39
+ if key in os.environ
40
+ },
41
+ "PATH": str(Path(sys.executable).parent) + ":/usr/local/bin:/usr/bin:/bin",
42
+ "HOME": temporary,
43
+ "PYTHONDONTWRITEBYTECODE": "1",
44
+ "PYTEST_DISABLE_PLUGIN_AUTOLOAD": "1",
45
+ }
46
+
47
+
48
+ def validate_submission(workspace: Path, contract: dict) -> None:
49
+ """Validate private staging and remove inert backups before importing Python."""
50
+ submitted = set(contract["submitted_files"])
51
+ backups: set[str] = set()
52
+ optional = submitted & set(contract.get("optional_files", []))
53
+ paths = submitted - optional
54
+ for relative in optional:
55
+ path = workspace / relative
56
+ if any(component.is_symlink() for component in (path, *path.parents)):
57
+ raise ValueError("Submitted source contains a symlink")
58
+ # Added standalone modules may be absent in the baseline. If supplied,
59
+ # apply the same regular-file and size checks as every required module.
60
+ if path.exists():
61
+ paths.add(relative)
62
+ roots = contract.get("submitted_roots", [])
63
+ immutable = contract.get("immutable_assets", {})
64
+ paths.update(immutable)
65
+ for relative in roots:
66
+ root = workspace / relative
67
+ if root.is_symlink() or not root.is_dir():
68
+ raise ValueError("Submitted source root is missing or linked")
69
+ for path in root.rglob("*"):
70
+ if path.is_symlink():
71
+ raise ValueError("Submitted source contains a symlink")
72
+ if path.is_dir():
73
+ continue
74
+ name = path.relative_to(workspace).as_posix()
75
+ if path.suffix != ".py" and name not in immutable:
76
+ if name not in submitted and path.name.endswith((".py.bak", ".py~")):
77
+ backups.add(name)
78
+ else:
79
+ raise ValueError("Only Python source files may be added")
80
+ paths.add(name)
81
+ for relative in sorted(paths):
82
+ path = workspace / relative
83
+ for component in (path, *path.parents):
84
+ if component.is_symlink():
85
+ raise ValueError("Submitted source contains a symlink")
86
+ if (
87
+ not path.is_file()
88
+ or not stat.S_ISREG(path.stat().st_mode)
89
+ or path.stat().st_size > 8 * 1024 * 1024
90
+ ):
91
+ raise ValueError("Submitted source is not a bounded regular file")
92
+ if (
93
+ relative in immutable
94
+ and hashlib.sha256(path.read_bytes()).hexdigest() != immutable[relative]
95
+ ):
96
+ raise ValueError("Non-Python source assets must remain unchanged")
97
+ if relative not in backups:
98
+ # os.chown doesn't exist on Windows. This module only ever runs for
99
+ # real inside the Linux verifier container (every other path here
100
+ # is an absolute container path); the guard exists so the tests
101
+ # that call validate_submission() directly can run on a Windows
102
+ # host without touching real container-only ownership semantics.
103
+ if sys.platform != "win32":
104
+ os.chown(path, 0, 0)
105
+ path.chmod(0o644)
106
+ # Only the verifier's collected copy is cleaned. The learner workspace and
107
+ # archived submission retain their bytes. Validate every path first so a
108
+ # backup cannot bypass linked, oversized, required, or immutable file checks.
109
+ for relative in sorted(backups):
110
+ (workspace / relative).unlink()
111
+
112
+
113
+ def main() -> None:
114
+ directory = Path("/tests")
115
+ parser_spec = importlib.util.spec_from_file_location(
116
+ "test_results", directory / "test_results.py"
117
+ )
118
+ parser = importlib.util.module_from_spec(parser_spec)
119
+ sys.modules[parser_spec.name] = parser
120
+ parser_spec.loader.exec_module(parser)
121
+ contract = json.loads((directory / "contract.json").read_text())
122
+ logs = Path("/logs/verifier")
123
+ logs.mkdir(parents=True, exist_ok=True)
124
+ logs.chmod(0o755)
125
+ reward = logs / "reward.txt"
126
+ reward.write_text("0\n")
127
+ reward.chmod(0o644)
128
+ try:
129
+ validate_submission(Path("/workspace"), contract)
130
+ except (ValueError, OSError) as exc:
131
+ (logs / "result.json").write_text(json.dumps({"passed": False, "reason": str(exc)}))
132
+ return
133
+ with tempfile.TemporaryDirectory(prefix="r2e-grade-") as temporary:
134
+ working = Path(temporary)
135
+ if sys.platform != "win32": # os.chown doesn't exist on Windows; see above
136
+ os.chown(working, 1001, 1001)
137
+ working.chmod(0o700)
138
+ report = working / "results.xml"
139
+ command = [
140
+ sys.executable,
141
+ "-I",
142
+ "/tests/test_driver.py",
143
+ *contract["test_paths"],
144
+ *contract.get("pytest_args", []),
145
+ "-q",
146
+ "--tb=short",
147
+ "-p",
148
+ "no:cacheprovider",
149
+ f"--junitxml={report}",
150
+ ]
151
+ with (logs / "stdout.txt").open("w") as stdout, (logs / "stderr.txt").open("w") as stderr:
152
+ process = subprocess.Popen(
153
+ command,
154
+ cwd="/workspace",
155
+ stdout=stdout,
156
+ stderr=stderr,
157
+ user=1001,
158
+ group=1001,
159
+ extra_groups=[],
160
+ start_new_session=True,
161
+ env=child_environment(temporary),
162
+ )
163
+ try:
164
+ code = process.wait(timeout=contract["timeout_sec"])
165
+ finally:
166
+ # Terminate descendants too: they must not keep modifying the
167
+ # child-owned report while the trusted parent checks it.
168
+ try:
169
+ os.killpg(process.pid, signal.SIGKILL)
170
+ except ProcessLookupError:
171
+ pass
172
+ process.wait()
173
+ if report.is_symlink() or not report.is_file() or report.stat().st_size > 16 * 1024 * 1024:
174
+ (logs / "result.json").write_text(
175
+ json.dumps({"passed": False, "returncode": code, "reason": "invalid_report"})
176
+ )
177
+ return
178
+ text = report.read_text()
179
+ (logs / "results.xml").write_text(text)
180
+ try:
181
+ parsed = parser.parse_junit(text, returncode=code)
182
+ except ValueError as exc:
183
+ (logs / "result.json").write_text(
184
+ json.dumps({"passed": False, "returncode": code, "reason": str(exc)})
185
+ )
186
+ return
187
+ expected = set(contract["expected_passes"])
188
+ passed = code == 0 and bool(expected) and parsed.passed == expected
189
+ (logs / "result.json").write_text(
190
+ json.dumps({"passed": passed, "returncode": code, "statuses": parsed.statuses})
191
+ )
192
+ reward.write_text("1\n" if passed else "0\n")
193
+
194
+
195
+ if __name__ == "__main__":
196
+ main()
tasks/tasksmith-a7e859277e7a/tests/source/.github/CODE_OF_CONDUCT.md ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ All NumPy-Financial participants are expected to honor the NumPy Code of Conduct.
2
+
3
+ This code of conduct applies to all spaces managed by the NumPy project, including all public and private mailing lists, issue trackers, wikis, blogs, Twitter, and any other communication channel used by our community. The NumPy project does not organise in-person events, however events related to our community should have a code of conduct similar in spirit to this one.
4
+
5
+ This code of conduct should be honored by everyone who participates in the NumPy community formally or informally, or claims any affiliation with the project, in any project-related activities and especially when representing the project, in any role.
6
+
7
+ This code is not exhaustive or complete. It serves to distill our common understanding of a collaborative, shared environment and goals. Please try to follow this code in spirit as much as in letter, to create a friendly and productive environment that enriches the surrounding community.
8
+
9
+ To view the full Code of Conduct, please see: https://numpy.org/code-of-conduct/
tasks/tasksmith-a7e859277e7a/tests/source/.github/ISSUE_TEMPLATE/bug-report.yml ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Bug report
2
+ description: Report a bug. For security vulnerabilities see Report a security vulnerability in the templates.
3
+ title: "BUG: <Please write a comprehensive title after the 'BUG: ' prefix>"
4
+ labels: [00 - Bug]
5
+
6
+ body:
7
+ - type: markdown
8
+ attributes:
9
+ value: >
10
+ Thank you for taking the time to file a bug report. Before creating a new
11
+ issue, please make sure to take a few minutes to check the issue tracker
12
+ for existing issues about the bug.
13
+
14
+ - type: textarea
15
+ attributes:
16
+ label: "Describe the issue:"
17
+ validations:
18
+ required: true
19
+
20
+ - type: textarea
21
+ attributes:
22
+ label: "Reproduce the code example:"
23
+ description: >
24
+ A short code example that reproduces the problem/missing feature. It
25
+ should be self-contained, i.e., can be copy-pasted into the Python
26
+ interpreter or run as-is via `python myproblem.py`.
27
+ placeholder: |
28
+ import numpy_financial as npf
29
+ << your code here >>
30
+ render: python
31
+ validations:
32
+ required: true
33
+
34
+ - type: textarea
35
+ attributes:
36
+ label: "Error message:"
37
+ description: >
38
+ Please include full error message, if any.
39
+ If you are reporting a segfault please include a GDB traceback,
40
+ which you can generate by following
41
+ [these instructions](https://github.com/numpy/numpy/blob/main/doc/source/dev/development_environment.rst#debugging).
42
+ placeholder: |
43
+ << Full traceback starting from `Traceback: ...` >>
44
+ render: shell
45
+
46
+ - type: textarea
47
+ attributes:
48
+ label: "Runtime information:"
49
+ description: >
50
+ Output from `import sys, numpy; print(numpy.__version__); print(sys.version)`
51
+ If you are running NumPy 1.24+, also show `print(numpy.show_runtime())`
52
+ validations:
53
+ required: true
54
+
55
+ - type: textarea
56
+ attributes:
57
+ label: "Context for the issue:"
58
+ description: |
59
+ Please explain how this issue affects your work or why it should be prioritized.
60
+ placeholder: |
61
+ << your explanation here >>
62
+ validations:
63
+ required: false
tasks/tasksmith-a7e859277e7a/tests/source/.github/ISSUE_TEMPLATE/config.yml ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ contact_links:
2
+ - name: Question/Help/Support
3
+ url: https://numpy.org/gethelp/
4
+ about: "If you have a question, please look at the listed resources available on the website."
5
+ - name: Development-related matters
6
+ url: https://numpy.org/community/
7
+ about: "If you would like to discuss development-related matters or need help from the NumPy team, see our community's communication channels."
tasks/tasksmith-a7e859277e7a/tests/source/.github/ISSUE_TEMPLATE/documentation.yml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Documentation
2
+ description: Report an issue related to the NumPy-Financial documentation.
3
+ title: "DOC: <Please write a comprehensive title after the 'DOC: ' prefix>"
4
+ labels: [04 - Documentation]
5
+
6
+ body:
7
+ - type: textarea
8
+ attributes:
9
+ label: "Issue with current documentation:"
10
+ description: >
11
+ Please make sure to leave a reference to the document/code you're
12
+ referring to. You can also check the development version of the
13
+ documentation and see if this issue has already been addressed at
14
+ https://numpy.org/devdocs.
15
+
16
+ - type: textarea
17
+ attributes:
18
+ label: "Idea or request for content:"
19
+ description: >
20
+ Please describe as clearly as possible what topics you think are missing
21
+ from the current documentation. Make sure to check
22
+ https://github.com/numpy/numpy-tutorials and see if this issue might be
23
+ more appropriate there.
tasks/tasksmith-a7e859277e7a/tests/source/.github/ISSUE_TEMPLATE/feature-request.yml ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Feature request
2
+ description: Check instructions for submitting your idea on the mailing list first.
3
+ title: "ENH: <Please write a comprehensive title after the 'ENH: ' prefix>"
4
+
5
+ body:
6
+ - type: markdown
7
+ attributes:
8
+ value: >
9
+ If you're looking to request a new feature or change in functionality,
10
+ including adding or changing the meaning of arguments to an existing
11
+ function, please post your idea on the
12
+ [numpy-discussion mailing list](https://mail.python.org/mailman/listinfo/numpy-discussion)
13
+ to explain your reasoning in addition to opening an issue or pull request.
14
+ You can also check out our
15
+ [Contributor Guide](https://github.com/numpy/numpy/blob/main/doc/source/dev/index.rst)
16
+ if you need more information.
17
+
18
+ - type: textarea
19
+ attributes:
20
+ label: "Proposed new feature or change:"
21
+ validations:
22
+ required: true
tasks/tasksmith-a7e859277e7a/tests/source/.github/workflows/lint.yml ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Lint
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - "*"
7
+ pull_request:
8
+ branches:
9
+ - main
10
+
11
+ permissions:
12
+ contents: read # to fetch code (actions/checkout)
13
+
14
+ concurrency:
15
+ group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
16
+ cancel-in-progress: true
17
+
18
+ jobs:
19
+ test_lint:
20
+ name: Lint
21
+ # If using act to run CI locally the github object does not exist and the usual skipping should not be enforced
22
+ if: "github.repository == 'numpy/numpy-financial' || github.repository == ''"
23
+ runs-on: ubuntu-22.04
24
+ strategy:
25
+ matrix:
26
+ python-version: ['3.11']
27
+
28
+ steps:
29
+ - uses: actions/checkout@v3
30
+ with:
31
+ fetch-depth: 0
32
+ submodules: recursive
33
+
34
+ - name: Setup Python
35
+ uses: actions/setup-python@v4
36
+ with:
37
+ python-version: ${{ matrix.python-version }}
38
+
39
+ - name: Install Python packages
40
+ run: |
41
+ python -m pip install --upgrade pip poetry
42
+ poetry env use ${{ matrix.python-version }}
43
+ poetry install --with=lint
44
+
45
+ - name: Lint with Ruff
46
+ run: |
47
+ set -euo pipefail
48
+ # Tell us what version we are using
49
+ poetry run ruff version
50
+ # Check the source file, ignore type annotations (ANN) for now.
51
+ poetry run ruff check numpy_financial/ --ignore F403 --select E,F,B,I
52
+ # Check the test and benchmark files
53
+ poetry run ruff check tests/ benchmarks/ --select E,F,B,I
tasks/tasksmith-a7e859277e7a/tests/source/.github/workflows/publish_docs_to_pages.yml ADDED
@@ -0,0 +1,76 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Publish docs to gh-pages
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - master
7
+
8
+ jobs:
9
+ build:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v1
13
+ - uses: actions/setup-python@v1
14
+ with:
15
+ python-version: '3.7'
16
+ - name: Install dependencies
17
+ run: |
18
+ export DEBIAN_FRONTEND=noninteractive
19
+ sudo apt-get -q -y install dvipng texlive-latex-extra
20
+ python -m pip install --upgrade pip
21
+ pip install -r requirements.txt
22
+ pip install sphinx
23
+ pip install numpydoc
24
+ - name: Install numpy-financial
25
+ run: |
26
+ pip install .
27
+ - name: Build documentation with Sphinx
28
+ run: |
29
+ cd doc
30
+ make html
31
+ mv build/html /tmp
32
+ cd ..
33
+ - name: Deploy to gh-pages branch
34
+ env:
35
+ GH_ACTION_PAGES_DEPLOY_KEY: ${{ secrets.GH_ACTION_PAGES_DEPLOY_KEY }}
36
+ run: |
37
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
38
+ # Set up SSH key
39
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
40
+ mkdir -p ~/.ssh/
41
+ echo "$GH_ACTION_PAGES_DEPLOY_KEY" > ~/.ssh/id_rsa
42
+ chmod 600 ~/.ssh/id_rsa
43
+ ssh-keyscan github.com >> ~/.ssh/known_hosts
44
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
45
+ # Reconfigure the git remote to use SSH
46
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
47
+ git remote rm origin
48
+ git remote add origin git@github.com:numpy/numpy-financial.git
49
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
50
+ # Configure the git user
51
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
52
+ git config user.name "${GITHUB_ACTOR}"
53
+ git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
54
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
55
+ # Go to work on gh-pages...
56
+ # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
57
+ echo "Fetching gh-pages"
58
+ git fetch origin gh-pages
59
+ echo "Checking out gh-pages branch"
60
+ git checkout gh-pages
61
+ echo "Removing old dev documentation"
62
+ git clean -xdf .
63
+ cd dev
64
+ git rm -r '*'
65
+ cd ..
66
+ echo "Committing emptied dev directory"
67
+ git commit -m "Remove old dev documentation"
68
+ mkdir dev
69
+ cd dev
70
+ echo "Copying /tmp/html here"
71
+ cp -v -r /tmp/html/* .
72
+ echo "Adding new dev documentation"
73
+ git add -A .
74
+ git commit -m "Add new dev documentation"
75
+ echo "Pushing new documentation to origin"
76
+ git push -v origin gh-pages
tasks/tasksmith-a7e859277e7a/tests/source/.github/workflows/pythonpackage.yml ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ name: Python package
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ${{ matrix.os }}
8
+ strategy:
9
+ matrix:
10
+ os: [ubuntu-latest, macos-latest, windows-latest]
11
+ python-version: ["3.10", "3.11", "3.12"]
12
+ steps:
13
+ - uses: actions/checkout@v3
14
+ - name: Set up Python ${{ matrix.python-version }}
15
+ uses: actions/setup-python@v4
16
+ with:
17
+ python-version: ${{ matrix.python-version }}
18
+ - name: Install dependencies
19
+ run: |
20
+ python -m pip install --upgrade pip poetry
21
+ poetry env use ${{ matrix.python-version }}
22
+ poetry install --with=test
23
+ - name: Test with pytest
24
+ run: |
25
+ poetry run pytest --doctest-modules
tasks/tasksmith-a7e859277e7a/tests/source/.gitignore ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Editor temporary/working/backup files #
2
+ #########################################
3
+ .#*
4
+ [#]*#
5
+ *~
6
+ *$
7
+ *.bak
8
+ *.diff
9
+ .idea/
10
+ *.iml
11
+ *.ipr
12
+ *.iws
13
+ *.org
14
+ .project
15
+ pmip
16
+ *.rej
17
+ .settings/
18
+ .*.sw[nop]
19
+ .sw[nop]
20
+ *.tmp
21
+ *.vim
22
+ .vscode
23
+ tags
24
+ cscope.out
25
+ # gnu global
26
+ GPATH
27
+ GRTAGS
28
+ GSYMS
29
+ GTAGS
30
+ .cache
31
+
32
+ # Compiled source #
33
+ ###################
34
+ *.a
35
+ *.com
36
+ *.class
37
+ *.dll
38
+ *.exe
39
+ *.o
40
+ *.o.d
41
+ *.py[ocd]
42
+ *.so
43
+
44
+ # Packages #
45
+ ############
46
+ # it's better to unpack these files and commit the raw source
47
+ # git has its own built in compression methods
48
+ *.7z
49
+ *.bz2
50
+ *.bzip2
51
+ *.dmg
52
+ *.gz
53
+ *.iso
54
+ *.jar
55
+ *.rar
56
+ *.tar
57
+ *.tbz2
58
+ *.tgz
59
+ *.zip
60
+
61
+ # Python files #
62
+ ################
63
+ # setup.py working directory
64
+ build
65
+ # sphinx build directory
66
+ _build
67
+ # setup.py dist directory
68
+ dist
69
+ doc/build
70
+ doc/cdoc/build
71
+ # Egg metadata
72
+ *.egg-info
73
+ # The shelf plugin uses this dir
74
+ ./.shelf
75
+ MANIFEST
76
+ .cache
77
+
78
+ # Paver generated files #
79
+ #########################
80
+ /release
81
+
82
+ # Logs and databases #
83
+ ######################
84
+ *.log
85
+ *.sql
86
+ *.sqlite
87
+
88
+ # Patches #
89
+ ###########
90
+ *.patch
91
+ *.diff
92
+
93
+ # OS generated files #
94
+ ######################
95
+ .DS_Store*
96
+ .VolumeIcon.icns
97
+ .fseventsd
98
+ Icon?
99
+ .gdb_history
100
+ ehthumbs.db
101
+ Thumbs.db
102
+ .directory
103
+
104
+ # pytest generated files #
105
+ ##########################
106
+ /.pytest_cache
107
+
108
+ # Poetry lock file #
109
+ ####################
110
+ poetry.lock
111
+
112
+ # Things specific to this project #
113
+ ###################################
tasks/tasksmith-a7e859277e7a/tests/source/Dockerfile ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.12-slim
2
+ WORKDIR /workspace
3
+ RUN python -m pip install --no-cache-dir poetry-core==1.9.1 numba==0.68.1 llvmlite==0.50.0 numpy==2.5.5 pytest==8.3.5 'hypothesis[numpy]==6.99.11' 'pytest-xdist[psutil]==3.5.0'
4
+ COPY . /workspace
5
+ RUN python -m pip install --no-cache-dir -e .
6
+ RUN rm -rf /workspace/.git /root/.cache/pip
7
+ ENV PYTHONDONTWRITEBYTECODE=1 PYTEST_DISABLE_PLUGIN_AUTOLOAD=1
8
+ ENV HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1 HF_DATASETS_OFFLINE=1
tasks/tasksmith-a7e859277e7a/tests/source/LICENSE.txt ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Copyright (c) 2005-2019, NumPy Developers.
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are
6
+ met:
7
+
8
+ * Redistributions of source code must retain the above copyright
9
+ notice, this list of conditions and the following disclaimer.
10
+
11
+ * Redistributions in binary form must reproduce the above
12
+ copyright notice, this list of conditions and the following
13
+ disclaimer in the documentation and/or other materials provided
14
+ with the distribution.
15
+
16
+ * Neither the name of the NumPy Developers nor the names of any
17
+ contributors may be used to endorse or promote products derived
18
+ from this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
+ OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
+ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
+ LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
+ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
+ (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
tasks/tasksmith-a7e859277e7a/tests/source/README.md ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # NumPy Financial
2
+
3
+ The `numpy-financial` package contains a collection of elementary financial
4
+ functions.
5
+
6
+ The [financial functions in NumPy](https://numpy.org/doc/1.17/reference/routines.financial.html)
7
+ are deprecated and eventually will be removed from NumPy; see
8
+ [NEP-32](https://numpy.org/neps/nep-0032-remove-financial-functions.html)
9
+ for more information. This package is the replacement for the original
10
+ NumPy financial functions.
11
+
12
+ The source code for this package is available at https://github.com/numpy/numpy-financial.
13
+
14
+ The importable name of the package is `numpy_financial`. The recommended
15
+ alias is `npf`. For example,
16
+
17
+ ```
18
+ >>> import numpy_financial as npf
19
+ >>> npf.irr([-250000, 100000, 150000, 200000, 250000, 300000])
20
+ 0.5672303344358536
21
+ ```
tasks/tasksmith-a7e859277e7a/tests/source/asv.conf.json ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ // The version of the config file format. Do not change, unless
3
+ // you know what you are doing.
4
+ "version": 1,
5
+
6
+ // The name of the project being benchmarked
7
+ "project": "NumPy-Financial",
8
+
9
+ // The project's homepage
10
+ "project_url": "https://numpy.org/numpy-financial//",
11
+
12
+ // The URL or local path of the source code repository for the
13
+ // project being benchmarked
14
+ "repo": ".",
15
+
16
+ // The Python project's subdirectory in your repo. If missing or
17
+ // the empty string, the project is assumed to be located at the root
18
+ // of the repository.
19
+ // "repo_subdir": "",
20
+
21
+ // Customizable commands for building the project.
22
+ // See asv.conf.json documentation.
23
+ // To build the package using pyproject.toml (PEP518), uncomment the following lines
24
+ "build_command": [
25
+ "python -m pip install build",
26
+ "python -m build",
27
+ "PIP_NO_BUILD_ISOLATION=false python -mpip wheel --no-deps --no-index -w {build_cache_dir} {build_dir}"
28
+ ],
29
+ // To build the package using setuptools and a setup.py file, uncomment the following lines
30
+ // "build_command": [
31
+ // "python setup.py build",
32
+ // "PIP_NO_BUILD_ISOLATION=false python -mpip wheel --no-deps --no-index -w {build_cache_dir} {build_dir}"
33
+ // ],
34
+
35
+ // Customizable commands for installing and uninstalling the project.
36
+ // See asv.conf.json documentation.
37
+ // "install_command": ["in-dir={env_dir} python -mpip install {wheel_file}"],
38
+ // "uninstall_command": ["return-code=any python -mpip uninstall -y {project}"],
39
+
40
+ // List of branches to benchmark. If not provided, defaults to "master"
41
+ // (for git) or "default" (for mercurial).
42
+ "branches": ["main"],
43
+
44
+ // The DVCS being used. If not set, it will be automatically
45
+ // determined from "repo" by looking at the protocol in the URL
46
+ // (if remote), or by looking for special directories, such as
47
+ // ".git" (if local).
48
+ "dvcs": "git",
49
+
50
+ // The tool to use to create environments. May be "conda",
51
+ // "virtualenv", "mamba" (above 3.8)
52
+ // or other value depending on the plugins in use.
53
+ // If missing or the empty string, the tool will be automatically
54
+ // determined by looking for tools on the PATH environment
55
+ // variable.
56
+ "environment_type": "virtualenv",
57
+
58
+ // timeout in seconds for installing any dependencies in environment
59
+ // defaults to 10 min
60
+ //"install_timeout": 600,
61
+
62
+ // the base URL to show a commit for the project.
63
+ // "show_commit_url": "http://github.com/owner/project/commit/",
64
+
65
+ // The Pythons you'd like to test against. If not provided, defaults
66
+ // to the current version of Python used to run `asv`.
67
+ // "pythons": ["2.7", "3.8"],
68
+
69
+ // The list of conda channel names to be searched for benchmark
70
+ // dependency packages in the specified order
71
+ // "conda_channels": ["conda-forge", "defaults"],
72
+
73
+ // A conda environment file that is used for environment creation.
74
+ // "conda_environment_file": "environment.yml",
75
+
76
+ // The matrix of dependencies to test. Each key of the "req"
77
+ // requirements dictionary is the name of a package (in PyPI) and
78
+ // the values are version numbers. An empty list or empty string
79
+ // indicates to just test against the default (latest)
80
+ // version. null indicates that the package is to not be
81
+ // installed. If the package to be tested is only available from
82
+ // PyPi, and the 'environment_type' is conda, then you can preface
83
+ // the package name by 'pip+', and the package will be installed
84
+ // via pip (with all the conda available packages installed first,
85
+ // followed by the pip installed packages).
86
+ //
87
+ // The ``@env`` and ``@env_nobuild`` keys contain the matrix of
88
+ // environment variables to pass to build and benchmark commands.
89
+ // An environment will be created for every combination of the
90
+ // cartesian product of the "@env" variables in this matrix.
91
+ // Variables in "@env_nobuild" will be passed to every environment
92
+ // during the benchmark phase, but will not trigger creation of
93
+ // new environments. A value of ``null`` means that the variable
94
+ // will not be set for the current combination.
95
+ //
96
+ // "matrix": {
97
+ // "req": {
98
+ // "numpy": ["1.6", "1.7"],
99
+ // "six": ["", null], // test with and without six installed
100
+ // "pip+emcee": [""] // emcee is only available for install with pip.
101
+ // },
102
+ // "env": {"ENV_VAR_1": ["val1", "val2"]},
103
+ // "env_nobuild": {"ENV_VAR_2": ["val3", null]},
104
+ // },
105
+
106
+ // Combinations of libraries/python versions can be excluded/included
107
+ // from the set to test. Each entry is a dictionary containing additional
108
+ // key-value pairs to include/exclude.
109
+ //
110
+ // An exclude entry excludes entries where all values match. The
111
+ // values are regexps that should match the whole string.
112
+ //
113
+ // An include entry adds an environment. Only the packages listed
114
+ // are installed. The 'python' key is required. The exclude rules
115
+ // do not apply to includes.
116
+ //
117
+ // In addition to package names, the following keys are available:
118
+ //
119
+ // - python
120
+ // Python version, as in the *pythons* variable above.
121
+ // - environment_type
122
+ // Environment type, as above.
123
+ // - sys_platform
124
+ // Platform, as in sys.platform. Possible values for the common
125
+ // cases: 'linux2', 'win32', 'cygwin', 'darwin'.
126
+ // - req
127
+ // Required packages
128
+ // - env
129
+ // Environment variables
130
+ // - env_nobuild
131
+ // Non-build environment variables
132
+ //
133
+ // "exclude": [
134
+ // {"python": "3.2", "sys_platform": "win32"}, // skip py3.2 on windows
135
+ // {"environment_type": "conda", "req": {"six": null}}, // don't run without six on conda
136
+ // {"env": {"ENV_VAR_1": "val2"}}, // skip val2 for ENV_VAR_1
137
+ // ],
138
+ //
139
+ // "include": [
140
+ // // additional env for python2.7
141
+ // {"python": "2.7", "req": {"numpy": "1.8"}, "env_nobuild": {"FOO": "123"}},
142
+ // // additional env if run on windows+conda
143
+ // {"platform": "win32", "environment_type": "conda", "python": "2.7", "req": {"libpython": ""}},
144
+ // ],
145
+
146
+ // The directory (relative to the current directory) that benchmarks are
147
+ // stored in. If not provided, defaults to "benchmarks"
148
+ // "benchmark_dir": "benchmarks",
149
+
150
+ // The directory (relative to the current directory) to cache the Python
151
+ // environments in. If not provided, defaults to "env"
152
+ "env_dir": ".asv/env",
153
+
154
+ // The directory (relative to the current directory) that raw benchmark
155
+ // results are stored in. If not provided, defaults to "results".
156
+ "results_dir": ".asv/results",
157
+
158
+ // The directory (relative to the current directory) that the html tree
159
+ // should be written to. If not provided, defaults to "html".
160
+ "html_dir": ".asv/html",
161
+
162
+ // The number of characters to retain in the commit hashes.
163
+ // "hash_length": 8,
164
+
165
+ // `asv` will cache results of the recent builds in each
166
+ // environment, making them faster to install next time. This is
167
+ // the number of builds to keep, per environment.
168
+ // "build_cache_size": 2,
169
+
170
+ // The commits after which the regression search in `asv publish`
171
+ // should start looking for regressions. Dictionary whose keys are
172
+ // regexps matching to benchmark names, and values corresponding to
173
+ // the commit (exclusive) after which to start looking for
174
+ // regressions. The default is to start from the first commit
175
+ // with results. If the commit is `null`, regression detection is
176
+ // skipped for the matching benchmark.
177
+ //
178
+ // "regressions_first_commits": {
179
+ // "some_benchmark": "352cdf", // Consider regressions only after this commit
180
+ // "another_benchmark": null, // Skip regression detection altogether
181
+ // },
182
+
183
+ // The thresholds for relative change in results, after which `asv
184
+ // publish` starts reporting regressions. Dictionary of the same
185
+ // form as in ``regressions_first_commits``, with values
186
+ // indicating the thresholds. If multiple entries match, the
187
+ // maximum is taken. If no entry matches, the default is 5%.
188
+ //
189
+ // "regressions_thresholds": {
190
+ // "some_benchmark": 0.01, // Threshold of 1%
191
+ // "another_benchmark": 0.5, // Threshold of 50%
192
+ // },
193
+ }
tasks/tasksmith-a7e859277e7a/tests/source/benchmarks/__init__.py ADDED
File without changes
tasks/tasksmith-a7e859277e7a/tests/source/benchmarks/benchmarks.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from decimal import Decimal
2
+
3
+ import numpy as np
4
+
5
+ import numpy_financial as npf
6
+
7
+
8
+ def _to_decimal_array_1d(array):
9
+ return np.array([Decimal(x) for x in array.tolist()])
10
+
11
+
12
+ def _to_decimal_array_2d(array):
13
+ decimals = [Decimal(x) for row in array.tolist() for x in row]
14
+ return np.array(decimals).reshape(array.shape)
15
+
16
+
17
+ class Npv2D:
18
+
19
+ param_names = ["n_cashflows", "cashflow_lengths", "rates_lengths"]
20
+ params = [
21
+ (1, 10, 100),
22
+ (1, 10, 100),
23
+ (1, 10, 100),
24
+ ]
25
+
26
+ def __init__(self):
27
+ self.rates_decimal = None
28
+ self.rates = None
29
+ self.cashflows_decimal = None
30
+ self.cashflows = None
31
+
32
+ def setup(self, n_cashflows, cashflow_lengths, rates_lengths):
33
+ rng = np.random.default_rng(0)
34
+ cf_shape = (n_cashflows, cashflow_lengths)
35
+ self.cashflows = rng.standard_normal(cf_shape)
36
+ self.rates = rng.standard_normal(rates_lengths)
37
+ self.cashflows_decimal = _to_decimal_array_2d(self.cashflows)
38
+ self.rates_decimal = _to_decimal_array_1d(self.rates)
39
+
40
+ def time_for_loop(self, n_cashflows, cashflow_lengths, rates_lengths):
41
+ for rate in self.rates:
42
+ for cashflow in self.cashflows:
43
+ npf.npv(rate, cashflow)
44
+
45
+ def time_for_loop_decimal(self, n_cashflows, cashflow_lengths, rates_lengths):
46
+ for rate in self.rates_decimal:
47
+ for cashflow in self.cashflows_decimal:
48
+ npf.npv(rate, cashflow)
49
+
tasks/tasksmith-a7e859277e7a/tests/source/doc/Makefile ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Minimal makefile for Sphinx documentation
2
+ #
3
+
4
+ # You can set these variables from the command line, and also
5
+ # from the environment for the first two.
6
+ SPHINXOPTS ?=
7
+ SPHINXBUILD ?= sphinx-build
8
+ SOURCEDIR = source
9
+ BUILDDIR = build
10
+
11
+ # Put it first so that "make" without argument is like "make help".
12
+ help:
13
+ @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
14
+
15
+ .PHONY: help Makefile
16
+
17
+ # Catch-all target: route all unknown targets to Sphinx using the new
18
+ # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
19
+ %: Makefile
20
+ @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
tasks/tasksmith-a7e859277e7a/tests/source/doc/make.bat ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ @ECHO OFF
2
+
3
+ pushd %~dp0
4
+
5
+ REM Command file for Sphinx documentation
6
+
7
+ if "%SPHINXBUILD%" == "" (
8
+ set SPHINXBUILD=sphinx-build
9
+ )
10
+ set SOURCEDIR=source
11
+ set BUILDDIR=build
12
+
13
+ if "%1" == "" goto help
14
+
15
+ %SPHINXBUILD% >NUL 2>NUL
16
+ if errorlevel 9009 (
17
+ echo.
18
+ echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
19
+ echo.installed, then set the SPHINXBUILD environment variable to point
20
+ echo.to the full path of the 'sphinx-build' executable. Alternatively you
21
+ echo.may add the Sphinx directory to PATH.
22
+ echo.
23
+ echo.If you don't have Sphinx installed, grab it from
24
+ echo.http://sphinx-doc.org/
25
+ exit /b 1
26
+ )
27
+
28
+ %SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
29
+ goto end
30
+
31
+ :help
32
+ %SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
33
+
34
+ :end
35
+ popd
tasks/tasksmith-a7e859277e7a/tests/source/doc/source/_static/numpy_financial_favicon.png ADDED

Git LFS Details

  • SHA256: 28f9fc915f503b23ec5f8c8fd088f608140cc457bff13fd0361ab7b1e48b1519
  • Pointer size: 128 Bytes
  • Size of remote file: 170 Bytes
tasks/tasksmith-a7e859277e7a/tests/source/doc/source/_static/numpy_financial_logov.svg ADDED
tasks/tasksmith-a7e859277e7a/tests/source/doc/source/conf.py ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Configuration file for the Sphinx documentation builder.
2
+ #
3
+ # This file only contains a selection of the most common options. For a full
4
+ # list see the documentation:
5
+ # https://www.sphinx-doc.org/en/master/usage/configuration.html
6
+
7
+ import numpy_financial
8
+
9
+ # -- Path setup --------------------------------------------------------------
10
+
11
+ # If extensions (or modules to document with autodoc) are in another directory,
12
+ # add these directories to sys.path here. If the directory is relative to the
13
+ # documentation root, use os.path.abspath to make it absolute, like shown here.
14
+ #
15
+ # import os
16
+ # import sys
17
+ # sys.path.insert(0, os.path.abspath('.'))
18
+
19
+
20
+ # -- Project information -----------------------------------------------------
21
+
22
+ project = 'numpy-financial'
23
+ copyright = '2023, numpy-financial developers'
24
+ author = 'numpy-financial developers'
25
+
26
+
27
+ # -- General configuration ---------------------------------------------------
28
+
29
+ # Add any Sphinx extension module names here, as strings. They can be
30
+ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
31
+ # ones.
32
+ extensions = [
33
+ 'sphinx.ext.autodoc',
34
+ 'numpydoc',
35
+ 'sphinx.ext.mathjax',
36
+ 'myst_parser',
37
+ ]
38
+
39
+ # Add any paths that contain templates here, relative to this directory.
40
+ templates_path = ['_templates']
41
+
42
+ # List of patterns, relative to source directory, that match files and
43
+ # directories to ignore when looking for source files.
44
+ # This pattern also affects html_static_path and html_extra_path.
45
+ exclude_patterns = []
46
+
47
+ version = numpy_financial.__version__
48
+
49
+ # -- Options for HTML output -------------------------------------------------
50
+
51
+ # The theme to use for HTML and HTML Help pages. See the documentation for
52
+ # a list of builtin themes.
53
+ #
54
+ html_theme = 'pydata_sphinx_theme'
55
+ html_copy_source = False
56
+
57
+ # Add any paths that contain custom static files (such as style sheets) here,
58
+ # relative to this directory. They are copied after the builtin static files,
59
+ # so a file named "default.css" will overwrite the builtin "default.css".
60
+ html_static_path = ['_static']
61
+
62
+ html_logo = "_static/numpy_financial_logov.svg"
63
+ html_favicon = "_static/numpy_financial_favicon.png"
64
+
65
+ html_sidebars = {
66
+ '**': ['localtoc.html', 'searchbox.html'],
67
+ }
tasks/tasksmith-a7e859277e7a/tests/source/doc/source/dev/building_with_poetry.md ADDED
@@ -0,0 +1,67 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Building with poetry
2
+
3
+ ## Installing poetry
4
+ numpy-financial uses [poetry](https://python-poetry.org/) to manage
5
+ dependencies, build wheels and sdists, and publish to PyPI this page documents
6
+ how to work with poetry.
7
+
8
+ To install poetry follow their [official guide](https://python-poetry.org/docs/#installing-with-the-official-installer)
9
+ it is recommended to use the official installer for local development.
10
+
11
+ To check your installation try to check the version of poetry:
12
+
13
+ ```shell
14
+ poetry -V
15
+ ```
16
+
17
+ ## Setting up a virtual environment using poetry
18
+
19
+ Once poetry is installed it is time to set up the virtual environment. To do
20
+ this run:
21
+
22
+ ```shell
23
+ poetry install
24
+ ```
25
+
26
+ ``poetry install`` looks for dependencies in the ``pyproject.toml`` file,
27
+ resolves them to the most recent version and installs the dependencies
28
+ in a virtual environment. It is now possible to launch an interactive REPL
29
+ by running the following command:
30
+
31
+ ```shell
32
+ poetry run python
33
+ ```
34
+
35
+ ## Running the test suite
36
+
37
+ numpy-financial has an extensive test suite, which can be run with the
38
+ following command:
39
+
40
+ ```shell
41
+ poetry run pytest
42
+ ```
43
+
44
+ ## Building distributions
45
+
46
+ It is possible to manually build distributions for numpy-financial using
47
+ poetry. This is possible via the `build` command:
48
+
49
+ ```shell
50
+ poetry build
51
+ ```
52
+
53
+ The `build` command creates a `dist` directory containing a wheel and sdist
54
+ file.
55
+
56
+
57
+ ## Publishing to PyPI
58
+
59
+ poetry provides support to publish packages to PyPI. This is possible using
60
+ the ``publish`` command:
61
+
62
+ ```shell
63
+ poetry publish --build --username <your username> --password <your password>
64
+ ```
65
+
66
+ Note that this builds the package before publishing it. You will need to
67
+ provide the correct username and password for PyPI.
tasks/tasksmith-a7e859277e7a/tests/source/doc/source/dev/getting_the_code.md ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Getting the code
2
+
3
+ This document explains how to get the source code for NumPy-Financial using Git.
4
+
5
+ ## Code Location
6
+
7
+ NumPy-Financial is hosted on GitHub. The repository URL is https://github.com/numpy/numpy-financial.
8
+
9
+ ## Creating a fork
10
+
11
+ To create a fork click the green "fork" button at the top right of the page. This creates a new repository on your
12
+ GitHub profile. This will have the URL: https://github.com/<your_username>/numpy-financial.
13
+
14
+ ## Cloning the repository
15
+
16
+ Now that you have forked the repository you will need to clone it. This copies the repository from GitHub to the local
17
+ machine. To clone a repository enter the following commands in the terminal.
18
+
19
+ ```shell
20
+ git clone https://github.com/<your_username>/numpy-financial.git
21
+ ```
22
+
23
+ Hooray! You now have a working copy of NumPy-Financial.
24
+
25
+
26
+ ## Updating the code with other's changes
27
+
28
+ From time to time you may want to pull down the latest code. Do this with:
29
+
30
+ ```shell
31
+ git fetch
32
+ ```
33
+
34
+ The `git fetch` command downloads commits, files and refs from a remote repo into your local repo.
35
+
36
+ Then run:
37
+
38
+ ```shell
39
+ git merge --ff-only
40
+ ```
41
+
42
+ The `git merge` command is Git's way of putting independent branches back together. The `--ff-only` flag tells git to
43
+ use `fast-forward` merges. This is preferable as fast-forward merge avoids creating merge commits.
tasks/tasksmith-a7e859277e7a/tests/source/doc/source/dev/running_the_benchmarks.md ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Running the benchmarks
2
+
3
+ This document outlines how to setup and run the benchmarks using [asv](https://asv.readthedocs.io/en/v0.6.1/).
4
+
5
+ ## Installing asv
6
+
7
+ `asv` can be installed with poetry via the `bench` group to install the bench group run:
8
+
9
+ ```shell
10
+ poetry install --with=bench
11
+ ```
12
+
13
+ This will install ``asv`` into your poetry environment.
14
+
15
+ ## Running the benchmarks
16
+
17
+ To run the benchmarks with ``asv``, simply enter:
18
+
19
+ ```shell
20
+ poetry run asv run
21
+ ```
22
+
23
+ ## Viewing the results
24
+
25
+ There are two steps to viewing the results locally. The results need to be published and the launched in a local web browser.
26
+
27
+ To publish the results use:
28
+
29
+ ```shell
30
+ poetry run asv publish
31
+ ```
32
+
33
+ And then to view the results:
34
+
35
+ ```shell
36
+ poetry run asv preview
37
+ ```
38
+
39
+ This will launch a local web browser from which you can view the results
40
+
41
+ ## Dry runs
42
+
43
+ One common use case is to use ``asv`` in development, there are several useful flags that should be used:
44
+
45
+ ```shell
46
+ poetry run asv --python=same --quick --dry-run
47
+ ```
48
+
49
+ We are adding three flags, these flags are:
50
+
51
+ 1. `--python=same` uses the same environment as your development environment (saves time to avoid building environments)
52
+ 2. `--quick` only runs the benchmarks once
53
+ 3. `--dry-run` to not save the results of the benchmarks
54
+
55
+ These can be useful for getting quick feedback during development, but should not be used as anything other than a rough guide.
tasks/tasksmith-a7e859277e7a/tests/source/doc/source/fv.rst ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ fv
2
+ ==
3
+
4
+ .. currentmodule:: numpy_financial
5
+
6
+ .. toctree::
7
+
8
+ .. autofunction:: fv
tasks/tasksmith-a7e859277e7a/tests/source/doc/source/generate_rst_function_files.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # This script was used to generate the rst function stubs
3
+ # numpy_financial.fv.rst, numpy_financial.ipmt.rst, etc.
4
+ # It requires that numpy_financial is already installed,
5
+ # although it could just as easily use a hard-coded list
6
+ # of function names.
7
+
8
+ import numpy_financial as nf
9
+
10
+
11
+ def generate_rst_function_files():
12
+ names = [name for name in dir(nf) if not name.startswith('_')]
13
+ for name in names:
14
+ with open(name + '.rst', 'w') as f:
15
+ f.write('''{name}
16
+ {underline}
17
+
18
+ .. currentmodule:: numpy_financial
19
+
20
+ .. toctree::
21
+
22
+ .. autofunction:: {name}
23
+ '''.format(name=name, underline='='*len(name)))
24
+
25
+
26
+ if __name__ == "__main__":
27
+ generate_rst_function_files()
tasks/tasksmith-a7e859277e7a/tests/source/doc/source/index.rst ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ numpy-financial |version|
3
+ =========================
4
+
5
+ The `numpy-financial` package is a collection of elementary financial
6
+ functions.
7
+
8
+ The `financial functions in NumPy <https://numpy.org/doc/1.17/reference/routines.financial.html>`_
9
+ are deprecated and eventually will be removed from NumPy; see
10
+ `NEP-32 <https://numpy.org/neps/nep-0032-remove-financial-functions.html>`_
11
+ for more information. This package is the replacement for the deprecated
12
+ NumPy financial functions.
13
+
14
+ The source code for this package is available at https://github.com/numpy/numpy-financial.
15
+
16
+ The importable name of the package is `numpy_financial`. The recommended
17
+ alias is `npf`. For example,
18
+
19
+ >>> import numpy_financial as npf
20
+ >>> npf.irr([-250000, 100000, 150000, 200000, 250000, 300000])
21
+ 0.5672303344358536
22
+
23
+
24
+ Functions
25
+ ---------
26
+
27
+ .. currentmodule:: numpy_financial
28
+
29
+ .. toctree::
30
+ :maxdepth: 4
31
+
32
+ .. autosummary::
33
+
34
+ fv
35
+ ipmt
36
+ irr
37
+ mirr
38
+ nper
39
+ npv
40
+ pmt
41
+ ppmt
42
+ pv
43
+ rate
44
+
45
+ .. The following "hidden" toctree is a hack to prevent Sphinx warnings
46
+ about "document isn't included in any toctree"
47
+
48
+ .. toctree::
49
+ :hidden:
50
+
51
+ fv
52
+ ipmt
53
+ irr
54
+ mirr
55
+ nper
56
+ npv
57
+ pmt
58
+ ppmt
59
+ pv
60
+ rate
61
+
62
+ Development
63
+ ===========
64
+
65
+ .. toctree::
66
+ :maxdepth: 1
67
+
68
+ dev/getting_the_code.md
69
+ dev/building_with_poetry.md
70
+ dev/running_the_benchmarks.md
71
+
72
+ .. include:: release-notes.rst
73
+
74
+
75
+ Index and Search
76
+ ================
77
+
78
+ * :ref:`genindex`
79
+ * :ref:`search`
tasks/tasksmith-a7e859277e7a/tests/source/doc/source/ipmt.rst ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ ipmt
2
+ ====
3
+
4
+ .. currentmodule:: numpy_financial
5
+
6
+ .. toctree::
7
+
8
+ .. autofunction:: ipmt
tasks/tasksmith-a7e859277e7a/tests/source/doc/source/irr.rst ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ irr
2
+ ===
3
+
4
+ .. currentmodule:: numpy_financial
5
+
6
+ .. toctree::
7
+
8
+ .. autofunction:: irr
tasks/tasksmith-a7e859277e7a/tests/source/doc/source/mirr.rst ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ mirr
2
+ ====
3
+
4
+ .. currentmodule:: numpy_financial
5
+
6
+ .. toctree::
7
+
8
+ .. autofunction:: mirr
tasks/tasksmith-a7e859277e7a/tests/source/doc/source/nper.rst ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ nper
2
+ ====
3
+
4
+ .. currentmodule:: numpy_financial
5
+
6
+ .. toctree::
7
+
8
+ .. autofunction:: nper
tasks/tasksmith-a7e859277e7a/tests/source/doc/source/npv.rst ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ npv
2
+ ===
3
+
4
+ .. currentmodule:: numpy_financial
5
+
6
+ .. toctree::
7
+
8
+ .. autofunction:: npv
tasks/tasksmith-a7e859277e7a/tests/source/doc/source/pmt.rst ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ pmt
2
+ ===
3
+
4
+ .. currentmodule:: numpy_financial
5
+
6
+ .. toctree::
7
+
8
+ .. autofunction:: pmt
tasks/tasksmith-a7e859277e7a/tests/source/doc/source/ppmt.rst ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ ppmt
2
+ ====
3
+
4
+ .. currentmodule:: numpy_financial
5
+
6
+ .. toctree::
7
+
8
+ .. autofunction:: ppmt
tasks/tasksmith-a7e859277e7a/tests/source/doc/source/pv.rst ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ pv
2
+ ==
3
+
4
+ .. currentmodule:: numpy_financial
5
+
6
+ .. toctree::
7
+
8
+ .. autofunction:: pv
tasks/tasksmith-a7e859277e7a/tests/source/doc/source/rate.rst ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ rate
2
+ ====
3
+
4
+ .. currentmodule:: numpy_financial
5
+
6
+ .. toctree::
7
+
8
+ .. autofunction:: rate
tasks/tasksmith-a7e859277e7a/tests/source/doc/source/release-notes.rst ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Release Notes
2
+ -------------
3
+ 1.1.0
4
+ ~~~~~
5
+ * **1.1.0 is not released yet.**
6
+
7
+ 1.0.0
8
+ ~~~~~
9
+ * The transition of the source code from NumPy to this package is complete.
10
+
11
+ 0.2.0
12
+ ~~~~~
13
+ * Removed the use of `numpy.core.overrides.array_function_dispatch` to create
14
+ wrappers of the financial functions.
15
+ * Support NumPy versions back to 1.15.
16
+
17
+ 0.1.0
18
+ ~~~~~
19
+ * This is the initial release of numpy-financial. The functions were
20
+ copied from NumPy 1.17.
tasks/tasksmith-a7e859277e7a/tests/source/docweb/README.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ This directory contains the files for the top-level online documentation.
2
+ If these files are changed, the changes must be copied over to the top directory
3
+ of the gh-pages branch.
tasks/tasksmith-a7e859277e7a/tests/source/docweb/css/home.css ADDED
@@ -0,0 +1,128 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ body {
3
+ margin: auto;
4
+ padding-right: 1em;
5
+ padding-left: 1em;
6
+ max-width: 48em;
7
+ color: black;
8
+ font-family: sans-serif;
9
+ font-size: 100%;
10
+ line-height: 125%;
11
+ color: #333;
12
+ }
13
+ pre {
14
+ border: 1px dotted gray;
15
+ background-color: #E8E8E8;
16
+ color: #101010;
17
+ padding: 0.5em;
18
+ }
19
+ code {
20
+ font-family: monospace;
21
+ font-size: 130%;
22
+ font-weight: bold;
23
+ }
24
+ h1 a, h2 a, h3 a, h4 a, h5 a {
25
+ text-decoration: none;
26
+ color: #336699;
27
+ }
28
+ h1, h2, h3, h4, h5 {
29
+ font-family: sans-serif;
30
+ font-weight: bold;
31
+ color: #336699; }
32
+
33
+ h1 {
34
+ font-size: 130%;
35
+ }
36
+
37
+ h2 {
38
+ font-size: 110%;
39
+ font-style: italic;
40
+ }
41
+
42
+ h3 {
43
+ font-size: 95%;
44
+ font-style: italic;
45
+ }
46
+
47
+ h4 {
48
+ font-size: 90%;
49
+ font-style: italic;
50
+ }
51
+
52
+ h5 {
53
+ font-size: 90%;
54
+ font-style: italic;
55
+ }
56
+
57
+ h1.title {
58
+ font-size: 200%;
59
+ font-weight: bold;
60
+ padding-top: 0.2em;
61
+ padding-bottom: 0.2em;
62
+ text-align: left;
63
+ border: none;
64
+ }
65
+
66
+ dt code {
67
+ font-weight: bold;
68
+ }
69
+ dd p {
70
+ margin-top: 0;
71
+ }
72
+
73
+ ul {
74
+ padding: 0px 0px 0px 16px;
75
+ }
76
+
77
+ ul li {
78
+ margin: 0px;
79
+ padding: 0px;
80
+ }
81
+
82
+ .link2 {
83
+ border: solid 1px #000;
84
+ border-radius: 3x;
85
+ -moz-border-radius: 3px;
86
+ -webkit-border-radius: 3px;
87
+ background-color: #FFF;
88
+ color: #336699;
89
+ text-decoration: none;
90
+ text-align: center;
91
+ width: 180px;
92
+ margin: 0px 0px 2px 0px;
93
+ padding: 2px 0 0px 0px;
94
+ display: inline-block;
95
+ }
96
+ .link2:hover { background-color: #FFF060; }
97
+
98
+ aside h3 {
99
+ margin: 10px 0px 2px 0px;
100
+ }
101
+
102
+ /*
103
+ * Specific id styles.
104
+ */
105
+
106
+ #logo {
107
+ border: solid 1px #000;
108
+ padding: 5px 5px 3px 5px;
109
+ background-color: #FFFFEA;
110
+ }
111
+
112
+ #asidelinks {
113
+ width: 25%;
114
+ float: right;
115
+ color: black;
116
+ background-color: #E8F4FF;
117
+ padding: 0px 10px 10px 10px;
118
+ border: solid 1px #000;
119
+ margin: 0em 0.75em 0em 0.5em;
120
+ box-shadow: 5px 8px 9px #b0b0b0;
121
+ }
122
+
123
+ #footer {
124
+ padding-top: 1em;
125
+ font-size: 70%;
126
+ color: gray;
127
+ text-align: center;
128
+ }
tasks/tasksmith-a7e859277e7a/tests/source/docweb/images/numpy_financial_favicon.png ADDED

Git LFS Details

  • SHA256: 28f9fc915f503b23ec5f8c8fd088f608140cc457bff13fd0361ab7b1e48b1519
  • Pointer size: 128 Bytes
  • Size of remote file: 170 Bytes
tasks/tasksmith-a7e859277e7a/tests/source/docweb/images/numpy_financial_logoh.svg ADDED