# finlabR

Portfolio analytics and simulation toolkit in R. Includes:
- Mean-variance optimization (efficient frontier, max Sharpe, min variance)
- CVaR minimization
- Risk parity (equal risk contribution)
- Regime clustering (k-means)
- Asset correlation and clustering (PCA, EM, k-means)
- VaR/CVaR analysis
- Monte Carlo price simulation
- Option pricing (Monte Carlo, binomial tree, American)
- Limit order book simulation and features

## Quick start

```r
library(finlabR)

# load example dataset
prices <- get_example_prices()
rets <- calc_returns(prices[, -1])

# returns matrix (rows = time, cols = assets)
min_var <- mvo_min_variance(rets)
frontier <- mvo_efficient_frontier(rets, n = 30)
max_sharpe <- mvo_max_sharpe(rets, rf = 0.02)

cvar <- cvar_minimize(rets, alpha = 0.95)
rp <- risk_parity_weights(stats::cov(rets))

varcvar <- var_cvar(rets, alpha = 0.95)

# limit order book demo
book <- simulate_orderbook(n_steps = 200, p0 = 100)
lob_features <- extract_features(book)
# run source('runme.R') for Shiny App
```

## Full reference

See `REFERENCE.md` in the repository for the full list of functions and usage examples.
#file <- system.file("extdata/runme.R", package = "finlabR")
#source(file)
## Run the Shiny dashboard

```r
shiny::runApp(system.file("shiny/finlabR-dashboard", package = "finlabR"))
```
