-
Notifications
You must be signed in to change notification settings - Fork 185
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bollinger mark & transform #1772
Conversation
src/marks/bollinger.js
Outdated
); | ||
} | ||
|
||
export function bollingerX(n, k, options) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure n and k should be required positional arguments here. Probably would be more consistent to have a bollingerOptions argument, and allow a single combined options, too. And maybe a single number could be used to specify n; n defaults to 20 and k defaults to 2.
src/marks/bollinger.js
Outdated
if (x === undefined && x1 === undefined && x2 === undefined) options = {...options, x: (x = identity)}; | ||
const outputs = {}; | ||
if (x != null) outputs.x = bollinger(n, k); | ||
if (x1 != null) outputs.x1 = bollinger(n, -k); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
By negating k here, bollingerX behaves like mapX, and can be used for either area or line!
Nice, we get a build failure now when we don’t document something. 😁 I’ll add that to the PR. |
Nice! It’s a useful and sound method for general time series analysis. I'm just wondering if we should keep that name and defaults of the transform. “Bollinger” seems to be confined to finance (according to wikipedia), and has the default multiplier = 2 (not a bad choice, but mathematically surprising). Reading https://www.bollingerbands.com/bollinger-bands, I see that "bands" is plural—they represent the three lines y = moving average MA, y2 = MA+2 Dev, and y1 = MA-2 Dev. Whereas how I see it in our usage, we're considering a singular band, the area between y1 and y2. Also, there is a trademark on the name. Even in finance, people seem to be using “volatility” often (shown as a 1-sigma band). The 1-sigma band excludes 31.8% of the distribution on a normal model, so it makes sense to use a 2-sigma band as the default (4.6% outliers), but it's also legit to do 3-sigma (0.3%), etc. Other data science domains seem to be using words like “rolling window variance” or “rolling window deviation”, and plotting them with 1-sigma, 2-sigma, 3-sigma lines or bands, or adapting the sigmas to match 10%, 5%, 1%…. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only blocking remark is that there is a TODO in the documentation.
Non-blocking remarks & questions:
- To apply in log-space rather than in linear-space (e.g., to avoid negative values if the multiplier × the deviation is high), one can do:
Plot.bollingerY(aapl, { x: "Date", y: (d) => t(d.Close), k }).plot({
y: { transform: (d) => t.invert(d), domain: [0, 300], nice: true }
})
with t = d3.scaleLog()
👍. (Note that the difference on aapl with the default parameters is totally imperceptible.)
-
Should we add the anchor option? For time series we obviously don't want to use “values from the future“, and if the data is coming in reverse chronological order (e.g.
data = d3.reverse(aapl)
, it seems important to either anchor: "start" or use an explicit sort: "Date". Similarly, it could be useful to anchor “middle” if x is not time, and we want to gauge local variance. -
In that vein I'd also want to expose the underlying strict option, which would be particularly useful to set to false when the data has gaps (e.g., interval: "day" on the aapl dataset). (If we support that option and default it to true, we should document it as it is the converse of windowY's default.)
67fbf48
to
b0afd6c
Compare
200f911
to
a0f9de6
Compare
* bollinger mark & transform * strict & anchor for bollinger * fancy candlesticks 🕯️ * more documentation
* bollinger mark & transform * strict & anchor for bollinger * fancy candlesticks 🕯️ * more documentation
Fixes #548.