## Risk Platform

##### High frequency portfolio backtesting and optimization
• API for R, MATLAB, Python, Java
• Market microstructure analysis
• Historical prices since 2013
• 8,000+ symbols (stocks, ETFs & indices)
• Client-side market data
• 40+ portfolio & position metrics

##### 1. Create Portfolio
``````# create empty portfolio
portfolio=portfolio_create(fromTime="2014-10-01",
toTime="2014-10-02")

# add GOOG and AAPL positions

# display summary table and chart
print(portfolio)
plot(portfolio)``````
###### Output in RStudio
``````% create empty portfolio
portfolio=portfolio_create('fromTime','2014-10-01',...
'toTime','2014-10-02');

% add GOOG and AAPL positions

% display summary table and chart
display(portfolio);
plot(portfolio);``````
##### 2. Compute Sharpe Ratio
Compute position and portfolio-level intraday Sharpe Ratio on a daily time scale (default settings).
``````# position-level Sharpe ratio
aapl.ratio = position_sharpeRatio(portfolio,"AAPL")
goog.ratio = position_sharpeRatio(portfolio,"GOOG")
c.ratio = position_sharpeRatio(portfolio,"C")
portf.ratio = portfolio_sharpeRatio(portfolio)

# plot metrics
util_plot2d(aapl.ratio,title="Sharpe Ratio, daily",
legend="AAPL")+
util_line2d(goog.ratio,legend="GOOG")+
util_line2d(c.ratio,legend="C")+
util_line2d(port.ratio,legend="Portfolio")``````
###### Output in RStudio
``````% position-level Sharpe ratio
aapl.ratio = position_sharpeRatio(portfolio,'AAPL');
goog.ratio = position_sharpeRatio(portfolio,'GOOG');
c.ratio = position_sharpeRatio(portfolio,'C');
portf.ratio = portfolio_sharpeRatio(portfolio);

% plot metrics
util_plot2d(aapl.ratio,'AAPL','Title',...
'Sharpe Ratio, daily')+...
util_line2d(goog.ratio,'GOOG')+...
util_line2d(c.ratio,'C')+...
util_line2d(portf.ratio,'Portfolio')``````

##### 1. Create Portfolio
``````# create empty portfolio
portfolio=portfolio_create(fromTime="2014-10-01",
toTime="2014-10-02")

# add GOOG and AAPL positions

# display summary table and chart
print(portfolio)
plot(portfolio)``````
###### Output in RStudio
``````% create empty portfolio
portfolio=portfolio_create('fromTime','2014-10-01',...
'toTime','2014-10-02');

% add GOOG and AAPL positions

% display summary table and chart
display(portfolio);
plot(portfolio);``````
##### 2. Run Optimization
Compute position and portfolio-level intraday Sharpe Ratio on a daily time scale (default settings).
``````# set goals, constraints an perform optimization
opt=optimization_goal(portfolio,10^9,
"Variance","minimize")
opt=optimization_constraint_expectedReturn(opt,">=",0)

opt.portfolio=optimization_run(opt)

# compare expected return of both portfolios
util_plot2d(portfolio_expectedReturn(portfolio),
"Exp. Return, daily", legend="Original Portfolio")+
util_line2d(portfolio_expectedReturn(opt.portfolio),
Legend="Optimal Portfolio")
``````
###### Output in RStudio
``````% set goals, constraints an perform optimization
opt=optimization_goal(portfolio,10^9,...
'Variance','minimize');
opt=optimization_constraint_expectedReturn(opt,'>=',0);

opt.portfolio=optimization_run(opt);

% compare expected return of both portfolios
util_plot2d(portfolio_expectedReturn(portfolio),...
'Original Portfolio','Title','Exp. Return, daily')+...
util_line2d(portfolio_expectedReturn(opt.portfolio),...
'Optimal Portfolio')``````