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

Round-trip problem with to_price_index and to_returns #95

Open
KikeM opened this issue Apr 5, 2020 · 0 comments
Open

Round-trip problem with to_price_index and to_returns #95

KikeM opened this issue Apr 5, 2020 · 0 comments

Comments

@KikeM
Copy link

KikeM commented Apr 5, 2020

Hi,

Great job you have done here.

I have realized that the methods to_price_index and to_returns have a round-trip problem.

It is due to the fact that to_price_index is not including the start parameter it takes as an argument in the first value of the returned prices.

Minimal working example

import ffn
import numpy as np

ffn.extend_pandas()

ret_ss = pd.Series(np.random.randn(100))
prices_ss = ret_ss.to_price_index(start = 100)

ret_ss.head()
# 0   -0.934990
# 1   -0.017586
# 2   -0.116771
# 3   -0.474929
# 4    0.566763
# dtype: float64

prices_ss.head()
# 0    6.500992
# 1    6.386665
# 2    5.640886
# 3    2.961868
# 4    4.640544
# dtype: float64

# The first value is using the first return, it is not start!
assert prices_ss[0] == (100 * (ret_ss[0] + 1))

# No round trip 
prices_ss.to_returns().head()
# 0         NaN
# 1   -0.017586
# 2   -0.116771
# 3   -0.474929
# 4    0.566763
# dtype: float64
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

1 participant