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

Representing NA values #15

Closed
zhengyangfeng00 opened this issue Oct 29, 2019 · 3 comments
Closed

Representing NA values #15

zhengyangfeng00 opened this issue Oct 29, 2019 · 3 comments

Comments

@zhengyangfeng00
Copy link
Contributor

Hi! I think it's useful to have a special NA or NaN value to represent the case where a value cannot be calculated. Other popular data analysis libraries such like numpy/pandas all have it.

One use case is that I want to calculate the difference between today's close price and yesterday's close price for each candle in the time series. Then I want to do dif := techan.NewDifferenceIndicator(today, NewRefIndicator(yday, 1)) but if I accidentally call dif.Calculate(0) it will segfault.

I think we can workaround this problem by other means but I feel the most natural way is to add a NA value. What's your thoughts on this?

@sdcoffey
Copy link
Owner

Hey @zhengyangfeng00, I like the idea! Definitely an omission from the library in it's current state. How would you feel about collaborating on this? If you send me a PR i'm happy to look at it, otherwise, i'll try to address this as soon as I have time

@zhengyangfeng00
Copy link
Contributor Author

I'm happy to work on a PR. I'm experimenting with a very simple implementation:

package na

import (
	"math"
	
	"github.com/sdcoffey/big"
)

var (
	// NA is a decimal object that represents a result that cannot be calculated.
	NA = big.NewDecimal(float64(math.MaxInt64))
)

func IsNA(d big.Decimal) bool {
	return d.EQ(NA)
}

and it worked fine with my use cases. I basically have all indicators be aware of this NaN value. Essentially if an indicator depends on another one, then in its Calculate it first checks if the indicator it depends on calculates to NaN and if so, it returns NaN as well.

The majority of work I image is to update all existing indicators to behave similar?

@sdcoffey
Copy link
Owner

sdcoffey commented Jan 9, 2020

@zhengyangfeng00 Since this is more of a feature of big, i've moved this ticket here:
sdcoffey/big#3

@sdcoffey sdcoffey closed this as completed Jan 9, 2020
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

No branches or pull requests

2 participants