import datetime as dt
import pandas as pd
from gs_quant.markets.position_set import Position, PositionSet
from gs_quant.session import Environment, GsSession
client = 'CLIENT ID'
secret = 'CLIENT SECRET'
GsSession.use(Environment.PROD, client_id=client, client_secret=secret, scopes=('read_product_data',))
If you have historical positions that you'd like to bring into Marquee, you should create an individual position set per each position date. The below examples show the three valid ways to do this (column names/format included)
identifier | weight | date |
---|---|---|
AAPL UW | 0.4 | 2022-06-03 |
MSFT UW | 0.6 | 2022-06-03 |
AAPL UW | 0.4 | 2023-01-04 |
MSFT UW | 0.2 | 2023-01-04 |
IBM UN | 0.4 | 2023-01-04 |
columns = ['identifier', 'weight', 'date']
equalize = False
identifier | quantity | date |
---|---|---|
AAPL UW | 100 | 2022-06-03 |
MSFT UW | 100 | 2022-06-03 |
AAPL UW | 200 | 2023-01-04 |
MSFT UW | 300 | 2023-01-04 |
IBM UN | 200 | 2023-01-04 |
columns = ['identifier', 'quantity', 'date']
equalize = False
identifier | date |
---|---|
AAPL UW | 2022-06-03 |
MSFT UW | 2022-06-03 |
AAPL UW | 2023-01-04 |
MSFT UW | 2023-01-04 |
IBM UN | 2023-01-04 |
columns = ['identifier', 'date']
equalize = True
positions_data = pd.read_excel('positions_data.xlsx', engine='openpyxl')
all_positions = positions_data[columns]
positions_dict, position_sets = {}, []
for i, row in all_positions.iterrows():
date = row.get('date')
if not date in positions_dict:
positions_dict[date] = set()
positions_dict[date].add(Position(identifier=row.get('identifier'),
weight=row.get('weight', None),
quantity=row.get('quantity', None)))
for date in positions_dict:
position_date = dt.datetime.strptime(str(date), '%Y-%m-%d %H:%M:%S').date()
position_set = PositionSet(positions=positions_dict[date], date=position_date)
if equalize:
position_set.equalize_position_weights()
position_sets.append(position_set)
print(position_sets)