Laguna wrote:
Hi Gurus,
I want to find the expiration date of stock options (3rd Friday of the
month) for an any give month and year. I have tried a few tricks with
the functions provided by the built-in module time, but the problem was
that the 9 element tuple need to be populated
Laguna wrote:
Hi Gurus,
I want to find the expiration date of stock options (3rd Friday of the
month) for an any give month and year. I have tried a few tricks with
the functions provided by the built-in module time, but the problem was
that the 9 element tuple need to be populated
import calendar
[y[4] for y in calendar.monthcalendar(2005, 9) if y[4]!=0][2]
16
[y[4] for y in calendar.monthcalendar(2003, 6) if y[4]!=0][2]
20
[y[4] for y in calendar.monthcalendar(2006, 2) if y[4]!=0][2]
17
--
http://mail.python.org/mailman/listinfo/python-list
Laguna wrote:
I want to find the expiration date of stock options (3rd Friday of the
month) for an any give month and year.
From year and month (and day=1) get the day of the week (n in [0,6]) of the
first of the month using some version of the the standard formula (see
below) and look up
Terry Reedy wrote:
Laguna wrote:
I want to find the expiration date of stock options (3rd Friday of the
month) for an any give month and year.
From year and month (and day=1) get the day of the week (n in [0,6]) of the
first of the month using some version of the the standard formula (see
Donn,
You didn't look closely enough at those results. The OP's point was
that he did not know how to set all the tuple values correctly. Here's
a clearer example, I think:
import time
print time.asctime((2005,9,1,0,0,0,0,0,0))
print time.asctime((2005,9,1,0,0,0,1,0,0))
print
Paul Rubin wrote:
Peter Hansen [EMAIL PROTECTED] writes:
(And, if I were optimizing, I would of course dispense with the
dynamic creation of the static table upon every execution of
expiration(), and move it outside the function.)
Replacing it with a tuple might be enough for that.
You're
On Fri, 02 Sep 2005 20:53:44 -0400, Peter Hansen [EMAIL PROTECTED] wrote:
Carsten Haese wrote:
On Fri, 2005-09-02 at 16:46, Laguna wrote:
def expiration(year, month):
weekday = calendar.weekday(year, month, 1)
table = [19, 18, 17, 16, 15, 21, 20]
return table[weekday]
...
True,
Hi Gurus,
I want to find the expiration date of stock options (3rd Friday of the
month) for an any give month and year. I have tried a few tricks with
the functions provided by the built-in module time, but the problem was
that the 9 element tuple need to be populated correctly. Can anyone
help
Laguna [EMAIL PROTECTED] writes:
I want to find the expiration date of stock options (3rd Friday of the
month) for an any give month and year. I have tried a few tricks with
the functions provided by the built-in module time, but the problem was
that the 9 element tuple need to be populated
Laguna wrote:
Hi Gurus,
I want to find the expiration date of stock options (3rd Friday of the
month) for an any give month and year. I have tried a few tricks with
the functions provided by the built-in module time, but the problem was
that the 9 element tuple need to be populated
In article [EMAIL PROTECTED],
Laguna [EMAIL PROTECTED] wrote:
I want to find the expiration date of stock options (3rd Friday of the
month) for an any give month and year. I have tried a few tricks with
the functions provided by the built-in module time, but the problem was
that the 9
What do you mean by, the 9 element tuple need to be populated
correctly? Do you need someone to tell you what values it
needs? What happens if you use (2005, 9, 1, 0, 0, 0, 0, 0, 0),
for example? If you make this tuple with localtime or gmtime,
do you know what the 7th (tm[6]) element of
Paul,
Thanks for the suggestion on calendar module. Here is my solution and
it works:
def expiration(year, month):
weekday = calendar.weekday(year, month, 1)
table = [19, 18, 17, 16, 15, 21, 20]
return table[weekday]
Cheers,
Laguna
--
On Fri, 2005-09-02 at 16:46, Laguna wrote:
Paul,
Thanks for the suggestion on calendar module. Here is my solution and
it works:
def expiration(year, month):
weekday = calendar.weekday(year, month, 1)
table = [19, 18, 17, 16, 15, 21, 20]
return table[weekday]
Thanks for the hint :) I may use your solution if this becomes my
bottleneck!
I try to get away from Perl-ish syntax though.
Best,
L
--
http://mail.python.org/mailman/listinfo/python-list
In article [EMAIL PROTECTED],
Laguna [EMAIL PROTECTED] wrote:
What do you mean by, the 9 element tuple need to be populated
correctly? Do you need someone to tell you what values it
needs? What happens if you use (2005, 9, 1, 0, 0, 0, 0, 0, 0),
for example? If you make this tuple with
Hey Donn,
I don't mean to offend anyone here. I was just saying that the other
solution is better suited for my problem. I truly appreciate your
analysis and suggestions.
BTW, I am not a programmer :( and I like the simplest solution whenever
possible.
Cheers,
L
--
Carsten Haese wrote:
On Fri, 2005-09-02 at 16:46, Laguna wrote:
def expiration(year, month):
weekday = calendar.weekday(year, month, 1)
table = [19, 18, 17, 16, 15, 21, 20]
return table[weekday]
This, of course, can be optimized into
def expiration(year, month):
return
Peter Hansen [EMAIL PROTECTED] writes:
(And, if I were optimizing, I would of course dispense with the
dynamic creation of the static table upon every execution of
expiration(), and move it outside the function.)
Replacing it with a tuple might be enough for that.
--
Peter Hansen wrote:
Carsten Haese wrote:
On Fri, 2005-09-02 at 16:46, Laguna wrote:
def expiration(year, month):
weekday = calendar.weekday(year, month, 1)
table = [19, 18, 17, 16, 15, 21, 20]
return table[weekday]
This, of course, can be optimized into
def
21 matches
Mail list logo