Skip to main content

sharpe_ratio

Get Rolling Sharpe Ratio.

This function calculates the Sharpe Ratio, a metric used to assess the return of an investment compared to its risk. By factoring in the risk-free rate, it helps you understand how much extra return you're getting for the extra volatility that you endure by holding a riskier asset. The Sharpe Ratio is essential for investors looking to compare the efficiency of different investments, providing a clear picture of potential rewards in relation to their risks over a specified period. Ideal for gauging the effectiveness of investment strategies, it offers insights into optimizing your portfolio for maximum return on risk.

Example​

from openbb import obb

stock_data = obb.equity.price.historical(symbol="TSLA", start_date="2023-01-01", provider="fmp").to_df()
returns = stock_data["close"].pct_change().dropna()
obb.quantitative.sharpe_ratio(data=returns, target="close")

Parameters​

NameTypeDescriptionDefaultOptional
dataList[Data]Time series data.False
targetstrTarget column name.False
rfrfloatRisk-free rate, by default 0.00.0False
windowintWindow size, by default 252252False
indexstrdateFalse

Returns​

OBBject
results : List[Data]
Sharpe ratio.