@@ -104,10 +104,43 @@ The namespace contains the following functions for creating iterator protocol-co
104
104
<!-- eslint no-undef: "error" -->
105
105
106
106
``` javascript
107
- var objectKeys = require ( ' @stdlib/utils/keys' );
108
- var ns = require ( ' @stdlib/random/iter' );
109
-
110
- console .log ( objectKeys ( ns ) );
107
+ var roundn = require ( ' @stdlib/math/base/special/roundn' );
108
+ var mean = require ( ' @stdlib/stats/base/mean' );
109
+ var iter = require ( ' @stdlib/random/iter' );
110
+
111
+ var initialPrice = 100.0 ;
112
+ var currentPrice = initialPrice;
113
+ var numDays = 30 ;
114
+ var volatility = 0.02 ; // 2% daily volatility
115
+
116
+ // Create iterator for random price movements:
117
+ var priceIter = iter .normal ( 0.0 , volatility );
118
+ var prices = [ initialPrice ];
119
+ var dailyReturns = [];
120
+
121
+ // Simulate price movements:
122
+ var change;
123
+ var i;
124
+ for ( i = 0 ; i < numDays; i++ ) {
125
+ change = priceIter .next ().value ;
126
+ currentPrice *= ( 1.0 + change );
127
+ prices .push ( roundn ( currentPrice, - 2 ) );
128
+ dailyReturns .push ( change * 100.0 );
129
+ }
130
+
131
+ // Calculate summary statistics:
132
+ var totalReturn = ( ( currentPrice - initialPrice ) / initialPrice ) * 100.0 ;
133
+ var avgReturn = mean ( numDays, dailyReturns, 1 );
134
+
135
+ // Print results:
136
+ console .log ( ' Stock Price Simulation Results:' );
137
+ console .log ( ' -------------------------------' );
138
+ console .log ( ' Initial Price: $%d' , initialPrice );
139
+ console .log ( ' Final Price: $%d' , roundn ( currentPrice, - 2 ) );
140
+ console .log ( ' Total Return: %d%' , roundn ( totalReturn, - 2 ) );
141
+ console .log ( ' Average Daily Return: %d%' , roundn ( avgReturn, - 2 ) );
142
+ console .log ( ' \n Price History:' );
143
+ console .log ( prices .join ( ' → ' ) );
111
144
```
112
145
113
146
</section >
0 commit comments