No trading on "DividendPayDate" month

Hi all,

I am trying to figure out how to filter Stocks if their GetFNnData("DividendPayDate") month is the current month. Any ideas?

I suppose by current month you refer last month of price data...

/// @link https://forum.amibroker.com/t/no-trading-on-dividendpaydate-month/8518/2
// Dividend date
divdate = GetFNData("DividendPayDate");
printf( "Dividend date: %s", DateTimeToStr(divdate) );
// Dividend month
divmth = int(DateTimeConvert(0, divdate ) / 100 % 100);
printf( "\nDividend month: %g", divmth );
// Is last month == dividend month?
mth = Month();
is_div_last_mth = LastValue(mth) == divmth;

Filter = is_div_last_mth;
AddColumn( divdate, "Dividend Date", formatDateTime );

For AB versions 6.16+

Version( 6.20); // min. final AB 6.20 version required
/// @link https://forum.amibroker.com/t/no-trading-on-dividendpaydate-month/8518/2
// Dividend Date
divdate = GetFNData("DividendPayDate");
printf( "Dividend date: %s", DateTimeToStr(divdate) );
// Dividend Month
divmth = DateTimeConvert(7, divdate);// 7 - new in AB 6.16+
printf( "\nDividend month: %g", divmth );
// Is last month == Dividend month?
mth = Month();
is_div_last_mth = LastValue(mth) == divmth;

Filter = is_div_last_mth;
AddColumn( divdate, "Dividend Date", formatDateTime );

Hi fxshrat,
Thanks for the quick reply. I am writing call options so I need to filter the current month if the stock is expecting a Dividen. Here is the code I come up with tonight:

DividendPD = GetfnData("DividendPayDate");
FirstOfMonth = DateTimeAdd( DateTime(), Day()-(Day()*2), inDaily );
LastOfMonth = DateTimeAdd(FirstOfMonth, 1, inMonthly);
PayDate = IIF(DividendPD >= FirstOfMonth and DividendPD <= LastOfMonth, False, True);

@mbirrell, That one will not work for every date because of invalid datetime here and there.
This one works

/// Skip dividend month
/// @link https://forum.amibroker.com/t/no-trading-on-dividendpaydate-month/8518/4
div_dn = DateTimeConvert(0, GetFNData("DividendPayDate"));// number
yr_mth = 10000 * (Year() - 1900 ) + 100 * Month();// array
Skip_PayDate_Month = ! (div_dn >= yr_mth + 1 AND div_dn <= yr_mth + 31);// array

BTW, next time be more precisely in first post.
(And why didn't you post code in first post but in 3rd one?)

1 Like

Hi fxshrat, Thanks for your effort in helping me resolve my coding problem. I really appreciate it.