如何使用Investpy获取在德国交易所上市的美国公司股票数据(以慕尼黑交易所的亚马逊为例)
Let's break down how to grab that Munich-listed AMZN data (WKN 906866, ISIN US0231351067) in euros—since your initial approach with country='germany' and stock='amzn' didn't work (as you noted, AMZN isn't a German domestic stock; its German listing is a cross-border one).
Why Your First Attempt Failed
When you use stock='amzn' with country='germany', investpy looks for stocks originally listed in Germany with that ticker. Since AMZN's primary listing is in the US, it won't show up in that filtered set. Instead, we need to target its specific German listing identifiers.
Solution 1: Use the Munich Boerse WKN Directly
The quickest fix is to use AMZN's German WKN (906866) instead of the US ticker. Here's the code:
import investpy as inv # Fetch daily Euro-denominated data using the German WKN df = inv.get_stock_recent_data(stock='906866', country='germany', interval='daily')
This pulls data directly from the Munich listing, which uses euros as the base currency.
Solution 2: Search via ISIN for Reliability
If you prefer using the global ISIN identifier, you can first search for the stock and filter to the German listing:
import investpy as inv # Search for AMZN using its global ISIN search_results = inv.search_stocks(by='isin', value='US0231351067') # Filter results to the Munich Boerse listing (Germany) munich_amzn = search_results[search_results['country'] == 'germany'].iloc[0] # Fetch data using the German listing's specific symbol df = inv.get_stock_recent_data(stock=munich_amzn['symbol'], country='germany', interval='daily')
This method lets you confirm you're targeting the exact listing before pulling data, which is helpful if you're working with multiple cross-border stocks.
Quick Currency Check
Once you have the dataframe, you can verify the currency by cross-referencing the closing prices with public Munich Boerse data—they should reflect euro values, not USD. Some versions of investpy also include currency metadata in the dataframe's attributes, so you can check that too.
内容的提问来源于stack exchange,提问作者jaydeepsb

