Skip to content
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

Ability to remove (to re-calc) cached calculations #33

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

tomcruise81
Copy link

Not sure if this would be something that you're interested in, but I've found benefit from using the MACD Histogram with minute candles, where the last candle is updated based on sub-minute streamed values - i.e. the last candle is an approximation, but still provides value. It requires the ability to re-calculate (i.e. not use the cached value).

@codecov
Copy link

codecov bot commented Mar 5, 2021

Codecov Report

Merging #33 (61a09a5) into main (e87ec2e) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #33      +/-   ##
==========================================
+ Coverage   99.29%   99.31%   +0.02%     
==========================================
  Files          35       35              
  Lines         566      587      +21     
==========================================
+ Hits          562      583      +21     
  Misses          2        2              
  Partials        2        2              
Impacted Files Coverage Δ
indicator_basic.go 100.00% <ø> (ø)
indicator_cci.go 100.00% <ø> (ø)
indicator_constant.go 100.00% <ø> (ø)
indicator_fixed.go 100.00% <ø> (ø)
indicator_aroon.go 93.54% <100.00%> (+0.21%) ⬆️
indicator_bollinger_band.go 100.00% <100.00%> (ø)
indicator_derivative.go 100.00% <100.00%> (ø)
indicator_difference.go 100.00% <100.00%> (ø)
indicator_maximum_drawdown.go 100.00% <100.00%> (ø)
indicator_maximum_value.go 100.00% <100.00%> (ø)
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e87ec2e...61a09a5. Read the comment docs.

@sdcoffey
Copy link
Owner

sdcoffey commented Mar 6, 2021

Hey @tomcruise81! Love the idea. Check out #30 which I just merged. I think if we export the new cachedIndicator type, and you add this method there, and then change the return types of all cached indicators to the new type, we can accomplish this without changing the base type or breaking the API. Lmk what you think

@tomcruise81
Copy link
Author

@sdcoffey - I think we'd still need to augment the other types due to the need for recursively removing the cached calculations from inner indicators. So even if I do something like:

type CachedIndicator interface {
	Indicator
	cache() resultCache
	setCache(cache resultCache)
	windowSize() int
}

func RemoveCachedEntry(indicator Indicator, index int) {
	cachedIndicator, ok := indicator.(CachedIndicator)
	if ok {
		cacheResult(cachedIndicator, index, nil)
	}
	for _, subIndicator := range indicator.subIndicators() {
		RemoveCachedEntry(subIndicator, index)
	}
}

we'd need to change to something like indicator.subIndicators() for the recursive part...

@tomcruise81
Copy link
Author

...although I may be able to create another interface:

type NestedIndicator interface {
	Indicator
	nestedIndicators() []Indicator
}

func RemoveCachedEntry(indicator Indicator, index int) {
	cachedIndicator, ok := indicator.(CachedIndicator)
	if ok {
		cacheResult(cachedIndicator, index, nil)
	}

	// Recursion
	nestedIndicator, ok := indicator.(NestedIndicator)
	if ok {
		for _, nestedIndicator := range nestedIndicator.nestedIndicators() {
			cachedNestedIndicator, ok := nestedIndicator.(CachedIndicator)
			if ok {
				RemoveCachedEntry(cachedNestedIndicator, index)
			}
		}
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants