matlab capm
时间: 2023-10-11 16:10:22 浏览: 217
capm
CAPM, or the Capital Asset Pricing Model, is a widely used financial model that quantifies the relationship between an asset's expected return and its risk. It provides a framework for estimating the expected return on an investment by taking into account its beta, which measures the asset's sensitivity to market movements.
In MATLAB, you can calculate the CAPM using the following steps:
1. Gather historical data for the asset's returns and a market index (such as S&P 500).
2. Calculate the returns for both the asset and the market index.
3. Estimate the asset's beta by regressing the asset's returns against the market index returns using the "regress" function in MATLAB.
4. Once you have the beta, estimate the asset's expected return using the CAPM formula: Expected Return = Risk-Free Rate + Beta * (Market Return - Risk-Free Rate).
Here is some example code in MATLAB to calculate the CAPM:
```matlab
% Step 1: Gather historical data
assetReturns = [0.05, 0.03, -0.02, 0.04, 0.01]; % Example asset returns
marketReturns = [0.06, 0.04, 0.01, 0.02, -0.03]; % Example market returns
% Step 2: Calculate returns
assetReturns = diff(assetReturns);
marketReturns = diff(marketReturns);
% Step 3: Estimate beta
[beta, ~] = regress(assetReturns', [ones(size(marketReturns')), marketReturns']);
% Step 4: Calculate expected return
riskFreeRate = 0.02; % Example risk-free rate
marketReturn = mean(marketReturns);
expectedReturn = riskFreeRate + beta * (marketReturn - riskFreeRate);
disp(['Estimated Beta: ', num2str(beta)]);
disp(['Expected Return: ', num2str(expectedReturn)]);
```
Note that this is a simplified example, and you may need to adjust it depending on your specific requirements and data availability.
阅读全文