#!/usr/bin/env python # coding: utf-8 # # Rebalancing a Custom Basket # # Here we will go through how to modify your basket's current composition. You may concurrently modify basket details, pricing options, and publishing preferences. # ## Step 1: Authenticate & Initialize your session # # First you will import the necessary modules and add your client id and client secret. # In[ ]: from gs_quant.markets.position_set import PositionSet from gs_quant.markets.baskets import Basket 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 read_user_profile',)) # ## Step 2: Fetch your basket and set your changes # # Next you will fetch the basket you'd like to update by passing in any of its identifiers such as BloombergId, Cusip, Ticker, etc. If this is a basket you or someone from your organization created, please make sure your application has admin entitlements or you will not be able to submit the rebalance request. You will then be ready to change any of the properties listed below. # # | Parameter Name | Required? | Description | # |:-------------------|:-----------|:------------| # |position_set |**Required**|Information of constituents associated with the basket. You may provide the weight or quantity for each position. If neither is provided we will distribute the total weight evenly among each position. Please note that any fractional shares will be rounded up to whole numbers.| # |divisor |Optional |Divisor to be applied to the overall position set. Ideally, you should not to change this as it will cause a price deviation on the basket.| # |initial_price |Optional |Price you'd like to reset the basket to. Ideally, you should not to do this as it will cause a price deviation on the basket.| # |publish_to_bloomberg|Optional |If you'd like us to publish your basket to Bloomberg| # |publish_to_reuters |Optional |If you'd like us to publish your basket to Reuters | # |publish_to_factset |Optional |If you'd like us to publish your basket to Factset | # |include_price_history|Optional |Republish price history based on current composition when publishing to Bloomberg| # |reweight |Optional |If you'd like us to reweight positions if input weights don't add up to 1 upon submission| # |weighting_strategy |Optional |Strategy used to price the position set (will be inferred if not indicated). One of Equal, Market Capitalization, Quantity, Weight| # |allow_ca_restricted_assets|Optional|Allow your basket to have constituents that will not be corporate action adjusted in the future (You will recieve a message indicating if this action is needed when attempting to rebalance your basket)| # |allow_limited_access_assets|Optional|Allow basket to have constituents that GS has limited access to (You will recieve a message indicating if this action is needed when attempting to rebalance your basket)| # |cash_reinvestment_treatment|How to treat cash acquisitions, regular dividends, and special dividends for basket underliers.| # |historical_methodology|Preferred methodology to be applied when publishing basket history.