[R] writing function help

casperyc casperyc at hotmail.co.uk
Sat Apr 10 22:32:00 CEST 2010


Hi,

I have written a function,
( or 2 functions)
becasue there are only tiny difference,

One of them has lines
==========================
#c2 (price.mat) call option price
c2=c(
max(S.mat[1,3]-K,0),
max(S.mat[2,3]-K,0),
max(S.mat[3,3]-K,0)
)

(some lines)

list(
"Stock Value"=round(S.mat,dp),
"Call Price"=round(price.mat,dp),
"Phi"=round(phi.mat,dp),
"Psi"=round(psi.mat,dp)
)
===========================

and the other one is

==========================
#c2 (price.mat) put option price
c2=c(
max(K-S.mat[1,3],0), <---------difference
max(K-S.mat[2,3],0), <---------difference
max(K-S.mat[3,3],0)  <---------difference
)

(some lines)

list(
"Stock Value"=round(S.mat,dp),
"Put Price"=round(price.mat,dp),  <---------"label" difference
"Phi"=round(phi.mat,dp),
"Psi"=round(psi.mat,dp)
)
===========================

Can I combine them into one function?
just by adding a 'dummy variable' say 'type' 
which takes "call"/"put" or values 1,2

The full codes are in attachment.

Thanks!


http://n4.nabble.com/file/n1835638/mycall.r mycall.r 

http://n4.nabble.com/file/n1835638/myput.r myput.r 

casper

-- 
View this message in context: http://n4.nabble.com/writing-function-help-tp1835638p1835638.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list