Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some code quality and bug-risk issues #106

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions .deepsource.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version = 1

test_patterns = ["*/test/**"]

exclude_patterns = [
"*/data/**",
"*/examples/**"
]

[[analyzers]]
name = "python"
enabled = true

[analyzers.meta]
runtime_version = "3.x.x"
9 changes: 9 additions & 0 deletions dco/Prajjwal Nijhara.dco
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
1) I, Prajjwal Nijhara, certify that all work committed with the commit message
"covered by: Prajjwal Nijhara.dco" is my original work and I own the copyright
to this work. I agree to contribute this code under the Apache 2.0 license.

2) I understand and agree all contribution including all personal
information I submit with it is maintained indefinitely and may be
redistributed consistent with the open source license(s) involved.

This certification is effective for all code contributed from 2020-04-28 to 9999-01-01.
2 changes: 1 addition & 1 deletion gs_quant/api/fred/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def construct_dataframe_with_types(self, dataset_id: str, data: pd.Series) -> pd
:param data: Data to convert with correct types
:return: Dataframe with correct types
"""
if len(data) and isinstance(data, pd.Series):
if data and isinstance(data, pd.Series):
return data.to_frame()
else:
return pd.DataFrame({})
Expand Down
4 changes: 3 additions & 1 deletion gs_quant/api/gs/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def get_contents(
tags: set = None,
offset: int = 0,
limit: int = 10,
order_by: dict = {'direction': OrderBy.DESC, 'field': 'createdTime'}
order_by: dict = None
) -> List[ContentResponse]:
"""
Get contents for given parameters
Expand All @@ -69,6 +69,8 @@ def get_contents(
>>> GsSession.use()
>>> contents = GsContentApi.get_contents(channels=['G10'])
"""
if order_by is None:
order_by = {'direction': OrderBy.DESC, 'field': 'createdTime'}

if limit and limit > 1000:
raise ValueError('Limit is too large. Limit must be <= 1000.')
Expand Down
6 changes: 4 additions & 2 deletions gs_quant/target/backtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2552,9 +2552,11 @@ def __init__(
trading_parameters: BacktestTradingParameters,
index_initial_value: float,
underliers: Tuple[BacktestStrategyUnderlier, ...] = None,
measures: Tuple[Union[FlowVolBacktestMeasure, str], ...] = ['ALL MEASURES'],
measures: Tuple[Union[FlowVolBacktestMeasure, str], ...] = None,
name: str = None
):
):
if measures is None:
measures = ['ALL MEASURES']
super().__init__()
self.index_initial_value = index_initial_value
self.underliers = underliers
Expand Down
9 changes: 9 additions & 0 deletions gs_quant/timeseries/measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,15 @@ def vol_term(asset: Asset, strike_reference: VolReference, relative_strike: Real
raise NotImplementedError('realtime forward term not implemented') # TODO

if asset.asset_class == AssetClass.FX:
if strike_reference in (VolReference.FORWARD, VolReference.SPOT) and relative_strike != 100:
raise MqValueError('relative strike must be 100 for Spot or Forward strike reference')
if strike_reference == VolReference.NORMALIZED:
raise MqValueError(f'strike reference {strike_reference} not supported for FX')
if strike_reference == VolReference.DELTA_NEUTRAL and relative_strike != 0:
raise MqValueError('relative_strike must be 0 for delta_neutral')

if strike_reference == VolReference.DELTA_PUT:
relative_strike *= -1
sr_string, relative_strike = _preprocess_implied_vol_strikes_fx(strike_reference, relative_strike)
asset_id = cross_stored_direction_for_fx_vol(asset)
buffer = 1 # FX vol data is loaded later
Expand Down