I'm working on a dataframe with prices. I find the returns calculated arithmetic or log are different than actual return between first price value and the last. As I see it they should be the same or differ by small fractions.
dfset.head()
Open Close High Low Volume
Date_utc
2017-12-01 00:00:00 432.01 434.56 435.09 432.01 781.788110
2017-12-01 00:05:00 434.25 435.82 436.98 434.25 584.017105
2017-12-01 00:10:00 435.81 435.50 436.39 434.80 494.047392
2017-12-01 00:15:00 435.88 435.10 436.07 434.50 527.840340
2017-12-01 00:20:00 434.51 433.50 434.95 432.98 458.557971
dfset.tail()
Open Close High Low Volume
Date_utc
2017-12-21 23:40:00 781.41 781.01 783.46 778.12 792.433089
2017-12-21 23:45:00 779.60 784.76 784.90 778.20 657.316066
2017-12-21 23:50:00 784.83 783.42 784.90 782.22 473.108867
2017-12-21 23:55:00 783.40 786.98 787.00 782.62 1492.764405
2017-12-22 00:00:00 786.96 791.93 792.00 786.86 1745.559100
when calculating returns either by:
dfset['Close'].pct_change().sum()
0.694478597676
or using log returns:
np.log(dfset['Close'] / dfset['Close'].shift(1)).sum()
0.60013897914
Actual overall return which I consider to be the correct one:
dfset['Close'].iloc[len(dfset) - 1] / dfset['Close'].iloc[0] - 1
0.822372054492
Any ideas please why the arithmetic and log returns are off?
INSTALLED VERSIONS
------------------
commit: None
python: 3.6.3.final.0
python-bits: 64
OS: Darwin
OS-release: 16.7.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.21.1
pytest: 3.2.1
pip: 9.0.1
setuptools: 36.5.0.post20170921
Cython: 0.26.1
numpy: 1.13.3
scipy: 0.19.1
pyarrow: None
xarray: None
IPython: 6.1.0
sphinx: 1.6.3
patsy: 0.4.1
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.2
feather: None
matplotlib: 2.1.0
openpyxl: 2.4.8
xlrd: 1.1.0
xlwt: 1.2.0
xlsxwriter: 1.0.2
lxml: 4.1.0
bs4: 4.6.0
html5lib: 0.999999999
sqlalchemy: 1.1.13
pymysql: None
psycopg2: None
jinja2: 2.9.6
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: 0.5.0
None