joshuaulrich / joshuaulrich/quantmod

Volume Endpoints Functionality

Open
#236 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
R
Stars
906
Forks
233
PR merge metrics
No merged PRs in 30d

Description

I propose adding functionality to create an endpoints vector based on volume. This is similar to `xts::endpoints`, but extracts index values based on volume rather than a time based frequency. For example, this function could be used to create an OHLCV series with an observation every 5000 shares traded. This is based on the idea of a "volume clock" as presented in [The Volume Clock: Insights into the High Frequency Paradigm](https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2034858).

```
volume.endpoints <- function (x, k = 1)
{
# assumes x is univariate with volume or trade size
x <- try.xts(x)
z <- coredata(na.fill(x, 0))
sum.vol <- 0
v.ep <- 0
ne0 <- which(z != 0)
for (i in ne0) {
sum.vol <- sum.vol + z[i]
if (sum.vol >= k) {
v.ep <- c(v.ep, i)
sum.vol <- 0
}
}
if (last(v.ep) != nrow(x))
v.ep <- c(v.ep, nrow(x))
v.ep
}
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by comparing the proposed volume.endpoints function with xts::endpoints and the supplied pseudocode. Determine how volume-based index positions should be exposed and validated, then confirm the implementation produces endpoints at the requested volume threshold and includes the final observation.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.