This example shows how to retrieve historical data with an applied calculation from Quandl®. Also, the example limits and sorts the rows in the returned data. The example assumes that you have obtained an API key from Quandl.
Create a Quandl connection using a Quandl API key.
apikey = 'abcdef12345';
c = quandl(apikey);
Adjust the display format to display currency.
format bank
Retrieve historical data for the CHRIS/ASX_WM2
security from
January 1, 2017 through December 31, 2017. This security provides historical future
prices for Eastern Australian Wheat Futures, Continuous Contract #2. Apply these
conditions to the returned data:
Use a monthly periodicity for the returned data.
Transform the historical price data by calculating the row-on-row percent change.
Specify the calculation using the name-value argument
"transform"
with the "rdiff"
value.
Limit the returned data to the first six rows using the name-value argument
"limit"
.
Sort the dates in ascending order using the name-value argument
"order"
.
d
is a timetable with the time in the first variable and the percent
change of the previous settlement price in the second variable.
s = 'CHRIS/ASX_WM2'; startdate = datetime('01-01-2017','InputFormat','MM-dd-yyyy'); enddate = datetime('12-31-2017','InputFormat','MM-dd-yyyy'); periodicity = 'monthly'; d = history(c,s,startdate,enddate,periodicity, ... "transform","rdiff","limit",6,"order","asc");
Display the sorted percent changes.
d
d = 6×1 timetable Time PreviousSettlement ___________ __________________ 31-Mar-2017 -0.01 30-Apr-2017 0.02 31-May-2017 0.02 30-Jun-2017 0.21 31-Jul-2017 -0.01 31-Aug-2017 -0.08
Decide to buy or sell this contract based on the historical percent changes.