# Illustration with Infantino’s PCA Strategy

### Revision for “Illustration with Infantino’s PCA Strategy” created on May 8, 2015 @ 02:18:03

TitleContentExcerptRevision Note
 Illustration with Infantino’s PCA Strategy In this tutorial, we demonstrate some powerful features of AlgoQuant (which is backed by our SuanShu library) using Infantino’s PCA strategy as an example. All the code referenced in this tutorial can be found in algoquant/model/infantino2010 package and its demo.

Powerful Mathematical Support

AlgoQuant is backed by our numerical library (SuanShu), so computing strategy signals becomes a very simple task, and the code usually takes only a few lines. For example, Infantino’s strategy computes its buy/sell signals based on principal component analysis (PCA). Here is the code snipplet for the computation of matrix D for the "dimensionally reduced returns" (mentioned on pages 25 and 26 in the paper):
PCA pca = new PCAbyEigen(X, false); Vector mean = pca.mean(); Matrix M_t = rbind(mean); Matrix M = rbind(nCopies(T, mean)); // each column is the average log returns for each stock Matrix Y = X.minus(M); // T by N List loadings = new ArrayList(k); for (int i = 1; i < = k; ++i) {     loadings.add(pca.loading(i)); } Matrix PHI = cbind(loadings); // N by k Matrix D = Y.multiply(PHI); // T by k

Quick Strategy Prototyping

With AlgoQuant, coding strategies for simulation can be done with minimal effort. A strategy class just needs to implement an interface, Strategy. Simulation in AlgoQuant is event-driven, so a strategy just needs to subscribe to the events it is interested, such as price changes, order executions, etc. By implementing the corresponding event handlers, the strategy is called back when the subscribed events happened. Here is the skeleton for Infantino2010Strategy which makes trade descisions upon price updates:
public class Infantino2010Strategy         implements Strategy, DepthHandler {     // … 	@Override     public void onDepthUpdate(DateTime now, Depth depth, MarketCondition mc, TradeBlotter blotter, Broker broker) {         // … compute buy/sell signals from the updated prices (or depths)         List orders = param.infantinoOrders.getOrders(signal, regime, blotter.positions(), mc.depths());         broker.sendOrder(orders);     } }

Historical price data from various sources (e.g., Bloomberg, Yahoo! Finance, Gain Capital, Compustat, etc.) can be loaded for simulation. For example, we use end-of-day data from Yahoo! Finance in our simulation. The following code snippet loads the data files cached in the harddrive or automatically downloads them from Yahoo! Finance website if the cache is absent.
// load data from Yahoo! this.caches =     new DepthCaches(     new DepthCacheFactory(){       @Override       public SequentialCache newInstance(Stock stock,Interval interval) throws Exception {         return new YahooDepthCacheFactory("./log/Yahoo").newInstance(stock, interval);       } 	},     stocks,     interval);

Simple Simulation Setup

Simulator with various options can be configured easily. For example, we configure the simulator to update the strategy with synchronized views of product depths by this:

Flexible & Extendible Performance Measures for Analysis

There are plenty of performance measures available for you to analyze the performance of your strategy (see performance package for more details). You can also conveniently develop your own set of measures.

Parallelized Sensitivity Analysis and Monte Carlo Simulation

Usually, a strategy takes in a few parameters, and we want to find the optimal ones to trade with. In addition, we are also interested in how sensitive the strategy’s performance is to the change of these parameters. With parallelized SensitivityAnalyzer in AlgoQuant, you can find the answer in plots with a few lines of code (see Infantino2010ParamAnalysis):
SimSetting simSetting = new SimSetting(simulator, caches, rates); SensitivityAnalyzer analyzer 	= new SensitivityAnalyzer( 	simSetting, 	measures, 	new StrategyFactory() { 	  @Override 	  public Infantino2010Strategy newInstance(Param param) { 		return new Infantino2010Strategy(param); 	  } 	}); SensitivityAnalysisReport report = analyzer.run(params, new NoOpProgressListener()); SensitivityPlotterUtils.plotAllMeasures(new GenericParamPlotter(true), report); printReport(report);
The simulations on various parameters run in parallel by utilizing all the available CPU cores, so that results can be obtained multiple times faster. Besides, you can also run MCSimulation with customizable price models.

Old New Date Created Author Actions
May 8, 2015 @ 02:18:03 henrymorco
May 8, 2015 @ 02:17:24 [Autosave] henrymorco
May 8, 2015 @ 01:54:09 henrymorco
May 7, 2015 @ 11:18:43 henrymorco
May 7, 2015 @ 11:18:03 henrymorco
May 7, 2015 @ 10:25:46 henrymorco
April 15, 2015 @ 15:29:19 webmaster
April 15, 2015 @ 15:29:18 [Autosave] webmaster
April 15, 2015 @ 15:24:53 webmaster
April 15, 2015 @ 15:23:05 webmaster
April 14, 2015 @ 06:27:20 sanjay
April 14, 2015 @ 06:26:29 [Autosave] sanjay
April 13, 2015 @ 13:24:49 sanjay
April 13, 2015 @ 12:00:53 sanjay
April 13, 2015 @ 11:59:21 sanjay
April 13, 2015 @ 08:00:20 sanjay