danghungithp's picture
Upload 1398 files
bec48e1 verified
raw
history blame contribute delete
895 Bytes
const calculatePV = (priceData, volumeData) => {
if (priceData.length !== volumeData.length) {
throw new Error("Price and volume data must have the same length");
}
const pv = [];
for (let i = 0; i < priceData.length; i++) {
const priceChange = priceData[i] - (priceData[i - 1] || priceData[i]);
const volume = volumeData[i];
pv.push(priceChange * volume);
}
return pv;
};
const analyzePV = (pvData) => {
const analysis = {
bullish: 0,
bearish: 0,
neutral: 0,
};
for (let i = 1; i < pvData.length; i++) {
if (pvData[i] > 0 && pvData[i - 1] > 0) {
analysis.bullish++;
} else if (pvData[i] < 0 && pvData[i - 1] < 0) {
analysis.bearish++;
} else {
analysis.neutral++;
}
}
return analysis;
};
export { calculatePV, analyzePV };