Nightly.exe


The Nightly application is an overnight process.   You should run this program in a scheduled process or manually from the command line.  In either case, you need to attach valid user information to the invocation of the nightly program.  For example, if you were typing in a DOS command shell, you could type:

    Nightly.exe "USER NAME"=admin PASSWORD=mypass

Other parameters for the Nightly include:

print=yes prints the log to the default printer
printOrient=landscape prints the report landscape, otherwise, prints portrait
printPage=legal prints the report on legal paper size, otherwise, prints on letter size

A user may not run afs:TRADE unless Nightly has run for the day before.

Nightly User

If Nightly User is set on the System Defaults form [V2003.02.28]

  • Nightly will not run if the database login name used to run Nightly does not match Nightly user
  • Nightly will not run of the login name is already connected to the database when Nightly is run (this is to prevent Nightly from being run more than once at one time).

Note that it is possible for the DBLIB client (as set in the BDE Administrator) to create multiple connections to the database.  This can cause Nightly to fail even in the login is only used for Nightly.  It is best to set the CDLIB client if the Nightly User feature is used.  See CTLib vs. DBLib for more details.

Historical Database Backup

If your system maintains historical information, the Nightly program will dump a backup copy of the complete database on the first processing day of each month. These backups can be reloaded (on demand) into a parallel database for use by reports. In addition, on a quarterly basis, the Nightly program automatically reloads the parallel database to synchronize it with the online system.

Ticket activity

Tickets are posted on both a trade date and a settlement date basis. Some trades settle same-day and are posted to both sides immediately when the user saves the trade in afs:TRADE. All trades which were executed on a prior day but settle today must be posted before active trading begins.

Procedure: All information concerning average price, yield, etc., is maintained on a trade date basis. Therefore, the overnight procedure simply gathers a list of all trades that settle today with a posting_flag of POST_TD_BASIS. Based on the transaction_type (BOT, SLD, etc), the matching currposn record must be retrieved, and the settle_qty incremented or decremented as appropriate.

Put and variable rate reset

The Nightly program compiles a list of all actively owned securities that change periodically due to put and/or variable rate considerations. As long as you fill in all necessary information up front and keep your benchmark rate tables up to date, the system should roll these values forward without any additional intervention. This stage occurs before position processing, so the new values are compiled into the system averages and cumulations.

Cash Logging (>= V2002.11.8.0)

If the table postlog is in the database, the Nightly will write a record for each cash adjustment made.  These adjustments include settling tickets, coupon payments, maturing positions, cash ticket posting, 

Position reset

The position reset procedure serves two purposes: It removes items that have reached their final maturity dates, and it resets certain information for positions that remain. In addition, it handles closed positions – where both trade_qty and settle_qty reach 0 – because they are not always removed dynamically during the trading day (for reasons that are discussed below).

Procedure: If the system maintains compliance information, the limtotal table is emptied. Then the entire currposn table is retrieved and reviewed, account by account. For each account, the acttotal record is reset and recomputed, according to the following rules:

If the position has matured, it is removed from the currposn table, the remaining quantity in the tckdtl table is written down to 0, and realized lots are discarded.  If the system maintains cash balances, the maturity value (returning principal + interest) is added to the cash balances in the acttotal table.  Note that the value of tckmast.maturity_date determines whether to mature the lots.  If you prefer the value of product.maturity_date be used, you should set ForceProductMaturityDate=1 in the [Nightly] section of the afstrade.ini file.

If the position is not maturing, the price is accreted as necessary (mostly for short term securities) and added to the computed net asset value and average maturity of the portfolio. If the system maintains compliance information, the limtotal table is reposted. For reporting convenience, certain values like yield, duration, and convexity are computed at this point and stored in the prodcalc table.

If the security in question is scheduled to make a coupon payment today, the amount is calculated and a cash transaction is created to cover the inflow. That way, if the system somehow generates a wrong amount (as could happen with adjustable rate securities that have incomplete information) or credits for a day when a payment was not made, you can modify or cancel the cash ticket.

Finally, if both trade_qty and settle_qty are 0, and the last_settle_date is more than 10 days ago (assures positions exist for a few days after they settle) the record may need to be deleted, based on the following rule: If type_indicator = 'L' or 'S', it is safe to delete the record immediately. If type_indicator = 'X', the tckdtl table is queried to see if there are any trades for this desk_code/acct_code/product_id combination where has_remaining_quantity = 1. That's because cross-over accounts may be simultaneously long and short, where the net position balances to 0. In such circumstances, the currposn record must not be deleted.

Daily Cleanup (>= V2002.11.8.0)

Removes records from various tables.  This section is driven by a number of [Nightly] ini values. Set TCKQUEUE_KEEP_DAYS to indicate number of tckqueue records to keep or zero to keep all records (default = 7).  Set FIXEVENT_KEEP_DAYS to indicate number of fixevent records to keep or zero to keep all records (default = 7).  Set AFSEVENT_KEEP_DAYS to indicate number of afsevent records to keep or zero to keep all records (default = 0).  

Daily Backup (>= V2002.11.8.0)

Nightly will backup the afstrade database if the BACKUP_SERVER_DIRECTORY value is set. 

The Backup process consists of three distinct functions. 

  • First, the database is issued a dump command to a specified directory, BACKUP_SERVER_DIRECTORY.  This directory name is from the perspective of the database server. The dump file created is named <db_name>_<day_of_week>_dump.dat. (Eg. afstrade_Monday_dump.dat). If the dump process succeeds, the transaction log is purged.
  • Second, the backup file is copied to a second location. The process copies the file from the BACKUP_LOCAL_DIRECTORY to the BACKUP_REMOTE_DIRECTORY.  Both these directories are from the perspective of the machine running Nightly.exe.  Note that since the nightly process may be run on a machine different than the database server, the directory structure known to Windows (copy function) may be different than the structure known to the Sybase server (dump function). As such,  BACKUP_LOCAL_DIRECTORY must point to the same physical directory as BACKUP_SERVER_DIRECTORY.
  • If the parameter BACKUP_COMPRESS_FILE = 1, the files on both directories (local and remote) are compressed using a zip command. The original backup files are destroyed after the compression is complete, leaving only the ".zip" file.

Position History

This process builds position history records for the current day, assigning the current price to the history record (to cover the case where an outside process was used to update the product price history).  It also assigns values to Unrealized P&L, Accrued Interest, and Accreted Interest. This process only runs if the database contains the histposn table.

SYSDFLTS update

In the sysdflts table, sets current_day to today and previous day to the day before today.   afs:TRADE uses the value in current_day when determining if a user can run afs:TRADE.  If current_day is less than the database server's current day, the user may not run afs:TRADE.

Updating database statistics

Because several of the database tables are very dynamic, Sybase Adaptive Server indexes can become outdated so that they are not used and potentially causing a full table scan when an index should be used.  This module resets the internal statistics for all indexes for the following tables: 

  • tckmast 
  • tckdtl
  • currposn
  • custposn
  • custhist
  • product
  • opmast

To use this module, add the following statement to the Nightly section of the afstrade.ini file:
        DB_UPDATE_STATISTICS=1.

See Also

Revision Notes

  • V2003.3.27 - If AverageCostPostingEnabled, do not update tckdtl.average_cost.