Return data should always come with additional meta-data to explicitly determine return properties. Therefore, the following data types exist.
Composite types
#
DynAssMgmt.ReturnType
— Type.
ReturnType(isPercent::Bool, isLog::Bool, period::Dates.DatePeriod, isGross::Bool)
Specification of return type. Returns could differ with regards to following properties:
- fractional / percentage returns
- discrete / logarithmic returns
- daily, monthly, yearly, ... returns
- net / gross returns
Standard return type is fractional, discrete, net daily returns.
#
DynAssMgmt.Returns
— Type.
Returns(data::TimeSeries.TimeArray, retType::ReturnType)
Data type to store return data together with meta-data.
#
DynAssMgmt.Prices
— Type.
Prices(data::TimeSeries.TimeArray, isLog::Bool)
Data type to store prices together with meta-data. This basically allows to robustly identify logarithmic prices.
#
DynAssMgmt.Performances
— Type.
Performance(data::TimeSeries.TimeArray, retType::ReturnType)
Data type to store performance data together with meta-data. Performance basically can be interpreted as aggregated returns. For the special case of gross performance values, performances also can be interpreted as normalized prices.
Fields of composite types
julia> using DynAssMgmt
julia> fieldnames(ReturnType)
4-element Array{Symbol,1}:
:isPercent
:isLog
:period
:isGross
julia> fieldnames(Returns)
2-element Array{Symbol,1}:
:data
:retType
julia> fieldnames(Prices)
2-element Array{Symbol,1}:
:data
:isLog
julia> fieldnames(Performances)
2-element Array{Symbol,1}:
:data
:retType
Price and return data handling
For each data type, there exist several different scales in which the data could be given. For example, prices can be regular discrete prices, or logarithmic prices. Similarly, performances can be measured in percentages and discrete or logarithmic. For each data type, however, there exists a default scale in which any given instance can be translated using function standardize.
#
DynAssMgmt.standardize
— Function.
standardize(rets::Returns)
Convert return data to default return type: fractional, discrete and net returns.
standardize(prices::Prices)
Convert price data to default price type: discrete, not logarithmic prices.
standardize(perfs::Performances)
Convert performance data to default performance type: fractional, discrete and net performances.
Defining conversion methods from any possible data scale to this default scale will allow conversion between any arbitrary scales. For example, for Prices the following methods exist:
#
DynAssMgmt.getLogPrices
— Function.
getLogPrices(prices::Prices)
Transform prices to logarithmic prices if necessary.
#
DynAssMgmt.getDiscretePrices
— Function.
getDiscretePrices(prices::Prices)
Transform prices to discrete values if necessary.
#
DynAssMgmt.normalizePrices
— Function.
normalizePrices(xx::Array{Float64, 1})
Rescale prices such that first observation starts at 1.
normalizePrices(xx::Array{Float64, 2})
normalizePrices(xx::TimeArray)
normalizePrices(xx::Prices)
As Returns, Prices and Performances are closely interconnected, there also exist default conversion methods between them. These methods make use of the following low-level functions:
#
DynAssMgmt.computeReturns
— Function.
computeReturns(prices::Array{Float64, 1}, retType = ReturnType())
Compute returns from prices. The function uses default settings for return calculations:
- discrete returns (not logarithmic)
- fractional returns (not percentage)
- single-period returns (not multi-period)
- net returns (not gross returns)
- straight-forward application to
NaN
s also
computeReturns(prices::Array{Float64, 2}, retType = ReturnType())
computeReturns(xx::TimeSeries.TimeArray, retType = ReturnType())
#
DynAssMgmt.aggregateReturns
— Function.
aggregateReturns(rets::Array{Float64, 1}, retType::ReturnType, prependStart=false)
Aggregate returns to performances (not prices). The function uses default types of returns:
- discrete returns (not logarithmic)
- fractional returns (not percentage)
- single-period returns (not multi-period)
- net returns (not gross returns)
- convention for how to deal with
NaN
s still needs to be defined
aggregateReturns(discRets::Array{Float64, 2}, retType::ReturnType, prependStart=false)
aggregateReturns(discRets::TimeSeries.TimeArray, retType::ReturnType, prependStart=false)
aggregateReturns(rets::Returns, prependStart=false)
#
DynAssMgmt.rets2prices
— Function.
rets2prices(rets::Array{Float64, 1}, retType::ReturnType, startPrice=1., prependStart=false)
Aggregate returns to prices (not performances). The function uses default types of returns:
- discrete returns (not logarithmic)
- fractional returns (not percentage)
- single-period returns (not multi-period)
- net returns (not gross returns)
- convention for how to deal with
NaN
s still needs to be defined
rets2prices(rets::Array{Float64, 2}, retType::ReturnType)
rets2prices(rets::TimeSeries.TimeArray, retType::ReturnType, startPrice=1., prependStart=false)
rets2prices(rets::Returns, startPrice=1., prependStart=false)
Data imputation
#
DynAssMgmt.locf!
— Function.
locf!(xx::Array{Float64, 1})
Replacing NaN
according to last observation carried forward.
#
DynAssMgmt.locf
— Function.
locf(xx::Array{Float64, 1})
Replacing NaN
according to last observation carried forward.
locf(xx::Array{Float64, 2})
locf(xx::TimeArray)
#
DynAssMgmt.nocb!
— Function.
nocb!(xx::Array{Float64, 1})
Replacing NaN
according to next observation carried backward.
#
DynAssMgmt.nocb
— Function.
nocb(xx::Array{Float64, 1})
Replacing NaN
according to next observation carried backward.
nocb(xx::Array{Float64, 2})
nocb(xx::TimeArray)