Question: In this exercise, you will create a function that takes two currency codes and converts them to a ticker suitable for downloading from yfinance. code:
In this exercise, you will create a function that takes two currency codes and converts them to a ticker suitable for downloading from yfinance.
code: The currency ISO code eg USD US Dollar, AUD Australian Dollar You can find a list of currency codes here.
fx: The exchange rate, ie the value of one currency in terms of another currency. We will represent an exchange rate like this:
AUDUSD : The price in US dollars of one Australian dollar
USDAUD : The price in Australian dollars of one US dollar
AAABBB : The price in currency BBB of one unit of currency AAA
fromcur: The currency which we want to price AAA in the example above
tocur: The price of one unit of the fromcur BBB in the example above
Yahoo finance uses the following naming rules to define the ticker of the exchange rate AAABBB the price of one unit of AAA in terms of currency BBB:
If AAA is the USD, then the ticker is BBBX ie the second currency code with X added at the end.
If AAA is not the USD, then the ticker is "AAABBBX
For example, the ticker for AUDUSD is "AUDUSDX while the ticker for USDAUD is "AUDX
The scaffold provides you with a declaration defining the function's arguments and a docstring that describes what the function should do You need to fill in the body of the function. Note that a function called getfx is provided as a reference. Once your fxcode function passes the diagnostic tests, you should be able to copy the entire file to an environment with yfinance installed eg PyCharm and use this program to download currency data.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
