Return data should always come with additional meta-data to explicitly determine return properties. Therefore, the following data types exist.

Composite types

# DynAssMgmt.ReturnTypeType.

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.

source

# DynAssMgmt.ReturnsType.

Returns(data::TimeSeries.TimeArray, retType::ReturnType)

Data type to store return data together with meta-data.

source

# DynAssMgmt.PricesType.

Prices(data::TimeSeries.TimeArray, isLog::Bool)

Data type to store prices together with meta-data. This basically allows to robustly identify logarithmic prices.

source

# DynAssMgmt.PerformancesType.

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.

source

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.standardizeFunction.

standardize(rets::Returns)

Convert return data to default return type: fractional, discrete and net returns.

source

standardize(prices::Prices)

Convert price data to default price type: discrete, not logarithmic prices.

source

standardize(perfs::Performances)

Convert performance data to default performance type: fractional, discrete and net performances.

source

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.getLogPricesFunction.

getLogPrices(prices::Prices)

Transform prices to logarithmic prices if necessary.

source

# DynAssMgmt.getDiscretePricesFunction.

getDiscretePrices(prices::Prices)

Transform prices to discrete values if necessary.

source

# DynAssMgmt.normalizePricesFunction.

normalizePrices(xx::Array{Float64, 1})

Rescale prices such that first observation starts at 1.

source

normalizePrices(xx::Array{Float64, 2})

source

normalizePrices(xx::TimeArray)

source

normalizePrices(xx::Prices)

source

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.computeReturnsFunction.

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 NaNs also

source

computeReturns(prices::Array{Float64, 2}, retType = ReturnType())

source

computeReturns(xx::TimeSeries.TimeArray, retType = ReturnType())

source

# DynAssMgmt.aggregateReturnsFunction.

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 NaNs still needs to be defined

source

aggregateReturns(discRets::Array{Float64, 2}, retType::ReturnType, prependStart=false)

source

aggregateReturns(discRets::TimeSeries.TimeArray, retType::ReturnType, prependStart=false)

source

aggregateReturns(rets::Returns, prependStart=false)

source

# DynAssMgmt.rets2pricesFunction.

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 NaNs still needs to be defined

source

rets2prices(rets::Array{Float64, 2}, retType::ReturnType)

source

rets2prices(rets::TimeSeries.TimeArray, retType::ReturnType, startPrice=1., prependStart=false)

source

rets2prices(rets::Returns, startPrice=1., prependStart=false)

source

Data imputation

# DynAssMgmt.locf!Function.

locf!(xx::Array{Float64, 1})

Replacing NaN according to last observation carried forward.

source

# DynAssMgmt.locfFunction.

locf(xx::Array{Float64, 1})

Replacing NaN according to last observation carried forward.

source

locf(xx::Array{Float64, 2})

source

locf(xx::TimeArray)

source

# DynAssMgmt.nocb!Function.

nocb!(xx::Array{Float64, 1})

Replacing NaN according to next observation carried backward.

source

# DynAssMgmt.nocbFunction.

nocb(xx::Array{Float64, 1})

Replacing NaN according to next observation carried backward.

source

nocb(xx::Array{Float64, 2})

source

nocb(xx::TimeArray)

source