|
From: LovingTheCane <tun...@gm...> - 2019-02-18 00:10:52
|
Hi,
I compiled the C++ library with high_resolution_date uncommented and am now
using it to value options intraday. Its quite nice.
The only problem I am coming across is when I am trying to calc theta.
Below is how I would normally calculate it. With .0027777 being a fraction
of a year which is a day. Then adding the fraction to time which is again a
fraction of a year(less than a day) then calculating the delta between those
then multiplied by -1. The only problem im having is when you subtract dates
in the python version it doesnt do fractions of a day. AND when im plugging
in the date to the american option pricing engine obviously those take
ql.Dates.
def get_theta(self, dt = 0.0027777):
self.time += dt
self.get_price_delta()
after_price = self.calc_price
self.time -= dt
self.get_price_delta()
orig_price = self.calc_price
self.theta = (after_price - orig_price) * (-1)
This is how I am currently doing it but am having problems.
def theta(self):
#set calculation date to +1 hour then calculate the price
self.calculation_date =
ql.Date(self.day+1,self.month,self.year,self.hour,self.min,self.sec,self.micro)
self.expiration_date =
ql.Date(self.day1+1,self.month1,self.year1,self.hour1,self.minute1,self.sec1,self.micro1)
self.initialize_pricing_engine(self.calculation_date,
self.expiration_date)
self.get_price_binomial()
after_price = self.american_option.NPV()
#self calc date to -1 hour then calc the price
self.calculation_date =
ql.Date(self.day-1,self.month,self.year,self.hour,self.min,self.sec,self.micro)
self.expiration_date =
ql.Date(self.day1,self.month1,self.year1,self.hour1,self.minute1,self.sec1,self.micro1)
self.initialize_pricing_engine(self.calculation_date,
self.expiration_date)
self.get_price_binomial()
orig_price = self.american_option.NPV()
#calculate theta by taking the price diff * -1
theta = (after_price - orig_price ) * (-1)
return theta
So I have a bunch of variables I get from a string, then save them to
variables. the self.day and so on.
I have a solution but its so wacky that I thought it would be better to post
it here. The only solution I can think of, is to convert the ql.Dates into
fractions of a year in my theta calc then do the calculation the first way I
thought of it above, but that would require I process the fractions back
into dates in the binomial pricing model then get the price.
Is there a timedelta or a way to get an int from subtracting two ql.Dates?
like if i subtract 10am from 1600 it should be 6 hours divided by 22 hours
(the last day session(6pm-4pm) or to get the pricing engine to take
fractions of a year?
--
Sent from: http://quantlib.10058.n7.nabble.com/quantlib-dev-f8818.html
|