May
24

## How to Generate Report Automatically From Matlab

Often we have to generate reports to our boss, colleagues, and clients, etc. Generally those reports include Matlab source codes, maths equations, and possibly graphs. How do you generate your reports? writing down your equations in Word, running your matlab codes, copying and pasting the results?

It is all right to do like that, but the whole process becomes extremely simple with the cell mode in Matlab, it generates report automatically for us, any change you make regarding description, codes and results will be updated by clicking a simple button:

The following steps outline the procedure,

For a simple demonstration, I write the files as follows.

The final report is shown at http://www.mathfinance.cn/attachment/CellPublishDemo.html, looks fantastic.

Hot posts:

15 Incredibly Stupid Ways People Made Their Millions

Online stock practice

Ino.com: Don't Join Marketclub until You Read This MarketClub Reviews

World Changing Mathematical Discoveries

Value at Risk xls

Random posts:

Up-and-out call option by Monte Carlo

Feedforward neural networks package

Is the Greece Default Immanent? (And What You Can Learn from it)

Kalman Filter Finance

Fourth Set: Basel III counterparty credit risk - Frequently asked questions

It is all right to do like that, but the whole process becomes extremely simple with the cell mode in Matlab, it generates report automatically for us, any change you make regarding description, codes and results will be updated by clicking a simple button:

**Publish to HTML**.The following steps outline the procedure,

First, opening an editor in Matlab by choosing File -> New -> M-file;

Second, selecting cell and enable cell mode in the editor;

Third, inserting cell divider under cell window, it allows you to type a name for each section, similar with the title for chapters in Word;

Fourth, depending on your reports, inserting Text Markup, where you are able to insert description text, bold text, etc. most importantly, it supports TeX equations;

Finally, clicking "Publish to HTML", a nice-looking report is generated, and if necessary, changing the codes and re-running to update the report.

Second, selecting cell and enable cell mode in the editor;

Third, inserting cell divider under cell window, it allows you to type a name for each section, similar with the title for chapters in Word;

Fourth, depending on your reports, inserting Text Markup, where you are able to insert description text, bold text, etc. most importantly, it supports TeX equations;

Finally, clicking "Publish to HTML", a nice-looking report is generated, and if necessary, changing the codes and re-running to update the report.

For a simple demonstration, I write the files as follows.

%% Cell mode publish demonstration

% abiao @ mathfinance.cn

%% Using Black Scholes formula as an example

% The value of a call and put options in terms of the Black–Scholes parameters

% is:

%

% $$C(S,t) = SN(d_1) - Ke^{-r(T - t)}N(d_2) \,$$

%

% $$P(S,t) = Ke^{-r(T-t)} - S + (SN(d_1) - Ke^{-r(T - t)}N(d_2)) = Ke^{-r(T-t)} - S + C(S,t)$$

%

% $$d_1 = \frac{\ln(\frac{S}{K}) + (r + \frac{\sigma^2}{2})(T - t)}{\sigma\sqrt{T - t}}$$

%

% $$d_2 = d_1 - \sigma\sqrt{T - t}$$

%% Sample code, for simplicity, I use the embedded command

[call, put] = blsprice(10,9,0.02,2,0.3);

fprintf('Call option value is %g. \n',call)

fprintf('Put option value is %g. \n',put)

call1 = [];

put1 = [];

for i = 1:10

call1(i) = blsprice(5+i,9,0.02,2,0.3);

end

%% Sample plot for demonstration only

plot(5+(1:10), call1)

% abiao @ mathfinance.cn

%% Using Black Scholes formula as an example

% The value of a call and put options in terms of the Black–Scholes parameters

% is:

%

% $$C(S,t) = SN(d_1) - Ke^{-r(T - t)}N(d_2) \,$$

%

% $$P(S,t) = Ke^{-r(T-t)} - S + (SN(d_1) - Ke^{-r(T - t)}N(d_2)) = Ke^{-r(T-t)} - S + C(S,t)$$

%

% $$d_1 = \frac{\ln(\frac{S}{K}) + (r + \frac{\sigma^2}{2})(T - t)}{\sigma\sqrt{T - t}}$$

%

% $$d_2 = d_1 - \sigma\sqrt{T - t}$$

%% Sample code, for simplicity, I use the embedded command

[call, put] = blsprice(10,9,0.02,2,0.3);

fprintf('Call option value is %g. \n',call)

fprintf('Put option value is %g. \n',put)

call1 = [];

put1 = [];

for i = 1:10

call1(i) = blsprice(5+i,9,0.02,2,0.3);

end

%% Sample plot for demonstration only

plot(5+(1:10), call1)

The final report is shown at http://www.mathfinance.cn/attachment/CellPublishDemo.html, looks fantastic.

**People viewing this post also viewed:**

Hot posts:

Random posts:

btw, the new theme is simple and nice, except for the huge Citi banner on the top little bit wierd...