react-financial-charts
react-financial-charts copied to clipboard
extraction of calculation functions
I'm submitting a...
- [ ] bug
- [x] feature
- [ ] chore
What is the current behavior
anonymous functions used in calculator of various indicators
What is the expected behavior
hello! i think your project is very useful. while reviewing the codebase, i was looking specifically for calculations used for various technical indicators, and was wondering if it would be possible (or perhaps better said - desirable from your point of view) to abstract the calculations. for example, the anonymous function here could be useful for an application that wants to calculate these values in isolation from displaying the chart:
https://github.com/react-financial/react-financial-charts/blob/5243344cf288255c0f001fa669d78ab0437dab64/packages/indicators/src/calculator/bollingerband.ts#L64-L76
simple example of extracted function (perhaps multiplier could be passed as an additional parameter or so):
const bollingerBandAlgorithm = slidingWindow()
.windowSize(windowSize)
.accumulator(extractedFunction);
const extractedFunction = (values: any[]) => {
const avg = values[values.length - 1].mean;
const stdDev = deviation<any>(values, (each) => source(each.datum));
if (stdDev === undefined) {
return undefined;
}
return {
top: avg + multiplier * stdDev,
middle: avg,
bottom: avg - multiplier * stdDev,
};
};
in particular, my reasoning behind this query is that i would like to avoid having duplicated code used for the calculation in these values for purposes other than charting. in addition, i think it could also simplify the development of tests.
please let me know if this is a change you would either be interested in implementing or alternatively if you would be interested in merging a pull request that implements this abstraction. if this is not a change that you believe is beneficial, i would also of course love to see your reasoning so that i can enlighten myself.
thank you!
Please tell us about your environment
- Version: 5243344cf288255c0f001fa669d78ab0437dab64
- Browser: n/a
Other information
i was not sure this format is ideal for my question, but in any case have done my best to adhere to the guidelines (i'm not really sure it qualifies as a feature, but it seemed the cloest).
Yeah I currently don't like the way the calculators are done at all, we haven't had time to rewrite the way they work. I agree any technical calcs should be either from an external library or separated.
do you have any opinion in regard to which lib you'd be interested in using? i have come across a few that could potentially be suitable. the best one i think so far that i've found is https://github.com/oransel/node-talib but unfortunately i don't think it would work from browser.
GitHub
A technical analysis library for node.js. Contribute to oransel/node-talib development by creating an account on GitHub.