10
10
start_date = '1988-01-01'
11
11
12
12
# Dealing with some missing values in Dow Jones index
13
- DowJones_df = yf .download ('DJIA' ,start_date ,str (yesterday ))
14
- Nasdaq_df = yf .download ('^IXIC' ,start_date ,str (yesterday ))
15
- diff = Nasdaq_df .index .difference (DowJones_df .index )
16
- # Display Dow Jones missing values
17
- print (diff )
18
-
19
- DowJones = np .asarray (DowJones_df .Close ).reshape (- 1 ,1 )
20
- Nasdaq = np .asarray (Nasdaq_df .drop (diff ).Close ).reshape (- 1 ,1 )
21
- Russell = np .asarray (yf .download ('^RUT' ,start_date ,str (yesterday )).drop (diff ).Close ).reshape (- 1 ,1 )
22
- SP500 = np .asarray (yf .download ('^GSPC' ,start_date ,str (yesterday )).drop (diff ).Close ).reshape (- 1 ,1 )
23
-
24
- # Ensure the data have the same shape
25
- assert DowJones .shape == Nasdaq .shape == Russell .shape == SP500 .shape
26
-
27
- ts = np .concatenate ((DowJones , Nasdaq , Russell , SP500 ), axis = 1 )
13
+ df = yf .download ('^DJI ^IXIC ^GSPC ^RUT' ,start_date ,str (yesterday ))
14
+ # Dealing with some missing values
15
+ df = df .Close .dropna (axis = 0 )
16
+ ts = np .asarray (df )
28
17
29
18
# Calculate the log returns
30
19
ratios = np .log (ts / np .roll (ts , - 1 , axis = 0 ))[:- 1 ]
31
20
32
21
# Put the returns in a dataframe
33
- tsdf = pd .DataFrame (ratios , index = DowJones_df .index [:- 1 ])
22
+ tsdf = pd .DataFrame (ratios , index = df .index [:- 1 ])
34
23
tsdf .to_csv ("latest.csv" )
0 commit comments