Joe Byers
2006-May-22 15:57 UTC
[R] RQuantlib Array processing applying EuropeanOptionExampleArray
I am trying to replicate part of the EuropeanOptionExample using my date. I have a data.frame containing all my inputs atm.vols<-subset(data.vols,moneyness==min); #Some days have the abs(moneyness) exactly between two strike prices, #Traders will alway price an option at the higher vol when selling it, so we will too. atm.vols.max<-data.frame(vol.max=tapply(atm.vols$sigma,INDEX=factor(atm.vols$date),max)); #y<-date.mmddyy(as.numeric(row.names(atm.vols))); #row.names(atm.vols.max)<-date.mmddyy(as.numeric(row.names(atm.vols.max))); atm.work<-merge(atm.vols,atm.vols.max,by.x="date",by.y="row.names",all=TRUE) #ok get only the vols we need atm.work<-subset(atm.work,sigma==vol.max); atm.work is has 749 rows. I try and run the EuropeanOption example using atm.work$For_Price as my array of underlying prices and the other inputs from row 9 of atm.work. i<-9; x<-EuropeanOption(type = "put", underlying = atm.work$For_Price, strike = atm.work$K[i], dividendYield = atm.work$BEY[i], riskFreeRate = atm.work$BEY[i], maturity = atm.work$t_exp[i], volatility = atm.work$sigma[i]) x$parameters has the array of underlying prices but the results is only a single vector using the first row of atm.work$For_Price. Is this because I am pulling the inputs from data.frame not arrays? Any help is greatly appreciated. Thank you Joe
Dirk Eddelbuettel
2006-May-23 02:13 UTC
[R] RQuantlib Array processing applying EuropeanOptionExampleArray
On 22 May 2006 at 10:57, Joe Byers wrote: | I try and run the EuropeanOption example using atm.work$For_Price as my | array of underlying prices and the other inputs from row 9 of atm.work. | i<-9; | x<-EuropeanOption(type = "put", underlying = atm.work$For_Price, strike | = atm.work$K[i], | dividendYield = atm.work$BEY[i], riskFreeRate = | atm.work$BEY[i], maturity = atm.work$t_exp[i], | volatility = atm.work$sigma[i]) | | x$parameters has the array of underlying prices but the results is only | a single vector using the first row of atm.work$For_Price. Is this | because I am pulling the inputs from data.frame not arrays? If I understand correctly what you are trying to do, then there may simply be a misunderstanding on your part. EuropeanOption(), like all but one [ more on that in the next paragraph ] of the other RQuantLib functions, expects _scalars_ for all its inputs. But you seem to expect that it magically vectorises things automatically for you. It doesn't, and that's why you get errors or unexpected results. There is however one convenience function -- mostly as a proof of concept -- which unrolls vectors (or sequences) in any of its arguments. See > help(EuropeanOptionArrays) and > example(EuropeanOptionArrays) where the results are shown in terms of two sequences of values for the underlying and the volatility. As always, there will be many more clever ways for doing this. Suggestions and patches welcome. | Any help is greatly appreciated. Hope this helps. Regards, Dirk -- Hell, there are no rules here - we're trying to accomplish something. -- Thomas A. Edison