Stop rounding when importing Google finance currency - currency

I am importing currency from Google finance to Google spreadsheets (latest version). The number that is imported is rounded both in terms of what is displayed and the underlying number. Is there a way to get the actual underlying currency number to all necessary decimal places?

Look at your menu bar and select:
Format > Number > More Formats > Custom Number Format

I used the external lookup -
=ImportHTML("http://www.xe.com","table", 1)
in a unused part of the spreadsheet and then sourced the appropriate rate from the table contents. Will probably work with other currencies too - look at xe.com
Updates every minute which is fine for my purposes.

=round((googlefinance("asx:"&B12,"marketcap")/googlefinance("asx:"&B12,"shares")),4)
Where:
ASX (Australian Stock eXchange) can be replaced for TSE, etc or removed for NASDAQ
B12 is the Ticker.

Related

Google Sheets: API To Get Crypto Prices and History?

As GOOGLEFINANCE() seems very limited in the cryptocurrencies it supports, are there any (free?) APIs that I can use to get data from?
Although I use GF() for ETH and BTC, I'm specifically looking for Price and Historical Closing Prices on ADA (Cardano).
I've searched the forum for suggestions, there aren't many and most are old. Binance's API seemed OK, but it gives prices in USDT instead of USD.
If anyone is interested, I found an API that offers a free key, although limited in the number of daily calls you can make: CoinAPI.
It seems very powerful, with quotes available in most currencies. So far, I've managed to get a current price:
Formulas shown in brown.
(1) shows the raw data returned, a two rows delimited by semi-colons.
(2) wraps a QUERY() around IMPORTDATA(), using offset 1 plus param 0, to not return the header row, then wraps all that in SPLIT() to separate the delimited text into columns.
(3) wraps (2) with INDEX() so I can get just the Price in the 4th col.
As this value will not automatically update like GOOGLEFINANCE(), I think I'll need to set a Trigger to do that.
I've also retrieved historical data, but I've yet to figure out how to split multiple rows of delimited text from the IMPORTDATA() function.
[Edit] See the solution to splitting multiple rows by #player0 at https://stackoverflow.com/a/69055990/190925.

Results from IMPORTHTML formula in Google Sheets if starts with 0. the 0. is skipped

I want to obtain in a Google Sheets cell, the value of a cryptocoin at certain date.
So I have, for example, the following url which shows the prices (open, high, low, close) of the Waves criptocurrency at 15th of December:
Link
So with
=INDEX(IMPORTHTML("https://coinmarketcap.com/currencies/Waves/historical-data/?start=20171215&end=20171215";"table";1);2;2)
I am getting the Openning Price from that url. In this case: 13.55
But I don't know why when the resulting value starts by 0 point, it skips that part (the 0 point) . With the following formula:
=INDEX(IMPORTHTML("https://coinmarketcap.com/currencies/Ripple/historical-data/?start=20171215&end=20171215";"table";1);2;2)
I am getting 861760 whereas the Opening Price in the url is: 0.861760
I don't know if it has to do with me being from Spain and here we use 0, (zero comma) and no 0. (0 point) and I must configure something to use the 0. notation or what...
Try adjusting your number formats from Automatic to a custom format like '0.00000. If that doesn't work this might...
=IF(INDEX(IMPORTHTML("https://coinmarketcap.com/currencies/Ripple/historical-data/?start=20171215&end=20171215","table",1),2,2)>1,CONCATENATE("0.",INDEX(IMPORTHTML("https://coinmarketcap.com/currencies/Ripple/historical-data/?start=20171215&end=20171215","table",1),2,2)),INDEX(IMPORTHTML("https://coinmarketcap.com/currencies/Ripple/historical-data/?start=20171215&end=20171215","table",1),2,2))
You might need to switch the ">" for "<"
Or perhaps...
=INDEX(IMPORTHTML("https://coinmarketcap.com/currencies/Ripple/historical-data/?start=20171215&end=20171215","table",1),2,2)*CONCATENATE("0.", REPT(0,len(INDEX(IMPORTHTML("https://coinmarketcap.com/currencies/Ripple/historical-data/?start=20171215&end=20171215","table",1),2,2))-1),1)
The problem is that importhtml already parses the data using the spreadsheet's locale, so there is nothing you can do to restore correct data if it was parsed incorrectly. Information is already corrupted.
What you can do:
Change the locale in Spreadsheet Settings to some country which uses dot as decimal separator (see the list here). It's probably best to use the country from where the data comes from.
But you probably prefer to work in your familiar locale. In that case, create a new spreadsheet just with importhtml that you need, setting its locale as in #1. In your main spreadsheet, use importrange to import the data from the new spreadsheet. The data now arrives unharmed, because importhtml interpreted it correctly, and importrange knows what to do to move data between spreadsheets, even between different locales.

