_candy
(~..candy..~)
7 يناير 2011، 8:36ص
41
AhmedEldeep:
فى هذا السؤال والذى قبله لا تستخدمى دوال جاهزة فى الماتلاب ادخلى المعادلة كما موجودة فى الاسئلة وقومى بتعريف المتغيرات
كذلك مطلوب فى الجزء a دالة خاصة Write a user defined function وانتى لم تقومى بتعريف دالة خاصة فى حلك
Write an equation that takes S, K, T, r, σ, and the number of iterations
يعنى لا تستخدمى الدوال الجاهزة فى الماتلاب
طيب يامهندس على اي اساس اعرف الداله الخاصه انا كتبت المعادلات الموجوده في المسأله بس قبلها طلبت من المستخدم يدخل البيانات وكلها اعداد input فايش هيا المتغيرات المفروض اعرفها
1-بداية المسأله اطلب من المستخدم المتغيرات المفروض تكون input
2- اكتب المعادلات المعطاه في المسأله
اذا مااستخدمت الدوال الجاهزه في الماتلاب كيف اتصرف في الحل
اعذرنا على التأخر في الرد بسبب ظروف الاختبارات
مشكوور يامهندس
طيب يامهندس على اي اساس اعرف الداله الخاصه انا كتبت المعادلات الموجوده في المسأله بس قبلها طلبت من المستخدم يدخل البيانات وكلها اعداد input فايش هيا المتغيرات المفروض اعرفها
1-بداية المسأله اطلب من المستخدم المتغيرات المفروض تكون input
2- اكتب المعادلات المعطاه في المسأله
اذا مااستخدمت الدوال الجاهزه في الماتلاب كيف اتصرف في الحل
اعذرنا على التأخر في الرد بسبب ظروف الاختبارات
مشكوور يامهندس
مرفق فى كل سؤال المعادلة
تقومى باخد قيم المتغيرات من المستخدم وادخالها فى المعادلة وايجاد الناتج
_candy
(~..candy..~)
7 يناير 2011، 9:54ص
43
fprintf('Please enter the current stock price
')
s=input('s= ')
fprintf('Please enter the exercise price at time
')
k=input('k= ')
fprintf('Please enter the time until option can be exercised
')
t=input('t= ')
fprintf('Please enter the risk free rate of interest
')
r=input('r= ')
fprintf('Please enter the stock volatiiity
')
v=input('v= ')
fprintf('Please enter the yelid
')
y=input('y= ')
d1=(log(s/k)+(r+(v^2)/2)*t)/v*sqrt(t);
d2=d1-v*sqrt(t);
c=s*y*d1-k*exp(-r*t)*y*d2
%or use [Call,]= blsprice(s, k, t, r, v, y)
هل كذا حل فقره a من اكسرسايز 5 السؤال الاول صح
والحل حق فقره b من نفس السؤالاغيره ولا لأ ؟؟
_candy
(~..candy..~)
7 يناير 2011، 9:57ص
44
[FONT=Courier New][SIZE=2]
[SIZE=2][FONT=Courier New]s=100;[/font][/size]
[SIZE=2][FONT=Courier New]k=100;[/font][/size]
[SIZE=2][FONT=Courier New]r=0.1;[/font][/size]
[SIZE=2][FONT=Courier New]v=0.3;[/font][/size]
[SIZE=2][FONT=Courier New]y=r;[/font][/size]
[SIZE=2][FONT=Courier New][Call, Put]= blsprice(s, k, t, r, v, y)[/font][/size]
[/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]for[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] T=0:0.1:1[/color][/size][/font]
[SIZE=2][FONT=Courier New]plot(T,Call,[/font][/size][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'or'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]), grid [/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]on[/color][/size][/font]
[/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]end[/color][/size][/font]
[/color][/size][/font][/color][/size][/font]
حل فقره b
_candy
(~..candy..~)
7 يناير 2011، 10:00ص
45
الرسمه اللي طلعتلي في المرفقات هل هي صحيحه
fprintf('Please enter the current stock price
')
s=input('s= ')
fprintf('Please enter the exercise price at time
')
k=input('k= ')
fprintf('Please enter the time until option can be exercised
')
t=input('t= ')
fprintf('Please enter the risk free rate of interest
')
r=input('r= ')
fprintf('Please enter the stock volatiiity
')
v=input('v= ')
fprintf('Please enter the yelid
')
y=input('y= ')
d1=(log(s/k)+(r+(v^2)/2)*t)/v*sqrt(t);
d2=d1-v*sqrt(t);
c=s*y*d1-k*exp(-r*t)*y*d2
%or use [Call,]= blsprice(s, k, t, r, v, y)
هل كذا حل فقره a من اكسرسايز 5 السؤال الاول صح
والحل حق فقره b من نفس السؤالاغيره ولا لأ ؟؟
هنا قيمتى بايجاد d1 و d2 ولايجاد c انا لا اعلم لماذا قمتى بعملها كالاتى :
c=s*y*d1-k*exp(-r*t)*y*d2
فى السؤال مطلوب
standard normal cumulative distribution function
وهذا له معادلة
[FONT=Courier New][SIZE=2]
[SIZE=2][FONT=Courier New]s=100;[/font][/size]
[SIZE=2][FONT=Courier New]k=100;[/font][/size]
[SIZE=2][FONT=Courier New]r=0.1;[/font][/size]
[SIZE=2][FONT=Courier New]v=0.3;[/font][/size]
[SIZE=2][FONT=Courier New]y=r;[/font][/size]
[SIZE=2][FONT=Courier New][Call, Put]= blsprice(s, k, t, r, v, y)[/font][/size]
[/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]for[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] T=0:0.1:1[/color][/size][/font]
[SIZE=2][FONT=Courier New]plot(T,Call,[/font][/size][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'or'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]), grid [/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]on[/color][/size][/font]
[/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]end[/color][/size][/font]
[/color][/size][/font][/color][/size][/font]
حل فقره b
لا تستخدمى هذه الدالة
blsprice
_candy
(~..candy..~)
7 يناير 2011، 10:41ص
49
[FONT=Courier New][SIZE=2][COLOR=#228b22][FONT=Courier New][SIZE=2][COLOR=#228b22][FONT=Courier New][SIZE=2][COLOR=#228b22]
%1(a):
[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]fprintf([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'Please enter the current stock price
'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
s=input([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'s= '[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
fprintf([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'Please enter the exercise price at time
'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
k=input([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'k= '[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
fprintf([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'Please enter the time until option can be exercised
'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
t=input([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'t= '[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
fprintf([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'Please enter the risk free rate of interest
'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
r=input([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'r= '[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
fprintf([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'Please enter the stock volatiiity
'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
v=input([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'v= '[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
fprintf([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'Please enter the yelid
'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
y=input([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'y= '[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
d1=(log(s/k)+(r+(v^2)/2)*t)/v*sqrt(t);
d2=d1-v*sqrt(t);
c=s*(1/sqrt(2*pi)*exp((-1/2)*d1.^2))-k*(exp(-r*t))*(1/sqrt(2*pi)*exp(-1/2*d2.^2))
[/size][/font][/size][/font]
عدلت حل فقره a
فقره b ارجع اكتب المعادلات ولأ احذف جزئية الداله اللي جبتها من الهيلب
_candy
(~..candy..~)
7 يناير 2011، 10:42ص
50
بالنسبه للرسمه رفعت على المركز بس مو راضي يزبط يكتبلي هذي العباره
غير مسموح برفع هذا النوع من الملفات
نوع الملف الذي اخترته : fig
[FONT=Courier New][SIZE=2][COLOR=#228b22][FONT=Courier New][SIZE=2][COLOR=#228b22][FONT=Courier New][SIZE=2][COLOR=#228b22]
%1(a):
[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]fprintf([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'Please enter the current stock price
'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
s=input([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'s= '[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
fprintf([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'Please enter the exercise price at time
'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
k=input([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'k= '[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
fprintf([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'Please enter the time until option can be exercised
'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
t=input([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'t= '[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
fprintf([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'Please enter the risk free rate of interest
'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
r=input([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'r= '[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
fprintf([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'Please enter the stock volatiiity
'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
v=input([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'v= '[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
fprintf([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'Please enter the yelid
'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
y=input([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'y= '[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
d1=(log(s/k)+(r+(v^2)/2)*t)/v*sqrt(t);
d2=d1-v*sqrt(t);
c=s*(1/sqrt(2*pi)*exp((-1/2)*d1.^2))-k*(exp(-r*t))*(1/sqrt(2*pi)*exp(-1/2*d2.^2))
[/size][/font][/size][/font]
عدلت حل فقره a
فقره b ارجع اكتب المعادلات ولأ احذف جزئية الداله اللي جبتها من الهيلب
والان يجب عليك عملها فى صورة دالة كما ذكرت لك سابقا
_candy
(~..candy..~)
7 يناير 2011، 11:18ص
52
والله مني فاهمه كيف اسوي منها داله
اية داله ؟؟
_candy
(~..candy..~)
7 يناير 2011، 12:39م
54
[FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]
function[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000][c]=funname(s,k,t,r,v,y)[/color]
fprintf([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'Please enter the current stock price
'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
s=input([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'s= '[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
fprintf([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'Please enter the exercise price at time
'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
k=input([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'k= '[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
fprintf([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'Please enter the time until option can be exercised
'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
t=input([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'t= '[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
fprintf([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'Please enter the risk free rate of interest
'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
r=input([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'r= '[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
fprintf([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'Please enter the stock volatiiity
'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
v=input([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'v= '[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
fprintf([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'Please enter the yelid
'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
y=input([/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'y= '[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])
d1=(log(s/k)+(r+(v^2)/2)*t)/v*sqrt(t);
d2=d1-v*sqrt(t);
c=s*(1/sqrt(2*pi)*exp((-1/2)*d1.^2))-k*(exp(-r*t))*(1/sqrt(2*pi)*exp(-1/2*d2.^2))
[/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#228b22][FONT=Courier New][SIZE=2][COLOR=#228b22][FONT=Courier New][SIZE=2][COLOR=#228b22]%(b):
[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]s=100;
k=100;
r=0.1;
v=0.3;
y=r;
[/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]for[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] T=0:0.1:1[/color]
plot(T,c,[/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'or'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]), grid [/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]on
[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]end
[/color][/size][/font][/color][/size][/font][/color][/size][/font]
كذا صح للفقرتين والرسمه تطلع دائره صغيره في النص
عند عمل دالة لا داعى لوضع الاتى
fprintf('Please enter the current stock price
')
s=input('s= ')
fprintf('Please enter the exercise price at time
')
k=input('k= ')
fprintf('Please enter the time until option can be exercised
')
t=input('t= ')
fprintf('Please enter the risk free rate of interest
')
r=input('r= ')
fprintf('Please enter the stock volatiiity
')
v=input('v= ')
fprintf('Please enter the yelid
')
y=input('y= ' )
_candy
(~..candy..~)
7 يناير 2011، 1:59م
56
[FONT=Courier New][SIZE=2][COLOR=#228b22][FONT=Courier New][SIZE=2][COLOR=#228b22][FONT=Courier New][SIZE=2][COLOR=#228b22]
%1(a):
[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]syms [/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]s[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2],k,t,r,v,y
[/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]function[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000][c]=funname(s,k,t,r,v,y)[/color]
d1=(log(s/k)+(r+(v^2)/2)*t)/v*sqrt(t);
d2=d1-v*sqrt(t);
c=s*(1/sqrt(2*pi)*exp((-1/2)*d1.^2))-k*(exp(-r*t))*(1/sqrt(2*pi)*exp(-1/2*d2.^2))
[/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#228b22][FONT=Courier New][SIZE=2][COLOR=#228b22][FONT=Courier New][SIZE=2][COLOR=#228b22]%(b):
[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]s=100;
k=100;
r=0.1;
v=0.3;
y=r;
[/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]for[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] T=0:0.1:1[/color]
plot(T,c,[/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]'or'[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]), grid [/size][/font][/size][/font][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0][FONT=Courier New][SIZE=2][COLOR=#a020f0]on
[/color][/size][/font][/color][/size][/font][/color][/size][/font][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]end
[/color][/size][/font][/color][/size][/font][/color][/size][/font]
عدلت الامر بس يطلعلي error
شوفى عمل الدالة فى الماتلاب بيكون عن طريق استخدام الامر function
مع تحديد المدخلات والمخرجات
وبعد عمل الدالة فى ملف خاص بها وحفظها
يتم تنفيذها من خلال ال command window او من خلال برنامج أخر
فى الملف المرفق الدالة فى صورة m file قومى بوضعها فى current directory
ثم قومى بتنفيذ الامر الاتى فى ال Command window
>> my_Black_Scholes (100,100,.1,0.1,0.3)
فانتى الان قمتى بتعريف دالة خاصة بك مثل الدوال الموجود فى الماتلاب ويمكنك استخدامها فى البرامج الاخرى
مثل الاتى
hold on
for t=0 : 0.1 : 1
c = my_Black_Scholes (100,100,t,0.1,0.3);
plot(t,c,'or')
end
hold off
grid on
وتكون النتيجة كما يلى
_candy
(~..candy..~)
7 يناير 2011، 2:57م
58
شكرااااااا يامهندس أحمد
بس عندي سؤال لماجيت احفظ الملف عشان اشوف الطريقة اللي قلتلي عليها مسار الحفظ تغير مو المفروض نحفظ في الwork دورت عليها ماحصلتها
_candy
(~..candy..~)
7 يناير 2011، 3:32م
60
فى الملف المرفق الدالة فى صورة m file قومى بوضعها فى current directory
كيف اسوي ؟؟
انا اعرف ال current directory بس كيف يرتبط ال command window وكمان m-file اللي اكتب فيها بقية الاوامر
والله تعبتك معايا اعذرناا