tahistory
Historical technical analysis for Bloomberg connection V3
Description
Examples
Request Bloomberg Directional Movement Indicator (DMI) Study for Security
Return all available Bloomberg studies and use the DMI study to run a technical analysis for a security.
Create the Bloomberg connection.
c = blp;
Alternatively, you can connect to the Bloomberg Server using blpsrv
or Bloomberg
B-PIPE® using bpipe
.
List the available Bloomberg studies.
d = tahistory(c)
d = dmiStudyAttributes: [1x1 struct] smavgStudyAttributes: [1x1 struct] bollStudyAttributes: [1x1 struct] maoStudyAttributes: [1x1 struct] fgStudyAttributes: [1x1 struct] rsiStudyAttributes: [1x1 struct] macdStudyAttributes: [1x1 struct] tasStudyAttributes: [1x1 struct] emavgStudyAttributes: [1x1 struct] maxminStudyAttributes: [1x1 struct] ptpsStudyAttributes: [1x1 struct] cmciStudyAttributes: [1x1 struct] wlprStudyAttributes: [1x1 struct] wmavgStudyAttributes: [1x1 struct] trenderStudyAttributes: [1x1 struct] gocStudyAttributes: [1x1 struct] kltnStudyAttributes: [1x1 struct] momentumStudyAttributes: [1x1 struct] rocStudyAttributes: [1x1 struct] maeStudyAttributes: [1x1 struct] hurstStudyAttributes: [1x1 struct] chkoStudyAttributes: [1x1 struct] teStudyAttributes: [1x1 struct] vmavgStudyAttributes: [1x1 struct] tmavgStudyAttributes: [1x1 struct] atrStudyAttributes: [1x1 struct] rexStudyAttributes: [1x1 struct] adoStudyAttributes: [1x1 struct] alStudyAttributes: [1x1 struct] etdStudyAttributes: [1x1 struct] vatStudyAttributes: [1x1 struct] tvatStudyAttributes: [1x1 struct] pdStudyAttributes: [1x1 struct] rvStudyAttributes: [1x1 struct] ipmavgStudyAttributes: [1x1 struct] pivotStudyAttributes: [1x1 struct] orStudyAttributes: [1x1 struct] pcrStudyAttributes: [1x1 struct] bsStudyAttributes: [1x1 struct]
d
contains structures pertaining to each available Bloomberg study.
Display the name-value pairs for the DMI study.
d.dmiStudyAttributes
ans = period: [1x104 char] priceSourceHigh: [1x123 char] priceSourceLow: [1x121 char] priceSourceClose: [1x125 char]
Obtain more information about the period
property.
d.dmiStudyAttributes.period
ans = DEFINITION period { Min Value = 1 Max Value = 1 TYPE Int64 } // End Definition: period
Run the DMI study for the IBM® security for the last month with period
equal to
14
, the high price, the low price, and the closing price.
d = tahistory(c,'IBM US Equity',floor(now)-30,floor(now),'dmi',... 'all_calendar_days','period',14,... 'priceSourceHigh','PX_HIGH',... 'priceSourceLow','PX_LOW','priceSourceClose','PX_LAST')
d = date: [31x1 double] DMI_PLUS: [31x1 double] DMI_MINUS: [31x1 double] ADX: [31x1 double] ADXR: [31x1 double]
d
contains a studyDataTable
with one
studyDataRow
for each interval returned.
Display the first five dates in the returned data.
d.date(1:5,1)
ans = 735507.00 735508.00 735509.00 735510.00 735511.00
Display the first five prices in the plus DI line.
d.DMI_PLUS(1:5,1)
ans = 18.92 17.84 16.83 15.86 15.63
Display the first five prices in the minus DI line.
d.DMI_MINUS(1:5,1)
ans = 30.88 29.12 28.16 30.67 29.24
Display the first five values of the Average Directional Index.
d.ADX(1:5,1)
ans = 22.15 22.28 22.49 23.15 23.67
Display the first five values of the Average Directional Movement Index Rating.
d.ADXR(1:5,1)
ans = 25.20 25.06 25.05 25.60 26.30
Close the Bloomberg connection.
close(c)
Request DMI Study for Security with Pricing Source
Run a technical analysis to return the DMI study for a security with a pricing source.
Create the Bloomberg connection.
c = blp;
Alternatively, you can connect to the Bloomberg Server using blpsrv
or Bloomberg
B-PIPE using bpipe
.
Run the DMI study for the Microsoft® security with pricing source ETPX
for the last month
with period
equal to 14
, the high price, the low
price, and the closing price.
d = tahistory(c,'MSFT@ETPX US Equity',floor(now)-30,floor(now),... 'dmi','all_calendar_days','period',14,... 'priceSourceHigh','PX_HIGH','priceSourceLow','PX_LOW',... 'priceSourceClose','PX_LAST')
d = date: [31x1 double] DMI_PLUS: [31x1 double] DMI_MINUS: [31x1 double] ADX: [31x1 double] ADXR: [31x1 double]
d
contains a studyDataTable
with one
studyDataRow
for each interval returned.
Display the first five dates in the returned data.
d.date(1:5,1)
ans = 735507.00 735508.00 735509.00 735510.00 735511.00
Display the first five prices in the plus DI line.
d.DMI_PLUS(1:5,1)
ans = 28.37 30.63 32.72 30.65 29.37
Display the first five prices in the minus DI line.
d.DMI_MINUS(1:5,1)
ans = 21.97 21.17 19.47 18.24 17.48
Display the first values of the Average Directional Index.
d.ADX(1:5,1)
ans = 13.53 13.86 14.69 15.45 16.16
Display the first five values of the Average Directional Movement Index Rating.
d.ADXR(1:5,1)
ans = 15.45 15.36 15.53 15.85 16.37
Close the Bloomberg connection.
close(c)
Return DMI Study Data as Table with Dates
Create a Bloomberg® connection, and then return data for a DMI study. The tahistory
function returns data for dates as a datetime
array.
Create the Bloomberg connection.
c = blp;
Alternatively, you can connect to the Bloomberg Server using blpsrv
or Bloomberg B-PIPE® using bpipe
.
Return data as a table by setting the DataReturnFormat
property of the connection object. If you do not set this property, the tahistory
function returns data as a structure.
Return dates as a datetime
array by setting the DatetimeType
property of the connection object. In this case, the table contains dates in variables that are datetime
arrays.
c.DataReturnFormat = 'table'; c.DatetimeType = 'datetime';
Adjust the display format of the returned data for currency.
format bank
Run the DMI study for the IBM® security from June 12, 2017 through June 16, 2017 with period
equal to 14, the high price, the low price, and the closing price.
d = tahistory(c,'IBM US Equity','6/12/2017','6/16/2017','dmi', ... 'all_calendar_days','period',14,'priceSourceHigh','PX_HIGH', ... 'priceSourceLow','PX_LOW','priceSourceClose','PX_LAST');
Access the DMI study data for the first three dates.
d(1:3,:)
ans = 3×5 table date DMI_PLUS DMI_MINUS ADX ADXR ___________ ________ _________ _____ _____ 12-Jun-2017 30.48 16.31 33.93 45.26 13-Jun-2017 28.88 15.45 33.67 44.10 14-Jun-2017 26.62 18.98 32.46 42.67
d
is a table
that contains these columns:
date
-- DateDMI_PLUS
-- Prices in plus DI lineDMI_MINUS
-- Prices in minus DI lineADX
-- Average Directional Index valuesADXR
-- Average Directional Movement Index Rating values
Access the first three dates in the returned data.
d.date(1:3)
ans = 3×1 datetime array 12-Jun-2017 13-Jun-2017 14-Jun-2017
Close the Bloomberg connection.
close(c)
Return DMI Study Data as Timetable
Create a Bloomberg® connection, and then return data for a DMI study. The tahistory
function returns data as a timetable
.
Create the Bloomberg connection.
c = blp;
Alternatively, you can connect to the Bloomberg Server using blpsrv
or Bloomberg B-PIPE® using bpipe
.
Return data as a table by setting the DataReturnFormat
property of the connection object. If you do not set this property, the tahistory
function returns data as a structure.
c.DataReturnFormat = 'timetable';
Adjust the display format of the returned data for currency.
format bank
Run the DMI study for the IBM® security from June 12, 2017 through June 16, 2017 with period
equal to 14, the high price, the low price, and the closing price.
d = tahistory(c,'IBM US Equity','6/12/2017','6/16/2017','dmi', ... 'all_calendar_days','period',14,'priceSourceHigh','PX_HIGH', ... 'priceSourceLow','PX_LOW','priceSourceClose','PX_LAST');
Access the DMI study data for the first three dates.
d(1:3,:)
ans = 3×4 timetable date DMI_PLUS DMI_MINUS ADX ADXR ___________ ________ _________ _____ _____ 12-Jun-2017 30.48 16.31 33.93 45.26 13-Jun-2017 28.88 15.45 33.67 44.10 14-Jun-2017 26.62 18.98 32.46 42.67
d
is a timetable
that contains these columns:
date
-- DateDMI_PLUS
-- Prices in plus DI lineDMI_MINUS
-- Prices in minus DI lineADX
-- Average Directional Index valuesADXR
-- Average Directional Movement Index Rating values
Close the Bloomberg connection.
close(c)
Input Arguments
s
— Security
character vector | string scalar
Security, specified as a character vector or string scalar for a single Bloomberg security.
Data Types: char
| string
startdate
— Start date
numeric scalar | character vector | string scalar
Start date, specified as a numeric scalar, character vector, or string scalar to denote the start date of the date range for the returned tick data.
Example: floor(now-1)
Data Types: double
| char
| string
enddate
— End date
numeric scalar | character vector | string scalar
End date, specified as a numeric scalar, character vector, or string scalar to denote the end date of the date range for the returned tick data.
Example: floor(now)
Data Types: double
| char
| string
study
— Study type
character vector | string scalar
Study type, specified as a character vector or string scalar to denote the study to use for historical analysis.
Data Types: char
| string
period
— Periodicity
'daily'
| 'weekly'
| 'monthly'
| 'quarterly'
| ...
Periodicity, specified as one of these values to denote the
data to return. For specifying multiple values, use a cell array.
For example, when period
is set to {'daily','all_calendar_days'}
, tahistory
returns
daily data for all calendar days, and reports missing data as NaN
s.
When period
is set to 'active_days_only'
, tahistory
returns
data using the default periodicity for active trading days only. The
default periodicity depends on the security. If a security is reported
on a monthly basis, the default periodicity is monthly. These tables
show the values for period
.
To specify the periodicity of the return data, see this table.
Value | Description |
---|---|
'daily' | Return data for each day. |
'weekly' | Return data for each week. |
'monthly' | Return data for each month. |
'quarterly' | Return data for each quarter. |
'semi_annually' | Return data semiannually. |
'yearly' | Return data for each year. |
The anchor date is the date to which all other reported dates are related. To specify the anchor date, see this table.
Value | Description |
---|---|
'actual' | Anchor date specification for an actual date. For this
function, for periodicities other than daily, If the period is weekly and the |
'calendar' | Anchor date specification for a calendar year. |
'fiscal' | Anchor date specification for a fiscal year. |
To specify returning data for particular days, see this table.
Value | Description |
---|---|
'non_trading_weekdays' | Return data for all weekdays. |
'all_calendar_days' | Return data for all calendar days. |
'active_days_only' | Return data for only active trading days. |
To specify how to fill missing values, see this table.
Value | Description |
---|---|
'previous_value' | Fill missing values with previous values for dates without trading activity for the security. |
'nil_value' | Fill missing values with a NaN for dates
without trading activity for the security. |
Data Types: char
| cell
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose
Name
in quotes.
Example: 'period',14
, 'priceSourceHigh','PX_HIGH'
,
'priceSourceLow','PX_LOW'
,
'priceSourceClose','PX_LAST'
Note
For details about the full list of name-value pair arguments, see the Bloomberg tool located at
C:\blp\API\APIv3\bin\BBAPIDemo.exe
.
period
— Period
numeric scalar
Period, specified as the comma-separated pair consisting of
'period'
and a numeric scalar. For details about the period, see
the Bloomberg API Developer’s Guide using the WAPI
<GO> option from the Bloomberg terminal.
Data Types: double
priceSourceHigh
— High price
character vector | string scalar
High price, specified as the comma-separated pair consisting of
'priceSourceHigh'
and a character vector or string scalar. For
details about the high price, see the Bloomberg API Developer’s Guide using the WAPI
<GO> option from the Bloomberg terminal.
Data Types: char
| string
priceSourceLow
— Low price
character vector | string scalar
Low price, specified as the comma-separated pair consisting of
'priceSourceLow'
and a character vector or string scalar. For
details about the low price, see the Bloomberg API Developer’s Guide using the WAPI
<GO> option from the Bloomberg terminal.
Data Types: char
| string
priceSourceClose
— Closing price
character vector | string scalar
Closing price, specified as the comma-separated pair consisting of
'priceSourceClose'
and a character vector or string scalar. For
details about the closing price, see the Bloomberg API Developer’s Guide using the WAPI
<GO> option from the Bloomberg terminal.
Data Types: char
| string
Output Arguments
d
— Technical analysis data
structure (default) | table | timetable
Technical analysis data, returned as a structure, table, or timetable. The data type of the returned data depends on the DataReturnFormat and DatetimeType properties of the connection object.
For details about the data, see the Bloomberg API Developer’s Guide using the WAPI <GO> option from the Bloomberg terminal.
Version History
Introduced in R2012b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)