我想为美国证券交易所,纽约证券交易所,纳斯达克证券交易所上市的美国股票编制一个筛选器。但是我很难处理月度股票价格信息。 我已经在下面制作了一些代码来获取雅虎财务的月度股票价格。
问题1:如何在AMEX,NYSE,纳斯达克上市所有股票?
问题2:我想做最近三个月的close_price> open_price等条件判断,以及当月的close_price>上个月的close_price,上个月的close_price>每个的前一个月的收盘价自动收报机(判断一些股票的起义趋势)
问题3:我的输出可能有问题? 你可以帮助我摆脱这种情况吗?谢谢。
import pandas_datareader.data as web
import pandas as pd
all_data = {}
for ticker in ['MTW', 'CYH', 'PAH', 'FCX']:
#try:
all_data[ticker] = web.get_data_yahoo(ticker,'01/01/2016',interval='m')
print(all_data[ticker])
#print(all_data)
open_price = pd.DataFrame({tic: data['Open']
for tic, data in all_data.items()})
close_price = pd.DataFrame({tic: data['Close']
for tic, data in all_data.items()})
volume = pd.DataFrame({tic: data['Volume']
for tic, data in all_data.items()})
#date = pd.DataFrame({tic: data['Date']
#for tic, data in all_data.items()})
print(open_price,close_price,volume)
#except:
#print("Cant find",ticker)
输出如下:
Open High Low Close Volume Adj Close
Date
2016-01-04 15.610001 16.07 11.73 15.740001 21098600 3.564441
2016-02-01 15.560000 16.07 13.17 15.850001 16000500 3.589351
2016-03-01 15.990001 17.40 4.00 4.330000 5162800 4.330000
2016-04-01 4.330000 5.87 4.21 5.700000 3370100 5.700000
2016-05-02 5.730000 6.15 5.38 5.700000 3662100 5.700000
2016-06-01 5.630000 5.89 5.03 5.450000 3600500 5.450000
2016-07-01 5.460000 5.79 4.97 5.570000 2903900 5.570000
2016-08-01 5.570000 5.84 4.62 4.900000 2983800 4.900000
2016-09-01 4.920000 4.96 4.27 4.790000 1460400 4.790000
2016-10-03 4.790000 4.86 3.98 4.040000 1311500 4.040000
2016-11-01 4.030000 6.04 3.65 5.960000 2759000 5.960000
2016-12-01 6.010000 6.30 5.70 5.980000 1880800 5.980000
2017-01-03 6.030000 7.57 5.65 7.110000 1886100 7.110000
MTW
Date
2016-01-04 15.610001
2016-02-01 15.560000
2016-03-01 15.990001
2016-04-01 4.330000
2016-05-02 5.730000
2016-06-01 5.630000
2016-07-01 5.460000
2016-08-01 5.570000
2016-09-01 4.920000
2016-10-03 4.790000
2016-11-01 4.030000
2016-12-01 6.010000
2017-01-03 6.030000 MTW
Date
2016-01-04 15.740001
2016-02-01 15.850001
2016-03-01 4.330000
2016-04-01 5.700000
2016-05-02 5.700000
2016-06-01 5.450000
2016-07-01 5.570000
2016-08-01 4.900000
2016-09-01 4.790000
2016-10-03 4.040000
2016-11-01 5.960000
2016-12-01 5.980000
2017-01-03 7.110000 MTW
Date
2016-01-04 21098600
2016-02-01 16000500
2016-03-01 5162800
2016-04-01 3370100
2016-05-02 3662100
2016-06-01 3600500
2016-07-01 2903900
2016-08-01 2983800
2016-09-01 1460400
2016-10-03 1311500
2016-11-01 2759000
2016-12-01 1880800
2017-01-03 1886100
Open High Low Close Volume Adj Close
Date
2016-01-04 25.610001 27.300001 17.650000 21.480000 5194900 17.752066
2016-02-01 21.300001 21.780001 12.860001 15.120001 6480900 12.495868
2016-03-01 15.180001 18.980000 14.910001 18.510000 4489500 15.297522
2016-04-01 18.440001 21.379999 18.000000 19.080000 3343100 19.080000
2016-05-02 16.150000 16.340000 11.810000 13.440000 4500200 13.440000
2016-06-01 13.330000 15.520000 11.700000 12.050000 4401000 12.050000
2016-07-01 12.080000 13.590000 11.430000 12.770000 3953800 12.770000
2016-08-01 12.900000 12.920000 9.660000 10.680000 5137800 10.680000
2016-09-01 10.700000 13.280000 9.810000 11.540000 5801900 11.540000
2016-10-03 11.610000 11.740000 4.880000 5.280000 8011100 5.280000
2016-11-01 5.290000 6.180000 4.150000 5.440000 6704700 5.440000
2016-12-01 5.420000 5.890000 5.240000 5.590000 3224200 5.590000
2017-01-03 5.690000 7.390000 5.410000 6.200000 3640200 6.200000
CYH MTW
Date
2016-01-04 25.610001 15.610001
2016-02-01 21.300001 15.560000
2016-03-01 15.180001 15.990001
2016-04-01 18.440001 4.330000
2016-05-02 16.150000 5.730000
2016-06-01 13.330000 5.630000
2016-07-01 12.080000 5.460000
2016-08-01 12.900000 5.570000
2016-09-01 10.700000 4.920000
2016-10-03 11.610000 4.790000
2016-11-01 5.290000 4.030000
2016-12-01 5.420000 6.010000
2017-01-03 5.690000 6.030000 CYH MTW
Date
2016-01-04 21.480000 15.740001
2016-02-01 15.120001 15.850001
2016-03-01 18.510000 4.330000
2016-04-01 19.080000 5.700000
2016-05-02 13.440000 5.700000
2016-06-01 12.050000 5.450000
2016-07-01 12.770000 5.570000
2016-08-01 10.680000 4.900000
2016-09-01 11.540000 4.790000
2016-10-03 5.280000 4.040000
2016-11-01 5.440000 5.960000
2016-12-01 5.590000 5.980000
2017-01-03 6.200000 7.110000 CYH MTW
Date
2016-01-04 5194900 21098600
2016-02-01 6480900 16000500
2016-03-01 4489500 5162800
2016-04-01 3343100 3370100
2016-05-02 4500200 3662100
2016-06-01 4401000 3600500
2016-07-01 3953800 2903900
2016-08-01 5137800 2983800
2016-09-01 5801900 1460400
2016-10-03 8011100 1311500
2016-11-01 6704700 2759000
2016-12-01 3224200 1880800
2017-01-03 3640200 1886100
Open High Low Close Volume Adj Close
Date
2016-01-04 12.35 12.36 6.48 7.63 4767700 7.63
2016-02-01 7.50 8.18 5.25 7.09 5294200 7.09
2016-03-01 7.01 9.48 6.21 8.60 3426300 8.60
2016-04-01 8.38 10.91 8.04 10.30 2084900 10.30
2016-05-02 10.24 10.55 8.39 9.49 2357400 9.49
2016-06-01 9.38 11.06 7.99 8.88 2065000 8.88
2016-07-01 8.79 9.39 7.77 9.20 1490500 9.20
2016-08-01 9.19 10.19 8.68 9.05 1692000 9.05
2016-09-01 9.07 9.75 7.82 8.11 3738300 8.11
2016-10-03 8.13 8.22 6.85 7.29 3499600 7.29
2016-11-01 7.38 9.47 7.16 9.35 2931900 9.35
2016-12-01 9.45 10.59 9.26 9.81 1761000 9.81
2017-01-03 9.90 12.11 9.64 12.00 2278800 12.00
CYH MTW PAH
Date
2016-01-04 25.610001 15.610001 12.35
2016-02-01 21.300001 15.560000 7.50
2016-03-01 15.180001 15.990001 7.01
2016-04-01 18.440001 4.330000 8.38
2016-05-02 16.150000 5.730000 10.24
2016-06-01 13.330000 5.630000 9.38
2016-07-01 12.080000 5.460000 8.79
2016-08-01 12.900000 5.570000 9.19
2016-09-01 10.700000 4.920000 9.07
2016-10-03 11.610000 4.790000 8.13
2016-11-01 5.290000 4.030000 7.38
2016-12-01 5.420000 6.010000 9.45
2017-01-03 5.690000 6.030000 9.90 CYH MTW PAH
Date
2016-01-04 21.480000 15.740001 7.63
2016-02-01 15.120001 15.850001 7.09
2016-03-01 18.510000 4.330000 8.60
2016-04-01 19.080000 5.700000 10.30
2016-05-02 13.440000 5.700000 9.49
2016-06-01 12.050000 5.450000 8.88
2016-07-01 12.770000 5.570000 9.20
2016-08-01 10.680000 4.900000 9.05
2016-09-01 11.540000 4.790000 8.11
2016-10-03 5.280000 4.040000 7.29
2016-11-01 5.440000 5.960000 9.35
2016-12-01 5.590000 5.980000 9.81
2017-01-03 6.200000 7.110000 12.00 CYH MTW PAH
Date
2016-01-04 5194900 21098600 4767700
2016-02-01 6480900 16000500 5294200
2016-03-01 4489500 5162800 3426300
2016-04-01 3343100 3370100 2084900
2016-05-02 4500200 3662100 2357400
2016-06-01 4401000 3600500 2065000
2016-07-01 3953800 2903900 1490500
2016-08-01 5137800 2983800 1692000
2016-09-01 5801900 1460400 3738300
2016-10-03 8011100 1311500 3499600
2016-11-01 6704700 2759000 2931900
2016-12-01 3224200 1880800 1761000
2017-01-03 3640200 1886100 2278800
Open High Low Close Volume Adj Close
Date
2016-01-04 6.60 6.760000 3.52 4.60 74784300 4.60
2016-02-01 4.50 7.970000 4.26 7.63 59604100 7.63
2016-03-01 7.84 11.450000 7.26 10.34 54212800 10.34
2016-04-01 9.92 14.060000 8.76 14.00 52896300 14.00
2016-05-02 14.03 14.040000 10.22 11.08 46463800 11.08
2016-06-01 11.08 11.930000 9.82 11.14 39599200 11.14
2016-07-01 11.04 13.590000 10.27 12.96 37208000 12.96
2016-08-01 13.01 13.040000 10.18 10.29 26767400 10.29
2016-09-01 10.32 11.140000 9.43 10.86 32267800 10.86
2016-10-03 10.98 11.200000 9.24 11.18 29236000 11.18
2016-11-01 11.31 16.420000 10.50 15.35 43726700 15.35
2016-12-01 15.50 16.080000 13.13 13.19 27355600 13.19
2017-01-03 13.49 17.059999 13.41 16.25 32808900 16.25
CYH FCX MTW PAH
Date
2016-01-04 25.610001 6.60 15.610001 12.35
2016-02-01 21.300001 4.50 15.560000 7.50
2016-03-01 15.180001 7.84 15.990001 7.01
2016-04-01 18.440001 9.92 4.330000 8.38
2016-05-02 16.150000 14.03 5.730000 10.24
2016-06-01 13.330000 11.08 5.630000 9.38
2016-07-01 12.080000 11.04 5.460000 8.79
2016-08-01 12.900000 13.01 5.570000 9.19
2016-09-01 10.700000 10.32 4.920000 9.07
2016-10-03 11.610000 10.98 4.790000 8.13
2016-11-01 5.290000 11.31 4.030000 7.38
2016-12-01 5.420000 15.50 6.010000 9.45
2017-01-03 5.690000 13.49 6.030000 9.90 CYH FCX MTW PAH
Date
2016-01-04 21.480000 4.60 15.740001 7.63
2016-02-01 15.120001 7.63 15.850001 7.09
2016-03-01 18.510000 10.34 4.330000 8.60
2016-04-01 19.080000 14.00 5.700000 10.30
2016-05-02 13.440000 11.08 5.700000 9.49
2016-06-01 12.050000 11.14 5.450000 8.88
2016-07-01 12.770000 12.96 5.570000 9.20
2016-08-01 10.680000 10.29 4.900000 9.05
2016-09-01 11.540000 10.86 4.790000 8.11
2016-10-03 5.280000 11.18 4.040000 7.29
2016-11-01 5.440000 15.35 5.960000 9.35
2016-12-01 5.590000 13.19 5.980000 9.81
2017-01-03 6.200000 16.25 7.110000 12.00 CYH FCX MTW PAH
Date
2016-01-04 5194900 74784300 21098600 4767700
2016-02-01 6480900 59604100 16000500 5294200
2016-03-01 4489500 54212800 5162800 3426300
2016-04-01 3343100 52896300 3370100 2084900
2016-05-02 4500200 46463800 3662100 2357400
2016-06-01 4401000 39599200 3600500 2065000
2016-07-01 3953800 37208000 2903900 1490500
2016-08-01 5137800 26767400 2983800 1692000
2016-09-01 5801900 32267800 1460400 3738300
2016-10-03 8011100 29236000 1311500 3499600
2016-11-01 6704700 43726700 2759000 2931900
2016-12-01 3224200 27355600 1880800 1761000
2017-01-03 3640200 32808900 1886100 2278800