Skip to content

Commit

Permalink
Chore: Make release 1.0.66
Browse files Browse the repository at this point in the history
  • Loading branch information
martinroberson authored and DominicCYK committed Mar 5, 2024
1 parent 2271c53 commit 85e02dd
Show file tree
Hide file tree
Showing 6 changed files with 97 additions and 38 deletions.
Expand Up @@ -10,7 +10,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -23,7 +23,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -33,17 +33,9 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Original price: 605,255.51\n"
]
}
],
"outputs": [],
"source": [
"# Create and price a swaption\n",
"swaption = IRSwaption('Pay', '5y', 'USD', expiration_date='3m')\n",
Expand All @@ -68,20 +60,13 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Scenario price: 635,392.60\n"
]
}
],
"outputs": [],
"source": [
"import pandas as pd\n",
"\n",
"from gs_quant.markets import PricingContext\n",
"from gs_quant.common import MarketBehaviour\n",
"# Read discount factors from a csv file\n",
"df = pd.read_csv (r'CurveExample.csv', sep=\",\" )\n",
"dates = df.MaturityDate.tolist()\n",
Expand All @@ -95,16 +80,24 @@
" csa_term = \"USD-SOFR\",\n",
" curve_type = \"Discount Curve\"\n",
")\n",
"with curve_overlay_scenario:\n",
" price_with_overlay = swaption.price()\n",
"\n",
"print('Scenario price: {:,.2f}'.format(price_with_overlay))"
"with PricingContext(market_behaviour=MarketBehaviour.Calibrated):\n",
" with curve_overlay_scenario:\n",
" price_with_overlay = swaption.price()\n",
"p = price_with_overlay.result()\n",
"print('Scenario price: {:,.2f}'.format(p))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -118,7 +111,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.1"
"version": "3.10.10"
}
},
"nbformat": 4,
Expand Down
5 changes: 4 additions & 1 deletion gs_quant/risk/results.py
Expand Up @@ -127,7 +127,10 @@ def _value_for_date(result: Union[DataFrameWithInfo, SeriesWithInfo], date: Unio
if result.empty:
return result

raw_value = result.loc[date]
# if the result is a dataframe try to preserve the type
# if a dataframe has only 1 row selected it otherwise gets turned into a series
raw_value = result.loc[[date]] if isinstance(result, DataFrameWithInfo) and isinstance(date, dt.date) \
else result.loc[date]
key = result.risk_key

risk_key = RiskKey(
Expand Down
18 changes: 11 additions & 7 deletions gs_quant/session.py
Expand Up @@ -190,7 +190,8 @@ def init(self):
self._session.headers.update({'X-Application': self.application})
self._session.headers.update({'X-Version': self.application_version})
self._authenticate()
self.post_to_activity_service()
if self.domain == Domain.APP:
self.post_to_activity_service()

def close(self):
self._session: requests.Session
Expand Down Expand Up @@ -527,12 +528,15 @@ def post_to_activity_service(self):
params = {'featureApplication': self.application,
'gsQuantVersion': self.application_version,
'pythonVersion': f'{sys.version_info.major}.{sys.version_info.minor}'}
self._session.post(f'{self.domain}/{self.api_version}/activities',
verify=self.verify,
headers={'Content-Type': 'application/json; charset=utf-8'},
data=json.dumps({'action': 'Initiated', 'kpis': [{'id': 'gsqInitiated', 'value': 1}],
'resource': 'GSQuant',
'parameters': params}))
try:
self._session.post(f'{self.domain}/{self.api_version}/activities',
verify=self.verify,
headers={'Content-Type': 'application/json; charset=utf-8'},
data=json.dumps({'action': 'Initiated', 'kpis': [{'id': 'gsqInitiated', 'value': 1}],
'resource': 'GSQuant',
'parameters': params}))
except Exception:
pass

@classmethod
def get(
Expand Down
1 change: 1 addition & 0 deletions gs_quant/target/workflow_quote.py
Expand Up @@ -248,6 +248,7 @@ class WorkflowPosition(Base):
description: Optional[str] = field(default=None, metadata=field_metadata)
entitlements: Optional[WorkflowEntitlements] = field(default=None, metadata=field_metadata)
creator: Optional[str] = field(default=None, metadata=field_metadata)
originating_system: Optional[str] = field(default=None, metadata=field_metadata)
is_read_only: Optional[bool] = field(default=None, metadata=field_metadata)
name: Optional[str] = field(default=None, metadata=name_metadata)

Expand Down
@@ -0,0 +1,50 @@
[
[
[
[
{
"$type": "RiskVector",
"points": [
{
"path": "",
"type": "CMD NRG",
"asset": "WTI",
"class_": "FUTURE",
"point": "Z24",
"quoteStyle": "Price"
}
],
"asset": [
-1630.8292216583252
],
"calculationTime": 2170,
"queueingTime": -10164
}
]
]
],
[
[
[
{
"$type": "RiskVector",
"points": [
{
"path": "",
"type": "CMD NRG",
"asset": "WTI",
"class_": "FUTURE",
"point": "Z24",
"quoteStyle": "Price"
}
],
"asset": [
-1630.8292216583252
],
"calculationTime": 2170,
"queueingTime": -10164
}
]
]
]
]
10 changes: 9 additions & 1 deletion gs_quant/test/risk/test_results.py
Expand Up @@ -19,7 +19,7 @@
import gs_quant.risk as risk
import numpy as np
import pytest
from gs_quant.instrument import IRSwap, IRBasisSwap, IRSwaption, FXMultiCrossBinary, FXMultiCrossBinaryLeg
from gs_quant.instrument import IRSwap, IRBasisSwap, IRSwaption, FXMultiCrossBinary, FXMultiCrossBinaryLeg, CommodSwap
from gs_quant.markets import HistoricalPricingContext, PricingContext, CloseMarket, MarketDataCoordinate
from gs_quant.markets.portfolio import Portfolio
from gs_quant.risk import MultiScenario, ResolvedInstrumentValues
Expand Down Expand Up @@ -70,12 +70,14 @@ def get_attributes(p, risks, ctx='PricingCtx1', resolve=False, no_frame=False):
swap_6 = IRSwap("Pay", "10y", "GBP", fixed_rate=-0.005, name="10y")
swap_7 = IRSwap("Pay", "5y", "JPY", fixed_rate=-0.005, name="5y")
swap_8 = IRSwap("Pay", "10y", "JPY", fixed_rate=-0.005, name="10y")
commod_swap = CommodSwap(name="Test")
eur_port = Portfolio([swap_1, swap_2], name="EUR")
usd_port = Portfolio([swap_3, swap_4], name="USD")
gbp_port = Portfolio([swap_5, swap_6], name="GBP")
jpy_port = Portfolio([swap_7, swap_8], name='JPY')
port1 = Portfolio([eur_port, gbp_port], name='EURGBP')
port2 = Portfolio([jpy_port, usd_port], name='USDJPY')
commod_port = Portfolio([commod_swap])
port = Portfolio([port1, port2])
swaption_port = Portfolio([IRSwaption("Receive", '5y', 'USD', expiration_date='2m', strike='atm', name='Swaption1'),
IRSwaption("Receive", '10y', 'USD', expiration_date='3m', strike='atm', name='Swaption2')])
Expand Down Expand Up @@ -302,6 +304,7 @@ def test_bucketed_risks(mocker):
_, res4, frame4 = get_attributes(port1, risk.IRDelta, 'Multiple')
_, res5, frame5 = get_attributes(bs_port, risk.IRBasis(aggregation_level=AggregationLevel.Asset))
_, res6, frame6 = get_attributes(jpy_port, risk.IRBasis(aggregation_level=AggregationLevel.Asset), 'Multiple')
_, res7, frame7 = get_attributes(commod_port, risk.CommodDelta, "Multiple")

def check_depth(res, f, with_dates=''):
temp_res = list(res)[0].drop('value', axis=1)
Expand All @@ -316,13 +319,15 @@ def check_depth(res, f, with_dates=''):
check_depth(res4, frame4, 'dated')
check_depth(res5, frame5)
check_depth(res6, frame6, 'dated')
check_depth(res7, frame7, 'dated')

default_pivot_table_test(res1, 'has_bucketed')
default_pivot_table_test(res2, 'has_bucketed')
default_pivot_table_test(res3, 'has_bucketed')
default_pivot_table_test(res4, 'has_bucketed')
default_pivot_table_test(res5, 'has_bucketed')
default_pivot_table_test(res6, 'has_bucketed')
default_pivot_table_test(res7, 'has_bucketed')

# test slicing
# slice one portfolio
Expand All @@ -349,6 +354,9 @@ def filter_lambda(x):
manual_agg_f6 = frame6.loc[frame6.apply(filter_lambda, axis=1)]['value'].values.sum()
np.testing.assert_almost_equal(filter_agg_r6, manual_agg_f6, 8)

assert isinstance(res7[date(2020, 1, 14)].result().futures[0].result(), DataFrameWithInfo)
assert res7[date(2020, 1, 14)].to_frame()["mkt_type"][0] == "CMD NRG"


def test_cashflows_risk(mocker):
with MockCalc(mocker):
Expand Down

0 comments on commit 85e02dd

Please sign in to comment.