What is a DAX?
The DAX is a stock exchange index consisting of the 30 major German blue chip companies trading on the Frankfurt stock market . it's a complete return index. Prices are taken from the Xetra trading venue.
How to analyze dax data in python?
!pip install yfinance
import math
import numpy as np
import pandas as pd
import pandas_datareader as web
import matplotlib.pyplot as plt
How to import dax data from yahoo finance?
import yfinance as yf
DAX = yf.download('^GDAXI',
start='2010-01-01',
end='2021-02-26',
progress=False)
How to get a dax returns in python?
DAX['Returns'] = np.log(DAX['Close'] / DAX['Close'].shift(1))
plt.figure(figsize=(7, 5))
plt.subplot(211)
DAX['Adj Close'].plot()
plt.title('DAX Index')
plt.subplot(212)
DAX['Returns'].plot()
plt.title('log returns')
How to plot log return and dax data in python?
plt.tight_layout()
S0 = DAX['Close'][-1]
vol = np.std(DAX['Returns']) * math.sqrt(252)
r = 0.01
K = 10000.
T = 1.0
M = 50 # number of time steps
dt = T / M # length of time interval
I = 10000 # number of paths to simulate
np.random.seed(5000) # fixed seed value
# Simulation
S = np.zeros((M + 1, I), dtype=np.float) # array for simulated DAX levels
S[0] = S0 # initial values
for t in xrange(1, M + 1):
ran = np.random.standard_normal(I) # pseudo-random numbers
S[t] = S[t - 1] * np.exp((r - vol ** 2 / 2) * dt
+ vol * math.sqrt(dt) * ran)
V0 = math.exp(-r * T) * np.sum(np.maximum(S[-1] - K, 0)) / I
h5file = pd.HDFStore('DAX_data.h5')
h5file['DAX'] = DAX
h5file.close()
DAX
Open | High | Low | Close | Adj Close | Volume | Returns | |
---|---|---|---|---|---|---|---|
Date | |||||||
2010-01-04 | 5975.520020 | 6048.299805 | 5974.430176 | 6048.299805 | 6048.299805 | 104344400 | NaN |
2010-01-05 | 6043.939941 | 6058.020020 | 6015.669922 | 6031.859863 | 6031.859863 | 117572100 | -0.002722 |
2010-01-06 | 6032.390137 | 6047.569824 | 5997.089844 | 6034.330078 | 6034.330078 | 108742400 | 0.000409 |
2010-01-07 | 6016.799805 | 6037.569824 | 5961.250000 | 6019.359863 | 6019.359863 | 133704300 | -0.002484 |
2010-01-08 | 6028.620117 | 6053.040039 | 5972.240234 | 6037.609863 | 6037.609863 | 126099000 | 0.003027 |
... | ... | ... | ... | ... | ... | ... | ... |
2021-02-19 | 13941.400391 | 14026.179688 | 13892.719727 | 13993.230469 | 13993.230469 | 72974000 | 0.007626 |
2021-02-22 | 13858.559570 | 13975.080078 | 13802.549805 | 13950.040039 | 13950.040039 | 66035300 | -0.003091 |
2021-02-23 | 13984.980469 | 13989.240234 | 13664.709961 | 13864.809570 | 13864.809570 | 88194700 | -0.006128 |
2021-02-24 | 13855.849609 | 13998.299805 | 13855.849609 | 13976.000000 | 13976.000000 | 68922400 | 0.007988 |
2021-02-25 | 14045.019531 | 14051.009766 | 13879.169922 | 13879.330078 | 13879.330078 | 95431900 | -0.006941 |
2824 rows × 7 columns
S0
13879.330078125
vol
0.20526795893307773
S
array([[13879.33007812, 13879.33007812, 13879.33007812, ...,
13879.33007812, 13879.33007812, 13879.33007812],
[ 0. , 0. , 0. , ...,
0. , 0. , 0. ],
[ 0. , 0. , 0. , ...,
0. , 0. , 0. ],
...,
[ 0. , 0. , 0. , ...,
0. , 0. , 0. ],
[ 0. , 0. , 0. , ...,
0. , 0. , 0. ],
[ 0. , 0. , 0. , ...,
0. , 0. , 0. ]])
DAX['Close'].plot(label='DAX Index')
plt.legend(loc=0)
For all the new updates visit our github
0 Comments