Convert price series to return series
Load the file SimulatedStock.mat
, which provides a timetable (TMW
) for financial data for TMW stock. Then convert a price series to a return series, given the first 10 periodic returns of TMW
.
load SimulatedStock.mat TMW_Close = TMW(1:10,'Close'); [Returns,Intervals] = tick2ret(TMW_Close)
Returns=9×1 timetable
Time Close
___________ ___________
05-Sep-2012 0.0017955
06-Sep-2012 0.013741
07-Sep-2012 -0.022591
10-Sep-2012 -0.011557
11-Sep-2012 -0.014843
12-Sep-2012 -0.0012384
13-Sep-2012 0.0081628
14-Sep-2012 -0.00051245
17-Sep-2012 -0.02902
Intervals = 9x1 duration
24:00:00
24:00:00
24:00:00
72:00:00
24:00:00
24:00:00
24:00:00
24:00:00
72:00:00
datetime
InputUse datetime
input to convert a price series to a return series, given periodic returns of two stocks observed in the first, second, third, and fourth quarters.
TickSeries = [100 80 110 90 115 88 110 91]; TickTimes = datetime({'1/1/2015','1/7/2015','1/16/2015','1/28/2015'},'InputFormat','MM/dd/uuuu'); [Returns,Intervals] = tick2ret(TickSeries,'TickTimes',TickTimes)
Returns = 3×2
0.1000 0.1250
0.0455 -0.0222
-0.0435 0.0341
Intervals = 3x1 duration
144:00:00
216:00:00
288:00:00
Data
— Data for asset pricesSpecify optional
comma-separated pairs of Name,Value
arguments. Name
is
the argument name and Value
is the corresponding value.
Name
must appear inside quotes. You can specify several name and value
pair arguments in any order as
Name1,Value1,...,NameN,ValueN
.
[Returns,Intervals] =
tick2ret(TickSeries,'TickTimes',TickTimes)
'TickTimes'
— Observation times associated with prices1
,2
,...NUMOBS
assumed for all assets (default) | vectorObservation times associated with prices, specified as the
comma-separated pair consisting of 'TickTimes'
and a
NUMOBS
element column vector of monotonically
increasing observation times associated with the prices in
Data
. Times are taken either as serial date
numbers (day units), date strings, datetime arrays, or as decimal
numbers in arbitrary units (for example, yearly).
Note
If the input Data
type is a timetable, the
row times information in the timetable overwrites the
TickTimes
input.
Data Types: double
| datetime
| string
'Method'
— Method to convert asset prices to returns'Simple'
(default) | character vector with value of 'Simple'
or
'Continuous'
| string with value of "Simple"
or
"Continuous"
Method to convert asset prices to returns, specified as the
comma-separated pair consisting of 'Method'
and a
string or character vector indicating the method to convert asset prices
to returns.
If the method is 'Simple'
, then simple periodic
returns at time t are computed
as:
Returns(t) = Data(t)/Data(t-1) - 1.
If the method is 'Continuous'
, the continuous
returns are computed
as:
Returns(t) = log(Data(t)/Data(t-1)).
Data Types: char
| string
Returns
— Time series array of asset returnsTime series array of asset returns, returned as a
NUMOBS-1
-by-NASSETS
array of asset
returns with the same type (matrix, table, or timetable) as the input
Data
. The first row contains the oldest returns and
the last row contains the most recent. Returns across a given row are
assumed to occur at the same time for all columns, and each column is a
return series of an individual asset.
Intervals
— Interval times between successive pricesInterval times between successive prices, returned as a
NUMOBS-1
length column vector where
Intervals
(t) =
TickTimes
(t) -
TickTimes
(t - 1).
This function supports input Data
that is specified as a tall
column vector, a tall table, or a tall timetable. For more information, see tall
and Tall Arrays.
You have a modified version of this example. Do you want to open this example with your edits?