Q: Feeding Exchange Rate into Numbers
Hi,
I'm creating a Position Size Calculator in Numbers to manage my risk in the trading game. Most trading instruments are denominated in foreign currencies and to work out what I'm risking in Australian dollars, I need exchange rate feed into numbers to calculate from. Most of the time it would be calculating the exchange rate between Australia and United States. Otherwise I would have to manually input the exchange rate.
Is it possible to do this, if so how? I'm guessing a site like Yahoo Finance would be used!
Thanks in advance ...
Graeme
iMac (21.5-inch, Late 2013), OS X Yosemite (10.10.1)
Posted on Jul 16, 2016 9:40 AM
Here's as simple script that places the current rate in a designated cell in a specified sheet and table of the front document.
- Copy-paste script below into into AppleScript Editor (in Applications > Utilities)
- Make sure you have your document set up in way that the script can address it properly. Change the sheet, table, and cell names in the script (where currently there is "Sheet 1", "Table 1", "B2") to match your document.
- Click the triangle 'run' button.
This can be made more sophisticated, e.g. retrieve the quote data and time, etc., or retrieve several different exchange rates at once. It can also be placed in the menu and/or attached to a keyboard shortcut.
But it should get you started. Post if you encounter problems.
SG
-- properties that could be used: s symbol; l1 current rate; d1 date; t1 time; b bid; a asked
-- see http://stackoverflow.com/questions/181990/programmatically-access-currency-excha nge-rates
set quoteProperties to "l1"
set theSymbol to "USDAUD=X"
set {s, t, c} to {"Sheet 1", "Table 1", "B2"}
tell application "Numbers" to tell front document's sheet s's table t
set cell c's value to my getYDATA(theSymbol, quoteProperties)
end tell
to getYDATA(symb, qProp)
set baseURL to "http://download.finance.yahoo.com/d/quotes.csv?"
set symbStr to "s=" & symb
set propStr to "&f=" & qProp
do shell script "curl -s " & "'" & baseURL & symbStr & propStr & "'"
end getYDATA
Posted on Jul 16, 2016 11:08 PM