Steps from Mupad to custom Matlab M function
Here are the steps involved to create an M function from a Mupad session:
(This uses calculating the basis used in futures trading of Cash Price – Future Price)
http://www.mathworks.com/help/symbolic/create-matlab-functions-from-mupad-expressions.html
>> notebook_handle = mupad;
>> basis = getVar(notebook_handle,’basis’) <–note: do keep Mupad open in order for this to work!!
basis =
FC – FP
>> h = matlabFunction(S)
Undefined function or variable ‘S’.
>> h = matlabFunction(basis)
h =
@(FC,FP)FC-FP
>> basis = matlabFunction(basis,’file’, ‘basis.m’);
Here is the resulting M function basis.m:
function basis = basis(FC,FP)
%BASIS
% BASIS = BASIS(FC,FP)
% This function was generated by the Symbolic Math Toolbox version 6.2.
% 26-Jul-2015 21:13:44
basis = FC-FP;
Join my FREE newsletter as I apply these tools to my automated algo trading
NOTE I now post my
TRADING ALERTS into my personal
FACEBOOK ACCOUNT and
TWITTER. Don't worry as I don't post stupid cat videos or what I eat!