body
stringlengths
26
98.2k
body_hash
int64
-9,222,864,604,528,158,000
9,221,803,474B
docstring
stringlengths
1
16.8k
path
stringlengths
5
230
name
stringlengths
1
96
repository_name
stringlengths
7
89
lang
stringclasses
1 value
body_without_docstring
stringlengths
20
98.2k
def __init__(self, l2_norm_clip, stddev): 'Initializes the GaussianSumQuery.\n\n Args:\n l2_norm_clip: The clipping norm to apply to the global norm of each\n record.\n stddev: The stddev of the noise added to the sum.\n ' self._l2_norm_clip = l2_norm_clip self._stddev = stddev se...
830,702,645,456,667,900
Initializes the GaussianSumQuery. Args: l2_norm_clip: The clipping norm to apply to the global norm of each record. stddev: The stddev of the noise added to the sum.
tensorflow_privacy/privacy/dp_query/gaussian_query.py
__init__
Juspem1980/privacy
python
def __init__(self, l2_norm_clip, stddev): 'Initializes the GaussianSumQuery.\n\n Args:\n l2_norm_clip: The clipping norm to apply to the global norm of each\n record.\n stddev: The stddev of the noise added to the sum.\n ' self._l2_norm_clip = l2_norm_clip self._stddev = stddev se...
def make_global_state(self, l2_norm_clip, stddev): 'Creates a global state from the given parameters.' return self._GlobalState(tf.cast(l2_norm_clip, tf.float32), tf.cast(stddev, tf.float32))
7,631,861,765,875,769,000
Creates a global state from the given parameters.
tensorflow_privacy/privacy/dp_query/gaussian_query.py
make_global_state
Juspem1980/privacy
python
def make_global_state(self, l2_norm_clip, stddev): return self._GlobalState(tf.cast(l2_norm_clip, tf.float32), tf.cast(stddev, tf.float32))
def preprocess_record_impl(self, params, record): 'Clips the l2 norm, returning the clipped record and the l2 norm.\n\n Args:\n params: The parameters for the sample.\n record: The record to be processed.\n\n Returns:\n A tuple (preprocessed_records, l2_norm) where `preprocessed_records` is\n ...
-7,945,747,213,345,504,000
Clips the l2 norm, returning the clipped record and the l2 norm. Args: params: The parameters for the sample. record: The record to be processed. Returns: A tuple (preprocessed_records, l2_norm) where `preprocessed_records` is the structure of preprocessed tensors, and l2_norm is the total l2 norm befor...
tensorflow_privacy/privacy/dp_query/gaussian_query.py
preprocess_record_impl
Juspem1980/privacy
python
def preprocess_record_impl(self, params, record): 'Clips the l2 norm, returning the clipped record and the l2 norm.\n\n Args:\n params: The parameters for the sample.\n record: The record to be processed.\n\n Returns:\n A tuple (preprocessed_records, l2_norm) where `preprocessed_records` is\n ...
def get_noised_result(self, sample_state, global_state): 'See base class.' if (LooseVersion(tf.__version__) < LooseVersion('2.0.0')): def add_noise(v): return (v + tf.random.normal(tf.shape(input=v), stddev=global_state.stddev)) else: random_normal = tf.random_normal_initializer...
-6,189,862,732,280,817,000
See base class.
tensorflow_privacy/privacy/dp_query/gaussian_query.py
get_noised_result
Juspem1980/privacy
python
def get_noised_result(self, sample_state, global_state): if (LooseVersion(tf.__version__) < LooseVersion('2.0.0')): def add_noise(v): return (v + tf.random.normal(tf.shape(input=v), stddev=global_state.stddev)) else: random_normal = tf.random_normal_initializer(stddev=global_st...
def __init__(self, l2_norm_clip, sum_stddev, denominator): 'Initializes the GaussianAverageQuery.\n\n Args:\n l2_norm_clip: The clipping norm to apply to the global norm of each\n record.\n sum_stddev: The stddev of the noise added to the sum (before\n normalization).\n denominator: ...
-4,537,654,262,657,255,000
Initializes the GaussianAverageQuery. Args: l2_norm_clip: The clipping norm to apply to the global norm of each record. sum_stddev: The stddev of the noise added to the sum (before normalization). denominator: The normalization constant (applied after noise is added to the sum).
tensorflow_privacy/privacy/dp_query/gaussian_query.py
__init__
Juspem1980/privacy
python
def __init__(self, l2_norm_clip, sum_stddev, denominator): 'Initializes the GaussianAverageQuery.\n\n Args:\n l2_norm_clip: The clipping norm to apply to the global norm of each\n record.\n sum_stddev: The stddev of the noise added to the sum (before\n normalization).\n denominator: ...
def _assert_community_contribution_stats_is_in_default_state(self): 'Checks if the community contribution stats is in its default\n state.\n ' community_contribution_stats = suggestion_services.get_community_contribution_stats() self.assertEqual(community_contribution_stats.translation_reviewe...
-8,273,821,425,724,012,000
Checks if the community contribution stats is in its default state.
core/domain/suggestion_registry_test.py
_assert_community_contribution_stats_is_in_default_state
AdityaDubey0/oppia
python
def _assert_community_contribution_stats_is_in_default_state(self): 'Checks if the community contribution stats is in its default\n state.\n ' community_contribution_stats = suggestion_services.get_community_contribution_stats() self.assertEqual(community_contribution_stats.translation_reviewe...
def conversion_fn(): 'Temporary function.' pass
-7,532,713,194,701,360,000
Temporary function.
core/domain/suggestion_registry_test.py
conversion_fn
AdityaDubey0/oppia
python
def conversion_fn(): pass
def __init__(self, feats_extract: Optional[AbsFeatsExtract], normalize: Optional[(AbsNormalize and InversibleInterface)], tts: AbsGANTTS): 'Initialize ESPnetGANTTSModel module.' assert check_argument_types() super().__init__() self.feats_extract = feats_extract self.normalize = normalize self.tt...
-4,964,261,881,008,749,000
Initialize ESPnetGANTTSModel module.
espnet2/gan_tts/espnet_model.py
__init__
actboy/espnet
python
def __init__(self, feats_extract: Optional[AbsFeatsExtract], normalize: Optional[(AbsNormalize and InversibleInterface)], tts: AbsGANTTS): assert check_argument_types() super().__init__() self.feats_extract = feats_extract self.normalize = normalize self.tts = tts assert hasattr(tts, 'gener...
def forward(self, text: torch.Tensor, text_lengths: torch.Tensor, speech: torch.Tensor, speech_lengths: torch.Tensor, spembs: Optional[torch.Tensor]=None, sids: Optional[torch.Tensor]=None, lids: Optional[torch.Tensor]=None, forward_generator: bool=True) -> Dict[(str, Any)]: 'Return generator or discriminator loss ...
-8,931,493,892,899,705,000
Return generator or discriminator loss with dict format. Args: text (Tensor): Text index tensor (B, T_text). text_lengths (Tensor): Text length tensor (B,). speech (Tensor): Speech waveform tensor (B, T_wav). speech_lengths (Tensor): Speech length tensor (B,). spembs (Optional[Tensor]): Speaker emb...
espnet2/gan_tts/espnet_model.py
forward
actboy/espnet
python
def forward(self, text: torch.Tensor, text_lengths: torch.Tensor, speech: torch.Tensor, speech_lengths: torch.Tensor, spembs: Optional[torch.Tensor]=None, sids: Optional[torch.Tensor]=None, lids: Optional[torch.Tensor]=None, forward_generator: bool=True) -> Dict[(str, Any)]: 'Return generator or discriminator loss ...
def collect_feats(self, text: torch.Tensor, text_lengths: torch.Tensor, speech: torch.Tensor, speech_lengths: torch.Tensor, spembs: Optional[torch.Tensor]=None, sids: Optional[torch.Tensor]=None, lids: Optional[torch.Tensor]=None) -> Dict[(str, torch.Tensor)]: 'Calculate features and return them as a dict.\n\n ...
-8,469,345,931,603,927,000
Calculate features and return them as a dict. Args: text (Tensor): Text index tensor (B, T_text). text_lengths (Tensor): Text length tensor (B,). speech (Tensor): Speech waveform tensor (B, T_wav). speech_lengths (Tensor): Speech length tensor (B, 1). spembs (Optional[Tensor]): Speaker embedding te...
espnet2/gan_tts/espnet_model.py
collect_feats
actboy/espnet
python
def collect_feats(self, text: torch.Tensor, text_lengths: torch.Tensor, speech: torch.Tensor, speech_lengths: torch.Tensor, spembs: Optional[torch.Tensor]=None, sids: Optional[torch.Tensor]=None, lids: Optional[torch.Tensor]=None) -> Dict[(str, torch.Tensor)]: 'Calculate features and return them as a dict.\n\n ...
@staticmethod def factory(sql_connection_type: SqlDialect, **kwargs) -> 'SqlConnectionOptions': '\n Function signatures for factory method\n\n Postgres: (dialect: SqlDialects, host: str, port: int, username: str, password: str,\n database_name: str, timeout: int = None)\n ' return Sq...
-2,160,951,259,533,789,000
Function signatures for factory method Postgres: (dialect: SqlDialects, host: str, port: int, username: str, password: str, database_name: str, timeout: int = None)
flask_app/utilities/DataInterfaces/SqlInterface.py
factory
cliftbar/flask_app_template
python
@staticmethod def factory(sql_connection_type: SqlDialect, **kwargs) -> 'SqlConnectionOptions': '\n Function signatures for factory method\n\n Postgres: (dialect: SqlDialects, host: str, port: int, username: str, password: str,\n database_name: str, timeout: int = None)\n ' return Sq...
def get_latest_version() -> str: '\n :return: The latest available version in the format "vX.Y.Z"\n ' subdomain = ('staging.' if config.is_staging.value else '') credentials = config.staging_credentials() url = BRAINFRAME_LATEST_TAG_URL.format(subdomain=subdomain) response = requests.get(url, ...
-3,277,660,655,089,626,000
:return: The latest available version in the format "vX.Y.Z"
brainframe/cli/docker_compose.py
get_latest_version
aotuai/brainframe-cli
python
def get_latest_version() -> str: '\n \n ' subdomain = ('staging.' if config.is_staging.value else ) credentials = config.staging_credentials() url = BRAINFRAME_LATEST_TAG_URL.format(subdomain=subdomain) response = requests.get(url, auth=credentials) return response.text
def _assert_has_docker_permissions() -> None: 'Fails if the user does not have permissions to interact with Docker' if (not (os_utils.is_root() or os_utils.currently_in_group('docker'))): error_message = ((i18n.t('general.docker-bad-permissions') + '\n') + _group_recommendation_message('docker')) ...
3,725,551,011,273,241,600
Fails if the user does not have permissions to interact with Docker
brainframe/cli/docker_compose.py
_assert_has_docker_permissions
aotuai/brainframe-cli
python
def _assert_has_docker_permissions() -> None: if (not (os_utils.is_root() or os_utils.currently_in_group('docker'))): error_message = ((i18n.t('general.docker-bad-permissions') + '\n') + _group_recommendation_message('docker')) print_utils.fail(error_message)
def _assert_has_write_permissions(path: Path) -> None: 'Fails if the user does not have write access to the given path.' if os.access(path, os.W_OK): return error_message = i18n.t('general.file-bad-write-permissions', path=path) error_message += '\n' if (path.stat().st_gid == os_utils.BRAINF...
-1,048,546,519,596,421,600
Fails if the user does not have write access to the given path.
brainframe/cli/docker_compose.py
_assert_has_write_permissions
aotuai/brainframe-cli
python
def _assert_has_write_permissions(path: Path) -> None: if os.access(path, os.W_OK): return error_message = i18n.t('general.file-bad-write-permissions', path=path) error_message += '\n' if (path.stat().st_gid == os_utils.BRAINFRAME_GROUP_ID): error_message += (' ' + _group_recommenda...
def configure_logger(path: pathlib.Path, verbose: bool=False) -> logging.Logger: 'Configure logger\n\n Args:\n path (pathlib.Path): Path where the persistent logger should write to.\n verbose (bool, optional): Use verbose logging. Defaults to False.\n\n Returns:\n logging.Logger: Created ...
664,404,265,283,654,300
Configure logger Args: path (pathlib.Path): Path where the persistent logger should write to. verbose (bool, optional): Use verbose logging. Defaults to False. Returns: logging.Logger: Created logger
c8ylp/cli/core.py
configure_logger
SoftwareAG/cumulocity-remote-access-local-proxy
python
def configure_logger(path: pathlib.Path, verbose: bool=False) -> logging.Logger: 'Configure logger\n\n Args:\n path (pathlib.Path): Path where the persistent logger should write to.\n verbose (bool, optional): Use verbose logging. Defaults to False.\n\n Returns:\n logging.Logger: Created ...
def signal_handler(_signal, _frame): 'Signal handler' sys.exit(ExitCodes.TERMINATE)
1,730,254,604,786,225,000
Signal handler
c8ylp/cli/core.py
signal_handler
SoftwareAG/cumulocity-remote-access-local-proxy
python
def signal_handler(_signal, _frame): sys.exit(ExitCodes.TERMINATE)
def register_signals(): 'Register signal handlers' signal.signal(signal.SIGINT, signal_handler)
7,165,289,326,244,733,000
Register signal handlers
c8ylp/cli/core.py
register_signals
SoftwareAG/cumulocity-remote-access-local-proxy
python
def register_signals(): signal.signal(signal.SIGINT, signal_handler)
def create_client(ctx: click.Context, opts: ProxyContext) -> CumulocityClient: 'Create Cumulocity client and prompt for missing credentials\n if necessary.\n\n Args:\n ctx (click.Context): Click context\n opts (ProxyContext): Proxy options\n\n Returns:\n CumulocityClient: Configured Cu...
180,156,177,567,948,860
Create Cumulocity client and prompt for missing credentials if necessary. Args: ctx (click.Context): Click context opts (ProxyContext): Proxy options Returns: CumulocityClient: Configured Cumulocity client
c8ylp/cli/core.py
create_client
SoftwareAG/cumulocity-remote-access-local-proxy
python
def create_client(ctx: click.Context, opts: ProxyContext) -> CumulocityClient: 'Create Cumulocity client and prompt for missing credentials\n if necessary.\n\n Args:\n ctx (click.Context): Click context\n opts (ProxyContext): Proxy options\n\n Returns:\n CumulocityClient: Configured Cu...
def store_credentials(opts: ProxyContext, client: CumulocityClient): 'Store credentials to the environment file. It creates\n the file if it does not already exist.\n\n The file will only be written to if it has changed.\n\n Args:\n opts (ProxyContext): Proxy options\n client (CumulocityClien...
-3,190,738,371,489,343,000
Store credentials to the environment file. It creates the file if it does not already exist. The file will only be written to if it has changed. Args: opts (ProxyContext): Proxy options client (CumulocityClient): Cumulocity client containing valid credentials
c8ylp/cli/core.py
store_credentials
SoftwareAG/cumulocity-remote-access-local-proxy
python
def store_credentials(opts: ProxyContext, client: CumulocityClient): 'Store credentials to the environment file. It creates\n the file if it does not already exist.\n\n The file will only be written to if it has changed.\n\n Args:\n opts (ProxyContext): Proxy options\n client (CumulocityClien...
def get_config_id(ctx: click.Context, mor: Dict[(str, Any)], config: str) -> str: 'Get the remote access configuration id matching a specific type\n from a device managed object\n\n Args:\n mor (Dict[str, Any]): Device managed object\n config (str): Expected configuration type\n\n Returns:\n ...
6,785,673,878,745,491,000
Get the remote access configuration id matching a specific type from a device managed object Args: mor (Dict[str, Any]): Device managed object config (str): Expected configuration type Returns: str: Remote access configuration id
c8ylp/cli/core.py
get_config_id
SoftwareAG/cumulocity-remote-access-local-proxy
python
def get_config_id(ctx: click.Context, mor: Dict[(str, Any)], config: str) -> str: 'Get the remote access configuration id matching a specific type\n from a device managed object\n\n Args:\n mor (Dict[str, Any]): Device managed object\n config (str): Expected configuration type\n\n Returns:\n ...
def run_proxy_in_background(ctx: click.Context, opts: ProxyContext, connection_data: RemoteAccessConnectionData, ready_signal: threading.Event=None): 'Run the proxy in a background thread\n\n Args:\n ctx (click.Context): Click context\n opts (ProxyContext): Proxy options\n connection_data (R...
-36,272,710,872,368,430
Run the proxy in a background thread Args: ctx (click.Context): Click context opts (ProxyContext): Proxy options connection_data (RemoteAccessConnectionData): Remote access connection data
c8ylp/cli/core.py
run_proxy_in_background
SoftwareAG/cumulocity-remote-access-local-proxy
python
def run_proxy_in_background(ctx: click.Context, opts: ProxyContext, connection_data: RemoteAccessConnectionData, ready_signal: threading.Event=None): 'Run the proxy in a background thread\n\n Args:\n ctx (click.Context): Click context\n opts (ProxyContext): Proxy options\n connection_data (R...
def pre_start_checks(ctx: click.Context, opts: ProxyContext) -> Optional[RemoteAccessConnectionData]: 'Run prestart checks before starting the local proxy\n\n Args:\n ctx (click.Context): Click context\n opts (ProxyContext): Proxy options\n\n Returns:\n Optional[RemoteAccessConnectionData...
3,013,459,128,331,044,000
Run prestart checks before starting the local proxy Args: ctx (click.Context): Click context opts (ProxyContext): Proxy options Returns: Optional[RemoteAccessConnectionData]: Remote access connection data
c8ylp/cli/core.py
pre_start_checks
SoftwareAG/cumulocity-remote-access-local-proxy
python
def pre_start_checks(ctx: click.Context, opts: ProxyContext) -> Optional[RemoteAccessConnectionData]: 'Run prestart checks before starting the local proxy\n\n Args:\n ctx (click.Context): Click context\n opts (ProxyContext): Proxy options\n\n Returns:\n Optional[RemoteAccessConnectionData...
def start_proxy(ctx: click.Context, opts: ProxyContext, connection_data: RemoteAccessConnectionData, stop_signal: threading.Event=None, ready_signal: threading.Event=None) -> NoReturn: 'Start the local proxy\n\n Args:\n ctx (click.Context): Click context\n opts (ProxyContext): Proxy options\n ' ...
6,606,672,606,113,287,000
Start the local proxy Args: ctx (click.Context): Click context opts (ProxyContext): Proxy options
c8ylp/cli/core.py
start_proxy
SoftwareAG/cumulocity-remote-access-local-proxy
python
def start_proxy(ctx: click.Context, opts: ProxyContext, connection_data: RemoteAccessConnectionData, stop_signal: threading.Event=None, ready_signal: threading.Event=None) -> NoReturn: 'Start the local proxy\n\n Args:\n ctx (click.Context): Click context\n opts (ProxyContext): Proxy options\n ' ...
@property def used_port(self) -> int: 'Get the port used by the local proxy\n\n Returns:\n int: Port number\n ' return self._root_context.get('used_port', self.port)
8,691,517,613,530,922,000
Get the port used by the local proxy Returns: int: Port number
c8ylp/cli/core.py
used_port
SoftwareAG/cumulocity-remote-access-local-proxy
python
@property def used_port(self) -> int: 'Get the port used by the local proxy\n\n Returns:\n int: Port number\n ' return self._root_context.get('used_port', self.port)
@used_port.setter def used_port(self, value: int): 'Store the port used by the local proxy for later reference\n\n Args:\n value (int): Port number\n ' self._root_context['used_port'] = value
-7,539,411,045,327,996,000
Store the port used by the local proxy for later reference Args: value (int): Port number
c8ylp/cli/core.py
used_port
SoftwareAG/cumulocity-remote-access-local-proxy
python
@used_port.setter def used_port(self, value: int): 'Store the port used by the local proxy for later reference\n\n Args:\n value (int): Port number\n ' self._root_context['used_port'] = value
def exit_server_not_ready(self) -> NoReturn: 'Exit with a server not ready error\n\n Returns:\n NoReturn: The function does not return\n ' self.show_error(f'Timed out waiting for local port to open: port={self.used_port}, timeout={self.wait_port_timeout}s') self._ctx.exit(ExitCodes....
-3,488,656,533,846,449,700
Exit with a server not ready error Returns: NoReturn: The function does not return
c8ylp/cli/core.py
exit_server_not_ready
SoftwareAG/cumulocity-remote-access-local-proxy
python
def exit_server_not_ready(self) -> NoReturn: 'Exit with a server not ready error\n\n Returns:\n NoReturn: The function does not return\n ' self.show_error(f'Timed out waiting for local port to open: port={self.used_port}, timeout={self.wait_port_timeout}s') self._ctx.exit(ExitCodes....
def fromdict(self, src_dict: Dict[(str, Any)]) -> 'ProxyContext': 'Load proxy settings from a dictionary\n\n Args:\n src_dict (Dict[str, Any]): [description]\n\n Returns:\n ProxyContext: Proxy options after the values have been set\n via the dictionary\n ' ...
6,400,380,737,886,094,000
Load proxy settings from a dictionary Args: src_dict (Dict[str, Any]): [description] Returns: ProxyContext: Proxy options after the values have been set via the dictionary
c8ylp/cli/core.py
fromdict
SoftwareAG/cumulocity-remote-access-local-proxy
python
def fromdict(self, src_dict: Dict[(str, Any)]) -> 'ProxyContext': 'Load proxy settings from a dictionary\n\n Args:\n src_dict (Dict[str, Any]): [description]\n\n Returns:\n ProxyContext: Proxy options after the values have been set\n via the dictionary\n ' ...
def start_background(self, ctx: click.Context=None) -> 'ProxyContext': 'Start the local proxy in the background\n\n Returns:\n ProxyContext: Reference to the proxy context so it can be chained\n with other commands or used after the initialization of the class.\n ' cur_ct...
7,925,858,526,088,870,000
Start the local proxy in the background Returns: ProxyContext: Reference to the proxy context so it can be chained with other commands or used after the initialization of the class.
c8ylp/cli/core.py
start_background
SoftwareAG/cumulocity-remote-access-local-proxy
python
def start_background(self, ctx: click.Context=None) -> 'ProxyContext': 'Start the local proxy in the background\n\n Returns:\n ProxyContext: Reference to the proxy context so it can be chained\n with other commands or used after the initialization of the class.\n ' cur_ct...
def start(self, ctx: click.Context=None) -> None: 'Start the local proxy in the background\n\n Returns:\n ProxyContext: Reference to the proxy context so it can be chained\n with other commands or used after the initialization of the class.\n ' cur_ctx = (ctx or self._ctx...
-3,952,982,397,710,996,500
Start the local proxy in the background Returns: ProxyContext: Reference to the proxy context so it can be chained with other commands or used after the initialization of the class.
c8ylp/cli/core.py
start
SoftwareAG/cumulocity-remote-access-local-proxy
python
def start(self, ctx: click.Context=None) -> None: 'Start the local proxy in the background\n\n Returns:\n ProxyContext: Reference to the proxy context so it can be chained\n with other commands or used after the initialization of the class.\n ' cur_ctx = (ctx or self._ctx...
@classmethod def show_message(cls, msg: str, *args, **kwargs): 'Show an message to the user and log it\n\n Args:\n msg (str): User message to print on the console\n ' click.secho(msg, fg='green') logging.info(msg, *args, **kwargs)
-635,830,249,380,264,400
Show an message to the user and log it Args: msg (str): User message to print on the console
c8ylp/cli/core.py
show_message
SoftwareAG/cumulocity-remote-access-local-proxy
python
@classmethod def show_message(cls, msg: str, *args, **kwargs): 'Show an message to the user and log it\n\n Args:\n msg (str): User message to print on the console\n ' click.secho(msg, fg='green') logging.info(msg, *args, **kwargs)
def show_error(self, msg: str, *args, **kwargs): 'Show an error to the user and log it\n\n Args:\n msg (str): User message to print on the console\n ' if (not self.verbose): click.secho(msg, fg='red') logging.warning(msg, *args, **kwargs)
6,178,511,922,028,288,000
Show an error to the user and log it Args: msg (str): User message to print on the console
c8ylp/cli/core.py
show_error
SoftwareAG/cumulocity-remote-access-local-proxy
python
def show_error(self, msg: str, *args, **kwargs): 'Show an error to the user and log it\n\n Args:\n msg (str): User message to print on the console\n ' if (not self.verbose): click.secho(msg, fg='red') logging.warning(msg, *args, **kwargs)
def show_info(self, msg: str, *args, **kwargs): 'Show an info message to the user and log it\n\n Args:\n msg (str): User message to print on the console\n ' if (not self.verbose): click.secho(msg) logging.warning(msg, *args, **kwargs)
3,718,197,683,893,955,600
Show an info message to the user and log it Args: msg (str): User message to print on the console
c8ylp/cli/core.py
show_info
SoftwareAG/cumulocity-remote-access-local-proxy
python
def show_info(self, msg: str, *args, **kwargs): 'Show an info message to the user and log it\n\n Args:\n msg (str): User message to print on the console\n ' if (not self.verbose): click.secho(msg) logging.warning(msg, *args, **kwargs)
def show_warning(self, msg: str, *args, **kwargs): 'Show a warning to the user and log it\n\n Args:\n msg (str): User message to print on the console\n ' if (not self.verbose): click.secho(msg, fg='yellow') logging.warning(msg, *args, **kwargs)
-5,328,920,099,859,709,000
Show a warning to the user and log it Args: msg (str): User message to print on the console
c8ylp/cli/core.py
show_warning
SoftwareAG/cumulocity-remote-access-local-proxy
python
def show_warning(self, msg: str, *args, **kwargs): 'Show a warning to the user and log it\n\n Args:\n msg (str): User message to print on the console\n ' if (not self.verbose): click.secho(msg, fg='yellow') logging.warning(msg, *args, **kwargs)
def set_env(self): 'Set environment variables so information about the proxy can\n be access by plugins\n ' os.environ['C8Y_HOST'] = str(self.host) os.environ['PORT'] = str(self.used_port) os.environ['DEVICE'] = self.device os.environ['WSLENV'] = 'PORT/u:DEVICE/u:C8Y_HOST/u'
-3,005,475,876,850,048,500
Set environment variables so information about the proxy can be access by plugins
c8ylp/cli/core.py
set_env
SoftwareAG/cumulocity-remote-access-local-proxy
python
def set_env(self): 'Set environment variables so information about the proxy can\n be access by plugins\n ' os.environ['C8Y_HOST'] = str(self.host) os.environ['PORT'] = str(self.used_port) os.environ['DEVICE'] = self.device os.environ['WSLENV'] = 'PORT/u:DEVICE/u:C8Y_HOST/u'
@classmethod def log_path(cls) -> pathlib.Path: 'Get the log path' return (pathlib.Path(os.getenv('C8YLP_LOG_DIR', '~/.c8ylp/')).expanduser() / 'localproxy.log')
-4,331,468,252,760,386,000
Get the log path
c8ylp/cli/core.py
log_path
SoftwareAG/cumulocity-remote-access-local-proxy
python
@classmethod def log_path(cls) -> pathlib.Path: return (pathlib.Path(os.getenv('C8YLP_LOG_DIR', '~/.c8ylp/')).expanduser() / 'localproxy.log')
def get_ffme_returns(): '\n Load the Fama-French Dataset for the returns of the Top and Bottom Deciles by MarketCap\n ' me_m = pd.read_csv('data/Portfolios_Formed_on_ME_monthly_EW.csv', header=0, index_col=0, na_values=(- 99.99)) rets = me_m[['Lo 10', 'Hi 10']] rets.columns = ['SmallCap', 'LargeCa...
-8,356,439,846,472,406,000
Load the Fama-French Dataset for the returns of the Top and Bottom Deciles by MarketCap
kit.py
get_ffme_returns
jaimeaguilera/Investing-projects
python
def get_ffme_returns(): '\n \n ' me_m = pd.read_csv('data/Portfolios_Formed_on_ME_monthly_EW.csv', header=0, index_col=0, na_values=(- 99.99)) rets = me_m[['Lo 10', 'Hi 10']] rets.columns = ['SmallCap', 'LargeCap'] rets = (rets / 100) rets.index = pd.to_datetime(rets.index, format='%Y%m')....
def get_fff_returns(): '\n Load the Fama-French Research Factor Monthly Dataset\n ' rets = (pd.read_csv('data/F-F_Research_Data_Factors_m.csv', header=0, index_col=0, na_values=(- 99.99)) / 100) rets.index = pd.to_datetime(rets.index, format='%Y%m').to_period('M') return rets
-7,927,721,906,992,404,000
Load the Fama-French Research Factor Monthly Dataset
kit.py
get_fff_returns
jaimeaguilera/Investing-projects
python
def get_fff_returns(): '\n \n ' rets = (pd.read_csv('data/F-F_Research_Data_Factors_m.csv', header=0, index_col=0, na_values=(- 99.99)) / 100) rets.index = pd.to_datetime(rets.index, format='%Y%m').to_period('M') return rets
def get_hfi_returns(): '\n Load and format the EDHEC Hedge Fund Index Returns\n ' hfi = pd.read_csv('data/edhec-hedgefundindices.csv', header=0, index_col=0, parse_dates=True) hfi = (hfi / 100) hfi.index = hfi.index.to_period('M') return hfi
-2,043,821,786,576,152,000
Load and format the EDHEC Hedge Fund Index Returns
kit.py
get_hfi_returns
jaimeaguilera/Investing-projects
python
def get_hfi_returns(): '\n \n ' hfi = pd.read_csv('data/edhec-hedgefundindices.csv', header=0, index_col=0, parse_dates=True) hfi = (hfi / 100) hfi.index = hfi.index.to_period('M') return hfi
def get_ind_file(filetype, weighting='vw', n_inds=30): '\n Load and format the Ken French Industry Portfolios files\n Variant is a tuple of (weighting, size) where:\n weighting is one of "ew", "vw"\n number of inds is 30 or 49\n ' if (filetype is 'returns'): name = f'{weighting}_r...
-1,716,315,270,824,754,000
Load and format the Ken French Industry Portfolios files Variant is a tuple of (weighting, size) where: weighting is one of "ew", "vw" number of inds is 30 or 49
kit.py
get_ind_file
jaimeaguilera/Investing-projects
python
def get_ind_file(filetype, weighting='vw', n_inds=30): '\n Load and format the Ken French Industry Portfolios files\n Variant is a tuple of (weighting, size) where:\n weighting is one of "ew", "vw"\n number of inds is 30 or 49\n ' if (filetype is 'returns'): name = f'{weighting}_r...
def get_ind_returns(weighting='vw', n_inds=30): '\n Load and format the Ken French Industry Portfolios Monthly Returns\n ' return get_ind_file('returns', weighting=weighting, n_inds=n_inds)
8,765,230,633,926,116,000
Load and format the Ken French Industry Portfolios Monthly Returns
kit.py
get_ind_returns
jaimeaguilera/Investing-projects
python
def get_ind_returns(weighting='vw', n_inds=30): '\n \n ' return get_ind_file('returns', weighting=weighting, n_inds=n_inds)
def get_ind_nfirms(n_inds=30): '\n Load and format the Ken French 30 Industry Portfolios Average number of Firms\n ' return get_ind_file('nfirms', n_inds=n_inds)
-3,638,385,353,629,806,600
Load and format the Ken French 30 Industry Portfolios Average number of Firms
kit.py
get_ind_nfirms
jaimeaguilera/Investing-projects
python
def get_ind_nfirms(n_inds=30): '\n \n ' return get_ind_file('nfirms', n_inds=n_inds)
def get_ind_size(n_inds=30): '\n Load and format the Ken French 30 Industry Portfolios Average size (market cap)\n ' return get_ind_file('size', n_inds=n_inds)
-8,120,265,645,189,793,000
Load and format the Ken French 30 Industry Portfolios Average size (market cap)
kit.py
get_ind_size
jaimeaguilera/Investing-projects
python
def get_ind_size(n_inds=30): '\n \n ' return get_ind_file('size', n_inds=n_inds)
def get_ind_market_caps(n_inds=30, weights=False): '\n Load the industry portfolio data and derive the market caps\n ' ind_nfirms = get_ind_nfirms(n_inds=n_inds) ind_size = get_ind_size(n_inds=n_inds) ind_mktcap = (ind_nfirms * ind_size) if weights: total_mktcap = ind_mktcap.sum(axis=1...
-2,019,311,730,886,692,000
Load the industry portfolio data and derive the market caps
kit.py
get_ind_market_caps
jaimeaguilera/Investing-projects
python
def get_ind_market_caps(n_inds=30, weights=False): '\n \n ' ind_nfirms = get_ind_nfirms(n_inds=n_inds) ind_size = get_ind_size(n_inds=n_inds) ind_mktcap = (ind_nfirms * ind_size) if weights: total_mktcap = ind_mktcap.sum(axis=1) ind_capweight = ind_mktcap.divide(total_mktcap, a...
def get_total_market_index_returns(n_inds=30): '\n Load the 30 industry portfolio data and derive the returns of a capweighted total market index\n ' ind_capweight = get_ind_market_caps(n_inds=n_inds) ind_return = get_ind_returns(weighting='vw', n_inds=n_inds) total_market_return = (ind_capweight ...
-2,314,792,494,135,799,300
Load the 30 industry portfolio data and derive the returns of a capweighted total market index
kit.py
get_total_market_index_returns
jaimeaguilera/Investing-projects
python
def get_total_market_index_returns(n_inds=30): '\n \n ' ind_capweight = get_ind_market_caps(n_inds=n_inds) ind_return = get_ind_returns(weighting='vw', n_inds=n_inds) total_market_return = (ind_capweight * ind_return).sum(axis='columns') return total_market_return
def skewness(r): '\n Alternative to scipy.stats.skew()\n Computes the skewness of the supplied Series or DataFrame\n Returns a float or a Series\n ' r = r[((r != 0) & r.notnull())] demeaned_r = (r - r.mean()) sigma_r = r.std(ddof=0) exp = (demeaned_r ** 3).mean() return (exp / (sigma...
7,755,191,297,281,593,000
Alternative to scipy.stats.skew() Computes the skewness of the supplied Series or DataFrame Returns a float or a Series
kit.py
skewness
jaimeaguilera/Investing-projects
python
def skewness(r): '\n Alternative to scipy.stats.skew()\n Computes the skewness of the supplied Series or DataFrame\n Returns a float or a Series\n ' r = r[((r != 0) & r.notnull())] demeaned_r = (r - r.mean()) sigma_r = r.std(ddof=0) exp = (demeaned_r ** 3).mean() return (exp / (sigma...
def kurtosis(r): '\n Alternative to scipy.stats.kurtosis()\n Computes the kurtosis of the supplied Series or DataFrame\n Returns a float or a Series\n ' r = r[((r != 0) & r.notnull())] demeaned_r = (r - r.mean()) sigma_r = r.std(ddof=0) exp = (demeaned_r ** 4).mean() return (exp / (s...
-8,853,748,143,048,105,000
Alternative to scipy.stats.kurtosis() Computes the kurtosis of the supplied Series or DataFrame Returns a float or a Series
kit.py
kurtosis
jaimeaguilera/Investing-projects
python
def kurtosis(r): '\n Alternative to scipy.stats.kurtosis()\n Computes the kurtosis of the supplied Series or DataFrame\n Returns a float or a Series\n ' r = r[((r != 0) & r.notnull())] demeaned_r = (r - r.mean()) sigma_r = r.std(ddof=0) exp = (demeaned_r ** 4).mean() return (exp / (s...
def compound(r): '\n returns the result of compounding the set of returns in r\n ' return np.expm1(np.log1p(r).sum())
-5,716,126,220,503,370,000
returns the result of compounding the set of returns in r
kit.py
compound
jaimeaguilera/Investing-projects
python
def compound(r): '\n \n ' return np.expm1(np.log1p(r).sum())
def annualize_rets(r): '\n Annualizes a set of returns\n We should infer the periods per year\n but that is currently left as an exercise\n to the reader :-)\n ' r_valid = r[((r != 0) & r.notnull())] date_beg = r_valid.agg((lambda x: x.first_valid_index())) date_end = r_valid.agg((lambda ...
444,043,545,948,035,400
Annualizes a set of returns We should infer the periods per year but that is currently left as an exercise to the reader :-)
kit.py
annualize_rets
jaimeaguilera/Investing-projects
python
def annualize_rets(r): '\n Annualizes a set of returns\n We should infer the periods per year\n but that is currently left as an exercise\n to the reader :-)\n ' r_valid = r[((r != 0) & r.notnull())] date_beg = r_valid.agg((lambda x: x.first_valid_index())) date_end = r_valid.agg((lambda ...
def annualize_vol(r): '\n Annualizes the vol of a set of returns\n We should infer the periods per year\n but that is currently left as an exercise\n to the reader :-)\n ' r_valid = r[((r != 0) & r.notnull())] total_num_periods = r_valid.count() date_beg = r_valid.agg((lambda x: x.first_v...
4,409,763,613,660,388,000
Annualizes the vol of a set of returns We should infer the periods per year but that is currently left as an exercise to the reader :-)
kit.py
annualize_vol
jaimeaguilera/Investing-projects
python
def annualize_vol(r): '\n Annualizes the vol of a set of returns\n We should infer the periods per year\n but that is currently left as an exercise\n to the reader :-)\n ' r_valid = r[((r != 0) & r.notnull())] total_num_periods = r_valid.count() date_beg = r_valid.agg((lambda x: x.first_v...
def sharpe_ratio(r, riskfree_rate): '\n Computes the annualized sharpe ratio of a set of returns\n ' r_valid = r[((r != 0) & r.notnull())] total_num_periods = r_valid.count() date_beg = r_valid.agg((lambda x: x.first_valid_index())) date_end = r_valid.agg((lambda x: x.last_valid_index())) ...
2,533,955,272,572,073,000
Computes the annualized sharpe ratio of a set of returns
kit.py
sharpe_ratio
jaimeaguilera/Investing-projects
python
def sharpe_ratio(r, riskfree_rate): '\n \n ' r_valid = r[((r != 0) & r.notnull())] total_num_periods = r_valid.count() date_beg = r_valid.agg((lambda x: x.first_valid_index())) date_end = r_valid.agg((lambda x: x.last_valid_index())) try: years_fraction = ((date_end - date_beg).dt....
def is_normal(r, level=0.01): '\n Applies the Jarque-Bera test to determine if a Series is normal or not\n Test is applied at the 1% level by default\n Returns True if the hypothesis of normality is accepted, False otherwise\n ' if isinstance(r, pd.DataFrame): return r.aggregate(is_normal) ...
4,814,920,000,768,772,000
Applies the Jarque-Bera test to determine if a Series is normal or not Test is applied at the 1% level by default Returns True if the hypothesis of normality is accepted, False otherwise
kit.py
is_normal
jaimeaguilera/Investing-projects
python
def is_normal(r, level=0.01): '\n Applies the Jarque-Bera test to determine if a Series is normal or not\n Test is applied at the 1% level by default\n Returns True if the hypothesis of normality is accepted, False otherwise\n ' if isinstance(r, pd.DataFrame): return r.aggregate(is_normal) ...
def drawdown(return_series: pd.Series): 'Takes a time series of asset returns.\n returns a DataFrame with columns for\n the wealth index, \n the previous peaks, and \n the percentage drawdown\n ' wealth_index = (1000 * (1 + return_series).cumprod()) previous_peaks = wealth_index.c...
1,925,900,058,201,987,300
Takes a time series of asset returns. returns a DataFrame with columns for the wealth index, the previous peaks, and the percentage drawdown
kit.py
drawdown
jaimeaguilera/Investing-projects
python
def drawdown(return_series: pd.Series): 'Takes a time series of asset returns.\n returns a DataFrame with columns for\n the wealth index, \n the previous peaks, and \n the percentage drawdown\n ' wealth_index = (1000 * (1 + return_series).cumprod()) previous_peaks = wealth_index.c...
def semideviation(r): '\n Returns the semideviation aka negative semideviation of r\n r must be a Series or a DataFrame, else raises a TypeError\n ' if isinstance(r, pd.Series): is_negative = (r < 0) return r[is_negative].std(ddof=0) elif isinstance(r, pd.DataFrame): return ...
-1,785,064,964,747,070,700
Returns the semideviation aka negative semideviation of r r must be a Series or a DataFrame, else raises a TypeError
kit.py
semideviation
jaimeaguilera/Investing-projects
python
def semideviation(r): '\n Returns the semideviation aka negative semideviation of r\n r must be a Series or a DataFrame, else raises a TypeError\n ' if isinstance(r, pd.Series): is_negative = (r < 0) return r[is_negative].std(ddof=0) elif isinstance(r, pd.DataFrame): return ...
def var_historic(r, level=5): '\n Returns the historic Value at Risk at a specified level\n i.e. returns the number such that "level" percent of the returns\n fall below that number, and the (100-level) percent are above\n ' r = r[((r != 0) & r.notnull())] if isinstance(r, pd.DataFrame): ...
8,531,678,315,750,730,000
Returns the historic Value at Risk at a specified level i.e. returns the number such that "level" percent of the returns fall below that number, and the (100-level) percent are above
kit.py
var_historic
jaimeaguilera/Investing-projects
python
def var_historic(r, level=5): '\n Returns the historic Value at Risk at a specified level\n i.e. returns the number such that "level" percent of the returns\n fall below that number, and the (100-level) percent are above\n ' r = r[((r != 0) & r.notnull())] if isinstance(r, pd.DataFrame): ...
def cvar_historic(r, level=5): '\n Computes the Conditional VaR of Series or DataFrame\n ' r = r[((r != 0) & r.notnull())] if isinstance(r, pd.Series): is_beyond = (r <= (- var_historic(r, level=level))) return (- r[is_beyond].mean()) elif isinstance(r, pd.DataFrame): retur...
-3,315,997,735,787,485,000
Computes the Conditional VaR of Series or DataFrame
kit.py
cvar_historic
jaimeaguilera/Investing-projects
python
def cvar_historic(r, level=5): '\n \n ' r = r[((r != 0) & r.notnull())] if isinstance(r, pd.Series): is_beyond = (r <= (- var_historic(r, level=level))) return (- r[is_beyond].mean()) elif isinstance(r, pd.DataFrame): return r.aggregate(cvar_historic, level=level) else:...
def var_gaussian(r, level=5, modified=False): '\n Returns the Parametric Gauusian VaR of a Series or DataFrame\n If "modified" is True, then the modified VaR is returned,\n using the Cornish-Fisher modification\n ' r = r[((r != 0) & r.notnull())] z = norm.ppf((level / 100)) if modified: ...
4,522,035,123,193,760,300
Returns the Parametric Gauusian VaR of a Series or DataFrame If "modified" is True, then the modified VaR is returned, using the Cornish-Fisher modification
kit.py
var_gaussian
jaimeaguilera/Investing-projects
python
def var_gaussian(r, level=5, modified=False): '\n Returns the Parametric Gauusian VaR of a Series or DataFrame\n If "modified" is True, then the modified VaR is returned,\n using the Cornish-Fisher modification\n ' r = r[((r != 0) & r.notnull())] z = norm.ppf((level / 100)) if modified: ...
def portfolio_return(weights, returns): '\n Computes the return on a portfolio from constituent returns and weights\n weights are a numpy array or Nx1 matrix and returns are a numpy array or Nx1 matrix\n ' return (weights.T @ returns)
-1,847,745,247,972,241,200
Computes the return on a portfolio from constituent returns and weights weights are a numpy array or Nx1 matrix and returns are a numpy array or Nx1 matrix
kit.py
portfolio_return
jaimeaguilera/Investing-projects
python
def portfolio_return(weights, returns): '\n Computes the return on a portfolio from constituent returns and weights\n weights are a numpy array or Nx1 matrix and returns are a numpy array or Nx1 matrix\n ' return (weights.T @ returns)
def portfolio_vol(weights, covmat): '\n Computes the vol of a portfolio from a covariance matrix and constituent weights\n weights are a numpy array or N x 1 maxtrix and covmat is an N x N matrix\n ' vol = (((weights.T @ covmat) @ weights) ** 0.5) return vol
-3,955,678,057,595,877,400
Computes the vol of a portfolio from a covariance matrix and constituent weights weights are a numpy array or N x 1 maxtrix and covmat is an N x N matrix
kit.py
portfolio_vol
jaimeaguilera/Investing-projects
python
def portfolio_vol(weights, covmat): '\n Computes the vol of a portfolio from a covariance matrix and constituent weights\n weights are a numpy array or N x 1 maxtrix and covmat is an N x N matrix\n ' vol = (((weights.T @ covmat) @ weights) ** 0.5) return vol
def plot_ef2(n_points, er, cov): '\n Plots the 2-asset efficient frontier\n ' if ((er.shape[0] != 2) or (er.shape[0] != 2)): raise ValueError('plot_ef2 can only plot 2-asset frontiers') weights = [np.array([w, (1 - w)]) for w in np.linspace(0, 1, n_points)] rets = [portfolio_return(w, er) ...
6,113,814,886,680,996,000
Plots the 2-asset efficient frontier
kit.py
plot_ef2
jaimeaguilera/Investing-projects
python
def plot_ef2(n_points, er, cov): '\n \n ' if ((er.shape[0] != 2) or (er.shape[0] != 2)): raise ValueError('plot_ef2 can only plot 2-asset frontiers') weights = [np.array([w, (1 - w)]) for w in np.linspace(0, 1, n_points)] rets = [portfolio_return(w, er) for w in weights] vols = [portfo...
def minimize_vol(target_return, er, cov): '\n Returns the optimal weights that achieve the target return\n given a set of expected returns and a covariance matrix\n ' n = er.shape[0] init_guess = np.repeat((1 / n), n) bounds = (((0.0, 1.0),) * n) weights_sum_to_1 = {'type': 'eq', 'fun': (la...
7,147,474,082,142,541,000
Returns the optimal weights that achieve the target return given a set of expected returns and a covariance matrix
kit.py
minimize_vol
jaimeaguilera/Investing-projects
python
def minimize_vol(target_return, er, cov): '\n Returns the optimal weights that achieve the target return\n given a set of expected returns and a covariance matrix\n ' n = er.shape[0] init_guess = np.repeat((1 / n), n) bounds = (((0.0, 1.0),) * n) weights_sum_to_1 = {'type': 'eq', 'fun': (la...
def tracking_error(r_a, r_b): '\n Returns the Tracking Error between the two return series\n ' return np.sqrt(((r_a - r_b) ** 2).sum())
-6,295,209,354,440,144,000
Returns the Tracking Error between the two return series
kit.py
tracking_error
jaimeaguilera/Investing-projects
python
def tracking_error(r_a, r_b): '\n \n ' return np.sqrt(((r_a - r_b) ** 2).sum())
def msr(riskfree_rate, er, cov): '\n Returns the weights of the portfolio that gives you the maximum sharpe ratio\n given the riskfree rate and expected returns and a covariance matrix\n ' n = er.shape[0] init_guess = np.repeat((1 / n), n) bounds = (((0.0, 1.0),) * n) weights_sum_to_1 = {'t...
3,631,754,018,628,217,300
Returns the weights of the portfolio that gives you the maximum sharpe ratio given the riskfree rate and expected returns and a covariance matrix
kit.py
msr
jaimeaguilera/Investing-projects
python
def msr(riskfree_rate, er, cov): '\n Returns the weights of the portfolio that gives you the maximum sharpe ratio\n given the riskfree rate and expected returns and a covariance matrix\n ' n = er.shape[0] init_guess = np.repeat((1 / n), n) bounds = (((0.0, 1.0),) * n) weights_sum_to_1 = {'t...
def gmv(cov): '\n Returns the weights of the Global Minimum Volatility portfolio\n given a covariance matrix\n ' n = cov.shape[0] return msr(0, np.repeat(1, n), cov)
239,850,363,951,659,140
Returns the weights of the Global Minimum Volatility portfolio given a covariance matrix
kit.py
gmv
jaimeaguilera/Investing-projects
python
def gmv(cov): '\n Returns the weights of the Global Minimum Volatility portfolio\n given a covariance matrix\n ' n = cov.shape[0] return msr(0, np.repeat(1, n), cov)
def optimal_weights(n_points, er, cov): '\n Returns a list of weights that represent a grid of n_points on the efficient frontier\n ' target_rs = np.linspace(er.min(), er.max(), n_points) weights = [minimize_vol(target_return, er, cov) for target_return in target_rs] return weights
-8,565,410,215,275,897,000
Returns a list of weights that represent a grid of n_points on the efficient frontier
kit.py
optimal_weights
jaimeaguilera/Investing-projects
python
def optimal_weights(n_points, er, cov): '\n \n ' target_rs = np.linspace(er.min(), er.max(), n_points) weights = [minimize_vol(target_return, er, cov) for target_return in target_rs] return weights
def plot_ef(n_points, er, cov, style='.-', legend=False, show_cml=False, riskfree_rate=0, show_ew=False, show_gmv=False): '\n Plots the multi-asset efficient frontier\n ' weights = optimal_weights(n_points, er, cov) rets = [portfolio_return(w, er) for w in weights] vols = [portfolio_vol(w, cov) fo...
-588,327,934,387,513,900
Plots the multi-asset efficient frontier
kit.py
plot_ef
jaimeaguilera/Investing-projects
python
def plot_ef(n_points, er, cov, style='.-', legend=False, show_cml=False, riskfree_rate=0, show_ew=False, show_gmv=False): '\n \n ' weights = optimal_weights(n_points, er, cov) rets = [portfolio_return(w, er) for w in weights] vols = [portfolio_vol(w, cov) for w in weights] ef = pd.DataFrame({'...
def run_cppi(risky_r, safe_r=None, m=3, start=1000, floor=0.8, riskfree_rate=0.03, drawdown=None): '\n Run a backtest of the CPPI strategy, given a set of returns for the risky asset\n Returns a dictionary containing: Asset Value History, Risk Budget History, Risky Weight History\n ' dates = risky_r.in...
1,973,406,296,599,866,400
Run a backtest of the CPPI strategy, given a set of returns for the risky asset Returns a dictionary containing: Asset Value History, Risk Budget History, Risky Weight History
kit.py
run_cppi
jaimeaguilera/Investing-projects
python
def run_cppi(risky_r, safe_r=None, m=3, start=1000, floor=0.8, riskfree_rate=0.03, drawdown=None): '\n Run a backtest of the CPPI strategy, given a set of returns for the risky asset\n Returns a dictionary containing: Asset Value History, Risk Budget History, Risky Weight History\n ' dates = risky_r.in...
def summary_stats(r, riskfree_rate=0.03): '\n Return a DataFrame that contains aggregated summary stats for the returns in the columns of r\n ' ann_r = annualize_rets(r) ann_vol = annualize_vol(r) ann_sr = sharpe_ratio(r, riskfree_rate=riskfree_rate) dd = r.aggregate((lambda r: drawdown(r).Dra...
-3,695,334,458,142,436,400
Return a DataFrame that contains aggregated summary stats for the returns in the columns of r
kit.py
summary_stats
jaimeaguilera/Investing-projects
python
def summary_stats(r, riskfree_rate=0.03): '\n \n ' ann_r = annualize_rets(r) ann_vol = annualize_vol(r) ann_sr = sharpe_ratio(r, riskfree_rate=riskfree_rate) dd = r.aggregate((lambda r: drawdown(r).Drawdown.min())) skew = r.aggregate(skewness) kurt = r.aggregate(kurtosis) cf_var5 =...
def gbm(n_years=10, n_scenarios=1000, mu=0.07, sigma=0.15, steps_per_year=12, s_0=100.0, prices=True): '\n Evolution of Geometric Brownian Motion trajectories, such as for Stock Prices through Monte Carlo\n :param n_years: The number of years to generate data for\n :param n_paths: The number of scenarios/...
-5,941,378,999,358,949,000
Evolution of Geometric Brownian Motion trajectories, such as for Stock Prices through Monte Carlo :param n_years: The number of years to generate data for :param n_paths: The number of scenarios/trajectories :param mu: Annualized Drift, e.g. Market Return :param sigma: Annualized Volatility :param steps_per_year: gran...
kit.py
gbm
jaimeaguilera/Investing-projects
python
def gbm(n_years=10, n_scenarios=1000, mu=0.07, sigma=0.15, steps_per_year=12, s_0=100.0, prices=True): '\n Evolution of Geometric Brownian Motion trajectories, such as for Stock Prices through Monte Carlo\n :param n_years: The number of years to generate data for\n :param n_paths: The number of scenarios/...
def regress(dependent_variable, explanatory_variables, alpha=True): "\n Runs a linear regression to decompose the dependent variable into the explanatory variables\n returns an object of type statsmodel's RegressionResults on which you can call\n .summary() to print a full summary\n .params for th...
-2,629,055,977,376,220,700
Runs a linear regression to decompose the dependent variable into the explanatory variables returns an object of type statsmodel's RegressionResults on which you can call .summary() to print a full summary .params for the coefficients .tvalues and .pvalues for the significance levels .rsquared_adj and .rsqu...
kit.py
regress
jaimeaguilera/Investing-projects
python
def regress(dependent_variable, explanatory_variables, alpha=True): "\n Runs a linear regression to decompose the dependent variable into the explanatory variables\n returns an object of type statsmodel's RegressionResults on which you can call\n .summary() to print a full summary\n .params for th...
def portfolio_tracking_error(weights, ref_r, bb_r): '\n returns the tracking error between the reference returns\n and a portfolio of building block returns held with given weights\n ' return tracking_error(ref_r, (weights * bb_r).sum(axis=1))
-5,504,051,318,243,047,000
returns the tracking error between the reference returns and a portfolio of building block returns held with given weights
kit.py
portfolio_tracking_error
jaimeaguilera/Investing-projects
python
def portfolio_tracking_error(weights, ref_r, bb_r): '\n returns the tracking error between the reference returns\n and a portfolio of building block returns held with given weights\n ' return tracking_error(ref_r, (weights * bb_r).sum(axis=1))
def style_analysis(dependent_variable, explanatory_variables): '\n Returns the optimal weights that minimizes the Tracking error between\n a portfolio of the explanatory variables and the dependent variable\n ' n = explanatory_variables.shape[1] init_guess = np.repeat((1 / n), n) bounds = (((0....
-7,954,644,322,848,577,000
Returns the optimal weights that minimizes the Tracking error between a portfolio of the explanatory variables and the dependent variable
kit.py
style_analysis
jaimeaguilera/Investing-projects
python
def style_analysis(dependent_variable, explanatory_variables): '\n Returns the optimal weights that minimizes the Tracking error between\n a portfolio of the explanatory variables and the dependent variable\n ' n = explanatory_variables.shape[1] init_guess = np.repeat((1 / n), n) bounds = (((0....
def ff_analysis(r, factors): '\n Returns the loadings of r on the Fama French Factors\n which can be read in using get_fff_returns()\n the index of r must be a (not necessarily proper) subset of the index of factors\n r is either a Series or a DataFrame\n ' if isinstance(r, pd.Series): d...
5,331,380,417,579,062,000
Returns the loadings of r on the Fama French Factors which can be read in using get_fff_returns() the index of r must be a (not necessarily proper) subset of the index of factors r is either a Series or a DataFrame
kit.py
ff_analysis
jaimeaguilera/Investing-projects
python
def ff_analysis(r, factors): '\n Returns the loadings of r on the Fama French Factors\n which can be read in using get_fff_returns()\n the index of r must be a (not necessarily proper) subset of the index of factors\n r is either a Series or a DataFrame\n ' if isinstance(r, pd.Series): d...
def weight_ew(r, cap_weights=None, max_cw_mult=None, microcap_threshold=None, **kwargs): '\n Returns the weights of the EW portfolio based on the asset returns "r" as a DataFrame\n If supplied a set of capweights and a capweight tether, it is applied and reweighted \n ' n = len(r.columns) ew = pd.S...
8,770,652,885,608,347,000
Returns the weights of the EW portfolio based on the asset returns "r" as a DataFrame If supplied a set of capweights and a capweight tether, it is applied and reweighted
kit.py
weight_ew
jaimeaguilera/Investing-projects
python
def weight_ew(r, cap_weights=None, max_cw_mult=None, microcap_threshold=None, **kwargs): '\n Returns the weights of the EW portfolio based on the asset returns "r" as a DataFrame\n If supplied a set of capweights and a capweight tether, it is applied and reweighted \n ' n = len(r.columns) ew = pd.S...
def weight_cw(r, cap_weights, **kwargs): '\n Returns the weights of the CW portfolio based on the time series of capweights\n ' w = cap_weights.loc[r.index[1]] return (w / w.sum())
345,298,233,300,992,060
Returns the weights of the CW portfolio based on the time series of capweights
kit.py
weight_cw
jaimeaguilera/Investing-projects
python
def weight_cw(r, cap_weights, **kwargs): '\n \n ' w = cap_weights.loc[r.index[1]] return (w / w.sum())
def backtest_ws(r, estimation_window=60, weighting=weight_ew, verbose=False, **kwargs): '\n Backtests a given weighting scheme, given some parameters:\n r : asset returns to use to build the portfolio\n estimation_window: the window to use to estimate parameters\n weighting: the weighting scheme to use,...
4,342,074,272,339,228,000
Backtests a given weighting scheme, given some parameters: r : asset returns to use to build the portfolio estimation_window: the window to use to estimate parameters weighting: the weighting scheme to use, must be a function that takes "r", and a variable number of keyword-value arguments
kit.py
backtest_ws
jaimeaguilera/Investing-projects
python
def backtest_ws(r, estimation_window=60, weighting=weight_ew, verbose=False, **kwargs): '\n Backtests a given weighting scheme, given some parameters:\n r : asset returns to use to build the portfolio\n estimation_window: the window to use to estimate parameters\n weighting: the weighting scheme to use,...
def sample_cov(r, **kwargs): '\n Returns the sample covariance of the supplied returns\n ' return r.cov()
3,398,896,989,843,861,500
Returns the sample covariance of the supplied returns
kit.py
sample_cov
jaimeaguilera/Investing-projects
python
def sample_cov(r, **kwargs): '\n \n ' return r.cov()
def weight_gmv(r, cov_estimator=sample_cov, **kwargs): '\n Produces the weights of the GMV portfolio given a covariance matrix of the returns \n ' est_cov = cov_estimator(r, **kwargs) return gmv(est_cov)
-4,044,872,262,371,711,500
Produces the weights of the GMV portfolio given a covariance matrix of the returns
kit.py
weight_gmv
jaimeaguilera/Investing-projects
python
def weight_gmv(r, cov_estimator=sample_cov, **kwargs): '\n \n ' est_cov = cov_estimator(r, **kwargs) return gmv(est_cov)
def cc_cov(r, **kwargs): '\n Estimates a covariance matrix by using the Elton/Gruber Constant Correlation model\n ' rhos = r.corr() n = rhos.shape[0] rho_bar = ((rhos.values.sum() - n) / (n * (n - 1))) ccor = np.full_like(rhos, rho_bar) np.fill_diagonal(ccor, 1.0) sd = r.std() retu...
-2,987,201,178,320,407,000
Estimates a covariance matrix by using the Elton/Gruber Constant Correlation model
kit.py
cc_cov
jaimeaguilera/Investing-projects
python
def cc_cov(r, **kwargs): '\n \n ' rhos = r.corr() n = rhos.shape[0] rho_bar = ((rhos.values.sum() - n) / (n * (n - 1))) ccor = np.full_like(rhos, rho_bar) np.fill_diagonal(ccor, 1.0) sd = r.std() return pd.DataFrame((ccor * np.outer(sd, sd)), index=r.columns, columns=r.columns)
def shrinkage_cov(r, delta=0.5, **kwargs): '\n Covariance estimator that shrinks between the Sample Covariance and the Constant Correlation Estimators\n ' prior = cc_cov(r, **kwargs) sample = sample_cov(r, **kwargs) return ((delta * prior) + ((1 - delta) * sample))
7,209,318,898,781,462,000
Covariance estimator that shrinks between the Sample Covariance and the Constant Correlation Estimators
kit.py
shrinkage_cov
jaimeaguilera/Investing-projects
python
def shrinkage_cov(r, delta=0.5, **kwargs): '\n \n ' prior = cc_cov(r, **kwargs) sample = sample_cov(r, **kwargs) return ((delta * prior) + ((1 - delta) * sample))
def risk_contribution(w, cov): '\n Compute the contributions to risk of the constituents of a portfolio, given a set of portfolio weights and a covariance matrix\n ' total_portfolio_var = (portfolio_vol(w, cov) ** 2) marginal_contrib = (cov @ w) risk_contrib = (np.multiply(marginal_contrib, w.T) /...
499,167,234,481,604,100
Compute the contributions to risk of the constituents of a portfolio, given a set of portfolio weights and a covariance matrix
kit.py
risk_contribution
jaimeaguilera/Investing-projects
python
def risk_contribution(w, cov): '\n \n ' total_portfolio_var = (portfolio_vol(w, cov) ** 2) marginal_contrib = (cov @ w) risk_contrib = (np.multiply(marginal_contrib, w.T) / total_portfolio_var) return risk_contrib
def target_risk_contributions(target_risk, cov): '\n Returns the weights of the portfolio that gives you the weights such\n that the contributions to portfolio risk are as close as possible to\n the target_risk, given the covariance matrix\n ' n = cov.shape[0] init_guess = np.repeat((1 / n), n) ...
-6,586,840,443,301,521,000
Returns the weights of the portfolio that gives you the weights such that the contributions to portfolio risk are as close as possible to the target_risk, given the covariance matrix
kit.py
target_risk_contributions
jaimeaguilera/Investing-projects
python
def target_risk_contributions(target_risk, cov): '\n Returns the weights of the portfolio that gives you the weights such\n that the contributions to portfolio risk are as close as possible to\n the target_risk, given the covariance matrix\n ' n = cov.shape[0] init_guess = np.repeat((1 / n), n) ...
def equal_risk_contributions(cov): '\n Returns the weights of the portfolio that equalizes the contributions\n of the constituents based on the given covariance matrix\n ' n = cov.shape[0] return target_risk_contributions(target_risk=np.repeat((1 / n), n), cov=cov)
-4,143,323,565,454,961,700
Returns the weights of the portfolio that equalizes the contributions of the constituents based on the given covariance matrix
kit.py
equal_risk_contributions
jaimeaguilera/Investing-projects
python
def equal_risk_contributions(cov): '\n Returns the weights of the portfolio that equalizes the contributions\n of the constituents based on the given covariance matrix\n ' n = cov.shape[0] return target_risk_contributions(target_risk=np.repeat((1 / n), n), cov=cov)
def weight_erc(r, cov_estimator=sample_cov, **kwargs): '\n Produces the weights of the ERC portfolio given a covariance matrix of the returns \n ' est_cov = cov_estimator(r, **kwargs) return equal_risk_contributions(est_cov)
1,028,696,242,090,410,500
Produces the weights of the ERC portfolio given a covariance matrix of the returns
kit.py
weight_erc
jaimeaguilera/Investing-projects
python
def weight_erc(r, cov_estimator=sample_cov, **kwargs): '\n \n ' est_cov = cov_estimator(r, **kwargs) return equal_risk_contributions(est_cov)
def implied_returns(delta, sigma, w): '\nObtain the implied expected returns by reverse engineering the weights\nInputs:\ndelta: Risk Aversion Coefficient (scalar)\nsigma: Variance-Covariance Matrix (N x N) as DataFrame\n w: Portfolio weights (N x 1) as Series\nReturns an N x 1 vector of Returns as Series\n '...
-2,040,071,156,509,215,700
Obtain the implied expected returns by reverse engineering the weights Inputs: delta: Risk Aversion Coefficient (scalar) sigma: Variance-Covariance Matrix (N x N) as DataFrame w: Portfolio weights (N x 1) as Series Returns an N x 1 vector of Returns as Series
kit.py
implied_returns
jaimeaguilera/Investing-projects
python
def implied_returns(delta, sigma, w): '\nObtain the implied expected returns by reverse engineering the weights\nInputs:\ndelta: Risk Aversion Coefficient (scalar)\nsigma: Variance-Covariance Matrix (N x N) as DataFrame\n w: Portfolio weights (N x 1) as Series\nReturns an N x 1 vector of Returns as Series\n '...
def proportional_prior(sigma, tau, p): '\n Returns the He-Litterman simplified Omega\n Inputs:\n sigma: N x N Covariance Matrix as DataFrame\n tau: a scalar\n p: a K x N DataFrame linking Q and Assets\n returns a P x P DataFrame, a Matrix representing Prior Uncertainties\n ' helit_omega = p...
-3,693,253,497,267,448,300
Returns the He-Litterman simplified Omega Inputs: sigma: N x N Covariance Matrix as DataFrame tau: a scalar p: a K x N DataFrame linking Q and Assets returns a P x P DataFrame, a Matrix representing Prior Uncertainties
kit.py
proportional_prior
jaimeaguilera/Investing-projects
python
def proportional_prior(sigma, tau, p): '\n Returns the He-Litterman simplified Omega\n Inputs:\n sigma: N x N Covariance Matrix as DataFrame\n tau: a scalar\n p: a K x N DataFrame linking Q and Assets\n returns a P x P DataFrame, a Matrix representing Prior Uncertainties\n ' helit_omega = p...
def bl(w_prior, sigma_prior, p, q, omega=None, delta=2.5, tau=0.02): '\n# Computes the posterior expected returns based on \n# the original black litterman reference model\n#\n# W.prior must be an N x 1 vector of weights, a Series\n# Sigma.prior is an N x N covariance matrix, a DataFrame\n# P must be a K x N matrix...
-185,691,400,770,407,680
# Computes the posterior expected returns based on # the original black litterman reference model # # W.prior must be an N x 1 vector of weights, a Series # Sigma.prior is an N x N covariance matrix, a DataFrame # P must be a K x N matrix linking Q and the Assets, a DataFrame # Q must be an K x 1 vector of views, a Se...
kit.py
bl
jaimeaguilera/Investing-projects
python
def bl(w_prior, sigma_prior, p, q, omega=None, delta=2.5, tau=0.02): '\n# Computes the posterior expected returns based on \n# the original black litterman reference model\n#\n# W.prior must be an N x 1 vector of weights, a Series\n# Sigma.prior is an N x N covariance matrix, a DataFrame\n# P must be a K x N matrix...
def inverse(d): '\n Invert the dataframe by inverting the underlying matrix\n ' return pd.DataFrame(inv(d.values), index=d.columns, columns=d.index)
-3,257,535,559,224,084,500
Invert the dataframe by inverting the underlying matrix
kit.py
inverse
jaimeaguilera/Investing-projects
python
def inverse(d): '\n \n ' return pd.DataFrame(inv(d.values), index=d.columns, columns=d.index)
def weight_msr(sigma, mu, scale=True): '\n Optimal (Tangent/Max Sharpe Ratio) Portfolio weights\n by using the Markowitz Optimization Procedure\n Mu is the vector of Excess expected Returns\n Sigma must be an N x N matrix as a DataFrame and Mu a column vector as a Series\n This implements page 188 Eq...
1,760,906,879,167,205,600
Optimal (Tangent/Max Sharpe Ratio) Portfolio weights by using the Markowitz Optimization Procedure Mu is the vector of Excess expected Returns Sigma must be an N x N matrix as a DataFrame and Mu a column vector as a Series This implements page 188 Equation 5.2.28 of "The econometrics of financial markets" Campbell, Lo ...
kit.py
weight_msr
jaimeaguilera/Investing-projects
python
def weight_msr(sigma, mu, scale=True): '\n Optimal (Tangent/Max Sharpe Ratio) Portfolio weights\n by using the Markowitz Optimization Procedure\n Mu is the vector of Excess expected Returns\n Sigma must be an N x N matrix as a DataFrame and Mu a column vector as a Series\n This implements page 188 Eq...
def neg_sharpe(weights, riskfree_rate, er, cov): '\n Returns the negative of the sharpe ratio\n of the given portfolio\n ' r = portfolio_return(weights, er) vol = portfolio_vol(weights, cov) return ((- (r - riskfree_rate)) / vol)
-5,140,026,034,260,675,000
Returns the negative of the sharpe ratio of the given portfolio
kit.py
neg_sharpe
jaimeaguilera/Investing-projects
python
def neg_sharpe(weights, riskfree_rate, er, cov): '\n Returns the negative of the sharpe ratio\n of the given portfolio\n ' r = portfolio_return(weights, er) vol = portfolio_vol(weights, cov) return ((- (r - riskfree_rate)) / vol)
def msd_risk(weights, target_risk, cov): '\n Returns the Mean Squared Difference in risk contributions\n between weights and target_risk\n ' w_contribs = risk_contribution(weights, cov) return ((w_contribs - target_risk) ** 2).sum()
-1,417,795,964,434,329,000
Returns the Mean Squared Difference in risk contributions between weights and target_risk
kit.py
msd_risk
jaimeaguilera/Investing-projects
python
def msd_risk(weights, target_risk, cov): '\n Returns the Mean Squared Difference in risk contributions\n between weights and target_risk\n ' w_contribs = risk_contribution(weights, cov) return ((w_contribs - target_risk) ** 2).sum()
def __init__(self, datasetPathList, nodeList, group, level='dataset', priority='normal', move='n', static='n', custodial='n', request_only='y', blocks=None, subscriptionId=(- 1), comments=''): '\n Initialize PhEDEx subscription with default value\n ' if isinstance(datasetPathList, basestring): ...
-6,030,256,932,251,470,000
Initialize PhEDEx subscription with default value
src/python/WMCore/Services/PhEDEx/DataStructs/SubscriptionList.py
__init__
cbbrainerd/WMCore
python
def __init__(self, datasetPathList, nodeList, group, level='dataset', priority='normal', move='n', static='n', custodial='n', request_only='y', blocks=None, subscriptionId=(- 1), comments=): '\n \n ' if isinstance(datasetPathList, basestring): datasetPathList = [datasetPathList] if isi...
def __str__(self): '\n Write out useful information for this object\n :return:\n ' res = {'datasetPaths': self.datasetPaths, 'nodes': self.nodes, 'priority': self.priority, 'move': self.move, 'group': self.group, 'custodial': self.custodial, 'request_only': self.request_only, 'blocks': self...
-1,481,429,788,718,934,000
Write out useful information for this object :return:
src/python/WMCore/Services/PhEDEx/DataStructs/SubscriptionList.py
__str__
cbbrainerd/WMCore
python
def __str__(self): '\n Write out useful information for this object\n :return:\n ' res = {'datasetPaths': self.datasetPaths, 'nodes': self.nodes, 'priority': self.priority, 'move': self.move, 'group': self.group, 'custodial': self.custodial, 'request_only': self.request_only, 'blocks': self...
def getDatasetsAndBlocks(self): '\n _getDatasetsAndBlocks_\n\n Get the block structure\n with datasets and blocks\n ' return self.blocks
7,009,327,071,037,417,000
_getDatasetsAndBlocks_ Get the block structure with datasets and blocks
src/python/WMCore/Services/PhEDEx/DataStructs/SubscriptionList.py
getDatasetsAndBlocks
cbbrainerd/WMCore
python
def getDatasetsAndBlocks(self): '\n _getDatasetsAndBlocks_\n\n Get the block structure\n with datasets and blocks\n ' return self.blocks
def matchesExistingTransferRequest(self, phedexDataSvc): '\n _matchesExistingTransferRequest_\n\n Check the given phedex data service to verify if an unapproved\n transfer request equal to this subscription is already in the system.\n ' if ((len(self.datasetPaths) != 1) or (len(self....
6,305,325,705,504,872,000
_matchesExistingTransferRequest_ Check the given phedex data service to verify if an unapproved transfer request equal to this subscription is already in the system.
src/python/WMCore/Services/PhEDEx/DataStructs/SubscriptionList.py
matchesExistingTransferRequest
cbbrainerd/WMCore
python
def matchesExistingTransferRequest(self, phedexDataSvc): '\n _matchesExistingTransferRequest_\n\n Check the given phedex data service to verify if an unapproved\n transfer request equal to this subscription is already in the system.\n ' if ((len(self.datasetPaths) != 1) or (len(self....
def matchesExistingSubscription(self, phedexDataSvc): '\n _matchesExistingSubscription_\n\n Check the given phedex data service to verify if a PhEDEx subscription\n equal to this subscription is already in the system.\n ' if ((len(self.datasetPaths) != 1) or (len(self.nodes) != 1)): ...
1,436,007,145,053,543,200
_matchesExistingSubscription_ Check the given phedex data service to verify if a PhEDEx subscription equal to this subscription is already in the system.
src/python/WMCore/Services/PhEDEx/DataStructs/SubscriptionList.py
matchesExistingSubscription
cbbrainerd/WMCore
python
def matchesExistingSubscription(self, phedexDataSvc): '\n _matchesExistingSubscription_\n\n Check the given phedex data service to verify if a PhEDEx subscription\n equal to this subscription is already in the system.\n ' if ((len(self.datasetPaths) != 1) or (len(self.nodes) != 1)): ...
def addSubscription(self, subObj): '\n _addSubscription_\n Add a new subscription to the subscription policy.\n If the same subscription key exist just add the node list\n ' for subscription in self._subList: if subscription.isEqualOptions(subObj): if subscription...
5,781,099,127,773,631,000
_addSubscription_ Add a new subscription to the subscription policy. If the same subscription key exist just add the node list
src/python/WMCore/Services/PhEDEx/DataStructs/SubscriptionList.py
addSubscription
cbbrainerd/WMCore
python
def addSubscription(self, subObj): '\n _addSubscription_\n Add a new subscription to the subscription policy.\n If the same subscription key exist just add the node list\n ' for subscription in self._subList: if subscription.isEqualOptions(subObj): if subscription...
def compact(self): '\n _compact_\n\n Compact the subscription list by aggregating the subscriptions where the nodes\n share a list of dataset paths.\n ' bags = [] baggedIndexes = set() for (i, subscriptionA) in enumerate(self._subList): if (i in baggedIndexes): ...
2,831,347,083,717,089,300
_compact_ Compact the subscription list by aggregating the subscriptions where the nodes share a list of dataset paths.
src/python/WMCore/Services/PhEDEx/DataStructs/SubscriptionList.py
compact
cbbrainerd/WMCore
python
def compact(self): '\n _compact_\n\n Compact the subscription list by aggregating the subscriptions where the nodes\n share a list of dataset paths.\n ' bags = [] baggedIndexes = set() for (i, subscriptionA) in enumerate(self._subList): if (i in baggedIndexes): ...
def get_source(category): '\n function that gets the json response to our url request\n ' get_source_url = NEWS_API_BASE_URL.format(category, api_key) print(get_source_url) with urllib.request.urlopen(get_source_url) as url: get_source_data = url.read() get_source_response = json.l...
2,996,768,572,009,040,400
function that gets the json response to our url request
app/requests.py
get_source
ClarisseU/newsHighlight
python
def get_source(category): '\n \n ' get_source_url = NEWS_API_BASE_URL.format(category, api_key) print(get_source_url) with urllib.request.urlopen(get_source_url) as url: get_source_data = url.read() get_source_response = json.loads(get_source_data) sources_result = None ...
def process_sources(sources_list): '\n Function that checks the news results and turn them into objects\n \n Args:\n sources_list: A list of dictionaries that contain sources details\n ' sources_result = [] for source_item in sources_list: author = source_item.get('author') ...
5,628,184,623,351,458,000
Function that checks the news results and turn them into objects Args: sources_list: A list of dictionaries that contain sources details
app/requests.py
process_sources
ClarisseU/newsHighlight
python
def process_sources(sources_list): '\n Function that checks the news results and turn them into objects\n \n Args:\n sources_list: A list of dictionaries that contain sources details\n ' sources_result = [] for source_item in sources_list: author = source_item.get('author') ...
def get_articles(id): '\n Function that processes the articles and returns a list of articles objects\n ' get_articles_url = ARTICLE.format(id, api_key) print(get_articles_url) with urllib.request.urlopen(get_articles_url) as url: article_data = url.read() articles_response = json....
-5,579,780,585,189,511,000
Function that processes the articles and returns a list of articles objects
app/requests.py
get_articles
ClarisseU/newsHighlight
python
def get_articles(id): '\n \n ' get_articles_url = ARTICLE.format(id, api_key) print(get_articles_url) with urllib.request.urlopen(get_articles_url) as url: article_data = url.read() articles_response = json.loads(article_data) articles_object = None if articles_resp...