k-line/dist8/assets/computedInfo-DRxOaYt6.js

2 lines
2.2 KiB
JavaScript

function x(a,o){if(a.length<o)return null;let i=[];for(let u=0;u<=a.length-o;u++){let l=0;for(let t=0;t<o;t++)l+=a[u+t];i.push(l/o)}return i=i.map(u=>parseFloat(u.toFixed(2))),i}function M(a){if(a.length===0)throw new Error("价格数组不能为空");const o=a.reduce((t,h)=>t+h,0)/a.length,u=a.reduce((t,h)=>t+Math.pow(h-o,2),0)/(a.length-1);return parseFloat(Math.sqrt(u).toFixed(2))}function j(a,o=12,i=26,u=9){function l(s,r){let c=[],m=2/(r+1),g=0;for(let p=0;p<r;p++)g+=s[p];let F=g/r;c.push(F);for(let p=r;p<s.length;p++){let d=(s[p]-F)*m+F;c.push(d),F=d}return c}let t=l(a,o),h=l(a,i),n=[];for(let s=0;s<Math.min(t.length,h.length);s++)n.push(t[s]-h[s]);let e=l(n,u),f=[];for(let s=0;s<Math.min(n.length,e.length);s++)f.push((n[s]-e[s])*2);return n=n.map(s=>parseFloat(s.toFixed(2))),e=e.map(s=>parseFloat(s.toFixed(2))),f=f.map(s=>parseFloat(s.toFixed(2))),{dif:n,dea:e,macd:f}}function v(a){let o=[];const i=Object.keys(a.date);for(let u of i){const l=parseInt(u,10),t=[a.date[l],a.low[l],a.high[l],a.close[l]];o.push(t)}return o}function w(a){a=v(a);let o=[],i=[],u=[];a.forEach(e=>{o.push(e[1]),i.push(e[2]),u.push(e[3])});let l=[],t=[],h=[],n=9;for(let e=0;e<u.length;e++){if(e<n-1){l.push(10),t.push(10),h.push(10);continue}let f=Math.min(...o.slice(e-n+1,e+1)),s=Math.max(...i.slice(e-n+1,e+1)),r=(u[e]-f)/(s-f)*100;if(e===n-1)l.push(r),t.push(r);else{let m=.6666666666666666*l[e-1]+.3333333333333333*r;l.push(m);let g=2/3*t[e-1]+1/3*m;t.push(g)}let c=3*l[e]-2*t[e];h.push(c)}return l=l.map(e=>parseFloat(e.toFixed(2))),t=t.map(e=>parseFloat(e.toFixed(2))),h=h.map(e=>parseFloat(e.toFixed(2))),{kValues:l,dValues:t,jValues:h}}function A(a,o=6){let i=[],u=[],l=[];for(let t=0;t<a.length;t++){if(t===0)i.push(0),u.push(0);else{let h=a[t]-a[t-1];h>0?(i.push(h),u.push(0)):(i.push(0),u.push(Math.abs(h)))}if(t>=o-1){let h=0,n=0;for(let r=t-(o-1);r<=t;r++)h+=i[r],n+=u[r];let e=h/o,f=n/o,s=e/f;l.push(100-100/(1+s))}}return l=l.map(t=>parseFloat(t.toFixed(2))),l}function E(a,o,i){let u=[],l=Object.values(a),t=Object.values(o),h=Object.values(i);for(let n=0;n<l.length;n++){let e=(t[n]+h[n])/2;u.push({value:l[n],itemStyle:{color:l[n]>=e?"#FF0000":"#00FF00"}})}return u}export{M as a,j as b,x as c,E as d,w as e,A as f};