sharpe(): number
Computes the Sharpe Ratio.
Calculates the Sharpe Ratio for an asset or portfolio given its returns and a risk-free rate. The risk-free rate should be adjusted to match the timeframe of the returns.
The Sharpe Ratio formula: SR = (Mean Return - Risk-Free Rate) / Standard Deviation
Sharpe Ratio for a single asset
Sharpe Ratio for a single asset
import { assertEquals } from "jsr:@std/assert"; const x = [0.003, 0.026, 0.015, -0.009, 0.014, 0.024, 0.015, 0.066, -0.014, 0.039]; assertEquals(sharpe(x, 0.02 / 12), 0.6987943426529188);
x: array
Asset/portfolio returns
sharpe(): array | matrix
Computes the Sharpe Ratio.
Calculates the Sharpe Ratio for an asset or portfolio given its returns and a risk-free rate. The risk-free rate should be adjusted to match the timeframe of the returns.
The Sharpe Ratio formula: SR = (Mean Return - Risk-Free Rate) / Standard Deviation
Sharpe Ratio for a single asset
Sharpe Ratio for a single asset
import { assertEquals } from "jsr:@std/assert"; const x = [0.003, 0.026, 0.015, -0.009, 0.014, 0.024, 0.015, 0.066, -0.014, 0.039]; assertEquals(sharpe(x, 0.02 / 12), 0.6987943426529188);
x: matrix
Asset/portfolio returns