# Tag Archives: v # Payoff options chart code for Matlab

Payoff options chart code for Matlab

Here are some code samples

http://www.mathworks.com/matlabcentral/fileexchange/17411-visualize-payoffs-of-an-option-strategy
http://homepages.math.uic.edu/~tier/Finance/hw1s06.pdf

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! # Research paper algo for call or put options to Matlab Mupad converted to clean C or C++ Demo Intro

Research paper  algo for call or put options  to Matlab Mupad converted to clean C or C++ Demo Intro

The following is a working derivative of (done in Matlab 2014a)

All source with MUPAD MN, and C resource files included  options

http://www.mathworks.com/products/symbolic/code-examples.html?file=/products/demos/symbolictlbx/exotic_options/exotic-options-from-symbolic-modeling-to-c-code.html

Other video highlights:

At APPROXIMATELY 21:00,  I show how to convert from Mupad to a custom Matlab M function which can also be implemented into a Simulink model

Matlab M function:

Join my FREE newsletter to see how we proceed with this new workflow

————–

The Mupad Notebook file (RelativeOptionModel.mn) contains:

N:=stats::normalCDF(0,1)

F:=S1/S2*exp((b1 – b2 + sigma2^2 – rho*sigma1*sigma2)*T)

sigmahat:=sqrt(sigma1^2+sigma2^2-2*rho*sigma1*sigma2):

d1:=(ln(F/X)+sigmahat^2*T/2)/(sigmahat*sqrt(T))

d2:=d1-sigmahat*sqrt(T)

Call:=exp(-r*T)*(F*N(d1)-X*N(d2))

Put:=exp(-r*T)*(F*N(d2)-X*N(d1))

S1

S2

S1

———–

Matlab command history:

>> clear all

>> model=’RelativeOptionModel.mn’

model =

RelativeOptionModel.mn

ans =

1

>> getVar(nb,’S1′)

ans =

S1

>> S1=getVar(nb,’S1′)

S1 =

S1

>> Put=getVar(nb,’Put)

Put=getVar(nb,’Put)

|

Error: String is not terminated properly.

>> Put=getVar(nb,’Put’)

Put =

-exp(-T*r)*(X*(erf((2^(1/2)*(log((S1*exp(T*(sigma2^2 – rho*sigma1*sigma2 + b1 – b2)))/(S2*X)) + (T*(sigma1^2 – 2*rho*sigma1*sigma2 + sigma2^2))/2))/(2*T^(1/2)*(sigma1^2 – 2*rho*sigma1*sigma2 + sigma2^2)^(1/2)))/2 + 1/2) + (S1*exp(T*(sigma2^2 – rho*sigma1*sigma2 + b1 – b2))*(erf((2^(1/2)*(T^(1/2)*(sigma1^2 – 2*rho*sigma1*sigma2 + sigma2^2)^(1/2) – (log((S1*exp(T*(sigma2^2 – rho*sigma1*sigma2 + b1 – b2)))/(S2*X)) + (T*(sigma1^2 – 2*rho*sigma1*sigma2 + sigma2^2))/2)/(T^(1/2)*(sigma1^2 – 2*rho*sigma1*sigma2 + sigma2^2)^(1/2))))/2)/2 – 1/2))/S2)

>> Call=getVar(nb,’Call’)

Call =

exp(-T*r)*(X*(erf((2^(1/2)*(T^(1/2)*(sigma1^2 – 2*rho*sigma1*sigma2 + sigma2^2)^(1/2) – (log((S1*exp(T*(sigma2^2 – rho*sigma1*sigma2 + b1 – b2)))/(S2*X)) + (T*(sigma1^2 – 2*rho*sigma1*sigma2 + sigma2^2))/2)/(T^(1/2)*(sigma1^2 – 2*rho*sigma1*sigma2 + sigma2^2)^(1/2))))/2)/2 – 1/2) + (S1*exp(T*(sigma2^2 – rho*sigma1*sigma2 + b1 – b2))*(erf((2^(1/2)*(log((S1*exp(T*(sigma2^2 – rho*sigma1*sigma2 + b1 – b2)))/(S2*X)) + (T*(sigma1^2 – 2*rho*sigma1*sigma2 + sigma2^2))/2))/(2*T^(1/2)*(sigma1^2 – 2*rho*sigma1*sigma2 + sigma2^2)^(1/2)))/2 + 1/2))/S2)

>> call_ROP = matlabFunction(Call,’file’,’Call_ROP.m’);

>> put_ROP = matlabFunction(Call,’file’,’Put_ROP.m’);

—–

Some Code Generation to C (generates yucky MEX file)

>> codegen Call_ROP  -args {0.07,130.00,100.0,1.0,0.3,0.4,0.25,0.5,0.05,0.03}

>> codegen Put_ROP  -args {0.07,130.00,100.0,1.0,0.3,0.4,0.25,0.5,0.05,0.03}

Using ccode

>> ccode(Call,’file’,’CallC’)

Warning: Function “erf” is not verified to be a valid C function.

Warning: Function “erf” is not verified to be a valid C function.

Join my FREE newsletter to see how we proceed with this new workflow

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! # FIll in the shortfalls of Matlab by writing your Microsoft C# DotNet scripts? Makes sense?

FIll in the shortfalls of Matlab by writing your Microsoft C# DotNet scripts? Makes sense?

Here is a very practical guide to fill in the shortcomings of Matlab. Write your Microsoft DotNet C# scripts to get the same performance as commercial products. There are no monthly subscriptions fees either. No fuss no muss.

Makes sense? Let me know your thoughts by commenting below.

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! # 2 videos of Moving Average conversion to C++ and full HFT update! New trading model API!

Hi there

Listed below are 2 new videos for both you and my Members.
We are in the counting days to get your discounted rates for the QuantLabs.net Premium Membership. It goes up 50% this Monday on Jan 14. Do I really need to say anything further about it?
1. Youtube video on moving average algo completed and converted from Matlab to C++
Watch this to see how I do it and why I use Matlab. I even show how you could use it to build algos visually!
2. For Members: Trading platform with Matlab, C++, C#, Interactive Brokers. and IQFeed update video posted for Jan 9 2013
This has been uploaded for my members only. It was a live webinar from a few days ago to showcase the power of all the software I use it to rapidly my custom HFT potential platform. Not only that, you will easily see the power of Matlab in itself.
3. Now creating super C++ API for HFT. Adding moving average, parameter sweeping, lead lag, grid optimization, Sharpe, and more!
This could be the ultimate benefit of my membership once complete with my 15 strategies I plan to implement. It might take a while but when you look at the expensive option of an API like FAME,it makes me wonder why I am adding all this value. I think I need to see a doctor about this.
4. Oh me oh my! It is another quant finance and/or Matlab R user group social Meetup in Toronto Jan 14
You should know the drill by now. Get your current and this year’s only ‘discount’ now as the first installment of price increases happen this Monday on Jan 14! It is 50%!
See you on the other side of the membership
Thanks Bryan