@stdlib/random-iter 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/NOTICE +1 -1
- package/README.md +42 -9
- package/docs/types/index.d.ts +2 -1
- package/package.json +3 -3
package/NOTICE
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
Copyright (c) 2016-
|
|
1
|
+
Copyright (c) 2016-2026 The Stdlib Authors.
|
package/README.md
CHANGED
|
@@ -127,10 +127,43 @@ The namespace contains the following functions for creating iterator protocol-co
|
|
|
127
127
|
<!-- eslint no-undef: "error" -->
|
|
128
128
|
|
|
129
129
|
```javascript
|
|
130
|
-
var
|
|
131
|
-
var
|
|
132
|
-
|
|
133
|
-
|
|
130
|
+
var roundn = require( '@stdlib/math-base-special-roundn' );
|
|
131
|
+
var mean = require( '@stdlib/stats-strided-mean' );
|
|
132
|
+
var iter = require( '@stdlib/random-iter' );
|
|
133
|
+
|
|
134
|
+
var initialPrice = 100.0;
|
|
135
|
+
var currentPrice = initialPrice;
|
|
136
|
+
var numDays = 30;
|
|
137
|
+
var volatility = 0.02; // 2% daily volatility
|
|
138
|
+
|
|
139
|
+
// Create iterator for random price movements:
|
|
140
|
+
var priceIter = iter.normal( 0.0, volatility );
|
|
141
|
+
var prices = [ initialPrice ];
|
|
142
|
+
var dailyReturns = [];
|
|
143
|
+
|
|
144
|
+
// Simulate price movements:
|
|
145
|
+
var change;
|
|
146
|
+
var i;
|
|
147
|
+
for ( i = 0; i < numDays; i++ ) {
|
|
148
|
+
change = priceIter.next().value;
|
|
149
|
+
currentPrice *= ( 1.0 + change );
|
|
150
|
+
prices.push( roundn( currentPrice, -2 ) );
|
|
151
|
+
dailyReturns.push( change * 100.0 );
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// Calculate summary statistics:
|
|
155
|
+
var totalReturn = ( ( currentPrice - initialPrice ) / initialPrice ) * 100.0;
|
|
156
|
+
var avgReturn = mean( numDays, dailyReturns, 1 );
|
|
157
|
+
|
|
158
|
+
// Print results:
|
|
159
|
+
console.log( 'Stock Price Simulation Results:' );
|
|
160
|
+
console.log( '-------------------------------' );
|
|
161
|
+
console.log( 'Initial Price: $%d', initialPrice );
|
|
162
|
+
console.log( 'Final Price: $%d', roundn( currentPrice, -2 ) );
|
|
163
|
+
console.log( 'Total Return: %d%', roundn( totalReturn, -2 ) );
|
|
164
|
+
console.log( 'Average Daily Return: %d%', roundn( avgReturn, -2 ) );
|
|
165
|
+
console.log( '\nPrice History:' );
|
|
166
|
+
console.log( prices.join( ' → ' ) );
|
|
134
167
|
```
|
|
135
168
|
|
|
136
169
|
</section>
|
|
@@ -171,7 +204,7 @@ See [LICENSE][stdlib-license].
|
|
|
171
204
|
|
|
172
205
|
## Copyright
|
|
173
206
|
|
|
174
|
-
Copyright © 2016-
|
|
207
|
+
Copyright © 2016-2026. The Stdlib [Authors][stdlib-authors].
|
|
175
208
|
|
|
176
209
|
</section>
|
|
177
210
|
|
|
@@ -184,8 +217,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
184
217
|
[npm-image]: http://img.shields.io/npm/v/@stdlib/random-iter.svg
|
|
185
218
|
[npm-url]: https://npmjs.org/package/@stdlib/random-iter
|
|
186
219
|
|
|
187
|
-
[test-image]: https://github.com/stdlib-js/random-iter/actions/workflows/test.yml/badge.svg?branch=v0.2.
|
|
188
|
-
[test-url]: https://github.com/stdlib-js/random-iter/actions/workflows/test.yml?query=branch:v0.2.
|
|
220
|
+
[test-image]: https://github.com/stdlib-js/random-iter/actions/workflows/test.yml/badge.svg?branch=v0.2.2
|
|
221
|
+
[test-url]: https://github.com/stdlib-js/random-iter/actions/workflows/test.yml?query=branch:v0.2.2
|
|
189
222
|
|
|
190
223
|
[coverage-image]: https://img.shields.io/codecov/c/github/stdlib-js/random-iter/main.svg
|
|
191
224
|
[coverage-url]: https://codecov.io/github/stdlib-js/random-iter?branch=main
|
|
@@ -197,8 +230,8 @@ Copyright © 2016-2024. The Stdlib [Authors][stdlib-authors].
|
|
|
197
230
|
|
|
198
231
|
-->
|
|
199
232
|
|
|
200
|
-
[chat-image]: https://img.shields.io/
|
|
201
|
-
[chat-url]: https://
|
|
233
|
+
[chat-image]: https://img.shields.io/badge/zulip-join_chat-brightgreen.svg
|
|
234
|
+
[chat-url]: https://stdlib.zulipchat.com
|
|
202
235
|
|
|
203
236
|
[stdlib]: https://github.com/stdlib-js/stdlib
|
|
204
237
|
|
package/docs/types/index.d.ts
CHANGED
|
@@ -457,6 +457,7 @@ interface Namespace {
|
|
|
457
457
|
*
|
|
458
458
|
* @param alpha - shape parameter
|
|
459
459
|
* @param s - rate parameter
|
|
460
|
+
* @param m - location parameter
|
|
460
461
|
* @param options - function options
|
|
461
462
|
* @throws `alpha` must be a positive number
|
|
462
463
|
* @throws `s` must be a positive number
|
|
@@ -465,7 +466,7 @@ interface Namespace {
|
|
|
465
466
|
* @returns iterator
|
|
466
467
|
*
|
|
467
468
|
* @example
|
|
468
|
-
* var iter = ns.frechet( 2.0, 5.0 );
|
|
469
|
+
* var iter = ns.frechet( 2.0, 5.0, 3.0 );
|
|
469
470
|
*
|
|
470
471
|
* var r = iter.next().value;
|
|
471
472
|
* // returns <number>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stdlib/random-iter",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Pseudorandom number generator iterators.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"@stdlib/random-iter-erlang": "^0.2.1",
|
|
45
45
|
"@stdlib/random-iter-exponential": "^0.2.1",
|
|
46
46
|
"@stdlib/random-iter-f": "^0.2.1",
|
|
47
|
-
"@stdlib/random-iter-frechet": "^0.2.
|
|
47
|
+
"@stdlib/random-iter-frechet": "^0.2.2",
|
|
48
48
|
"@stdlib/random-iter-gamma": "^0.2.1",
|
|
49
49
|
"@stdlib/random-iter-geometric": "^0.2.1",
|
|
50
50
|
"@stdlib/random-iter-gumbel": "^0.2.1",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"@stdlib/random-iter-triangular": "^0.2.1",
|
|
72
72
|
"@stdlib/random-iter-uniform": "^0.2.1",
|
|
73
73
|
"@stdlib/random-iter-weibull": "^0.2.1",
|
|
74
|
-
"@stdlib/utils-define-read-only-property": "^0.2.
|
|
74
|
+
"@stdlib/utils-define-read-only-property": "^0.2.2"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {},
|
|
77
77
|
"engines": {
|