API Docs

Manual, tutorials and complete function reference

portfolio_addPosition

Adds position to an existing portfolio.


Usage
portfolio_addPosition(portfolio, symbol, quantity, priceData=NULL)
portfolio
Portfolio object created using portfolio_create() function
symbol
Unique identifier of an instrument
quantity
One dimensional vector of position quantities or an integer number if quantity is constant
priceData
Vector of (time, price) for user-defined asset prices.

Return Value
Void
Examples
# create portfolio with client-side 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_settings(portfolio, windowLength = '1h')
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)

# create portfolio with server-side data
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)
% create portfolio with client-side data
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
 
% create trading portfolio with server-side data
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',3600);
portfolio