Dynamic Currency Conversion in Google Sheets

I'm using Google Sheets to organize data from my global royalty statements. Currently I'm querying several tabs (one for each country) to produce a single table with results from all countries. As you can imagine, I don't want 125 Japanese Yen showing up in my charts and graphs as $125 USD (125 Y is equivalent to about $1.09 USD).
Since I receive my royalty statements in their respective currencies, I'd like to apply average conversion rates either during the query operation or after the fact. Since the table is being generated dynamically, the values won't always be the same, so I need some way to apply the conversion by searching the list of currencies on the fly. I've got a separate table on the same tab containing all the average conversion rates for each currency. Here's a sample of how this is set up:
So basically I just don't know how to say, in coding terms, "If this line item comes from the UK, divide the royalty amount by the UK exchange rate. If it comes from Canada, divide by the Canadian rate, etc."
Anyone have any insight as to how I might pull this off (or whether it's possible)? The actual table includes over 500 line items from a dozen different countries, so doing this by hand is something I'd like to avoid.
I believe you are looking for the GoogleFinance() function. You may want to set the Country to a pick list of the valid country entries so you could create the string for the conversion. I have not looked at many, but this will take a value in CA & and apply the exchange rate to convert it to the US $ Equivalent. The exchange rate in this case is an average of, I believe, the past 30 days.
=C2 * GoogleFinance("CURRENCY:CADUSD" , "average")
For your use, you can get the country code from row M if you change it to match what the formula is after, such as CAD for Canadian Dollars."
=C2 * GoogleFinance("CURRENCY:" & M2 & "USD" , "average")
Another option would be to create a lookup table and use VLOOKUP or some other function, depending on how you set up your table.

How to convert currency in Google Docs Spreadsheet cell?

Okay I have a cell with Russian Roubles and want to convert them into US Dollars. What is the formula? I tried to find some keywords with =something (currency,finance,convert,dollar,double,ruble and much more) but found nothing.
There are certain function available in Google Spreadsheets to interact with other Google services such as Finance.
To get the realtime exchange rate between currencies and set up conversion you could follow these steps:
Get the exchange rate between currencies in a cell, or use it directly in a formula using the function: GoogleFinance("CURRENCY:EURUSD"). The format is GoogleFinance("CURRENCY:<from-currency><to-currency>")
Use it in a formula: =C4*GoogleFinance("CURRENCY:EURUSD")

On Google Spreadsheet how can you query 'GoogleFinance' for a past exchange rate?

I'd like to know if it is possible to query a past exchange rate on Google Spreadsheet.
For example; using formula =GoogleFinance("CURRENCY:USDEUR") will return the USD/EUR rate at this present moment. How can you retrieve a historic rate?
In order to retrieve the historical rate, you have to use the following formula:
=GoogleFinance("eurusd","price",today()-1,today())
where today()-1, today() is the desired time interval, which can be explicitly defined as the static pair of dates, or implicitly, as the dynamically calculated values, like in the example above. This expression returns a two-column array of the dates and close values. It is important to care about the suitable cell format (date/number), otherwise your data will be broken.
If you want to get the pure row with the date and currency exchange rate without column headers, wrap your formula with the INDEX() function:
=INDEX(GoogleFinance("eurusd","price",today()-1,today()),2,)
To retrieve the exchange rate value only, define the column number parameter:
=INDEX(GoogleFinance("eurusd","price",today()-1,today()),2,2)
To get today's currency exchange rates in Google Docs/Spreadsheet from Google Finance:
=GoogleFinance("eurusd","price",today())
A shorter way to get today's rates:
=GoogleFinance("currency:usdeur")
P.S. There is also the way to get live currency exchange rate in Microsoft Excel.
Try,
=GoogleFinance("usdeur","price",date(2013,12,1),date(2013,12,16))
Make sure that the dates are as per your spreadsheet settings.
Edit as comment, changed date for capturing single day data:-
Only with headers:
=INDEX(GoogleFinance("usdeur","price",date(2013,12,3),date(2013,12,4)),,2)
without headers:
=FILTER(INDEX(GoogleFinance("usdeur","price",date(2013,12,3),date(2013,12,4)),,2),INDEX(GoogleFinance("usdeur","price",date(2013,12,3),date(2013,12,4)),,2)<>"Close")
The instructions for all related to googlefinance are in here: https://support.google.com/docs/answer/3093281
Remember the actual Google Spreadsheets Formulas use semicolon (;) instead of comma (,).
Once made the replacement on some examples would look like this:
For a 30 day INDEX of USD vs EUR you should use (note that in the case of currencies they go together in the same first variable):
=INDEX(GoogleFinance(USDEUR;"price";today()-30;today());2;2)
TIP: You can get the graph over the entire size of the cell by simply changing INDEX for SPARKLINE, like this:
=SPARKLINE(GoogleFinance(USDEUR;"price";today()-30;today());2;2)
Vasim's answer is excellent, however notice if you want the exchange date on that day only, you can omit the range and just specify the day such as the following
=FILTER(INDEX(GoogleFinance("usdeur","price",today()),,2),INDEX(GoogleFinance("usdeur","price",today()),,2)<>"Close")
You may notice that GOOGLEFINANCE will return N/A for some dates, this is because the date is a day off (usually a weekend), what you can do is to get the last working from the specified date, e.g. Jun 21st 2015 is Sunday, so you should request the rate for Jun 19th (Friday), you can do this via WORKDAY function as was suggested here:
WORKDAY("6/21/2015"+1,-1)
So, the resulting formula will look something like that:
INDEX(GoogleFinance("CURRENCY:USDRUB", "price", WORKDAY("6/21/2015"+1,-1),1),2,2)
Additionally, you want to get the exchange rates for future dates you can additionally check if the date is in the future and if so, just use the today date:
WORKDAY(IF("6/21/2099">TODAY(),TODAY(),"6/21/2099")+1,-1)
For bigger spreadsheets, Google Sheets limitations usually will show randomly the following error:
Error Function INDEX parameter 2 value is 2. Valid values are between
0 and 1 inclusive.
Even modifying Index() and GoogleFinance() following the expected parameters GOOGLEFINANCE(ticker, [attribute], [start_date], [end_date|num_days], [interval]) the error will continue.
A workaround is to copy smaller parts into new spreadsheets but often it will fail.
As an alternative, I used ImportXML as web scraper for x-rates historical currency exchange data.
=index(IMPORTXML("https://www.x-rates.com/historical/?from="&N2&"&amount="&K2&"&date="&YEAR(B2)&"-"&TEXT(B2,"mm")&"-"&TEXT(B2,"dd")&"","//td[#class='rtRates']"),1)
I'm assuming column B are dates, K is for amounts and N for currencies.
Randomly it also will fail for a 2000+ rows spreadsheet but overall for my requirement, it worked too much better than GoogleFinance()
ImportXML examples
The ImportXML Guide for Google Docs from beginner to advanced
Other option is using the CurrencyConverter function from this Google Sheets add-on.
It is fast and and has simple syntax. For example,
=CurrencyConverter(100, "USD", "EUR", "2/28/2020")
returns 91.09957183

Resources