NexusFi: Find Your Edge


Home Menu

 





help with expiration dates for options.


Discussion in TradeStation

Updated
    1. trending_up 774 views
    2. thumb_up 0 thanks given
    3. group 1 followers
    1. forum 0 posts
    2. attach_file 0 attachments




 
Search this Thread

help with expiration dates for options.

  #1 (permalink)
maggtrading
quintana roo, méxico
 
Posts: 84 since Mar 2013
Thanks Given: 222
Thanks Received: 40

regards to everyone.


i have been working on an open source trading platform to create an automated options trading system to place trades based on alerts generated by ts. i have been able to get ts to appropriately calculate some necessary values like the strike prices to be selected but i have had significant problems with the expiration dates that should be printed as text for my automated system to trade.


expiration dates have been hard to get right because of ts's date formats, because there are many different cases and also because there are some exceptions.


if anyone can help me with this code i'm working on or point me to working examples i will be most grateful.



- the first thing to get right would be the exceptions. expiration dates for weekly options are always fridays, but once or twice a year when a market holiday falls on a friday the expiration date is moved to the preceding thursday.

it would be too difficult for me to create two parallel structures, one for thursdays and one for fridays, particularly when there are very few cases when options expiration is moved to a thursday. what i think could work would be to create two inputs for the expiration dates. if the next expiration date was a thursday i would just input that date by hand on input number 1 and ts should use it. if the expiration falls on a friday as usual, i would leave the first input blank, and ts should use the second input which would take 3 values.

so, ¿is this kind of structure possible in ts? ¿can i have a string input that i would just leave blank and in that case ts should ignore it but if it is not blank then it should use that value?


typical expiration on friday.
inputs:
string thuexp(""),
string poscas(a or b or c);


expiration on a thursday.
inputs:
string thuexp("190418"),
string poscas(a or b or c);



- the second aspect i have been having a hard time with is choosing the appropriate expiration date. i would normally want all contracts to be bought for the same week as this keeps risk to a minimum, however, i have realized there could be 3 different cases. a) monday to friday, return the date for the friday of this same week. b) monday to thursday, return the date for the friday of this same week, if it is a friday, return the date of the friday of the next week. c) return the date of the friday of the next week


¿would there be any way to combine the inputs i described above with the script below in ts?


if thuexp is not blank, return or print thuexp.

if thuexp is blank, use the value for poscas to determine the appropriate expiration date.


for case a,

return date for friday of this week in yymmdd format.


for case b,

if dow <= 4,

return date for friday of this week in yymmdd format..

if dow = 5,

return date for the friday of the next week in yymmdd format.


for case c,

return date for the friday of the next week in yymmdd format.



the people with ts support provided some this very sample code below but i haven't been able to get it to work as desired, and i have no idea where i should insert all the conditional cases described above. i have been working on the script below but it would only cover case b.


using elsystem;

inputs:
dowed(5),
edwa(0);


// returns a string in the format yymmdd from a datetime object
method string getnextexpdat(datetime dt)
variables:
int dow,
datetime nextexpdat;
begin

nextexpdat = dt;

dow = dayofweek( nextexpdat.eldate );


if dow = 5 then
nextexpdat.adddays( 7 * edwa )
else
nextexpdat.adddays( 5 - dow );


return nextexpdat.format( "%y%m%d" );

end;

print( getnextexpdat(bardatetime) );



very well, thanks to all, regards.

Reply With Quote




Last Updated on June 9, 2019


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts