Main Content

Decide to Buy Shares Using Current and Historical WDS Data

This example shows how to connect to Wind Data Feed Services (WDS) and retrieve current and historical WDS data. The example then shows how to trigger a buy decision for a single security using the current high price. This example requires that you open and log in to the Wind Financial Terminal.

Connect to WDS

c = wind;

Retrieve Current Data for Security

Format output data for currency.

format bank

Using the 0001.HK security, retrieve the current high and low prices.

s = '0001.HK';
f = ["high","low"];
d = getdata(c,s,f)
d=1×2 table
               HIGH      LOW 
               _____    _____

    0001.HK    99.00    97.70

d is a table with one row for the single security. Each variable in the table corresponds to each specified field.

Retrieve Historical Data for Security

Using the same security, retrieve the high and low prices from August 1, 2017 through August 30, 2017.

f = ["high","low"];
startdate = datetime('2017-08-01');
enddate = datetime('2017-08-30');
h = history(c,s,f,startdate,enddate);

h is a timetable that contains one row for each trading day with the time and a variable for each specified field.

To create a threshold, you can analyze the historical data for the maximum and minimum high price.

max(h.HIGH)
ans = 108.9000
min(h.HIGH)
ans = 100.7000

Decide to Buy Shares

Assume a threshold of $100. Determine if the current high price is less than $100. Set the buy indicator buynow to true when the threshold is met.

buynow = (d.HIGH < 100);

Use the buy indicator and the createorder function to create a buy order of 0001.HK shares.

Close WDS Connection

close(c)

See Also

| | | |

Related Topics

External Websites