Skip to content

Commit

Permalink
Chore: Make release 1.0.36
Browse files Browse the repository at this point in the history
  • Loading branch information
martinroberson committed Sep 12, 2023
1 parent e2d7059 commit 3de76d9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
27 changes: 23 additions & 4 deletions gs_quant/test/timeseries/test_measures_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
specific language governing permissions and limitations
under the License.
"""
import copy
import datetime

import pandas
Expand Down Expand Up @@ -461,10 +462,6 @@ def test_factor_pnl():
mock = replace('gs_quant.api.gs.reports.GsReportApi.get_report', Mock())
mock.return_value = factor_risk_report

# mock getting report factor data
mock = replace('gs_quant.api.gs.reports.GsReportApi.get_factor_risk_report_results', Mock())
mock.return_value = factor_data

# mock getting risk model dates
mock = replace('gs_quant.api.gs.risk_models.GsRiskModelApi.get_risk_model_dates', Mock())
mock.return_value = ['2010-01-01']
Expand All @@ -489,9 +486,31 @@ def test_factor_pnl():
}]

with DataContext(datetime.date(2020, 11, 23), datetime.date(2020, 11, 25)):
# mock getting report factor data
mock = replace('gs_quant.api.gs.reports.GsReportApi.get_factor_risk_report_results', Mock())
mock.return_value = factor_data

actual = mr.factor_pnl('report_id', 'Factor Name')
assert all(actual.values == [11.23, 11.24, 11.25])

with DataContext(datetime.date(2020, 11, 22), datetime.date(2020, 11, 25)):
# mock getting report factor data with first day set to 0
factor_data_copy = copy.copy(factor_data)
factor_data_copy.insert(0, {
'date': '2020-11-22',
'reportId': 'report_id',
'factor': 'factor_id',
'factorCategory': 'CNT',
'pnl': 0,
'exposure': -11.23,
'proportionOfRisk': 1
})
mock = replace('gs_quant.api.gs.reports.GsReportApi.get_factor_risk_report_results', Mock())
mock.return_value = factor_data_copy

actual = mr.factor_pnl('report_id', 'Factor Name')
assert all(actual.values == [0.0, 11.23, 11.24, 11.25])

with pytest.raises(MqValueError):
mr.factor_pnl('report_id', 'Wrong Factor Name')
replace.restore()
Expand Down
2 changes: 1 addition & 1 deletion gs_quant/timeseries/measures_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def _get_factor_data(report_id: str, factor_name: str, query_type: QueryType, un
end_date=DataContext.current.end_date,
return_format=ReturnFormat.JSON
)
factor_data = [d for d in factor_data if d.get(data_type)]
factor_data = [d for d in factor_data if d.get(data_type) is not None]
if unit == Unit.PERCENT:
if report.position_source_type != PositionSourceType.Portfolio:
raise MqValueError('Unit can only be set to percent for portfolio reports')
Expand Down

0 comments on commit 3de76d9

Please sign in to comment.