library(reticulate)
#py_install("numpy")
py_install("seaborn")
py_install("scipy")
Importando paquetes.
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set()
Importando los datos.
import pandas as pd
raw_csv_data=pd.read_csv("E:/Index2018.csv")
df_comp=raw_csv_data.copy()
Examinando la data.
df_comp.head(10)
## date spx dax ftse nikkei
## 0 07/01/1994 469.90 2224.95 3445.98 18124.01
## 1 10/01/1994 475.27 2225.00 3440.58 18443.44
## 2 11/01/1994 474.13 2228.10 3413.77 18485.25
## 3 12/01/1994 474.17 2182.06 3372.02 18793.88
## 4 13/01/1994 472.47 2142.37 3360.01 18577.26
## 5 14/01/1994 474.91 2151.05 3400.56 18973.70
## 6 17/01/1994 473.30 2115.56 3407.83 18725.37
## 7 18/01/1994 474.25 2130.35 3437.01 18514.55
## 8 19/01/1994 474.30 2132.52 3475.15 19039.40
## 9 20/01/1994 474.98 2098.36 3469.99 19183.92
df_comp
## date spx dax ftse nikkei
## 0 07/01/1994 469.900000 2224.95 3445.980000 18124.01
## 1 10/01/1994 475.270000 2225.00 3440.580000 18443.44
## 2 11/01/1994 474.130000 2228.10 3413.770000 18485.25
## 3 12/01/1994 474.170000 2182.06 3372.020000 18793.88
## 4 13/01/1994 472.470000 2142.37 3360.010000 18577.26
## ... ... ... ... ... ...
## 6264 23/01/2018 2839.130362 13559.60 7731.827774 24124.15
## 6265 24/01/2018 2837.544008 13414.74 7643.428966 23940.78
## 6266 25/01/2018 2839.253031 13298.36 7615.839954 23669.49
## 6267 26/01/2018 2872.867839 13340.17 7665.541292 23631.88
## 6268 29/01/2018 2853.528411 13324.48 7671.533300 23629.34
##
## [6269 rows x 5 columns]
df_comp.describe()
## spx dax ftse nikkei
## count 6269.000000 6269.000000 6269.000000 6269.000000
## mean 1288.127542 6080.063363 5422.713545 14597.055700
## std 487.586473 2754.361032 1145.572428 4043.122953
## min 438.920000 1911.700000 2876.600000 7054.980000
## 25% 990.671905 4069.350000 4486.100000 10709.290000
## 50% 1233.420000 5773.340000 5662.430000 15028.170000
## 75% 1459.987747 7443.070000 6304.250000 17860.470000
## max 2872.867839 13559.600000 7778.637689 24124.150000
df_comp.isna()
## date spx dax ftse nikkei
## 0 False False False False False
## 1 False False False False False
## 2 False False False False False
## 3 False False False False False
## 4 False False False False False
## ... ... ... ... ... ...
## 6264 False False False False False
## 6265 False False False False False
## 6266 False False False False False
## 6267 False False False False False
## 6268 False False False False False
##
## [6269 rows x 5 columns]
df_comp.isna().sum()
## date 0
## spx 0
## dax 0
## ftse 0
## nikkei 0
## dtype: int64
df_comp['spx'].isna().sum()
## 0
Ploteando la data.
import matplotlib.pyplot as plt
df_comp.spx.plot(figsize=(20,10),title="S&P500 Prices")
## <AxesSubplot:title={'center':'S&P500 Prices'}>
plt.show()

df_comp.ftse.plot(figsize=(20,8), title = "FTSE100 Prices")
## <AxesSubplot:title={'center':'FTSE100 Prices'}>
plt.show()

df_comp.spx.plot(figsize=(20,8), title = "S&P500 Prices")
## <AxesSubplot:title={'center':'S&P500 Prices'}>
df_comp.ftse.plot(figsize=(20,8), title = "FTSE100 Prices")
## <AxesSubplot:title={'center':'FTSE100 Prices'}>
plt.title("S&P vs FTSE")
## Text(0.5, 1.0, 'S&P vs FTSE')
plt.show()

El gráfico QQplot.
import scipy.stats
scipy.stats.probplot(df_comp.spx, plot = plt)
## ((array([-3.69357572, -3.46171913, -3.33410335, ..., 3.33410335,
## 3.46171913, 3.69357572]), array([ 438.92 , 441.49 , 441.96 , ..., 2839.253031,
## 2853.528411, 2872.867839])), (476.460561028412, 1288.1275420815123, 0.9767273150948816))
plt.title("QQ Plot", size = 24)
## Text(0.5, 1.0, 'QQ Plot')
plt.show()
## Traceback (most recent call last):
## File "C:\Users\Jaime\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\matplotlib\backends\backend_qt5.py", line 475, in _draw_idle
## self.draw()
## File "C:\Users\Jaime\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\matplotlib\backends\backend_agg.py", line 406, in draw
## self.figure.draw(self.renderer)
## File "C:\Users\Jaime\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\matplotlib\artist.py", line 74, in draw_wrapper
## result = draw(artist, renderer, *args, **kwargs)
## File "C:\Users\Jaime\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
## return draw(artist, renderer, *args, **kwargs)
## File "C:\Users\Jaime\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\matplotlib\figure.py", line 2780, in draw
## mimage._draw_list_compositing_images(
## File "C:\Users\Jaime\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\matplotlib\image.py", line 132, in _draw_list_compositing_images
## a.draw(renderer)
## File "C:\Users\Jaime\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\matplotlib\artist.py", line 51, in draw_wrapper
## return draw(artist, renderer, *args, **kwargs)
## File "C:\Users\Jaime\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\matplotlib\_api\deprecation.py", line 431, in wrapper
## return func(*inner_args, **inner_kwargs)
## File "C:\Users\Jaime\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\matplotlib\axes\_base.py", line 2881, in draw
## self._update_title_position(renderer)
## File "C:\Users\Jaime\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\matplotlib\axes\_base.py", line 2810, in _update_title_position
## if (ax.xaxis.get_ticks_position() in ['top', 'unknown']
## File "C:\Users\Jaime\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\matplotlib\axis.py", line 2229, in get_ticks_position
## self._get_ticks_position()]
## File "C:\Users\Jaime\AppData\Local\R-MINI~1\envs\R-RETI~1\lib\site-packages\matplotlib\axis.py", line 1934, in _get_ticks_position
## minor = self.minorTicks[0]
## IndexError: list index out of range
