sharpe ratio in Financial time series toolbox

5 Ansichten (letzte 30 Tage)
Kaijie Cui
Kaijie Cui am 21 Feb. 2013
Kommentiert: james am 5 Nov. 2024 um 11:31
Dear all,
I used the "sharpe" function to calculate the sharpe ratio of my monthly return data. But the result is different from the the function I wrote using the definition from http://financetrainingcourse.com/education/2011/04/market-risk-metrics-sharpe-and-treynor-ratios/.
Here is my code:
RI = (sum(Return))*12/N; % holding period return
MonSigma = std(Return); % monthly volatility
AnuSigma = MonSigma*sqrt(12); % annual volatility
IPO.SharpeRatio = (RI-RIF)/AnuSigma;
could anyone help me out with this?
Thank you.
  1 Kommentar
james
james am 5 Nov. 2024 um 11:31
% Sharpe Ratio Calculation using Financial Time Series Toolbox
% For more insights on effective intraday strategies, visit:
% Example data: Replace with your actual return series
% Assume 'returns' is a vector of asset returns (e.g., daily returns)
returns = [0.01, -0.005, 0.007, 0.002, -0.003, 0.004, 0.006]; % Sample data
% Define the risk-free rate (annualized). Adjust based on your context.
riskFreeRateAnnual = 0.02; % 2% annual risk-free rate
% Convert annual risk-free rate to the same period as returns (e.g., daily)
% Assuming 252 trading days in a year
riskFreeRate = riskFreeRateAnnual / 252;
% Calculate excess returns
excessReturns = returns - riskFreeRate;
% Compute the mean and standard deviation of excess returns
meanExcessReturn = mean(excessReturns);
stdExcessReturn = std(excessReturns);
% Calculate the Sharpe Ratio (assuming returns are in the same period as risk-free rate)
sharpeRatio = meanExcessReturn / stdExcessReturn;
% Annualize the Sharpe Ratio if needed
% sharpeRatioAnnualized = sharpeRatio * sqrt(252);
% Display the Sharpe Ratio
fprintf('Sharpe Ratio: %.4f\n', sharpeRatio);
% fprintf('Annualized Sharpe Ratio: %.4f\n', sharpeRatioAnnualized);

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Sean de Wolski
Sean de Wolski am 21 Feb. 2013
Just run:
edit sharpe
Scroll down and you can see exactly what it's doing. Looks like likes 75:79 are the engine.
  2 Kommentare
Kaijie Cui
Kaijie Cui am 21 Feb. 2013
Thank you for your answer. I checked the sharpe source code, the problem is I do not understand what kind of data is the function "sharpe" working with, annual return? monthly? or daily? That might be financial question not Matlab question...
Sean de Wolski
Sean de Wolski am 21 Feb. 2013
It describes it in the doc for sharpe and provides an example.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Risk Management Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by