API Docs

Manual, tutorials and complete function reference

portfolio_create

Creates new empty portfolio To add positions use portfolio_addPosition(). To remove positions use portfolio_removePosition().


Usage
portfolio_create(index, fromTime, toTime)
portfolio_create(priceDataIx)
index
Index symbol that should be used in the Single Index Model. Defaults to "SPY".
fromTime
Start of market data interval in "yyyy-MM-dd hh:mm:ss" format when internal market data is used. ffset from last available date/time by N days is denoted as "t-N" (e.g. "t-7" denotes offset by 7 days).
toTime
End of market data interval in "yyyy-MM-dd hh:mm:ss" format when internal market data is used. Offset from last available date/time by N days is denoted as "t-N" (e.g. "t-7" denotes offset by 7 days).
priceDataIx
Vector of (time, price) observations for market index asset when external market data is used.

Return Value
Portfolio object
Examples
data(aapl.data) 
data(goog.data) 
data(spy.data) 
portfolio=portfolio_create(priceDataIx=spy.data)
portfolio_addPosition(portfolio,'GOOG',100,priceData=goog.data) 
portfolio_addPosition(portfolio,'AAPL',300,priceData=aapl.data) 
portfolio_addPosition(portfolio,'SPY',150,priceData=spy.data)
portfolio_settings(portfolio, windowLength='1h')
print(portfolio)

portfolio=portfolio_create(priceDataIx=spy.data)
portfolio_addPosition(portfolio,'GOOG',c(100,200),time=c(1412256601000,1412266600000),priceData=goog.data) 
portfolio_addPosition(portfolio,'AAPL',c(300,150),time=c(1412266600000,1412276600000),priceData=aapl.data) 
portfolio_addPosition(portfolio,'SPY',150,priceData=spy.data)
portfolio_settings(portfolio, windowLength='1h')
print(portfolio)

portfolio=portfolio_create(fromTime="2014-09-01 09:00:00",toTime="2014-09-14 16:00:00")
portfolio_addPosition(portfolio,c('C','SPY'),c(500,600))
portfolio_settings(portfolio, windowLength='1h')
print(portfolio)

portfolio=portfolio_create(fromTime="2014-10-02 09:30:00",toTime="2014-10-02 16:00:00")
portfolio_addPosition(portfolio,c('C','SPY'),c(500,600))
portfolio_addPosition(portfolio,'GOOG',100,priceData=goog.data) 
portfolio_addPosition(portfolio,'AAPL',c(300,150),time=c(1412266600000,1412276600000),priceData=aapl.data) 
portfolio_settings(portfolio, windowLength='1h')
print(portfolio)

portfolio=portfolio_create(fromTime="t-7", toTime="t")
portfolio_addPosition(portfolio,c('C','SPY'),c(500,600))
portfolio_settings(portfolio, windowLength='1h')
print(portfolio)
goog.data=importdata('data_goog.mat'); 
aapl.data=importdata('data_aapl.mat');  
spy.data=importdata('data_spy.mat'); 
portfolio=portfolio_create('priceDataIx',spy.data); 
portfolio_addPosition(portfolio,'GOOG',100,'priceData',goog.data);
portfolio_addPosition(portfolio,'AAPL',300,'priceData',aapl.data);
portfolio_addPosition(portfolio,'SPY',150,'priceData',spy.data);
portfolio_settings(portfolio,'windowLength','1h');
portfolio

portfolio=portfolio_create('priceDataIx',spy.data); 
portfolio_settings(portfolio,'windowLength',3600);
portfolio_addPosition(portfolio,'GOOG',[100,200],'time',[1412256601000,1412266600000],'priceData',goog.data) ;
portfolio_addPosition(portfolio,'AAPL',[300,150],'time',[1412266600000,1412276600000],'priceData',aapl.data) ;
portfolio_addPosition(portfolio,'SPY',150,'priceData',spy.data);
portfolio_settings(portfolio,'windowLength','1h');
portfolio

portfolio=portfolio_create('index','SPY','fromTime','2014-09-10 09:30:01','toTime','2014-09-14 16:00:00');
portfolio_addPosition(portfolio,'GOOG',200);
portfolio_addPosition(portfolio,'AAPL',100);
portfolio_addPosition(portfolio,'SPY',100);
portfolio_settings(portfolio,'windowLength','1h');
portfolio

portfolio=portfolio_create('index','SPY','fromTime','2014-10-02 09:30:01','toTime','2014-10-02 16:00:00');
portfolio_addPosition(portfolio,'GOOG',[100,200],'time',[1412256601000,1412266600000]);
portfolio_addPosition(portfolio,'AAPL',100,'priceData',aapl.data);
portfolio_addPosition(portfolio,'SPY',100);
portfolio_settings(portfolio,'windowLength','1h');
portfolio

portfolio=portfolio_create('index','SPY','fromTime','t-7','toTime','t');
portfolio_addPosition(portfolio,'GOOG',200);
portfolio_addPosition(portfolio,'AAPL',100);
portfolio_addPosition(portfolio,'SPY',100);
portfolio_settings(portfolio,'windowLength','1h');
portfolio