{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true, "pycharm": { "is_executing": false } }, "outputs": [], "source": [ "from datetime import date\n", "\n", "from gs_quant.datetime.relative_date import RelativeDate\n", "from gs_quant.markets.securities import ExchangeCode\n", "from gs_quant.session import GsSession, Environment" ] }, { "cell_type": "code", "execution_count": 1, "outputs": [ { "traceback": [ "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0myesterday\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mdate\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdate\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mtoday\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;33m-\u001b[0m \u001b[0mtimedelta\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdays\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 2\u001b[0m \u001b[0mdate\u001b[0m\u001b[1;33m:\u001b[0m \u001b[0mdate\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mRelativeDate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'-1d'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mbase_date\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0myesterday\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mapply_rule\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m# Returns 2 days ago\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", "\u001b[1;31mNameError\u001b[0m: name 'date' is not defined" ], "ename": "NameError", "evalue": "name 'date' is not defined", "output_type": "error" } ], "source": [ "# external users should substitute their client id and secret; please skip this step if using internal jupyterh\n", "\n", "GsSession.use(Environment.PROD, client_id=None, client_secret=None, scopes=('read_product_data',))" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n", "is_executing": false } } }, { "cell_type": "markdown", "source": [ "## Date Rule conventions\n", "A: first day of th year\n", "b: business days of calendar passed, USD by default\n", "d: Gregorian calendar days\n", "e: end of month (ignores number)\n", "m: month\n", "r: end of year\n", "u: business days ignoring USD holidays\n", "v: gets last business day of month (does not ignore number)\n", "x: gets last business day of month (ignores the number)\n", "y: add years, Result will be moved to the next week if falling on a weekend" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%% md\n" } } }, { "cell_type": "code", "execution_count": null, "outputs": [], "source": [ "# Returns four business days after the first business day on or after the 15th calendar day of the month\n", "date: date = RelativeDate('14d+0u+4u').apply_rule(exchanges=[ExchangeCode.NYSE])" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n" } } } ], "metadata": { "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.6" }, "kernelspec": { "name": "python3", "language": "python", "display_name": "Python 3" }, "pycharm": { "stem_cell": { "cell_type": "raw", "source": [], "metadata": { "collapsed": false } } } }, "nbformat": 4, "nbformat_minor": 0 }