{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import datetime as dt\n", "import pandas as pd\n", "\n", "from gs_quant.markets.position_set import Position, PositionSet\n", "from gs_quant.session import Environment, GsSession" ] }, { "cell_type": "code", "execution_count": null, "outputs": [], "source": [ "client = 'CLIENT ID'\n", "secret = 'CLIENT SECRET'\n", "\n", "GsSession.use(Environment.PROD, client_id=client, client_secret=secret, scopes=('read_product_data',))" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n" } } }, { "cell_type": "markdown", "source": [ "If you have historical positions that you'd like to bring into Marquee, you should create an individual position\n", "set per each position date. The below examples show the three valid ways to do this (column names/format included)\n", "\n", "### Step 1: Define your file format\n", "#### Option 1: Create historical position sets by weight\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
identifierweightdate
AAPL UW0.42022-06-03
MSFT UW0.62022-06-03
AAPL UW0.42023-01-04
MSFT UW0.22023-01-04
IBM UN0.42023-01-04
" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": null, "outputs": [], "source": [ "columns = ['identifier', 'weight', 'date']\n", "equalize = False" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n" } } }, { "cell_type": "markdown", "source": [ "#### Option 2: Create historical position sets by quantity\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
identifierquantitydate
AAPL UW1002022-06-03
MSFT UW1002022-06-03
AAPL UW2002023-01-04
MSFT UW3002023-01-04
IBM UN2002023-01-04
" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": null, "outputs": [], "source": [ "columns = ['identifier', 'quantity', 'date']\n", "equalize = False" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n" } } }, { "cell_type": "markdown", "source": [ "#### Option 3: Create equally-weighted historical position sets\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
identifierdate
AAPL UW2022-06-03
MSFT UW2022-06-03
AAPL UW2023-01-04
MSFT UW2023-01-04
IBM UN2023-01-04
" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": null, "outputs": [], "source": [ "columns = ['identifier', 'date']\n", "equalize = True" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n" } } }, { "cell_type": "markdown", "source": [ "### Step 2: Upload your excel file and convert your positions into position sets" ], "metadata": { "collapsed": false } }, { "cell_type": "code", "execution_count": null, "outputs": [], "source": [ "positions_data = pd.read_excel('positions_data.xlsx', engine='openpyxl')\n", "all_positions = positions_data[columns]\n", "\n", "positions_dict, position_sets = {}, []\n", "for i, row in all_positions.iterrows():\n", " date = row.get('date')\n", " if not date in positions_dict:\n", " positions_dict[date] = set()\n", " positions_dict[date].add(Position(identifier=row.get('identifier'),\n", " weight=row.get('weight', None),\n", " quantity=row.get('quantity', None)))\n", "\n", "for date in positions_dict:\n", " position_date = dt.datetime.strptime(str(date), '%Y-%m-%d %H:%M:%S').date()\n", " position_set = PositionSet(positions=positions_dict[date], date=position_date)\n", " if equalize:\n", " position_set.equalize_position_weights()\n", " position_sets.append(position_set)\n", "\n", "print(position_sets)" ], "metadata": { "collapsed": false, "pycharm": { "name": "#%%\n" } } } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "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" } }, "nbformat": 4, "nbformat_minor": 0 }