API Docs

Manual, tutorials and complete function reference

Portfolio Construction

Client Data

Users may supply their own historical datasets for index and position entries. This external data could be one a OHLC bar column element (e.g. 1-second close prices) or a vector of actual transaction prices that contains non-equidistant data points. You might want to pre-pend at least N =(4 x windowLength) data points to the beginning of the interval of interest which would be used for initial calibration of portfolio metrics.

Create Portfolio

Method portfolio_create() takes a vector of index prices in the format [UTC timestamp, price] with UTC timestamp expressed in milliseconds from 1970-01-01 00:00:00 EST.

	Time        Value
 [1,] 1412256601000 99.30
 [2,] 1412256602000 99.33
 [3,] 1412256603000 99.30
 [4,] 1412256604000 99.26
 [5,] 1412256605000 99.36
 [6,] 1412256606000 99.36
 [7,] 1412256607000 99.36
 [8,] 1412256608000 99.38
 [9,] 1412256609000 99.40
[10,] 1412256610000 99.37

If index symbol is specified, it is silently ignored.

data(spy.data)

# Create portfolio
portfolio=portfolio_create(priceDataIx=spy.data)
spy.data=importdata('data_spy.mat'); 

% Create portfolio			
portfolio=portfolio_create('priceDataIx', spy.data)
Add Positions

Positions are added same way as before using portfolio_addPosition() with a 'priceData' in the same format as index prices.

data(goog.data)
data(aapl.data)

# Single position without rebalancing
portfolio_addPosition(portfolio, 
			symbol='GOOG', 
			quantity=100, 
			priceData=goog.data) 

# Single position with rebalancing
portfolio_addPosition(portfolio, 
			symbol='AAPL', 
			quantity=c(300,150), 
			time=c("2014-09-01 09:00:00","2014-09-07 14:30:00"), 
			priceData=aapl.data)
goog.data=importdata('data_goog.mat'); 
aapl.data=importdata('data_aapl.mat'); 

% Single position without rebalancing
portfolio_addPosition(portfolio, 		% portfolio	
			'GOOG', 		% symbol
			100, 			% position quantity
			'priceData', goog.data)	% price data - [UTC mills, price] 

% Single position with rebalancing
portfolio_addPosition(portfolio, 		% portfolio
			'AAPL',			% symbol
			[300;150], 		% position quantities
			'time', ['2014-09-01 09:00:00','2014-09-07 14:30:00'], 	% rebalancing times (string or UTC mills)
			'priceData', aapl.data)	% price data - [UTC mills, price]