# Code Repo

https://github.com/hy2632/Efficient-Frontier

## Brief

Barings 的 Nick Leeson 在1995年 short straddle 损失 \$1B。 How Did Nick Leeson Contribute To The Fall of Barings Bank? ## Preface

In Robert Carver's book "Systematic Trading", he compared the two mindsets of trading: "Early Profit Taker" and "Early Loss Taker". The previous one is our mankind's "flawed instinction" and the latter one is believed to outperform the previous one.

This notebook implements the argument and verifies it through different examples.

Some of the parameters in the method is at your own discretion. Stocks and futures might take values to different orders of magnitude w.r.t. the "tolerance_lo", let alone the fact that everyone has his own extent of tolerance.

# Data Mining Final

Hua Yao, UNI:hy2632

## Problem 1: Reducing the variance of the Monte Carlo estimators [50 points]

### Proposed estimator

Here we propose an estimator using antithetic sampling for variance reduction.

# Evolutional Strategy

## RL Policies Optimization

State, Action

Policy: Deterministic / Randomized

Function $$F: \mathbb{R}^d \to \mathbb{R}$$, reward from vector to scalar.

# HW3

Hua Yao, UNI:hy2632

## Problem 1: SVM algorithm in action [50 points]

### Description of the algorithm:

1. Used dual SVM

2. Did not consider regularization, a.k.a. set $$C=\infty$$, because this problem (binary classification between 0/9) should be separable, and the representation of $$b$$ becomes nasty with regularization.

3. Used the SMO (sequential minimal optimization) algorithm. During optimization, within each iteration, randomly select $$\alpha_1, \alpha_2$$, optimize the QP w.r.t. $$\alpha_2$$ and update $$\alpha_1$$ accordingly. Added constraint $$\alpha_2 \geq 0$$ to the $$\alpha_2$$ optimizer. This does not constrain $$\alpha_1\geq 0$$ directly. However, with the randomization within each iteration, $$\alpha_i \geq 0$$ is satisfied when the whole optimzation over $$\alpha$$ finally converges.

4. Provide 2 options: Linear Kernel (baseline SVM) or Softmax kernel

$K_{SM}(x, y) = \exp{x^\top y}$

To avoid explosion on scale, normalized the input $$x$$.

Included the trigonometric feature map $$\phi(x)$$ of the softmax kernel for calculating $$b$$, (not for $$w$$ because when making prediction, we use kernel function instead of $$w^\top \phi$$).

Use exact kernel instead of approximating kernel with random feature map, because softmax's dimensionality is infinite. Directly compute the exponential in numpy is more efficient.

The prediction comes like this (vectorized version):

$y_{new} = K(X_{new}, X)\cdot (\alpha * y) + b$

Note that b is broadcasted to $$n'$$ new data points. $$K(X_{new}, X)$$ is $$n' \times n$$ kernel matrix. $$\alpha*y$$ means the elementwise product of two vectors.

5. SVM is expensive when $$n$$ is large. Here in practice, we trained on a small batch (default=64). The randomness here influences the performance.

6. Have a few trial runs to get the model with best prediction on the training data. Then it should give good prediction on the validation data. You might also need to tune the hyperparameters a little bit, like batch_size and tol.

Primal:

## 实现效果 ## Recap

KKT, Lagrangian

$L(w, b, \alpha, \beta) = f(w,b) + \sum_{i=1}^{N}{\alpha_ig_i(w,b)} + \sum_{i=1}^{N}{\beta_ih_i(w,b)}$

$\theta(w,b) = \max_{\alpha, \beta} L(w, b, \alpha, \beta)$

$\theta(w,b) = \begin{cases} f(w,b) \text{\: if feasible} \\ \infty \text{\: otherwise} \end{cases}$

# HW2

Hua Yao, UNI:hy2632

## Problem 1: Convolutional Neural Networks [20 points]

The input RGB- image has 3 channels. Apply Conv2D to each channel to get 3 feature maps.

When there's no padding, the shape of 3 feature maps are $$125\times125$$.