writing a formula in matlab

1 次查看(过去 30 天)
amir khalighi
amir khalighi 2018-4-30
Hello all I have a formula that I want to write it in matlab but I don't know about sigma and Combination,can anyone help me please the formula is
i want to calculate 'C' amount but when it is less or equal with 0 'C=0' and when it is bigger than 0 C amount=the calculated amount all of the amounts (r,u,d,n,St-n,k) are given ('p' should calculate) and if it is possible I want to do it with xlsread for given data and rewrite C amount in the main excel file I don't know i explained it well or not :( thanks for all of your helps
  1 个评论
amir khalighi
amir khalighi 2018-5-2
I wrote this program but it's not working could anyone tell me what's the problem please?

请先登录,再进行评论。

回答(1 个)

Geoff Hayes
Geoff Hayes 2018-4-30
amir - since you have a summation, then consider using a for loop to iterate from 0 to n. See for loops for more details. As for the n choose j, see nchoosek.
  11 个评论
amir khalighi
amir khalighi 2018-5-4
编辑:Geoff Hayes 2018-5-5
maybe for help the code is :
clc;
clear;
r=0.01;
u=0.05;
d=-0.04;
n=4;
j=0;
St=40;
K=25;
p=(r-d)/(u-d)
C=(1/(1+r)^n)*(symsum(nchoosek(n,j)*p^j*(1-p)^(n-j)*max(0,((1+u)^j)*(1+d)^(n-j)*St/K))),j,0,n)
also I made another post HERE
you also can help me there
thank you
Geoff Hayes
Geoff Hayes 2018-5-5
The error message is telling you that there is a problem with the brackets in your line of code - possibly too many. You may want something like
C=(1/(1+r)^n)*symsum(nchoosek(n,j)*p^j*(1-p)^(n-j)*max(0,((1+u)^j)*(1+d)^(n-j)*St/K),j,0,n)
Please verify which are the inputs to your symsum function call.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by