[scilab-financial] 01/01: Initial import of scilab-financial version 1.0.1
Ruben Bibas
rubs-guest at alioth.debian.org
Tue Sep 10 21:18:53 UTC 2013
This is an automated email from the git hooks/post-receive script.
rubs-guest pushed a commit to branch master
in repository scilab-financial.
commit a79e2565d0f81f250e5c077ef4ac136d362187ed
Author: Ruben Bibas <ruben.bibas+debian at gmail.com>
Date: Tue Sep 10 22:01:07 2013 +0200
Initial import of scilab-financial version 1.0.1
---
builder.sce | 31 ++
changelog.txt | 16 +
cleaner.sce | 34 +++
debian/changelog | 5 +
debian/compat | 1 +
debian/control | 41 +++
debian/copyright | 20 ++
debian/docs | 3 +
debian/files | 1 +
debian/orig-tar.sh | 20 ++
debian/rules | 22 ++
debian/scilab-financial.debhelper.log | 36 +++
debian/scilab-financial.install | 5 +
debian/scilab-financial.substvars | 1 +
debian/scilab-financial/DEBIAN/control | 36 +++
debian/scilab-financial/DEBIAN/md5sums | 63 ++++
.../usr/lib/scilab-financial/demos/bsgreeks.sce | 30 ++
.../demos/financial.dem.gateway.sce | 7 +
.../usr/lib/scilab-financial/etc/financial.start | 34 +++
.../lib/scilab-financial/jar/scilab_en_US_help.jar | Bin 0 -> 75290 bytes
.../usr/lib/scilab-financial/loader.sce | 10 +
.../usr/lib/scilab-financial/macros/backtest.bin | Bin 0 -> 11100 bytes
.../usr/lib/scilab-financial/macros/backtest.sci | 57 ++++
.../usr/lib/scilab-financial/macros/bollinger.bin | Bin 0 -> 6432 bytes
.../usr/lib/scilab-financial/macros/bollinger.sci | 36 +++
.../usr/lib/scilab-financial/macros/bsgreeks.bin | Bin 0 -> 15180 bytes
.../usr/lib/scilab-financial/macros/bsgreeks.sci | 62 ++++
.../usr/lib/scilab-financial/macros/bsimpvol.bin | Bin 0 -> 5812 bytes
.../usr/lib/scilab-financial/macros/bsimpvol.sci | 37 +++
.../usr/lib/scilab-financial/macros/bsoption.bin | Bin 0 -> 4912 bytes
.../usr/lib/scilab-financial/macros/bsoption.sci | 28 ++
.../lib/scilab-financial/macros/buildmacros.bat | 1 +
.../lib/scilab-financial/macros/buildmacros.sce | 1 +
.../usr/lib/scilab-financial/macros/cfr.bin | Bin 0 -> 3664 bytes
.../usr/lib/scilab-financial/macros/cfr.sci | 35 +++
.../lib/scilab-financial/macros/cleanmacros.bat | 3 +
.../lib/scilab-financial/macros/cleanmacros.sce | 16 +
.../usr/lib/scilab-financial/macros/duration.bin | Bin 0 -> 5160 bytes
.../usr/lib/scilab-financial/macros/duration.sci | 31 ++
.../usr/lib/scilab-financial/macros/esvarevt.bin | Bin 0 -> 6732 bytes
.../usr/lib/scilab-financial/macros/esvarevt.sci | 37 +++
.../usr/lib/scilab-financial/macros/esvarlin.bin | Bin 0 -> 6984 bytes
.../usr/lib/scilab-financial/macros/esvarlin.sci | 38 +++
.../usr/lib/scilab-financial/macros/esvaroptim.bin | Bin 0 -> 22664 bytes
.../usr/lib/scilab-financial/macros/esvaroptim.sci | 118 ++++++++
.../usr/lib/scilab-financial/macros/euler.bin | Bin 0 -> 8436 bytes
.../usr/lib/scilab-financial/macros/euler.sci | 45 +++
.../usr/lib/scilab-financial/macros/evt.bin | Bin 0 -> 4508 bytes
.../usr/lib/scilab-financial/macros/evt.sci | 30 ++
.../usr/lib/scilab-financial/macros/gbm.bin | Bin 0 -> 6608 bytes
.../usr/lib/scilab-financial/macros/gbm.sci | 40 +++
.../usr/lib/scilab-financial/macros/hedge.bin | Bin 0 -> 8160 bytes
.../usr/lib/scilab-financial/macros/hedge.sci | 49 ++++
.../usr/lib/scilab-financial/macros/hurst.bin | Bin 0 -> 5940 bytes
.../usr/lib/scilab-financial/macros/hurst.sci | 38 +++
.../usr/lib/scilab-financial/macros/interest.bin | Bin 0 -> 15144 bytes
.../usr/lib/scilab-financial/macros/interest.sci | 78 +++++
.../usr/lib/scilab-financial/macros/irs.bin | Bin 0 -> 7756 bytes
.../usr/lib/scilab-financial/macros/irs.sci | 45 +++
.../usr/lib/scilab-financial/macros/lib | Bin 0 -> 1016 bytes
.../usr/lib/scilab-financial/macros/markowitz.bin | Bin 0 -> 19324 bytes
.../usr/lib/scilab-financial/macros/markowitz.sci | 107 +++++++
.../usr/lib/scilab-financial/macros/mef.bin | Bin 0 -> 3444 bytes
.../usr/lib/scilab-financial/macros/mef.sci | 27 ++
.../usr/lib/scilab-financial/macros/movav.bin | Bin 0 -> 3500 bytes
.../usr/lib/scilab-financial/macros/movav.sci | 28 ++
.../usr/lib/scilab-financial/macros/names | 22 ++
.../lib/scilab-financial/macros/nelson_siegel.bin | Bin 0 -> 7532 bytes
.../lib/scilab-financial/macros/nelson_siegel.sci | 56 ++++
.../usr/lib/scilab-financial/macros/svennson.bin | Bin 0 -> 7916 bytes
.../usr/lib/scilab-financial/macros/svennson.sci | 57 ++++
.../share/doc/scilab-financial/buildinfo_all.gz | Bin 0 -> 5391 bytes
.../share/doc/scilab-financial/changelog.Debian.gz | Bin 0 -> 168 bytes
.../usr/share/doc/scilab-financial/changelog.gz | Bin 0 -> 294 bytes
.../share/doc/scilab-financial/changelog.txt.gz | Bin 0 -> 294 bytes
.../usr/share/doc/scilab-financial/copyright | 20 ++
.../usr/share/doc/scilab-financial/license.txt | 7 +
.../usr/share/doc/scilab-financial/readme.txt | 73 +++++
.../usr/share/scilab/contrib/financial | 1 +
debian/source/format | 1 +
debian/watch | 4 +
demos/bsgreeks.sce | 30 ++
demos/financial.dem.gateway.sce | 7 +
etc/financial.start | 34 +++
help/builder_help.sce | 1 +
help/cleanhelp.sce | 11 +
help/en_US/0overview.xml | 129 +++++++++
help/en_US/backtest.xml | 68 +++++
help/en_US/bollinger.xml | 49 ++++
help/en_US/bsgreeks.xml | 106 +++++++
help/en_US/bsimpvol.xml | 92 ++++++
help/en_US/bsoption.xml | 79 +++++
help/en_US/build_help.sce | 1 +
help/en_US/cfr.xml | 85 ++++++
help/en_US/duration.xml | 68 +++++
help/en_US/esvarevt.xml | 99 +++++++
help/en_US/esvarlin.xml | 77 +++++
help/en_US/esvaroptim.xml | 105 +++++++
help/en_US/euler.xml | 80 +++++
help/en_US/evt.xml | 82 ++++++
help/en_US/gbm.xml | 63 ++++
help/en_US/hedge.xml | 61 ++++
help/en_US/hurst.xml | 58 ++++
help/en_US/interest.xml | 109 +++++++
help/en_US/irs.xml | 76 +++++
help/en_US/markowitz.xml | 91 ++++++
help/en_US/master_help.xml | 67 +++++
help/en_US/mef.xml | 47 +++
help/en_US/movav.xml | 52 ++++
help/en_US/nelson_siegel.xml | 96 ++++++
help/en_US/scilab_en_US_help/JavaHelpSearch/DOCS | Bin 0 -> 3603 bytes
.../scilab_en_US_help/JavaHelpSearch/DOCS.TAB | Bin 0 -> 683 bytes
.../en_US/scilab_en_US_help/JavaHelpSearch/OFFSETS | Bin 0 -> 96 bytes
.../scilab_en_US_help/JavaHelpSearch/POSITIONS | Bin 0 -> 16156 bytes
help/en_US/scilab_en_US_help/JavaHelpSearch/SCHEMA | 2 +
help/en_US/scilab_en_US_help/JavaHelpSearch/TMAP | Bin 0 -> 12288 bytes
help/en_US/scilab_en_US_help/ScilabEdit.png | Bin 0 -> 574 bytes
help/en_US/scilab_en_US_help/ScilabExecute.png | Bin 0 -> 660 bytes
help/en_US/scilab_en_US_help/backtest.html | 88 ++++++
help/en_US/scilab_en_US_help/bollinger.html | 73 +++++
help/en_US/scilab_en_US_help/bsgreeks.html | 112 +++++++
help/en_US/scilab_en_US_help/bsimpvol.html | 92 ++++++
help/en_US/scilab_en_US_help/bsoption.html | 87 ++++++
help/en_US/scilab_en_US_help/c_code.css | 54 ++++
help/en_US/scilab_en_US_help/cfr.html | 101 +++++++
help/en_US/scilab_en_US_help/duration.html | 86 ++++++
help/en_US/scilab_en_US_help/esvarevt.html | 103 +++++++
help/en_US/scilab_en_US_help/esvarlin.html | 89 ++++++
help/en_US/scilab_en_US_help/esvaroptim.html | 111 +++++++
help/en_US/scilab_en_US_help/euler.html | 94 ++++++
help/en_US/scilab_en_US_help/evt.html | 94 ++++++
.../scilab_en_US_help/financial_overview.html | 100 +++++++
help/en_US/scilab_en_US_help/gbm.html | 85 ++++++
help/en_US/scilab_en_US_help/hedge.html | 89 ++++++
help/en_US/scilab_en_US_help/hurst.html | 84 ++++++
help/en_US/scilab_en_US_help/index.html | 122 ++++++++
help/en_US/scilab_en_US_help/interest.html | 116 ++++++++
help/en_US/scilab_en_US_help/irs.html | 92 ++++++
help/en_US/scilab_en_US_help/jhelpidx.xml | 3 +
help/en_US/scilab_en_US_help/jhelpmap.jhm | 29 ++
help/en_US/scilab_en_US_help/jhelpset.hs | 28 ++
help/en_US/scilab_en_US_help/jhelptoc.xml | 31 ++
help/en_US/scilab_en_US_help/markowitz.html | 105 +++++++
help/en_US/scilab_en_US_help/mef.html | 75 +++++
help/en_US/scilab_en_US_help/movav.html | 78 +++++
help/en_US/scilab_en_US_help/nelson_siegel.html | 106 +++++++
help/en_US/scilab_en_US_help/scilab_code.css | 96 ++++++
.../section_4af098ac34d3d4ed2e545bfe2ad89215.html | 122 ++++++++
help/en_US/scilab_en_US_help/style.css | 305 ++++++++++++++++++++
help/en_US/scilab_en_US_help/svennson.html | 108 +++++++
help/en_US/scilab_en_US_help/xml_code.css | 94 ++++++
help/en_US/svennson.xml | 100 +++++++
help/en_US/update_help.sce | 233 +++++++++++++++
jar/scilab_en_US_help.jar | Bin 0 -> 75290 bytes
license.txt | 7 +
loader.sce | 10 +
macros/backtest.bin | Bin 0 -> 11100 bytes
macros/backtest.sci | 57 ++++
macros/bollinger.bin | Bin 0 -> 6432 bytes
macros/bollinger.sci | 36 +++
macros/bsgreeks.bin | Bin 0 -> 15180 bytes
macros/bsgreeks.sci | 62 ++++
macros/bsimpvol.bin | Bin 0 -> 5812 bytes
macros/bsimpvol.sci | 37 +++
macros/bsoption.bin | Bin 0 -> 4912 bytes
macros/bsoption.sci | 28 ++
macros/buildmacros.bat | 1 +
macros/buildmacros.sce | 1 +
macros/cfr.bin | Bin 0 -> 3664 bytes
macros/cfr.sci | 35 +++
macros/cleanmacros.bat | 3 +
macros/cleanmacros.sce | 16 +
macros/duration.bin | Bin 0 -> 5160 bytes
macros/duration.sci | 31 ++
macros/esvarevt.bin | Bin 0 -> 6732 bytes
macros/esvarevt.sci | 37 +++
macros/esvarlin.bin | Bin 0 -> 6984 bytes
macros/esvarlin.sci | 38 +++
macros/esvaroptim.bin | Bin 0 -> 22664 bytes
macros/esvaroptim.sci | 118 ++++++++
macros/euler.bin | Bin 0 -> 8436 bytes
macros/euler.sci | 45 +++
macros/evt.bin | Bin 0 -> 4508 bytes
macros/evt.sci | 30 ++
macros/gbm.bin | Bin 0 -> 6608 bytes
macros/gbm.sci | 40 +++
macros/hedge.bin | Bin 0 -> 8160 bytes
macros/hedge.sci | 49 ++++
macros/hurst.bin | Bin 0 -> 5940 bytes
macros/hurst.sci | 38 +++
macros/interest.bin | Bin 0 -> 15144 bytes
macros/interest.sci | 78 +++++
macros/irs.bin | Bin 0 -> 7756 bytes
macros/irs.sci | 45 +++
macros/lib | Bin 0 -> 1016 bytes
macros/markowitz.bin | Bin 0 -> 19324 bytes
macros/markowitz.sci | 107 +++++++
macros/mef.bin | Bin 0 -> 3444 bytes
macros/mef.sci | 27 ++
macros/movav.bin | Bin 0 -> 3500 bytes
macros/movav.sci | 28 ++
macros/names | 22 ++
macros/nelson_siegel.bin | Bin 0 -> 7532 bytes
macros/nelson_siegel.sci | 56 ++++
macros/svennson.bin | Bin 0 -> 7916 bytes
macros/svennson.sci | 57 ++++
readme.txt | 73 +++++
207 files changed, 8166 insertions(+)
diff --git a/builder.sce b/builder.sce
new file mode 100644
index 0000000..8642419
--- /dev/null
+++ b/builder.sce
@@ -0,0 +1,31 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+// Copyright (C) 2010 - DIGITEO - Michael Baudin
+mode(-1);
+lines(0);
+
+try
+ getversion("scilab");
+catch
+ error(gettext("Scilab 5.0 or more is required."));
+end;
+
+if ~with_module("development_tools") then
+ error(msprintf(gettext("%s module not installed."),"development_tools"));
+end
+
+// =============================================================================
+
+TOOLBOX_NAME = "financial";
+TOOLBOX_TITLE = "Financial module";
+
+// =============================================================================
+
+toolbox_dir = get_absolute_file_path("builder.sce");
+
+tbx_builder_macros(toolbox_dir);
+tbx_builder_help(toolbox_dir);
+tbx_build_loader(TOOLBOX_NAME, toolbox_dir);
+tbx_build_cleaner(TOOLBOX_NAME, toolbox_dir);
+
+
+clear toolbox_dir TOOLBOX_NAME TOOLBOX_TITLE;
diff --git a/changelog.txt b/changelog.txt
new file mode 100644
index 0000000..7024d5d
--- /dev/null
+++ b/changelog.txt
@@ -0,0 +1,16 @@
+changelog of the Financial Toolbox
+
+financial (not released yet)
+ * Import on the Forge.
+ * Restored the structure of the module from the ATOMS sources (etc, help).
+ * Added copyright notice into the macros.
+ * Updated TODOs.
+ * Created an overview as an xml page.
+ * Updated bsgreeks.sci to generate the help from the sci.
+ * Added the help\en_US\update_help.sce script to generate the help from sci.
+
+financial (v1: 2010-09-27)
+ * Initial version
+
+
+
diff --git a/cleaner.sce b/cleaner.sce
new file mode 100644
index 0000000..685f06e
--- /dev/null
+++ b/cleaner.sce
@@ -0,0 +1,34 @@
+// This file is released under the 3-clause BSD license. See COPYING-BSD.
+// Generated by builder.sce: Please, do not edit this file
+
+try
+ getversion("scilab");
+catch
+ error("Scilab 5.0 or more is required.");
+end
+function perform_clean()
+ root_tlbx = get_absolute_file_path('cleaner.sce');
+
+ if isfile(root_tlbx + '/macros/cleanmacros.sce') then
+ exec(root_tlbx+'/macros/cleanmacros.sce');
+ end
+
+ if isfile(root_tlbx + '/src/cleaner_src.sce') then
+ exec(root_tlbx+'/src/cleaner_src.sce');
+ end
+
+ if isfile(root_tlbx + "/sci_gateway/cleaner_gateway.sce") then
+ exec(root_tlbx + "/sci_gateway/cleaner_gateway.sce");
+ mdelete(root_tlbx + "/sci_gateway/cleaner_gateway.sce");
+ end
+
+ if isfile(root_tlbx + "/help/cleaner_help.sce") then
+ exec(root_tlbx + "/help/cleaner_help.sce");
+ end
+
+ if isfile(root_tlbx + "/loader.sce") then
+ mdelete(root_tlbx + "/loader.sce");
+ end
+endfunction
+perform_clean();
+clear perform_clean;
diff --git a/debian/changelog b/debian/changelog
new file mode 100644
index 0000000..3d65188
--- /dev/null
+++ b/debian/changelog
@@ -0,0 +1,5 @@
+scilab-financial (1.0.1-1) experimental; urgency=low
+
+ * Initial release (Closes: #700390)
+
+ -- Ruben Bibas <ruben.bibas+debian at gmail.com> Thu, 29 Aug 2013 13:51:55 +0100
diff --git a/debian/compat b/debian/compat
new file mode 100644
index 0000000..45a4fb7
--- /dev/null
+++ b/debian/compat
@@ -0,0 +1 @@
+8
diff --git a/debian/control b/debian/control
new file mode 100644
index 0000000..3dab3d6
--- /dev/null
+++ b/debian/control
@@ -0,0 +1,41 @@
+Source: scilab-financial
+Section: math
+Priority: optional
+Maintainer: Debian Science Team <debian-science-maintainers at lists.alioth.debian.org>
+Uploaders: Ruben Bibas <ruben.bibas+debian at gmail.com>
+Build-Depends: debhelper (>= 8.0.0), scilab (>= 5.0), scilab-doc, cdbs
+Standards-Version: 3.9.4
+Homepage: http://atoms.scilab.org/toolboxes/Financial
+Vcs-Svn: svn://svn.debian.org/svn/debian-science/packages/scilab-toolboxes/financial/trunk
+Vcs-Browser: http://svn.debian.org/viewsvn/debian-science/packages/scilab-toolboxes/financial/trunk
+
+Package: scilab-financial
+Architecture: all
+Depends: ${shlibs:Depends}, ${misc:Depends}, scilab (>= 5.0)
+Description: Library of financial computations functions based on Scilab
+ The module is dedicated to finance. There are three main areas that are
+ covered: (i) risk measure and management, (ii) asset allocation, and
+ (iii) pricing.
+ For what concerns the risk measure, some functions are dedicated to the
+ computation of Value at Risk (VaR) and Expected Shortfall (ES). Backtest is
+ also implemented in order to check the goodness of such risk measures. Both
+ VaR and ES are also computed in an Extreme Value Theory framework (EVT).
+ Furthermore, it is possible to estimate the parameters of the EVT density
+ function (through maximum likelihood). The Mean Excess Function for graphical
+ study of an EVT distribution is also implemented.
+ The interest rate risk is faced by functions aimed at computing duration,
+ convexity, and yield to maturity. Furthermore, Merton, Vasicek and Cox,
+ Ingersoll and Ross interest rate models are implemented together with the
+ estimation of their parameters. Parametric interpolation of the interest rate
+ curve is possible through both Svennson’s and Nelson-Siegel’s models.
+ Finally, some technical analysis indicators are implemented: Bollinger bands,
+ moving averages, Hurst index.
+ The asset allocation problem is faced by two functions which compute: (i) the
+ optimal portfolio minimizing the variance of its return and (ii) the optimal
+ portfolio minimizing the expected shortfall of its return. In both cases, the
+ portfolios with and without a riskless asset and with and without short selling
+ are computed.
+ Pricing problem is approached through functions aimed at: (i) computing the
+ spread on Interest Rate Swaps, (ii) computing the value of options in the Black
+ and Scholes framework (with Greeks and implied volatility), (iii) simulating
+ stochastic processes (through Euler discretization).
diff --git a/debian/copyright b/debian/copyright
new file mode 100644
index 0000000..2c057f3
--- /dev/null
+++ b/debian/copyright
@@ -0,0 +1,20 @@
+This package was debianized by Ruben Bibas <ruben.bibas+debian at gmail.com> on
+Mon Feb 11 19:00:52 CET 2013
+
+It was downloaded from http://atoms.scilab.org/toolboxes/Financial
+
+Upstream Authors:
+
+ Michael Baudin
+ Francesco Menoncin
+
+Copyright:
+
+ <Copyright (C) 2009 - 2010 - Francesco Menoncin>
+ <Copyright (C) 2010 - DIGITEO - Michael Baudin>
+
+License:
+
+ GPL (3.0)
+
+Please see /usr/share/common-licenses/GPL-3 for the full license.
diff --git a/debian/docs b/debian/docs
new file mode 100644
index 0000000..b127caf
--- /dev/null
+++ b/debian/docs
@@ -0,0 +1,3 @@
+changelog.txt
+license.txt
+readme.txt
diff --git a/debian/files b/debian/files
new file mode 100644
index 0000000..89208c3
--- /dev/null
+++ b/debian/files
@@ -0,0 +1 @@
+scilab-financial_1.0.1-1_all.deb math optional
diff --git a/debian/orig-tar.exclude b/debian/orig-tar.exclude
new file mode 100644
index 0000000..e69de29
diff --git a/debian/orig-tar.sh b/debian/orig-tar.sh
new file mode 100755
index 0000000..bef9992
--- /dev/null
+++ b/debian/orig-tar.sh
@@ -0,0 +1,20 @@
+#!/bin/sh -e
+
+# called by uscan with '--upstream-version' <version> <file>
+DIR=financial
+TAR=../scilab-financial_$2.orig.tar.bz2
+
+# clean up the upstream tarball
+tar zxvf $3
+find $DIR -type f -exec chmod -x {} \;
+tar -c -j -f $TAR -X debian/orig-tar.exclude $DIR
+rm -rf $DIR $3
+
+# move to directory 'tarballs'
+if [ -r .svn/deb-layout ]; then
+ . .svn/deb-layout
+ mv $TAR $origDir
+ echo "moved $TAR to $origDir"
+fi
+
+exit 0
diff --git a/debian/rules b/debian/rules
new file mode 100755
index 0000000..d34ab11
--- /dev/null
+++ b/debian/rules
@@ -0,0 +1,22 @@
+#!/usr/bin/make -f
+# Copyright 2013 Ruben Bibas <ruben.bibas+debian at gmail.com>
+
+include /usr/share/cdbs/1/rules/debhelper.mk
+
+build-indep:
+ DEB_MAKE_ENVVARS=SCI_DISABLE_TK=1 SCI_JAVA_ENABLE_HEADLESS=1 DOCBOOK_ROOT=/usr/share/sgml/docbook/stylesheet/xsl/nwalsh /usr/bin/scilab -nw -e "exec builder.sce;exit"
+
+clean::
+ rm -fr build-stamp help/*/scilab_*_help/ jar/
+
+install/scilab-financial::
+ mkdir -p $(CURDIR)/debian/scilab-financial/usr/lib/scilab-financial/
+
+ mkdir -p $(CURDIR)/debian/scilab-financial/usr/share/scilab/contrib/
+ cd $(CURDIR)/debian/scilab-financial/usr/share/scilab/contrib/; \
+ rm -f scilab-financial; \
+ ln -s ../../../lib/scilab-financial/ financial
+
+get-orig-source:
+ -uscan --upstream-version 0
+
diff --git a/debian/scilab-financial.debhelper.log b/debian/scilab-financial.debhelper.log
new file mode 100644
index 0000000..66bfaa2
--- /dev/null
+++ b/debian/scilab-financial.debhelper.log
@@ -0,0 +1,36 @@
+dh_prep
+dh_installdirs
+dh_installdirs
+dh_installdocs
+dh_installexamples
+dh_installman
+dh_installinfo
+dh_installmenu
+dh_installcron
+dh_installinit
+dh_installdebconf
+dh_installemacsen
+dh_installcatalogs
+dh_installpam
+dh_installlogrotate
+dh_installlogcheck
+dh_installchangelogs
+dh_installudev
+dh_lintian
+dh_bugfiles
+dh_install
+dh_link
+dh_buildinfo
+dh_installmime
+dh_installgsettings
+dh_strip
+dh_compress
+dh_fixperms
+dh_makeshlibs
+dh_installdeb
+dh_perl
+dh_shlibdeps
+dh_gencontrol
+dh_md5sums
+dh_builddeb
+dh_builddeb
diff --git a/debian/scilab-financial.install b/debian/scilab-financial.install
new file mode 100644
index 0000000..a78da1f
--- /dev/null
+++ b/debian/scilab-financial.install
@@ -0,0 +1,5 @@
+demos/ usr/lib/scilab-financial
+etc/ usr/lib/scilab-financial
+macros/ usr/lib/scilab-financial
+loader.sce usr/lib/scilab-financial
+jar/ usr/lib/scilab-financial
diff --git a/debian/scilab-financial.substvars b/debian/scilab-financial.substvars
new file mode 100644
index 0000000..abd3ebe
--- /dev/null
+++ b/debian/scilab-financial.substvars
@@ -0,0 +1 @@
+misc:Depends=
diff --git a/debian/scilab-financial/DEBIAN/control b/debian/scilab-financial/DEBIAN/control
new file mode 100644
index 0000000..696cc03
--- /dev/null
+++ b/debian/scilab-financial/DEBIAN/control
@@ -0,0 +1,36 @@
+Package: scilab-financial
+Version: 1.0.1-1
+Architecture: all
+Maintainer: Debian Science Team <debian-science-maintainers at lists.alioth.debian.org>
+Installed-Size: 365
+Depends: scilab (>= 5.0)
+Section: math
+Priority: optional
+Homepage: http://atoms.scilab.org/toolboxes/Financial
+Description: Library of financial computations functions based on Scilab
+ The module is dedicated to finance. There are three main areas that are
+ covered: (i) risk measure and management, (ii) asset allocation, and
+ (iii) pricing.
+ For what concerns the risk measure, some functions are dedicated to the
+ computation of Value at Risk (VaR) and Expected Shortfall (ES). Backtest is
+ also implemented in order to check the goodness of such risk measures. Both
+ VaR and ES are also computed in an Extreme Value Theory framework (EVT).
+ Furthermore, it is possible to estimate the parameters of the EVT density
+ function (through maximum likelihood). The Mean Excess Function for graphical
+ study of an EVT distribution is also implemented.
+ The interest rate risk is faced by functions aimed at computing duration,
+ convexity, and yield to maturity. Furthermore, Merton, Vasicek and Cox,
+ Ingersoll and Ross interest rate models are implemented together with the
+ estimation of their parameters. Parametric interpolation of the interest rate
+ curve is possible through both Svennson’s and Nelson-Siegel’s models.
+ Finally, some technical analysis indicators are implemented: Bollinger bands,
+ moving averages, Hurst index.
+ The asset allocation problem is faced by two functions which compute: (i) the
+ optimal portfolio minimizing the variance of its return and (ii) the optimal
+ portfolio minimizing the expected shortfall of its return. In both cases, the
+ portfolios with and without a riskless asset and with and without short selling
+ are computed.
+ Pricing problem is approached through functions aimed at: (i) computing the
+ spread on Interest Rate Swaps, (ii) computing the value of options in the Black
+ and Scholes framework (with Greeks and implied volatility), (iii) simulating
+ stochastic processes (through Euler discretization).
diff --git a/debian/scilab-financial/DEBIAN/md5sums b/debian/scilab-financial/DEBIAN/md5sums
new file mode 100644
index 0000000..7085118
--- /dev/null
+++ b/debian/scilab-financial/DEBIAN/md5sums
@@ -0,0 +1,63 @@
+6bd377574bf0412dc2fbc98fbe636672 usr/lib/scilab-financial/demos/bsgreeks.sce
+d32eacd18ded210948819ba8793ae98d usr/lib/scilab-financial/demos/financial.dem.gateway.sce
+d41d8cd98f00b204e9800998ecf8427e usr/lib/scilab-financial/etc/financial.quit
+0edffb7a2a2f9b443c14de92589cad22 usr/lib/scilab-financial/etc/financial.start
+c3e9663bcf859aaf1333e44d7be48aca usr/lib/scilab-financial/jar/scilab_en_US_help.jar
+44841c85551cc76ebadfa106f55983f2 usr/lib/scilab-financial/loader.sce
+e62c5fce3a9e736a01a6dcac2b0d0300 usr/lib/scilab-financial/macros/backtest.bin
+093f1db6ab2d2b9dbd4313e3f8ebbde3 usr/lib/scilab-financial/macros/backtest.sci
+04f06aee69984f5b64744a6a6467b0f8 usr/lib/scilab-financial/macros/bollinger.bin
+f358aa8a1d01d7bcd6c415eb3b7fae11 usr/lib/scilab-financial/macros/bollinger.sci
+ab389860784c9ee50d57281a3b6a446a usr/lib/scilab-financial/macros/bsgreeks.bin
+e5dc57049d225203de2a0bb6720aad01 usr/lib/scilab-financial/macros/bsgreeks.sci
+6b8307ade308e299db2e2ac653f4f968 usr/lib/scilab-financial/macros/bsimpvol.bin
+889be50a5a88b368f7ffd05497ceb2f4 usr/lib/scilab-financial/macros/bsimpvol.sci
+7d9a02c730c198574d0ce8d553983721 usr/lib/scilab-financial/macros/bsoption.bin
+b49b84b5969e05594a14b732d84d63e4 usr/lib/scilab-financial/macros/bsoption.sci
+e9090e94dc22d78b86ed4638aeba081c usr/lib/scilab-financial/macros/buildmacros.bat
+2264f397ea7f6e36a2020c203e38ed83 usr/lib/scilab-financial/macros/buildmacros.sce
+7d05923229f5c3dae317724576e7df0b usr/lib/scilab-financial/macros/cfr.bin
+0c591e3ff701bbe2ac44751cbfaee8af usr/lib/scilab-financial/macros/cfr.sci
+ecd5375bddbab1f56c80ddbddbf223c7 usr/lib/scilab-financial/macros/cleanmacros.bat
+1efb1f274aa403d018a4c5ffbd468324 usr/lib/scilab-financial/macros/cleanmacros.sce
+35c85de648f5b775d9b2b0a7e4c59cd2 usr/lib/scilab-financial/macros/duration.bin
+205c7cfc2ca988727d52ba3393c503bd usr/lib/scilab-financial/macros/duration.sci
+4f68fe4845ef9ad0d1c16468978d61f8 usr/lib/scilab-financial/macros/esvarevt.bin
+b03fc1614afe230d4081df8aa5c8799e usr/lib/scilab-financial/macros/esvarevt.sci
+fc81d8faa3d733784d927ef595d0b42f usr/lib/scilab-financial/macros/esvarlin.bin
+00fe777f462a25a2d5d11df34417f919 usr/lib/scilab-financial/macros/esvarlin.sci
+0e76cd9afcfa2bef6235301a036a047d usr/lib/scilab-financial/macros/esvaroptim.bin
+bcd75491832f867ccac2c777f71d90ec usr/lib/scilab-financial/macros/esvaroptim.sci
+43c05c8504270b8cb59c289484423d3e usr/lib/scilab-financial/macros/euler.bin
+30e8eb9325e317b5749e658b20d12331 usr/lib/scilab-financial/macros/euler.sci
+e5ac2b7be5d41fec7c79b976208f6a4a usr/lib/scilab-financial/macros/evt.bin
+1d3c11ade0baf66ffe5b4728e7b845b7 usr/lib/scilab-financial/macros/evt.sci
+c360f5ac292862ccf49c848b606de89f usr/lib/scilab-financial/macros/gbm.bin
+b2a86f4fd742ba7d13869fdc9ecb98f6 usr/lib/scilab-financial/macros/gbm.sci
+d487b4d64d43212ae9a6de4b5bdb9fe1 usr/lib/scilab-financial/macros/hedge.bin
+55987e485f1dd3f9a06fc5c372d944c3 usr/lib/scilab-financial/macros/hedge.sci
+c6c6a423cafaa2c3530d693e569c9718 usr/lib/scilab-financial/macros/hurst.bin
+fe25685fe8a0a56f991875751e31da87 usr/lib/scilab-financial/macros/hurst.sci
+174a942905b5d1b3dcb10e39c9a5450e usr/lib/scilab-financial/macros/interest.bin
+e3046d9e81543907802dc361dad95dd1 usr/lib/scilab-financial/macros/interest.sci
+888e2dc42cae6a028713e8a641943894 usr/lib/scilab-financial/macros/irs.bin
+118d16a2350c612d3f6078ccea9c9f5d usr/lib/scilab-financial/macros/irs.sci
+94b2d0a2bd760eb3754f9bae7398e5ff usr/lib/scilab-financial/macros/lib
+b359340e67f1a40356c55173eeb7fe0c usr/lib/scilab-financial/macros/markowitz.bin
+39b2d80b735c53d389e8c6ee683f56aa usr/lib/scilab-financial/macros/markowitz.sci
+b9d8a9a021cc3b15c31d22931ad68be0 usr/lib/scilab-financial/macros/mef.bin
+98b989ab212dd650e424bb1996eb40e1 usr/lib/scilab-financial/macros/mef.sci
+ff41309f0cea799531fb0c95087d5cb8 usr/lib/scilab-financial/macros/movav.bin
+867492978d7a222225250a26887acc83 usr/lib/scilab-financial/macros/movav.sci
+19eea50c01f54f1361214e3dd602aef1 usr/lib/scilab-financial/macros/names
+df01755d6235cba94b6dc49e4a8bf566 usr/lib/scilab-financial/macros/nelson_siegel.bin
+71f10e6a1904d8ea5ca0f97e2a3e3ce5 usr/lib/scilab-financial/macros/nelson_siegel.sci
+fe7943b4034230cc200390e9037a5cc8 usr/lib/scilab-financial/macros/svennson.bin
+54858c4cf276c08832ae136adf456d94 usr/lib/scilab-financial/macros/svennson.sci
+c533c55834761db33e16f4653a807ce5 usr/share/doc/scilab-financial/buildinfo_all.gz
+6f038cd3f9c14b35c8586b7d07b46af8 usr/share/doc/scilab-financial/changelog.Debian.gz
+c6664c05b9962b9c88975cb2f98d42d7 usr/share/doc/scilab-financial/changelog.gz
+c6664c05b9962b9c88975cb2f98d42d7 usr/share/doc/scilab-financial/changelog.txt.gz
+53a7e2c2701dffca178b565af708b1bb usr/share/doc/scilab-financial/copyright
+820631ab3f9faf72bc3c296a0bc45e4c usr/share/doc/scilab-financial/license.txt
+43d4a3a4cc5c5ca8a4ec1f046e24263d usr/share/doc/scilab-financial/readme.txt
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/demos/bsgreeks.sce b/debian/scilab-financial/usr/lib/scilab-financial/demos/bsgreeks.sce
new file mode 100644
index 0000000..7d484b6
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/demos/bsgreeks.sce
@@ -0,0 +1,30 @@
+//
+// This help file was automatically generated from bsgreeks.sci using help_from_sci().
+// PLEASE DO NOT EDIT
+//
+mode(1)
+//
+// Demo of bsgreeks.sci
+//
+
+// We compute the Greeks on both a call and put option
+// with: underlying price 25 euros,
+// strike price 25 euros,
+// 0.01 (annual) riskless interest rate,
+// 3 month time to maturity (i.e. T=3/12),
+// and 0.2 (annual) volatility.
+[D,G,Th,R,V]=bsgreeks(25,25,0.01,3/12,0.2)
+V = 4.9727729;
+R = [3.0550246;-3.1793699];
+T = [2.1113101;1.8619344];
+G = 4.9727729;
+D = [0.5298926;-0.4701074];
+halt() // Press return to continue
+
+//========= E N D === O F === D E M O =========//
+//
+// Load this script into the editor
+//
+filename = "bsgreeks.sce";
+dname = get_absolute_file_path(filename);
+editor ( fullfile(dname,filename) );
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/demos/financial.dem.gateway.sce b/debian/scilab-financial/usr/lib/scilab-financial/demos/financial.dem.gateway.sce
new file mode 100644
index 0000000..95485de
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/demos/financial.dem.gateway.sce
@@ -0,0 +1,7 @@
+// This help file was automatically generated using helpupdate
+// PLEASE DO NOT EDIT
+demopath = get_absolute_file_path("financial.dem.gateway.sce");
+subdemolist = [
+"bsgreeks", "bsgreeks.sce"; ..
+];
+subdemolist(:,2) = demopath + subdemolist(:,2)
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/etc/financial.quit b/debian/scilab-financial/usr/lib/scilab-financial/etc/financial.quit
new file mode 100644
index 0000000..e69de29
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/etc/financial.start b/debian/scilab-financial/usr/lib/scilab-financial/etc/financial.start
new file mode 100644
index 0000000..a0f523d
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/etc/financial.start
@@ -0,0 +1,34 @@
+mprintf("Start Financial module\n");
+
+if isdef("financiallib") then
+ warning("Financial module library is already loaded");
+ return;
+end
+
+etc_tlbx = get_absolute_file_path("financial.start");
+etc_tlbx = getshortpathname(etc_tlbx);
+root_tlbx = strncpy( etc_tlbx, length(etc_tlbx)-length("\etc\") );
+
+//Load functions library
+// =============================================================================
+
+mprintf("\tLoad macros\n");
+pathmacros = pathconvert( root_tlbx ) + "macros" + filesep();
+financiallib = lib(pathmacros);
+clear pathmacros;
+
+// Load and add help chapter
+// =============================================================================
+
+if or(getscilabmode() == ["NW";"STD"]) then
+ mprintf("\tLoad help\n");
+ path_addchapter = pathconvert(root_tlbx+"/jar");
+ if ( isdir(path_addchapter) <> [] ) then
+ add_help_chapter("Financial module", path_addchapter, %F);
+ clear add_help_chapter;
+ end
+ clear path_addchapter;
+end
+
+clear root_tlbx;
+clear etc_tlbx;
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/jar/scilab_en_US_help.jar b/debian/scilab-financial/usr/lib/scilab-financial/jar/scilab_en_US_help.jar
new file mode 100644
index 0000000..f336e81
Binary files /dev/null and b/debian/scilab-financial/usr/lib/scilab-financial/jar/scilab_en_US_help.jar differ
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/loader.sce b/debian/scilab-financial/usr/lib/scilab-financial/loader.sce
new file mode 100644
index 0000000..00aa08a
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/loader.sce
@@ -0,0 +1,10 @@
+// This file is released under the 3-clause BSD license. See COPYING-BSD.
+// Generated by builder.sce: Please, do not edit this file
+
+try
+ getversion("scilab");
+catch
+ error("Scilab 5.0 or more is required.");
+end;
+
+exec(get_absolute_file_path("loader.sce")+"etc/"+"financial.start");
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/backtest.bin b/debian/scilab-financial/usr/lib/scilab-financial/macros/backtest.bin
new file mode 100644
index 0000000..2ecba51
Binary files /dev/null and b/debian/scilab-financial/usr/lib/scilab-financial/macros/backtest.bin differ
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/backtest.sci b/debian/scilab-financial/usr/lib/scilab-financial/macros/backtest.sci
new file mode 100644
index 0000000..5b9c564
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/macros/backtest.sci
@@ -0,0 +1,57 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function backtest(price,alpha,varargin);
+
+// PURPOSE: Apply the backtest to three different
+// risk measures (as percentage of lost):
+// Expected Shortfall, Value at Risk,
+// and a Spectral Measure with linear spectrum.
+// Finally, show the graph of historical returns and
+// the risk measures.
+// The thresholds of the backtest are also computed
+//--------------------------------------------------------------
+// INPUT:
+// * price = matrix whose columns contain the historical
+// prices of each asset
+// * alpha = confidence level of risk measures
+// * N = (optional input) number of observations which
+// the backtest is computed on (default value 250
+// if there are more than 500 historical prices,
+// else N is half the size of "price")
+// -------------------------------------------------------------
+// OUTPUT:
+// Compute the exceptions of three risk sources and show
+// them graphically
+// -------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ if size(varargin)==1 then
+ N=varargin(1);
+ else
+ if size(price,1)>=500 then
+ N=250;
+ else
+ N=floor(size(price,1)/2);
+ end
+ end
+ for i=1:N
+ [ES(i),VaR(i),M(i)]=esvarlin(price($-2*N+i:$-(N+1)+i),alpha);
+ end;
+ y=diff(price,1,1)./price(1:$-1,:);
+ exeptions=[sum(bool2s(y($-(N-1):$)<=-ES)) sum(bool2s(y($-(N-1):$)<=-VaR)) sum(bool2s(y($-(N-1):$)<=-M))];
+ z1=find(cumsum(binomial(alpha,N))>=0.95);
+ z1=z1(1)-1;
+ z2=find(cumsum(binomial(alpha,N))>=0.9999);
+ z2=z2(1)-1;
+ disp(['Green zone:' '0-'+string(z1);
+ 'Yellow zone:' string(z1)+'-'+string(z2);
+ 'Red zone:' string(z2)+'-']);
+ disp(['ES: ' string(exeptions(1))+' exeptions';
+ 'VaR: ' string(exeptions(2))+' exeptions';
+ 'Linear Spectrum: ' string(exeptions(3))+' exeptions']);
+ plot([y($-(N-1):$) -ES -VaR -M]);
+ legend(['Historical returns','ES','VaR','Linear Spectrum'],2);
+endfunction
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/bollinger.bin b/debian/scilab-financial/usr/lib/scilab-financial/macros/bollinger.bin
new file mode 100644
index 0000000..2f495b7
Binary files /dev/null and b/debian/scilab-financial/usr/lib/scilab-financial/macros/bollinger.bin differ
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/bollinger.sci b/debian/scilab-financial/usr/lib/scilab-financial/macros/bollinger.sci
new file mode 100644
index 0000000..93e9418
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/macros/bollinger.sci
@@ -0,0 +1,36 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function bollinger(S,m,a)
+
+// PURPOSE: On historical data "S", draw both the moving
+// average of length "m" and the Bollinger bands
+// of width "a". Also draw the percentage b.
+//---------------------------------------------------------
+// INPUT:
+// * S = historical data
+// * m = moving average length
+// * a = width of the Bollinger bands
+// -------------------------------------------------------------
+// OUTPUT:
+//
+// -------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ for k=size(S,1):-1:m
+ M(k,1)=mean(S(k-m+1:k));
+ V(k,1)=sqrt(variance(S(k-m+1:k)));
+ end
+ M(1:m-1)=%nan;
+ subplot(2,1,1);
+ plot(S); plot(M,'green'); plot([M+a*V,M-a*V],'--red');
+ title('Moving average and Bollinger bands');
+ b(1:m-1,1)=%nan;
+ b=[b;(S(m:$)-(M(m:$)-a*V(m:$)))./(2*a*V(m:$))];
+ subplot(2,1,2);
+ plot(b);
+ plot([zeros(size(S,1),1), ones(size(S,1),1)],'--red');
+ title('Percentage b');
+endfunction
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/bsgreeks.bin b/debian/scilab-financial/usr/lib/scilab-financial/macros/bsgreeks.bin
new file mode 100644
index 0000000..4a64297
Binary files /dev/null and b/debian/scilab-financial/usr/lib/scilab-financial/macros/bsgreeks.bin differ
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/bsgreeks.sci b/debian/scilab-financial/usr/lib/scilab-financial/macros/bsgreeks.sci
new file mode 100644
index 0000000..b285c58
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/macros/bsgreeks.sci
@@ -0,0 +1,62 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+// Copyright (C) 2010 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [delta,gama,theta,rho,vega]=bsgreeks(S,K,r,T,sigma)
+ // Compute the Greeks for both a call and a put option in a Black and Scholes model.
+ //
+ // Calling Sequence
+ // [delta,gama,theta,rho,vega]=bsgreeks(S,K,r,T,sigma)
+ //
+ // Parameters
+ // S : a 1-by-1 matrix of doubles, current price of the underlying asset
+ // K : a 1-by-1 matrix of doubles, strike price of the option
+ // r : a 1-by-1 matrix of doubles, riskless interest rate (assumed to be constant until the maturity)
+ // T : a 1-by-1 matrix of doubles, time to maturity; it must be in the same time unit of measure as the riskless interest rate (if the riskless interest rate is annual, then an option with maturity of 3 months must have T=3/12)
+ // sigma : a 1-by-1 matrix of doubles, volatility of the underlying (log-) returns; it must be in the same time unit of measure as the riskless interest rate
+ // delta : a 2-by-1 matrix of doubles, the first derivative of the call (first term) and put (second term) option prices with respect to the underlying asset price
+ // gama : a 1-by-1 matrix of doubles, second derivative of the call (or put) option price with respect to the underlying asset price
+ // theta : a 2-by-1 matrix of doubles, vector containing the first derivative of the call (first term) and put (second term) option prices with respect to the time to maturity
+ // rho : a 2-by-1 matrix of doubles, vector containing the first derivative of the call (first term) and put (second term) option prices with respect to the riskless interest rate
+ // vega : a 1-by-1 matrix of doubles, first derivative of the call (or put) option price with respect to the standard deviation of the underlying (log-) returns
+ //
+ // Description
+ // Computes the Greeks of both call and put option in a Black and Scholes framework
+ //
+ // Examples
+ // // We compute the Greeks on both a call and put option
+ // // with: underlying price 25 euros,
+ // // strike price 25 euros,
+ // // 0.01 (annual) riskless interest rate,
+ // // 3 month time to maturity (i.e. T=3/12),
+ // // and 0.2 (annual) volatility.
+ // [D,G,Th,R,V]=bsgreeks(25,25,0.01,3/12,0.2)
+ // V = 4.9727729;
+ // R = [3.0550246;-3.1793699];
+ // T = [2.1113101;1.8619344];
+ // G = 4.9727729;
+ // D = [0.5298926;-0.4701074];
+ //
+ // Authors
+ // Copyright (C) 2009 - 2010 - Francesco Menoncin
+ // Copyright (C) 2010 - DIGITEO - Michael Baudin
+ //
+ // Bibliography
+ // TODO
+ //
+ // See also
+ // bsoption
+ // bsimpvol
+
+ d1=-((log(K/S)-(r+1/2*sigma^2)*T)/(sigma*sqrt(T)))
+ d2=-((log(K/S)-(r-1/2*sigma^2)*T)/(sigma*sqrt(T)))
+ delta=[cdfnor('PQ',d1,0,1);-cdfnor('PQ',-d1,0,1)]
+ gama=S*sqrt(T)*exp(-d1^2/2)/sqrt(2*%pi)
+ theta=[K*exp(-r*T)*(r*cdfnor('PQ',d2,0,1)+sigma*exp(-d2^2/2)/sqrt(2*%pi)/(2*sqrt(T)));...
+ K*exp(-r*T)*(-r*cdfnor('PQ',-d2,0,1)+sigma*exp(-d2^2/2)/sqrt(2*%pi)/(2*sqrt(T)))]
+ rho=[T*K*exp(-r*T)*cdfnor('PQ',d2,0,1);-T*K*exp(-r*T)*cdfnor('PQ',-d2,0,1)]
+ vega=S*sqrt(T)*exp(-d1^2/2)/sqrt(2*%pi)
+endfunction
+
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/bsimpvol.bin b/debian/scilab-financial/usr/lib/scilab-financial/macros/bsimpvol.bin
new file mode 100644
index 0000000..c9f44cb
Binary files /dev/null and b/debian/scilab-financial/usr/lib/scilab-financial/macros/bsimpvol.bin differ
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/bsimpvol.sci b/debian/scilab-financial/usr/lib/scilab-financial/macros/bsimpvol.sci
new file mode 100644
index 0000000..905ade5
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/macros/bsimpvol.sci
@@ -0,0 +1,37 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [sigmaC,sigmaP]=bsimpvol(option,S,K,r,T,sigma0);
+
+// PURPOSE: Compute the implicit volatility for the Black and Scholes
+// model when the price of an option is known, for both
+// call option and put option
+//------------------------------------------------------------------
+// INPUT:
+// * option = option price
+// * S = price of the underlying asset
+// * K = strike price
+// * r = riskless interest rate
+// * T = time to maturity
+// * sigma0 = starting guess value for the iterations
+// -----------------------------------------------------------------
+// OUTPUT:
+// * sigmaC = implied volatility of a call option
+// * sigmaP = implied volatility of a put option
+// -----------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ function [Y]=difference(s);
+ d1=-((log(K/S)-(r+1/2*s^2)*T)/(s*sqrt(T)));
+ d2=-((log(K/S)-(r-1/2*s^2)*T)/(s*sqrt(T)));
+ Y=segno*S*cdfnor('PQ',segno*d1,0,1)-segno*K*exp(-r*T)*cdfnor('PQ',segno*d2,0,1)-option;
+ endfunction
+ segno=1;
+ [sigmaC,d,inf]=fsolve(sigma0,difference);
+ if inf==1 then disp('Call: good convergence'); else disp('Call: bad convergence'); end
+ segno=-1;
+ [sigmaP,d,inf]=fsolve(sigma0,difference);
+ if inf==1 then disp('Put: good convergence'); else disp('Put: bad convergence'); end
+endfunction
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/bsoption.bin b/debian/scilab-financial/usr/lib/scilab-financial/macros/bsoption.bin
new file mode 100644
index 0000000..62867a7
Binary files /dev/null and b/debian/scilab-financial/usr/lib/scilab-financial/macros/bsoption.bin differ
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/bsoption.sci b/debian/scilab-financial/usr/lib/scilab-financial/macros/bsoption.sci
new file mode 100644
index 0000000..678bf6c
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/macros/bsoption.sci
@@ -0,0 +1,28 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [C,P]=bsoption(S,K,r,T,sigma);
+
+// PURPOSE: Compute the value of both call and put options
+// with the Black and Scholes formula
+//------------------------------------------------------------------
+// INPUT:
+// * S = price of the underlying asset
+// * K = strike price
+// * r = riskless interest rate
+// * T = time to maturity
+// * sigma = diffusion of the underlying asset return
+// -----------------------------------------------------------------
+// OUTPUT:
+// * C = value of the call option
+// * P = value of the put option
+// -----------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ d1=-((log(K/S)-(r+1/2*sigma^2)*T)/(sigma*sqrt(T)));
+ d2=-((log(K/S)-(r-1/2*sigma^2)*T)/(sigma*sqrt(T)));
+ C=S*cdfnor('PQ',d1,0,1)-K*exp(-r*T)*cdfnor('PQ',d2,0,1);
+ P=C+K*exp(-r*T)-S;
+endfunction
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/buildmacros.bat b/debian/scilab-financial/usr/lib/scilab-financial/macros/buildmacros.bat
new file mode 100644
index 0000000..f6f1b04
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/macros/buildmacros.bat
@@ -0,0 +1 @@
+ at scilex -nwni -e exec("buildmacros.sce");quit;
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/buildmacros.sce b/debian/scilab-financial/usr/lib/scilab-financial/macros/buildmacros.sce
new file mode 100644
index 0000000..ceac364
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/macros/buildmacros.sce
@@ -0,0 +1 @@
+tbx_build_macros("financial", get_absolute_file_path("buildmacros.sce"));
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/cfr.bin b/debian/scilab-financial/usr/lib/scilab-financial/macros/cfr.bin
new file mode 100644
index 0000000..c7d96f4
Binary files /dev/null and b/debian/scilab-financial/usr/lib/scilab-financial/macros/cfr.bin differ
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/cfr.sci b/debian/scilab-financial/usr/lib/scilab-financial/macros/cfr.sci
new file mode 100644
index 0000000..cc8ede5
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/macros/cfr.sci
@@ -0,0 +1,35 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [S]=cfr(varargin);
+
+// PURPOSE: Compare two or more time series and eliminate
+// the data whose date is not in all the series
+//---------------------------------------------------------
+// INPUT:
+// As many two-clumn matrix as time series. The first column
+// of any matrix must contain the dates, the second column
+// must contain the data
+// -------------------------------------------------------------
+// OUTPUT:
+// * S = a matrix containing the dates in the first clumn and
+// the times series in all the other columns
+// -------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+function [z]=cfr2(x,y);
+z=[];
+for i=1:size(x,1)
+ [r,c]=find(y==x(i,1));
+ if r<>[] then z=[z; x(i,:), y(r,2)]; else end;
+end
+endfunction
+
+S=varargin(1);
+for k=2:size(varargin)
+ S=cfr2(S,varargin(k));
+end;
+
+endfunction
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/cleanmacros.bat b/debian/scilab-financial/usr/lib/scilab-financial/macros/cleanmacros.bat
new file mode 100644
index 0000000..fe30bc9
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/macros/cleanmacros.bat
@@ -0,0 +1,3 @@
+ at rm *.bin
+ at rm lib
+ at rm names
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/cleanmacros.sce b/debian/scilab-financial/usr/lib/scilab-financial/macros/cleanmacros.sce
new file mode 100644
index 0000000..07c6bbe
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/macros/cleanmacros.sce
@@ -0,0 +1,16 @@
+// ====================================================================
+// Allan CORNET
+// DIGITEO 2009
+// This file is released into the public domain
+// ====================================================================
+libpath = get_absolute_file_path('cleanmacros.sce');
+
+binfiles = ls(libpath+'/*.bin');
+for i = 1:size(binfiles,'*')
+ mdelete(binfiles(i));
+end
+
+mdelete(libpath+'/names');
+mdelete(libpath+'/lib');
+
+// ====================================================================
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/duration.bin b/debian/scilab-financial/usr/lib/scilab-financial/macros/duration.bin
new file mode 100644
index 0000000..3739a20
Binary files /dev/null and b/debian/scilab-financial/usr/lib/scilab-financial/macros/duration.bin differ
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/duration.sci b/debian/scilab-financial/usr/lib/scilab-financial/macros/duration.sci
new file mode 100644
index 0000000..c226f39
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/macros/duration.sci
@@ -0,0 +1,31 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [dur,con,ytm]=duration(t,c);
+
+// PURPOSE: Compute "Duration", "Convexity" and "Yield to Maturity"
+// for an asset paying a stream of cash flows
+//--------------------------------------------------------------
+// INPUT:
+// * t = column vector of times where flows are paid
+// (the first value must be zero)
+// * c = column vector of cash flows (the first negative
+// cash flow must be the price of the asset)
+// -------------------------------------------------------------
+// OUTPUT:
+// * dur = duration of the asset
+// * con = convexity of the asset
+// * ytm = yield to maturity
+//
+// Cash flows are discounted with the Yield to Maturity
+// -------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ deff('[van]=van(r)','van=c''*(1+r)^(-t)');
+ [ytm,f,inf]=fsolve(0,van);
+ if inf<>1 then disp('Bad convergence'); else end
+ dur=c(2:$)'*((1+ytm)^(-t(2:$)).*t(2:$))/(-c(1));
+ con=c(2:$)'*((1+ytm)^(-t(2:$)).*(t(2:$).^2))/(-c(1));
+endfunction
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/esvarevt.bin b/debian/scilab-financial/usr/lib/scilab-financial/macros/esvarevt.bin
new file mode 100644
index 0000000..b1b8061
Binary files /dev/null and b/debian/scilab-financial/usr/lib/scilab-financial/macros/esvarevt.bin differ
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/esvarevt.sci b/debian/scilab-financial/usr/lib/scilab-financial/macros/esvarevt.sci
new file mode 100644
index 0000000..c4b759b
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/macros/esvarevt.sci
@@ -0,0 +1,37 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [es,var,xoptim,v,inf]=esvarevt(x0,data,u,alpha)
+
+// PURPOSE: Estimate the parameters ("xi" and "beta") of a
+// Generalized Pareto Density f(x) with Maximum Likelihood
+// and compute both VaR and Expected Shortfall
+//
+// f(x) = (1+xi*(x-u)/beta)^(-1/xi-1)/beta
+//------------------------------------------------------------------
+// INPUT:
+// * x0 = starting values for the parameters "xi" and "beta"
+// * data = historical data
+// * u = threshold parameter
+// * alpha = confidence level fot the risk measures
+// -----------------------------------------------------------------
+// OUTPUT:
+// * var = Value at Risk (at "alpha" confidence level)
+// * es = Expected Shortfall (at "alpha" confidence level)
+// * xoptim = maximum likelihood value of the parameters
+// "xi" and "beta"
+// * v = same value as "v" in the "fsolve" function
+// * inf = same values as "inf" in the "fsolve" function
+// -----------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ x=data(data>u);
+ deff('[y]=eq(z)','y=[1/z(1)/z(2)-(1/z(1)+1)/z(2)*mean((1+z(1)*(x-u)/z(2))^(-1));...
+ -(1/z(1)+1)/z(1)+1/z(1)^2*mean(log(1+z(1)*(x-u)/z(2)))+(1/z(1)+1)/z(1)*mean((1+z(1)*(x-u)/z(2))^(-1))]');
+ [xoptim,v,inf]=fsolve(x0,eq);
+ N=size(data,1); Nu=size(x,1);
+ var=u+xoptim(2)/xoptim(1)*((N*alpha/Nu)^(-xoptim(1))-1);
+ es=(var+xoptim(2)-u*xoptim(1))/(1-xoptim(1));
+endfunction
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/esvarlin.bin b/debian/scilab-financial/usr/lib/scilab-financial/macros/esvarlin.bin
new file mode 100644
index 0000000..aa4e754
Binary files /dev/null and b/debian/scilab-financial/usr/lib/scilab-financial/macros/esvarlin.bin differ
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/esvarlin.sci b/debian/scilab-financial/usr/lib/scilab-financial/macros/esvarlin.sci
new file mode 100644
index 0000000..6fa0249
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/macros/esvarlin.sci
@@ -0,0 +1,38 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [ES,VaR,M]=esvarlin(price,alpha);
+
+// PURPOSE: With historical simulation, computes three
+// risk measures (as percentage of loss):
+// Expected Shortfall, Value at Risk,
+// and a Spectral Measure with linear spectrum
+//--------------------------------------------------------------
+// INPUT:
+// * price = matrix whose columns contain the historical
+// prices of each asset
+// * alpha = confidence level of risk measures;
+// it can be a vector for simlutaneously computing
+// the risk meausures at different confidence levels
+// -------------------------------------------------------------
+// OUTPUT:
+// * ES = Expected Shortfall
+// * VaR = Value at Risk
+// * M = Linear Spectral Risk Measure
+// -------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ y=diff(price,1,1)./price(1:$-1,:);
+ y=gsort(y,'r','i');
+ n=size(y,1);
+ for i=1:max(size(alpha))
+ k=size(y(1:$*alpha(i),:),1);
+ ES(i,:)=-(sum(y(1:k,:),1)/n+y(k+1,:)*(alpha(i)-k/n))/alpha(i);
+ VaR(i,:)=-y(ceil(size(y,1)*alpha(i)),:);
+ if k<2 then k=2, end;
+ fi=max(2*n*(k-[1:n]')/(k*(k-1)),0);
+ M(i,:)=-fi'*y/n;
+ end
+endfunction
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/esvaroptim.bin b/debian/scilab-financial/usr/lib/scilab-financial/macros/esvaroptim.bin
new file mode 100644
index 0000000..44d9fcc
Binary files /dev/null and b/debian/scilab-financial/usr/lib/scilab-financial/macros/esvaroptim.bin differ
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/esvaroptim.sci b/debian/scilab-financial/usr/lib/scilab-financial/macros/esvaroptim.sci
new file mode 100644
index 0000000..6c03c9d
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/macros/esvaroptim.sci
@@ -0,0 +1,118 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [w,ES,VaR]=esvaroptim(price,ER,r,dt,alpha);
+
+// PURPOSE: Compute the optimal portfolio
+// minimizing the "Expected Shortfall" and
+// also show the value of the "Value at Risk"
+//--------------------------------------------------------------
+// INPUT:
+// * price = matrix whose columns contain the historical
+// prices of each asset
+// * ER = expected (annual) portfolio return
+// * r = riskless (annual) interest rate
+// * dt = data frequencty (e.g. dt=1 for annual data,
+// dt=1/4 for quarter data, and so on...)
+// * alpha = confidence level of both Expected Shortfall
+// and Value at Risk
+// -------------------------------------------------------------
+// OUTPUT:
+// * w = matrix of the optimal portfolio composition
+// first raw : with short selling and with r
+// second raw : with short selling and without r
+// third raw : without short selling and with r
+// fourth raw : without short selling and without r
+// * ES = Expected Shortfall of the optimal portfolio
+// * VaR = Value at Risk of the optimal portfolio
+// -------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ ER=ER*dt;
+ r=r*dt,
+ Rp=diff(price,1,1)./price(1:$-1,:);
+ K=size(Rp,1);
+ n=size(Rp,2);
+ p=[-1;ones(K,1)/(alpha*K);zeros(n,1)];
+ yiw=[-100000; zeros(K+n,1)];
+ yi=[-100000; zeros(K,1); -ones(n,1)*100000]
+ //
+ // Matrices without r
+ //
+ C=[zeros(1,K+1),mean(Rp,1); zeros(1,K+1),ones(1,n); ones(K,1),-eye(K,K),-Rp];
+ b=[ER;1;zeros(K,1)];
+ //
+ // Matrice with r
+ //
+ Cr=[zeros(1,K+1),mean(Rp,1)-r;ones(K,1),-eye(K,K),-Rp+r];
+ br=[ER-r;ones(K,1)*r];
+ //
+ // Portfolio with short selling
+ //
+ Q=zeros(size(p,1),size(p,1));
+ yr=qld(Q,p,Cr,br,yi,[],1);
+ y=qld(Q,p,C,b,yi,[],2);
+ VaR=[-yr(1) -y(1)];
+ w=[yr(K+2:$) y(K+2:$)];
+ ES=[yr'*p y'*p];
+ //
+ // Portfolio without short selling
+ //
+ if ER>min(mean(Rp,1)) & ER<max(mean(Rp,1)) then
+ yrw=qld(Q,p,Cr,br,yiw,[],1);
+ yw=qld(Q,p,C,b,yiw,[],2);
+ VaR(:,3:4)=[-yrw(1) -yw(1)];
+ w(:,3:4)=[yrw(K+2:$) yw(K+2:$)];
+ ES(:,3:4)=[yrw'*p yw'*p];
+ else
+ VaR(:,3:4)=%nan;
+ w(:,3:4)=%nan;
+ ES(:,3:4)=%nan;
+ end
+ //
+ // Draw frontiers
+ //
+ frontier=input('Draw frontier? (y/n) ','string');
+ disp([' with short selling',' without short selling']);
+ disp([' with r',' without r',' with r',' without r']);
+if frontier=='y' then
+ xtitle('Return-Expected Shortfall Frontier','Expected Shortfall','Mean return');
+ //
+ // Define coordinates
+ //
+ ordi=max(0,min(mean(Rp,1)));
+ ords=max(mean(Rp,1));
+ ord=[ordi:(ords-ordi)/100:ords];
+ //
+ // Compute and draw unconstrained frontiers
+ //
+ for i=1:size(ord,2)
+ b=[ord(i);1;zeros(K,1)];
+ br=[ord(i)-r;ones(K,1)*r];
+ y=qld(Q,p,C,b,yi,[],2);
+ yr=qld(Q,p,Cr,br,yi,[],1);
+ x(i)=y'*p;
+ xr(i)=yr'*p;
+ end
+ plot(x,ord,'black');
+ plot(xr,ord,'--black');
+ if ER>min(mean(Rp,1)) & ER<max(mean(Rp,1)) then
+ for i=1:size(ord,2)
+ b=[ord(i);1;zeros(K,1)];
+ br=[ord(i)-r;ones(K,1)*r];
+ yw=qld(Q,p,C,b,yiw,[],2);
+ yrw=qld(Q,p,Cr,br,yiw,[],1);
+ xw(i)=yw'*p;
+ xrw(i)=yrw'*p;
+ end
+ plot(xw,ord,'red');
+ plot(xrw,ord,'--red');
+ legend(['Without r - with short selling','With r - with short selling','Without r - without short selling','With r - without short selling'],2)
+ else
+ legend(['Without r - with short selling','With r - with short selling'],2)
+ end
+ else
+end
+endfunction
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/euler.bin b/debian/scilab-financial/usr/lib/scilab-financial/macros/euler.bin
new file mode 100644
index 0000000..19fc5d6
Binary files /dev/null and b/debian/scilab-financial/usr/lib/scilab-financial/macros/euler.bin differ
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/euler.sci b/debian/scilab-financial/usr/lib/scilab-financial/macros/euler.sci
new file mode 100644
index 0000000..c4cd16d
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/macros/euler.sci
@@ -0,0 +1,45 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [x]=euler(drift,diffusion,dt,T,x0,t0);
+
+// PURPOSE: Through Euler method, find the numerical
+// solution to a system of stochastic differential
+// equations of the following form
+// dx = drift(t,x) dt + diffusion(t,x) dW
+// where "dx" is a vecotr, "drift" is a vector,
+// "diffusion" is a matrix, and "dW" is a vector
+//---------------------------------------------------------------
+// INPUT:
+// * drift = STRING describing the COLUMN vector of the
+// drifts, the unknowns must be named
+// "t" and "x" (if there are more x's, then they
+// must be named "x(1)", "x(2)",and so on)
+// * diffusion = STRING describing the MATRIX of the
+// diffusions, the unknowns must be named
+// as in the drift
+// * T = time during which performing the simulation
+// * dt = time interval (e.g. with daily data and "T"
+// set in years, dt=1/250)
+// * x0 = the vector of initial values of variables "x"'s
+// * t0 = the initial value of variable "t"
+// ---------------------------------------------------------------
+// OUTPUT:
+// * x = matrix whose columns contain the series of
+// simulated variable "x"'s
+// ---------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ deff('y=mu(t,x)',strcat(['y=',drift]));
+ deff('y=sigma(t,x)',strcat(['y=',diffusion]));
+ dW=rand(size(sigma(t0,x0),2),T/dt,'normal')*sqrt(dt);
+ x(:,1)=x0;
+ t(1)=t0;
+ for i=2:T/dt
+ x(:,i)=x(:,i-1)+mu(t(i-1),x(:,i-1))*dt+sigma(t(i-1),x(:,i-1))*dW(:,i);
+ t(i)=t(i-1)+dt;
+ end;
+ x=x';
+endfunction
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/evt.bin b/debian/scilab-financial/usr/lib/scilab-financial/macros/evt.bin
new file mode 100644
index 0000000..9c28d00
Binary files /dev/null and b/debian/scilab-financial/usr/lib/scilab-financial/macros/evt.bin differ
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/evt.sci b/debian/scilab-financial/usr/lib/scilab-financial/macros/evt.sci
new file mode 100644
index 0000000..d31aec0
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/macros/evt.sci
@@ -0,0 +1,30 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [xoptim,v,inf]=evt(x0,x,u)
+
+// PURPOSE: Estimate the parameters ("xi" and "beta") of a
+// Generalized Pareto Density with Maximum Likelihood
+//
+// f(x) = (1+xi*(x-u)/beta)^(-1/xi-1)/beta
+//------------------------------------------------------------------
+// INPUT:
+// * x0 = starting values for the parameters "xi" and "beta"
+// * x = historical asset returns
+// * u = threshold parameter
+// -----------------------------------------------------------------
+// OUTPUT:
+// * xoptim = maximum likelihood value of the parameters
+// "xi" and "beta"
+// * v = same value as "v" in the "fsolve" function
+// * inf = same values as "inf" in the "fsolve" function
+// -----------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ x=x(x>u);
+ deff('[y]=eq(z)','y=[1/z(1)/z(2)-(1/z(1)+1)/z(2)*mean((1+z(1)*(x-u)/z(2))^(-1));...
+ -(1/z(1)+1)/z(1)+1/z(1)^2*mean(log(1+z(1)*(x-u)/z(2)))+(1/z(1)+1)/z(1)*mean((1+z(1)*(x-u)/z(2))^(-1))]');
+ [xoptim,v,inf]=fsolve(x0,eq);
+endfunction
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/gbm.bin b/debian/scilab-financial/usr/lib/scilab-financial/macros/gbm.bin
new file mode 100644
index 0000000..84f122e
Binary files /dev/null and b/debian/scilab-financial/usr/lib/scilab-financial/macros/gbm.bin differ
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/gbm.sci b/debian/scilab-financial/usr/lib/scilab-financial/macros/gbm.sci
new file mode 100644
index 0000000..a7b1728
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/macros/gbm.sci
@@ -0,0 +1,40 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [mu,sigma]=gbm(data,dt);
+
+// PURPOSE: Estimate the parameters of a Geometric Brownian
+// Motion - GBM (through the method of moments) and
+// graphically show the result
+//----------------------------------------------------------------
+// INPUT:
+// * data = historical data (in a column vector)
+// * dt = data frequencty (e.g. dt=1 for annual data,
+// dt=1/4 for quarter data, and so on...)
+// ----------------------------------------------------------------
+// OUTPUT:
+// * mu = drift term of the GBM
+// * sigma = diffusion term of the GBM
+// In the final figure:
+// in black : the historical data
+// in blue : the mean of the process
+// in dotted blue : the confidence interval
+// (mean +/- st_dev and
+// mena +/- 2 times st_dev)
+//
+// ----------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ dln=diff(log(data));
+ sigma=sqrt(mvvacov(dln)/dt);
+ mu=mean(dln)/dt+1/2*sigma^2;
+ N=size(data,1);
+ t=[1:N]'*dt;
+ M=data(1)*exp(mu*t);
+ Std=data(1)*exp(mu*t).*sqrt(exp(sigma^2*t)-1);
+ plot(data,'black');
+ plot(M,'blue');
+ plot([M-Std M-2*Std M+2*Std M+Std],'blue--');
+endfunction
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/hedge.bin b/debian/scilab-financial/usr/lib/scilab-financial/macros/hedge.bin
new file mode 100644
index 0000000..9a0bce6
Binary files /dev/null and b/debian/scilab-financial/usr/lib/scilab-financial/macros/hedge.bin differ
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/hedge.sci b/debian/scilab-financial/usr/lib/scilab-financial/macros/hedge.sci
new file mode 100644
index 0000000..6db223e
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/macros/hedge.sci
@@ -0,0 +1,49 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [h]=hedge(S,F);
+
+// PURPOSE: Compute the hedge ratio between an asset "S"
+// and a derivative on it "F"
+//------------------------------------------------------------------
+// INPUT:
+// * S = column vector of historical prices of an asset
+// * F = column vector of historical prices of a derivative
+//
+// S and F must have the same dimension
+// -----------------------------------------------------------------
+// OUTPUT:
+// * h = hedge ratio between S and F. If one multiplies the wealth
+// invested in S by "h", one obtains the wealth that must be
+// invested in F in order to hedged the position on S
+// -----------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ dlnS=diff(log(S),1,1);
+ dlnF=diff(log(F),1,1);
+
+ X=[ones(dlnS) dlnS];
+ [nobs,nvar]=size(X);
+ bhat=(X'*X)^(-1)*X'*dlnF;
+ h=-1/bhat(2);
+ R2=1-(dlnF-X*bhat)'*(dlnF-X*bhat)/((dlnF-mean(dlnF))'*(dlnF-mean(dlnF)));
+ R2c=1-(1-R2)*(nobs-1)/(nobs-nvar);
+
+// computation of t-statistics
+
+ tstat=sqrt((nobs-nvar)/((dlnF-X*bhat)'*(dlnF-X*bhat)))*bhat./sqrt(diag((X'*X)^(-1)));
+
+ plot(dlnF,'blue');
+ plot(X*bhat,'red');
+ legend(['Historical values','Estimated values']);
+
+ disp(['N. observations' string(nobs);...
+ 'N. variables' string(nvar);...
+ 'R-square' string(R2);...
+ 'R-square corrected' string(R2c)]);
+ disp(['Coefficients' 't-statistics';...
+ string(bhat) string(tstat)]);
+
+endfunction
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/hurst.bin b/debian/scilab-financial/usr/lib/scilab-financial/macros/hurst.bin
new file mode 100644
index 0000000..2273416
Binary files /dev/null and b/debian/scilab-financial/usr/lib/scilab-financial/macros/hurst.bin differ
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/hurst.sci b/debian/scilab-financial/usr/lib/scilab-financial/macros/hurst.sci
new file mode 100644
index 0000000..8a4856b
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/macros/hurst.sci
@@ -0,0 +1,38 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [H]=hurst(price,varargin);
+
+// PURPOSE: Compute the Hurst index on
+// historical prices
+//--------------------------------------------------------------
+// INPUT:
+// * price = vector of historical prices
+// * period = (optional input, by default 250) first number of
+// prices used for computing the index
+// * step = (optional input, by default 10) each increment
+// in the number of prices used for computing
+// the index
+// -------------------------------------------------------------
+// OUTPUT:
+// H = Hurst index
+// -------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ select size(varargin)
+ case 0 then period=250; step=10;
+ case 1 then period=varargin(1); step=10;
+ case 2 then period=varargin(1); step=varargin(2);
+ end
+ for i=1:(length(price)-period)/step
+ dlnS=diff(log(price(1:period+step*(i-1))));
+ x(i)=log(length(dlnS));
+ y(i)=log((max(cumsum(dlnS-mean(dlnS)))-min(cumsum(dlnS-mean(dlnS))))/stdev(dlnS));
+ end
+ plot(x,y,'.');
+ x=[ones(x) x];
+ bhat=(x'*x)^(-1)*x'*y;
+ H=bhat(2);
+endfunction
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/interest.bin b/debian/scilab-financial/usr/lib/scilab-financial/macros/interest.bin
new file mode 100644
index 0000000..aee3ecb
Binary files /dev/null and b/debian/scilab-financial/usr/lib/scilab-financial/macros/interest.bin differ
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/interest.sci b/debian/scilab-financial/usr/lib/scilab-financial/macros/interest.sci
new file mode 100644
index 0000000..cf16bd4
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/macros/interest.sci
@@ -0,0 +1,78 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [rf]=interest(r,dt,T,model,n,r0);
+
+// PURPOSE: Simulate future interest rate by estimating
+// the parameters of three models on the historical
+// interest rate
+//---------------------------------------------------------
+// INPUT:
+// * r = column vector of historical interest rates
+// * dt = time unit of measure
+// * T = number of periods to simulate
+// * model = either "merton", or "vasicek", or "cir"
+// * n = the number of simulations to perform
+// * r0 = the first interest rate for simulation
+// -------------------------------------------------------------
+// OUTPUT:
+// * rf = the matrix whose rows contain the future values of
+// interest rate and whose columns contains
+// each simulation
+// -------------------------------------------------------------
+// Francesco Menoncin (2009)
+
+ select model
+ case 'merton' then
+ mu=mean(diff(r))/dt;
+ sigma=sqrt(mvvacov(diff(r))/dt);
+ rf=r0*ones(1,n);
+ for j=1:n
+ dW=rand(T/dt,1,'normal')*sqrt(dt);
+ for i=2:T/dt
+ rf(i,j)=rf(i-1,j)+mu*dt+sigma*dW(i);
+ end;
+ end;
+ disp(['Coefficient', 'Value';...
+ 'Drift', string(mu);...
+ 'Diffusion', string(sigma)]);
+ case 'vasicek' then
+ X=[ones(size(r,1)-1,1),r(1:$-1)];
+ bhat=(X'*X)^(-1)*X'*r(2:$);
+ a=(1-bhat(2))/dt;
+ b=bhat(1)/(1-bhat(2));
+ sigma=sqrt(mvvacov(diff(r))/dt);
+ rf=r0*ones(1,n);
+ for j=1:n
+ dW=rand(T/dt,1,'normal')*sqrt(dt);
+ for i=2:T/dt
+ rf(i,j)=rf(i-1,j)+a*(b-rf(i-1,j))*dt+sigma*dW(i);
+ end;
+ end;
+ disp(['Coefficient', 'Value';...
+ 'Mean reversion', string(a);...
+ 'Mean', string(b);...
+ 'Diffusion', string(sigma)]);
+ case 'cir' then
+ sigma=sqrt(mvvacov(diff(2*sqrt(r)))/dt);
+ X=[2*sqrt(r(1:$-1)),(2*sqrt(r(1:$-1))).^(-1)];
+ bhat=(X'*X)^(-1)*X'*(2*sqrt(r(2:$)));
+ a=2*(1-bhat(1))/dt;
+ b=(bhat(2)+sigma^2*dt/2)/(4*(1-bhat(1)));
+ rf=r0*ones(1,n);
+ for j=1:n
+ dW=rand(T/dt,1,'normal')*sqrt(dt);
+ for i=2:T/dt
+ rf(i,j)=rf(i-1,j)+a*(b-rf(i-1,j))*dt+sigma*sqrt(rf(i-1,j))*dW(i);
+ end;
+ end;
+ disp(['Coefficient', 'Value';...
+ 'Mean reversion', string(a);...
+ 'Mean', string(b);...
+ 'Diffusion coeff.', string(sigma)]);
+ end
+ plot([1:size(rf,1)]'*dt,rf);
+ title('Simulated interest rates');
+endfunction
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/irs.bin b/debian/scilab-financial/usr/lib/scilab-financial/macros/irs.bin
new file mode 100644
index 0000000..aa4c7ae
Binary files /dev/null and b/debian/scilab-financial/usr/lib/scilab-financial/macros/irs.bin differ
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/irs.sci b/debian/scilab-financial/usr/lib/scilab-financial/macros/irs.sci
new file mode 100644
index 0000000..b688710
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/macros/irs.sci
@@ -0,0 +1,45 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [spread,leg]=irs(time,months,r,setting);
+
+// PURPOSE: Compute both the spread for a fix-for-floating
+// Interest Rate Swap and the value of the legs
+//
+//--------------------------------------------------------------
+// INPUT:
+// * time = subscribing date in the form
+// [year month day]
+// * months = number of months for each period
+// * r = curve of relevant
+// spot interest rates (column vector)
+// * setting = must be "0" (zero) for "in advance" swap
+// and "1" for "in arrears" swap
+// -------------------------------------------------------------
+// OUTPUT:
+// * spread = is the fix amount that
+// must be paid at each perdio
+// * leg = is the value of both legs of the swap
+// -------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ Y(1)=time(1); M(1)=time(2);
+ for i=2:max(size(r))+1
+ if M(i-1)+months>12 then
+ M(i)=modulo(M(i-1)+months,12);
+ Y(i)=Y(i-1)+1;
+ else
+ M(i)=M(i-1)+months;
+ Y(i)=Y(i-1);
+ end
+ end
+ t=datenum(Y,M,time(3)*ones(M));
+ g=diff(t)/360;
+ gg=cumsum(g);
+ B=[1; (1+r.*gg).^(-1)];
+ f=(B(1:$-1)./B(2:$)-1)./g;
+ leg=sum(f(1+setting:$).*B(2:$-setting).*g(1:$-setting));
+ spread=leg/sum(B(2:$-setting).*g(1:$-setting));
+endfunction
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/lib b/debian/scilab-financial/usr/lib/scilab-financial/macros/lib
new file mode 100644
index 0000000..ae95965
Binary files /dev/null and b/debian/scilab-financial/usr/lib/scilab-financial/macros/lib differ
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/markowitz.bin b/debian/scilab-financial/usr/lib/scilab-financial/macros/markowitz.bin
new file mode 100644
index 0000000..0edc685
Binary files /dev/null and b/debian/scilab-financial/usr/lib/scilab-financial/macros/markowitz.bin differ
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/markowitz.sci b/debian/scilab-financial/usr/lib/scilab-financial/macros/markowitz.sci
new file mode 100644
index 0000000..bf8a77a
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/macros/markowitz.sci
@@ -0,0 +1,107 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [portf,varoptim]=markowitz(price,ER,r,dt);
+
+// PURPOSE: Compute the optimal portfolio in the Markowitz
+// framework with and without riskless interest
+// rate, with and without short selling
+// Finally, the mean-variance frontier is drawn
+//--------------------------------------------------------------
+// INPUT:
+// * price = matrix whose columns contain the historical
+// prices of each asset
+// * ER = expected (annual) portfolio return
+// * r = riskless (annual) interest rate
+// * dt = data frequencty (e.g. dt=1 for annual data,
+// dt=1/4 for quarter data, and so on...)
+// -------------------------------------------------------------
+// OUTPUT:
+// * portf = matrix of the optimal portfolio composition
+// first raw : with short selling and with r
+// second raw : with short selling and without r
+// third raw : without short selling and with r
+// fourth raw : without short selling and without r
+// -------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+//
+// Compute variances, covariances, and means
+//
+dlnprice=diff(log(price),1,1);
+Q=mvvacov(dlnprice)/dt;
+mu=mean(dlnprice,1)'/dt+1/2*diag(Q);
+//
+// Define vectors p and xi
+//
+p=zeros(size(price,2),1);
+xi=zeros(size(price,2),1);
+//
+// Compute optimal unconstrained portfolio and variance
+//
+ww=qld(2*Q,p,(mu'-r),(ER-r),[],[],1);
+varw=ww'*Q*ww;
+wrw=qld(2*Q,p,[mu';ones(size(price,2),1)'],[ER;1],[],[],2);
+varrw=wrw'*Q*wrw;
+portf=[ww,wrw];
+varoptim=[varw,varrw];
+//
+// Compute optimal constrained portfolio and variance
+//
+if ER>min(mu) & ER<max(mu) then
+ w=qld(2*Q,p,(mu'-r),(ER-r),xi,[],1);
+ var=w'*Q*w;
+ wr=qld(2*Q,p,[mu';ones(size(price,2),1)'],[ER;1],xi,[],2);
+ varr=wr'*Q*wr;
+ portf=[ww,wrw,w,wr];
+ varoptim=[varw,varrw,var,varr];
+else
+ portf(:,3)=%nan;
+ portf(:,4)=%nan;
+ varoptim(:,3)=%nan;
+ varoptim(:,4)=%nan;
+end
+
+frontier=input('Draw frontiers? (y/n) ','string');
+disp([' with short selling',' without short selling']);
+disp([' with r',' without r',' with r',' without r']);
+if frontier=='y' then
+ xtitle('Mean-Std frontier','Standard Deviation','Mean return');
+ //
+ // Define coordinates
+ //
+ ordi=max(0,min(mu));
+ ords=max(mu);
+ ord=[ordi:(ords-ordi)/100:ords];
+ //
+ // Compute and draw unconstrained frontiers
+ //
+ for i=1:size(ord,2)
+ ww=qld(2*Q,p,(mu'-r),(ord(i)-r),[],[],1);
+ xw(i)=ww'*Q*ww;
+ wrw=qld(2*Q,p,[mu';ones(size(price,2),1)'],[ord(i);1],[],[],2);
+ xrw(i)=wrw'*Q*wrw;
+ end
+ plot(sqrt(xw),ord,'--black');
+ plot(sqrt(xrw),ord,'black');
+ if ER>min(mu) & ER<max(mu) then
+ //
+ // Compute and draw constrained frontiers
+ //
+ for i=1:size(ord,2)
+ w=qld(2*Q,p,(mu'-r),(ord(i)-r),xi,[],1);
+ x(i)=w'*Q*w;
+ wr=qld(2*Q,p,[mu';ones(size(price,2),1)'],[ord(i);1],xi,[],2);
+ xr(i)=wr'*Q*wr;
+ end
+ plot(sqrt(x),ord,'--red');
+ plot(sqrt(xr),ord,'red');
+ legend(['With r - with short selling','Without r - with short selling','With r - without short selling','Without r - without short selling'],2)
+ else
+ legend(['With r - with short selling','Without r - with short selling'],2)
+ end
+ else
+end
+endfunction
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/mef.bin b/debian/scilab-financial/usr/lib/scilab-financial/macros/mef.bin
new file mode 100644
index 0000000..5dd95b5
Binary files /dev/null and b/debian/scilab-financial/usr/lib/scilab-financial/macros/mef.bin differ
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/mef.sci b/debian/scilab-financial/usr/lib/scilab-financial/macros/mef.sci
new file mode 100644
index 0000000..0cd84dc
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/macros/mef.sci
@@ -0,0 +1,27 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [E]=mef(x);
+
+// PURPOSE: Draw the "Mean Excess Function"
+//------------------------------------------------------------------
+// INPUT:
+// * x = column vector of historical returns on an asset
+// -----------------------------------------------------------------
+// OUTPUT:
+// * E = values of the Mean Excess Function for any possible
+// threshold (i.e. alternatively taking any historical
+// retur as a threshold)
+//
+// Finally the Mean Excess Function is plotted
+// -----------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ xo=gsort(x,'r','i');
+ for i=1:size(x,1)-1
+ E(i)=mean(xo(i+1:$)-xo(i));
+ end
+ plot(xo(1:$-1),E,'.');
+endfunction
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/movav.bin b/debian/scilab-financial/usr/lib/scilab-financial/macros/movav.bin
new file mode 100644
index 0000000..28b12ef
Binary files /dev/null and b/debian/scilab-financial/usr/lib/scilab-financial/macros/movav.bin differ
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/movav.sci b/debian/scilab-financial/usr/lib/scilab-financial/macros/movav.sci
new file mode 100644
index 0000000..72e44b5
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/macros/movav.sci
@@ -0,0 +1,28 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [M]=movav(S,varargin);
+
+// PURPOSE: Compute the moving avarages of a time series
+//---------------------------------------------------------
+// INPUT:
+// * S = historical data (column vector)
+// * varargin = the lenght of the moving avarages
+// -------------------------------------------------------------
+// OUTPUT:
+// * M = matrix containing, in any column, the moving
+// average of the historical data
+// -------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ for i=1:size(varargin)
+ m=varargin(i);
+ for k=size(S,1):-1:m
+ M(k,i)=mean(S(k-m+1:k));
+ end
+ M(1:m-1,i)=%nan;
+ end
+ plot([S M]);
+endfunction
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/names b/debian/scilab-financial/usr/lib/scilab-financial/macros/names
new file mode 100644
index 0000000..7d1d031
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/macros/names
@@ -0,0 +1,22 @@
+esvaroptim
+movav
+markowitz
+nelson_siegel
+duration
+esvarlin
+bollinger
+euler
+hedge
+cfr
+svennson
+mef
+hurst
+gbm
+bsgreeks
+backtest
+esvarevt
+evt
+bsoption
+interest
+irs
+bsimpvol
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/nelson_siegel.bin b/debian/scilab-financial/usr/lib/scilab-financial/macros/nelson_siegel.bin
new file mode 100644
index 0000000..f348afc
Binary files /dev/null and b/debian/scilab-financial/usr/lib/scilab-financial/macros/nelson_siegel.bin differ
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/nelson_siegel.sci b/debian/scilab-financial/usr/lib/scilab-financial/macros/nelson_siegel.sci
new file mode 100644
index 0000000..7d09dcc
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/macros/nelson_siegel.sci
@@ -0,0 +1,56 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [uopt,rf]=nelson_siegel(t,r,u0,varargin);
+
+// PURPOSE: Estimate the parameters u1, u2, u3, u4
+// for the Nelson Siegel model f(t) of spot
+// interest rates (least square method)
+//
+// f(t)=u1+(u2+u3)*u4/t*(1-e^(-t/u4))-u4*e^(-t/u4)
+//
+// Finally draw the actual spot rate curve and the
+// interporalted curve
+//--------------------------------------------------------------
+// INPUT:
+// * t = spot rate maturities (column vector)
+// * r = spot interest rates (column vector)
+// * u0 = initial values of the parameters (vector 4x1)
+// * tf = optional input: the dates for which spot rates
+// must be foreseen (column vector)
+// -------------------------------------------------------------
+// OUTPUT:
+// * uopt = optimal values of the parameters u1, u2, u3, u4
+// (vector 4x1)
+// * rf = optional output: foreseen values of spot rates
+// -------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ function rh=rhat(u,t);
+ rh=u(1)+(u(2)+u(3))*u(4)*(1-exp(-t/u(4)))./t...
+ -u(3)*exp(-t/u(4));
+ endfunction
+
+ function D=Diff(u);
+ D=rhat(u,t)-r;
+ endfunction
+
+ [f,uopt,gopt]=leastsq(Diff,u0);
+ disp('Gradient');
+ disp(gopt);
+ disp('Objective function');
+ disp(f);
+ r_estim=rhat(uopt,t)
+ plot(t,r);
+ plot(t,r_estim,'red');
+ if size(varargin)<>0 then
+ tf=varargin(1);
+ rf=rhat(uopt,tf);
+ plot([t($);tf],[r_estim($);rf],'green');
+ legend(['Actual values','Estimated values','Foreseen values'],4);
+ else
+ legend(['Actual values','Estimated values'],4);
+ end
+endfunction
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/svennson.bin b/debian/scilab-financial/usr/lib/scilab-financial/macros/svennson.bin
new file mode 100644
index 0000000..9d2bddb
Binary files /dev/null and b/debian/scilab-financial/usr/lib/scilab-financial/macros/svennson.bin differ
diff --git a/debian/scilab-financial/usr/lib/scilab-financial/macros/svennson.sci b/debian/scilab-financial/usr/lib/scilab-financial/macros/svennson.sci
new file mode 100644
index 0000000..74907bf
--- /dev/null
+++ b/debian/scilab-financial/usr/lib/scilab-financial/macros/svennson.sci
@@ -0,0 +1,57 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [uopt,rf]=svennson(t,r,u0,varargin);
+
+// PURPOSE: Estimate the parameters u1, u2, u3, u4, u5, u6
+// for the Svennson model f(t) of spot
+// interest rates (least square method)
+//
+// f(t)=u1+u4*u6/t+(u2+u3)*u5/t*(1-e^(-t/u5))
+// -(u6/t-1)*u4*e^(-t/u6)-u3*e^(-t/u5)
+//
+// Finally draw the actual spot rate curve and the
+// interporalted curve
+//--------------------------------------------------------------
+// INPUT:
+// * t = spot rate maturities (column vector)
+// * r = spot interest rates (column vector)
+// * u0 = initial values of the parameters (vector 6x1)
+// * tf = optional input: the dates for which spot rates
+// must be foreseen (column vector)
+// -------------------------------------------------------------
+// OUTPUT:
+// * uopt = optimal values of the parameters
+// u1, u2, u3, u4, u5, u6 (vector 6x1)
+// * rf = optional output: foreseen values of spot rates
+// -------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ function rh=rhat(u,t);
+ rh=u(1)+u(4)*u(6)*t.^(-1)+(u(2)+u(3))*u(5)*(1-exp(-t/u(5)))./t...
+ -u(4)*(u(6)*t.^(-1)-1).*exp(-t/u(6))-u(3)*exp(-t/u(5));
+ endfunction
+
+ function D=Diff(u);
+ D=rhat(u,t)-r;
+ endfunction
+
+ [f,uopt,gopt]=leastsq(Diff,u0);
+ disp('Gradient');
+ disp(gopt);
+ disp('Objective function');
+ disp(f);
+ r_estim=rhat(uopt,t)
+ plot(t,r);
+ plot(t,r_estim,'red');
+ if size(varargin)<>0 then
+ tf=varargin(1);
+ rf=rhat(uopt,tf);
+ plot([t($);tf],[r_estim($);rf],'green');
+ legend(['Actual values','Estimated values','Foreseen values'],4);
+ else
+ legend(['Actual values','Estimated values'],4);
+ end
+endfunction
diff --git a/debian/scilab-financial/usr/share/doc/scilab-financial/buildinfo_all.gz b/debian/scilab-financial/usr/share/doc/scilab-financial/buildinfo_all.gz
new file mode 100644
index 0000000..e24e3fe
Binary files /dev/null and b/debian/scilab-financial/usr/share/doc/scilab-financial/buildinfo_all.gz differ
diff --git a/debian/scilab-financial/usr/share/doc/scilab-financial/changelog.Debian.gz b/debian/scilab-financial/usr/share/doc/scilab-financial/changelog.Debian.gz
new file mode 100644
index 0000000..4404899
Binary files /dev/null and b/debian/scilab-financial/usr/share/doc/scilab-financial/changelog.Debian.gz differ
diff --git a/debian/scilab-financial/usr/share/doc/scilab-financial/changelog.gz b/debian/scilab-financial/usr/share/doc/scilab-financial/changelog.gz
new file mode 100644
index 0000000..60c53f3
Binary files /dev/null and b/debian/scilab-financial/usr/share/doc/scilab-financial/changelog.gz differ
diff --git a/debian/scilab-financial/usr/share/doc/scilab-financial/changelog.txt.gz b/debian/scilab-financial/usr/share/doc/scilab-financial/changelog.txt.gz
new file mode 100644
index 0000000..60c53f3
Binary files /dev/null and b/debian/scilab-financial/usr/share/doc/scilab-financial/changelog.txt.gz differ
diff --git a/debian/scilab-financial/usr/share/doc/scilab-financial/copyright b/debian/scilab-financial/usr/share/doc/scilab-financial/copyright
new file mode 100644
index 0000000..2c057f3
--- /dev/null
+++ b/debian/scilab-financial/usr/share/doc/scilab-financial/copyright
@@ -0,0 +1,20 @@
+This package was debianized by Ruben Bibas <ruben.bibas+debian at gmail.com> on
+Mon Feb 11 19:00:52 CET 2013
+
+It was downloaded from http://atoms.scilab.org/toolboxes/Financial
+
+Upstream Authors:
+
+ Michael Baudin
+ Francesco Menoncin
+
+Copyright:
+
+ <Copyright (C) 2009 - 2010 - Francesco Menoncin>
+ <Copyright (C) 2010 - DIGITEO - Michael Baudin>
+
+License:
+
+ GPL (3.0)
+
+Please see /usr/share/common-licenses/GPL-3 for the full license.
diff --git a/debian/scilab-financial/usr/share/doc/scilab-financial/license.txt b/debian/scilab-financial/usr/share/doc/scilab-financial/license.txt
new file mode 100644
index 0000000..a455933
--- /dev/null
+++ b/debian/scilab-financial/usr/share/doc/scilab-financial/license.txt
@@ -0,0 +1,7 @@
+Financial Scilab Toolbox
+
+This toolbox is released under the terms of the GPL (3.0) license :
+
+http://gplv3.fsf.org/
+
+
diff --git a/debian/scilab-financial/usr/share/doc/scilab-financial/readme.txt b/debian/scilab-financial/usr/share/doc/scilab-financial/readme.txt
new file mode 100644
index 0000000..020fb24
--- /dev/null
+++ b/debian/scilab-financial/usr/share/doc/scilab-financial/readme.txt
@@ -0,0 +1,73 @@
+Financial toolbox
+
+Purpose
+-------
+
+The module is dedicated to finance. There are three main areas that are covered:
+
+ * risk measure and management,
+ * asset allocation,
+ * pricing.
+
+For what concerns the risk measure, some functions are dedicated to the computation of Value at Risk (VaR) and Expected Shortfall (ES). Backtest is also implemented in order to check the goodness of such risk measures. Both VaR and ES are also computed in an Extreme Value Theory framework (EVT). Furthermore, it is possible to estimate the parameters of the EVT density function (through maximum likelihood). The Mean Excess Function for graphical study of an EVT distribution is also implemented.
+The interest rate risk is faced by functions aimed at computing duration, convexity, and yield to maturity. Furthermore, Merton, Vasicek and Cox, Ingersoll and Ross interest rate models are implemented together with the estimation of their parameters. Parametric interpolation of the interest rate curve is possible through both Svennson’s and Nelson-Siegel’s models.
+Finally, some technical analysis indicators are implemented: Bollinger bands, moving averages, Hurst index.
+
+The asset allocation problem is faced by two functions which compute:
+
+ * the optimal portfolio minimizing the variance of its return and
+ * the optimal portfolio minimizing the expected shortfall of its return.
+In both cases, the portfolios with and without a riskless asset and with and without short selling are computed.
+
+
+Pricing problem is approached through functions aimed at:
+
+ * computing the spread on Interest Rate Swaps,
+ * computing the value of options in the Black and Scholes framework (with Greeks and implied volatility),
+ * simulating stochastic processes (through Euler discretization).
+
+Features
+--------
+
+ * backtest : Apply the backtest to Expected Shortfall, Value at Risk and a Linear Spectral risk measure.
+ * bollinger : Plots the historical prices, the Bollinger bands, and the b-percentage.
+ * bsgreeks : Compute the Greeks for Black and Scholes put and call options.
+ * bsimpvol : Compute the implied volatility in a Black and Scholes framework.
+ * bsoption : Compute the value of both a call and a put option in a Black and Scholes framework.
+ * cfr : Compare and merge two or more time series according to dates.
+ * duration : Compute both duration and convexity of cash flows by using the yield-to-maturity.
+ * esvarevt : Compute both Expected Shortfall and Value at Risk.
+ * esvarlin : Compute Expected Shortfall, Value at Risk and a Linear Spectral risk measure on a set of assets.
+ * esvaroptim : Compute the optimal portfolio minimizing the Expected Shortfall.
+ * euler : Simulate the solution of a system of stochastic differential equation.
+ * evt : Estimate the parameters of the Generalized Pareto Distribution.
+ * gbm : Estimate the parameters of a Geometric Brownian Motion.
+ * hedge : Compute the hedge ratio between an asset and a derivative on that asset.
+ * hurst : Compute the Hurst index on historical prices.
+ * interest : Estimate the parameters of three spot interest rate models (Merton - Vasicek - CIR).
+ * irs : Compute both the spread and the value of the legs of a fix-for-floating Interest Rate Swap.
+ * markowitz : Compute the optimal portfolio minimizing the variance.
+ * mef : Compute and draw the Mean Excess Function.
+ * movav : Compute and draw the moving average of a given time series.
+ * nelson_siegel : Estimate the parameters for the Nelson Siegel model of spot interest rates.
+ * svennson : Estimate the parameters for the Svennson model of spot interest rates.
+
+TODO
+----
+ * Rename functions into "finance_*".
+ * Shorten description of functions.
+ * The help page of the svennson function is not properly formatted.
+ * Create unit tests.
+
+Authors
+------
+
+2009-2010 - Francesco Menoncin
+2010 - DIGITEO - Michaël Baudin
+
+Licence
+-------
+
+This toolbox is distributed under the GPL (3.0).
+
+
diff --git a/debian/scilab-financial/usr/share/scilab/contrib/financial b/debian/scilab-financial/usr/share/scilab/contrib/financial
new file mode 120000
index 0000000..3f879a8
--- /dev/null
+++ b/debian/scilab-financial/usr/share/scilab/contrib/financial
@@ -0,0 +1 @@
+../../../lib/scilab-financial
\ No newline at end of file
diff --git a/debian/source/format b/debian/source/format
new file mode 100644
index 0000000..163aaf8
--- /dev/null
+++ b/debian/source/format
@@ -0,0 +1 @@
+3.0 (quilt)
diff --git a/debian/watch b/debian/watch
new file mode 100644
index 0000000..d828544
--- /dev/null
+++ b/debian/watch
@@ -0,0 +1,4 @@
+# Compulsory line, this is a version 3 file
+version=3
+http://atoms.scilab.org/toolboxes/financial .*/files/financial-(.*)-src\.tar\.gz \
+ debian debian/orig-tar.sh
diff --git a/demos/bsgreeks.sce b/demos/bsgreeks.sce
new file mode 100644
index 0000000..7d484b6
--- /dev/null
+++ b/demos/bsgreeks.sce
@@ -0,0 +1,30 @@
+//
+// This help file was automatically generated from bsgreeks.sci using help_from_sci().
+// PLEASE DO NOT EDIT
+//
+mode(1)
+//
+// Demo of bsgreeks.sci
+//
+
+// We compute the Greeks on both a call and put option
+// with: underlying price 25 euros,
+// strike price 25 euros,
+// 0.01 (annual) riskless interest rate,
+// 3 month time to maturity (i.e. T=3/12),
+// and 0.2 (annual) volatility.
+[D,G,Th,R,V]=bsgreeks(25,25,0.01,3/12,0.2)
+V = 4.9727729;
+R = [3.0550246;-3.1793699];
+T = [2.1113101;1.8619344];
+G = 4.9727729;
+D = [0.5298926;-0.4701074];
+halt() // Press return to continue
+
+//========= E N D === O F === D E M O =========//
+//
+// Load this script into the editor
+//
+filename = "bsgreeks.sce";
+dname = get_absolute_file_path(filename);
+editor ( fullfile(dname,filename) );
diff --git a/demos/financial.dem.gateway.sce b/demos/financial.dem.gateway.sce
new file mode 100644
index 0000000..95485de
--- /dev/null
+++ b/demos/financial.dem.gateway.sce
@@ -0,0 +1,7 @@
+// This help file was automatically generated using helpupdate
+// PLEASE DO NOT EDIT
+demopath = get_absolute_file_path("financial.dem.gateway.sce");
+subdemolist = [
+"bsgreeks", "bsgreeks.sce"; ..
+];
+subdemolist(:,2) = demopath + subdemolist(:,2)
diff --git a/etc/financial.quit b/etc/financial.quit
new file mode 100644
index 0000000..e69de29
diff --git a/etc/financial.start b/etc/financial.start
new file mode 100644
index 0000000..a0f523d
--- /dev/null
+++ b/etc/financial.start
@@ -0,0 +1,34 @@
+mprintf("Start Financial module\n");
+
+if isdef("financiallib") then
+ warning("Financial module library is already loaded");
+ return;
+end
+
+etc_tlbx = get_absolute_file_path("financial.start");
+etc_tlbx = getshortpathname(etc_tlbx);
+root_tlbx = strncpy( etc_tlbx, length(etc_tlbx)-length("\etc\") );
+
+//Load functions library
+// =============================================================================
+
+mprintf("\tLoad macros\n");
+pathmacros = pathconvert( root_tlbx ) + "macros" + filesep();
+financiallib = lib(pathmacros);
+clear pathmacros;
+
+// Load and add help chapter
+// =============================================================================
+
+if or(getscilabmode() == ["NW";"STD"]) then
+ mprintf("\tLoad help\n");
+ path_addchapter = pathconvert(root_tlbx+"/jar");
+ if ( isdir(path_addchapter) <> [] ) then
+ add_help_chapter("Financial module", path_addchapter, %F);
+ clear add_help_chapter;
+ end
+ clear path_addchapter;
+end
+
+clear root_tlbx;
+clear etc_tlbx;
diff --git a/help/builder_help.sce b/help/builder_help.sce
new file mode 100644
index 0000000..1f9a40a
--- /dev/null
+++ b/help/builder_help.sce
@@ -0,0 +1 @@
+tbx_builder_help_lang("en_US",get_absolute_file_path("builder_help.sce"));
diff --git a/help/cleanhelp.sce b/help/cleanhelp.sce
new file mode 100644
index 0000000..c09ef90
--- /dev/null
+++ b/help/cleanhelp.sce
@@ -0,0 +1,11 @@
+// ====================================================================
+// 2010 - DIGITEO - Michael Baudin
+// This file is released into the public domain
+// ====================================================================
+libpath = get_absolute_file_path('cleanhelp.sce');
+
+exec(fullfile(libpath,"en_US","cleanhelp.sce"));
+
+clear libpath;
+
+// ====================================================================
diff --git a/help/en_US/0overview.xml b/help/en_US/0overview.xml
new file mode 100644
index 0000000..e4192a5
--- /dev/null
+++ b/help/en_US/0overview.xml
@@ -0,0 +1,129 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Copyright (C) 2009 - 2010 - Francesco Menoncin
+ * Copyright (C) 2010 - DIGITEO - Michael Baudin
+-->
+<refentry
+ version="5.0-subset Scilab"
+ xml:id="financial_overview"
+ xml:lang="fr"
+ xmlns="http://docbook.org/ns/docbook"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns:ns4="http://www.w3.org/1999/xhtml"
+ xmlns:mml="http://www.w3.org/1998/Math/MathML"
+ xmlns:db="http://docbook.org/ns/docbook">
+
+ <refnamediv>
+ <refname>financial_overview</refname>
+
+ <refpurpose>An overview of the Financial toolbox.</refpurpose>
+ </refnamediv>
+
+ <refsection>
+ <title>Purpose</title>
+
+ <para>
+ The module is dedicated to finance. There are three main areas that are covered:
+ <itemizedlist>
+ <listitem>
+ <para>
+ risk measure and management,
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ asset allocation,
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ pricing.
+ </para>
+ </listitem>
+ </itemizedlist>
+ </para>
+
+ <para>
+ For what concerns the risk measure, some functions are dedicated to the computation of Value at Risk (VaR)
+ and Expected Shortfall (ES).
+ Backtest is also implemented in order to check the goodness of such risk measures.
+ Both VaR and ES are also computed in an Extreme Value Theory framework (EVT).
+ Furthermore, it is possible to estimate the parameters of the EVT density function (through maximum likelihood).
+ The Mean Excess Function for graphical study of an EVT distribution is also implemented.
+ The interest rate risk is faced by functions aimed at computing duration, convexity, and yield to maturity.
+ Furthermore, Merton, Vasicek and Cox, Ingersoll and Ross interest rate models are implemented together with
+ the estimation of their parameters. Parametric interpolation of the interest rate curve is possible through
+ both Svennsons and Nelson-Siegels models.
+ Finally, some technical analysis indicators are implemented: Bollinger bands, moving averages, Hurst index.
+ </para>
+
+ <para>
+ The asset allocation problem is faced by two functions which compute:
+
+ <itemizedlist>
+ <listitem>
+ <para>
+ the optimal portfolio minimizing the variance of its return and
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ the optimal portfolio minimizing the expected shortfall of its return.
+ </para>
+ </listitem>
+ </itemizedlist>
+ In both cases, the portfolios with and without a riskless asset and with and without short selling are computed.
+ </para>
+
+ <para>
+ Pricing problem is approached through functions aimed at:
+ <itemizedlist>
+ <listitem>
+ <para>
+ computing the spread on Interest Rate Swaps,
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ computing the value of options in the Black and Scholes framework (with Greeks and implied volatility),
+ </para>
+ </listitem>
+ <listitem>
+ <para>
+ simulating stochastic processes (through Euler discretization).
+ </para>
+ </listitem>
+ </itemizedlist>
+ </para>
+
+ </refsection>
+
+ <refsection>
+ <title>Quick start</title>
+
+ <para>
+ TODO
+ </para>
+
+ <programlisting role="example">
+ <![CDATA[
+TODO
+ ]]>
+ </programlisting>
+ </refsection>
+
+ <refsection>
+ <title>Authors</title>
+
+ <para>
+ Copyright (C) 2009 - 2010 - Francesco Menoncin
+ </para>
+
+ <para>
+ Copyright (C) 2010 - DIGITEO - Michael Baudin
+ </para>
+
+ </refsection>
+
+</refentry>
diff --git a/help/en_US/backtest.xml b/help/en_US/backtest.xml
new file mode 100644
index 0000000..a44c8a9
--- /dev/null
+++ b/help/en_US/backtest.xml
@@ -0,0 +1,68 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:id="backtest" xml:lang="en">
+ <refnamediv>
+ <refname>backtest</refname>
+ <refpurpose>Apply the backtest to three different risk measures (as percentage of lost): Expected Shortfall, Value at Risk, and a Spectral Measure with linear spectrum. Show the graph of historical returns and the risk measures. The thresholds of the backtest are also computed.</refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <title>SYNOPSIS</title>
+ <synopsis>backtest (prices, alpha [, N])</synopsis>
+ </refsynopsisdiv>
+ <refsection>
+ <title>Description</title>
+ <para>Thia function checks the ability of three different risk measures (VaR, ES, and linear spectral) to suitably measure the shortfalls in asset returns.</para>
+ </refsection>
+ <refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry>
+ <term>prices</term>
+ <listitem>
+ <para>matrix whose columns contain the historical prices of each asset</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>alpha</term>
+ <listitem>
+ <para>confidence level of risk measures; it goes from 0 to 1 (both 0 and 1 excluded)</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>N</term>
+ <listitem>the number of observations which the backtest is computed on (default value 250 if there are more than 500 historical prices, else N is half the number of rows of the matrix "prices")</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Example</title>
+ <para>First we generate 10000 log-normally distributed prices for three different assets whose initial values are 25 euros, 50 euros, and 110 euros. First step is the creation of a 10000x3 matrix of normal random variables (with mean 0.1/250 and standard deviation 0.2/sqrt(250))</para>
+ <para>-->M=grand(10000,3,'nor',0.1/250,0.2/sqrt(250));</para>
+ <para>Then we create the prices</para>
+ <para>-->prices=exp(cumsum(M,1))*diag([25 50 110])</para>
+ <para>and apply the function with an alpha, for instance, equal to 0.01:</para>
+ <para>-->backtest(prices,0.01);</para>
+ <para>The result is:</para>
+ <para>!Green zone: 0-5 ! </para>
+ <para>!Yellow zone: 5-10 ! </para>
+ <para>!Red zone: 10- !</para>
+ <para>!ES: 1 exeptions !</para>
+ <para>!VaR: 4 exeptions !</para>
+ <para>!Linear Spectrum: 1 exeptions !</para>
+ <para>Which shows that the ES and the Linear Spectral measure are very reliable (since they present only 1 exeption), while the VaR is the less reliable. The figure which is created shows the same result is graphical form.</para>
+ </refsection>
+ <refsection>
+ <title>Authors</title>
+ <para>Francesco Menoncin - Brescia University - 2010</para>
+ </refsection>
+ <refsection>
+ <title>See Also</title>
+ <simplelist type="inline">
+ <member>
+ <link linkend="esvarlin">esvarlin</link>
+ </member>
+ <member>
+ <link linkend="esvaroptim">esvaroptim</link>
+ </member>
+ </simplelist>
+ </refsection>
+</refentry>
diff --git a/help/en_US/bollinger.xml b/help/en_US/bollinger.xml
new file mode 100644
index 0000000..b7619bc
--- /dev/null
+++ b/help/en_US/bollinger.xml
@@ -0,0 +1,49 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:id="bollinger" xml:lang="en">
+ <refnamediv>
+ <refname>bollinger</refname>
+ <refpurpose>Given a moving average on the historical prices of an asset, the function creates two figures: in the first both the historical prices and the Bollinger bands (i.e. the moving average +/- "a" times the price standard deviation) are shown, in the second the so-called b-percentage is shown </refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <title>SYNOPSIS</title>
+ <synopsis>bollinger (prices, m, a)</synopsis>
+ </refsynopsisdiv>
+ <refsection>
+ <title>Description</title>
+ <para>Function which creates two graphs: one with the Bollinger bands and one with the b-percentage index</para>
+ </refsection>
+ <refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry>
+ <term>prices</term>
+ <listitem>
+ <para>column vector containing the historical prices of an asset</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>m</term>
+ <listitem>
+ <para>the lenght (in days if "prices" contains daily values) of the moving average which the bands are based on</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>a</term>
+ <listitem>factor which multiplies the standard deviation of historical prices for creating the bands around the mean</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection><title>Example</title><para>First we generate 1000 log-normally distributed prices for an asset whose initial values is 25 euros. First step is the creation of 1000 normal random variables (with mean 0.1/250 and standard deviation 0.2/sqrt(250))</para>-->M=grand(1000,1,'nor',0.1/250,0.2/sqrt(250));<para>Then we create the prices</para><para>-->prices=exp(cumsum(M,1))*25</para><para>and apply the function with m=100 days and a=2.5 times:</para><para>-->bol [...]
+ <refsection>
+ <title>Authors</title>
+ <para>Francesco Menoncin - Brescia University - 2010</para>
+ </refsection>
+ <refsection>
+ <title>See Also</title>
+ <simplelist type="inline">
+ <member>
+ <link linkend="movav">movav</link>
+ </member>
+ </simplelist>
+ </refsection>
+</refentry>
diff --git a/help/en_US/bsgreeks.xml b/help/en_US/bsgreeks.xml
new file mode 100644
index 0000000..e730ce8
--- /dev/null
+++ b/help/en_US/bsgreeks.xml
@@ -0,0 +1,106 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ *
+ * This help file was generated from bsgreeks.sci using help_from_sci().
+ *
+ -->
+
+<refentry version="5.0-subset Scilab" xml:id="bsgreeks" xml:lang="en"
+ xmlns="http://docbook.org/ns/docbook"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns:ns3="http://www.w3.org/1999/xhtml"
+ xmlns:mml="http://www.w3.org/1998/Math/MathML"
+ xmlns:db="http://docbook.org/ns/docbook">
+
+
+ <refnamediv>
+ <refname>bsgreeks</refname><refpurpose>Compute the Greeks for both a call and a put option in a Black and Scholes model.</refpurpose>
+ </refnamediv>
+
+
+
+<refsynopsisdiv>
+ <title>Calling Sequence</title>
+ <synopsis>
+ [delta,gama,theta,rho,vega]=bsgreeks(S,K,r,T,sigma)
+
+ </synopsis>
+</refsynopsisdiv>
+
+<refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry><term>S :</term>
+ <listitem><para> a 1-by-1 matrix of doubles, current price of the underlying asset</para></listitem></varlistentry>
+ <varlistentry><term>K :</term>
+ <listitem><para> a 1-by-1 matrix of doubles, strike price of the option</para></listitem></varlistentry>
+ <varlistentry><term>r :</term>
+ <listitem><para> a 1-by-1 matrix of doubles, riskless interest rate (assumed to be constant until the maturity)</para></listitem></varlistentry>
+ <varlistentry><term>T :</term>
+ <listitem><para> a 1-by-1 matrix of doubles, time to maturity; it must be in the same time unit of measure as the riskless interest rate (if the riskless interest rate is annual, then an option with maturity of 3 months must have T=3/12)</para></listitem></varlistentry>
+ <varlistentry><term>sigma :</term>
+ <listitem><para> a 1-by-1 matrix of doubles, volatility of the underlying (log-) returns; it must be in the same time unit of measure as the riskless interest rate</para></listitem></varlistentry>
+ <varlistentry><term>delta :</term>
+ <listitem><para> a 2-by-1 matrix of doubles, the first derivative of the call (first term) and put (second term) option prices with respect to the underlying asset price</para></listitem></varlistentry>
+ <varlistentry><term>gama :</term>
+ <listitem><para> a 1-by-1 matrix of doubles, second derivative of the call (or put) option price with respect to the underlying asset price</para></listitem></varlistentry>
+ <varlistentry><term>theta :</term>
+ <listitem><para> a 2-by-1 matrix of doubles, vector containing the first derivative of the call (first term) and put (second term) option prices with respect to the time to maturity</para></listitem></varlistentry>
+ <varlistentry><term>rho :</term>
+ <listitem><para> a 2-by-1 matrix of doubles, vector containing the first derivative of the call (first term) and put (second term) option prices with respect to the riskless interest rate</para></listitem></varlistentry>
+ <varlistentry><term>vega :</term>
+ <listitem><para> a 1-by-1 matrix of doubles, first derivative of the call (or put) option price with respect to the standard deviation of the underlying (log-) returns</para></listitem></varlistentry>
+ </variablelist>
+</refsection>
+
+<refsection>
+ <title>Description</title>
+ <para>
+Computes the Greeks of both call and put option in a Black and Scholes framework
+ </para>
+ <para>
+</para>
+</refsection>
+
+<refsection>
+ <title>Examples</title>
+ <programlisting role="example"><![CDATA[
+// We compute the Greeks on both a call and put option
+// with: underlying price 25 euros,
+// strike price 25 euros,
+// 0.01 (annual) riskless interest rate,
+// 3 month time to maturity (i.e. T=3/12),
+// and 0.2 (annual) volatility.
+[D,G,Th,R,V]=bsgreeks(25,25,0.01,3/12,0.2)
+V = 4.9727729;
+R = [3.0550246;-3.1793699];
+T = [2.1113101;1.8619344];
+G = 4.9727729;
+D = [0.5298926;-0.4701074];
+
+ ]]></programlisting>
+</refsection>
+
+<refsection>
+ <title>Authors</title>
+ <simplelist type="vert">
+ <member>Copyright (C) 2009 - 2010 - Francesco Menoncin</member>
+ <member>Copyright (C) 2010 - DIGITEO - Michael Baudin</member>
+ </simplelist>
+</refsection>
+
+<refsection>
+ <title>Bibliography</title>
+ <para>TODO</para>
+</refsection>
+
+<refsection>
+ <title>See also</title>
+ <simplelist type="inline">
+ <member><link linkend="bsoption">bsoption</link></member>
+ <member><link linkend="bsimpvol">bsimpvol</link></member>
+ </simplelist>
+</refsection>
+</refentry>
diff --git a/help/en_US/bsimpvol.xml b/help/en_US/bsimpvol.xml
new file mode 100644
index 0000000..d17dd38
--- /dev/null
+++ b/help/en_US/bsimpvol.xml
@@ -0,0 +1,92 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:id="bsimpvol" xml:lang="en">
+ <refnamediv>
+ <refname>bsimpvol</refname>
+ <refpurpose>Compute the implied volatility in a Black and Scholes framework. The function computes the volatility by equating the theoretical value of an option (with both constant riskless interest rate and volatility) to its market value.</refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <title>SYNOPSIS</title>
+ <synopsis>[sigmaC,sigmaP]=bsimpvol(option,S,K,r,T,sigma0);</synopsis>
+ </refsynopsisdiv>
+ <refsection>
+ <title>Description</title>
+ <para>Compute the Black and Scholes implied volatility </para>
+ </refsection>
+ <refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry>
+ <term>option</term>
+ <listitem>
+ <para>the market price of an option (either put or call)</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>S</term>
+ <listitem>
+ <para>current price of the underlying asset</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>K</term>
+ <listitem>
+ <para>strike price of the option</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>r</term>
+ <listitem>riskless interest rate (assumed to be constant until the maturity)</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>T</term>
+ <listitem>time to maturity; it must be in the same time unit of measure as the riskless interest rate (if the riskless interest rate is annual, then an option with maturity of 3 months must have T=3/12)</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>sigma0</term>
+ <listitem>the value of the volatility the solver must start from (it is a guess value)</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Output</title>
+ <variablelist>
+ <varlistentry>
+ <term>sigmaC</term>
+ <listitem>
+ <para>implicit volatility of a call option; the function writes "Call: good convergence" if the solver finds a good value for the implicit volatility, instead it writes "Call: bad convergence"</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>sigmaP</term>
+ <listitem>implicit volatility of a put option; the function writes "Put: good convergence" if the solver finds a good value for the implicit volatility, instead it writes "Put: bad convergence"</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Example</title>
+ <para>We assume that an option (eithe call or put) is worth 1.09 euros on the market. It is written on an asset whose value is 25 euros, with a strike price of 25 euros. If the (annual) riskless interest rate is 0.001 and the time to maturity is 3 months, then the implicit volatility is computed with the following command.</para>
+ <para>-->[sigmaC,sigmaP]=bsimpvol(1.09,25,25,0.001,3/12,0.1) </para>
+ <para>Call: good convergence </para>
+ <para>Put: good convergence</para>
+ <para> sigmaP = 0.2193413</para>
+ <para> sigmaC = 0.2180861 </para>
+ </refsection>
+ <refsection>
+ <title>Authors</title>
+ <para>Francesco Menoncin - Brescia University - 2010</para>
+ </refsection>
+ <refsection>
+ <title>See Also</title>
+ <simplelist type="inline">
+ <member>
+ <link linkend="bsoption">bsoption</link>
+ </member>
+ <member>
+ <link linkend="bsimpvol">bsimpvol</link>
+ </member>
+ <member>
+ <link linkend="fsolve">fsolve</link>
+ </member>
+ </simplelist>
+ </refsection>
+</refentry>
diff --git a/help/en_US/bsoption.xml b/help/en_US/bsoption.xml
new file mode 100644
index 0000000..ac19601
--- /dev/null
+++ b/help/en_US/bsoption.xml
@@ -0,0 +1,79 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:id="bsoption" xml:lang="en">
+ <refnamediv>
+ <refname>bsoption</refname>
+ <refpurpose>Compute the value of both a call and a put option in a Black and Scholes framework (with both constant riskless interest rate and volatility)</refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <title>SYNOPSIS</title>
+ <synopsis>[C,P]=bsoption(S,K,r,T,sigma);</synopsis>
+ </refsynopsisdiv>
+ <refsection>
+ <title>Description</title>
+ <para>Compute the Black and Scholes value of both a call and a put option</para>
+ </refsection>
+ <refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry>
+ <term>S</term>
+ <listitem>
+ <para>current price of the underlying asset</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>K</term>
+ <listitem>
+ <para>strike price of the option</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>r</term>
+ <listitem>riskless interest rate (assumed to be constant until the maturity)</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>T</term>
+ <listitem>time to maturity; it must be in the same time unit of measure as the riskless interest rate (if the riskless interest rate is annual, then an option with maturity of 3 months must have T=3/12)</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>sigma</term>
+ <listitem>the volatility of the underlying (log-) returns; it must have the same time unit of measure as the riskless interest rate</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Output</title>
+ <variablelist>
+ <varlistentry>
+ <term>C</term>
+ <listitem>value of a call option</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>P</term>
+ <listitem>value of a put option</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Example</title>
+ <para>We assume that an option (either call or put) is written on an asset whose value is 25 euros, with a strike price of 25 euros. If the (annual) riskless interest rate is 0.001, the time to maturity is 3 months, and the (annual) volatility of the underlying (log-) returns is 0.22, then the value of the call and the put options are computed as follows.</para>
+ <para>-->[C,P]=bsoption(25,25,0.001,3/12,0.22)</para>
+ <para> P = 1.0932796</para>
+ <para> C = 1.0995288</para>
+ </refsection>
+ <refsection>
+ <title>Authors</title>
+ <para>Francesco Menoncin - Brescia University - 2010</para>
+ </refsection>
+ <refsection>
+ <title>See Also</title>
+ <simplelist type="inline">
+ <member>
+ <link linkend="bsgreeks">bsgreeks</link>
+ </member>
+ <member>
+ <link linkend="bsimpvol">bsimpvol</link>
+ </member>
+ </simplelist>
+ </refsection>
+</refentry>
diff --git a/help/en_US/build_help.sce b/help/en_US/build_help.sce
new file mode 100644
index 0000000..db4ad3d
--- /dev/null
+++ b/help/en_US/build_help.sce
@@ -0,0 +1 @@
+tbx_build_help("Financial module",get_absolute_file_path("build_help.sce"));
diff --git a/help/en_US/cfr.xml b/help/en_US/cfr.xml
new file mode 100644
index 0000000..eb996f2
--- /dev/null
+++ b/help/en_US/cfr.xml
@@ -0,0 +1,85 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:id="cfr" xml:lang="en">
+ <refnamediv>
+ <refname>cfr</refname>
+ <refpurpose>compare two or more time series of data and eliminate the elements which do not have the same date</refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <title>SYNOPSIS</title>
+ <synopsis>[S]=cfr(S1,S2[,S3,S4,...]);</synopsis>
+ </refsynopsisdiv>
+ <refsection>
+ <title>Description</title>
+ <para>Compare time series and make them homogeneous with respect to the dates (by eliminating the elements which do not have the same date)</para>
+ </refsection>
+ <refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry>
+ <term>S1</term>
+ <listitem>
+ <para>two column matrix: the first column must be a list of dates, while the second column must contain data</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>S2</term>
+ <listitem>
+ <para>two column matrix: the first column must be a list of dates, while the second column must contain data</para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>S3, S4,...</term>
+ <listitem>any other two-column matrix as the previous ones</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Output</title>
+ <variablelist>
+ <varlistentry>
+ <term>S</term>
+ <listitem>a matrix whose first column contains the dates, while the other columns contain the series of data</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Example</title>
+ <para>First we create two time series with the following commands</para>
+ <para>-->S1=[datenum(2010*ones(10,1),ones(10,1),[1:10]') [1:10]'] </para>
+ <para>S1 = 734139. 1. </para>
+ <para>734140. 2. </para>
+ <para>734141. 3. </para>
+ <para>734142. 4. </para>
+ <para>734143. 5. </para>
+ <para>734144. 6. </para>
+ <para>734145. 7. </para>
+ <para>734146. 8. </para>
+ <para>734147. 9. </para>
+ <para>734148. 10. </para>
+ <para>-->S2=[datenum(2010*ones(5,1),ones(5,1),[1:2:10]') [1:2:10]'*5+4] </para>
+ <para>S2 = 734139. 9. </para>
+ <para>734141. 19. </para>
+ <para>734143. 29. </para>
+ <para>734145. 39. </para>
+ <para>734147. 49. </para>
+ <para>Then we use the function for selecting, from these time series, only the data which compare in both of them</para>
+ <para>-->S=cfr(S1,S2)</para>
+ <para>S = 734139. 1. 9. </para>
+ <para>734141. 3. 19. </para>
+ <para>734143. 5. 29. </para>
+ <para>734145. 7. 39. </para>
+ <para>734147. 9. 49. </para>
+ </refsection>
+ <refsection>
+ <title>Authors</title>
+ <para>Francesco Menoncin - Brescia University - 2010</para>
+ </refsection>
+ <refsection>
+ <title>See Also</title>
+ <simplelist type="inline">
+ <member>
+ <link linkend="datenum">datenum</link>
+ </member>
+ </simplelist>
+ </refsection>
+</refentry>
diff --git a/help/en_US/duration.xml b/help/en_US/duration.xml
new file mode 100644
index 0000000..9a2ef97
--- /dev/null
+++ b/help/en_US/duration.xml
@@ -0,0 +1,68 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:id="duration" xml:lang="en">
+ <refnamediv>
+ <refname>duration</refname>
+ <refpurpose>given a set of cash flows (either positive of negative) from an investment and the dates at which they are available, the function computes: the duration of the cash flows, the convexity of the cash flows, and the yield-to-maturity "ytm" (both duration and convexity are computed by taking ytm as the discount rate)</refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <title>SYNOPSIS</title>
+ <synopsis>[dur,con,ytm]=duration(t,c);</synopsis>
+ </refsynopsisdiv>
+ <refsection>
+ <title>Description</title>
+ <para>On cash flows available at given dates, duration, convexity and yield to maturity are computed</para>
+ </refsection>
+ <refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry>
+ <term>t</term>
+ <listitem>column vector of dates at which cash flows are available: the first element must be zero; time unit of measure is generally the year</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>c</term>
+ <listitem>column vector containing the cash flows; the first element must be the cost of the investment (and it must be a negative number)</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Output</title>
+ <variablelist>
+ <varlistentry>
+ <term>dur</term>
+ <listitem>duration (weighted time to maturity) of the cash flows; this output has the same time unit of measure of the input "t"</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>con</term>
+ <listitem>convexity (weighted square time to maturity) of the cash flows; this output has the same time unit of measure of the input "t"</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>ytm</term>
+ <listitem>yield to maturity (i.e. internal rate of return) of the cash flows; this output has the same time unit of measure of the input "t"; this value is computed with the fsolve function; if the convergence of the algorithm is not good, a message is shown</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Example</title>
+ <para>A bond, whose value on the market is 101.5, pays a cash flow of 2.5 euros any six month (i.e. 1/2 year) and for the next 2 years. At maturity it pays also its face value of 100 euros. Let us compute duration, convexity, and yield-to-maturity.</para>
+ <para>At first we define the vector of dates and cash flows</para>
+ <para>-->t=[0 0.5 1 1.5 2]';</para>
+ <para>-->c=[-101.5 2.5 2.5 2.5 102.5]';</para>
+ <para>-->[D,C,Y]=duration(t,c)</para>
+ <para>Y = 0.0425443</para>
+ <para>C = 3.7981714</para>
+ <para>D = 1.9286213 </para>
+ </refsection>
+ <refsection>
+ <title>Authors</title>
+ <para>Francesco Menoncin - Brescia University - 2010</para>
+ </refsection>
+ <refsection>
+ <title>See Also</title>
+ <simplelist type="inline">
+ <member>
+ <link linkend="fsolve">fsolve</link>
+ </member>
+ </simplelist>
+ </refsection>
+</refentry>
diff --git a/help/en_US/esvarevt.xml b/help/en_US/esvarevt.xml
new file mode 100644
index 0000000..d1d73c0
--- /dev/null
+++ b/help/en_US/esvarevt.xml
@@ -0,0 +1,99 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:id="esvarevt" xml:lang="en">
+ <refnamediv>
+ <refname>esvarevt</refname>
+ <refpurpose>Compute both Expected Shortfall and Value at Risk by using the Extreme Value Theory. Furthermore, also the parameter of the Generalized Pareto Distribution are estimated with the Maximum Likelihood method</refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <title>SYNOPSIS</title>
+ <synopsis>[es,var,xoptim,v,inf]=esvarevt(x0,data,u,alpha);</synopsis>
+ </refsynopsisdiv>
+ <refsection>
+ <title>Description</title>
+ <para>The Extreme Value Theory assumes that a phenomenon has a uniform distribution before a given threshold "u", while after this threshold it follows a Generalized Pareto Distribution having the form</para>
+ <para>f(x) = (1+xi*(x-u)/beta)^(-1/xi-1)/beta</para>
+ <para>This function estimates both "xi" and "beta" on the data (by Maximum Likelihood) and computes both the Expected Shortfall and the Value at Risk by using this density function.</para>
+ </refsection>
+ <refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry>
+ <term>x0</term>
+ <listitem>guess values used by the fsolve function for estimating the parameters "xi" and "beta" of the Generalized Pareto Distribution (Maximum Likelihood estimation)</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>data</term>
+ <listitem>vector containing the historical data; these can be, for instance, prices or returns</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>u</term>
+ <listitem>threshold above which the data are assumed to follow the Generalized Pareto Distribution</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>alpha</term>
+ <listitem>confidence level at which all the risk measures must be computed; this value must strictly stay between 0 and 1 (and cannot be neither 0 nor 1)</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Output</title>
+ <variablelist>
+ <varlistentry>
+ <term>ES</term>
+ <listitem>expected shortfall, i.e. the mean of the data exceeding the alpha-quantile of the Generalized Pareto Distribution (on the right tail). The unit of measure is the same as that used for "data" (i.e. if data are returns, then this ES is expressed as a return)</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>VaR</term>
+ <listitem>value at risk, i.e. the loss coinciding with the alpha-quantile of the Generalized Pareto Distribution (on the right tail). The unit of measure is the same as that used for "data"</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>xoptim</term>
+ <listitem>estimated values (with maximum likelihood) of parameters "xi" and "beta" of the Generalized Pareto Distribution</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>v</term>
+ <listitem>value of the gradient of the likelihood function (it should be as close as possible to zero)</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>inf</term>
+ <listitem>same meaning as "inf" in the "fsolve" function</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Example</title>
+ <para>
+ <para>First we generate 1000 random numbers taken from a Generalized Pareto Distribution. First step is the creation of a vector of 1000 uniformly distributed random variables:</para>
+ <para>-->U=grand(1000,1,'def');</para>
+ <para>then we create the random variables from the GPD with parameters u=0.0001; xi=0.5; beta=0.00015:</para>
+ <para>-->x=0.0001-0.00015/0.5+0.00015/0.5*(1-U)^(-0.5);</para>
+ </para>
+ <para>These data could be daily return on an asset. Now we can use the function on vector x for computing ES and VaR at, for instance, 0.01 confidence level</para>
+ <para>-->[es,var,xoptim,v,inf]=esvarevt([0.2 0.0002],x,0.0001,0.01) </para>
+ <para>inf = 1. </para>
+ <para>v = 1.0D-12 * </para>
+ <para>- 1.8189894 - 0.0017764 </para>
+ <para>xoptim = 0.5020924 0.0001470 </para>
+ <para>var = 0.0027625 </para>
+ <para>es = 0.0057426 </para>
+ <para>We can see that the convergence is good (please note that the algorithm is very sensitive to the initial condition x0). The estimated values of "xi" and "beta" are close to the true ones.</para>
+ </refsection>
+ <refsection>
+ <title>Authors</title>
+ <para>Francesco Menoncin - Brescia University - 2010</para>
+ </refsection>
+ <refsection>
+ <title>See Also</title>
+ <simplelist type="inline">
+ <member>
+ <link linkend="esvaroptim">esvaroptim</link>
+ </member>
+ <member>
+ <link linkend="fsolve">fsolve</link>
+ </member>
+ <member>
+ <link linkend="esvarevt">esvarevt</link>
+ </member>
+ </simplelist>
+ </refsection>
+</refentry>
diff --git a/help/en_US/esvarlin.xml b/help/en_US/esvarlin.xml
new file mode 100644
index 0000000..53e0e35
--- /dev/null
+++ b/help/en_US/esvarlin.xml
@@ -0,0 +1,77 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:id="esvarlin" xml:lang="en">
+ <refnamediv>
+ <refname>esvarlin</refname>
+ <refpurpose>Compute three risk measures on historical prices of a set of assets, and at a given confidence level. The three risk measures are: Expected Shortfall (ES), Value at Risk (VaR) and a Linear Spectral risk measure (lin).</refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <title>SYNOPSIS</title>
+ <synopsis>[ES,VaR,L]=esvarlin(prices,alpha);</synopsis>
+ </refsynopsisdiv>
+ <refsection>
+ <title>Description</title>
+ <para>On historical prices of some assets compute three risk measures at a given confidence level. The three measures are: Expected Shortfall (the mean of the losses exceeding a given quantile), Value at Risk (coinciding with a quantile), and a Linear Spectral risk measure whose spectrum linearly decreases for losses exceeding a given quantile (the same used for the previous risk measures)</para>
+ </refsection>
+ <refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry>
+ <term>prices</term>
+ <listitem>any column of this matrix contains the historical prices of an asset</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>alpha</term>
+ <listitem>confidence level at which all the risk measures must be computed; this value must strictly stay between 0 and 1 (and cannot be neither 0 nor 1)</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Output</title>
+ <variablelist>
+ <varlistentry>
+ <term>ES</term>
+ <listitem>expected shortfall (as a percentage of the last price), i.e. the mean of the losses exceeding the alpha-quantile</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>VaR</term>
+ <listitem>value at risk (as percentage of the last price), i.e. the loss coinciding with the alpha-quantile</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>L</term>
+ <listitem>the wighted mean of the losses exceeding the alpha-quantile (the weights linearly decrease); as a percentage of last price</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Example</title>
+ <para>
+ <para>First we generate 1000 log-normally distributed prices for three different assets whose initial values are 25 euros, 50 euros, and 110 euros. First step is the creation of a 1000x3 matrix of normal random variables (with mean 0.1/250 and standard deviation 0.2/sqrt(250))</para>
+ <para>-->M=grand(1000,3,'nor',0.1/250,0.2/sqrt(250));</para>
+ <para>Then we create the prices</para>
+ <para>-->prices=exp(cumsum(M,1))*diag([25 50 110]);</para>
+ </para>
+ <para>Now the three risk measures are computed</para>
+ <para>-->[ES,VaR,L]=esvarlin(prices,0.01) </para>
+ <para>L = 0.0365767 0.0327525 0.0351212 </para>
+ <para>VaR = 0.0274819 0.0281535 0.0281464 </para>
+ <para>ES = 0.0331532 0.0309606 0.0323584 </para>
+ </refsection>
+ <refsection>
+ <title>Authors</title>
+ <para>Francesco Menoncin - Brescia University - 2010</para>
+ </refsection>
+ <refsection>
+ <title>See Also</title>
+ <simplelist type="inline">
+ <member>
+ <link linkend="esvaroptim">esvaroptim</link>
+ </member>
+ <member>
+ <link linkend="backtest">backtest</link>
+ </member>
+ <member>
+ <link linkend="esvarevt">esvarevt</link>
+ </member>
+ </simplelist>
+ </refsection>
+</refentry>
diff --git a/help/en_US/esvaroptim.xml b/help/en_US/esvaroptim.xml
new file mode 100644
index 0000000..f687bf7
--- /dev/null
+++ b/help/en_US/esvaroptim.xml
@@ -0,0 +1,105 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:id="esvaroptim" xml:lang="en">
+ <refnamediv>
+ <refname>esvaroptim</refname>
+ <refpurpose>Compute the optimal portfolio minimizing the Expected Value (this is a linear programming problem). The Value at Risk of the portfolio is also computed (this implements the Rockafeller-Uryasev algorithm)</refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <title>SYNOPSIS</title>
+ <synopsis>[w,ES,VaR]=esvaroptim(price,ER,r,dt,alpha);</synopsis>
+ </refsynopsisdiv>
+ <refsection>
+ <title>Description</title>
+ <para>Give the historical prices of a set of assets, compute the optimal portfolios solving four different problems. All of them minimize the Expected Shortfall subject to the constraint of having given expected return. The four problems are different for the following characteristics</para>
+ <para>1) optimal portfolio allowing short selling and investing in the riskless asset;</para>
+ <para>2) optimal portfolio allowing short selling but without investing in the riskless asset;</para>
+ <para>3) optimal portfolio not allowing short selling and investing in the riskless asset;</para>
+ <para>4) optimal portfolio not allowing short selling and without investing in the riskless asset.</para>
+ <para>Finally the Vale at Risk of the optimal portfolio is computed. The procedure uses "qld" function.</para>
+ </refsection>
+ <refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry>
+ <term>price</term>
+ <listitem>matrix whose columns contains the historical prices of the assets in the portfolio</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>ER</term>
+ <listitem>expected return that the investor wants to obtain on his portfolio</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>r</term>
+ <listitem>riskless interest rate</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>dt</term>
+ <listitem>time frequency of the prices with respect to the time unit of measure of both "ER" and "r"; if the matrix of prices contains daily data and both "ER" and "r" are annual return, then dt=1/250 since there are 250 working day in one year</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>alpha</term>
+ <listitem>confidence level at which both Expected Shortfall and Value at Risk must be computed (it must be between 0 and 1, with 0 and 1 both excluded)</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Output</title>
+ <variablelist>
+ <varlistentry>
+ <term>w</term>
+ <listitem>matrix containing the optimal portfolios; in particular:</listitem>
+ <listitem>first raw: with short selling and with r</listitem>
+ <listitem>second raw: with short selling and without r</listitem>
+ <listitem>third raw: without short selling and with r</listitem>
+ <listitem>fourth raw: without short selling and without r</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>ES</term>
+ <listitem>Expected Shortfall of the optimal portfolio (at alpha confidence level)</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>VaR</term>
+ <listitem>Value at Risk of the optimal portfolio (at alpha confidence level)</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Example</title>
+ <para>
+ <para>First we generate 1000x3 log-normally distributed daily asset prices with 0.1/250 mean and 0.2/sqrt(250) variance. The first prices of the three assets are 25 euros, 50 euros, and 110 euros respectively.</para>
+ <para>-->M=grand(1000,3,'nor',0.1/250,0.2/sqrt(250));</para>
+ <para>-->price=exp(cumsum(M,1))*diag([25 50 110]);</para>
+ </para>
+ <para>Now we can use the function on these prices.</para>
+ <para>-->[w,ES,VaR]=esvaroptim(price,0.05,0.01,1/250,0.01) </para>
+ <para>Draw frontier? (y/n) y </para>
+ <para>! with short selling without short selling !</para>
+ <para>! with r without r with r without r ! </para>
+ <para>VaR = 0.0122548 0.0178937 0.0135530 0.0178937 </para>
+ <para>ES = 0.0135257 0.0208130 0.0153525 0.0208130 </para>
+ <para>w = 0.3180045 0.5742962 0.4706583 0.5742962</para>
+ <para>0.1079194 0.2480433 0.1313949 0.2480433 </para>
+ <para>- 0.1904050 0.1776605 0. 0.1776605 </para>
+ <para>We see that the third asset is sold (negative portfolio component) when it is possible. If short selling is not allowed, then its weight is either positive or zero.</para>
+ <para>The function also asks if one wants to see the optimal frontiers (this is optional since the procedure takes some time). The figure which is created shows four frontiers corresponding to the four different problems (the legend explains the meanings).</para>
+ </refsection>
+ <refsection>
+ <title>Bibliography</title>
+ <para>"Optimization of Conditional Value-at-Risk", Rockafeller, R. T. and Uryasev, S., Journal of Risk, 2, 21-41, 2000</para>
+ </refsection>
+ <refsection>
+ <title>Authors</title>
+ <para>Francesco Menoncin - Brescia University - 2010</para>
+ </refsection>
+ <refsection>
+ <title>See Also</title>
+ <simplelist type="inline">
+ <member>
+ <link linkend="esvarevt">esvarevt</link>
+ </member>
+ <member>
+ <link linkend="qld">qld</link>
+ </member>
+ </simplelist>
+ </refsection>
+</refentry>
diff --git a/help/en_US/euler.xml b/help/en_US/euler.xml
new file mode 100644
index 0000000..ba47c6f
--- /dev/null
+++ b/help/en_US/euler.xml
@@ -0,0 +1,80 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:id="euler" xml:lang="en">
+ <refnamediv>
+ <refname>euler</refname>
+ <refpurpose>Numerically solves a system of stochastic differential equation (by using the Euler discretization)</refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <title>SYNOPSIS</title>
+ <synopsis>x=euler(drift,diffusion,dt,T,x0,t0);</synopsis>
+ </refsynopsisdiv>
+ <refsection>
+ <title>Description</title>
+ <para>The function numerically solves a system of stochastic differential equations in the following form:</para>
+ <para>dx(1) = drift_1(x(1),x(2),..,x(n),t) dt + diffusion_1(x(1),x(2),..,x(n),t) dW</para>
+ <para>dx(2) = drift_2(x(1),x(2),..,x(n),t) dt + diffusion_2(x(1),x(2),..,x(n),t) dW</para>
+ <para>...</para>
+ <para>dx(n) = drift_n(x(1),x(2),..,x(n),t) dt + diffusion_n(x(1),x(2),..,x(n),t) dW</para>
+ <para>Please note that dW (the differential form of a Wiener process) could be a vector and, accordingly, each "diffusion" term could be a vector itself. All the elements of dW are assumed to be independent.</para>
+ </refsection>
+ <refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry>
+ <term>drift</term>
+ <listitem>this is a string containing a column vector of the functional forms of drift_1, drift_2 and so on. The variables "x" and "t" must be named exactly "x" and "t" and if there are more than one "x" the values must be named "x(1)", "x(2)", and so on.</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>diffusion</term>
+ <listitem>This is a string containing a matrix which have as many raws as x's and as many columns as the elements of vector dW (containing the so-called risk sources). Thus, if there are three stochastic variables (i.e. x(1), x(2), and x(3)) driven by two risk sources (i.e. dW(1) and dW(2)) the "diffusion" is a 3x2 matrix </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>dt</term>
+ <listitem>time unit of measure: if data are in annual form (like returns, for instance) but have daily frequency, then dt=1/250 (since there are 250 working day in one year)</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>T</term>
+ <listitem>number of periods during which the stochastic differential equations must be solved (if T=2 years, and dt=1/250, then the function computes 500 values)</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>x0, t0</term>
+ <listitem>initial values for the variables "x" and for time "t". These are the values the Euler algorithm must start from. x0 must be a column vector, while t is a scalar</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Output</title>
+ <variablelist>
+ <varlistentry>
+ <term>x</term>
+ <listitem>matrix whose columns contain the series of simulated variable "x"</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Example</title>
+ <para>
+ <para>Let us assume a stochastic mean reverting process for the interest rate "r":</para>
+ <para>dr = 0.1 (b - r) dt + 0.056 sqrt(r) dWr</para>
+ <para>where the parameter "b" is another mean reverting process</para>
+ <para>db = 0.2 (0.05 - b) dt + 0.01 sqrt(b) dWb</para>
+ </para>
+ <para>In order to simulate two years of daily data starting from 0.04 for both "r" and "b" at time t=0, we must give the following command (we assume x(1)=r and x(2)=b)</para>
+ <para>-->drift='[0.1*(x(2)-x(1)); 0.2*(0.05-x(2))]';</para>
+ <para>-->diffusion='[0.056*sqrt(x(1)),0;0,0.01*sqrt(x(2))]';</para>
+ <para>-->x=euler(drift,diffusion,1/250,2,[0.04;0.04],0)</para>
+ <para>With command "plot(x)" one can see both stochastic processes</para>
+ </refsection>
+ <refsection>
+ <title>Authors</title>
+ <para>Francesco Menoncin - Brescia University - 2010</para>
+ </refsection>
+ <refsection>
+ <title>See Also</title>
+ <simplelist type="inline">
+ <member>
+ <link linkend="gbm">gbm</link>
+ </member>
+ </simplelist>
+ </refsection>
+</refentry>
diff --git a/help/en_US/evt.xml b/help/en_US/evt.xml
new file mode 100644
index 0000000..b1975b1
--- /dev/null
+++ b/help/en_US/evt.xml
@@ -0,0 +1,82 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:id="evt" xml:lang="en">
+ <refnamediv>
+ <refname>evt</refname>
+ <refpurpose>Estimate the parameters of the Generalized Pareto Distribution with the Maximum Likelihood method</refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <title>SYNOPSIS</title>
+ <synopsis>[xoptim,v,inf]=evt(x0,x,u)</synopsis>
+ </refsynopsisdiv>
+ <refsection>
+ <title>Description</title>
+ <para>For data (x) higher than a threshold "u", the Generalized Pareto Distribution have the form</para>
+ <para>f(x) = (1+xi*(x-u)/beta)^(-1/xi-1)/beta</para>
+ <para>This function estimates both "xi" and "beta" on the data (by Maximum Likelihood).</para>
+ </refsection>
+ <refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry>
+ <term>x0</term>
+ <listitem>guess values used by the fsolve function for estimating the parameters "xi" and "beta" of the Generalized Pareto Distribution (Maximum Likelihood estimation)</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>x</term>
+ <listitem>vector containing the historical data; these can be, for instance, prices or returns</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>u</term>
+ <listitem>threshold above which the data are assumed to follow the Generalized Pareto Distribution</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Output</title>
+ <variablelist>
+ <varlistentry>
+ <term>xoptim</term>
+ <listitem>estimated values (with maximum likelihood) of parameters "xi" and "beta" of the Generalized Pareto Distribution</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>v</term>
+ <listitem>value of the gradient of the likelihood function (it should be as close as possible to zero)</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>inf</term>
+ <listitem>same meaning as "inf" in the "fsolve" function</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Example</title>
+ <para>
+ <para>First we generate 1000 random numbers taken from a Generalized Pareto Distribution. First step is the creation of a vector of 1000 uniformly distributed random variables:</para>
+ <para>-->U=grand(1000,1,'def');</para>
+ <para>then we create the random variables from the GPD with parameters u=0.0001; xi=0.5; beta=0.00015:</para>
+ <para>-->x=0.0001-0.00015/0.5+0.00015/0.5*(1-U)^(-0.5);</para>
+ </para>
+ <para>These data could be daily return on an asset. Now we can use the function on vector x for computing ES and VaR at, for instance, 0.01 confidence level</para>
+ <para>-->[xoptim,v,inf]=evt([0.2 0.0002],x,0.0001) </para>
+ <para> inf = 1. </para>
+ <para>v = 1.0D-12 * </para>
+ <para>- 1.8189894 - 0.0017764 </para>
+ <para>xoptim = 0.5020924 0.0001470 </para>
+ <para>We can see that the convergence is good (please note that the algorithm is very sensitive to the initial condition x0). The estimated values of "xi" and "beta" are close to the true ones.</para>
+ </refsection>
+ <refsection>
+ <title>Authors</title>
+ <para>Francesco Menoncin - Brescia University - 2010</para>
+ </refsection>
+ <refsection>
+ <title>See Also</title>
+ <simplelist type="inline">
+ <member>
+ <link linkend="esvarevt">esvarevt</link>
+ </member>
+ <member>
+ <link linkend="fsolve">fsolve</link>
+ </member>
+ </simplelist>
+ </refsection>
+</refentry>
diff --git a/help/en_US/gbm.xml b/help/en_US/gbm.xml
new file mode 100644
index 0000000..57ac7cc
--- /dev/null
+++ b/help/en_US/gbm.xml
@@ -0,0 +1,63 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:id="gbm" xml:lang="en">
+ <refnamediv>
+ <refname>gbm</refname>
+ <refpurpose>Estimate the parameters of a Geometric Brownian Motion (through the method of moments) on the data and graphically show the mean and two confidence intervals</refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <title>SYNOPSIS</title>
+ <synopsis>[mu,sigma]=gbm(data,dt)</synopsis>
+ </refsynopsisdiv>
+ <refsection>
+ <title>Description</title>
+ <para>If the variable x follows a Geometric Brownian Motion then it solves the stochastic differential equaiton</para>
+ <para>dx/x = mu dt + sigma dW</para>
+ <para>where dW is the differential form of a Wiener process and both "mu" and "sigma" are constant parameters. On historical data, the function estimates both mu and sigma and show a graph with the mean of the process, the mean+/- the standard deviation, and the mean +/-2 times the standard deviation</para>
+ </refsection>
+ <refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry>
+ <term>data</term>
+ <listitem>column vector containing the historical data on which both the drift and the diffusion must be estimated</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>dt</term>
+ <listitem>time unit of measure: if data are in annual form (like returns, for instance) but have daily frequency, then dt=1/250 (since there are 250 working day in one year)</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Output</title>
+ <variablelist>
+ <varlistentry>
+ <term>mu, sigma</term>
+ <listitem>respectively the drift and diffusion terms of the Geometric Brownian Motion</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Example</title>
+ <para>First we generate 1000 log-normally distributed daily prices for an asset whose initial values is 25 euros. First step is the creation of 1000 normal random variables (with mean 0.1/250 and standard deviation 0.2/sqrt(250))</para>
+ <para>-->M=grand(1000,1,'nor',0.1/250,0.2/sqrt(250));</para>
+ <para>Then we create the prices</para>
+ <para>-->prices=exp(cumsum(M,1))*25;</para>
+ <para>and apply the function with</para>
+ <para>-->[mu,sigma]=gbm(prices,1/250);</para>
+ <para>sigma = 0.2039105</para>
+ <para>mu = 0.1443338 </para>
+ <para>We see the mean and the standard deviation are close to that we started from. The figure shows the original data, the mean and the confidence intervals.</para>
+ </refsection>
+ <refsection>
+ <title>Authors</title>
+ <para>Francesco Menoncin - Brescia University - 2010</para>
+ </refsection>
+ <refsection>
+ <title>See Also</title>
+ <simplelist type="inline">
+ <member>
+ <link linkend="euler">euler</link>
+ </member>
+ </simplelist>
+ </refsection>
+</refentry>
diff --git a/help/en_US/hedge.xml b/help/en_US/hedge.xml
new file mode 100644
index 0000000..e60fdb6
--- /dev/null
+++ b/help/en_US/hedge.xml
@@ -0,0 +1,61 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:id="hedge" xml:lang="en">
+ <refnamediv>
+ <refname>hedge</refname>
+ <refpurpose>Compute the hedge ratio between an asset "S" and a derivative on it "F"</refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <title>SYNOPSIS</title>
+ <synopsis>h=hedge(S,F);</synopsis>
+ </refsynopsisdiv>
+ <refsection>
+ <title>Description</title>
+ <para>Given the historical prices of both an asset "S" and a derivative written on it "F", the function computes the so-called hedge ration "h". If one multiplies the wealth invested in "S" by "h", one obtains the wealth that must be invested in "F" in order to hedged the position on "S". The hedge ratio is the opposite of the inverse of the elasticity of the derivative with respect to the underlying asset.</para>
+ </refsection>
+ <refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry>
+ <term>S</term>
+ <listitem>column vector containing the historical prices of the underlying asset</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>F</term>
+ <listitem>column vector containing the historical prices of the derivative</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Output</title>
+ <variablelist>
+ <varlistentry>
+ <term>h</term>
+ <listitem>hedge ratio (as the opposite of the inverse of the estimated elasticity of "S" with respect to "F")</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Example</title>
+ <para>First we generate 100 log-normally distributed daily prices for an asset whose initial values is 25 euros. First step is the creation of 100 normal random variables (with mean 0.1/250 and standard deviation 0.2/sqrt(250))</para>
+ <para>-->M=grand(100,1,'nor',0.1/250,0.2/sqrt(250));</para>
+ <para>Then we create the prices</para>
+ <para>-->S=exp(cumsum(M,1))*25;</para>
+ <para>Now we create the prices of a derivative whose returns are more or less 5 times the returns on the underlying</para>
+ <para>-->F=(S/S(1)).^grand(100,1,'unf',4.9,5.1);</para>
+ <para>and so we are ready for using the function</para>
+ <para>-->h=hedge(S,F)</para>
+ <para>!N. observations 99 ! </para>
+ <para>!N. variables 2 !</para>
+ <para>!R-square 0.9705684 !</para>
+ <para>!R-square corrected 0.9702650 !</para>
+ <para>!Coefficients t-statistics !</para>
+ <para>!-0.0001464 -0.1427691 !</para>
+ <para>!5.0436713 56.557729 !</para>
+ <para>h = - 0.1982683 </para>
+ <para>The statistics show that the regression is good and the hedge ratio is reliable.</para>
+ </refsection>
+ <refsection>
+ <title>Authors</title>
+ <para>Francesco Menoncin - Brescia University - 2010</para>
+ </refsection>
+</refentry>
diff --git a/help/en_US/hurst.xml b/help/en_US/hurst.xml
new file mode 100644
index 0000000..e3d2472
--- /dev/null
+++ b/help/en_US/hurst.xml
@@ -0,0 +1,58 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:id="hurst" xml:lang="en">
+ <refnamediv>
+ <refname>hurst</refname>
+ <refpurpose>Compute the Hurst index on historical prices</refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <title>SYNOPSIS</title>
+ <synopsis>H=hurst(price [,period [,step]]);</synopsis>
+ </refsynopsisdiv>
+ <refsection>
+ <title>Description</title>
+ <para>Given the historical prices of an asset the function computes the so-called Hurst index (or Hurst exponent) for fractional Brownian motion on the asset returns.</para>
+ <para>If the Hurst index H is 0.5, then the price process is a "regular" Brownian motion; if H>0.5, then the increments of the process are positively correlated; finally, if H<0.5, the increments of the process are negatively correlated. </para>
+ <para>The function also shows a scatter plot of the log of the sample length against the log of the variation coefficient of asset returns.</para>
+ </refsection>
+ <refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry>
+ <term>price</term>
+ <listitem>column vector containing the historical prices of an asset (in general they are daily prices)</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>period</term>
+ <listitem>optional parameter: first set of prices used for estimating the Hurst index (by default it is 250 - i.e. the working days in a year)</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>step</term>
+ <listitem>optional parameter: increment in the set of prices used for estimating the Hurst index (by default it is 10). This is the increasing step in the rolling estimation.</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Output</title>
+ <variablelist>
+ <varlistentry>
+ <term>H</term>
+ <listitem>estimated Hurst index on the asset (log-) returns</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Example</title>
+ <para>First we generate 1000 log-normally distributed daily prices for an asset whose initial values is 25 euros. First step is the creation of 1000 normal random variables (with mean 0.1/250 and standard deviation 0.2/sqrt(250))</para>
+ <para>-->M=grand(1000,1,'nor',0.1/250,0.2/sqrt(250));</para>
+ <para>Then we create the prices</para>
+ <para>-->S=exp(cumsum(M,1))*25;</para>
+ <para>Now we are ready to use the function. We use it on the first 100 prices and with a step of 10 days</para>
+ <para>-->H=hurst(S,100,10)</para>
+ <para>H = 0.5588872 </para>
+ <para>We have a value close to 0.5 which means that the data should be more or less follow a Brownian motion.</para>
+ </refsection>
+ <refsection>
+ <title>Authors</title>
+ <para>Francesco Menoncin - Brescia University - 2010</para>
+ </refsection>
+</refentry>
diff --git a/help/en_US/interest.xml b/help/en_US/interest.xml
new file mode 100644
index 0000000..00a3ca4
--- /dev/null
+++ b/help/en_US/interest.xml
@@ -0,0 +1,109 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:id="interest" xml:lang="en">
+ <refnamediv>
+ <refname>interest</refname>
+ <refpurpose>Estimate the parameters of three spot interest rate models and draw some simulations</refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <title>SYNOPSIS</title>
+ <synopsis>rf=interest(r,dt,T,model,n,r0);</synopsis>
+ </refsynopsisdiv>
+ <refsection>
+ <title>Description</title>
+ <para>The function can be used for estimating the parameters of three different models for spot interest rates, and performs some simulations of the resulting stochastic process.</para>
+ <para>The interest rate models taken into account are:</para>
+ <para>1) Merton's: the instantaneously riskless interest rate follows the stochastic differential equation</para>
+ <para>dr = mu dt + sigma dW</para>
+ <para>where dW is a Wiener process and both "mu" and "sigma" are constant;</para>
+ <para>2) Vasicek's: the instantaneously riskless interest rate follows the stochastic differential equation</para>
+ <para>
+ <para>dr = a (b - r) dt + sigma dW</para>
+ <para>where "a", "b", and "sigma" are all constant;</para>
+ <para>3) Cox, Ingersoll, and Ross': the instantaneously riskless interest rate follows the stochastic differential equaiton</para>
+ <para>dr = a (b - r) dt + sigma sqrt(r) dW.</para>
+ </para>
+ </refsection>
+ <refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry>
+ <term>r</term>
+ <listitem>column vector containing the historical riskless interest rate</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>dt</term>
+ <listitem>time unit of measure; if the (annual) interest rate is collected on a daily base, then dt=1/250 since there are 250 working days in a year</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>T</term>
+ <listitem>period during which the stochastic process must be simulated (if T=2 years, and dt=1/250, then 500 values are generated)</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>model</term>
+ <listitem>this is a string whose value must be either 'merton', or 'vasicek', or 'cir', for any of the three models presented above</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>n</term>
+ <listitem>the number of simulations that must be performed</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>r0</term>
+ <listitem>interest rate the simulations must start from (in order to check the goodness of the model r0 should be r(1), instead for foreseeing the future interest rates, r0 should be r($)</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Output</title>
+ <variablelist>
+ <varlistentry>
+ <term>rf</term>
+ <listitem>matrix whose columns contain the simulation of the interest rate (it has as many columns as "n") and as many rows as T/dt</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Example</title>
+ <para>First we generate 1000 uniformly distributed daily interest rate, between 4% and 6% (of course interest rates are not uniform, but this is useful just as an example).</para>
+ <para>-->r=grand(1000,1,'unf',0.04,0.06);</para>
+ <para>Then we are able to use the function. Let us see the results for all the three models. We create 10 simulations starting from the first interest rate and each simulation will be done for 1 year:</para>
+ <para>-->rf=interest(r,1/250,1,'merton',10,r(1));</para>
+ <para>!Coefficient Value !</para>
+ <para>!Drift 0.0016879 !</para>
+ <para>!Diffusion 0.1296796 !</para>
+ <para>We see that the drift "mu" is almost zero (in fact the interest rates oscillate on a sdtraight line with zero slope), while the diffusion "sigma" is quite high. The figure shows 10 possible trajectories which also have negative values with high probability. Let us see the Vasicek case:</para>
+ <para>-->rf=interest(r,1/250,1,'vasicek',10,r(1));</para>
+ <para>!Coefficient Value !</para>
+ <para>!Mean reversion 248.13562 !</para>
+ <para>!Mean 0.0498669 !</para>
+ <para>!Diffusion 0.1296796 !</para>
+ <para>The diffusion is the same as Merton's (as we expected). The mean reversion parameter "a" is very high (in fact the sample we used reverts to its mean with a remarkable strength). The mean "b" of the process is more or less 0.05 as we expected (in fact, we created interest rates uniformly distributed between 0.04 and 0.06). The figure shows ten trajectories with good oscillations. Finally, the CIR model:</para>
+ <para>--> rf=interest(r,1/250,1,'cir',10,r(1));</para>
+ <para>!Coefficient Value !</para>
+ <para>!Mean reversion 246.72311 !</para>
+ <para>!Mean 0.0498670 !</para>
+ <para>!Diffusion coeff. 0.5819574 !</para>
+ <para>Where we see values of mean reversion and mean very close to the previous one. The last term is different since the diffusion coefficient "sigma" in the CIR model must be multiplied by the square root of the interest rate. The graph should show trajectories similar to the previous ones.</para>
+ </refsection>
+ <refsection>
+ <title>Bibliography</title>
+ <para>"A Theory of the Term Structure of Interest Rates", Cox J.C., Ingersoll J.E. Jr., and Ross S.A., Econometrica, 53, 385-407, 1985 </para>
+ <para>"On the pricing of corporate debt: The risk structure of interest rates", Merton R.C., Journal of Finance, 29, 449-470, 1971</para>
+ <para>"An Equilibrium Characterization of the Term Structure", Vasiček O., Journal of Financial Economics, 5, 177-188 (1977)</para>
+ </refsection>
+ <refsection>
+ <title>Authors</title>
+ <para>Francesco Menoncin - Brescia University - 2010</para>
+ </refsection>
+ <refsection>
+ <title>See Also</title>
+ <simplelist type="inline">
+ <member>
+ <link linkend="gbm">gbm</link>
+ </member>
+ <member>
+ <link linkend="euler">euler</link>
+ </member>
+
+ </simplelist>
+ </refsection>
+</refentry>
diff --git a/help/en_US/irs.xml b/help/en_US/irs.xml
new file mode 100644
index 0000000..5fbf1f0
--- /dev/null
+++ b/help/en_US/irs.xml
@@ -0,0 +1,76 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:id="irs" xml:lang="en">
+ <refnamediv>
+ <refname>irs</refname>
+ <refpurpose>For a fix-for-floating Interest Rate Swap compute both the spread and the value of the legs.</refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <title>SYNOPSIS</title>
+ <synopsis>[spread,leg]=irs(time,months,r,setting);</synopsis>
+ </refsynopsisdiv>
+ <refsection>
+ <title>Description</title>
+ <para>The function computes both the spread (i.e. the fixed payment) and the value of the legs for an Interest Rate Swap. The function can take into account both "in advance" and "in arrears" IRS.</para>
+ </refsection>
+ <refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry>
+ <term>time</term>
+ <listitem>the subscribing date of the IRS; it must be in the form [year month day]</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>months</term>
+ <listitem>number of months between each payment (more common are 3 or 6)</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>r</term>
+ <listitem>column vector containing the relevant spot rates</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>setting</term>
+ <listitem>this variable must be zero (0) for "in advance" IRS and one (1) for "in arrears" IRS</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Output</title>
+ <variablelist>
+ <varlistentry>
+ <term>spread</term>
+ <listitem>fix payment of the IRS</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>leg</term>
+ <listitem>value of both legs of the IRS</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Example</title>
+ <para>Let as assume that 12th May 2010 an annual swap is subscribed (with 3-month payments).We first set the relevant interest rates (for one year swap with 3-month payments the interest rates must be four):</para>
+ <para>-->r=[0.00652 0.00956 0.01091 0.01216]';</para>
+ <para>Now we can use the function. For an "in advance" IRS we have</para>
+ <para>-->[spread,leg]=irs([2010 5 12],3,r,0)</para>
+ <para>leg = 0.0121787</para>
+ <para>spread = 0.0120930 </para>
+ <para>Thus we have to pay 1.2% in exchange of the floating interest rate.</para>
+ <para>In the case of an "in arrears" IRS the last</para>
+ <para>-->[spread,leg]=irs([2010 5 12],3,r,1)</para>
+ <para>leg = 0.0106842</para>
+ <para>spread = 0.0140050</para>
+ <para>The spread is higher since we eliminate the first interest rate with an increasing curve. </para>
+ </refsection>
+ <refsection>
+ <title>Authors</title>
+ <para>Francesco Menoncin - Brescia University - 2010</para>
+ </refsection>
+ <refsection>
+ <title>See Also</title>
+ <simplelist type="inline">
+ <member>
+ <link linkend="datenum">datenum</link>
+ </member>
+ </simplelist>
+ </refsection>
+</refentry>
diff --git a/help/en_US/markowitz.xml b/help/en_US/markowitz.xml
new file mode 100644
index 0000000..a07c621
--- /dev/null
+++ b/help/en_US/markowitz.xml
@@ -0,0 +1,91 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:id="markowitz" xml:lang="en">
+ <refnamediv>
+ <refname>markowitz</refname>
+ <refpurpose>Compute the optimal portfolio minimizing the variance (this is a quadratic programming problem). The optimal variance is also computed.</refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <title>SYNOPSIS</title>
+ <synopsis>[portf,varoptim]=markowitz(price,ER,r,dt);</synopsis>
+ </refsynopsisdiv>
+ <refsection>
+ <title>Description</title>
+ <para>Give the historical prices of a set of assets, compute the optimal portfolios solving four different problems. All of them minimize the Variance of the portfolio subject to the constraint of having given expected return. The four problems are different for the following characteristics</para>
+ <para>1) optimal portfolio allowing short selling and investing in the riskless asset;</para>
+ <para>2) optimal portfolio allowing short selling but without investing in the riskless asset;</para>
+ <para>3) optimal portfolio not allowing short selling and investing in the riskless asset;</para>
+ <para>4) optimal portfolio not allowing short selling and without investing in the riskless asset.</para>
+ <para>Finally the Variance of the optimal portfolio is computed. The procedure uses "qld" function.</para>
+ </refsection>
+ <refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry>
+ <term>price</term>
+ <listitem>matrix whose columns contains the historical prices of the assets in the portfolio</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>ER</term>
+ <listitem>expected return that the investor wants to obtain on his portfolio</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>r</term>
+ <listitem>riskless interest rate</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>dt</term>
+ <listitem>time frequency of the prices with respect to the time unit of measure of both "ER" and "r"; if the matrix of prices contains daily data and both "ER" and "r" are annual return, then dt=1/250 since there are 250 working day in one year</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Output</title>
+ <variablelist>
+ <varlistentry>
+ <term>portf</term>
+ <listitem>matrix containing the optimal portfolios; in particular:</listitem>
+ <listitem>first raw: with short selling and with r</listitem>
+ <listitem>second raw: with short selling and without r</listitem>
+ <listitem>third raw: without short selling and with r</listitem>
+ <listitem>fourth raw: without short selling and without r</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>varoptim</term>
+ <listitem>Variance of the optimal portfolio</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Example</title>
+ <para>
+ <para>First we generate 100x3 log-normally distributed daily asset prices with 0.1/250 mean and 0.2/sqrt(250) variance. The first prices of the three assets are 25 euros, 50 euros, and 110 euros respectively.</para>
+ <para>-->M=grand(100,3,'nor',0.1/250,0.2/sqrt(250));</para>
+ <para>-->price=exp(cumsum(M,1))*diag([25 50 110]);</para>
+ </para>
+ <para>Now we can use the function on these prices.</para>
+ <para>-->[portf,varoptim]=markowitz(price,0.05,0.01,1/250) </para>
+ <para>Draw frontiers? (y/n) y </para>
+ <para>! with short selling without short selling !</para>
+ <para>! with r without r with r without r !</para>
+ <para>varoptim =</para>
+ <para>0.0001508 0.0232294 0.0001508 0.0249650</para>
+ <para>portf = </para>
+ <para>- 0.0009446 0.6612090 - 1.444D-34 0.7614173 </para>
+ <para>0.0599034 - 0.0729724 0.0599186 0. </para>
+ <para>0.0157164 0.4117634 0.0157684 0.2385827 </para>
+ <para>We see that the third or the second asset are sold (negative portfolio component) when it is possible. If short selling is not allowed, then its weight is either positive or zero.</para>
+ <para>The function also asks if one wants to see the optimal frontiers (this is optional since the procedure takes some time). The figure which is created shows four frontiers corresponding to the four different problems (the legend explains the meanings).</para>
+ </refsection>
+ <refsection>
+ <title>Authors</title>
+ <para>Francesco Menoncin - Brescia University - 2010</para>
+ </refsection>
+ <refsection>
+ <title>See Also</title>
+ <simplelist type="inline">
+ <member>
+ <link linkend="qld">qld</link>
+ </member>
+ </simplelist>
+ </refsection>
+</refentry>
diff --git a/help/en_US/master_help.xml b/help/en_US/master_help.xml
new file mode 100644
index 0000000..0c2e581
--- /dev/null
+++ b/help/en_US/master_help.xml
@@ -0,0 +1,67 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE book [
+<!--Begin Entities-->
+<!ENTITY aa64b926d1068a265ee932f4e4dfbb79f SYSTEM "/home/ruben/debian/scilab-financial/scilab-financial/scilab-financial-1.0.1/help/en_US/0overview.xml">
+<!ENTITY a796a131b6a85adbdc5ab089d45ffea88 SYSTEM "/home/ruben/debian/scilab-financial/scilab-financial/scilab-financial-1.0.1/help/en_US/backtest.xml">
+<!ENTITY a4d68605394c654f5a5d7dbe1b56fad04 SYSTEM "/home/ruben/debian/scilab-financial/scilab-financial/scilab-financial-1.0.1/help/en_US/bollinger.xml">
+<!ENTITY a130fe291cadb69ebaea947a86268953d SYSTEM "/home/ruben/debian/scilab-financial/scilab-financial/scilab-financial-1.0.1/help/en_US/bsgreeks.xml">
+<!ENTITY a8169e9e58ce9d7281c45bb239909f8c7 SYSTEM "/home/ruben/debian/scilab-financial/scilab-financial/scilab-financial-1.0.1/help/en_US/bsimpvol.xml">
+<!ENTITY aea8c8d1d660a3a2d7239843e7cc7bf4e SYSTEM "/home/ruben/debian/scilab-financial/scilab-financial/scilab-financial-1.0.1/help/en_US/bsoption.xml">
+<!ENTITY aa1bd1b37673193b61830056930123777 SYSTEM "/home/ruben/debian/scilab-financial/scilab-financial/scilab-financial-1.0.1/help/en_US/cfr.xml">
+<!ENTITY aaaf5fdd7ff61ec4e7ede8d714a55373b SYSTEM "/home/ruben/debian/scilab-financial/scilab-financial/scilab-financial-1.0.1/help/en_US/duration.xml">
+<!ENTITY af9d5eccea322aaf9f5908864338296b8 SYSTEM "/home/ruben/debian/scilab-financial/scilab-financial/scilab-financial-1.0.1/help/en_US/esvarevt.xml">
+<!ENTITY a91e3a84a32fb0b86ecb4b47850a3ad99 SYSTEM "/home/ruben/debian/scilab-financial/scilab-financial/scilab-financial-1.0.1/help/en_US/esvarlin.xml">
+<!ENTITY a559213ee40adc2f5b6633d3e6b3e5e85 SYSTEM "/home/ruben/debian/scilab-financial/scilab-financial/scilab-financial-1.0.1/help/en_US/esvaroptim.xml">
+<!ENTITY a6d3f3c0577b1724f9ceca6aca3f6d960 SYSTEM "/home/ruben/debian/scilab-financial/scilab-financial/scilab-financial-1.0.1/help/en_US/euler.xml">
+<!ENTITY ab3b9710f2bd9d6c82e5549dbbf1222e1 SYSTEM "/home/ruben/debian/scilab-financial/scilab-financial/scilab-financial-1.0.1/help/en_US/evt.xml">
+<!ENTITY aa3e49924a87307ea34fccf3694970343 SYSTEM "/home/ruben/debian/scilab-financial/scilab-financial/scilab-financial-1.0.1/help/en_US/gbm.xml">
+<!ENTITY ad1cb118062e867dda861f8d909fde4b1 SYSTEM "/home/ruben/debian/scilab-financial/scilab-financial/scilab-financial-1.0.1/help/en_US/hedge.xml">
+<!ENTITY a08ed0751520725ccb0586073b3e37030 SYSTEM "/home/ruben/debian/scilab-financial/scilab-financial/scilab-financial-1.0.1/help/en_US/hurst.xml">
+<!ENTITY a4fff5a9d96d501186a36434f78651e31 SYSTEM "/home/ruben/debian/scilab-financial/scilab-financial/scilab-financial-1.0.1/help/en_US/interest.xml">
+<!ENTITY aee056c0afff92062ea256094682ca76e SYSTEM "/home/ruben/debian/scilab-financial/scilab-financial/scilab-financial-1.0.1/help/en_US/irs.xml">
+<!ENTITY aa355f2bf40642bdc22c5a85c62b2a26a SYSTEM "/home/ruben/debian/scilab-financial/scilab-financial/scilab-financial-1.0.1/help/en_US/markowitz.xml">
+<!ENTITY a573febb16db4f0b15770159d49d7e2c1 SYSTEM "/home/ruben/debian/scilab-financial/scilab-financial/scilab-financial-1.0.1/help/en_US/mef.xml">
+<!ENTITY a7eb4ecad198f2e3000a99f0ad14c1923 SYSTEM "/home/ruben/debian/scilab-financial/scilab-financial/scilab-financial-1.0.1/help/en_US/movav.xml">
+<!ENTITY abe4d7426ae2da0db70c543884d2263b4 SYSTEM "/home/ruben/debian/scilab-financial/scilab-financial/scilab-financial-1.0.1/help/en_US/nelson_siegel.xml">
+<!ENTITY a7ef85096a2ababa20113b877a473a93e SYSTEM "/home/ruben/debian/scilab-financial/scilab-financial/scilab-financial-1.0.1/help/en_US/svennson.xml">
+<!--End Entities-->
+]>
+<book version="5.0-subset Scilab" xml:lang="en_US"
+ xmlns="http://docbook.org/ns/docbook"
+ xmlns:xlink="http://www.w3.org/1999/xlink"
+ xmlns:xi="http://www.w3.org/2001/XInclude"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns:mml="http://www.w3.org/1998/Math/MathML"
+ xmlns:html="http://www.w3.org/1999/xhtml"
+ xmlns:db="http://docbook.org/ns/docbook">
+ <info xml:id='financial_module_manual'>
+ <title>Financial module</title>
+ </info>
+
+<part xml:id='section_4af098ac34d3d4ed2e545bfe2ad89215'>
+<title>Financial module</title>
+&aa64b926d1068a265ee932f4e4dfbb79f;
+&a796a131b6a85adbdc5ab089d45ffea88;
+&a4d68605394c654f5a5d7dbe1b56fad04;
+&a130fe291cadb69ebaea947a86268953d;
+&a8169e9e58ce9d7281c45bb239909f8c7;
+&aea8c8d1d660a3a2d7239843e7cc7bf4e;
+&aa1bd1b37673193b61830056930123777;
+&aaaf5fdd7ff61ec4e7ede8d714a55373b;
+&af9d5eccea322aaf9f5908864338296b8;
+&a91e3a84a32fb0b86ecb4b47850a3ad99;
+&a559213ee40adc2f5b6633d3e6b3e5e85;
+&a6d3f3c0577b1724f9ceca6aca3f6d960;
+&ab3b9710f2bd9d6c82e5549dbbf1222e1;
+&aa3e49924a87307ea34fccf3694970343;
+&ad1cb118062e867dda861f8d909fde4b1;
+&a08ed0751520725ccb0586073b3e37030;
+&a4fff5a9d96d501186a36434f78651e31;
+&aee056c0afff92062ea256094682ca76e;
+&aa355f2bf40642bdc22c5a85c62b2a26a;
+&a573febb16db4f0b15770159d49d7e2c1;
+&a7eb4ecad198f2e3000a99f0ad14c1923;
+&abe4d7426ae2da0db70c543884d2263b4;
+&a7ef85096a2ababa20113b877a473a93e;
+</part>
+</book>
diff --git a/help/en_US/mef.xml b/help/en_US/mef.xml
new file mode 100644
index 0000000..d2b8b86
--- /dev/null
+++ b/help/en_US/mef.xml
@@ -0,0 +1,47 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:id="mef" xml:lang="en">
+ <refnamediv>
+ <refname>mef</refname>
+ <refpurpose>Compute and draw the Mean Excess Function</refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <title>SYNOPSIS</title>
+ <synopsis>E=mef(x)</synopsis>
+ </refsynopsisdiv>
+ <refsection>
+ <title>Description</title>
+ <para>On the data "x" (for instance asset returns), the function computes and draw the Mean Excess Function. It is the mean of the data exceeding a given threshold. Each value of ordered "x" is taken as a threshold.</para>
+ </refsection>
+ <refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry>
+ <term>x</term>
+ <listitem>data the Mean Excess Function must be computed on</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Output</title>
+ <variablelist>
+ <varlistentry>
+ <term>E</term>
+ <listitem>vector of the values of the Mean Excess Function</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Example</title>
+ <para>
+ <para>First we generate 1000 normally daily returns on an asset with 0.1/250 mean and 0.2/sqrt(250) variance:</para>
+ <para>-->returns=grand(1000,1,'nor',0.1/250,0.2/sqrt(250));</para>
+ </para>
+ <para>Now we can use the function on these returns.</para>
+ <para>-->E=mef(returns); </para>
+ <para>The graph shows the values of the Mean Excess Function. For a normal random variable it is decreasing and convex.</para>
+ </refsection>
+ <refsection>
+ <title>Authors</title>
+ <para>Francesco Menoncin - Brescia University - 2010</para>
+ </refsection>
+</refentry>
diff --git a/help/en_US/movav.xml b/help/en_US/movav.xml
new file mode 100644
index 0000000..4e81809
--- /dev/null
+++ b/help/en_US/movav.xml
@@ -0,0 +1,52 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:id="movav" xml:lang="en">
+ <refnamediv>
+ <refname>movav</refname>
+ <refpurpose>Compute and draw the moving average of a given time series</refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <title>SYNOPSIS</title>
+ <synopsis>M=movav(x [,m1 [,m2 [,...]]]);</synopsis>
+ </refsynopsisdiv>
+ <refsection>
+ <title>Description</title>
+ <para>On the data "x" the function compute the moving averages of length m1, m2, and so on. Finally it draws the data "x" and all the moving averages.</para>
+ </refsection>
+ <refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry>
+ <term>x</term>
+ <listitem>data the moving averages are computed on</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>m1, m2, ...</term>
+ <listitem>lengths of the moving averages</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Output</title>
+ <variablelist>
+ <varlistentry>
+ <term>M</term>
+ <listitem>matrix containing, in any column, the moving average of the historical data (each column has a different length)</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Example</title>
+ <para>
+ <para>First we generate 1000 log-normally distributed daily asset prices with 0.1/250 mean and 0.2/sqrt(250) variance. The first price of the asset is 25 euros.</para>
+ <para>-->M=grand(1000,1,'nor',0.1/250,0.2/sqrt(250));</para>
+ <para>-->price=exp(cumsum(M,1))*25;</para>
+ </para>
+ <para>Now we can use the function for computing the moving averages at 10 days and 30 days</para>
+ <para>-->M=movav(price,10,30);</para>
+ <para>The graph shows the historical data and both moving averages.</para>
+ </refsection>
+ <refsection>
+ <title>Authors</title>
+ <para>Francesco Menoncin - Brescia University - 2010</para>
+ </refsection>
+</refentry>
diff --git a/help/en_US/nelson_siegel.xml b/help/en_US/nelson_siegel.xml
new file mode 100644
index 0000000..ae86f4f
--- /dev/null
+++ b/help/en_US/nelson_siegel.xml
@@ -0,0 +1,96 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:id="nelson_siegel" xml:lang="en">
+ <refnamediv>
+ <refname>nelson_siegel</refname>
+ <refpurpose>Estimate the parameters for the Nelson Siegel model of spot interest rates (least square method). Finally draw the actual spot rate curve and the interporalted curve</refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <title>SYNOPSIS</title>
+ <synopsis>[uopt [,rf]]=nelson_siegel(t,r,u0 [,tf]);</synopsis>
+ </refsynopsisdiv>
+ <refsection>
+ <title>Description</title>
+ <para>The Nelson Siegel model assumes that the spot interest rate follows the function (of time)</para>
+ <para>f(t)=u1+(u2+u3)*u4/t*(1-e^(-t/u4))-u4*e^(-t/u4)</para>
+ <para>The function estimates the parameters u1, u2, u3, and u4 with the least square method. It is also possible to foresee some rates for given dates.</para>
+ </refsection>
+ <refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry>
+ <term>t</term>
+ <listitem>dates corresponding to the spot interest rates</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>r</term>
+ <listitem>spot interest rate curve</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>u0</term>
+ <listitem>initial values for the parameters (it must be a vector of four elements)</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>tf</term>
+ <listitem>optional parameter: (column vector) the dates for which we want to use the model in order to foresee the interest rates</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Output</title>
+ <variablelist>
+ <varlistentry>
+ <term>uopt</term>
+ <listitem>vector containing the estimated values of the parameters</listitem>
+ </varlistentry>
+ </variablelist>
+ <variablelist>
+ <varlistentry>
+ <term>rf</term>
+ <listitem>optional output: the foreseen interest rates (for the dates in vector "tf")</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Example</title>
+ <para>
+ <para>First we define the dates and the interest rates (taken from the Euribor curve)</para>
+ <para>-->t=[ 0.0192308 0.0384615 0.0576923 0.0833333 0.1666667 0.25 0.3333333 0.4166667 0.5 0.5833333 0.6666667 0.75 0.8333333 0.9166667 1];</para>
+ <para>-->r=[0.00944 0.00949 0.0097 0.01009 0.01213 0.01405 0.01486 0.01534 0.016 0.01636 0.01662 0.01687 0.01716 0.01742 0.01766 ];</para>
+ <para> Now we can use the function and also foreseen the interest rates for 2 years, 3 years, and 4 years</para>
+ <para>-->[uopt,rf]=nelson_siegel(t,r,ones(4,1),[2 3 4]')</para>
+ <para>Gradient </para>
+ <para>1.0D-11 * </para>
+ <para>- 1.2365855 </para>
+ <para>0.0194767 </para>
+ <para>- 0.8091640 </para>
+ <para>0.0844415 </para>
+ <para>Objective function </para>
+ <para>0.0000010 </para>
+ <para>rf = </para>
+ <para>0.0178524 </para>
+ <para>0.0178558 </para>
+ <para>0.0178501 </para>
+ <para>uopt = </para>
+ <para>0.0178308 </para>
+ <para>- 0.0094562 </para>
+ <para>0.0097015 </para>
+ <para>0.3151036</para>
+ </para>
+ <para>The figure shows the actual interest rates, the estimated ones and the foreseen ones.</para>
+ </refsection>
+ <refsection>
+ <title>Authors</title>
+ <para>Francesco Menoncin - Brescia University - 2010</para>
+ </refsection>
+ <refsection>
+ <title>See Also</title>
+ <simplelist type="inline">
+ <member>
+ <link linkend="leastsq">leastsq</link>
+ </member>
+ <member>
+ <link linkend="svennson">svennson</link>
+ </member>
+ </simplelist>
+ </refsection>
+</refentry>
diff --git a/help/en_US/scilab_en_US_help/JavaHelpSearch/DOCS b/help/en_US/scilab_en_US_help/JavaHelpSearch/DOCS
new file mode 100644
index 0000000..ac7ef38
Binary files /dev/null and b/help/en_US/scilab_en_US_help/JavaHelpSearch/DOCS differ
diff --git a/help/en_US/scilab_en_US_help/JavaHelpSearch/DOCS.TAB b/help/en_US/scilab_en_US_help/JavaHelpSearch/DOCS.TAB
new file mode 100644
index 0000000..11b5a54
Binary files /dev/null and b/help/en_US/scilab_en_US_help/JavaHelpSearch/DOCS.TAB differ
diff --git a/help/en_US/scilab_en_US_help/JavaHelpSearch/OFFSETS b/help/en_US/scilab_en_US_help/JavaHelpSearch/OFFSETS
new file mode 100644
index 0000000..082d049
Binary files /dev/null and b/help/en_US/scilab_en_US_help/JavaHelpSearch/OFFSETS differ
diff --git a/help/en_US/scilab_en_US_help/JavaHelpSearch/POSITIONS b/help/en_US/scilab_en_US_help/JavaHelpSearch/POSITIONS
new file mode 100644
index 0000000..6ef5fb9
Binary files /dev/null and b/help/en_US/scilab_en_US_help/JavaHelpSearch/POSITIONS differ
diff --git a/help/en_US/scilab_en_US_help/JavaHelpSearch/SCHEMA b/help/en_US/scilab_en_US_help/JavaHelpSearch/SCHEMA
new file mode 100644
index 0000000..323b402
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/JavaHelpSearch/SCHEMA
@@ -0,0 +1,2 @@
+JavaSearch 1.0
+TMAP bs=2048 rt=1 fl=-1 id1=1018 id2=1
diff --git a/help/en_US/scilab_en_US_help/JavaHelpSearch/TMAP b/help/en_US/scilab_en_US_help/JavaHelpSearch/TMAP
new file mode 100644
index 0000000..67766d6
Binary files /dev/null and b/help/en_US/scilab_en_US_help/JavaHelpSearch/TMAP differ
diff --git a/help/en_US/scilab_en_US_help/ScilabEdit.png b/help/en_US/scilab_en_US_help/ScilabEdit.png
new file mode 100644
index 0000000..188e1c1
Binary files /dev/null and b/help/en_US/scilab_en_US_help/ScilabEdit.png differ
diff --git a/help/en_US/scilab_en_US_help/ScilabExecute.png b/help/en_US/scilab_en_US_help/ScilabExecute.png
new file mode 100644
index 0000000..a7de0fe
Binary files /dev/null and b/help/en_US/scilab_en_US_help/ScilabExecute.png differ
diff --git a/help/en_US/scilab_en_US_help/backtest.html b/help/en_US/scilab_en_US_help/backtest.html
new file mode 100644
index 0000000..33206e0
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/backtest.html
@@ -0,0 +1,88 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>backtest</title>
+ <style type="text/css" media="all">
+ @import url("scilab_code.css");
+ @import url("xml_code.css");
+ @import url("c_code.css");
+ @import url("style.css");
+ </style>
+ </head>
+ <body>
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="financial_overview.html"><< financial_overview</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="bollinger.html">bollinger >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+
+
+
+ <span class="path"><a href="index.html">Financial module</a> >> <a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a> > backtest</span>
+
+ <br /><br />
+ <div class="refnamediv"><h1 class="refname">backtest</h1>
+ <p class="refpurpose">Apply the backtest to three different risk measures (as percentage of lost): Expected Shortfall, Value at Risk, and a Spectral Measure with linear spectrum. Show the graph of historical returns and the risk measures. The thresholds of the backtest are also computed.</p></div>
+ <div class="refsynopsisdiv"><h3 class="title">SYNOPSIS</h3>
+ <div class="synopsis"><pre><span class="functionid">backtest</span><span class="default"> (</span><span class="default">prices</span><span class="default">, </span><span class="default">alpha</span><span class="default"> [, </span><span class="default">N</span><span class="default">])</span></pre></div></div>
+ <div class="refsection"><h3 class="title">Description</h3>
+ <p class="para">Thia function checks the ability of three different risk measures (VaR, ES, and linear spectral) to suitably measure the shortfalls in asset returns.</p></div>
+ <div class="refsection"><h3 class="title">Parameters</h3>
+ <dl><dt><span class="term">prices</span>
+ <dd><p class="para">matrix whose columns contain the historical prices of each asset</p></dd></dt>
+ <dt><span class="term">alpha</span>
+ <dd><p class="para">confidence level of risk measures; it goes from 0 to 1 (both 0 and 1 excluded)</p></dd></dt>
+ <dt><span class="term">N</span>
+ <dd>the number of observations which the backtest is computed on (default value 250 if there are more than 500 historical prices, else N is half the number of rows of the matrix "prices")</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Example</h3>
+ <p class="para">First we generate 10000 log-normally distributed prices for three different assets whose initial values are 25 euros, 50 euros, and 110 euros. First step is the creation of a 10000x3 matrix of normal random variables (with mean 0.1/250 and standard deviation 0.2/sqrt(250))</p>
+ <p class="para">-->M=grand(10000,3,'nor',0.1/250,0.2/sqrt(250));</p>
+ <p class="para">Then we create the prices</p>
+ <p class="para">-->prices=exp(cumsum(M,1))*diag([25 50 110])</p>
+ <p class="para">and apply the function with an alpha, for instance, equal to 0.01:</p>
+ <p class="para">-->backtest(prices,0.01);</p>
+ <p class="para">The result is:</p>
+ <p class="para">!Green zone: 0-5 !</p>
+ <p class="para">!Yellow zone: 5-10 !</p>
+ <p class="para">!Red zone: 10- !</p>
+ <p class="para">!ES: 1 exeptions !</p>
+ <p class="para">!VaR: 4 exeptions !</p>
+ <p class="para">!Linear Spectrum: 1 exeptions !</p>
+ <p class="para">Which shows that the ES and the Linear Spectral measure are very reliable (since they present only 1 exeption), while the VaR is the less reliable. The figure which is created shows the same result is graphical form.</p></div>
+ <div class="refsection"><h3 class="title">Authors</h3>
+ <p class="para">Francesco Menoncin - Brescia University - 2010</p></div>
+ <div class="refsection"><h3 class="title">See Also</h3>
+ <ul class="itemizedlist"><li class="member"><a href="esvarlin.html" class="link">esvarlin</a></li>
+ <li class="member"><a href="esvaroptim.html" class="link">esvaroptim</a></li></ul></div>
+
+
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="financial_overview.html"><< financial_overview</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="bollinger.html">bollinger >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+ </body>
+</html>
diff --git a/help/en_US/scilab_en_US_help/bollinger.html b/help/en_US/scilab_en_US_help/bollinger.html
new file mode 100644
index 0000000..1634a4b
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/bollinger.html
@@ -0,0 +1,73 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>bollinger</title>
+ <style type="text/css" media="all">
+ @import url("scilab_code.css");
+ @import url("xml_code.css");
+ @import url("c_code.css");
+ @import url("style.css");
+ </style>
+ </head>
+ <body>
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="backtest.html"><< backtest</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="bsgreeks.html">bsgreeks >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+
+
+
+ <span class="path"><a href="index.html">Financial module</a> >> <a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a> > bollinger</span>
+
+ <br /><br />
+ <div class="refnamediv"><h1 class="refname">bollinger</h1>
+ <p class="refpurpose">Given a moving average on the historical prices of an asset, the function creates two figures: in the first both the historical prices and the Bollinger bands (i.e. the moving average +/- "a" times the price standard deviation) are shown, in the second the so-called b-percentage is shown</p></div>
+ <div class="refsynopsisdiv"><h3 class="title">SYNOPSIS</h3>
+ <div class="synopsis"><pre><span class="functionid">bollinger</span><span class="default"> (</span><span class="default">prices</span><span class="default">, </span><span class="default">m</span><span class="default">, </span><span class="default">a</span><span class="default">)</span></pre></div></div>
+ <div class="refsection"><h3 class="title">Description</h3>
+ <p class="para">Function which creates two graphs: one with the Bollinger bands and one with the b-percentage index</p></div>
+ <div class="refsection"><h3 class="title">Parameters</h3>
+ <dl><dt><span class="term">prices</span>
+ <dd><p class="para">column vector containing the historical prices of an asset</p></dd></dt>
+ <dt><span class="term">m</span>
+ <dd><p class="para">the lenght (in days if "prices" contains daily values) of the moving average which the bands are based on</p></dd></dt>
+ <dt><span class="term">a</span>
+ <dd>factor which multiplies the standard deviation of historical prices for creating the bands around the mean</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Example</h3><p class="para">First we generate 1000 log-normally distributed prices for an asset whose initial values is 25 euros. First step is the creation of 1000 normal random variables (with mean 0.1/250 and standard deviation 0.2/sqrt(250))</p>-->M=grand(1000,1,'nor',0.1/250,0.2/sqrt(250));<p class="para">Then we create the prices</p><p class="para">-->prices=exp(cumsum(M,1))*25</p><p class="para">and apply the function w [...]
+ <div class="refsection"><h3 class="title">Authors</h3>
+ <p class="para">Francesco Menoncin - Brescia University - 2010</p></div>
+ <div class="refsection"><h3 class="title">See Also</h3>
+ <ul class="itemizedlist"><li class="member"><a href="movav.html" class="link">movav</a></li></ul></div>
+
+
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="backtest.html"><< backtest</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="bsgreeks.html">bsgreeks >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+ </body>
+</html>
diff --git a/help/en_US/scilab_en_US_help/bsgreeks.html b/help/en_US/scilab_en_US_help/bsgreeks.html
new file mode 100644
index 0000000..f6e2737
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/bsgreeks.html
@@ -0,0 +1,112 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>bsgreeks</title>
+ <style type="text/css" media="all">
+ @import url("scilab_code.css");
+ @import url("xml_code.css");
+ @import url("c_code.css");
+ @import url("style.css");
+ </style>
+ </head>
+ <body>
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="bollinger.html"><< bollinger</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="bsimpvol.html">bsimpvol >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+
+
+
+ <span class="path"><a href="index.html">Financial module</a> >> <a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a> > bsgreeks</span>
+
+ <br /><br />
+ <div class="refnamediv"><h1 class="refname">bsgreeks</h1><p class="refpurpose">Compute the Greeks for both a call and a put option in a Black and Scholes model.</p></div>
+
+
+
+<div class="refsynopsisdiv"><h3 class="title">Calling Sequence</h3>
+ <div class="synopsis"><pre><span class="default">[</span><span class="default">delta</span><span class="default">,</span><span class="default">gama</span><span class="default">,</span><span class="default">theta</span><span class="default">,</span><span class="default">rho</span><span class="default">,</span><span class="default">vega</span><span class="default">]=</span><span class="functionid">bsgreeks</span><span class="default">(</span><span class="default">S</span><span class="de [...]
+
+<div class="refsection"><h3 class="title">Parameters</h3>
+ <dl><dt><span class="term">S :</span>
+ <dd><p class="para">a 1-by-1 matrix of doubles, current price of the underlying asset</p></dd></dt>
+ <dt><span class="term">K :</span>
+ <dd><p class="para">a 1-by-1 matrix of doubles, strike price of the option</p></dd></dt>
+ <dt><span class="term">r :</span>
+ <dd><p class="para">a 1-by-1 matrix of doubles, riskless interest rate (assumed to be constant until the maturity)</p></dd></dt>
+ <dt><span class="term">T :</span>
+ <dd><p class="para">a 1-by-1 matrix of doubles, time to maturity; it must be in the same time unit of measure as the riskless interest rate (if the riskless interest rate is annual, then an option with maturity of 3 months must have T=3/12)</p></dd></dt>
+ <dt><span class="term">sigma :</span>
+ <dd><p class="para">a 1-by-1 matrix of doubles, volatility of the underlying (log-) returns; it must be in the same time unit of measure as the riskless interest rate</p></dd></dt>
+ <dt><span class="term">delta :</span>
+ <dd><p class="para">a 2-by-1 matrix of doubles, the first derivative of the call (first term) and put (second term) option prices with respect to the underlying asset price</p></dd></dt>
+ <dt><span class="term">gama :</span>
+ <dd><p class="para">a 1-by-1 matrix of doubles, second derivative of the call (or put) option price with respect to the underlying asset price</p></dd></dt>
+ <dt><span class="term">theta :</span>
+ <dd><p class="para">a 2-by-1 matrix of doubles, vector containing the first derivative of the call (first term) and put (second term) option prices with respect to the time to maturity</p></dd></dt>
+ <dt><span class="term">rho :</span>
+ <dd><p class="para">a 2-by-1 matrix of doubles, vector containing the first derivative of the call (first term) and put (second term) option prices with respect to the riskless interest rate</p></dd></dt>
+ <dt><span class="term">vega :</span>
+ <dd><p class="para">a 1-by-1 matrix of doubles, first derivative of the call (or put) option price with respect to the standard deviation of the underlying (log-) returns</p></dd></dt></dl></div>
+
+<div class="refsection"><h3 class="title">Description</h3>
+ <p class="para">Computes the Greeks of both call and put option in a Black and Scholes framework</p>
+ <p class="para"></p></div>
+
+<div class="refsection"><h3 class="title">Examples</h3>
+ <div class="programlisting"><table border="0" width="100%"><tr><td width="98%"><pre class="scilabcode"><span class="scilabcomment">// We compute the Greeks on both a call and put option</span>
+<span class="scilabcomment">// with: underlying price 25 euros,</span>
+<span class="scilabcomment">// strike price 25 euros,</span>
+<span class="scilabcomment">// 0.01 (annual) riskless interest rate,</span>
+<span class="scilabcomment">// 3 month time to maturity (i.e. T=3/12),</span>
+<span class="scilabcomment">// and 0.2 (annual) volatility.</span>
+<span class="scilabopenclose">[</span><span class="scilabid">D</span><span class="scilabdefault">,</span><span class="scilabid">G</span><span class="scilabdefault">,</span><span class="scilabid">Th</span><span class="scilabdefault">,</span><span class="scilabid">R</span><span class="scilabdefault">,</span><span class="scilabid">V</span><span class="scilabopenclose">]</span><span class="scilaboperator">=</span><span class="scilabid">bsgreeks</span><span class="scilabopenclose">(</span><sp [...]
+<span class="scilabid">V</span> <span class="scilaboperator">=</span> <span class="scilabnumber">4.9727729</span><span class="scilabdefault">;</span>
+<span class="scilabid">R</span> <span class="scilaboperator">=</span> <span class="scilabopenclose">[</span><span class="scilabnumber">3.0550246</span><span class="scilabdefault">;</span><span class="scilaboperator">-</span><span class="scilabnumber">3.1793699</span><span class="scilabopenclose">]</span><span class="scilabdefault">;</span>
+<span class="scilabid">T</span> <span class="scilaboperator">=</span> <span class="scilabopenclose">[</span><span class="scilabnumber">2.1113101</span><span class="scilabdefault">;</span><span class="scilabnumber">1.8619344</span><span class="scilabopenclose">]</span><span class="scilabdefault">;</span>
+<span class="scilabid">G</span> <span class="scilaboperator">=</span> <span class="scilabnumber">4.9727729</span><span class="scilabdefault">;</span>
+<span class="scilabid">D</span> <span class="scilaboperator">=</span> <span class="scilabopenclose">[</span><span class="scilabnumber">0.5298926</span><span class="scilabdefault">;</span><span class="scilaboperator">-</span><span class="scilabnumber">0.4701074</span><span class="scilabopenclose">]</span><span class="scilabdefault">;</span></pre></td><td valign="top"><a href="scilab://scilab.execexample/"><img src="ScilabExecute.png" border="0"/></a></td><td valign="top"><a href="scilab:/ [...]
+
+<div class="refsection"><h3 class="title">Authors</h3>
+ <ul class="itemizedlist"><li class="member">Copyright (C) 2009 - 2010 - Francesco Menoncin</li>
+ <li class="member">Copyright (C) 2010 - DIGITEO - Michael Baudin</li></ul></div>
+
+<div class="refsection"><h3 class="title">Bibliography</h3>
+ <p class="para">TODO</p></div>
+
+<div class="refsection"><h3 class="title">See also</h3>
+ <ul class="itemizedlist"><li class="member"><a href="bsoption.html" class="link">bsoption</a></li>
+ <li class="member"><a href="bsimpvol.html" class="link">bsimpvol</a></li></ul></div>
+
+
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="bollinger.html"><< bollinger</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="bsimpvol.html">bsimpvol >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+ </body>
+</html>
diff --git a/help/en_US/scilab_en_US_help/bsimpvol.html b/help/en_US/scilab_en_US_help/bsimpvol.html
new file mode 100644
index 0000000..eecf021
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/bsimpvol.html
@@ -0,0 +1,92 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>bsimpvol</title>
+ <style type="text/css" media="all">
+ @import url("scilab_code.css");
+ @import url("xml_code.css");
+ @import url("c_code.css");
+ @import url("style.css");
+ </style>
+ </head>
+ <body>
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="bsgreeks.html"><< bsgreeks</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="bsoption.html">bsoption >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+
+
+
+ <span class="path"><a href="index.html">Financial module</a> >> <a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a> > bsimpvol</span>
+
+ <br /><br />
+ <div class="refnamediv"><h1 class="refname">bsimpvol</h1>
+ <p class="refpurpose">Compute the implied volatility in a Black and Scholes framework. The function computes the volatility by equating the theoretical value of an option (with both constant riskless interest rate and volatility) to its market value.</p></div>
+ <div class="refsynopsisdiv"><h3 class="title">SYNOPSIS</h3>
+ <div class="synopsis"><pre><span class="default">[</span><span class="default">sigmaC</span><span class="default">,</span><span class="default">sigmaP</span><span class="default">]=</span><span class="functionid">bsimpvol</span><span class="default">(</span><span class="default">option</span><span class="default">,</span><span class="default">S</span><span class="default">,</span><span class="default">K</span><span class="default">,</span><span class="default">r</span><span class="de [...]
+ <div class="refsection"><h3 class="title">Description</h3>
+ <p class="para">Compute the Black and Scholes implied volatility</p></div>
+ <div class="refsection"><h3 class="title">Parameters</h3>
+ <dl><dt><span class="term">option</span>
+ <dd><p class="para">the market price of an option (either put or call)</p></dd></dt>
+ <dt><span class="term">S</span>
+ <dd><p class="para">current price of the underlying asset</p></dd></dt>
+ <dt><span class="term">K</span>
+ <dd><p class="para">strike price of the option</p></dd></dt>
+ <dt><span class="term">r</span>
+ <dd>riskless interest rate (assumed to be constant until the maturity)</dd></dt>
+ <dt><span class="term">T</span>
+ <dd>time to maturity; it must be in the same time unit of measure as the riskless interest rate (if the riskless interest rate is annual, then an option with maturity of 3 months must have T=3/12)</dd></dt>
+ <dt><span class="term">sigma0</span>
+ <dd>the value of the volatility the solver must start from (it is a guess value)</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Output</h3>
+ <dl><dt><span class="term">sigmaC</span>
+ <dd><p class="para">implicit volatility of a call option; the function writes "Call: good convergence" if the solver finds a good value for the implicit volatility, instead it writes "Call: bad convergence"</p></dd></dt>
+ <dt><span class="term">sigmaP</span>
+ <dd>implicit volatility of a put option; the function writes "Put: good convergence" if the solver finds a good value for the implicit volatility, instead it writes "Put: bad convergence"</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Example</h3>
+ <p class="para">We assume that an option (eithe call or put) is worth 1.09 euros on the market. It is written on an asset whose value is 25 euros, with a strike price of 25 euros. If the (annual) riskless interest rate is 0.001 and the time to maturity is 3 months, then the implicit volatility is computed with the following command.</p>
+ <p class="para">-->[sigmaC,sigmaP]=bsimpvol(1.09,25,25,0.001,3/12,0.1)</p>
+ <p class="para">Call: good convergence</p>
+ <p class="para">Put: good convergence</p>
+ <p class="para">sigmaP = 0.2193413</p>
+ <p class="para">sigmaC = 0.2180861</p></div>
+ <div class="refsection"><h3 class="title">Authors</h3>
+ <p class="para">Francesco Menoncin - Brescia University - 2010</p></div>
+ <div class="refsection"><h3 class="title">See Also</h3>
+ <ul class="itemizedlist"><li class="member"><a href="bsoption.html" class="link">bsoption</a></li>
+ <li class="member"><a href="bsimpvol.html" class="link">bsimpvol</a></li>
+ <li class="member"></li></ul></div>
+
+
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="bsgreeks.html"><< bsgreeks</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="bsoption.html">bsoption >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+ </body>
+</html>
diff --git a/help/en_US/scilab_en_US_help/bsoption.html b/help/en_US/scilab_en_US_help/bsoption.html
new file mode 100644
index 0000000..549b37e
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/bsoption.html
@@ -0,0 +1,87 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>bsoption</title>
+ <style type="text/css" media="all">
+ @import url("scilab_code.css");
+ @import url("xml_code.css");
+ @import url("c_code.css");
+ @import url("style.css");
+ </style>
+ </head>
+ <body>
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="bsimpvol.html"><< bsimpvol</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="cfr.html">cfr >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+
+
+
+ <span class="path"><a href="index.html">Financial module</a> >> <a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a> > bsoption</span>
+
+ <br /><br />
+ <div class="refnamediv"><h1 class="refname">bsoption</h1>
+ <p class="refpurpose">Compute the value of both a call and a put option in a Black and Scholes framework (with both constant riskless interest rate and volatility)</p></div>
+ <div class="refsynopsisdiv"><h3 class="title">SYNOPSIS</h3>
+ <div class="synopsis"><pre><span class="default">[</span><span class="default">C</span><span class="default">,</span><span class="default">P</span><span class="default">]=</span><span class="functionid">bsoption</span><span class="default">(</span><span class="default">S</span><span class="default">,</span><span class="default">K</span><span class="default">,</span><span class="default">r</span><span class="default">,</span><span class="default">T</span><span class="default">,</span> [...]
+ <div class="refsection"><h3 class="title">Description</h3>
+ <p class="para">Compute the Black and Scholes value of both a call and a put option</p></div>
+ <div class="refsection"><h3 class="title">Parameters</h3>
+ <dl><dt><span class="term">S</span>
+ <dd><p class="para">current price of the underlying asset</p></dd></dt>
+ <dt><span class="term">K</span>
+ <dd><p class="para">strike price of the option</p></dd></dt>
+ <dt><span class="term">r</span>
+ <dd>riskless interest rate (assumed to be constant until the maturity)</dd></dt>
+ <dt><span class="term">T</span>
+ <dd>time to maturity; it must be in the same time unit of measure as the riskless interest rate (if the riskless interest rate is annual, then an option with maturity of 3 months must have T=3/12)</dd></dt>
+ <dt><span class="term">sigma</span>
+ <dd>the volatility of the underlying (log-) returns; it must have the same time unit of measure as the riskless interest rate</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Output</h3>
+ <dl><dt><span class="term">C</span>
+ <dd>value of a call option</dd></dt>
+ <dt><span class="term">P</span>
+ <dd>value of a put option</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Example</h3>
+ <p class="para">We assume that an option (either call or put) is written on an asset whose value is 25 euros, with a strike price of 25 euros. If the (annual) riskless interest rate is 0.001, the time to maturity is 3 months, and the (annual) volatility of the underlying (log-) returns is 0.22, then the value of the call and the put options are computed as follows.</p>
+ <p class="para">-->[C,P]=bsoption(25,25,0.001,3/12,0.22)</p>
+ <p class="para">P = 1.0932796</p>
+ <p class="para">C = 1.0995288</p></div>
+ <div class="refsection"><h3 class="title">Authors</h3>
+ <p class="para">Francesco Menoncin - Brescia University - 2010</p></div>
+ <div class="refsection"><h3 class="title">See Also</h3>
+ <ul class="itemizedlist"><li class="member"><a href="bsgreeks.html" class="link">bsgreeks</a></li>
+ <li class="member"><a href="bsimpvol.html" class="link">bsimpvol</a></li></ul></div>
+
+
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="bsimpvol.html"><< bsimpvol</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="cfr.html">cfr >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+ </body>
+</html>
diff --git a/help/en_US/scilab_en_US_help/c_code.css b/help/en_US/scilab_en_US_help/c_code.css
new file mode 100644
index 0000000..948d2ee
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/c_code.css
@@ -0,0 +1,54 @@
+.ccomment {
+ font-style: italic;
+ color: #b22222
+}
+
+.cdefault {
+ font-style: normal;
+ color: #000000
+}
+
+.copenclose {
+ font-style: normal;
+ color: #000000
+}
+
+.coperator {
+ font-style: normal;
+ color: #000000
+}
+
+.cstring {
+ font-style: normal;
+ color: #a6557a
+}
+
+.ctype {
+ font-style: normal;
+ color: #55a655
+}
+
+.cpreprocessor {
+ font-style: normal;
+ color: #9965a6
+}
+
+.cid {
+ font-style: normal;
+ color: #000000
+}
+
+.ckeyword {
+ font-style: normal;
+ color: #ad3ff2
+}
+
+.cmodifier {
+ font-style: normal;
+ color: #ad3ff2
+}
+
+.cnumber {
+ font-style: normal;
+ color: #008b8b
+}
diff --git a/help/en_US/scilab_en_US_help/cfr.html b/help/en_US/scilab_en_US_help/cfr.html
new file mode 100644
index 0000000..4368440
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/cfr.html
@@ -0,0 +1,101 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>cfr</title>
+ <style type="text/css" media="all">
+ @import url("scilab_code.css");
+ @import url("xml_code.css");
+ @import url("c_code.css");
+ @import url("style.css");
+ </style>
+ </head>
+ <body>
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="bsoption.html"><< bsoption</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="duration.html">duration >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+
+
+
+ <span class="path"><a href="index.html">Financial module</a> >> <a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a> > cfr</span>
+
+ <br /><br />
+ <div class="refnamediv"><h1 class="refname">cfr</h1>
+ <p class="refpurpose">compare two or more time series of data and eliminate the elements which do not have the same date</p></div>
+ <div class="refsynopsisdiv"><h3 class="title">SYNOPSIS</h3>
+ <div class="synopsis"><pre><span class="default">[</span><span class="default">S</span><span class="default">]=</span><span class="functionid">cfr</span><span class="default">(</span><span class="default">S1</span><span class="default">,</span><span class="default">S2</span><span class="default">[,</span><span class="default">S3</span><span class="default">,</span><span class="default">S4</span><span class="default">,...]);</span></pre></div></div>
+ <div class="refsection"><h3 class="title">Description</h3>
+ <p class="para">Compare time series and make them homogeneous with respect to the dates (by eliminating the elements which do not have the same date)</p></div>
+ <div class="refsection"><h3 class="title">Parameters</h3>
+ <dl><dt><span class="term">S1</span>
+ <dd><p class="para">two column matrix: the first column must be a list of dates, while the second column must contain data</p></dd></dt>
+ <dt><span class="term">S2</span>
+ <dd><p class="para">two column matrix: the first column must be a list of dates, while the second column must contain data</p></dd></dt>
+ <dt><span class="term">S3, S4,...</span>
+ <dd>any other two-column matrix as the previous ones</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Output</h3>
+ <dl><dt><span class="term">S</span>
+ <dd>a matrix whose first column contains the dates, while the other columns contain the series of data</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Example</h3>
+ <p class="para">First we create two time series with the following commands</p>
+ <p class="para">-->S1=[datenum(2010*ones(10,1),ones(10,1),[1:10]') [1:10]']</p>
+ <p class="para">S1 = 734139. 1.</p>
+ <p class="para">734140. 2.</p>
+ <p class="para">734141. 3.</p>
+ <p class="para">734142. 4.</p>
+ <p class="para">734143. 5.</p>
+ <p class="para">734144. 6.</p>
+ <p class="para">734145. 7.</p>
+ <p class="para">734146. 8.</p>
+ <p class="para">734147. 9.</p>
+ <p class="para">734148. 10.</p>
+ <p class="para">-->S2=[datenum(2010*ones(5,1),ones(5,1),[1:2:10]') [1:2:10]'*5+4]</p>
+ <p class="para">S2 = 734139. 9.</p>
+ <p class="para">734141. 19.</p>
+ <p class="para">734143. 29.</p>
+ <p class="para">734145. 39.</p>
+ <p class="para">734147. 49.</p>
+ <p class="para">Then we use the function for selecting, from these time series, only the data which compare in both of them</p>
+ <p class="para">-->S=cfr(S1,S2)</p>
+ <p class="para">S = 734139. 1. 9.</p>
+ <p class="para">734141. 3. 19.</p>
+ <p class="para">734143. 5. 29.</p>
+ <p class="para">734145. 7. 39.</p>
+ <p class="para">734147. 9. 49.</p></div>
+ <div class="refsection"><h3 class="title">Authors</h3>
+ <p class="para">Francesco Menoncin - Brescia University - 2010</p></div>
+ <div class="refsection"><h3 class="title">See Also</h3>
+ <ul class="itemizedlist"><li class="member"></li></ul></div>
+
+
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="bsoption.html"><< bsoption</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="duration.html">duration >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+ </body>
+</html>
diff --git a/help/en_US/scilab_en_US_help/duration.html b/help/en_US/scilab_en_US_help/duration.html
new file mode 100644
index 0000000..6c9a369
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/duration.html
@@ -0,0 +1,86 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>duration</title>
+ <style type="text/css" media="all">
+ @import url("scilab_code.css");
+ @import url("xml_code.css");
+ @import url("c_code.css");
+ @import url("style.css");
+ </style>
+ </head>
+ <body>
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="cfr.html"><< cfr</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="esvarevt.html">esvarevt >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+
+
+
+ <span class="path"><a href="index.html">Financial module</a> >> <a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a> > duration</span>
+
+ <br /><br />
+ <div class="refnamediv"><h1 class="refname">duration</h1>
+ <p class="refpurpose">given a set of cash flows (either positive of negative) from an investment and the dates at which they are available, the function computes: the duration of the cash flows, the convexity of the cash flows, and the yield-to-maturity "ytm" (both duration and convexity are computed by taking ytm as the discount rate)</p></div>
+ <div class="refsynopsisdiv"><h3 class="title">SYNOPSIS</h3>
+ <div class="synopsis"><pre><span class="default">[</span><span class="default">dur</span><span class="default">,</span><span class="default">con</span><span class="default">,</span><span class="default">ytm</span><span class="default">]=</span><span class="functionid">duration</span><span class="default">(</span><span class="default">t</span><span class="default">,</span><span class="default">c</span><span class="default">);</span></pre></div></div>
+ <div class="refsection"><h3 class="title">Description</h3>
+ <p class="para">On cash flows available at given dates, duration, convexity and yield to maturity are computed</p></div>
+ <div class="refsection"><h3 class="title">Parameters</h3>
+ <dl><dt><span class="term">t</span>
+ <dd>column vector of dates at which cash flows are available: the first element must be zero; time unit of measure is generally the year</dd></dt>
+ <dt><span class="term">c</span>
+ <dd>column vector containing the cash flows; the first element must be the cost of the investment (and it must be a negative number)</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Output</h3>
+ <dl><dt><span class="term">dur</span>
+ <dd>duration (weighted time to maturity) of the cash flows; this output has the same time unit of measure of the input "t"</dd></dt>
+ <dt><span class="term">con</span>
+ <dd>convexity (weighted square time to maturity) of the cash flows; this output has the same time unit of measure of the input "t"</dd></dt>
+ <dt><span class="term">ytm</span>
+ <dd>yield to maturity (i.e. internal rate of return) of the cash flows; this output has the same time unit of measure of the input "t"; this value is computed with the fsolve function; if the convergence of the algorithm is not good, a message is shown</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Example</h3>
+ <p class="para">A bond, whose value on the market is 101.5, pays a cash flow of 2.5 euros any six month (i.e. 1/2 year) and for the next 2 years. At maturity it pays also its face value of 100 euros. Let us compute duration, convexity, and yield-to-maturity.</p>
+ <p class="para">At first we define the vector of dates and cash flows</p>
+ <p class="para">-->t=[0 0.5 1 1.5 2]';</p>
+ <p class="para">-->c=[-101.5 2.5 2.5 2.5 102.5]';</p>
+ <p class="para">-->[D,C,Y]=duration(t,c)</p>
+ <p class="para">Y = 0.0425443</p>
+ <p class="para">C = 3.7981714</p>
+ <p class="para">D = 1.9286213</p></div>
+ <div class="refsection"><h3 class="title">Authors</h3>
+ <p class="para">Francesco Menoncin - Brescia University - 2010</p></div>
+ <div class="refsection"><h3 class="title">See Also</h3>
+ <ul class="itemizedlist"><li class="member"></li></ul></div>
+
+
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="cfr.html"><< cfr</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="esvarevt.html">esvarevt >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+ </body>
+</html>
diff --git a/help/en_US/scilab_en_US_help/esvarevt.html b/help/en_US/scilab_en_US_help/esvarevt.html
new file mode 100644
index 0000000..1399e00
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/esvarevt.html
@@ -0,0 +1,103 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>esvarevt</title>
+ <style type="text/css" media="all">
+ @import url("scilab_code.css");
+ @import url("xml_code.css");
+ @import url("c_code.css");
+ @import url("style.css");
+ </style>
+ </head>
+ <body>
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="duration.html"><< duration</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="esvarlin.html">esvarlin >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+
+
+
+ <span class="path"><a href="index.html">Financial module</a> >> <a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a> > esvarevt</span>
+
+ <br /><br />
+ <div class="refnamediv"><h1 class="refname">esvarevt</h1>
+ <p class="refpurpose">Compute both Expected Shortfall and Value at Risk by using the Extreme Value Theory. Furthermore, also the parameter of the Generalized Pareto Distribution are estimated with the Maximum Likelihood method</p></div>
+ <div class="refsynopsisdiv"><h3 class="title">SYNOPSIS</h3>
+ <div class="synopsis"><pre><span class="default">[</span><span class="default">es</span><span class="default">,</span><span class="default">var</span><span class="default">,</span><span class="default">xoptim</span><span class="default">,</span><span class="default">v</span><span class="default">,</span><span class="default">inf</span><span class="default">]=</span><span class="functionid">esvarevt</span><span class="default">(</span><span class="default">x0</span><span class="defaul [...]
+ <div class="refsection"><h3 class="title">Description</h3>
+ <p class="para">The Extreme Value Theory assumes that a phenomenon has a uniform distribution before a given threshold "u", while after this threshold it follows a Generalized Pareto Distribution having the form</p>
+ <p class="para">f(x) = (1+xi*(x-u)/beta)^(-1/xi-1)/beta</p>
+ <p class="para">This function estimates both "xi" and "beta" on the data (by Maximum Likelihood) and computes both the Expected Shortfall and the Value at Risk by using this density function.</p></div>
+ <div class="refsection"><h3 class="title">Parameters</h3>
+ <dl><dt><span class="term">x0</span>
+ <dd>guess values used by the fsolve function for estimating the parameters "xi" and "beta" of the Generalized Pareto Distribution (Maximum Likelihood estimation)</dd></dt>
+ <dt><span class="term">data</span>
+ <dd>vector containing the historical data; these can be, for instance, prices or returns</dd></dt>
+ <dt><span class="term">u</span>
+ <dd>threshold above which the data are assumed to follow the Generalized Pareto Distribution</dd></dt>
+ <dt><span class="term">alpha</span>
+ <dd>confidence level at which all the risk measures must be computed; this value must strictly stay between 0 and 1 (and cannot be neither 0 nor 1)</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Output</h3>
+ <dl><dt><span class="term">ES</span>
+ <dd>expected shortfall, i.e. the mean of the data exceeding the alpha-quantile of the Generalized Pareto Distribution (on the right tail). The unit of measure is the same as that used for "data" (i.e. if data are returns, then this ES is expressed as a return)</dd></dt>
+ <dt><span class="term">VaR</span>
+ <dd>value at risk, i.e. the loss coinciding with the alpha-quantile of the Generalized Pareto Distribution (on the right tail). The unit of measure is the same as that used for "data"</dd></dt>
+ <dt><span class="term">xoptim</span>
+ <dd>estimated values (with maximum likelihood) of parameters "xi" and "beta" of the Generalized Pareto Distribution</dd></dt>
+ <dt><span class="term">v</span>
+ <dd>value of the gradient of the likelihood function (it should be as close as possible to zero)</dd></dt>
+ <dt><span class="term">inf</span>
+ <dd>same meaning as "inf" in the "fsolve" function</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Example</h3>
+ <p class="para"><p class="para">First we generate 1000 random numbers taken from a Generalized Pareto Distribution. First step is the creation of a vector of 1000 uniformly distributed random variables:</p>
+ <p class="para">-->U=grand(1000,1,'def');</p>
+ <p class="para">then we create the random variables from the GPD with parameters u=0.0001; xi=0.5; beta=0.00015:</p>
+ <p class="para">-->x=0.0001-0.00015/0.5+0.00015/0.5*(1-U)^(-0.5);</p></p>
+ <p class="para">These data could be daily return on an asset. Now we can use the function on vector x for computing ES and VaR at, for instance, 0.01 confidence level</p>
+ <p class="para">-->[es,var,xoptim,v,inf]=esvarevt([0.2 0.0002],x,0.0001,0.01)</p>
+ <p class="para">inf = 1.</p>
+ <p class="para">v = 1.0D-12 *</p>
+ <p class="para">- 1.8189894 - 0.0017764</p>
+ <p class="para">xoptim = 0.5020924 0.0001470</p>
+ <p class="para">var = 0.0027625</p>
+ <p class="para">es = 0.0057426</p>
+ <p class="para">We can see that the convergence is good (please note that the algorithm is very sensitive to the initial condition x0). The estimated values of "xi" and "beta" are close to the true ones.</p></div>
+ <div class="refsection"><h3 class="title">Authors</h3>
+ <p class="para">Francesco Menoncin - Brescia University - 2010</p></div>
+ <div class="refsection"><h3 class="title">See Also</h3>
+ <ul class="itemizedlist"><li class="member"><a href="esvaroptim.html" class="link">esvaroptim</a></li>
+ <li class="member"></li>
+ <li class="member"><a href="esvarevt.html" class="link">esvarevt</a></li></ul></div>
+
+
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="duration.html"><< duration</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="esvarlin.html">esvarlin >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+ </body>
+</html>
diff --git a/help/en_US/scilab_en_US_help/esvarlin.html b/help/en_US/scilab_en_US_help/esvarlin.html
new file mode 100644
index 0000000..7e6c43c
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/esvarlin.html
@@ -0,0 +1,89 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>esvarlin</title>
+ <style type="text/css" media="all">
+ @import url("scilab_code.css");
+ @import url("xml_code.css");
+ @import url("c_code.css");
+ @import url("style.css");
+ </style>
+ </head>
+ <body>
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="esvarevt.html"><< esvarevt</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="esvaroptim.html">esvaroptim >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+
+
+
+ <span class="path"><a href="index.html">Financial module</a> >> <a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a> > esvarlin</span>
+
+ <br /><br />
+ <div class="refnamediv"><h1 class="refname">esvarlin</h1>
+ <p class="refpurpose">Compute three risk measures on historical prices of a set of assets, and at a given confidence level. The three risk measures are: Expected Shortfall (ES), Value at Risk (VaR) and a Linear Spectral risk measure (lin).</p></div>
+ <div class="refsynopsisdiv"><h3 class="title">SYNOPSIS</h3>
+ <div class="synopsis"><pre><span class="default">[</span><span class="default">ES</span><span class="default">,</span><span class="default">VaR</span><span class="default">,</span><span class="default">L</span><span class="default">]=</span><span class="functionid">esvarlin</span><span class="default">(</span><span class="default">prices</span><span class="default">,</span><span class="default">alpha</span><span class="default">);</span></pre></div></div>
+ <div class="refsection"><h3 class="title">Description</h3>
+ <p class="para">On historical prices of some assets compute three risk measures at a given confidence level. The three measures are: Expected Shortfall (the mean of the losses exceeding a given quantile), Value at Risk (coinciding with a quantile), and a Linear Spectral risk measure whose spectrum linearly decreases for losses exceeding a given quantile (the same used for the previous risk measures)</p></div>
+ <div class="refsection"><h3 class="title">Parameters</h3>
+ <dl><dt><span class="term">prices</span>
+ <dd>any column of this matrix contains the historical prices of an asset</dd></dt>
+ <dt><span class="term">alpha</span>
+ <dd>confidence level at which all the risk measures must be computed; this value must strictly stay between 0 and 1 (and cannot be neither 0 nor 1)</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Output</h3>
+ <dl><dt><span class="term">ES</span>
+ <dd>expected shortfall (as a percentage of the last price), i.e. the mean of the losses exceeding the alpha-quantile</dd></dt>
+ <dt><span class="term">VaR</span>
+ <dd>value at risk (as percentage of the last price), i.e. the loss coinciding with the alpha-quantile</dd></dt>
+ <dt><span class="term">L</span>
+ <dd>the wighted mean of the losses exceeding the alpha-quantile (the weights linearly decrease); as a percentage of last price</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Example</h3>
+ <p class="para"><p class="para">First we generate 1000 log-normally distributed prices for three different assets whose initial values are 25 euros, 50 euros, and 110 euros. First step is the creation of a 1000x3 matrix of normal random variables (with mean 0.1/250 and standard deviation 0.2/sqrt(250))</p>
+ <p class="para">-->M=grand(1000,3,'nor',0.1/250,0.2/sqrt(250));</p>
+ <p class="para">Then we create the prices</p>
+ <p class="para">-->prices=exp(cumsum(M,1))*diag([25 50 110]);</p></p>
+ <p class="para">Now the three risk measures are computed</p>
+ <p class="para">-->[ES,VaR,L]=esvarlin(prices,0.01)</p>
+ <p class="para">L = 0.0365767 0.0327525 0.0351212</p>
+ <p class="para">VaR = 0.0274819 0.0281535 0.0281464</p>
+ <p class="para">ES = 0.0331532 0.0309606 0.0323584</p></div>
+ <div class="refsection"><h3 class="title">Authors</h3>
+ <p class="para">Francesco Menoncin - Brescia University - 2010</p></div>
+ <div class="refsection"><h3 class="title">See Also</h3>
+ <ul class="itemizedlist"><li class="member"><a href="esvaroptim.html" class="link">esvaroptim</a></li>
+ <li class="member"><a href="backtest.html" class="link">backtest</a></li>
+ <li class="member"><a href="esvarevt.html" class="link">esvarevt</a></li></ul></div>
+
+
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="esvarevt.html"><< esvarevt</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="esvaroptim.html">esvaroptim >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+ </body>
+</html>
diff --git a/help/en_US/scilab_en_US_help/esvaroptim.html b/help/en_US/scilab_en_US_help/esvaroptim.html
new file mode 100644
index 0000000..910185d
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/esvaroptim.html
@@ -0,0 +1,111 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>esvaroptim</title>
+ <style type="text/css" media="all">
+ @import url("scilab_code.css");
+ @import url("xml_code.css");
+ @import url("c_code.css");
+ @import url("style.css");
+ </style>
+ </head>
+ <body>
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="esvarlin.html"><< esvarlin</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="euler.html">euler >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+
+
+
+ <span class="path"><a href="index.html">Financial module</a> >> <a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a> > esvaroptim</span>
+
+ <br /><br />
+ <div class="refnamediv"><h1 class="refname">esvaroptim</h1>
+ <p class="refpurpose">Compute the optimal portfolio minimizing the Expected Value (this is a linear programming problem). The Value at Risk of the portfolio is also computed (this implements the Rockafeller-Uryasev algorithm)</p></div>
+ <div class="refsynopsisdiv"><h3 class="title">SYNOPSIS</h3>
+ <div class="synopsis"><pre><span class="default">[</span><span class="default">w</span><span class="default">,</span><span class="default">ES</span><span class="default">,</span><span class="default">VaR</span><span class="default">]=</span><span class="functionid">esvaroptim</span><span class="default">(</span><span class="default">price</span><span class="default">,</span><span class="default">ER</span><span class="default">,</span><span class="default">r</span><span class="default [...]
+ <div class="refsection"><h3 class="title">Description</h3>
+ <p class="para">Give the historical prices of a set of assets, compute the optimal portfolios solving four different problems. All of them minimize the Expected Shortfall subject to the constraint of having given expected return. The four problems are different for the following characteristics</p>
+ <p class="para">1) optimal portfolio allowing short selling and investing in the riskless asset;</p>
+ <p class="para">2) optimal portfolio allowing short selling but without investing in the riskless asset;</p>
+ <p class="para">3) optimal portfolio not allowing short selling and investing in the riskless asset;</p>
+ <p class="para">4) optimal portfolio not allowing short selling and without investing in the riskless asset.</p>
+ <p class="para">Finally the Vale at Risk of the optimal portfolio is computed. The procedure uses "qld" function.</p></div>
+ <div class="refsection"><h3 class="title">Parameters</h3>
+ <dl><dt><span class="term">price</span>
+ <dd>matrix whose columns contains the historical prices of the assets in the portfolio</dd></dt>
+ <dt><span class="term">ER</span>
+ <dd>expected return that the investor wants to obtain on his portfolio</dd></dt>
+ <dt><span class="term">r</span>
+ <dd>riskless interest rate</dd></dt>
+ <dt><span class="term">dt</span>
+ <dd>time frequency of the prices with respect to the time unit of measure of both "ER" and "r"; if the matrix of prices contains daily data and both "ER" and "r" are annual return, then dt=1/250 since there are 250 working day in one year</dd></dt>
+ <dt><span class="term">alpha</span>
+ <dd>confidence level at which both Expected Shortfall and Value at Risk must be computed (it must be between 0 and 1, with 0 and 1 both excluded)</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Output</h3>
+ <dl><dt><span class="term">w</span>
+ <dd>matrix containing the optimal portfolios; in particular:</dd>
+ <dd>first raw: with short selling and with r</dd>
+ <dd>second raw: with short selling and without r</dd>
+ <dd>third raw: without short selling and with r</dd>
+ <dd>fourth raw: without short selling and without r</dd></dt>
+ <dt><span class="term">ES</span>
+ <dd>Expected Shortfall of the optimal portfolio (at alpha confidence level)</dd></dt>
+ <dt><span class="term">VaR</span>
+ <dd>Value at Risk of the optimal portfolio (at alpha confidence level)</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Example</h3>
+ <p class="para"><p class="para">First we generate 1000x3 log-normally distributed daily asset prices with 0.1/250 mean and 0.2/sqrt(250) variance. The first prices of the three assets are 25 euros, 50 euros, and 110 euros respectively.</p>
+ <p class="para">-->M=grand(1000,3,'nor',0.1/250,0.2/sqrt(250));</p>
+ <p class="para">-->price=exp(cumsum(M,1))*diag([25 50 110]);</p></p>
+ <p class="para">Now we can use the function on these prices.</p>
+ <p class="para">-->[w,ES,VaR]=esvaroptim(price,0.05,0.01,1/250,0.01)</p>
+ <p class="para">Draw frontier? (y/n) y</p>
+ <p class="para">! with short selling without short selling !</p>
+ <p class="para">! with r without r with r without r !</p>
+ <p class="para">VaR = 0.0122548 0.0178937 0.0135530 0.0178937</p>
+ <p class="para">ES = 0.0135257 0.0208130 0.0153525 0.0208130</p>
+ <p class="para">w = 0.3180045 0.5742962 0.4706583 0.5742962</p>
+ <p class="para">0.1079194 0.2480433 0.1313949 0.2480433</p>
+ <p class="para">- 0.1904050 0.1776605 0. 0.1776605</p>
+ <p class="para">We see that the third asset is sold (negative portfolio component) when it is possible. If short selling is not allowed, then its weight is either positive or zero.</p>
+ <p class="para">The function also asks if one wants to see the optimal frontiers (this is optional since the procedure takes some time). The figure which is created shows four frontiers corresponding to the four different problems (the legend explains the meanings).</p></div>
+ <div class="refsection"><h3 class="title">Bibliography</h3>
+ <p class="para">"Optimization of Conditional Value-at-Risk", Rockafeller, R. T. and Uryasev, S., Journal of Risk, 2, 21-41, 2000</p></div>
+ <div class="refsection"><h3 class="title">Authors</h3>
+ <p class="para">Francesco Menoncin - Brescia University - 2010</p></div>
+ <div class="refsection"><h3 class="title">See Also</h3>
+ <ul class="itemizedlist"><li class="member"><a href="esvarevt.html" class="link">esvarevt</a></li>
+ <li class="member"></li></ul></div>
+
+
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="esvarlin.html"><< esvarlin</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="euler.html">euler >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+ </body>
+</html>
diff --git a/help/en_US/scilab_en_US_help/euler.html b/help/en_US/scilab_en_US_help/euler.html
new file mode 100644
index 0000000..4ce0b13
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/euler.html
@@ -0,0 +1,94 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>euler</title>
+ <style type="text/css" media="all">
+ @import url("scilab_code.css");
+ @import url("xml_code.css");
+ @import url("c_code.css");
+ @import url("style.css");
+ </style>
+ </head>
+ <body>
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="esvaroptim.html"><< esvaroptim</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="evt.html">evt >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+
+
+
+ <span class="path"><a href="index.html">Financial module</a> >> <a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a> > euler</span>
+
+ <br /><br />
+ <div class="refnamediv"><h1 class="refname">euler</h1>
+ <p class="refpurpose">Numerically solves a system of stochastic differential equation (by using the Euler discretization)</p></div>
+ <div class="refsynopsisdiv"><h3 class="title">SYNOPSIS</h3>
+ <div class="synopsis"><pre><span class="default">x</span><span class="default">=</span><span class="functionid">euler</span><span class="default">(</span><span class="default">drift</span><span class="default">,</span><span class="default">diffusion</span><span class="default">,</span><span class="default">dt</span><span class="default">,</span><span class="default">T</span><span class="default">,</span><span class="default">x0</span><span class="default">,</span><span class="default [...]
+ <div class="refsection"><h3 class="title">Description</h3>
+ <p class="para">The function numerically solves a system of stochastic differential equations in the following form:</p>
+ <p class="para">dx(1) = drift_1(x(1),x(2),..,x(n),t) dt + diffusion_1(x(1),x(2),..,x(n),t) dW</p>
+ <p class="para">dx(2) = drift_2(x(1),x(2),..,x(n),t) dt + diffusion_2(x(1),x(2),..,x(n),t) dW</p>
+ <p class="para">...</p>
+ <p class="para">dx(n) = drift_n(x(1),x(2),..,x(n),t) dt + diffusion_n(x(1),x(2),..,x(n),t) dW</p>
+ <p class="para">Please note that dW (the differential form of a Wiener process) could be a vector and, accordingly, each "diffusion" term could be a vector itself. All the elements of dW are assumed to be independent.</p></div>
+ <div class="refsection"><h3 class="title">Parameters</h3>
+ <dl><dt><span class="term">drift</span>
+ <dd>this is a string containing a column vector of the functional forms of drift_1, drift_2 and so on. The variables "x" and "t" must be named exactly "x" and "t" and if there are more than one "x" the values must be named "x(1)", "x(2)", and so on.</dd></dt>
+ <dt><span class="term">diffusion</span>
+ <dd>This is a string containing a matrix which have as many raws as x's and as many columns as the elements of vector dW (containing the so-called risk sources). Thus, if there are three stochastic variables (i.e. x(1), x(2), and x(3)) driven by two risk sources (i.e. dW(1) and dW(2)) the "diffusion" is a 3x2 matrix</dd></dt>
+ <dt><span class="term">dt</span>
+ <dd>time unit of measure: if data are in annual form (like returns, for instance) but have daily frequency, then dt=1/250 (since there are 250 working day in one year)</dd></dt>
+ <dt><span class="term">T</span>
+ <dd>number of periods during which the stochastic differential equations must be solved (if T=2 years, and dt=1/250, then the function computes 500 values)</dd></dt>
+ <dt><span class="term">x0, t0</span>
+ <dd>initial values for the variables "x" and for time "t". These are the values the Euler algorithm must start from. x0 must be a column vector, while t is a scalar</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Output</h3>
+ <dl><dt><span class="term">x</span>
+ <dd>matrix whose columns contain the series of simulated variable "x"</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Example</h3>
+ <p class="para"><p class="para">Let us assume a stochastic mean reverting process for the interest rate "r":</p>
+ <p class="para">dr = 0.1 (b - r) dt + 0.056 sqrt(r) dWr</p>
+ <p class="para">where the parameter "b" is another mean reverting process</p>
+ <p class="para">db = 0.2 (0.05 - b) dt + 0.01 sqrt(b) dWb</p></p>
+ <p class="para">In order to simulate two years of daily data starting from 0.04 for both "r" and "b" at time t=0, we must give the following command (we assume x(1)=r and x(2)=b)</p>
+ <p class="para">-->drift='[0.1*(x(2)-x(1)); 0.2*(0.05-x(2))]';</p>
+ <p class="para">-->diffusion='[0.056*sqrt(x(1)),0;0,0.01*sqrt(x(2))]';</p>
+ <p class="para">-->x=euler(drift,diffusion,1/250,2,[0.04;0.04],0)</p>
+ <p class="para">With command "plot(x)" one can see both stochastic processes</p></div>
+ <div class="refsection"><h3 class="title">Authors</h3>
+ <p class="para">Francesco Menoncin - Brescia University - 2010</p></div>
+ <div class="refsection"><h3 class="title">See Also</h3>
+ <ul class="itemizedlist"><li class="member"><a href="gbm.html" class="link">gbm</a></li></ul></div>
+
+
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="esvaroptim.html"><< esvaroptim</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="evt.html">evt >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+ </body>
+</html>
diff --git a/help/en_US/scilab_en_US_help/evt.html b/help/en_US/scilab_en_US_help/evt.html
new file mode 100644
index 0000000..c0d726d
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/evt.html
@@ -0,0 +1,94 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>evt</title>
+ <style type="text/css" media="all">
+ @import url("scilab_code.css");
+ @import url("xml_code.css");
+ @import url("c_code.css");
+ @import url("style.css");
+ </style>
+ </head>
+ <body>
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="euler.html"><< euler</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="gbm.html">gbm >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+
+
+
+ <span class="path"><a href="index.html">Financial module</a> >> <a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a> > evt</span>
+
+ <br /><br />
+ <div class="refnamediv"><h1 class="refname">evt</h1>
+ <p class="refpurpose">Estimate the parameters of the Generalized Pareto Distribution with the Maximum Likelihood method</p></div>
+ <div class="refsynopsisdiv"><h3 class="title">SYNOPSIS</h3>
+ <div class="synopsis"><pre><span class="default">[</span><span class="default">xoptim</span><span class="default">,</span><span class="default">v</span><span class="default">,</span><span class="default">inf</span><span class="default">]=</span><span class="functionid">evt</span><span class="default">(</span><span class="default">x0</span><span class="default">,</span><span class="default">x</span><span class="default">,</span><span class="default">u</span><span class="default">)</sp [...]
+ <div class="refsection"><h3 class="title">Description</h3>
+ <p class="para">For data (x) higher than a threshold "u", the Generalized Pareto Distribution have the form</p>
+ <p class="para">f(x) = (1+xi*(x-u)/beta)^(-1/xi-1)/beta</p>
+ <p class="para">This function estimates both "xi" and "beta" on the data (by Maximum Likelihood).</p></div>
+ <div class="refsection"><h3 class="title">Parameters</h3>
+ <dl><dt><span class="term">x0</span>
+ <dd>guess values used by the fsolve function for estimating the parameters "xi" and "beta" of the Generalized Pareto Distribution (Maximum Likelihood estimation)</dd></dt>
+ <dt><span class="term">x</span>
+ <dd>vector containing the historical data; these can be, for instance, prices or returns</dd></dt>
+ <dt><span class="term">u</span>
+ <dd>threshold above which the data are assumed to follow the Generalized Pareto Distribution</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Output</h3>
+ <dl><dt><span class="term">xoptim</span>
+ <dd>estimated values (with maximum likelihood) of parameters "xi" and "beta" of the Generalized Pareto Distribution</dd></dt>
+ <dt><span class="term">v</span>
+ <dd>value of the gradient of the likelihood function (it should be as close as possible to zero)</dd></dt>
+ <dt><span class="term">inf</span>
+ <dd>same meaning as "inf" in the "fsolve" function</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Example</h3>
+ <p class="para"><p class="para">First we generate 1000 random numbers taken from a Generalized Pareto Distribution. First step is the creation of a vector of 1000 uniformly distributed random variables:</p>
+ <p class="para">-->U=grand(1000,1,'def');</p>
+ <p class="para">then we create the random variables from the GPD with parameters u=0.0001; xi=0.5; beta=0.00015:</p>
+ <p class="para">-->x=0.0001-0.00015/0.5+0.00015/0.5*(1-U)^(-0.5);</p></p>
+ <p class="para">These data could be daily return on an asset. Now we can use the function on vector x for computing ES and VaR at, for instance, 0.01 confidence level</p>
+ <p class="para">-->[xoptim,v,inf]=evt([0.2 0.0002],x,0.0001)</p>
+ <p class="para">inf = 1.</p>
+ <p class="para">v = 1.0D-12 *</p>
+ <p class="para">- 1.8189894 - 0.0017764</p>
+ <p class="para">xoptim = 0.5020924 0.0001470</p>
+ <p class="para">We can see that the convergence is good (please note that the algorithm is very sensitive to the initial condition x0). The estimated values of "xi" and "beta" are close to the true ones.</p></div>
+ <div class="refsection"><h3 class="title">Authors</h3>
+ <p class="para">Francesco Menoncin - Brescia University - 2010</p></div>
+ <div class="refsection"><h3 class="title">See Also</h3>
+ <ul class="itemizedlist"><li class="member"><a href="esvarevt.html" class="link">esvarevt</a></li>
+ <li class="member"></li></ul></div>
+
+
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="euler.html"><< euler</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="gbm.html">gbm >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+ </body>
+</html>
diff --git a/help/en_US/scilab_en_US_help/financial_overview.html b/help/en_US/scilab_en_US_help/financial_overview.html
new file mode 100644
index 0000000..00adbd0
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/financial_overview.html
@@ -0,0 +1,100 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>financial_overview</title>
+ <style type="text/css" media="all">
+ @import url("scilab_code.css");
+ @import url("xml_code.css");
+ @import url("c_code.css");
+ @import url("style.css");
+ </style>
+ </head>
+ <body>
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html"><< Financial module</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="backtest.html">backtest >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+
+
+
+ <span class="path"><a href="index.html">Financial module</a> >> <a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a> > financial_overview</span>
+
+ <br /><br />
+ <div class="refnamediv"><h1 class="refname">financial_overview</h1>
+
+ <p class="refpurpose">An overview of the Financial toolbox.</p></div>
+
+ <div class="refsection"><h3 class="title">Purpose</h3>
+
+ <p class="para">The module is dedicated to finance. There are three main areas that are covered:
+ <ul class="itemizedlist"><li><p class="para">risk measure and management,</p></li>
+ <li><p class="para">asset allocation,</p></li>
+ <li><p class="para">pricing.</p></li></ul></p>
+
+ <p class="para">For what concerns the risk measure, some functions are dedicated to the computation of Value at Risk (VaR)
+ and Expected Shortfall (ES).
+ Backtest is also implemented in order to check the goodness of such risk measures.
+ Both VaR and ES are also computed in an Extreme Value Theory framework (EVT).
+ Furthermore, it is possible to estimate the parameters of the EVT density function (through maximum likelihood).
+ The Mean Excess Function for graphical study of an EVT distribution is also implemented.
+ The interest rate risk is faced by functions aimed at computing duration, convexity, and yield to maturity.
+ Furthermore, Merton, Vasicek and Cox, Ingersoll and Ross interest rate models are implemented together with
+ the estimation of their parameters. Parametric interpolation of the interest rate curve is possible through
+ both Svennsons and Nelson-Siegels models.
+ Finally, some technical analysis indicators are implemented: Bollinger bands, moving averages, Hurst index.</p>
+
+ <p class="para">The asset allocation problem is faced by two functions which compute:
+
+ <ul class="itemizedlist"><li><p class="para">the optimal portfolio minimizing the variance of its return and</p></li>
+ <li><p class="para">the optimal portfolio minimizing the expected shortfall of its return.</p></li></ul>
+ In both cases, the portfolios with and without a riskless asset and with and without short selling are computed.</p>
+
+ <p class="para">Pricing problem is approached through functions aimed at:
+ <ul class="itemizedlist"><li><p class="para">computing the spread on Interest Rate Swaps,</p></li>
+ <li><p class="para">computing the value of options in the Black and Scholes framework (with Greeks and implied volatility),</p></li>
+ <li><p class="para">simulating stochastic processes (through Euler discretization).</p></li></ul></p></div>
+
+ <div class="refsection"><h3 class="title">Quick start</h3>
+
+ <p class="para">TODO</p>
+
+ <div class="programlisting"><table border="0" width="100%"><tr><td width="98%"><pre class="scilabcode"><span class="scilabid">TODO</span></pre></td><td valign="top"><a href="scilab://scilab.execexample/"><img src="ScilabExecute.png" border="0"/></a></td><td valign="top"><a href="scilab://scilab.editexample/"><img src="ScilabEdit.png" border="0"/></a></td><td></td></tr></table></div></div>
+
+ <div class="refsection"><h3 class="title">Authors</h3>
+
+ <p class="para">Copyright (C) 2009 - 2010 - Francesco Menoncin</p>
+
+ <p class="para">Copyright (C) 2010 - DIGITEO - Michael Baudin</p></div>
+
+
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html"><< Financial module</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="backtest.html">backtest >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+ </body>
+</html>
diff --git a/help/en_US/scilab_en_US_help/gbm.html b/help/en_US/scilab_en_US_help/gbm.html
new file mode 100644
index 0000000..fb536a3
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/gbm.html
@@ -0,0 +1,85 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>gbm</title>
+ <style type="text/css" media="all">
+ @import url("scilab_code.css");
+ @import url("xml_code.css");
+ @import url("c_code.css");
+ @import url("style.css");
+ </style>
+ </head>
+ <body>
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="evt.html"><< evt</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="hedge.html">hedge >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+
+
+
+ <span class="path"><a href="index.html">Financial module</a> >> <a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a> > gbm</span>
+
+ <br /><br />
+ <div class="refnamediv"><h1 class="refname">gbm</h1>
+ <p class="refpurpose">Estimate the parameters of a Geometric Brownian Motion (through the method of moments) on the data and graphically show the mean and two confidence intervals</p></div>
+ <div class="refsynopsisdiv"><h3 class="title">SYNOPSIS</h3>
+ <div class="synopsis"><pre><span class="default">[</span><span class="default">mu</span><span class="default">,</span><span class="default">sigma</span><span class="default">]=</span><span class="functionid">gbm</span><span class="default">(</span><span class="default">data</span><span class="default">,</span><span class="default">dt</span><span class="default">)</span></pre></div></div>
+ <div class="refsection"><h3 class="title">Description</h3>
+ <p class="para">If the variable x follows a Geometric Brownian Motion then it solves the stochastic differential equaiton</p>
+ <p class="para">dx/x = mu dt + sigma dW</p>
+ <p class="para">where dW is the differential form of a Wiener process and both "mu" and "sigma" are constant parameters. On historical data, the function estimates both mu and sigma and show a graph with the mean of the process, the mean+/- the standard deviation, and the mean +/-2 times the standard deviation</p></div>
+ <div class="refsection"><h3 class="title">Parameters</h3>
+ <dl><dt><span class="term">data</span>
+ <dd>column vector containing the historical data on which both the drift and the diffusion must be estimated</dd></dt>
+ <dt><span class="term">dt</span>
+ <dd>time unit of measure: if data are in annual form (like returns, for instance) but have daily frequency, then dt=1/250 (since there are 250 working day in one year)</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Output</h3>
+ <dl><dt><span class="term">mu, sigma</span>
+ <dd>respectively the drift and diffusion terms of the Geometric Brownian Motion</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Example</h3>
+ <p class="para">First we generate 1000 log-normally distributed daily prices for an asset whose initial values is 25 euros. First step is the creation of 1000 normal random variables (with mean 0.1/250 and standard deviation 0.2/sqrt(250))</p>
+ <p class="para">-->M=grand(1000,1,'nor',0.1/250,0.2/sqrt(250));</p>
+ <p class="para">Then we create the prices</p>
+ <p class="para">-->prices=exp(cumsum(M,1))*25;</p>
+ <p class="para">and apply the function with</p>
+ <p class="para">-->[mu,sigma]=gbm(prices,1/250);</p>
+ <p class="para">sigma = 0.2039105</p>
+ <p class="para">mu = 0.1443338</p>
+ <p class="para">We see the mean and the standard deviation are close to that we started from. The figure shows the original data, the mean and the confidence intervals.</p></div>
+ <div class="refsection"><h3 class="title">Authors</h3>
+ <p class="para">Francesco Menoncin - Brescia University - 2010</p></div>
+ <div class="refsection"><h3 class="title">See Also</h3>
+ <ul class="itemizedlist"><li class="member"><a href="euler.html" class="link">euler</a></li></ul></div>
+
+
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="evt.html"><< evt</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="hedge.html">hedge >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+ </body>
+</html>
diff --git a/help/en_US/scilab_en_US_help/hedge.html b/help/en_US/scilab_en_US_help/hedge.html
new file mode 100644
index 0000000..8837ea7
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/hedge.html
@@ -0,0 +1,89 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>hedge</title>
+ <style type="text/css" media="all">
+ @import url("scilab_code.css");
+ @import url("xml_code.css");
+ @import url("c_code.css");
+ @import url("style.css");
+ </style>
+ </head>
+ <body>
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="gbm.html"><< gbm</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="hurst.html">hurst >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+
+
+
+ <span class="path"><a href="index.html">Financial module</a> >> <a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a> > hedge</span>
+
+ <br /><br />
+ <div class="refnamediv"><h1 class="refname">hedge</h1>
+ <p class="refpurpose">Compute the hedge ratio between an asset "S" and a derivative on it "F"</p></div>
+ <div class="refsynopsisdiv"><h3 class="title">SYNOPSIS</h3>
+ <div class="synopsis"><pre><span class="default">h</span><span class="default">=</span><span class="functionid">hedge</span><span class="default">(</span><span class="default">S</span><span class="default">,</span><span class="default">F</span><span class="default">);</span></pre></div></div>
+ <div class="refsection"><h3 class="title">Description</h3>
+ <p class="para">Given the historical prices of both an asset "S" and a derivative written on it "F", the function computes the so-called hedge ration "h". If one multiplies the wealth invested in "S" by "h", one obtains the wealth that must be invested in "F" in order to hedged the position on "S". The hedge ratio is the opposite of the inverse of the elasticity of the derivative with respect to the u [...]
+ <div class="refsection"><h3 class="title">Parameters</h3>
+ <dl><dt><span class="term">S</span>
+ <dd>column vector containing the historical prices of the underlying asset</dd></dt>
+ <dt><span class="term">F</span>
+ <dd>column vector containing the historical prices of the derivative</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Output</h3>
+ <dl><dt><span class="term">h</span>
+ <dd>hedge ratio (as the opposite of the inverse of the estimated elasticity of "S" with respect to "F")</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Example</h3>
+ <p class="para">First we generate 100 log-normally distributed daily prices for an asset whose initial values is 25 euros. First step is the creation of 100 normal random variables (with mean 0.1/250 and standard deviation 0.2/sqrt(250))</p>
+ <p class="para">-->M=grand(100,1,'nor',0.1/250,0.2/sqrt(250));</p>
+ <p class="para">Then we create the prices</p>
+ <p class="para">-->S=exp(cumsum(M,1))*25;</p>
+ <p class="para">Now we create the prices of a derivative whose returns are more or less 5 times the returns on the underlying</p>
+ <p class="para">-->F=(S/S(1)).^grand(100,1,'unf',4.9,5.1);</p>
+ <p class="para">and so we are ready for using the function</p>
+ <p class="para">-->h=hedge(S,F)</p>
+ <p class="para">!N. observations 99 !</p>
+ <p class="para">!N. variables 2 !</p>
+ <p class="para">!R-square 0.9705684 !</p>
+ <p class="para">!R-square corrected 0.9702650 !</p>
+ <p class="para">!Coefficients t-statistics !</p>
+ <p class="para">!-0.0001464 -0.1427691 !</p>
+ <p class="para">!5.0436713 56.557729 !</p>
+ <p class="para">h = - 0.1982683</p>
+ <p class="para">The statistics show that the regression is good and the hedge ratio is reliable.</p></div>
+ <div class="refsection"><h3 class="title">Authors</h3>
+ <p class="para">Francesco Menoncin - Brescia University - 2010</p></div>
+
+
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="gbm.html"><< gbm</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="hurst.html">hurst >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+ </body>
+</html>
diff --git a/help/en_US/scilab_en_US_help/hurst.html b/help/en_US/scilab_en_US_help/hurst.html
new file mode 100644
index 0000000..19161cc
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/hurst.html
@@ -0,0 +1,84 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>hurst</title>
+ <style type="text/css" media="all">
+ @import url("scilab_code.css");
+ @import url("xml_code.css");
+ @import url("c_code.css");
+ @import url("style.css");
+ </style>
+ </head>
+ <body>
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="hedge.html"><< hedge</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="interest.html">interest >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+
+
+
+ <span class="path"><a href="index.html">Financial module</a> >> <a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a> > hurst</span>
+
+ <br /><br />
+ <div class="refnamediv"><h1 class="refname">hurst</h1>
+ <p class="refpurpose">Compute the Hurst index on historical prices</p></div>
+ <div class="refsynopsisdiv"><h3 class="title">SYNOPSIS</h3>
+ <div class="synopsis"><pre><span class="default">H</span><span class="default">=</span><span class="functionid">hurst</span><span class="default">(</span><span class="default">price</span><span class="default"> [,</span><span class="default">period</span><span class="default"> [,</span><span class="default">step</span><span class="default">]]);</span></pre></div></div>
+ <div class="refsection"><h3 class="title">Description</h3>
+ <p class="para">Given the historical prices of an asset the function computes the so-called Hurst index (or Hurst exponent) for fractional Brownian motion on the asset returns.</p>
+ <p class="para">If the Hurst index H is 0.5, then the price process is a "regular" Brownian motion; if H>0.5, then the increments of the process are positively correlated; finally, if H<0.5, the increments of the process are negatively correlated.</p>
+ <p class="para">The function also shows a scatter plot of the log of the sample length against the log of the variation coefficient of asset returns.</p></div>
+ <div class="refsection"><h3 class="title">Parameters</h3>
+ <dl><dt><span class="term">price</span>
+ <dd>column vector containing the historical prices of an asset (in general they are daily prices)</dd></dt>
+ <dt><span class="term">period</span>
+ <dd>optional parameter: first set of prices used for estimating the Hurst index (by default it is 250 - i.e. the working days in a year)</dd></dt>
+ <dt><span class="term">step</span>
+ <dd>optional parameter: increment in the set of prices used for estimating the Hurst index (by default it is 10). This is the increasing step in the rolling estimation.</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Output</h3>
+ <dl><dt><span class="term">H</span>
+ <dd>estimated Hurst index on the asset (log-) returns</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Example</h3>
+ <p class="para">First we generate 1000 log-normally distributed daily prices for an asset whose initial values is 25 euros. First step is the creation of 1000 normal random variables (with mean 0.1/250 and standard deviation 0.2/sqrt(250))</p>
+ <p class="para">-->M=grand(1000,1,'nor',0.1/250,0.2/sqrt(250));</p>
+ <p class="para">Then we create the prices</p>
+ <p class="para">-->S=exp(cumsum(M,1))*25;</p>
+ <p class="para">Now we are ready to use the function. We use it on the first 100 prices and with a step of 10 days</p>
+ <p class="para">-->H=hurst(S,100,10)</p>
+ <p class="para">H = 0.5588872</p>
+ <p class="para">We have a value close to 0.5 which means that the data should be more or less follow a Brownian motion.</p></div>
+ <div class="refsection"><h3 class="title">Authors</h3>
+ <p class="para">Francesco Menoncin - Brescia University - 2010</p></div>
+
+
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="hedge.html"><< hedge</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="interest.html">interest >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+ </body>
+</html>
diff --git a/help/en_US/scilab_en_US_help/index.html b/help/en_US/scilab_en_US_help/index.html
new file mode 100644
index 0000000..cf03833
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/index.html
@@ -0,0 +1,122 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title></title>
+ <style type="text/css" media="all">
+ @import url("scilab_code.css");
+ @import url("xml_code.css");
+ @import url("c_code.css");
+ @import url("style.css");
+ </style>
+ </head>
+ <body>
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+
+ </td>
+ <td width="40%" class="center">
+
+ </td>
+ <td width="30%" class="next">
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+
+
+
+
+ <br /><br />
+ <h3 class="book-title">Financial module</h3>
+<ul class="list-part"><a name="financial_module_manual"></a><div class="info"></div>
+
+<li><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html" class="part">Financial module</a>
+<ul class="list-chapter"><li><a href="financial_overview.html" class="refentry">financial_overview</a> — <span class="refentry-description">An overview of the Financial toolbox.</span></li>
+
+
+<li><a href="backtest.html" class="refentry">backtest</a> — <span class="refentry-description">Apply the backtest to three different risk measures (as percentage of lost): Expected Shortfall, Value at Risk, and a Spectral Measure with linear spectrum. Show the graph of historical returns and the risk measures. The thresholds of the backtest are also computed.</span></li>
+
+
+<li><a href="bollinger.html" class="refentry">bollinger</a> — <span class="refentry-description">Given a moving average on the historical prices of an asset, the function creates two figures: in the first both the historical prices and the Bollinger bands (i.e. the moving average +/- "a" times the price standard deviation) are shown, in the second the so-called b-percentage is shown</span></li>
+
+
+
+
+
+<li><a href="bsgreeks.html" class="refentry">bsgreeks</a> — <span class="refentry-description">Compute the Greeks for both a call and a put option in a Black and Scholes model.</span></li>
+
+
+<li><a href="bsimpvol.html" class="refentry">bsimpvol</a> — <span class="refentry-description">Compute the implied volatility in a Black and Scholes framework. The function computes the volatility by equating the theoretical value of an option (with both constant riskless interest rate and volatility) to its market value.</span></li>
+
+
+<li><a href="bsoption.html" class="refentry">bsoption</a> — <span class="refentry-description">Compute the value of both a call and a put option in a Black and Scholes framework (with both constant riskless interest rate and volatility)</span></li>
+
+
+<li><a href="cfr.html" class="refentry">cfr</a> — <span class="refentry-description">compare two or more time series of data and eliminate the elements which do not have the same date</span></li>
+
+
+<li><a href="duration.html" class="refentry">duration</a> — <span class="refentry-description">given a set of cash flows (either positive of negative) from an investment and the dates at which they are available, the function computes: the duration of the cash flows, the convexity of the cash flows, and the yield-to-maturity "ytm" (both duration and convexity are computed by taking ytm as the discount rate)</span></li>
+
+
+<li><a href="esvarevt.html" class="refentry">esvarevt</a> — <span class="refentry-description">Compute both Expected Shortfall and Value at Risk by using the Extreme Value Theory. Furthermore, also the parameter of the Generalized Pareto Distribution are estimated with the Maximum Likelihood method</span></li>
+
+
+<li><a href="esvarlin.html" class="refentry">esvarlin</a> — <span class="refentry-description">Compute three risk measures on historical prices of a set of assets, and at a given confidence level. The three risk measures are: Expected Shortfall (ES), Value at Risk (VaR) and a Linear Spectral risk measure (lin).</span></li>
+
+
+<li><a href="esvaroptim.html" class="refentry">esvaroptim</a> — <span class="refentry-description">Compute the optimal portfolio minimizing the Expected Value (this is a linear programming problem). The Value at Risk of the portfolio is also computed (this implements the Rockafeller-Uryasev algorithm)</span></li>
+
+
+<li><a href="euler.html" class="refentry">euler</a> — <span class="refentry-description">Numerically solves a system of stochastic differential equation (by using the Euler discretization)</span></li>
+
+
+<li><a href="evt.html" class="refentry">evt</a> — <span class="refentry-description">Estimate the parameters of the Generalized Pareto Distribution with the Maximum Likelihood method</span></li>
+
+
+<li><a href="gbm.html" class="refentry">gbm</a> — <span class="refentry-description">Estimate the parameters of a Geometric Brownian Motion (through the method of moments) on the data and graphically show the mean and two confidence intervals</span></li>
+
+
+<li><a href="hedge.html" class="refentry">hedge</a> — <span class="refentry-description">Compute the hedge ratio between an asset "S" and a derivative on it "F"</span></li>
+
+
+<li><a href="hurst.html" class="refentry">hurst</a> — <span class="refentry-description">Compute the Hurst index on historical prices</span></li>
+
+
+<li><a href="interest.html" class="refentry">interest</a> — <span class="refentry-description">Estimate the parameters of three spot interest rate models and draw some simulations</span></li>
+
+
+<li><a href="irs.html" class="refentry">irs</a> — <span class="refentry-description">For a fix-for-floating Interest Rate Swap compute both the spread and the value of the legs.</span></li>
+
+
+<li><a href="markowitz.html" class="refentry">markowitz</a> — <span class="refentry-description">Compute the optimal portfolio minimizing the variance (this is a quadratic programming problem). The optimal variance is also computed.</span></li>
+
+
+<li><a href="mef.html" class="refentry">mef</a> — <span class="refentry-description">Compute and draw the Mean Excess Function</span></li>
+
+
+<li><a href="movav.html" class="refentry">movav</a> — <span class="refentry-description">Compute and draw the moving average of a given time series</span></li>
+
+
+<li><a href="nelson_siegel.html" class="refentry">nelson_siegel</a> — <span class="refentry-description">Estimate the parameters for the Nelson Siegel model of spot interest rates (least square method). Finally draw the actual spot rate curve and the interporalted curve</span></li>
+
+
+<li><a href="svennson.html" class="refentry">svennson</a> — <span class="refentry-description">Estimate the parameters for the Svennson model of spot interest rates (least square method). Finally draw the actual spot rate curve and the interporalted curve</span></li></ul></li></ul>
+
+
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+
+ </td>
+ <td width="40%" class="center">
+
+ </td>
+ <td width="30%" class="next">
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+ </body>
+</html>
diff --git a/help/en_US/scilab_en_US_help/interest.html b/help/en_US/scilab_en_US_help/interest.html
new file mode 100644
index 0000000..a2288ae
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/interest.html
@@ -0,0 +1,116 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>interest</title>
+ <style type="text/css" media="all">
+ @import url("scilab_code.css");
+ @import url("xml_code.css");
+ @import url("c_code.css");
+ @import url("style.css");
+ </style>
+ </head>
+ <body>
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="hurst.html"><< hurst</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="irs.html">irs >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+
+
+
+ <span class="path"><a href="index.html">Financial module</a> >> <a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a> > interest</span>
+
+ <br /><br />
+ <div class="refnamediv"><h1 class="refname">interest</h1>
+ <p class="refpurpose">Estimate the parameters of three spot interest rate models and draw some simulations</p></div>
+ <div class="refsynopsisdiv"><h3 class="title">SYNOPSIS</h3>
+ <div class="synopsis"><pre><span class="default">rf</span><span class="default">=</span><span class="functionid">interest</span><span class="default">(</span><span class="default">r</span><span class="default">,</span><span class="default">dt</span><span class="default">,</span><span class="default">T</span><span class="default">,</span><span class="default">model</span><span class="default">,</span><span class="default">n</span><span class="default">,</span><span class="default">r0< [...]
+ <div class="refsection"><h3 class="title">Description</h3>
+ <p class="para">The function can be used for estimating the parameters of three different models for spot interest rates, and performs some simulations of the resulting stochastic process.</p>
+ <p class="para">The interest rate models taken into account are:</p>
+ <p class="para">1) Merton's: the instantaneously riskless interest rate follows the stochastic differential equation</p>
+ <p class="para">dr = mu dt + sigma dW</p>
+ <p class="para">where dW is a Wiener process and both "mu" and "sigma" are constant;</p>
+ <p class="para">2) Vasicek's: the instantaneously riskless interest rate follows the stochastic differential equation</p>
+ <p class="para"><p class="para">dr = a (b - r) dt + sigma dW</p>
+ <p class="para">where "a", "b", and "sigma" are all constant;</p>
+ <p class="para">3) Cox, Ingersoll, and Ross': the instantaneously riskless interest rate follows the stochastic differential equaiton</p>
+ <p class="para">dr = a (b - r) dt + sigma sqrt(r) dW.</p></p></div>
+ <div class="refsection"><h3 class="title">Parameters</h3>
+ <dl><dt><span class="term">r</span>
+ <dd>column vector containing the historical riskless interest rate</dd></dt>
+ <dt><span class="term">dt</span>
+ <dd>time unit of measure; if the (annual) interest rate is collected on a daily base, then dt=1/250 since there are 250 working days in a year</dd></dt>
+ <dt><span class="term">T</span>
+ <dd>period during which the stochastic process must be simulated (if T=2 years, and dt=1/250, then 500 values are generated)</dd></dt>
+ <dt><span class="term">model</span>
+ <dd>this is a string whose value must be either 'merton', or 'vasicek', or 'cir', for any of the three models presented above</dd></dt>
+ <dt><span class="term">n</span>
+ <dd>the number of simulations that must be performed</dd></dt>
+ <dt><span class="term">r0</span>
+ <dd>interest rate the simulations must start from (in order to check the goodness of the model r0 should be r(1), instead for foreseeing the future interest rates, r0 should be r($)</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Output</h3>
+ <dl><dt><span class="term">rf</span>
+ <dd>matrix whose columns contain the simulation of the interest rate (it has as many columns as "n") and as many rows as T/dt</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Example</h3>
+ <p class="para">First we generate 1000 uniformly distributed daily interest rate, between 4% and 6% (of course interest rates are not uniform, but this is useful just as an example).</p>
+ <p class="para">-->r=grand(1000,1,'unf',0.04,0.06);</p>
+ <p class="para">Then we are able to use the function. Let us see the results for all the three models. We create 10 simulations starting from the first interest rate and each simulation will be done for 1 year:</p>
+ <p class="para">-->rf=interest(r,1/250,1,'merton',10,r(1));</p>
+ <p class="para">!Coefficient Value !</p>
+ <p class="para">!Drift 0.0016879 !</p>
+ <p class="para">!Diffusion 0.1296796 !</p>
+ <p class="para">We see that the drift "mu" is almost zero (in fact the interest rates oscillate on a sdtraight line with zero slope), while the diffusion "sigma" is quite high. The figure shows 10 possible trajectories which also have negative values with high probability. Let us see the Vasicek case:</p>
+ <p class="para">-->rf=interest(r,1/250,1,'vasicek',10,r(1));</p>
+ <p class="para">!Coefficient Value !</p>
+ <p class="para">!Mean reversion 248.13562 !</p>
+ <p class="para">!Mean 0.0498669 !</p>
+ <p class="para">!Diffusion 0.1296796 !</p>
+ <p class="para">The diffusion is the same as Merton's (as we expected). The mean reversion parameter "a" is very high (in fact the sample we used reverts to its mean with a remarkable strength). The mean "b" of the process is more or less 0.05 as we expected (in fact, we created interest rates uniformly distributed between 0.04 and 0.06). The figure shows ten trajectories with good oscillations. Finally, the CIR model:</p>
+ <p class="para">--> rf=interest(r,1/250,1,'cir',10,r(1));</p>
+ <p class="para">!Coefficient Value !</p>
+ <p class="para">!Mean reversion 246.72311 !</p>
+ <p class="para">!Mean 0.0498670 !</p>
+ <p class="para">!Diffusion coeff. 0.5819574 !</p>
+ <p class="para">Where we see values of mean reversion and mean very close to the previous one. The last term is different since the diffusion coefficient "sigma" in the CIR model must be multiplied by the square root of the interest rate. The graph should show trajectories similar to the previous ones.</p></div>
+ <div class="refsection"><h3 class="title">Bibliography</h3>
+ <p class="para">"A Theory of the Term Structure of Interest Rates", Cox J.C., Ingersoll J.E. Jr., and Ross S.A., Econometrica, 53, 385-407, 1985</p>
+ <p class="para">"On the pricing of corporate debt: The risk structure of interest rates", Merton R.C., Journal of Finance, 29, 449-470, 1971</p>
+ <p class="para">"An Equilibrium Characterization of the Term Structure", Vasiček O., Journal of Financial Economics, 5, 177-188 (1977)</p></div>
+ <div class="refsection"><h3 class="title">Authors</h3>
+ <p class="para">Francesco Menoncin - Brescia University - 2010</p></div>
+ <div class="refsection"><h3 class="title">See Also</h3>
+ <ul class="itemizedlist"><li class="member"><a href="gbm.html" class="link">gbm</a></li>
+ <li class="member"><a href="euler.html" class="link">euler</a></li></ul></div>
+
+
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="hurst.html"><< hurst</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="irs.html">irs >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+ </body>
+</html>
diff --git a/help/en_US/scilab_en_US_help/irs.html b/help/en_US/scilab_en_US_help/irs.html
new file mode 100644
index 0000000..346a885
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/irs.html
@@ -0,0 +1,92 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>irs</title>
+ <style type="text/css" media="all">
+ @import url("scilab_code.css");
+ @import url("xml_code.css");
+ @import url("c_code.css");
+ @import url("style.css");
+ </style>
+ </head>
+ <body>
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="interest.html"><< interest</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="markowitz.html">markowitz >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+
+
+
+ <span class="path"><a href="index.html">Financial module</a> >> <a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a> > irs</span>
+
+ <br /><br />
+ <div class="refnamediv"><h1 class="refname">irs</h1>
+ <p class="refpurpose">For a fix-for-floating Interest Rate Swap compute both the spread and the value of the legs.</p></div>
+ <div class="refsynopsisdiv"><h3 class="title">SYNOPSIS</h3>
+ <div class="synopsis"><pre><span class="default">[</span><span class="default">spread</span><span class="default">,</span><span class="default">leg</span><span class="default">]=</span><span class="functionid">irs</span><span class="default">(</span><span class="default">time</span><span class="default">,</span><span class="default">months</span><span class="default">,</span><span class="default">r</span><span class="default">,</span><span class="default">setting</span><span class="d [...]
+ <div class="refsection"><h3 class="title">Description</h3>
+ <p class="para">The function computes both the spread (i.e. the fixed payment) and the value of the legs for an Interest Rate Swap. The function can take into account both "in advance" and "in arrears" IRS.</p></div>
+ <div class="refsection"><h3 class="title">Parameters</h3>
+ <dl><dt><span class="term">time</span>
+ <dd>the subscribing date of the IRS; it must be in the form [year month day]</dd></dt>
+ <dt><span class="term">months</span>
+ <dd>number of months between each payment (more common are 3 or 6)</dd></dt>
+ <dt><span class="term">r</span>
+ <dd>column vector containing the relevant spot rates</dd></dt>
+ <dt><span class="term">setting</span>
+ <dd>this variable must be zero (0) for "in advance" IRS and one (1) for "in arrears" IRS</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Output</h3>
+ <dl><dt><span class="term">spread</span>
+ <dd>fix payment of the IRS</dd></dt>
+ <dt><span class="term">leg</span>
+ <dd>value of both legs of the IRS</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Example</h3>
+ <p class="para">Let as assume that 12th May 2010 an annual swap is subscribed (with 3-month payments).We first set the relevant interest rates (for one year swap with 3-month payments the interest rates must be four):</p>
+ <p class="para">-->r=[0.00652 0.00956 0.01091 0.01216]';</p>
+ <p class="para">Now we can use the function. For an "in advance" IRS we have</p>
+ <p class="para">-->[spread,leg]=irs([2010 5 12],3,r,0)</p>
+ <p class="para">leg = 0.0121787</p>
+ <p class="para">spread = 0.0120930</p>
+ <p class="para">Thus we have to pay 1.2% in exchange of the floating interest rate.</p>
+ <p class="para">In the case of an "in arrears" IRS the last</p>
+ <p class="para">-->[spread,leg]=irs([2010 5 12],3,r,1)</p>
+ <p class="para">leg = 0.0106842</p>
+ <p class="para">spread = 0.0140050</p>
+ <p class="para">The spread is higher since we eliminate the first interest rate with an increasing curve.</p></div>
+ <div class="refsection"><h3 class="title">Authors</h3>
+ <p class="para">Francesco Menoncin - Brescia University - 2010</p></div>
+ <div class="refsection"><h3 class="title">See Also</h3>
+ <ul class="itemizedlist"><li class="member"></li></ul></div>
+
+
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="interest.html"><< interest</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="markowitz.html">markowitz >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+ </body>
+</html>
diff --git a/help/en_US/scilab_en_US_help/jhelpidx.xml b/help/en_US/scilab_en_US_help/jhelpidx.xml
new file mode 100644
index 0000000..aa5a66e
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/jhelpidx.xml
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="utf-8" standalone="no"?>
+<!DOCTYPE index PUBLIC "-//Sun Microsystems Inc.//DTD JavaHelp Index Version 1.0//EN" "http://java.sun.com/products/javahelp/index_1_0.dtd">
+<index version="1.0"/>
\ No newline at end of file
diff --git a/help/en_US/scilab_en_US_help/jhelpmap.jhm b/help/en_US/scilab_en_US_help/jhelpmap.jhm
new file mode 100644
index 0000000..fda742c
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/jhelpmap.jhm
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="utf-8" standalone="no"?>
+<!DOCTYPE map PUBLIC "-//Sun Microsystems Inc.//DTD JavaHelp Map Version 1.0//EN" "http://java.sun.com/products/javahelp/map_1_0.dtd">
+<map version="1.0">
+<mapID target="index" url="index.html"/>
+<mapID target="section_4af098ac34d3d4ed2e545bfe2ad89215" url="section_4af098ac34d3d4ed2e545bfe2ad89215.html"/>
+<mapID target="financial_overview" url="financial_overview.html"/>
+<mapID target="backtest" url="backtest.html"/>
+<mapID target="bollinger" url="bollinger.html"/>
+<mapID target="bsgreeks" url="bsgreeks.html"/>
+<mapID target="bsimpvol" url="bsimpvol.html"/>
+<mapID target="bsoption" url="bsoption.html"/>
+<mapID target="cfr" url="cfr.html"/>
+<mapID target="duration" url="duration.html"/>
+<mapID target="esvarevt" url="esvarevt.html"/>
+<mapID target="esvarlin" url="esvarlin.html"/>
+<mapID target="esvaroptim" url="esvaroptim.html"/>
+<mapID target="euler" url="euler.html"/>
+<mapID target="evt" url="evt.html"/>
+<mapID target="gbm" url="gbm.html"/>
+<mapID target="hedge" url="hedge.html"/>
+<mapID target="hurst" url="hurst.html"/>
+<mapID target="interest" url="interest.html"/>
+<mapID target="irs" url="irs.html"/>
+<mapID target="markowitz" url="markowitz.html"/>
+<mapID target="mef" url="mef.html"/>
+<mapID target="movav" url="movav.html"/>
+<mapID target="nelson_siegel" url="nelson_siegel.html"/>
+<mapID target="svennson" url="svennson.html"/>
+</map>
\ No newline at end of file
diff --git a/help/en_US/scilab_en_US_help/jhelpset.hs b/help/en_US/scilab_en_US_help/jhelpset.hs
new file mode 100644
index 0000000..4754ac1
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/jhelpset.hs
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8" standalone="no"?>
+<!DOCTYPE helpset
+ PUBLIC "-//Sun Microsystems Inc.//DTD JavaHelp HelpSet Version 1.0//EN" "http://java.sun.com/products/javahelp/helpset_1_0.dtd">
+<helpset version="1.0">
+<title>Financial module</title>
+<maps>
+<homeID>top</homeID>
+<mapref location="jhelpmap.jhm"/>
+</maps>
+<view>
+<name>TOC</name>
+<label>Table Of Contents</label>
+<type>javax.help.TOCView</type>
+<data>jhelptoc.xml</data>
+</view>
+<view>
+<name>Index</name>
+<label>Index</label>
+<type>javax.help.IndexView</type>
+<data>jhelpidx.xml</data>
+</view>
+<view>
+<name>Search</name>
+<label>Search</label>
+<type>javax.help.SearchView</type>
+<data engine="com.sun.java.help.search.DefaultSearchEngine">JavaHelpSearch</data>
+</view>
+</helpset>
\ No newline at end of file
diff --git a/help/en_US/scilab_en_US_help/jhelptoc.xml b/help/en_US/scilab_en_US_help/jhelptoc.xml
new file mode 100644
index 0000000..44264b7
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/jhelptoc.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="utf-8" standalone="no"?>
+<!DOCTYPE toc PUBLIC "-//Sun Microsystems Inc.//DTD JavaHelp TOC Version 1.0//EN" "http://java.sun.com/products/javahelp/toc_1_0.dtd">
+<toc version="1.0">
+<tocitem target="index" text="Financial module">
+<tocitem target="section_4af098ac34d3d4ed2e545bfe2ad89215" text="Financial module">
+<tocitem target="financial_overview" text="financial_overview"/>
+<tocitem target="backtest" text="backtest"/>
+<tocitem target="bollinger" text="bollinger"/>
+<tocitem target="bsgreeks" text="bsgreeks"/>
+<tocitem target="bsimpvol" text="bsimpvol"/>
+<tocitem target="bsoption" text="bsoption"/>
+<tocitem target="cfr" text="cfr"/>
+<tocitem target="duration" text="duration"/>
+<tocitem target="esvarevt" text="esvarevt"/>
+<tocitem target="esvarlin" text="esvarlin"/>
+<tocitem target="esvaroptim" text="esvaroptim"/>
+<tocitem target="euler" text="euler"/>
+<tocitem target="evt" text="evt"/>
+<tocitem target="gbm" text="gbm"/>
+<tocitem target="hedge" text="hedge"/>
+<tocitem target="hurst" text="hurst"/>
+<tocitem target="interest" text="interest"/>
+<tocitem target="irs" text="irs"/>
+<tocitem target="markowitz" text="markowitz"/>
+<tocitem target="mef" text="mef"/>
+<tocitem target="movav" text="movav"/>
+<tocitem target="nelson_siegel" text="nelson_siegel"/>
+<tocitem target="svennson" text="svennson"/>
+</tocitem>
+</tocitem>
+</toc>
\ No newline at end of file
diff --git a/help/en_US/scilab_en_US_help/markowitz.html b/help/en_US/scilab_en_US_help/markowitz.html
new file mode 100644
index 0000000..c9d0ccd
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/markowitz.html
@@ -0,0 +1,105 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>markowitz</title>
+ <style type="text/css" media="all">
+ @import url("scilab_code.css");
+ @import url("xml_code.css");
+ @import url("c_code.css");
+ @import url("style.css");
+ </style>
+ </head>
+ <body>
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="irs.html"><< irs</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="mef.html">mef >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+
+
+
+ <span class="path"><a href="index.html">Financial module</a> >> <a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a> > markowitz</span>
+
+ <br /><br />
+ <div class="refnamediv"><h1 class="refname">markowitz</h1>
+ <p class="refpurpose">Compute the optimal portfolio minimizing the variance (this is a quadratic programming problem). The optimal variance is also computed.</p></div>
+ <div class="refsynopsisdiv"><h3 class="title">SYNOPSIS</h3>
+ <div class="synopsis"><pre><span class="default">[</span><span class="default">portf</span><span class="default">,</span><span class="default">varoptim</span><span class="default">]=</span><span class="functionid">markowitz</span><span class="default">(</span><span class="default">price</span><span class="default">,</span><span class="default">ER</span><span class="default">,</span><span class="default">r</span><span class="default">,</span><span class="default">dt</span><span class= [...]
+ <div class="refsection"><h3 class="title">Description</h3>
+ <p class="para">Give the historical prices of a set of assets, compute the optimal portfolios solving four different problems. All of them minimize the Variance of the portfolio subject to the constraint of having given expected return. The four problems are different for the following characteristics</p>
+ <p class="para">1) optimal portfolio allowing short selling and investing in the riskless asset;</p>
+ <p class="para">2) optimal portfolio allowing short selling but without investing in the riskless asset;</p>
+ <p class="para">3) optimal portfolio not allowing short selling and investing in the riskless asset;</p>
+ <p class="para">4) optimal portfolio not allowing short selling and without investing in the riskless asset.</p>
+ <p class="para">Finally the Variance of the optimal portfolio is computed. The procedure uses "qld" function.</p></div>
+ <div class="refsection"><h3 class="title">Parameters</h3>
+ <dl><dt><span class="term">price</span>
+ <dd>matrix whose columns contains the historical prices of the assets in the portfolio</dd></dt>
+ <dt><span class="term">ER</span>
+ <dd>expected return that the investor wants to obtain on his portfolio</dd></dt>
+ <dt><span class="term">r</span>
+ <dd>riskless interest rate</dd></dt>
+ <dt><span class="term">dt</span>
+ <dd>time frequency of the prices with respect to the time unit of measure of both "ER" and "r"; if the matrix of prices contains daily data and both "ER" and "r" are annual return, then dt=1/250 since there are 250 working day in one year</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Output</h3>
+ <dl><dt><span class="term">portf</span>
+ <dd>matrix containing the optimal portfolios; in particular:</dd>
+ <dd>first raw: with short selling and with r</dd>
+ <dd>second raw: with short selling and without r</dd>
+ <dd>third raw: without short selling and with r</dd>
+ <dd>fourth raw: without short selling and without r</dd></dt>
+ <dt><span class="term">varoptim</span>
+ <dd>Variance of the optimal portfolio</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Example</h3>
+ <p class="para"><p class="para">First we generate 100x3 log-normally distributed daily asset prices with 0.1/250 mean and 0.2/sqrt(250) variance. The first prices of the three assets are 25 euros, 50 euros, and 110 euros respectively.</p>
+ <p class="para">-->M=grand(100,3,'nor',0.1/250,0.2/sqrt(250));</p>
+ <p class="para">-->price=exp(cumsum(M,1))*diag([25 50 110]);</p></p>
+ <p class="para">Now we can use the function on these prices.</p>
+ <p class="para">-->[portf,varoptim]=markowitz(price,0.05,0.01,1/250)</p>
+ <p class="para">Draw frontiers? (y/n) y</p>
+ <p class="para">! with short selling without short selling !</p>
+ <p class="para">! with r without r with r without r !</p>
+ <p class="para">varoptim =</p>
+ <p class="para">0.0001508 0.0232294 0.0001508 0.0249650</p>
+ <p class="para">portf =</p>
+ <p class="para">- 0.0009446 0.6612090 - 1.444D-34 0.7614173</p>
+ <p class="para">0.0599034 - 0.0729724 0.0599186 0.</p>
+ <p class="para">0.0157164 0.4117634 0.0157684 0.2385827</p>
+ <p class="para">We see that the third or the second asset are sold (negative portfolio component) when it is possible. If short selling is not allowed, then its weight is either positive or zero.</p>
+ <p class="para">The function also asks if one wants to see the optimal frontiers (this is optional since the procedure takes some time). The figure which is created shows four frontiers corresponding to the four different problems (the legend explains the meanings).</p></div>
+ <div class="refsection"><h3 class="title">Authors</h3>
+ <p class="para">Francesco Menoncin - Brescia University - 2010</p></div>
+ <div class="refsection"><h3 class="title">See Also</h3>
+ <ul class="itemizedlist"><li class="member"></li></ul></div>
+
+
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="irs.html"><< irs</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="mef.html">mef >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+ </body>
+</html>
diff --git a/help/en_US/scilab_en_US_help/mef.html b/help/en_US/scilab_en_US_help/mef.html
new file mode 100644
index 0000000..dd092c4
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/mef.html
@@ -0,0 +1,75 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>mef</title>
+ <style type="text/css" media="all">
+ @import url("scilab_code.css");
+ @import url("xml_code.css");
+ @import url("c_code.css");
+ @import url("style.css");
+ </style>
+ </head>
+ <body>
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="markowitz.html"><< markowitz</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="movav.html">movav >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+
+
+
+ <span class="path"><a href="index.html">Financial module</a> >> <a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a> > mef</span>
+
+ <br /><br />
+ <div class="refnamediv"><h1 class="refname">mef</h1>
+ <p class="refpurpose">Compute and draw the Mean Excess Function</p></div>
+ <div class="refsynopsisdiv"><h3 class="title">SYNOPSIS</h3>
+ <div class="synopsis"><pre><span class="default">E</span><span class="default">=</span><span class="functionid">mef</span><span class="default">(</span><span class="default">x</span><span class="default">)</span></pre></div></div>
+ <div class="refsection"><h3 class="title">Description</h3>
+ <p class="para">On the data "x" (for instance asset returns), the function computes and draw the Mean Excess Function. It is the mean of the data exceeding a given threshold. Each value of ordered "x" is taken as a threshold.</p></div>
+ <div class="refsection"><h3 class="title">Parameters</h3>
+ <dl><dt><span class="term">x</span>
+ <dd>data the Mean Excess Function must be computed on</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Output</h3>
+ <dl><dt><span class="term">E</span>
+ <dd>vector of the values of the Mean Excess Function</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Example</h3>
+ <p class="para"><p class="para">First we generate 1000 normally daily returns on an asset with 0.1/250 mean and 0.2/sqrt(250) variance:</p>
+ <p class="para">-->returns=grand(1000,1,'nor',0.1/250,0.2/sqrt(250));</p></p>
+ <p class="para">Now we can use the function on these returns.</p>
+ <p class="para">-->E=mef(returns);</p>
+ <p class="para">The graph shows the values of the Mean Excess Function. For a normal random variable it is decreasing and convex.</p></div>
+ <div class="refsection"><h3 class="title">Authors</h3>
+ <p class="para">Francesco Menoncin - Brescia University - 2010</p></div>
+
+
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="markowitz.html"><< markowitz</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="movav.html">movav >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+ </body>
+</html>
diff --git a/help/en_US/scilab_en_US_help/movav.html b/help/en_US/scilab_en_US_help/movav.html
new file mode 100644
index 0000000..8068608
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/movav.html
@@ -0,0 +1,78 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>movav</title>
+ <style type="text/css" media="all">
+ @import url("scilab_code.css");
+ @import url("xml_code.css");
+ @import url("c_code.css");
+ @import url("style.css");
+ </style>
+ </head>
+ <body>
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="mef.html"><< mef</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="nelson_siegel.html">nelson_siegel >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+
+
+
+ <span class="path"><a href="index.html">Financial module</a> >> <a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a> > movav</span>
+
+ <br /><br />
+ <div class="refnamediv"><h1 class="refname">movav</h1>
+ <p class="refpurpose">Compute and draw the moving average of a given time series</p></div>
+ <div class="refsynopsisdiv"><h3 class="title">SYNOPSIS</h3>
+ <div class="synopsis"><pre><span class="default">M</span><span class="default">=</span><span class="functionid">movav</span><span class="default">(</span><span class="default">x</span><span class="default"> [,</span><span class="default">m1</span><span class="default"> [,</span><span class="default">m2</span><span class="default"> [,...]]]);</span></pre></div></div>
+ <div class="refsection"><h3 class="title">Description</h3>
+ <p class="para">On the data "x" the function compute the moving averages of length m1, m2, and so on. Finally it draws the data "x" and all the moving averages.</p></div>
+ <div class="refsection"><h3 class="title">Parameters</h3>
+ <dl><dt><span class="term">x</span>
+ <dd>data the moving averages are computed on</dd></dt>
+ <dt><span class="term">m1, m2, ...</span>
+ <dd>lengths of the moving averages</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Output</h3>
+ <dl><dt><span class="term">M</span>
+ <dd>matrix containing, in any column, the moving average of the historical data (each column has a different length)</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Example</h3>
+ <p class="para"><p class="para">First we generate 1000 log-normally distributed daily asset prices with 0.1/250 mean and 0.2/sqrt(250) variance. The first price of the asset is 25 euros.</p>
+ <p class="para">-->M=grand(1000,1,'nor',0.1/250,0.2/sqrt(250));</p>
+ <p class="para">-->price=exp(cumsum(M,1))*25;</p></p>
+ <p class="para">Now we can use the function for computing the moving averages at 10 days and 30 days</p>
+ <p class="para">-->M=movav(price,10,30);</p>
+ <p class="para">The graph shows the historical data and both moving averages.</p></div>
+ <div class="refsection"><h3 class="title">Authors</h3>
+ <p class="para">Francesco Menoncin - Brescia University - 2010</p></div>
+
+
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="mef.html"><< mef</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="nelson_siegel.html">nelson_siegel >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+ </body>
+</html>
diff --git a/help/en_US/scilab_en_US_help/nelson_siegel.html b/help/en_US/scilab_en_US_help/nelson_siegel.html
new file mode 100644
index 0000000..aed723c
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/nelson_siegel.html
@@ -0,0 +1,106 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>nelson_siegel</title>
+ <style type="text/css" media="all">
+ @import url("scilab_code.css");
+ @import url("xml_code.css");
+ @import url("c_code.css");
+ @import url("style.css");
+ </style>
+ </head>
+ <body>
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="movav.html"><< movav</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="svennson.html">svennson >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+
+
+
+ <span class="path"><a href="index.html">Financial module</a> >> <a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a> > nelson_siegel</span>
+
+ <br /><br />
+ <div class="refnamediv"><h1 class="refname">nelson_siegel</h1>
+ <p class="refpurpose">Estimate the parameters for the Nelson Siegel model of spot interest rates (least square method). Finally draw the actual spot rate curve and the interporalted curve</p></div>
+ <div class="refsynopsisdiv"><h3 class="title">SYNOPSIS</h3>
+ <div class="synopsis"><pre><span class="default">[</span><span class="default">uopt</span><span class="default"> [,</span><span class="default">rf</span><span class="default">]]=</span><span class="functionid">nelson_siegel</span><span class="default">(</span><span class="default">t</span><span class="default">,</span><span class="default">r</span><span class="default">,</span><span class="default">u0</span><span class="default"> [,</span><span class="default">tf</span><span class="d [...]
+ <div class="refsection"><h3 class="title">Description</h3>
+ <p class="para">The Nelson Siegel model assumes that the spot interest rate follows the function (of time)</p>
+ <p class="para">f(t)=u1+(u2+u3)*u4/t*(1-e^(-t/u4))-u4*e^(-t/u4)</p>
+ <p class="para">The function estimates the parameters u1, u2, u3, and u4 with the least square method. It is also possible to foresee some rates for given dates.</p></div>
+ <div class="refsection"><h3 class="title">Parameters</h3>
+ <dl><dt><span class="term">t</span>
+ <dd>dates corresponding to the spot interest rates</dd></dt>
+ <dt><span class="term">r</span>
+ <dd>spot interest rate curve</dd></dt>
+ <dt><span class="term">u0</span>
+ <dd>initial values for the parameters (it must be a vector of four elements)</dd></dt>
+ <dt><span class="term">tf</span>
+ <dd>optional parameter: (column vector) the dates for which we want to use the model in order to foresee the interest rates</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Output</h3>
+ <dl><dt><span class="term">uopt</span>
+ <dd>vector containing the estimated values of the parameters</dd></dt></dl>
+ <dl><dt><span class="term">rf</span>
+ <dd>optional output: the foreseen interest rates (for the dates in vector "tf")</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Example</h3>
+ <p class="para"><p class="para">First we define the dates and the interest rates (taken from the Euribor curve)</p>
+ <p class="para">-->t=[ 0.0192308 0.0384615 0.0576923 0.0833333 0.1666667 0.25 0.3333333 0.4166667 0.5 0.5833333 0.6666667 0.75 0.8333333 0.9166667 1];</p>
+ <p class="para">-->r=[0.00944 0.00949 0.0097 0.01009 0.01213 0.01405 0.01486 0.01534 0.016 0.01636 0.01662 0.01687 0.01716 0.01742 0.01766 ];</p>
+ <p class="para">Now we can use the function and also foreseen the interest rates for 2 years, 3 years, and 4 years</p>
+ <p class="para">-->[uopt,rf]=nelson_siegel(t,r,ones(4,1),[2 3 4]')</p>
+ <p class="para">Gradient</p>
+ <p class="para">1.0D-11 *</p>
+ <p class="para">- 1.2365855</p>
+ <p class="para">0.0194767</p>
+ <p class="para">- 0.8091640</p>
+ <p class="para">0.0844415</p>
+ <p class="para">Objective function</p>
+ <p class="para">0.0000010</p>
+ <p class="para">rf =</p>
+ <p class="para">0.0178524</p>
+ <p class="para">0.0178558</p>
+ <p class="para">0.0178501</p>
+ <p class="para">uopt =</p>
+ <p class="para">0.0178308</p>
+ <p class="para">- 0.0094562</p>
+ <p class="para">0.0097015</p>
+ <p class="para">0.3151036</p></p>
+ <p class="para">The figure shows the actual interest rates, the estimated ones and the foreseen ones.</p></div>
+ <div class="refsection"><h3 class="title">Authors</h3>
+ <p class="para">Francesco Menoncin - Brescia University - 2010</p></div>
+ <div class="refsection"><h3 class="title">See Also</h3>
+ <ul class="itemizedlist"><li class="member"></li>
+ <li class="member"><a href="svennson.html" class="link">svennson</a></li></ul></div>
+
+
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="movav.html"><< movav</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+ <span class="next"><a href="svennson.html">svennson >></a></span>
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+ </body>
+</html>
diff --git a/help/en_US/scilab_en_US_help/scilab_code.css b/help/en_US/scilab_en_US_help/scilab_code.css
new file mode 100644
index 0000000..658f42e
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/scilab_code.css
@@ -0,0 +1,96 @@
+.scilabcomment {
+ font-style: italic;
+ color: #01a801
+}
+
+.scilabdefault {
+ font-style: normal;
+ color: #000000
+}
+
+.scilabspecial {
+ font-style: normal;
+ color: #ffaa00
+}
+
+.scilabconstants {
+ font-style: normal;
+ color: #da70d6
+}
+
+.scilaboperator {
+ font-style: normal;
+ color: #5c5c5c
+}
+
+.scilabnumber {
+ font-style: normal;
+ color: #bc8f8f
+}
+
+.scilabfkeyword {
+ font-style: normal;
+ color: #b01813
+}
+
+.scilabskeyword {
+ font-style: normal;
+ color: #a020f0
+}
+
+.scilabckeyword {
+ font-style: normal;
+ color: #5f9ea0
+}
+
+.scilabcommand {
+ font-style: normal;
+ color: #32b9b9
+}
+
+.scilabmacro {
+ font-style: normal;
+ color: #ae5cb0
+}
+
+a.scilabcommand {
+ font-style: normal;
+ text-decoration: underline;
+ color: #32b9b9
+}
+
+a.scilabmacro {
+ font-style: normal;
+ text-decoration: underline;
+ color: #ae5cb0
+}
+
+.scilabstring {
+ font-style: normal;
+ color: #bc8f8f
+}
+
+.scilabid {
+ font-style: normal;
+ color: #000000
+}
+
+.scilabinputoutputargs {
+ font-weight: bold;
+ color: #834310
+}
+
+.scilabfunctionid {
+ font-weight: bold;
+ color: #000000
+}
+
+.scilabfield {
+ font-style: normal;
+ color: #aaaaaa
+}
+
+.scilabopenclose {
+ font-style: normal;
+ color: #4a55db
+}
diff --git a/help/en_US/scilab_en_US_help/section_4af098ac34d3d4ed2e545bfe2ad89215.html b/help/en_US/scilab_en_US_help/section_4af098ac34d3d4ed2e545bfe2ad89215.html
new file mode 100644
index 0000000..cb989e8
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/section_4af098ac34d3d4ed2e545bfe2ad89215.html
@@ -0,0 +1,122 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title></title>
+ <style type="text/css" media="all">
+ @import url("scilab_code.css");
+ @import url("xml_code.css");
+ @import url("c_code.css");
+ @import url("style.css");
+ </style>
+ </head>
+ <body>
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="index.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+
+
+
+ <span class="path"><a href="index.html">Financial module</a> >> Financial module</span>
+
+ <br /><br />
+ <h3 class="title-part">Financial module</h3>
+<ul class="list-chapter"><li><a href="financial_overview.html" class="refentry">financial_overview</a> — <span class="refentry-description">An overview of the Financial toolbox.</span></li>
+
+
+<li><a href="backtest.html" class="refentry">backtest</a> — <span class="refentry-description">Apply the backtest to three different risk measures (as percentage of lost): Expected Shortfall, Value at Risk, and a Spectral Measure with linear spectrum. Show the graph of historical returns and the risk measures. The thresholds of the backtest are also computed.</span></li>
+
+
+<li><a href="bollinger.html" class="refentry">bollinger</a> — <span class="refentry-description">Given a moving average on the historical prices of an asset, the function creates two figures: in the first both the historical prices and the Bollinger bands (i.e. the moving average +/- "a" times the price standard deviation) are shown, in the second the so-called b-percentage is shown</span></li>
+
+
+
+
+
+<li><a href="bsgreeks.html" class="refentry">bsgreeks</a> — <span class="refentry-description">Compute the Greeks for both a call and a put option in a Black and Scholes model.</span></li>
+
+
+<li><a href="bsimpvol.html" class="refentry">bsimpvol</a> — <span class="refentry-description">Compute the implied volatility in a Black and Scholes framework. The function computes the volatility by equating the theoretical value of an option (with both constant riskless interest rate and volatility) to its market value.</span></li>
+
+
+<li><a href="bsoption.html" class="refentry">bsoption</a> — <span class="refentry-description">Compute the value of both a call and a put option in a Black and Scholes framework (with both constant riskless interest rate and volatility)</span></li>
+
+
+<li><a href="cfr.html" class="refentry">cfr</a> — <span class="refentry-description">compare two or more time series of data and eliminate the elements which do not have the same date</span></li>
+
+
+<li><a href="duration.html" class="refentry">duration</a> — <span class="refentry-description">given a set of cash flows (either positive of negative) from an investment and the dates at which they are available, the function computes: the duration of the cash flows, the convexity of the cash flows, and the yield-to-maturity "ytm" (both duration and convexity are computed by taking ytm as the discount rate)</span></li>
+
+
+<li><a href="esvarevt.html" class="refentry">esvarevt</a> — <span class="refentry-description">Compute both Expected Shortfall and Value at Risk by using the Extreme Value Theory. Furthermore, also the parameter of the Generalized Pareto Distribution are estimated with the Maximum Likelihood method</span></li>
+
+
+<li><a href="esvarlin.html" class="refentry">esvarlin</a> — <span class="refentry-description">Compute three risk measures on historical prices of a set of assets, and at a given confidence level. The three risk measures are: Expected Shortfall (ES), Value at Risk (VaR) and a Linear Spectral risk measure (lin).</span></li>
+
+
+<li><a href="esvaroptim.html" class="refentry">esvaroptim</a> — <span class="refentry-description">Compute the optimal portfolio minimizing the Expected Value (this is a linear programming problem). The Value at Risk of the portfolio is also computed (this implements the Rockafeller-Uryasev algorithm)</span></li>
+
+
+<li><a href="euler.html" class="refentry">euler</a> — <span class="refentry-description">Numerically solves a system of stochastic differential equation (by using the Euler discretization)</span></li>
+
+
+<li><a href="evt.html" class="refentry">evt</a> — <span class="refentry-description">Estimate the parameters of the Generalized Pareto Distribution with the Maximum Likelihood method</span></li>
+
+
+<li><a href="gbm.html" class="refentry">gbm</a> — <span class="refentry-description">Estimate the parameters of a Geometric Brownian Motion (through the method of moments) on the data and graphically show the mean and two confidence intervals</span></li>
+
+
+<li><a href="hedge.html" class="refentry">hedge</a> — <span class="refentry-description">Compute the hedge ratio between an asset "S" and a derivative on it "F"</span></li>
+
+
+<li><a href="hurst.html" class="refentry">hurst</a> — <span class="refentry-description">Compute the Hurst index on historical prices</span></li>
+
+
+<li><a href="interest.html" class="refentry">interest</a> — <span class="refentry-description">Estimate the parameters of three spot interest rate models and draw some simulations</span></li>
+
+
+<li><a href="irs.html" class="refentry">irs</a> — <span class="refentry-description">For a fix-for-floating Interest Rate Swap compute both the spread and the value of the legs.</span></li>
+
+
+<li><a href="markowitz.html" class="refentry">markowitz</a> — <span class="refentry-description">Compute the optimal portfolio minimizing the variance (this is a quadratic programming problem). The optimal variance is also computed.</span></li>
+
+
+<li><a href="mef.html" class="refentry">mef</a> — <span class="refentry-description">Compute and draw the Mean Excess Function</span></li>
+
+
+<li><a href="movav.html" class="refentry">movav</a> — <span class="refentry-description">Compute and draw the moving average of a given time series</span></li>
+
+
+<li><a href="nelson_siegel.html" class="refentry">nelson_siegel</a> — <span class="refentry-description">Estimate the parameters for the Nelson Siegel model of spot interest rates (least square method). Finally draw the actual spot rate curve and the interporalted curve</span></li>
+
+
+<li><a href="svennson.html" class="refentry">svennson</a> — <span class="refentry-description">Estimate the parameters for the Svennson model of spot interest rates (least square method). Finally draw the actual spot rate curve and the interporalted curve</span></li></ul>
+
+
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="index.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+ </body>
+</html>
diff --git a/help/en_US/scilab_en_US_help/style.css b/help/en_US/scilab_en_US_help/style.css
new file mode 100644
index 0000000..ebb3a30
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/style.css
@@ -0,0 +1,305 @@
+body {
+ color:#000000;
+ background-color:#ffffff;
+ font-family:sans-serif;
+ font-size:100%;
+ margin:5px;
+ padding:0;
+ background : url("/img/body.png");
+ background-repeat : repeat-x;
+}
+
+.para {
+ padding-left: 10px;
+}
+
+.refname {
+ color: #ff6c0a;
+}
+.refpurpose {
+ font-size: 110%;
+}
+
+.synopsis {
+ border: 1px solid black;
+ width:80%;
+ padding: 0.5em;
+}
+
+.editbar {
+ text-align: right;
+}
+
+.term {
+ color:#800000;
+ font-size:100%;
+}
+
+h3 {
+ color: #000063;
+ font-weight: bold;
+ font-size:130%;
+ margin-bottom: 10px;
+}
+
+.programlisting {
+ font-family: monospace;
+ font-size: 100%;
+ background-color:#EEEEFF;
+ border-color:#CCCCCC ;
+ border-style:solid;
+ border-width:2px medium;
+ width:80%;
+ color:#333333;
+ line-height:120%;
+ padding:10px;
+}
+
+.literal {
+ font-size: 100%;
+}
+
+a {
+ color: blue;
+ text-decoration:none;
+}
+
+a:hover {
+ text-decoration:underline;
+}
+
+.itemizedlist {
+ list-style-type: disk;
+}
+
+.inline-list li {
+ display: inline;
+ list-style-type: disk;
+}
+
+.vert-list {
+ list-style-type: disk;
+}
+
+pre {
+ margin-bottom: 0px;
+ margin-top: 0px;
+}
+
+.leftpart {
+ position:absolute;
+ float:left;
+ width: 186px;
+ padding: 5px;
+ font-size: smaller;
+}
+
+.content {
+ margin-top: 100px;
+ margin-left: 196px
+}
+
+.container {
+ margin: 0 auto;
+ width:1024px;
+}
+
+ul.toc li.list-active {
+ list-style-type:disc;
+ font-weight:bold
+}
+
+ul.toc li.parent {
+ font-size: 115%;
+ padding: 5px 0px 5px 11px;
+ border-bottom: 1px solid #cccccc;
+ margin-bottom: 5px
+}
+
+ul.toc li.root {
+ font-size: 135%;
+ padding: 5px 0px 5px 11px;
+ border-bottom: 1px solid #cccccc;
+ margin-bottom: 5px
+}
+
+ul.toc li {
+ font-size: 85%;
+ margin: 1px 0 1px 1px;
+ padding: 1px 0 1px 11px;
+ background-repeat: no-repeat;
+ background-position: center left;
+ list-style-type: circle
+}
+
+.next {
+ float:right
+ text-align: right;
+}
+
+.center {
+ text-align: center;
+}
+
+.screen {
+ font-family: monospace;
+ font-size: 100%;
+ background-color:#FFFFFF;
+ border-color:#CCCCCC ;
+ border-style:solid;
+ border-width:2px medium;
+ width:80%;
+ color:#333333;
+ line-height:120%;
+ padding:10px;
+}
+
+/* Top and bottom navigation controls on manual pages --------------------- */
+div.manualnavbar {
+ background-color: #E0E0E0;
+ color: inherit;
+ padding: 4px;
+ margin-bottom: 10px;
+}
+div.manualnavbar .prev {
+ padding-right: 4px;
+}
+div.manualnavbar .next {
+ text-align: right;
+ padding-left: 4px;
+}
+
+div.manualnavbar .top {
+ text-align: center;
+ display: block;
+}
+
+div.manualnavbar hr {
+ color: #cccccc;
+ background-color: #cccccc;
+}
+
+/* Footer navigation area ------------------------------------------------- */
+
+#pagefooter {
+ position: relative;
+ font-size: 75%;
+ color: inherit;
+ background-color: #e5e5e5;
+ width: 100%;
+}
+
+#pagefooterleft {
+ top: 0px;
+ left: 0px;
+ padding: 6px;
+ margin-right: 30%;
+}
+
+#pagefooterright {
+ text-align: right;
+ margin-left: 50%;
+ padding: 6px;
+}
+#footnav {
+ color: inherit;
+ background-color: #9999cc;
+ border-width: 1px 0px;
+ border-color: #333366;
+ border-style: solid;
+ text-align: right;
+ padding-right: 6px;
+}
+
+
+
+
+ #global{
+/* width: 90%; */
+ max-width: 90em;
+/* min-width: 850px; */
+ margin-left: auto;
+ margin-right: auto;
+ }
+
+ #myHeader{
+ background-color:#000000;
+ color:white;
+ margin-bottom : 10px;
+ position : relative;
+ text-align: center;
+/* width : 1024px;*/
+ height : 100px;
+ padding-left : 20px;
+ background : url("http://atoms.scilab.org/images/homepage/cadre_head.png");
+ background-repeat : no-repeat;
+ background-position : 0px 0px;
+
+ }
+
+ #myFooter{
+ background-color:#E5E5E5;
+ font-color:black;
+/* width: 90%;*/
+ max-width: 90em;
+/* min-width: 850px;
+ margin-left: 5%;
+ margin-right: 5%;*/
+ margin-top:10px;
+ padding:10px;
+ }
+
+ #mainArea{
+ width: 100%;
+ overflow: hidden;
+ }
+
+ #myLeftArea{
+ color:white;
+ float: left;
+ width: 180px;
+ padding:5px;
+ }
+
+ #myMiddleArea{
+ color:black;
+ margin-left: 200px;
+ padding: 10px 20px;
+ }
+
+ #myRightArea{
+ color:white;
+ float: right;
+ width: 200px;
+ padding: 12px 20px;
+ }
+
+
+div#cadre_head
+{
+ position : relative;
+ text-align: center;
+/* width : 1024px;*/
+ height : 100px;
+ padding-left : 20px;
+ background : url("/img/cadre_head.png");
+ background-repeat : no-repeat;
+ background-position : 0px 0px;
+}
+
+
+div#slogan{
+ position: absolute;
+ top : 50px;
+ left:251px;
+ color:#0000AA;
+ font: 120%, Georgia,Serif;
+}
+div#cadre_help
+{
+ position: absolute;
+ top:45px;
+ right:0px;
+ font-size:0.8em;
+ color:#0000AA;
+}
diff --git a/help/en_US/scilab_en_US_help/svennson.html b/help/en_US/scilab_en_US_help/svennson.html
new file mode 100644
index 0000000..2f97d9d
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/svennson.html
@@ -0,0 +1,108 @@
+<html><head>
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+ <title>svennson</title>
+ <style type="text/css" media="all">
+ @import url("scilab_code.css");
+ @import url("xml_code.css");
+ @import url("c_code.css");
+ @import url("style.css");
+ </style>
+ </head>
+ <body>
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="nelson_siegel.html"><< nelson_siegel</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+
+
+
+ <span class="path"><a href="index.html">Financial module</a> >> <a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a> > svennson</span>
+
+ <br /><br />
+ <div class="refnamediv"><h1 class="refname">svennson</h1>
+ <p class="refpurpose">Estimate the parameters for the Svennson model of spot interest rates (least square method). Finally draw the actual spot rate curve and the interporalted curve</p></div>
+ <div class="refsynopsisdiv"><h3 class="title">SYNOPSIS</h3>
+ <div class="synopsis"><pre><span class="default">[</span><span class="default">uopt</span><span class="default"> [,</span><span class="default">rf</span><span class="default">]]=</span><span class="functionid">svennson</span><span class="default">(</span><span class="default">t</span><span class="default">,</span><span class="default">r</span><span class="default">,</span><span class="default">u0</span><span class="default"> [,</span><span class="default">tf</span><span class="defaul [...]
+ <div class="refsection"><h3 class="title">Description</h3>
+ <p class="para">The Svennson model assumes that the spot interest rate follows the function (of time)</p>
+ <p class="para">f(t)=u1+u4*u6/t+(u2+u3)*u5/t*(1-e^(-t/u5))-(u6/t-1)*u4*e^(-t/u6)-u3*e^(-t/u5)</p>
+ <p class="para">The function estimates the parameters u1, u2, u3, u4, u5, ad u6 with the least square method. It is also possible to foresee some rates for given dates.</p></div>
+ <div class="refsection"><h3 class="title">Parameters</h3>
+ <dl><dt><span class="term">t</span>
+ <dd>dates corresponding to the spot interest rates</dd></dt>
+ <dt><span class="term">r</span>
+ <dd>spot interest rate curve</dd></dt>
+ <dt><span class="term">u0</span>
+ <dd>initial values for the parameters (it must be a vector of six elements)</dd></dt>
+ <dt><span class="term">tf</span>
+ <dd>optional parameter: (column vector) the dates for which we want to use the model in order to foresee the interest rates</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Output</h3>
+ <dl><dt><span class="term">uopt</span>
+ <dd>vector containing the estimated values of the parameters</dd></dt></dl>
+ <dl><dt><span class="term">rf</span>
+ <dd>optional output: the foreseen interest rates (for the dates in vector "tf")</dd></dt></dl></div>
+ <div class="refsection"><h3 class="title">Example</h3>
+ <p class="para"><p class="para">First we define the dates and the interest rates (taken from the Euribor curve)</p>
+ <p class="para">-->t=[ 0.0192308 0.0384615 0.0576923 0.0833333 0.1666667 0.25 0.3333333 0.4166667 0.5 0.5833333 0.6666667 0.75 0.8333333 0.9166667 1];</p>
+ <p class="para">-->r=[0.00944 0.00949 0.0097 0.01009 0.01213 0.01405 0.01486 0.01534 0.016 0.01636 0.01662 0.01687 0.01716 0.01742 0.01766 ];</p>
+ <p class="para">Now we can use the function and also foreseen the interest rates for 2 years, 3 years, and 4 years</p>
+ <p class="para">-->[uopt,rf]=svennson(t,r,ones(6,1)*0.1,[2 3 4]')</p>
+ <p class="para">-->[uopt,rf]=svennson(t,r,ones(6,1)*0.1,[2 3 4]')</p>
+ <p class="para">Gradient</p>
+ <p class="para">- 0.0010055</p>
+ <p class="para">- 0.0002346</p>
+ <p class="para">- 0.0001655</p>
+ <p class="para">- 0.0005862</p>
+ <p class="para">0.0001849</p>
+ <p class="para">- 0.0000623</p>
+ <p class="para">Objective function</p>
+ <p class="para">0.0000001</p>
+ <p class="para">rf =</p>
+ <p class="para">0.0187098</p>
+ <p class="para">0.0191140</p>
+ <p class="para">0.0193162</p>
+ <p class="para">uopt =</p>
+ <p class="para">0.0199227</p>
+ <p class="para">- 0.0602590</p>
+ <p class="para">- 0.0341067</p>
+ <p class="para">0.0251565</p>
+ <p class="para">0.0698513</p>
+ <p class="para">0.1655826</p></p>
+ <p class="para">The figure shows the actual interest rates, the estimated ones and the foreseen ones.</p></div>
+ <div class="refsection"><h3 class="title">Authors</h3>
+ <p class="para">Francesco Menoncin - Brescia University - 2010</p></div>
+ <div class="refsection"><h3 class="title">See Also</h3>
+ <ul class="itemizedlist"><li class="member"></li>
+ <li class="member"><a href="nelson_siegel.html" class="link">nelson_siegel</a></li></ul></div>
+
+
+ <div class="manualnavbar">
+ <table width="100%"><tr>
+ <td width="30%">
+ <span class="previous"><a href="nelson_siegel.html"><< nelson_siegel</a></span>
+
+ </td>
+ <td width="40%" class="center">
+ <span class="top"><a href="section_4af098ac34d3d4ed2e545bfe2ad89215.html">Financial module</a></span>
+
+ </td>
+ <td width="30%" class="next">
+
+ </td>
+ </tr></table>
+ <hr />
+ </div>
+ </body>
+</html>
diff --git a/help/en_US/scilab_en_US_help/xml_code.css b/help/en_US/scilab_en_US_help/xml_code.css
new file mode 100644
index 0000000..9e4c27f
--- /dev/null
+++ b/help/en_US/scilab_en_US_help/xml_code.css
@@ -0,0 +1,94 @@
+.xmlcomment {
+ font-style: italic;
+ color: #01a801
+}
+
+.xmldefault {
+ font-style: normal;
+ color: #000000
+}
+
+.xmlentity {
+ font-style: normal;
+ color: #ffaa00
+}
+
+.xmlopeninstr {
+ font-style: normal;
+ color: #000000
+}
+
+.xmlcloseinstr {
+ font-style: normal;
+ color: #000000
+}
+
+.xmlinstrname {
+ font-style: normal;
+ color: #9965a6
+}
+
+.xmllowtag {
+ font-style: normal;
+ color: #000000
+}
+
+.xmltagname {
+ font-style: normal;
+ color: #0303ff
+}
+
+.xmllowclose {
+ font-style: normal;
+ color: #000000
+}
+
+.xmlopencomment {
+ font-style: italic;
+ color: #01a801
+}
+
+.xmlcommentend {
+ font-style: italic;
+ color: #01a801
+}
+
+.xmlcomment {
+ font-style: italic;
+ color: #01a801
+}
+
+.xmlopencdata {
+ font-style: normal;
+ color: #c45555
+}
+
+.xmlcdataend {
+ font-style: normal;
+ color: #c45555
+}
+
+.xmlcdata {
+ font-style: normal;
+ color: #000000
+}
+
+.xmlattributename {
+ font-style: normal;
+ color: #9965a6
+}
+
+.xmlequal {
+ font-style: normal;
+ color: #000000
+}
+
+.xmlattributevalue {
+ font-style: normal;
+ color: #973964
+}
+
+.xmlautoclose {
+ font-style: normal;
+ color: #000000
+}
diff --git a/help/en_US/svennson.xml b/help/en_US/svennson.xml
new file mode 100644
index 0000000..776c43d
--- /dev/null
+++ b/help/en_US/svennson.xml
@@ -0,0 +1,100 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns4="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:id="svennson" xml:lang="en">
+ <refnamediv>
+ <refname>svennson</refname>
+ <refpurpose>Estimate the parameters for the Svennson model of spot interest rates (least square method). Finally draw the actual spot rate curve and the interporalted curve</refpurpose>
+ </refnamediv>
+ <refsynopsisdiv>
+ <title>SYNOPSIS</title>
+ <synopsis>[uopt [,rf]]=svennson(t,r,u0 [,tf]);</synopsis>
+ </refsynopsisdiv>
+ <refsection>
+ <title>Description</title>
+ <para>The Svennson model assumes that the spot interest rate follows the function (of time)</para>
+ <para>f(t)=u1+u4*u6/t+(u2+u3)*u5/t*(1-e^(-t/u5))-(u6/t-1)*u4*e^(-t/u6)-u3*e^(-t/u5)</para>
+ <para>The function estimates the parameters u1, u2, u3, u4, u5, ad u6 with the least square method. It is also possible to foresee some rates for given dates.</para>
+ </refsection>
+ <refsection>
+ <title>Parameters</title>
+ <variablelist>
+ <varlistentry>
+ <term>t</term>
+ <listitem>dates corresponding to the spot interest rates</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>r</term>
+ <listitem>spot interest rate curve</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>u0</term>
+ <listitem>initial values for the parameters (it must be a vector of six elements)</listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>tf</term>
+ <listitem>optional parameter: (column vector) the dates for which we want to use the model in order to foresee the interest rates</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Output</title>
+ <variablelist>
+ <varlistentry>
+ <term>uopt</term>
+ <listitem>vector containing the estimated values of the parameters</listitem>
+ </varlistentry>
+ </variablelist>
+ <variablelist>
+ <varlistentry>
+ <term>rf</term>
+ <listitem>optional output: the foreseen interest rates (for the dates in vector "tf")</listitem>
+ </varlistentry>
+ </variablelist>
+ </refsection>
+ <refsection>
+ <title>Example</title>
+ <para>
+ <para>First we define the dates and the interest rates (taken from the Euribor curve)</para>
+ <para>-->t=[ 0.0192308 0.0384615 0.0576923 0.0833333 0.1666667 0.25 0.3333333 0.4166667 0.5 0.5833333 0.6666667 0.75 0.8333333 0.9166667 1];</para>
+ <para>-->r=[0.00944 0.00949 0.0097 0.01009 0.01213 0.01405 0.01486 0.01534 0.016 0.01636 0.01662 0.01687 0.01716 0.01742 0.01766 ];</para>
+ <para> Now we can use the function and also foreseen the interest rates for 2 years, 3 years, and 4 years</para>
+ <para>-->[uopt,rf]=svennson(t,r,ones(6,1)*0.1,[2 3 4]')</para>
+ <para>-->[uopt,rf]=svennson(t,r,ones(6,1)*0.1,[2 3 4]')</para>
+ <para>Gradient </para>
+ <para>- 0.0010055 </para>
+ <para>- 0.0002346 </para>
+ <para>- 0.0001655 </para>
+ <para>- 0.0005862 </para>
+ <para>0.0001849 </para>
+ <para>- 0.0000623 </para>
+ <para>Objective function </para>
+ <para>0.0000001 </para>
+ <para>rf = </para>
+ <para>0.0187098 </para>
+ <para>0.0191140 </para>
+ <para>0.0193162</para>
+ <para> uopt = </para>
+ <para>0.0199227 </para>
+ <para>- 0.0602590 </para>
+ <para>- 0.0341067 </para>
+ <para>0.0251565 </para>
+ <para>0.0698513 </para>
+ <para>0.1655826 </para>
+ </para>
+ <para>The figure shows the actual interest rates, the estimated ones and the foreseen ones.</para>
+ </refsection>
+ <refsection>
+ <title>Authors</title>
+ <para>Francesco Menoncin - Brescia University - 2010</para>
+ </refsection>
+ <refsection>
+ <title>See Also</title>
+ <simplelist type="inline">
+ <member>
+ <link linkend="leastsq">leastsq, </link>
+ </member>
+ <member>
+ <link linkend="nelson_siegel">nelson_siegel</link>
+ </member>
+ </simplelist>
+ </refsection>
+</refentry>
diff --git a/help/en_US/update_help.sce b/help/en_US/update_help.sce
new file mode 100644
index 0000000..6598473
--- /dev/null
+++ b/help/en_US/update_help.sce
@@ -0,0 +1,233 @@
+// Copyright (C) 2010 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the CeCILL.
+// This source file is licensed as described in the file COPYING, which
+// you should have received as part of this distribution. The terms
+// are also available at
+// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+
+// Updates the .xml files by deleting existing files and
+// creating them again from the .sci with help_from_sci.
+
+function b = isContentUptodate ( content , filename )
+ // Check if a content matches a file.
+ //
+ // Calling Sequence
+ // b = isContentUptodate ( content , filename )
+ //
+ // Parameters
+ // content : a 1x1 matrix of strings, the new content
+ // filename : a 1x1 matrix of strings, the file to be checked.
+ // b : a 1x1 matrix of booleans
+ //
+ // Description
+ // Returns true if the <literal>filename</literal> is up-to-date, that is,
+ // if the file does not require to be changed.
+ // The file is to be updated if one of the following conditions is satisfied.
+ // <itemizedlist>
+ // <listitem>
+ // The file does not exist.
+ // </listitem>
+ // <listitem>
+ // The file exists, but its content is not equal to <literal>content</literal>.
+ // The content comparison ignores the leading and trailing blanks.
+ // </listitem>
+ // </itemizedlist>
+ // Last update : 02/09/2010.
+ //
+ // Example
+ // // TODO...
+ //
+ // Author
+ // 2010 - DIGITEO - Michael Baudin
+ //
+
+ b = %t
+ if ( fileinfo(filename) == [] ) then
+ b = %f
+ else
+ txt = mgetl(filename)
+ if ( or ( stripblanks(content) <> stripblanks(txt) ) ) then
+ b = %f
+ end
+ end
+endfunction
+
+function b = fileUpdateIfNeeded ( content , filename )
+ // Update a file if this is needed.
+ //
+ // Calling Sequence
+ // b = fileUpdateIfNeeded ( content , filename )
+ //
+ // Parameters
+ // content : a 1x1 matrix of strings, the new content
+ // filename : a 1x1 matrix of strings, the file to be checked.
+ // b : a 1x1 matrix of booleans
+ //
+ // Description
+ // Returns true if the <literal>filename</literal> is up-to-date, that is,
+ // if the file was not changed.
+ // Returns false if the file was changed.
+ // The file is to be updated according to the rules of <literal>isContentUptodate</literal>.
+ // Generates an error if the file was to be changed, but that was not possible.
+ // Last update : 02/09/2010.
+ //
+ // Example
+ // // TODO...
+ //
+ // Author
+ // 2010 - DIGITEO - Michael Baudin
+ //
+
+ b = isContentUptodate ( content , filename )
+ if ( ~b ) then
+ r = mputl ( content , filename )
+ if ( ~r ) then
+ error(sprintf(gettext("%s: Unable to write xml file: %s\n"),"fileUpdateIfNeeded",filename));
+ end
+ end
+endfunction
+
+function helpupdate ( funarray , helpdir , macrosdir , demosdir , modulename , verbose )
+ // Update the help and the demos from the .sci files.
+ //
+ // Calling Sequence
+ // updatehelp ( funarray , helpdir , macrosdir , demosdir , modulename , verbose )
+ //
+ // Parameters
+ // funarray : column matrix of strings. The list of functions to update
+ // helpdir : the help directory
+ // macrosdir : the macros directory
+ // demosdir : the demonstration directory
+ // modulename: a 1x1 matrix of strings, the name of the module to update
+ // verbose: a 1x1 matrix of booleans, verbose = %t prints messages
+ // modulename : the name of the module
+ //
+ // Description
+ // Update the .xml help files and the demos scripts
+ // from the macros corresponding to the function array
+ // of strings funarray.
+ // The existing .xml files in the help dir which
+ // correspond to file in the funarray are deleted (Caution !).
+ // Generates the .xml and the .sce files from the help_from_sci function.
+ // Generates a demonstration gateway.
+ //
+ // If demosdir is an empty matrix, do not generate the demonstrations.
+ // Last update : 04/10/2010.
+ //
+ // Author
+ // 2010, Michael Baudin
+
+ if ( fileinfo ( helpdir ) == [] ) then
+ error(sprintf(gettext("%s: Wrong help directory: %s does not exist.\n"),"updatehelp",helpdir));
+ end
+ if ( fileinfo ( macrosdir ) == [] ) then
+ error(sprintf(gettext("%s: Wrong macros directory: %s does not exist.\n"),"updatehelp",macrosdir));
+ end
+ if ( demosdir <> [] ) then
+ if ( fileinfo ( demosdir ) == [] ) then
+ error(sprintf(gettext("%s: Wrong demos directory: %s does not exist.\n"),"updatehelp",demosdir));
+ end
+ end
+
+ //
+ // 2. Generate each .xml and each .sce from the .sci
+ flist = ls(macrosdir)';
+ for f = flist
+ issci = regexp(f,"/(.*).sci/");
+ kf = find(funarray==basename(f))
+ if ( issci <> [] & kf <> [] ) then
+ scifile = fullfile ( macrosdir , f )
+ if ( verbose ) then
+ mprintf("Processing %s\n",scifile);
+ end
+ funname = funarray(kf)
+ xmlfile = fullfile ( helpdir , funname + ".xml" )
+ // Generate the xml and the demo content
+ [helptxt,demotxt]= help_from_sci (scifile)
+ // Delete the "info" tag, containing the date (3 lines)
+ k = find(stripblanks(helptxt)=="<info>")
+ helptxt(k:k+2) = []
+ // Update the xml file, if necessary
+ isuptodate = fileUpdateIfNeeded ( helptxt , xmlfile )
+ if ( ~isuptodate & verbose ) then
+ changetxt = "XML Changed"
+ mprintf(" %s %s\n",changetxt,xmlfile);
+ end
+ // Create the demo
+ if ( demosdir <> [] ) then
+ demofile = fullfile ( demosdir , funname + ".sce" )
+ // Update the demo script
+ header = []
+ header($+1) = "//"
+ header($+1) = "// This help file was automatically generated from "+funname+".sci using help_from_sci()."
+ header($+1) = "// PLEASE DO NOT EDIT"
+ header($+1) = "//"
+ footer = []
+ footer($+1) = msprintf("//\n");
+ footer($+1) = msprintf("// Load this script into the editor\n");
+ footer($+1) = msprintf("//\n");
+ footer($+1) = msprintf("filename = ""%s"";\n",funname + ".sce");
+ footer($+1) = msprintf("dname = get_absolute_file_path(filename);\n");
+ footer($+1) = msprintf("editor ( fullfile(dname,filename) );\n");
+ demotxt = [header;demotxt;footer]
+ // Update the demo file, if necessary
+ isuptodate = fileUpdateIfNeeded ( demotxt , demofile )
+ if ( ~isuptodate & verbose ) then
+ changetxt = "SCE Changed"
+ mprintf(" %s %s\n",changetxt,demofile);
+ end
+ end
+ end
+ end
+ //
+ // 3. Generates the Demonstration gateway
+ // Include all .sce files in the gateway, including
+ // handcrafted scripts which might have been written
+ // by the user (and not generated by this function).
+ // To make so, use the list of .sce files in the demo dir and
+ /// not simply the funarray.
+ if ( demosdir <> [] ) then
+ gatetxt = []
+ gatetxt ($+1) = "// This help file was automatically generated using helpupdate"
+ gatetxt ($+1) = "// PLEASE DO NOT EDIT"
+ gatetxt ($+1) = "demopath = get_absolute_file_path(""" + modulename + ".dem.gateway.sce"");"
+ gatetxt ($+1) = "subdemolist = ["
+ flist = ls(demosdir)';
+ for f = flist
+ issce = regexp(f,"/(.*).sce/");
+ isgateway = regexp(f,"/(.*).gateway.sce/");
+ if ( issce <> [] & isgateway == [] ) then
+ flen = length(f)
+ funname = part(f,[1:flen-4])
+ gatetxt($+1) = """" + funname + """, """ + funname + ".sce""; .."
+ end
+ end
+ //
+ gatetxt ($+1) = "];"
+ gatetxt ($+1) = "subdemolist(:,2) = demopath + subdemolist(:,2)"
+ gatefile = fullfile ( demosdir , modulename+".dem.gateway.sce" )
+ // Update the gateway file, if necessary
+ isuptodate = fileUpdateIfNeeded ( gatetxt , gatefile )
+ if ( ~isuptodate & verbose ) then
+ changetxt = "SCE Gateway Changed"
+ mprintf("%s %s\n",changetxt,gatefile);
+ end
+ end
+endfunction
+
+//
+cwd = get_absolute_file_path("update_help.sce");
+mprintf("Working dir = %s\n",cwd);
+//
+// Generate the library help
+mprintf("Updating financial\n");
+helpdir = cwd;
+funmat = [
+ "bsgreeks"
+ ];
+macrosdir = cwd +"../../macros";
+demosdir = cwd +"../../demos";
+modulename = "financial";
+helpupdate ( funmat , helpdir , macrosdir , demosdir , modulename , %t )
+
diff --git a/jar/scilab_en_US_help.jar b/jar/scilab_en_US_help.jar
new file mode 100644
index 0000000..f336e81
Binary files /dev/null and b/jar/scilab_en_US_help.jar differ
diff --git a/license.txt b/license.txt
new file mode 100644
index 0000000..a455933
--- /dev/null
+++ b/license.txt
@@ -0,0 +1,7 @@
+Financial Scilab Toolbox
+
+This toolbox is released under the terms of the GPL (3.0) license :
+
+http://gplv3.fsf.org/
+
+
diff --git a/loader.sce b/loader.sce
new file mode 100644
index 0000000..00aa08a
--- /dev/null
+++ b/loader.sce
@@ -0,0 +1,10 @@
+// This file is released under the 3-clause BSD license. See COPYING-BSD.
+// Generated by builder.sce: Please, do not edit this file
+
+try
+ getversion("scilab");
+catch
+ error("Scilab 5.0 or more is required.");
+end;
+
+exec(get_absolute_file_path("loader.sce")+"etc/"+"financial.start");
diff --git a/macros/backtest.bin b/macros/backtest.bin
new file mode 100644
index 0000000..2ecba51
Binary files /dev/null and b/macros/backtest.bin differ
diff --git a/macros/backtest.sci b/macros/backtest.sci
new file mode 100644
index 0000000..5b9c564
--- /dev/null
+++ b/macros/backtest.sci
@@ -0,0 +1,57 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function backtest(price,alpha,varargin);
+
+// PURPOSE: Apply the backtest to three different
+// risk measures (as percentage of lost):
+// Expected Shortfall, Value at Risk,
+// and a Spectral Measure with linear spectrum.
+// Finally, show the graph of historical returns and
+// the risk measures.
+// The thresholds of the backtest are also computed
+//--------------------------------------------------------------
+// INPUT:
+// * price = matrix whose columns contain the historical
+// prices of each asset
+// * alpha = confidence level of risk measures
+// * N = (optional input) number of observations which
+// the backtest is computed on (default value 250
+// if there are more than 500 historical prices,
+// else N is half the size of "price")
+// -------------------------------------------------------------
+// OUTPUT:
+// Compute the exceptions of three risk sources and show
+// them graphically
+// -------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ if size(varargin)==1 then
+ N=varargin(1);
+ else
+ if size(price,1)>=500 then
+ N=250;
+ else
+ N=floor(size(price,1)/2);
+ end
+ end
+ for i=1:N
+ [ES(i),VaR(i),M(i)]=esvarlin(price($-2*N+i:$-(N+1)+i),alpha);
+ end;
+ y=diff(price,1,1)./price(1:$-1,:);
+ exeptions=[sum(bool2s(y($-(N-1):$)<=-ES)) sum(bool2s(y($-(N-1):$)<=-VaR)) sum(bool2s(y($-(N-1):$)<=-M))];
+ z1=find(cumsum(binomial(alpha,N))>=0.95);
+ z1=z1(1)-1;
+ z2=find(cumsum(binomial(alpha,N))>=0.9999);
+ z2=z2(1)-1;
+ disp(['Green zone:' '0-'+string(z1);
+ 'Yellow zone:' string(z1)+'-'+string(z2);
+ 'Red zone:' string(z2)+'-']);
+ disp(['ES: ' string(exeptions(1))+' exeptions';
+ 'VaR: ' string(exeptions(2))+' exeptions';
+ 'Linear Spectrum: ' string(exeptions(3))+' exeptions']);
+ plot([y($-(N-1):$) -ES -VaR -M]);
+ legend(['Historical returns','ES','VaR','Linear Spectrum'],2);
+endfunction
diff --git a/macros/bollinger.bin b/macros/bollinger.bin
new file mode 100644
index 0000000..2f495b7
Binary files /dev/null and b/macros/bollinger.bin differ
diff --git a/macros/bollinger.sci b/macros/bollinger.sci
new file mode 100644
index 0000000..93e9418
--- /dev/null
+++ b/macros/bollinger.sci
@@ -0,0 +1,36 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function bollinger(S,m,a)
+
+// PURPOSE: On historical data "S", draw both the moving
+// average of length "m" and the Bollinger bands
+// of width "a". Also draw the percentage b.
+//---------------------------------------------------------
+// INPUT:
+// * S = historical data
+// * m = moving average length
+// * a = width of the Bollinger bands
+// -------------------------------------------------------------
+// OUTPUT:
+//
+// -------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ for k=size(S,1):-1:m
+ M(k,1)=mean(S(k-m+1:k));
+ V(k,1)=sqrt(variance(S(k-m+1:k)));
+ end
+ M(1:m-1)=%nan;
+ subplot(2,1,1);
+ plot(S); plot(M,'green'); plot([M+a*V,M-a*V],'--red');
+ title('Moving average and Bollinger bands');
+ b(1:m-1,1)=%nan;
+ b=[b;(S(m:$)-(M(m:$)-a*V(m:$)))./(2*a*V(m:$))];
+ subplot(2,1,2);
+ plot(b);
+ plot([zeros(size(S,1),1), ones(size(S,1),1)],'--red');
+ title('Percentage b');
+endfunction
diff --git a/macros/bsgreeks.bin b/macros/bsgreeks.bin
new file mode 100644
index 0000000..4a64297
Binary files /dev/null and b/macros/bsgreeks.bin differ
diff --git a/macros/bsgreeks.sci b/macros/bsgreeks.sci
new file mode 100644
index 0000000..b285c58
--- /dev/null
+++ b/macros/bsgreeks.sci
@@ -0,0 +1,62 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+// Copyright (C) 2010 - DIGITEO - Michael Baudin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [delta,gama,theta,rho,vega]=bsgreeks(S,K,r,T,sigma)
+ // Compute the Greeks for both a call and a put option in a Black and Scholes model.
+ //
+ // Calling Sequence
+ // [delta,gama,theta,rho,vega]=bsgreeks(S,K,r,T,sigma)
+ //
+ // Parameters
+ // S : a 1-by-1 matrix of doubles, current price of the underlying asset
+ // K : a 1-by-1 matrix of doubles, strike price of the option
+ // r : a 1-by-1 matrix of doubles, riskless interest rate (assumed to be constant until the maturity)
+ // T : a 1-by-1 matrix of doubles, time to maturity; it must be in the same time unit of measure as the riskless interest rate (if the riskless interest rate is annual, then an option with maturity of 3 months must have T=3/12)
+ // sigma : a 1-by-1 matrix of doubles, volatility of the underlying (log-) returns; it must be in the same time unit of measure as the riskless interest rate
+ // delta : a 2-by-1 matrix of doubles, the first derivative of the call (first term) and put (second term) option prices with respect to the underlying asset price
+ // gama : a 1-by-1 matrix of doubles, second derivative of the call (or put) option price with respect to the underlying asset price
+ // theta : a 2-by-1 matrix of doubles, vector containing the first derivative of the call (first term) and put (second term) option prices with respect to the time to maturity
+ // rho : a 2-by-1 matrix of doubles, vector containing the first derivative of the call (first term) and put (second term) option prices with respect to the riskless interest rate
+ // vega : a 1-by-1 matrix of doubles, first derivative of the call (or put) option price with respect to the standard deviation of the underlying (log-) returns
+ //
+ // Description
+ // Computes the Greeks of both call and put option in a Black and Scholes framework
+ //
+ // Examples
+ // // We compute the Greeks on both a call and put option
+ // // with: underlying price 25 euros,
+ // // strike price 25 euros,
+ // // 0.01 (annual) riskless interest rate,
+ // // 3 month time to maturity (i.e. T=3/12),
+ // // and 0.2 (annual) volatility.
+ // [D,G,Th,R,V]=bsgreeks(25,25,0.01,3/12,0.2)
+ // V = 4.9727729;
+ // R = [3.0550246;-3.1793699];
+ // T = [2.1113101;1.8619344];
+ // G = 4.9727729;
+ // D = [0.5298926;-0.4701074];
+ //
+ // Authors
+ // Copyright (C) 2009 - 2010 - Francesco Menoncin
+ // Copyright (C) 2010 - DIGITEO - Michael Baudin
+ //
+ // Bibliography
+ // TODO
+ //
+ // See also
+ // bsoption
+ // bsimpvol
+
+ d1=-((log(K/S)-(r+1/2*sigma^2)*T)/(sigma*sqrt(T)))
+ d2=-((log(K/S)-(r-1/2*sigma^2)*T)/(sigma*sqrt(T)))
+ delta=[cdfnor('PQ',d1,0,1);-cdfnor('PQ',-d1,0,1)]
+ gama=S*sqrt(T)*exp(-d1^2/2)/sqrt(2*%pi)
+ theta=[K*exp(-r*T)*(r*cdfnor('PQ',d2,0,1)+sigma*exp(-d2^2/2)/sqrt(2*%pi)/(2*sqrt(T)));...
+ K*exp(-r*T)*(-r*cdfnor('PQ',-d2,0,1)+sigma*exp(-d2^2/2)/sqrt(2*%pi)/(2*sqrt(T)))]
+ rho=[T*K*exp(-r*T)*cdfnor('PQ',d2,0,1);-T*K*exp(-r*T)*cdfnor('PQ',-d2,0,1)]
+ vega=S*sqrt(T)*exp(-d1^2/2)/sqrt(2*%pi)
+endfunction
+
diff --git a/macros/bsimpvol.bin b/macros/bsimpvol.bin
new file mode 100644
index 0000000..c9f44cb
Binary files /dev/null and b/macros/bsimpvol.bin differ
diff --git a/macros/bsimpvol.sci b/macros/bsimpvol.sci
new file mode 100644
index 0000000..905ade5
--- /dev/null
+++ b/macros/bsimpvol.sci
@@ -0,0 +1,37 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [sigmaC,sigmaP]=bsimpvol(option,S,K,r,T,sigma0);
+
+// PURPOSE: Compute the implicit volatility for the Black and Scholes
+// model when the price of an option is known, for both
+// call option and put option
+//------------------------------------------------------------------
+// INPUT:
+// * option = option price
+// * S = price of the underlying asset
+// * K = strike price
+// * r = riskless interest rate
+// * T = time to maturity
+// * sigma0 = starting guess value for the iterations
+// -----------------------------------------------------------------
+// OUTPUT:
+// * sigmaC = implied volatility of a call option
+// * sigmaP = implied volatility of a put option
+// -----------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ function [Y]=difference(s);
+ d1=-((log(K/S)-(r+1/2*s^2)*T)/(s*sqrt(T)));
+ d2=-((log(K/S)-(r-1/2*s^2)*T)/(s*sqrt(T)));
+ Y=segno*S*cdfnor('PQ',segno*d1,0,1)-segno*K*exp(-r*T)*cdfnor('PQ',segno*d2,0,1)-option;
+ endfunction
+ segno=1;
+ [sigmaC,d,inf]=fsolve(sigma0,difference);
+ if inf==1 then disp('Call: good convergence'); else disp('Call: bad convergence'); end
+ segno=-1;
+ [sigmaP,d,inf]=fsolve(sigma0,difference);
+ if inf==1 then disp('Put: good convergence'); else disp('Put: bad convergence'); end
+endfunction
diff --git a/macros/bsoption.bin b/macros/bsoption.bin
new file mode 100644
index 0000000..62867a7
Binary files /dev/null and b/macros/bsoption.bin differ
diff --git a/macros/bsoption.sci b/macros/bsoption.sci
new file mode 100644
index 0000000..678bf6c
--- /dev/null
+++ b/macros/bsoption.sci
@@ -0,0 +1,28 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [C,P]=bsoption(S,K,r,T,sigma);
+
+// PURPOSE: Compute the value of both call and put options
+// with the Black and Scholes formula
+//------------------------------------------------------------------
+// INPUT:
+// * S = price of the underlying asset
+// * K = strike price
+// * r = riskless interest rate
+// * T = time to maturity
+// * sigma = diffusion of the underlying asset return
+// -----------------------------------------------------------------
+// OUTPUT:
+// * C = value of the call option
+// * P = value of the put option
+// -----------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ d1=-((log(K/S)-(r+1/2*sigma^2)*T)/(sigma*sqrt(T)));
+ d2=-((log(K/S)-(r-1/2*sigma^2)*T)/(sigma*sqrt(T)));
+ C=S*cdfnor('PQ',d1,0,1)-K*exp(-r*T)*cdfnor('PQ',d2,0,1);
+ P=C+K*exp(-r*T)-S;
+endfunction
diff --git a/macros/buildmacros.bat b/macros/buildmacros.bat
new file mode 100644
index 0000000..f6f1b04
--- /dev/null
+++ b/macros/buildmacros.bat
@@ -0,0 +1 @@
+ at scilex -nwni -e exec("buildmacros.sce");quit;
diff --git a/macros/buildmacros.sce b/macros/buildmacros.sce
new file mode 100644
index 0000000..ceac364
--- /dev/null
+++ b/macros/buildmacros.sce
@@ -0,0 +1 @@
+tbx_build_macros("financial", get_absolute_file_path("buildmacros.sce"));
diff --git a/macros/cfr.bin b/macros/cfr.bin
new file mode 100644
index 0000000..c7d96f4
Binary files /dev/null and b/macros/cfr.bin differ
diff --git a/macros/cfr.sci b/macros/cfr.sci
new file mode 100644
index 0000000..cc8ede5
--- /dev/null
+++ b/macros/cfr.sci
@@ -0,0 +1,35 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [S]=cfr(varargin);
+
+// PURPOSE: Compare two or more time series and eliminate
+// the data whose date is not in all the series
+//---------------------------------------------------------
+// INPUT:
+// As many two-clumn matrix as time series. The first column
+// of any matrix must contain the dates, the second column
+// must contain the data
+// -------------------------------------------------------------
+// OUTPUT:
+// * S = a matrix containing the dates in the first clumn and
+// the times series in all the other columns
+// -------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+function [z]=cfr2(x,y);
+z=[];
+for i=1:size(x,1)
+ [r,c]=find(y==x(i,1));
+ if r<>[] then z=[z; x(i,:), y(r,2)]; else end;
+end
+endfunction
+
+S=varargin(1);
+for k=2:size(varargin)
+ S=cfr2(S,varargin(k));
+end;
+
+endfunction
diff --git a/macros/cleanmacros.bat b/macros/cleanmacros.bat
new file mode 100644
index 0000000..fe30bc9
--- /dev/null
+++ b/macros/cleanmacros.bat
@@ -0,0 +1,3 @@
+ at rm *.bin
+ at rm lib
+ at rm names
diff --git a/macros/cleanmacros.sce b/macros/cleanmacros.sce
new file mode 100644
index 0000000..07c6bbe
--- /dev/null
+++ b/macros/cleanmacros.sce
@@ -0,0 +1,16 @@
+// ====================================================================
+// Allan CORNET
+// DIGITEO 2009
+// This file is released into the public domain
+// ====================================================================
+libpath = get_absolute_file_path('cleanmacros.sce');
+
+binfiles = ls(libpath+'/*.bin');
+for i = 1:size(binfiles,'*')
+ mdelete(binfiles(i));
+end
+
+mdelete(libpath+'/names');
+mdelete(libpath+'/lib');
+
+// ====================================================================
diff --git a/macros/duration.bin b/macros/duration.bin
new file mode 100644
index 0000000..3739a20
Binary files /dev/null and b/macros/duration.bin differ
diff --git a/macros/duration.sci b/macros/duration.sci
new file mode 100644
index 0000000..c226f39
--- /dev/null
+++ b/macros/duration.sci
@@ -0,0 +1,31 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [dur,con,ytm]=duration(t,c);
+
+// PURPOSE: Compute "Duration", "Convexity" and "Yield to Maturity"
+// for an asset paying a stream of cash flows
+//--------------------------------------------------------------
+// INPUT:
+// * t = column vector of times where flows are paid
+// (the first value must be zero)
+// * c = column vector of cash flows (the first negative
+// cash flow must be the price of the asset)
+// -------------------------------------------------------------
+// OUTPUT:
+// * dur = duration of the asset
+// * con = convexity of the asset
+// * ytm = yield to maturity
+//
+// Cash flows are discounted with the Yield to Maturity
+// -------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ deff('[van]=van(r)','van=c''*(1+r)^(-t)');
+ [ytm,f,inf]=fsolve(0,van);
+ if inf<>1 then disp('Bad convergence'); else end
+ dur=c(2:$)'*((1+ytm)^(-t(2:$)).*t(2:$))/(-c(1));
+ con=c(2:$)'*((1+ytm)^(-t(2:$)).*(t(2:$).^2))/(-c(1));
+endfunction
diff --git a/macros/esvarevt.bin b/macros/esvarevt.bin
new file mode 100644
index 0000000..b1b8061
Binary files /dev/null and b/macros/esvarevt.bin differ
diff --git a/macros/esvarevt.sci b/macros/esvarevt.sci
new file mode 100644
index 0000000..c4b759b
--- /dev/null
+++ b/macros/esvarevt.sci
@@ -0,0 +1,37 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [es,var,xoptim,v,inf]=esvarevt(x0,data,u,alpha)
+
+// PURPOSE: Estimate the parameters ("xi" and "beta") of a
+// Generalized Pareto Density f(x) with Maximum Likelihood
+// and compute both VaR and Expected Shortfall
+//
+// f(x) = (1+xi*(x-u)/beta)^(-1/xi-1)/beta
+//------------------------------------------------------------------
+// INPUT:
+// * x0 = starting values for the parameters "xi" and "beta"
+// * data = historical data
+// * u = threshold parameter
+// * alpha = confidence level fot the risk measures
+// -----------------------------------------------------------------
+// OUTPUT:
+// * var = Value at Risk (at "alpha" confidence level)
+// * es = Expected Shortfall (at "alpha" confidence level)
+// * xoptim = maximum likelihood value of the parameters
+// "xi" and "beta"
+// * v = same value as "v" in the "fsolve" function
+// * inf = same values as "inf" in the "fsolve" function
+// -----------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ x=data(data>u);
+ deff('[y]=eq(z)','y=[1/z(1)/z(2)-(1/z(1)+1)/z(2)*mean((1+z(1)*(x-u)/z(2))^(-1));...
+ -(1/z(1)+1)/z(1)+1/z(1)^2*mean(log(1+z(1)*(x-u)/z(2)))+(1/z(1)+1)/z(1)*mean((1+z(1)*(x-u)/z(2))^(-1))]');
+ [xoptim,v,inf]=fsolve(x0,eq);
+ N=size(data,1); Nu=size(x,1);
+ var=u+xoptim(2)/xoptim(1)*((N*alpha/Nu)^(-xoptim(1))-1);
+ es=(var+xoptim(2)-u*xoptim(1))/(1-xoptim(1));
+endfunction
diff --git a/macros/esvarlin.bin b/macros/esvarlin.bin
new file mode 100644
index 0000000..aa4e754
Binary files /dev/null and b/macros/esvarlin.bin differ
diff --git a/macros/esvarlin.sci b/macros/esvarlin.sci
new file mode 100644
index 0000000..6fa0249
--- /dev/null
+++ b/macros/esvarlin.sci
@@ -0,0 +1,38 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [ES,VaR,M]=esvarlin(price,alpha);
+
+// PURPOSE: With historical simulation, computes three
+// risk measures (as percentage of loss):
+// Expected Shortfall, Value at Risk,
+// and a Spectral Measure with linear spectrum
+//--------------------------------------------------------------
+// INPUT:
+// * price = matrix whose columns contain the historical
+// prices of each asset
+// * alpha = confidence level of risk measures;
+// it can be a vector for simlutaneously computing
+// the risk meausures at different confidence levels
+// -------------------------------------------------------------
+// OUTPUT:
+// * ES = Expected Shortfall
+// * VaR = Value at Risk
+// * M = Linear Spectral Risk Measure
+// -------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ y=diff(price,1,1)./price(1:$-1,:);
+ y=gsort(y,'r','i');
+ n=size(y,1);
+ for i=1:max(size(alpha))
+ k=size(y(1:$*alpha(i),:),1);
+ ES(i,:)=-(sum(y(1:k,:),1)/n+y(k+1,:)*(alpha(i)-k/n))/alpha(i);
+ VaR(i,:)=-y(ceil(size(y,1)*alpha(i)),:);
+ if k<2 then k=2, end;
+ fi=max(2*n*(k-[1:n]')/(k*(k-1)),0);
+ M(i,:)=-fi'*y/n;
+ end
+endfunction
diff --git a/macros/esvaroptim.bin b/macros/esvaroptim.bin
new file mode 100644
index 0000000..44d9fcc
Binary files /dev/null and b/macros/esvaroptim.bin differ
diff --git a/macros/esvaroptim.sci b/macros/esvaroptim.sci
new file mode 100644
index 0000000..6c03c9d
--- /dev/null
+++ b/macros/esvaroptim.sci
@@ -0,0 +1,118 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [w,ES,VaR]=esvaroptim(price,ER,r,dt,alpha);
+
+// PURPOSE: Compute the optimal portfolio
+// minimizing the "Expected Shortfall" and
+// also show the value of the "Value at Risk"
+//--------------------------------------------------------------
+// INPUT:
+// * price = matrix whose columns contain the historical
+// prices of each asset
+// * ER = expected (annual) portfolio return
+// * r = riskless (annual) interest rate
+// * dt = data frequencty (e.g. dt=1 for annual data,
+// dt=1/4 for quarter data, and so on...)
+// * alpha = confidence level of both Expected Shortfall
+// and Value at Risk
+// -------------------------------------------------------------
+// OUTPUT:
+// * w = matrix of the optimal portfolio composition
+// first raw : with short selling and with r
+// second raw : with short selling and without r
+// third raw : without short selling and with r
+// fourth raw : without short selling and without r
+// * ES = Expected Shortfall of the optimal portfolio
+// * VaR = Value at Risk of the optimal portfolio
+// -------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ ER=ER*dt;
+ r=r*dt,
+ Rp=diff(price,1,1)./price(1:$-1,:);
+ K=size(Rp,1);
+ n=size(Rp,2);
+ p=[-1;ones(K,1)/(alpha*K);zeros(n,1)];
+ yiw=[-100000; zeros(K+n,1)];
+ yi=[-100000; zeros(K,1); -ones(n,1)*100000]
+ //
+ // Matrices without r
+ //
+ C=[zeros(1,K+1),mean(Rp,1); zeros(1,K+1),ones(1,n); ones(K,1),-eye(K,K),-Rp];
+ b=[ER;1;zeros(K,1)];
+ //
+ // Matrice with r
+ //
+ Cr=[zeros(1,K+1),mean(Rp,1)-r;ones(K,1),-eye(K,K),-Rp+r];
+ br=[ER-r;ones(K,1)*r];
+ //
+ // Portfolio with short selling
+ //
+ Q=zeros(size(p,1),size(p,1));
+ yr=qld(Q,p,Cr,br,yi,[],1);
+ y=qld(Q,p,C,b,yi,[],2);
+ VaR=[-yr(1) -y(1)];
+ w=[yr(K+2:$) y(K+2:$)];
+ ES=[yr'*p y'*p];
+ //
+ // Portfolio without short selling
+ //
+ if ER>min(mean(Rp,1)) & ER<max(mean(Rp,1)) then
+ yrw=qld(Q,p,Cr,br,yiw,[],1);
+ yw=qld(Q,p,C,b,yiw,[],2);
+ VaR(:,3:4)=[-yrw(1) -yw(1)];
+ w(:,3:4)=[yrw(K+2:$) yw(K+2:$)];
+ ES(:,3:4)=[yrw'*p yw'*p];
+ else
+ VaR(:,3:4)=%nan;
+ w(:,3:4)=%nan;
+ ES(:,3:4)=%nan;
+ end
+ //
+ // Draw frontiers
+ //
+ frontier=input('Draw frontier? (y/n) ','string');
+ disp([' with short selling',' without short selling']);
+ disp([' with r',' without r',' with r',' without r']);
+if frontier=='y' then
+ xtitle('Return-Expected Shortfall Frontier','Expected Shortfall','Mean return');
+ //
+ // Define coordinates
+ //
+ ordi=max(0,min(mean(Rp,1)));
+ ords=max(mean(Rp,1));
+ ord=[ordi:(ords-ordi)/100:ords];
+ //
+ // Compute and draw unconstrained frontiers
+ //
+ for i=1:size(ord,2)
+ b=[ord(i);1;zeros(K,1)];
+ br=[ord(i)-r;ones(K,1)*r];
+ y=qld(Q,p,C,b,yi,[],2);
+ yr=qld(Q,p,Cr,br,yi,[],1);
+ x(i)=y'*p;
+ xr(i)=yr'*p;
+ end
+ plot(x,ord,'black');
+ plot(xr,ord,'--black');
+ if ER>min(mean(Rp,1)) & ER<max(mean(Rp,1)) then
+ for i=1:size(ord,2)
+ b=[ord(i);1;zeros(K,1)];
+ br=[ord(i)-r;ones(K,1)*r];
+ yw=qld(Q,p,C,b,yiw,[],2);
+ yrw=qld(Q,p,Cr,br,yiw,[],1);
+ xw(i)=yw'*p;
+ xrw(i)=yrw'*p;
+ end
+ plot(xw,ord,'red');
+ plot(xrw,ord,'--red');
+ legend(['Without r - with short selling','With r - with short selling','Without r - without short selling','With r - without short selling'],2)
+ else
+ legend(['Without r - with short selling','With r - with short selling'],2)
+ end
+ else
+end
+endfunction
diff --git a/macros/euler.bin b/macros/euler.bin
new file mode 100644
index 0000000..19fc5d6
Binary files /dev/null and b/macros/euler.bin differ
diff --git a/macros/euler.sci b/macros/euler.sci
new file mode 100644
index 0000000..c4cd16d
--- /dev/null
+++ b/macros/euler.sci
@@ -0,0 +1,45 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [x]=euler(drift,diffusion,dt,T,x0,t0);
+
+// PURPOSE: Through Euler method, find the numerical
+// solution to a system of stochastic differential
+// equations of the following form
+// dx = drift(t,x) dt + diffusion(t,x) dW
+// where "dx" is a vecotr, "drift" is a vector,
+// "diffusion" is a matrix, and "dW" is a vector
+//---------------------------------------------------------------
+// INPUT:
+// * drift = STRING describing the COLUMN vector of the
+// drifts, the unknowns must be named
+// "t" and "x" (if there are more x's, then they
+// must be named "x(1)", "x(2)",and so on)
+// * diffusion = STRING describing the MATRIX of the
+// diffusions, the unknowns must be named
+// as in the drift
+// * T = time during which performing the simulation
+// * dt = time interval (e.g. with daily data and "T"
+// set in years, dt=1/250)
+// * x0 = the vector of initial values of variables "x"'s
+// * t0 = the initial value of variable "t"
+// ---------------------------------------------------------------
+// OUTPUT:
+// * x = matrix whose columns contain the series of
+// simulated variable "x"'s
+// ---------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ deff('y=mu(t,x)',strcat(['y=',drift]));
+ deff('y=sigma(t,x)',strcat(['y=',diffusion]));
+ dW=rand(size(sigma(t0,x0),2),T/dt,'normal')*sqrt(dt);
+ x(:,1)=x0;
+ t(1)=t0;
+ for i=2:T/dt
+ x(:,i)=x(:,i-1)+mu(t(i-1),x(:,i-1))*dt+sigma(t(i-1),x(:,i-1))*dW(:,i);
+ t(i)=t(i-1)+dt;
+ end;
+ x=x';
+endfunction
diff --git a/macros/evt.bin b/macros/evt.bin
new file mode 100644
index 0000000..9c28d00
Binary files /dev/null and b/macros/evt.bin differ
diff --git a/macros/evt.sci b/macros/evt.sci
new file mode 100644
index 0000000..d31aec0
--- /dev/null
+++ b/macros/evt.sci
@@ -0,0 +1,30 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [xoptim,v,inf]=evt(x0,x,u)
+
+// PURPOSE: Estimate the parameters ("xi" and "beta") of a
+// Generalized Pareto Density with Maximum Likelihood
+//
+// f(x) = (1+xi*(x-u)/beta)^(-1/xi-1)/beta
+//------------------------------------------------------------------
+// INPUT:
+// * x0 = starting values for the parameters "xi" and "beta"
+// * x = historical asset returns
+// * u = threshold parameter
+// -----------------------------------------------------------------
+// OUTPUT:
+// * xoptim = maximum likelihood value of the parameters
+// "xi" and "beta"
+// * v = same value as "v" in the "fsolve" function
+// * inf = same values as "inf" in the "fsolve" function
+// -----------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ x=x(x>u);
+ deff('[y]=eq(z)','y=[1/z(1)/z(2)-(1/z(1)+1)/z(2)*mean((1+z(1)*(x-u)/z(2))^(-1));...
+ -(1/z(1)+1)/z(1)+1/z(1)^2*mean(log(1+z(1)*(x-u)/z(2)))+(1/z(1)+1)/z(1)*mean((1+z(1)*(x-u)/z(2))^(-1))]');
+ [xoptim,v,inf]=fsolve(x0,eq);
+endfunction
diff --git a/macros/gbm.bin b/macros/gbm.bin
new file mode 100644
index 0000000..84f122e
Binary files /dev/null and b/macros/gbm.bin differ
diff --git a/macros/gbm.sci b/macros/gbm.sci
new file mode 100644
index 0000000..a7b1728
--- /dev/null
+++ b/macros/gbm.sci
@@ -0,0 +1,40 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [mu,sigma]=gbm(data,dt);
+
+// PURPOSE: Estimate the parameters of a Geometric Brownian
+// Motion - GBM (through the method of moments) and
+// graphically show the result
+//----------------------------------------------------------------
+// INPUT:
+// * data = historical data (in a column vector)
+// * dt = data frequencty (e.g. dt=1 for annual data,
+// dt=1/4 for quarter data, and so on...)
+// ----------------------------------------------------------------
+// OUTPUT:
+// * mu = drift term of the GBM
+// * sigma = diffusion term of the GBM
+// In the final figure:
+// in black : the historical data
+// in blue : the mean of the process
+// in dotted blue : the confidence interval
+// (mean +/- st_dev and
+// mena +/- 2 times st_dev)
+//
+// ----------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ dln=diff(log(data));
+ sigma=sqrt(mvvacov(dln)/dt);
+ mu=mean(dln)/dt+1/2*sigma^2;
+ N=size(data,1);
+ t=[1:N]'*dt;
+ M=data(1)*exp(mu*t);
+ Std=data(1)*exp(mu*t).*sqrt(exp(sigma^2*t)-1);
+ plot(data,'black');
+ plot(M,'blue');
+ plot([M-Std M-2*Std M+2*Std M+Std],'blue--');
+endfunction
diff --git a/macros/hedge.bin b/macros/hedge.bin
new file mode 100644
index 0000000..9a0bce6
Binary files /dev/null and b/macros/hedge.bin differ
diff --git a/macros/hedge.sci b/macros/hedge.sci
new file mode 100644
index 0000000..6db223e
--- /dev/null
+++ b/macros/hedge.sci
@@ -0,0 +1,49 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [h]=hedge(S,F);
+
+// PURPOSE: Compute the hedge ratio between an asset "S"
+// and a derivative on it "F"
+//------------------------------------------------------------------
+// INPUT:
+// * S = column vector of historical prices of an asset
+// * F = column vector of historical prices of a derivative
+//
+// S and F must have the same dimension
+// -----------------------------------------------------------------
+// OUTPUT:
+// * h = hedge ratio between S and F. If one multiplies the wealth
+// invested in S by "h", one obtains the wealth that must be
+// invested in F in order to hedged the position on S
+// -----------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ dlnS=diff(log(S),1,1);
+ dlnF=diff(log(F),1,1);
+
+ X=[ones(dlnS) dlnS];
+ [nobs,nvar]=size(X);
+ bhat=(X'*X)^(-1)*X'*dlnF;
+ h=-1/bhat(2);
+ R2=1-(dlnF-X*bhat)'*(dlnF-X*bhat)/((dlnF-mean(dlnF))'*(dlnF-mean(dlnF)));
+ R2c=1-(1-R2)*(nobs-1)/(nobs-nvar);
+
+// computation of t-statistics
+
+ tstat=sqrt((nobs-nvar)/((dlnF-X*bhat)'*(dlnF-X*bhat)))*bhat./sqrt(diag((X'*X)^(-1)));
+
+ plot(dlnF,'blue');
+ plot(X*bhat,'red');
+ legend(['Historical values','Estimated values']);
+
+ disp(['N. observations' string(nobs);...
+ 'N. variables' string(nvar);...
+ 'R-square' string(R2);...
+ 'R-square corrected' string(R2c)]);
+ disp(['Coefficients' 't-statistics';...
+ string(bhat) string(tstat)]);
+
+endfunction
diff --git a/macros/hurst.bin b/macros/hurst.bin
new file mode 100644
index 0000000..2273416
Binary files /dev/null and b/macros/hurst.bin differ
diff --git a/macros/hurst.sci b/macros/hurst.sci
new file mode 100644
index 0000000..8a4856b
--- /dev/null
+++ b/macros/hurst.sci
@@ -0,0 +1,38 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [H]=hurst(price,varargin);
+
+// PURPOSE: Compute the Hurst index on
+// historical prices
+//--------------------------------------------------------------
+// INPUT:
+// * price = vector of historical prices
+// * period = (optional input, by default 250) first number of
+// prices used for computing the index
+// * step = (optional input, by default 10) each increment
+// in the number of prices used for computing
+// the index
+// -------------------------------------------------------------
+// OUTPUT:
+// H = Hurst index
+// -------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ select size(varargin)
+ case 0 then period=250; step=10;
+ case 1 then period=varargin(1); step=10;
+ case 2 then period=varargin(1); step=varargin(2);
+ end
+ for i=1:(length(price)-period)/step
+ dlnS=diff(log(price(1:period+step*(i-1))));
+ x(i)=log(length(dlnS));
+ y(i)=log((max(cumsum(dlnS-mean(dlnS)))-min(cumsum(dlnS-mean(dlnS))))/stdev(dlnS));
+ end
+ plot(x,y,'.');
+ x=[ones(x) x];
+ bhat=(x'*x)^(-1)*x'*y;
+ H=bhat(2);
+endfunction
diff --git a/macros/interest.bin b/macros/interest.bin
new file mode 100644
index 0000000..aee3ecb
Binary files /dev/null and b/macros/interest.bin differ
diff --git a/macros/interest.sci b/macros/interest.sci
new file mode 100644
index 0000000..cf16bd4
--- /dev/null
+++ b/macros/interest.sci
@@ -0,0 +1,78 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [rf]=interest(r,dt,T,model,n,r0);
+
+// PURPOSE: Simulate future interest rate by estimating
+// the parameters of three models on the historical
+// interest rate
+//---------------------------------------------------------
+// INPUT:
+// * r = column vector of historical interest rates
+// * dt = time unit of measure
+// * T = number of periods to simulate
+// * model = either "merton", or "vasicek", or "cir"
+// * n = the number of simulations to perform
+// * r0 = the first interest rate for simulation
+// -------------------------------------------------------------
+// OUTPUT:
+// * rf = the matrix whose rows contain the future values of
+// interest rate and whose columns contains
+// each simulation
+// -------------------------------------------------------------
+// Francesco Menoncin (2009)
+
+ select model
+ case 'merton' then
+ mu=mean(diff(r))/dt;
+ sigma=sqrt(mvvacov(diff(r))/dt);
+ rf=r0*ones(1,n);
+ for j=1:n
+ dW=rand(T/dt,1,'normal')*sqrt(dt);
+ for i=2:T/dt
+ rf(i,j)=rf(i-1,j)+mu*dt+sigma*dW(i);
+ end;
+ end;
+ disp(['Coefficient', 'Value';...
+ 'Drift', string(mu);...
+ 'Diffusion', string(sigma)]);
+ case 'vasicek' then
+ X=[ones(size(r,1)-1,1),r(1:$-1)];
+ bhat=(X'*X)^(-1)*X'*r(2:$);
+ a=(1-bhat(2))/dt;
+ b=bhat(1)/(1-bhat(2));
+ sigma=sqrt(mvvacov(diff(r))/dt);
+ rf=r0*ones(1,n);
+ for j=1:n
+ dW=rand(T/dt,1,'normal')*sqrt(dt);
+ for i=2:T/dt
+ rf(i,j)=rf(i-1,j)+a*(b-rf(i-1,j))*dt+sigma*dW(i);
+ end;
+ end;
+ disp(['Coefficient', 'Value';...
+ 'Mean reversion', string(a);...
+ 'Mean', string(b);...
+ 'Diffusion', string(sigma)]);
+ case 'cir' then
+ sigma=sqrt(mvvacov(diff(2*sqrt(r)))/dt);
+ X=[2*sqrt(r(1:$-1)),(2*sqrt(r(1:$-1))).^(-1)];
+ bhat=(X'*X)^(-1)*X'*(2*sqrt(r(2:$)));
+ a=2*(1-bhat(1))/dt;
+ b=(bhat(2)+sigma^2*dt/2)/(4*(1-bhat(1)));
+ rf=r0*ones(1,n);
+ for j=1:n
+ dW=rand(T/dt,1,'normal')*sqrt(dt);
+ for i=2:T/dt
+ rf(i,j)=rf(i-1,j)+a*(b-rf(i-1,j))*dt+sigma*sqrt(rf(i-1,j))*dW(i);
+ end;
+ end;
+ disp(['Coefficient', 'Value';...
+ 'Mean reversion', string(a);...
+ 'Mean', string(b);...
+ 'Diffusion coeff.', string(sigma)]);
+ end
+ plot([1:size(rf,1)]'*dt,rf);
+ title('Simulated interest rates');
+endfunction
diff --git a/macros/irs.bin b/macros/irs.bin
new file mode 100644
index 0000000..aa4c7ae
Binary files /dev/null and b/macros/irs.bin differ
diff --git a/macros/irs.sci b/macros/irs.sci
new file mode 100644
index 0000000..b688710
--- /dev/null
+++ b/macros/irs.sci
@@ -0,0 +1,45 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [spread,leg]=irs(time,months,r,setting);
+
+// PURPOSE: Compute both the spread for a fix-for-floating
+// Interest Rate Swap and the value of the legs
+//
+//--------------------------------------------------------------
+// INPUT:
+// * time = subscribing date in the form
+// [year month day]
+// * months = number of months for each period
+// * r = curve of relevant
+// spot interest rates (column vector)
+// * setting = must be "0" (zero) for "in advance" swap
+// and "1" for "in arrears" swap
+// -------------------------------------------------------------
+// OUTPUT:
+// * spread = is the fix amount that
+// must be paid at each perdio
+// * leg = is the value of both legs of the swap
+// -------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ Y(1)=time(1); M(1)=time(2);
+ for i=2:max(size(r))+1
+ if M(i-1)+months>12 then
+ M(i)=modulo(M(i-1)+months,12);
+ Y(i)=Y(i-1)+1;
+ else
+ M(i)=M(i-1)+months;
+ Y(i)=Y(i-1);
+ end
+ end
+ t=datenum(Y,M,time(3)*ones(M));
+ g=diff(t)/360;
+ gg=cumsum(g);
+ B=[1; (1+r.*gg).^(-1)];
+ f=(B(1:$-1)./B(2:$)-1)./g;
+ leg=sum(f(1+setting:$).*B(2:$-setting).*g(1:$-setting));
+ spread=leg/sum(B(2:$-setting).*g(1:$-setting));
+endfunction
diff --git a/macros/lib b/macros/lib
new file mode 100644
index 0000000..ae95965
Binary files /dev/null and b/macros/lib differ
diff --git a/macros/markowitz.bin b/macros/markowitz.bin
new file mode 100644
index 0000000..0edc685
Binary files /dev/null and b/macros/markowitz.bin differ
diff --git a/macros/markowitz.sci b/macros/markowitz.sci
new file mode 100644
index 0000000..bf8a77a
--- /dev/null
+++ b/macros/markowitz.sci
@@ -0,0 +1,107 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [portf,varoptim]=markowitz(price,ER,r,dt);
+
+// PURPOSE: Compute the optimal portfolio in the Markowitz
+// framework with and without riskless interest
+// rate, with and without short selling
+// Finally, the mean-variance frontier is drawn
+//--------------------------------------------------------------
+// INPUT:
+// * price = matrix whose columns contain the historical
+// prices of each asset
+// * ER = expected (annual) portfolio return
+// * r = riskless (annual) interest rate
+// * dt = data frequencty (e.g. dt=1 for annual data,
+// dt=1/4 for quarter data, and so on...)
+// -------------------------------------------------------------
+// OUTPUT:
+// * portf = matrix of the optimal portfolio composition
+// first raw : with short selling and with r
+// second raw : with short selling and without r
+// third raw : without short selling and with r
+// fourth raw : without short selling and without r
+// -------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+//
+// Compute variances, covariances, and means
+//
+dlnprice=diff(log(price),1,1);
+Q=mvvacov(dlnprice)/dt;
+mu=mean(dlnprice,1)'/dt+1/2*diag(Q);
+//
+// Define vectors p and xi
+//
+p=zeros(size(price,2),1);
+xi=zeros(size(price,2),1);
+//
+// Compute optimal unconstrained portfolio and variance
+//
+ww=qld(2*Q,p,(mu'-r),(ER-r),[],[],1);
+varw=ww'*Q*ww;
+wrw=qld(2*Q,p,[mu';ones(size(price,2),1)'],[ER;1],[],[],2);
+varrw=wrw'*Q*wrw;
+portf=[ww,wrw];
+varoptim=[varw,varrw];
+//
+// Compute optimal constrained portfolio and variance
+//
+if ER>min(mu) & ER<max(mu) then
+ w=qld(2*Q,p,(mu'-r),(ER-r),xi,[],1);
+ var=w'*Q*w;
+ wr=qld(2*Q,p,[mu';ones(size(price,2),1)'],[ER;1],xi,[],2);
+ varr=wr'*Q*wr;
+ portf=[ww,wrw,w,wr];
+ varoptim=[varw,varrw,var,varr];
+else
+ portf(:,3)=%nan;
+ portf(:,4)=%nan;
+ varoptim(:,3)=%nan;
+ varoptim(:,4)=%nan;
+end
+
+frontier=input('Draw frontiers? (y/n) ','string');
+disp([' with short selling',' without short selling']);
+disp([' with r',' without r',' with r',' without r']);
+if frontier=='y' then
+ xtitle('Mean-Std frontier','Standard Deviation','Mean return');
+ //
+ // Define coordinates
+ //
+ ordi=max(0,min(mu));
+ ords=max(mu);
+ ord=[ordi:(ords-ordi)/100:ords];
+ //
+ // Compute and draw unconstrained frontiers
+ //
+ for i=1:size(ord,2)
+ ww=qld(2*Q,p,(mu'-r),(ord(i)-r),[],[],1);
+ xw(i)=ww'*Q*ww;
+ wrw=qld(2*Q,p,[mu';ones(size(price,2),1)'],[ord(i);1],[],[],2);
+ xrw(i)=wrw'*Q*wrw;
+ end
+ plot(sqrt(xw),ord,'--black');
+ plot(sqrt(xrw),ord,'black');
+ if ER>min(mu) & ER<max(mu) then
+ //
+ // Compute and draw constrained frontiers
+ //
+ for i=1:size(ord,2)
+ w=qld(2*Q,p,(mu'-r),(ord(i)-r),xi,[],1);
+ x(i)=w'*Q*w;
+ wr=qld(2*Q,p,[mu';ones(size(price,2),1)'],[ord(i);1],xi,[],2);
+ xr(i)=wr'*Q*wr;
+ end
+ plot(sqrt(x),ord,'--red');
+ plot(sqrt(xr),ord,'red');
+ legend(['With r - with short selling','Without r - with short selling','With r - without short selling','Without r - without short selling'],2)
+ else
+ legend(['With r - with short selling','Without r - with short selling'],2)
+ end
+ else
+end
+endfunction
diff --git a/macros/mef.bin b/macros/mef.bin
new file mode 100644
index 0000000..5dd95b5
Binary files /dev/null and b/macros/mef.bin differ
diff --git a/macros/mef.sci b/macros/mef.sci
new file mode 100644
index 0000000..0cd84dc
--- /dev/null
+++ b/macros/mef.sci
@@ -0,0 +1,27 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [E]=mef(x);
+
+// PURPOSE: Draw the "Mean Excess Function"
+//------------------------------------------------------------------
+// INPUT:
+// * x = column vector of historical returns on an asset
+// -----------------------------------------------------------------
+// OUTPUT:
+// * E = values of the Mean Excess Function for any possible
+// threshold (i.e. alternatively taking any historical
+// retur as a threshold)
+//
+// Finally the Mean Excess Function is plotted
+// -----------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ xo=gsort(x,'r','i');
+ for i=1:size(x,1)-1
+ E(i)=mean(xo(i+1:$)-xo(i));
+ end
+ plot(xo(1:$-1),E,'.');
+endfunction
diff --git a/macros/movav.bin b/macros/movav.bin
new file mode 100644
index 0000000..28b12ef
Binary files /dev/null and b/macros/movav.bin differ
diff --git a/macros/movav.sci b/macros/movav.sci
new file mode 100644
index 0000000..72e44b5
--- /dev/null
+++ b/macros/movav.sci
@@ -0,0 +1,28 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [M]=movav(S,varargin);
+
+// PURPOSE: Compute the moving avarages of a time series
+//---------------------------------------------------------
+// INPUT:
+// * S = historical data (column vector)
+// * varargin = the lenght of the moving avarages
+// -------------------------------------------------------------
+// OUTPUT:
+// * M = matrix containing, in any column, the moving
+// average of the historical data
+// -------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ for i=1:size(varargin)
+ m=varargin(i);
+ for k=size(S,1):-1:m
+ M(k,i)=mean(S(k-m+1:k));
+ end
+ M(1:m-1,i)=%nan;
+ end
+ plot([S M]);
+endfunction
diff --git a/macros/names b/macros/names
new file mode 100644
index 0000000..7d1d031
--- /dev/null
+++ b/macros/names
@@ -0,0 +1,22 @@
+esvaroptim
+movav
+markowitz
+nelson_siegel
+duration
+esvarlin
+bollinger
+euler
+hedge
+cfr
+svennson
+mef
+hurst
+gbm
+bsgreeks
+backtest
+esvarevt
+evt
+bsoption
+interest
+irs
+bsimpvol
diff --git a/macros/nelson_siegel.bin b/macros/nelson_siegel.bin
new file mode 100644
index 0000000..f348afc
Binary files /dev/null and b/macros/nelson_siegel.bin differ
diff --git a/macros/nelson_siegel.sci b/macros/nelson_siegel.sci
new file mode 100644
index 0000000..7d09dcc
--- /dev/null
+++ b/macros/nelson_siegel.sci
@@ -0,0 +1,56 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [uopt,rf]=nelson_siegel(t,r,u0,varargin);
+
+// PURPOSE: Estimate the parameters u1, u2, u3, u4
+// for the Nelson Siegel model f(t) of spot
+// interest rates (least square method)
+//
+// f(t)=u1+(u2+u3)*u4/t*(1-e^(-t/u4))-u4*e^(-t/u4)
+//
+// Finally draw the actual spot rate curve and the
+// interporalted curve
+//--------------------------------------------------------------
+// INPUT:
+// * t = spot rate maturities (column vector)
+// * r = spot interest rates (column vector)
+// * u0 = initial values of the parameters (vector 4x1)
+// * tf = optional input: the dates for which spot rates
+// must be foreseen (column vector)
+// -------------------------------------------------------------
+// OUTPUT:
+// * uopt = optimal values of the parameters u1, u2, u3, u4
+// (vector 4x1)
+// * rf = optional output: foreseen values of spot rates
+// -------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ function rh=rhat(u,t);
+ rh=u(1)+(u(2)+u(3))*u(4)*(1-exp(-t/u(4)))./t...
+ -u(3)*exp(-t/u(4));
+ endfunction
+
+ function D=Diff(u);
+ D=rhat(u,t)-r;
+ endfunction
+
+ [f,uopt,gopt]=leastsq(Diff,u0);
+ disp('Gradient');
+ disp(gopt);
+ disp('Objective function');
+ disp(f);
+ r_estim=rhat(uopt,t)
+ plot(t,r);
+ plot(t,r_estim,'red');
+ if size(varargin)<>0 then
+ tf=varargin(1);
+ rf=rhat(uopt,tf);
+ plot([t($);tf],[r_estim($);rf],'green');
+ legend(['Actual values','Estimated values','Foreseen values'],4);
+ else
+ legend(['Actual values','Estimated values'],4);
+ end
+endfunction
diff --git a/macros/svennson.bin b/macros/svennson.bin
new file mode 100644
index 0000000..9d2bddb
Binary files /dev/null and b/macros/svennson.bin differ
diff --git a/macros/svennson.sci b/macros/svennson.sci
new file mode 100644
index 0000000..74907bf
--- /dev/null
+++ b/macros/svennson.sci
@@ -0,0 +1,57 @@
+// Copyright (C) 2009 - 2010 - Francesco Menoncin
+//
+// This file must be used under the terms of the GPL (3.0):
+// http://gplv3.fsf.org/
+
+function [uopt,rf]=svennson(t,r,u0,varargin);
+
+// PURPOSE: Estimate the parameters u1, u2, u3, u4, u5, u6
+// for the Svennson model f(t) of spot
+// interest rates (least square method)
+//
+// f(t)=u1+u4*u6/t+(u2+u3)*u5/t*(1-e^(-t/u5))
+// -(u6/t-1)*u4*e^(-t/u6)-u3*e^(-t/u5)
+//
+// Finally draw the actual spot rate curve and the
+// interporalted curve
+//--------------------------------------------------------------
+// INPUT:
+// * t = spot rate maturities (column vector)
+// * r = spot interest rates (column vector)
+// * u0 = initial values of the parameters (vector 6x1)
+// * tf = optional input: the dates for which spot rates
+// must be foreseen (column vector)
+// -------------------------------------------------------------
+// OUTPUT:
+// * uopt = optimal values of the parameters
+// u1, u2, u3, u4, u5, u6 (vector 6x1)
+// * rf = optional output: foreseen values of spot rates
+// -------------------------------------------------------------
+// Francesco Menoncin (2010)
+
+ function rh=rhat(u,t);
+ rh=u(1)+u(4)*u(6)*t.^(-1)+(u(2)+u(3))*u(5)*(1-exp(-t/u(5)))./t...
+ -u(4)*(u(6)*t.^(-1)-1).*exp(-t/u(6))-u(3)*exp(-t/u(5));
+ endfunction
+
+ function D=Diff(u);
+ D=rhat(u,t)-r;
+ endfunction
+
+ [f,uopt,gopt]=leastsq(Diff,u0);
+ disp('Gradient');
+ disp(gopt);
+ disp('Objective function');
+ disp(f);
+ r_estim=rhat(uopt,t)
+ plot(t,r);
+ plot(t,r_estim,'red');
+ if size(varargin)<>0 then
+ tf=varargin(1);
+ rf=rhat(uopt,tf);
+ plot([t($);tf],[r_estim($);rf],'green');
+ legend(['Actual values','Estimated values','Foreseen values'],4);
+ else
+ legend(['Actual values','Estimated values'],4);
+ end
+endfunction
diff --git a/readme.txt b/readme.txt
new file mode 100644
index 0000000..020fb24
--- /dev/null
+++ b/readme.txt
@@ -0,0 +1,73 @@
+Financial toolbox
+
+Purpose
+-------
+
+The module is dedicated to finance. There are three main areas that are covered:
+
+ * risk measure and management,
+ * asset allocation,
+ * pricing.
+
+For what concerns the risk measure, some functions are dedicated to the computation of Value at Risk (VaR) and Expected Shortfall (ES). Backtest is also implemented in order to check the goodness of such risk measures. Both VaR and ES are also computed in an Extreme Value Theory framework (EVT). Furthermore, it is possible to estimate the parameters of the EVT density function (through maximum likelihood). The Mean Excess Function for graphical study of an EVT distribution is also implemented.
+The interest rate risk is faced by functions aimed at computing duration, convexity, and yield to maturity. Furthermore, Merton, Vasicek and Cox, Ingersoll and Ross interest rate models are implemented together with the estimation of their parameters. Parametric interpolation of the interest rate curve is possible through both Svennson’s and Nelson-Siegel’s models.
+Finally, some technical analysis indicators are implemented: Bollinger bands, moving averages, Hurst index.
+
+The asset allocation problem is faced by two functions which compute:
+
+ * the optimal portfolio minimizing the variance of its return and
+ * the optimal portfolio minimizing the expected shortfall of its return.
+In both cases, the portfolios with and without a riskless asset and with and without short selling are computed.
+
+
+Pricing problem is approached through functions aimed at:
+
+ * computing the spread on Interest Rate Swaps,
+ * computing the value of options in the Black and Scholes framework (with Greeks and implied volatility),
+ * simulating stochastic processes (through Euler discretization).
+
+Features
+--------
+
+ * backtest : Apply the backtest to Expected Shortfall, Value at Risk and a Linear Spectral risk measure.
+ * bollinger : Plots the historical prices, the Bollinger bands, and the b-percentage.
+ * bsgreeks : Compute the Greeks for Black and Scholes put and call options.
+ * bsimpvol : Compute the implied volatility in a Black and Scholes framework.
+ * bsoption : Compute the value of both a call and a put option in a Black and Scholes framework.
+ * cfr : Compare and merge two or more time series according to dates.
+ * duration : Compute both duration and convexity of cash flows by using the yield-to-maturity.
+ * esvarevt : Compute both Expected Shortfall and Value at Risk.
+ * esvarlin : Compute Expected Shortfall, Value at Risk and a Linear Spectral risk measure on a set of assets.
+ * esvaroptim : Compute the optimal portfolio minimizing the Expected Shortfall.
+ * euler : Simulate the solution of a system of stochastic differential equation.
+ * evt : Estimate the parameters of the Generalized Pareto Distribution.
+ * gbm : Estimate the parameters of a Geometric Brownian Motion.
+ * hedge : Compute the hedge ratio between an asset and a derivative on that asset.
+ * hurst : Compute the Hurst index on historical prices.
+ * interest : Estimate the parameters of three spot interest rate models (Merton - Vasicek - CIR).
+ * irs : Compute both the spread and the value of the legs of a fix-for-floating Interest Rate Swap.
+ * markowitz : Compute the optimal portfolio minimizing the variance.
+ * mef : Compute and draw the Mean Excess Function.
+ * movav : Compute and draw the moving average of a given time series.
+ * nelson_siegel : Estimate the parameters for the Nelson Siegel model of spot interest rates.
+ * svennson : Estimate the parameters for the Svennson model of spot interest rates.
+
+TODO
+----
+ * Rename functions into "finance_*".
+ * Shorten description of functions.
+ * The help page of the svennson function is not properly formatted.
+ * Create unit tests.
+
+Authors
+------
+
+2009-2010 - Francesco Menoncin
+2010 - DIGITEO - Michaël Baudin
+
+Licence
+-------
+
+This toolbox is distributed under the GPL (3.0).
+
+
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/scilab-financial.git
More information about the debian-science-commits
mailing list