How

From FinMath

Jump to: navigation, search
This information is provided for contributors interested in the mechanics of this site and in particular, using it to "deploy" versioned code or applications. We have tried to keep it as simple as possible, but this may be more information than many users need. If you don't care about versioning, just edit a page called Code:myModule (say) and enclose code therein with matlab tags like this
<matlab myFunc.m> 
  function  y = myFunc(x)
    % Uses some other function from this site
    fmuse('/someOtherToolbox','someOtherFunction.m');
    y = x.^2 + someOtherFunction(x);
</matlab> 

The code will be swept into the repository from where it can be read and used. The syntax highlighted version on the wiki page might be easier to read however. For all we know, someOtherFunction might call other functions in the repository also but this is fine so long as users have visited quick start and thereby obtained the crucial utility fmuse.m. The function can be used by typing the following at the Matlab prompt

    fmuse('/myModule','myFunc.m');
    myFunc(3.14)

Here is a little more information for those who are interested...

Contents

[edit] Wiki generated code repository

Creation and "deployment" of programs here is transparent:

  • Contributors embed code in pre-format boxes, as in Code examples.
  • Code is extracted parsed from articles as they are edited and made available at [http://www.financialmathematics.com/code].
  • Utility fmuse.m implements remote on-the-fly usage of the repository within Matlab. Simply include a call fmuse('aGreatFunctionContributedBySomeone.m') in your code rather than downloading the requisite file manually. If a function includes a call to fmuse.m, the remote file will be downloaded only if no local copy exists.
  • Code:fin_math#fmuse.m calls Code:fin_math#fmver.m if a local copy of the latter exists in the matlab path, or assumes the default (empty) version string. Therefore by default the remote copy of an mfile obtained by fmuse.m is the latest greatest bang up to date bleeding edge version (i.e. the same as the code on the wiki - unless changes to the wiki contain unacceptable or dangerous keywords).
  • If an only if versioning is required, a local mfile must be created taking a file name as argument and returning a valid version string. For example, see fmver.m below.
  • Run fmuse('-refresh') to force re-download of all remote files in use. You may want to do this after modifying fmver.m, since Code:fin_math#fmuse.m will not clobber local files unless explicitly instructed.

[edit] Deployment

Needless to say, code written here is already deployed. Anyone wishing to use myFunc.m need only include a prior call to fmuse('myFunc.m') in their code, assuming they have performed the ten second install of fmuse.m at Quick start. If this is considered too much trouble for the end user, even this step can be obvated by writing a pithy startup function for end users along the following lines, which also achieves some other objectives.

function myCustomAppStart
  % 
  %  Grant user access to entire FinancialMathematics.Com repository and ensure  
  %  use of latest custom version control file
  %
     fminstall;          % see below
     urlwrite('http://www.myAppHomePage.com/fmver.m',which('fmver.m')); % Clobbers local fmver.m file
     fmuse('-refresh');  % Force re-download of the desired version of remote files from fin_math repository 
 
     function fminstall
     persistent fminstall_done
     if isempty(fminstall_done),
        urlwrite('http://www.financialmathematics.com/code/fin_math/fmgrow.m',fullfile(prefdir,'fin_math','fmgrow.m'));
        addpath(prefdir); 
        fmgrow; 
        fminstall_done=true;
     end

Unfortunately we don't have a mechanism for users to initiate code freezes. However, as periodic code freezes are performed by site administrators, a setup such as this can present your users with successively more stable programs. The only thing which requires updating is a single mfile fmver.m which you maintain yourself.


[edit] Advantages

See why contribute.

[edit] Disadvantages

We combine the disadvantages of a wiki with the disadvantages of the urlpath.m concept. Any reader may flame your work mercilessly, insert snide comments, break your code and otherwise vandalize your creation. The "deployment" of programs faces another issue as (by default) users of your hosted code will run local copies downloaded at different times.

Both methods will allow users to re-download all remote files with a single fmuse or urlpath "refresh" command. Versioning may be somewhat simpler with the latter. An example is presented in Matlab example with proprietary dependency.m.

[edit] See also

Personal tools