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

Crossany and crossover resulting in differing size arrays than original data #23

Closed
trevorwelch opened this issue Jul 10, 2018 · 6 comments

Comments

@trevorwelch
Copy link

From my Jupyter notebook:

In [24]:
len(ti.crossany(np.ascontiguousarray(df['high']), np.ascontiguousarray(df['bbands_2'])))
​
Out[24]:
2999

In [27]:
len(df['bbands_2'])

Out[27]:
3000

In [28]:
len(df['high'])

Out[28]:
3000

This seems odd!

@codeplea
Copy link
Member

What seem odd about it? It's not possible on the first bar to know if they've crossed or not.

@trevorwelch
Copy link
Author

Ah, got it. The docs sounded (to me) like any row (following my example above) in which bbands_2 was > high there should be a signal. It makes sense that it would be waiting for a "crossover" though, based on the name ;)

That said, it seems like it would be valuable to clarify in the docs that the array returned from a tulipy indicator must be padded at the front end in order to be aligned with/added to the original data given to the indicator function (i.e. a numpy array or pandas Series).

For my purposes, I accomplished this like so:

import tulipy as ti
import numpy as np
import pandas as pd

period = 14

df['RSI'] = pd.Series(np.pad(ti.rsi(np.ascontiguousarray(df.close), period=period), [(period,0)], mode='mean'))

@codeplea
Copy link
Member

The docs sounded (to me) like any row (following my example above) in which bbands_2 was > high there should be a signal. It makes sense that it would be waiting for a "crossover" though, based on the name ;)

I think the docs are pretty clear: https://tulipindicators.org/crossover It shows in the formula that must be input1 > input2 and that it wasn't the case on the previous bar.

The shorter output array thing is true for most of the functions. For example, if you call a simple moving average with a period of 10, your output will be 9 bars shorter. There's really no way around it.

@trevorwelch
Copy link
Author

I think the docs are pretty clear: https://tulipindicators.org/crossover It shows in the formula that must be input1 > input2 and that it wasn't the case on the previous bar.

Certainly the formula is clear! I suppose I expect the text surrounding the math notation to explain in plain speech alongside the formula.

The shorter output array thing is true for most of the functions. For example, if you call a simple moving average with a period of 10, your output will be 9 bars shorter. There's really no way around it.

Definitely is the case. I do think it would be helpful for the uninitiated to have a basic example of how to use the indicators in a typical Python data science environment. I'd be happy to make a Jupyter notebook and contribute it, if you're open to the idea.

@codeplea
Copy link
Member

I'd be happy to make a Jupyter notebook and contribute it, if you're open to the idea.

I'm certainly open to it.

I'm not sure padding the output arrays is always the most useful thing, though. When I use it, I just index from the end, rather than the beginning.

Looking over the Readme, I think it would also be nice to add that data arrays start with the oldest data in the first position, and end with the newest data in the last position. I've been asked this several times. It's really confusing if someone does it backwards.

Tulip Indicators (the C library tulipy is a wrapper of) also has functions to tell how much shorter the outputs will be compared to the inputs. In Python, it wasn't necessary because arrays store their lengths. You might want to take a look at https://tulipindicators.org/usage if you haven't already.

@cirla
Copy link
Collaborator

cirla commented Dec 1, 2019

Closing as there's no bug. Created #40 to follow-up on documentation updates.

@cirla cirla closed this as completed Dec 1, 2019
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

3 participants