# Anomaly Detection in Financial Time Series by Principal Component Analysis and Neural Networks +
## 7 Application to a Downstream Task: Value-at-Risk Computations  
In this section, we illustrate the benefits of applying the PCA NN approach as a pre-processing step for value-at-risk computations. Given a random variable \(\varrho\) representing the loss in portfolio position over a time horizon \(h\), its value-at-risk at the confidence level \(\alpha\in\left(\frac{1}{2},1\right)\), \(\text{VaR}_{\alpha}(\varrho)\), is defined by the quantile of level \(\alpha\) of the loss distribution, i.e., \(\mathbb{P}(\varrho\leq\text{VaR}_{\alpha}(\varrho))=\alpha\) (assuming \(\varrho\) is atomless for simplicity). Let \((S_{t})_{t=t_{1},\ldots,t_{T}}\) be a path price diffusion distributed according to the Black-Scholes model (7). The logarithmic returns to maturity are distributed according to the Gaussian distribution  
\[\ln\!\left(\frac{S_{t+\hat{\mu}}}{S_{t}}\right)\sim\mathcal{N}\!\left(\left( \mu-\frac{\sigma^{2}}{2}\right)h,\sigma^{2}h\right), \tag{14}\]  
with \(\mu\in\mathbb{R}\) and \(\sigma>0\). Figure 16: Mean \(F_{1}\)-score for localization step with respect to the various values of \(\rho\) for the training and test sets, respectively, represented by the blue and pink curves. Figure 15: Mean \(F_{1}\)-score for identification step with respect to the various values of \(\rho\) for the training and test sets, respectively, represented by the blue and pink curves. We assume the vector \(\mathbf{R}\) of the log-returns of our stocks to be joint-normal,  
\[\mathbf{R}=\left(R^{1},R^{2},\ldots,R^{i},\ldots,R^{N}\right)^{\top}\sim\mathcal{N}_ {N}(\mu_{R},\Sigma_{R}),\]  
where \(R^{i}=\log\left(\frac{S_{i+k}^{i}}{S_{i}^{i}}\right)\sim\mathcal{N}\left(\mu_{i,R},\sigma_{i,R}^{2}\right)\) and \(\Sigma_{R}\) is the covariance matrix. We consider a portfolio on \(N\) stocks, whose return is given by \(P=\mathcal{Q}^{\top}\mathbf{R}\), where \(\mathcal{Q}\in\mathbb{R}^{N}\) defines the composition of the portfolio. Hence, \(P\sim\mathcal{N}\big{(}\mu_{P},\sigma_{P}^{2}\big{)}\), where \(\mu_{P}=\mathcal{Q}^{\top}\mu_{R}\) and \(\sigma_{P}^{2}=\mathcal{Q}^{\top}\Sigma_{R}\mathcal{Q}\). The value-at-risk for the time horizon \(h\) at level \(a\) is  
\[\text{VaR}_{a}(P)=\mu_{P}+q_{a}\sigma_{P}\, \tag{15}\]  
where \(q_{a}\) is the \(a\)-quantile of a standard normal distribution and the parameters \(\mu_{R}\) and \(\Sigma_{R}\) are estimated from different types of time series to evaluate the impact of localizing and removing anomalies following our approach. Under the adopted framework, the true \(\text{VaR}_{a}(P)\), \(\text{VaR}^{theo}\), is thus known and can be computed using the diffusion parameters. An estimation \(\widehat{\text{VaR}}_{a}(P)\) can be obtained by replacing the parameters in (15) with their estimates \(\widehat{\mu_{P}}\) and \(\widehat{\sigma_{P}}\) computed from the time series with anomalies or after the imputation of anomalies. Then, the absolute errors and relative errors are computed as  
\[\text{AbsoluteError}_{\text{VaR}}=\left|\text{VaR}_{a}(P)- \widehat{\text{VaR}}_{a}(P)\right|,\] \[\text{RelativeError}_{\text{VaR}}=\frac{\left|\text{VaR}_{a}(P )-\widehat{\text{VaR}}_{a}(P)\right|}{\text{VaR}_{a}(P)}\]  
Table 17 summarizes the four VaR estimations we considered in the sequel. To conduct this analysis, we generated new stock path samples that we assumed to be clean, fixing the diffusion parameters \(\mu_{R}\) and \(\Sigma_{R}\). We then added the anomalies following the procedure described in Section 3. We applied our model to localize the anomalies and replaced the localized anomalies using the backward fill (BF) approach (shown to be the more efficient imputation technique in Section 6.1). For each stock and each run of the simulation, we obtained four estimates of the distribution parameters of the associated log-returns. Figure 17 and Table 18 summarize the distribution of the VaR estimates for \(\alpha=0.99\) and \(h=1(day)\) over several simulation runs. The box plots show the dispersion of the portfolio VaR estimates on several diffusions.