如何从Alphavantage获取字典的字典中的选定部分



我从Alphavantage得到了下一个端点,但我想使用RSI号码,用于股票列表。我怎样才能得到RSI?谢谢你的回答

{
'Meta Data': {'1: Symbol': 'ABMD',
'2: Indicator': 'Relative Strength Index (RSI)',
'3: Last Refreshed': '2021-10-13',
'4: Interval': 'weekly',
'5: Time Period': 10,
'6: Series Type': 'open',
'7: Time Zone': 'US/Eastern Time'},
'Technical Analysis: RSI': {'2021-10-13': {'RSI': '50.5159'},
'2021-10-08': {'RSI': '44.3446'},
'2021-10-01': {'RSI': '55.6364'},
'2021-09-24': {'RSI': '58.2600'},
'2021-09-17': {'RSI': '63.0876'},
'2021-09-10': {'RSI': '68.3045'},
'2021-09-03': {'RSI': '65.3299'},
'2021-08-27': {'RSI': '61.9752'},
'2021-08-20': {'RSI': '52.7723'},
'2021-08-13': {'RSI': '64.7634'},

对于第一个RSI

data['Technical Analysis: RSI']['2021-10-13']['RSI']

和其他日期的相同方式。


对于所有RSI,您可以使用for-loop与.values().items()

for date, values in data['Technical Analysis: RSI'].items():
print(date, values['RSI'])

data = {
'Meta Data': {
'1: Symbol': 'ABMD',
'2: Indicator': 'Relative Strength Index (RSI)',
'3: Last Refreshed': '2021-10-13',
'4: Interval': 'weekly',
'5: Time Period': 10,
'6: Series Type': 'open',
'7: Time Zone': 'US/Eastern Time'
},
'Technical Analysis: RSI': {
'2021-10-13': {'RSI': '50.5159'},
'2021-10-08': {'RSI': '44.3446'},
'2021-10-01': {'RSI': '55.6364'},
'2021-09-24': {'RSI': '58.2600'},
'2021-09-17': {'RSI': '63.0876'},
'2021-09-10': {'RSI': '68.3045'},
'2021-09-03': {'RSI': '65.3299'},
'2021-08-27': {'RSI': '61.9752'},
'2021-08-20': {'RSI': '52.7723'},
'2021-08-13': {'RSI': '64.7634'},
}
}
print('First:', data['Technical Analysis: RSI']['2021-10-13']['RSI'])
print('--- all ---')
for date, values in data['Technical Analysis: RSI'].items():
print(date, '|', values['RSI'])

结果:

First: 50.5159
--- all ---
2021-10-13 | 50.5159
2021-10-08 | 44.3446
2021-10-01 | 55.6364
2021-09-24 | 58.2600
2021-09-17 | 63.0876
2021-09-10 | 68.3045
2021-09-03 | 65.3299
2021-08-27 | 61.9752
2021-08-20 | 52.7723
2021-08-13 | 64.7634

相关内容

  • 没有找到相关文章

最新更新