ALLY, BX and SONY over the next half year (`expiry` = 0.5) conditioned the value at risk being in the 5th percentile. ### Other Notable Features 1. Distribution Modes scrilla will assume an asset price process and therefore a probability distribution for the population of asset returns. The model scrilla assumes is determined by the environment variable ANALYSIS_MODE. Currently, only one model is available: `geometric`, which corresponds to an assume price process that follows [geometric brownian motion](https://en.wikipedia.org/wiki/Geometric_Brownian_motion) and thus a probability distribution for the asset returns that is log-normal. In the near future, a mean reversion model will implemented. 2. Estimation Modes scrilla can estimate model parameters in a number of ways. The default estimation method is defined by the environment variable DEFAULT_ESTIMATION_METHOD, but all statistical functions can have their estimation overridden with a flag. scrilla supports three estimation modes: `moments`, `percents` and `likely`. `moments` will use the [method of moment matching](https://en.wikipedia.org/wiki/Method_of_moments_(statistics)), where the moments of a sample of data are equated to the moments of the assumed distribution in order to determine the distribution parameters. `percents` will use the method of percentile matching, where the first and third quartile of the sample are equated to the theoretical distribution percentiles to determine the distribution parameters. `likely` will use [maximum likelihood estimation](https://en.wikipedia.org/wiki/Maximum_likelihood_estimation), where the probability of each observation given the assumed distribution is calculated and then the intersection of the probabilities is minimized with respect to the distribution parameters. (Note: the underlying distribution can be configured through the ANALYSIS_MODE environment variable; see [Environment](#environment) for more information) For example, the following command will return the risk profile of ACI using the method of moment matching, ```shell scrilla risk-profile ACI -moments ``` Where as the following command will return the risk profile of ACI using maximum likelihood estimation, ```shell scrilla risk-profile ACI -likelihood ``` And the following command will return the risk profile of ACI using the method of percentile matching, ```shell scrilla risk-profile ACI -percentiles ``` Note, the following command, ```shell scrilla risk-profile ACI ``` will return the risk profile of ACI using the method set in the DEFAULT_ESTIMATION_METHOD environment variable. If this variable is not set, it will default to a value of `moments`. 2. Discount Dividend Model scrilla will pull an equity's dividend payment history, regress the payment amount against its date and infer a [simple linear regression model](https://en.wikipedia.org/wiki/Simple_linear_regression) from this time series. It will use this model to project future dividend payments and then calculate the current cost of equity and use that to discount the sum of dividend payments back to the present. The following command will perform this action, ```shell scrilla ddm ALLY ``` Alternatively, you can visualize the dividend payments against the regression model with a matplotlib graphic, ```shell scrilla plot-divs ALLY ``` 3. Financial Statistics - Beta: `scrilla capm-beta [TICKERS] [OPTIONS]` - Correlation Matrix: `scrilla cor [TICKERS] [OPTIONS]` - Conditional Value At Risk `scrilla cvar [TICKERS] -prob PROB -expiry EXP [OPTIONS]` - Cost Of Equity: `scrilla capm-equity [TICKERS] [OPTIONS]` - Risk-Return Profile: `scrilla risk-profile [TICKERS] [OPTIONS]` - Sharpe Ratio: `scrilla sharpe-ratio [TICKERS] [OPTIONS]` - Value At Risk: `scrilla var [TICKERS] -prob PROB -expiry EXP [OPTIONS]` 4. Stock Watchlist and Screening Stocks can be added to your watchlist with, ```shell scrilla watch [TICKERS] ``` You can then screen stocks according to some criteria. For example, the following command will search your watchlist for stock prices that are less than their Discount Dividend Model (very rare this happens...), ```shell scrilla screen -criteria DDM ``` 5. Visualizations - Discount Dividend Model: `scrilla plot-divs [TICKER] [OPTIONS]` - NOTE: THIS FUNCTION ONLY ACCEPTS ONE TICKER AT A TIME. - Efficient Fronter: `scrilla plot-ef [TICKERS] [OPTIONS]` - Moving Averages: `scrilla plot-mas [TICKERS] [OPTIONS]` - Risk Return Profile: `scrilla plot-rp [TICKERS] [OPTIONS]` - Yield Curve: `scrilla plot-yield` - QQ Plot of Returns: `scrilla plot-rets [TICKER] [OPTIONS]` - NOTE: THIS FUNCTION ONLY ACCEPTS ONE TICKER AT A TIME - Correlation Time Series `scrilla plot-cors [TICKERS] [OPTIONS]` - NOTE: THIS FUNCTION ACCEPTS EXACTLY TWO TICKERS ## Programmatic You can import and use **scrilla**'s function in a Python script. You must ensure the API keys have been set. See [Configuration](/CONFIGURATION.md) for more information. If the keys have not been configured through environment variables or set through the CLI, you must set the keys through Python's ``os`` library before importing any functions or modules from **scrilla**, ```python import os os.environ.setdefault('ALPHA_VANTAGE_KEY', 'key') os.environ.setdefault('QUANDL_KEY', 'key') os.environ.setdefault('IEX_KEY', 'key') ``` Replace `key` with the appropriate API key. Append this to the top of the script before **scrilla**'s modules are imported. ### Retrieve Price Data ```python import os os.environ.setdefault('ALPHA_VANTAGE_KEY', 'key') os.environ.setdefault('QUANDL_KEY', 'key') os.environ.setdefault('IEX_KEY', 'key') from scrilla.services import get_daily_price_history from scrilla.util import dater start = dater.parse('2021-01-01') end = dater.parse('2021-04-05') prices = get_daily_price_history(ticker='ALLY', start_date=start, end_date=end) ``` ### Risk Return ```python import os os.environ.setdefault('ALPHA_VANTAGE_KEY', 'key') os.environ.setdefault('QUANDL_KEY', 'key') os.environ.setdefault('IEX_KEY', 'key') from scrilla.analysis.models.geometric.statistics import calculate_risk_return from scrilla.util import dater start = dater.parse('2021-01-01') end = dater.parse('2021-04-05') prices = calulate_risk_return(ticker='BTC', start_date=start, end_date=end) ``` ### Portfolio Optimization ```python import os os.environ.setdefault('ALPHA_VANTAGE_KEY', 'key') os.environ.setdefault('QUANDL_KEY', 'key') os.environ.setdefault('IEX_KEY', 'key') from scrilla.analysis.objects.portfolio import Portfolio from scrilla.analysis.optimizer import optimize_portfolio_variance, maximize_sharpe_ratio from scrilla.util import dater start = dater.parse('2021-01-01') end = dater.parse('2021-04-05') port = Portfolio(tickers=['BTC','ALLY','SPY','GLD'], start_date=start, end_date=end) # calculate minimum variance portfolio & its risk profile min_vol_allocation = optimize_portfolio_variance(port) min_vol_port_ret = port.return_function(min_vol_allocation) min_vol_port_vol = port.volatility_function(min_vol_allocation) # calculate maximum sharpe ratio portfolio & its risk profile max_sh_allocation = maximize_sharpe_ratio(port) max_sh_port_ret = port.return_function(max_sh_allocation) max_sh_port_vol = port.volatility_function(max_sh_allocation) ```