Citadel Quant 店面

What is the optimal way to find the rolling window correlation between two vectors X1 = (X_1, X_2, …,X_n) and Y1 = (Y_1, Y_2, …,Y_n) . [Note: The definition for coorelation was not given, I asked but told I should know]. Since I didn’t know the definition I couldn’t answer this question but it should be similar to

Corr(X,Y) = Cov(X,Y) / ( Var(X)Var(Y) ), where
Cov(X,Y) = E[XY] - E[X]E[Y], Var(X) = E[X^2] - E[X]^2.

So, we need to maintain arrays for X, Y, XY, X^2, Y^2.
Calculate the moving average in each of these arrays. Plug them into the above formulae.

Give stock prices in an array nums find the way to minimize loss (or maximize profit). You can only buy and sell once!

Given an equation with variable x, perform constraint optimization over x S.T sum(X_1, X_2, … X_N) = 0. X again is a vector with n components.

A system design question for stocks using C++. What data members to use, what datastructures to use for implementing methods, what will their complexity be?

#### C++
### Class OrderBook
Sell Side:    
    level 1: price: 45.12$, Size: 5 shares
    level 2: price: 45.19$, Size: 3 shares
    level 3: price: 45.21$, Size: 10 shares
Buy Side: 
class OrderBook {
 public :
  void add(int order_id, char side, double price, int size);
  void modify(int order_id, int new_size);
  void remove(int order_id);
  double get_price(char side, int level);
  int get_size(char side, int level);
## data members?
  int size = 0;
  TreeNode root*; 
  # char SIDE = 'B';