Home

Awesome

FINANCE

NPM version

This module contains an implementation of Markowitz algorithm for the portfolio optimization, a routine for retrieving historical prices from Yahoo, statistical information for stocks and a routine for calculating implied volatility using Black and Scholes formula.

Example

See examples directory.

For a frontend, see node-conpa.

Installation

To install with npm:

npm install finance

Tested with Node.js 14.x, R 3.4.3 and Rserve 1.7.3.

Methods

keystatistics.getKeyStatistics(params, callback)

It retrieves the key statistics for the stocks and returns an array of objects to create an uneditable form on front-end side.

Params

Callback response

optionchain.getOptionChainFromYahoo(params, callback)

It retrieves the strike values for calls and puts from Yahoo! Finance.

Params

Callback response

parsecsv.parse(arr, options)

Arguments

performances.getPerformances(x, weights)

It calculates the weighted performance for a matrix.

Arguments

Returns a vector containing the weighted perfomance of the matrix.

portfolio.getOptimalPortfolio(params, callback, config)

It creates an optimal portfolio. If config is defined, the method call a Rserve instance, otherwise a native implementation is used.

Params

Callback response

Config

portfolio.getScriptOptimalPortfolio(params, callback)

It retrieves the source code of the R script calculating the optimal portfolio.

Params See portfolio.getOptimalPortfolio.

Callback response

quotes.getQuotes(symbol, refDate, callback)

It retrieves the prices from Yahoo! finance.

Arguments

Callback response

returns.getReturns(symbols, refDate, callback)

It retrieves the prices from Yahoo! finance and calculates the log returns of the close prices.

Arguments

Callback response

riskfreerate.getRiskFreeRateFromYahoo(callback)

It retrieves the risk free rate from Yahoo! Finance.

Callback response

volatility.getImpliedVolatility(params, callback)

It calculates the implied volatility for an option using Black and Scholes formula.

Arguments

Callback response