www.gusucode.com > econ 案例源码程序 matlab代码 > econ/ConvertAStockPricesSeriesToAReturnSeriesExample.m

    %% Convert a Stock Price Series to a Return Series
%%
% Create a stock price process continuously compounded at 10 percent:

% Copyright 2015 The MathWorks, Inc.

S = 100*exp(0.10 * [0:19]'); 
    % Create the stock price series
%%
% Convert the price series to a 10 percent return series:
R = price2ret(S);   % Convert the price series to a 
                    % 10 percent return series
[S [R;NaN]]  % Pad the return series so vectors are of  
   % same length. price2ret computes the ith return from 
   % the ith and i+1th prices.