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 =风;

Retrieve Current Data for Security

Format output data for currency.

formatbank

Using the0001.HKsecurity, retrieve the current high and low prices.

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

dis 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);

his 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 indicatorbuynowtotruewhen the threshold is met.

buynow = (d.HIGH < 100);

Use the buy indicator and thecreateorder函数创建一个购买订单0001.HKshares.

Close WDS Connection

close(c)

See Also

||||

Related Topics

External Websites