PageSourceSearch

https://mirawealth.io/assets/monte-carlo.worker-Dg61Zyrx.js

js mirawealth.io collected 2026-10-09 22:53:53 UTC 5,993 bytes, 1 lines download raw bytes

1var __defProp=Object.defineProperty,__defNormalProp=(e,t,n)=>t in e?__defProp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,__publicField=(e,t,n)=>__defNormalProp(e,"symbol"!=typeof t?t+"":t,n);!function(){"use strict";class e{constructor(e){__publicField(this,"seed"),this.seed=e>>>0||123456789}next(){let e=this.seed>>>0;return e^=e<<13,e^=e>>>17,e^=e<<5,this.seed=e>>>0,this.seed/4294967296}uniform(e=0,t=1){return e+(t-e)*this.next()}normal(){const e=Math.max(this.next(),1e-12),t=Math.max(this.next(),1e-12);return Math.sqrt(-2*Math.log(e))*Math.cos(2*Math.PI*t)}}let t=null;function n(){return t?t.next():Math.random()}function a(n){t=new e(n)}const s={50:.00341,51:.003684,52:.003992,53:.004345,54:.004748,55:.005198,56:.005686,57:.006213,58:.006788,59:.007429,60:.008156,61:.008959,62:.009829,63:.01076,64:.01176,65:.012843,66:.014014,67:.015278,68:.016645,69:.018134,70:.019771,71:.021572,72:.023551,73:.025707,74:.02805,75:.030618,76:.03346,77:.03662,78:.040124,79:.043994,80:.048252,81:.052921,82:.058025,83:.063588,84:.069637,85:.076197,86:.083295,87:.090958,88:.09921,89:.108077,90:.117583,91:.127754,92:.138612,93:.15018,94:.162481,95:.175535,96:.189365,97:.203989,98:.219427,99:.235696,100:.252813,101:.270796,102:.289661,103:.309426,104:.330105,105:.351716,106:.374274,107:.397795,108:.422293,109:.447784,110:.474285,111:.501809,112:.530372,113:.55999,114:.590677,115:.62245,116:.655324,117:.689314,118:.724436,119:.760707,120:1},r={excellent:.7,good:1,fair:1.5,poor:2.2};function o(e,t="good"){const a=s[Math.min(120,Math.max(50,Math.round(e)))]||s[120],o=Math.min(1,a*r[t]);return n()>o}function l(e,t,n,a){const s=o(e,t),r=o(n,a);return{userSurvives:s,spouseSurvives:r,eitherSurvives:s||r}}function i(e,t,a){let s;if(a<.25){const a=Math.max(t+5,e-8),r=e-3;s=a+n()*(r-a)}else if(a<.75){const t=e-2,a=e+2;s=t+n()*(a-t)}else{const t=e+3,a=Math.min(e+7,105);s=t+n()*(a-t)}const r=Math.max(t+1,70);return Math.round(Math.max(r,Math.min(105,s)))}function c(){if(t)return t.normal();let e=Math.max(Math.random(),1e-12),n=Math.max(Math.random(),1e-12);return Math.sqrt(-2*Math.log(e))*Math.cos(2*Math.PI*n)}function u(e,t,n,a,s){const r=[e,t,n];if(1===r.filter(e=>e>0).length){return a+s*c()}const o=function(e){const t=e.length,n=Array(t).fill(null).map(()=>Array(t).fill(0));for(let a=0;a<t;a++)for(let t=0;t<=a;t++)if(a===t){let a=0;for(let e=0;e<t;e++)a+=n[t][e]*n[t][e];n[t][t]=Math.sqrt(Math.max(0,e[t][t]-a))}else{let s=0;for(let e=0;e<t;e++)s+=n[a][e]*n[t][e];n[a][t]=0===n[t][t]?0:(e[a][t]-s)/n[t][t]}return n}([[1,.15,0],[.15,1,.3],[0,.3,1]]),l=[c(),c(),c()],i=[o[0][0]*l[0],o[1][0]*l[0]+o[1][1]*l[1],o[2][0]*l[0]+o[2][1]*l[1]+o[2][2]*l[2]],u=[1.2*a+1.2*s*i[0],.5*a+.3*s*i[1],.3*a+.1*s*i[2]];let h=0;for(let c=0;c<3;c++)h+=r[c]*u[c];return h}function h(e,t,n,a,s){const r=e/t;let o=e,l="inflation";return r>1.2*n?(o=.9*e,l="capital-preservation"):r<.8*n?(o=1.1*e,l="prosperity"):o=e*(1+a),{withdrawal:o,adjustmentType:l}}function f(e){let t=e.currentRetirementAssets;const a=[];let s=null;const r=Math.max(0,e.retirementAge-e.currentAge);let c;if(e.spouseAge&&e.spouseLifeExpectancy){const t=function(e,t,a,s,r=.4){const o=n(),l=r*o+(1-r)*n();return{userLife:i(e,t,o),spouseLife:i(a,s,l)}}(e.lifeExpectancy,e.currentAge,e.spouseLifeExpectancy,e.spouseAge,.4);c=Math.max(t.userLife,t.spouseLife)}else c=function(e,t){const a=n();let s;if(a<.25){const a=Math.max(t+5,e-8),r=e-3;s=a+n()*(r-a)}else if(a<.75){const t=e-2,a=e+2;s=t+n()*(a-t)}else{const t=e+3,a=Math.min(e+7,105);s=t+n()*(a-t)}const r=Math.max(t+1,70);return Math.round(Math.max(r,Math.min(105,s)))}(e.lifeExpectancy,e.currentAge);e.retirementAge;for(let n=0;n<r;n++){t+=e.annualSavings;t*=1+u(e.stockAllocation,e.bondAllocation,e.cashAllocation,e.expectedReturn,e.returnVolatility),t=Math.max(0,t)}let f=e.withdrawalRate*t,p=!0,d=void 0!==e.spouseAge,M=e.annualGuaranteedIncome,m=e.currentAge+r,g=0;for(;(p||d)&&t>0&&g<60;){if(t*=1+u(e.stockAllocation,e.bondAllocation,e.cashAllocation,e.expectedReturn,e.returnVolatility),e.useGuardrails&&g>0){f=h(f,t,e.withdrawalRate,e.inflationRate).withdrawal}else g>0&&(f*=1+e.inflationRate);
1const n=Math.max(0,f-M),i=n/(1-e.taxRate);if(t-=i,a.push({year:g+1,portfolioBalance:Math.max(0,t),withdrawal:i,netWithdrawal:n}),t<=0&&null===s){s=r+g+1;break}if(void 0!==e.spouseAge){const t=e.spouseAge+r+g,n=l(m,e.userHealthStatus||"good",t,e.spouseHealthStatus||"good");if(p=n.userSurvives,d=n.spouseSurvives,!n.eitherSurvives)break;(!p&&d||p&&!d)&&(f*=.75,M*=.6)}else if(p=o(m,e.userHealthStatus||"good"),!p)break;m++,g++}const y=t>=e.legacyGoal;return{endingBalance:Math.max(0,t),success:y,yearsUntilDepletion:s,yearlyData:a}}function p(e,t,n){const a=[],s=[];let r,o=0;for(let l=0;l<t;l++){const t=f(e);a.push(t.endingBalance),s.push(t.yearsUntilDepletion),t.success&&o++,0===l&&0===n&&(r=t.yearlyData)}return{endingBalances:a,successCount:o,depletionYears:s,yearlyData:r}}self.onmessage=function(e){const{type:t,id:n,params:s,iterations:r=1e3,batchSize:o=100,startSeed:l=12345}=e.data;if("RUN_SIMULATION"===t&&s)try{const e=Math.ceil(r/o),t=[],i=[];let c,u=0;for(let M=0;M<e;M++){const h=Math.min(o,r-M*o);a(l+1000003*M>>>0);const f=p(s,h,M);t.push(...f.endingBalances),i.push(...f.depletionYears),u+=f.successCount,0===M&&f.yearlyData&&(c=f.yearlyData);const d=(M+1)/e*100;self.postMessage({type:"PROGRESS",id:n,progress:d})}t.sort((e,t)=>e-t);const h=e=>{const n=Math.floor(e/100*(r-1));return t[n]},f=i.filter(e=>null!==e),d=f.length>0?f.reduce((e,t)=>e+t,0)/f.length:null;self.postMessage({type:"COMPLETE",id:n,result:{probabilityOfSuccess:u/r*100,medianEndingBalance:h(50),percentile10EndingBalance:h(10),percentile90EndingBalance:h(90),yearsUntilDepletion:d,confidenceIntervals:{percentile10:h(10),percentile25:h(25),percentile50:h(50),percentile75:h(75),percentile90:h(90)},scenarios:{successful:u,failed:r-u,total:r},yearlyCashFlows:c||[]}})}catch(i){self.postMessage({type:"ERROR",id:n,error:i instanceof Error?i.message:"Unknown error"})}}}();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.