Dataset Viewer
Auto-converted to Parquet Duplicate
repo
stringclasses
56 values
func_sig
stringlengths
3
801
func_type
stringclasses
2 values
context
stringlengths
113
343k
docstring
stringlengths
4
16.7k
func
stringlengths
80
318k
metadata
dict
bbfamily/abu
do_symbols_with_same_factors(target_symbols, benchmark, buy_factors, sell_factors, capital, apply_capital, kl_pd_manager, show, back_target_symbols, func_factors, show_progress)
function
Code snippets that use function: snippet 1: buy_factors = sub_dict['buy_factors'] sell_factors = sub_dict['sell_factors'] return buy_factors, sell_factors # 通过funcFactors在内层解开factors dict return do_symbols_with_same_factors(target_symbols, benchmark, None, None, capital, apply_capital=apply_cap...
输入为多个择时交易对象,以及相同的择时买入,卖出因子序列,对多个交易对象上实施相同的因子 :param target_symbols: 多个择时交易对象序列 :param benchmark: 交易基准对象,AbuBenchmark实例对象 :param buy_factors: 买入因子序列 :param sell_factors: 卖出因子序列 :param capital: AbuCapital实例对象 :param apply_capital: 是否进行资金对象的融合,多进程环境下将是False :param kl_pd_manager: 金融时间序列管理对象,AbuK...
from ..TradeBu import ABuTradeProxy from .ABuPickTimeWorker import AbuPickTimeWorker import pandas as pd import logging from ..UtilBu.ABuProgress import AbuMulPidProgress from ..TradeBu import ABuTradeExecute import numpy as np from ..CoreBu.ABuEnvProcess import add_process_env_sig from ..TradeBu.ABuKLManager i...
{ "api_call_count": 3, "dependencies_summary": { "classes_count": 1, "constants_count": 0, "functions_count": 2, "imports_count": 9, "variables_count": 11 }, "function_calls_found": 1, "function_name": "do_symbols_with_same_factors", "independence_code_length": 172, "matched_apis": [ ...
bbfamily/abu
do_symbols_with_same_factors_process(cls, target_symbols, benchmark, buy_factors, sell_factors, capital, kl_pd_manager, n_process_kl, n_process_pick_time, show_progress)
class_method
Code snippets that use function: snippet 1: # 在择时之前清理一下输出, 不能wait, windows上一些浏览器会卡死 ABuProgress.do_clear_output(wait=False) # 择时策略运行,多进程方式 orders_pd, action_pd, all_fit_symbols_cnt = AbuPickTimeMaster.do_symbols_with_same_factors_process( choice_symbols, benchmark, buy_factors, sell_factors...
将多个交易对象拆解为多份交易对象序列,多任务并行完成择时工作 :param target_symbols: 多个择时交易对象序列 :param benchmark: 交易基准对象,AbuBenchmark实例对象 :param buy_factors: 买入因子序列 :param sell_factors: 卖出因子序列 :param capital: AbuCapital实例对象 :param kl_pd_manager: 金融时间序列管理对象,AbuKLManager实例 :param n_process_kl: 控制...
from ..CoreBu import ABuEnv import pandas as pd from .ABuPickTimeExecute import do_symbols_with_same_factors import numpy as np from ..TradeBu import ABuTradeExecute from ..CoreBu.ABuParallel import delayed, Parallel from ..MarketBu.ABuMarket import split_k_market from ..CoreBu.ABuEnvProcess import AbuEnvProcess...
{ "api_call_count": 4, "dependencies_summary": { "classes_count": 0, "constants_count": 0, "functions_count": 0, "imports_count": 11, "variables_count": 10 }, "function_calls_found": 3, "function_name": "do_symbols_with_same_factors_process", "independence_code_length": 84, "matched_ap...
bbfamily/abu
store_abu_result_tuple(abu_result_tuple, n_folds, store_type, custom_name)
function
Code snippets that use function: snippet 1: :param abu_result_tuple: AbuResultTuple对象类型 :param n_folds: 回测执行了几年,只影响存贮文件名 :param store_type: 回测保存类型EStoreAbu类型,只影响存贮文件名 :param custom_name: 如果store_type=EStoreAbu.E_STORE_CUSTOM_NAME时需要的自定义文件名称 """ ABuStore.store_abu_result_tuple(abu_result_tuple, n_fol...
保存abu.run_loop_back的回测结果AbuResultTuple对象,根据n_folds,store_type参数 来定义存储的文件名称,透传参数使用ABuStore.store_abu_result_tuple执行操作 :param abu_result_tuple: AbuResultTuple对象类型 :param n_folds: 回测执行了几年,只影响存贮文件名 :param store_type: 回测保存类型EStoreAbu类型,只影响存贮文件名 :param custom_name: 如果store_type=EStoreAbu.E_STORE_CUSTOM_N...
from ..CoreBu import ABuStore from ..CoreBu.ABuStore import EStoreAbu def store_abu_result_tuple(abu_result_tuple, n_folds=None, store_type=EStoreAbu.E_STORE_NORMAL, custom_name=None): """ 保存abu.run_loop_back的回测结果AbuResultTuple对象,根据n_folds,store_type参数 来定义存储的文件名称,透传参数使用ABuStore.store_abu_result_tuple执行操作 ...
{ "api_call_count": 3, "dependencies_summary": { "classes_count": 0, "constants_count": 0, "functions_count": 0, "imports_count": 2, "variables_count": 0 }, "function_calls_found": 1, "function_name": "store_abu_result_tuple", "independence_code_length": 15, "matched_apis": [ "ESto...
bbfamily/abu
load_abu_result_tuple(n_folds, store_type, custom_name)
function
Code snippets that use function: snippet 1: :param n_folds: 回测执行了几年,只影响读取的文件名 :param store_type: 回测保存类型EStoreAbu类型,只影响读取的文件名 :param custom_name: 如果store_type=EStoreAbu.E_STORE_CUSTOM_NAME时需要的自定义文件名称 :return: AbuResultTuple对象 """ return ABuStore.load_abu_result_tuple(n_folds, store_type, custom_name=...
读取使用store_abu_result_tuple保存的回测结果,根据n_folds,store_type参数 来定义读取的文件名称,依次读取orders_pd,action_pd,capital,benchmark后构造 AbuResultTuple对象返回,透传参数使用ABuStore.load_abu_result_tuple执行操作 :param n_folds: 回测执行了几年,只影响读取的文件名 :param store_type: 回测保存类型EStoreAbu类型,只影响读取的文件名 :param custom_name: 如果store_type=EStoreAbu.E_...
from ..CoreBu import ABuStore from ..CoreBu.ABuStore import EStoreAbu def load_abu_result_tuple(n_folds=None, store_type=EStoreAbu.E_STORE_NORMAL, custom_name=None): """ 读取使用store_abu_result_tuple保存的回测结果,根据n_folds,store_type参数 来定义读取的文件名称,依次读取orders_pd,action_pd,capital,benchmark后构造 AbuResultTuple对象返回,...
{ "api_call_count": 3, "dependencies_summary": { "classes_count": 0, "constants_count": 0, "functions_count": 0, "imports_count": 2, "variables_count": 0 }, "function_calls_found": 1, "function_name": "load_abu_result_tuple", "independence_code_length": 16, "matched_apis": [ "EStor...
bbfamily/abu
init_plot_set()
function
Code snippets that use function: snippet 1: import matplotlib # conda 5.0后需要添加单独matplotlib的figure设置否则pandas的plot size不生效 matplotlib.rcParams['figure.figsize'] = g_plt_figsize init_plot_set()
全局plot设置
import seaborn as sns import matplotlib g_plt_figsize = (14, 7) def init_plot_set(): """全局plot设置""" import seaborn as sns sns.set_context('notebook', rc={'figure.figsize': g_plt_figsize}) sns.set_style('darkgrid') import matplotlib matplotlib.rcParams['figure.figsize'] = g_plt_figsize
{ "api_call_count": 6, "dependencies_summary": { "classes_count": 0, "constants_count": 0, "functions_count": 0, "imports_count": 2, "variables_count": 1 }, "function_calls_found": 1, "function_name": "init_plot_set", "independence_code_length": 13, "matched_apis": [ "sns", "ma...
bbfamily/abu
check_random_state(seed)
function
Code snippets that use function: snippet 1: self.shuffle = shuffle self.random_state = random_state self.idxs = np.arange(n) if shuffle: rng = check_random_state(self.random_state) rng.shuffle(self.idxs) def __iter__(s...
No docstring found
import numbers import numpy as np def check_random_state(seed): if seed is None or seed is np.random: return np.random.mtrand._rand if isinstance(seed, (numbers.Integral, np.integer)): return np.random.RandomState(seed) if isinstance(seed, np.random.RandomState): return seed ra...
{ "api_call_count": 6, "dependencies_summary": { "classes_count": 0, "constants_count": 0, "functions_count": 0, "imports_count": 2, "variables_count": 0 }, "function_calls_found": 1, "function_name": "check_random_state", "independence_code_length": 12, "matched_apis": [ "np", ...
bbfamily/abu
__pd_object_covert_start(iter_obj)
function
Code snippets that use function: snippet 1: @functools.wraps(func) def wrapper(pd_object, pd_object_cm, how, *args, **kwargs): """事前装饰工作__pd_object_covert_start,事后根据是否需要转换为np.array工作""" # 事前装饰工作__pd_object_covert_start pd_object, ret_covert = __pd_object_covert_start(pd_object) ret =...
_pd_object_covert中进行参数检测及转换 :param iter_obj: 将要进行操作的可迭代序列 :return: 操作之后的返回值是否需要转换为np.array
from collections import Iterable import pandas as pd from ..CoreBu.ABuFixes import six def __pd_object_covert_start(iter_obj): """ _pd_object_covert中进行参数检测及转换 :param iter_obj: 将要进行操作的可迭代序列 :return: 操作之后的返回值是否需要转换为np.array """ if isinstance(iter_obj, (pd.Series, pd.DataFrame)): return ...
{ "api_call_count": 3, "dependencies_summary": { "classes_count": 0, "constants_count": 0, "functions_count": 0, "imports_count": 3, "variables_count": 0 }, "function_calls_found": 1, "function_name": "__pd_object_covert_start", "independence_code_length": 17, "matched_apis": [ "pd...
bbfamily/abu
_parse_stock_info()
class_method
Code snippets that use function: snippet 1: def _crawl_imp(self, *args, **kwargs): for index, symbol in enumerate(self._symbols): try: if not ABuXqFile.exist_stock_info(self._market, symbol) or ('replace' in kwargs and kwargs['replace']): self.get(self._base_url +...
No docstring found
from lxml import etree company_industry = selector.xpath('//*[@id="relatedIndustry"]/h2/a/text()') quate_items = selector.xpath('//*[@id="center"]/div[2]/div[2]/div[2]/table/tbody/tr/td') stock_name = selector.xpath('//*[@id="center"]/div[2]/div[2]/div[1]/div[1]/span[1]/strong/text()') company_info_p = selector.xpa...
{ "api_call_count": 3, "dependencies_summary": { "classes_count": 0, "constants_count": 0, "functions_count": 2, "imports_count": 1, "variables_count": 15 }, "function_calls_found": 1, "function_name": "_parse_stock_info", "independence_code_length": 82, "matched_apis": [ "st" ],...
bbfamily/abu
fix_xq_columns_name()
function
Code snippets that use function: snippet 1: def update_all(markets=('US', 'CN', 'HK')): crawl_stock_code(markets) crawl_stock_info(markets) ABuXqFile.merge_stock_info_to_stock_list(markets) ABuXqFile.fix_xq_columns_name() def query_symbol_info(symbol): m, symbol = ensure_symbol(symbol) return ...
雪球获取的数据的key都是中文,dataframe的columns不变与用中文
from .ABuXqConsts import columns_map import pandas as pd from os import path from ..CoreBu.ABuEnv import g_project_rom_data_dir stock_df = pd.read_csv(map_stock_list_rom(m), dtype=str) columns_intersection = stock_df.columns & columns_map.keys() old_c = df.columns.tolist() df = pd.read_csv(map_stock_list(market)...
{ "api_call_count": 4, "dependencies_summary": { "classes_count": 0, "constants_count": 0, "functions_count": 2, "imports_count": 4, "variables_count": 5 }, "function_calls_found": 1, "function_name": "fix_xq_columns_name", "independence_code_length": 37, "matched_apis": [ "pd", ...
bbfamily/abu
_adjust_returns(returns, adjustment_factor)
function
Code snippets that use function: snippet 1: if len(returns) < 2: return np.nan ann_factor = annualization_factor(period, annualization) adj_returns = _adjust_returns(returns, required_return) mu = nanmean(adj_returns, axis=0) dsr = (_downside_risk if _downside_risk is not None else ...
Returns the returns series adjusted by adjustment_factor. Optimizes for the case of adjustment_factor being 0 by returning returns itself, not a copy! Parameters ---------- returns : pd.Series or np.ndarray adjustment_factor : pd.Series or np.ndarray or float or int Returns ------- pd....
returns = returns[~np.isnan(returns)] def _adjust_returns(returns, adjustment_factor): """ Returns the returns series adjusted by adjustment_factor. Optimizes for the case of adjustment_factor being 0 by returning returns itself, not a copy! Parameters ---------- returns : pd.Series or np.ndar...
{ "api_call_count": 6, "dependencies_summary": { "classes_count": 0, "constants_count": 0, "functions_count": 0, "imports_count": 0, "variables_count": 1 }, "function_calls_found": 7, "function_name": "_adjust_returns", "independence_code_length": 19, "matched_apis": [ "np", "p...
bbfamily/abu
cum_returns(returns, starting_value)
function
Code snippets that use function: snippet 1: """ if len(returns) < 1: return np.nan cumulative = cum_returns(returns, starting_value=100) max_return = np.fmax.accumulate(cumulative) return nanmin((cumulative - max_return) / max_return) def annual_return(returns, period=DAILY, annualization=No...
Compute cumulative returns from simple returns. Parameters ---------- returns : pd.Series or np.ndarray Returns of the strategy as a percentage, noncumulative. - Time series with decimal returns. - Example: 2015-07-16 -0.012143 2015-07-17 0.045350 ...
import numpy as np from functools import wraps mask = downside_diff > 0 result = np.cumsum(y, axis=axis, dtype=dtype) y = np.array(a, subok=True) obj = args[0] wrap = None a = alpha_aligned(returns, factor_returns, risk_free, period, annualization, _beta=b) df_cum = np.exp(nancumsum(np.log1p(returns))) returns...
{ "api_call_count": 8, "dependencies_summary": { "classes_count": 0, "constants_count": 0, "functions_count": 4, "imports_count": 2, "variables_count": 8 }, "function_calls_found": 8, "function_name": "cum_returns", "independence_code_length": 175, "matched_apis": [ "np", "pd" ...
bbfamily/abu
nancumsum(a, axis, dtype)
function
Code snippets that use function: snippet 1: if np.isnan(np.asanyarray(returns)[0]): returns = returns.copy() returns[0] = 0. df_cum = np.exp(nancumsum(np.log1p(returns))) if starting_value == 0: return df_cum - 1 else: return df_cum * starting_value
Return the cumulative sum of array elements over a given axis treating Not a Numbers (NaNs) as zero. The cumulative sum does not change when NaNs are encountered and leading NaNs are replaced by zeros. Handles a subset of the edge cases handled by the nancumsum added in numpy 1.12.0. Parameters ...
import numpy as np from functools import wraps mask = downside_diff > 0 result = np.cumsum(y, axis=axis, dtype=dtype) y = np.array(a, subok=True) obj = args[0] wrap = None a = alpha_aligned(returns, factor_returns, risk_free, period, annualization, _beta=b) def array_wrap(arg_name, _not_specified=object()): ...
{ "api_call_count": 13, "dependencies_summary": { "classes_count": 0, "constants_count": 0, "functions_count": 3, "imports_count": 2, "variables_count": 6 }, "function_calls_found": 1, "function_name": "nancumsum", "independence_code_length": 131, "matched_apis": [ "pd", "np", ...
bbfamily/abu
max_drawdown(returns)
function
Code snippets that use function: snippet 1: Note ----- See https://en.wikipedia.org/wiki/Calmar_ratio for more details. """ max_dd = max_drawdown(returns=returns) if max_dd < 0: temp = annual_return( returns=returns, period=period, annualization=annualiza...
Determines the maximum drawdown of a strategy. Parameters ---------- returns : pd.Series or np.ndarray Daily returns of the strategy, noncumulative. - See full explanation in :func:`~empyrical.stats.cum_returns`. Returns ------- float Maximum drawdown. Note ---...
import numpy as np from functools import wraps from .utils import nanmean, nanstd, nanmin max_return = np.fmax.accumulate(cumulative) cumulative = cum_returns(returns, starting_value=100) mask = downside_diff > 0 result = np.cumsum(y, axis=axis, dtype=dtype) y = np.array(a, subok=True) obj = args[0] wrap = Non...
{ "api_call_count": 5, "dependencies_summary": { "classes_count": 0, "constants_count": 0, "functions_count": 5, "imports_count": 3, "variables_count": 10 }, "function_calls_found": 3, "function_name": "max_drawdown", "independence_code_length": 206, "matched_apis": [ "np", "pd...
bbfamily/abu
annual_return(returns, period, annualization)
function
Code snippets that use function: snippet 1: See https://en.wikipedia.org/wiki/Calmar_ratio for more details. """ max_dd = max_drawdown(returns=returns) if max_dd < 0: temp = annual_return( returns=returns, period=period, annualization=annualization ) / ab...
Determines the mean annual growth rate of returns. Parameters ---------- returns : pd.Series or np.ndarray Periodic returns of the strategy, noncumulative. - See full explanation in :func:`~empyrical.stats.cum_returns`. period : str, optional Defines the periodicity of the 'retu...
import numpy as np from functools import wraps DAILY = 'daily' ANNUALIZATION_FACTORS = {DAILY: APPROX_BDAYS_PER_YEAR, WEEKLY: WEEKS_PER_YEAR, MONTHLY: MONTHS_PER_YEAR, YEARLY: 1} start_value = 100 mask = downside_diff > 0 result = np.cumsum(y, axis=axis, dtype=dtype) y = np.array(a, subok=True) obj = args[0] w...
{ "api_call_count": 5, "dependencies_summary": { "classes_count": 0, "constants_count": 2, "functions_count": 8, "imports_count": 2, "variables_count": 15 }, "function_calls_found": 1, "function_name": "annual_return", "independence_code_length": 288, "matched_apis": [ "np", "p...
bbfamily/abu
annual_volatility(returns, period, alpha, annualization)
function
Code snippets that use function: snippet 1: # 策略平均收益 # noinspection PyUnresolvedReferences self.mean_algorithm_returns = self.algorithm_returns.cumsum() / np.arange(1, self.num_trading_days + 1, dtype=np.float64) #...
Determines the annual volatility of a strategy. Parameters ---------- returns : pd.Series or np.ndarray Periodic returns of the strategy, noncumulative. - See full explanation in :func:`~empyrical.stats.cum_returns`. period : str, optional Defines the periodicity of the 'returns...
import numpy as np from .utils import nanmean, nanstd, nanmin from six import iteritems import pandas as pd from .utils import nanmean, nanstd, nanmin DAILY = 'daily' ANNUALIZATION_FACTORS = {DAILY: APPROX_BDAYS_PER_YEAR, WEEKLY: WEEKS_PER_YEAR, MONTHLY: MONTHS_PER_YEAR, YEARLY: 1} _beta = beta_aligned(returns, ...
{ "api_call_count": 5, "dependencies_summary": { "classes_count": 0, "constants_count": 2, "functions_count": 6, "imports_count": 5, "variables_count": 10 }, "function_calls_found": 3, "function_name": "annual_volatility", "independence_code_length": 263, "matched_apis": [ "np", ...
bbfamily/abu
sharpe_ratio(returns, risk_free, period, annualization)
function
Code snippets that use function: snippet 1: self.benchmark_volatility = stats.annual_volatility(self.benchmark_returns) # noinspection PyTypeChecker self.algorithm_volatility = stats.annual_volatility(self.algorithm_returns) # 夏普比率 self.benchmark_sharpe = stats.sharpe_ratio(self.benchma...
Determines the Sharpe ratio of a strategy. Parameters ---------- returns : pd.Series or np.ndarray Daily returns of the strategy, noncumulative. - See full explanation in :func:`~empyrical.stats.cum_returns`. risk_free : int, float Constant risk-free return throughout the period...
import numpy as np DAILY = 'daily' ANNUALIZATION_FACTORS = {DAILY: APPROX_BDAYS_PER_YEAR, WEEKLY: WEEKS_PER_YEAR, MONTHLY: MONTHS_PER_YEAR, YEARLY: 1} ann_factor = annualization_factor(period, annualization) factor = annualization returns = returns[~np.isnan(returns)] returns_risk_adj = returns_risk_adj[~np.isnan...
{ "api_call_count": 11, "dependencies_summary": { "classes_count": 0, "constants_count": 2, "functions_count": 2, "imports_count": 1, "variables_count": 4 }, "function_calls_found": 3, "function_name": "sharpe_ratio", "independence_code_length": 109, "matched_apis": [ "np", "pd...
bbfamily/abu
downside_risk(returns, required_return, period, annualization)
function
Code snippets that use function: snippet 1: ann_factor = annualization_factor(period, annualization) adj_returns = _adjust_returns(returns, required_return) mu = nanmean(adj_returns, axis=0) dsr = (_downside_risk if _downside_risk is not None else downside_risk(returns, required_return)) sor...
Determines the downside deviation below a threshold Parameters ---------- returns : pd.Series or np.ndarray or pd.DataFrame Daily returns of the strategy, noncumulative. - See full explanation in :func:`~empyrical.stats.cum_returns`. required_return: float / series minimum accep...
import pandas as pd import numpy as np from .utils import nanmean, nanstd, nanmin DAILY = 'daily' ANNUALIZATION_FACTORS = {DAILY: APPROX_BDAYS_PER_YEAR, WEEKLY: WEEKS_PER_YEAR, MONTHLY: MONTHS_PER_YEAR, YEARLY: 1} mask = downside_diff > 0 squares = np.square(downside_diff) returns = returns[~np.isnan(returns)] ...
{ "api_call_count": 12, "dependencies_summary": { "classes_count": 0, "constants_count": 2, "functions_count": 2, "imports_count": 3, "variables_count": 8 }, "function_calls_found": 1, "function_name": "downside_risk", "independence_code_length": 122, "matched_apis": [ "np", "p...
bbfamily/abu
information_ratio(returns, factor_returns)
function
Code snippets that use function: snippet 1: # noinspection PyTypeChecker self.algorithm_sharpe = stats.sharpe_ratio(self.algorithm_returns) # 信息比率 # noinspection PyUnresolvedReferences self.information = stats.information_ratio(self.algorithm_returns.values, self.benchmark_returns.value...
Determines the Information ratio of a strategy. Parameters ---------- returns : pd.Series or np.ndarray Daily returns of the strategy, noncumulative. - See full explanation in :func:`~empyrical.stats.cum_returns`. factor_returns: float / series Benchmark return to compare return...
from .utils import nanmean, nanstd, nanmin import numpy as np from .utils import nanmean, nanstd, nanmin active_return = _adjust_returns(returns, factor_returns) returns = returns[~np.isnan(returns)] tracking_error = nanstd(active_return, ddof=1) def _adjust_returns(returns, adjustment_factor): """ Return...
{ "api_call_count": 7, "dependencies_summary": { "classes_count": 0, "constants_count": 0, "functions_count": 1, "imports_count": 3, "variables_count": 3 }, "function_calls_found": 1, "function_name": "information_ratio", "independence_code_length": 61, "matched_apis": [ "np", ...
bbfamily/abu
_aligned_series(*many_series)
function
Code snippets that use function: snippet 1: """ if len(returns) < 2 or len(factor_returns) < 2: return np.nan, np.nan return alpha_beta_aligned(*_aligned_series(returns, factor_returns), risk_free=risk_free, period=period, annualization=annual...
Return a new list of series containing the data in the input series, but with their indices aligned. NaNs will be filled in for missing values. Parameters ---------- many_series : list[pd.Series] Returns ------- aligned_series : list[pd.Series] A new list of series containing the ...
from six import iteritems import pandas as pd def _aligned_series(*many_series): """ Return a new list of series containing the data in the input series, but with their indices aligned. NaNs will be filled in for missing values. Parameters ---------- many_series : list[pd.Series] Returns...
{ "api_call_count": 3, "dependencies_summary": { "classes_count": 0, "constants_count": 0, "functions_count": 0, "imports_count": 2, "variables_count": 0 }, "function_calls_found": 3, "function_name": "_aligned_series", "independence_code_length": 22, "matched_apis": [ "pd" ], ...
bbfamily/abu
alpha_beta_aligned(returns, factor_returns, risk_free, period, annualization)
function
Code snippets that use function: snippet 1: """ if len(returns) < 2 or len(factor_returns) < 2: return np.nan, np.nan return alpha_beta_aligned(*_aligned_series(returns, factor_returns), risk_free=risk_free, period=period, annualization=annual...
Calculates annualized alpha and beta. If they are pd.Series, expects returns and factor_returns have already been aligned on their labels. If np.ndarray, these arguments should have the same shape. Parameters ---------- returns : pd.Series or np.ndarray Daily returns of the strategy, ...
import numpy as np from .utils import nanmean, nanstd, nanmin DAILY = 'daily' ANNUALIZATION_FACTORS = {DAILY: APPROX_BDAYS_PER_YEAR, WEEKLY: WEEKS_PER_YEAR, MONTHLY: MONTHS_PER_YEAR, YEARLY: 1} _beta = beta_aligned(returns, factor_returns, risk_free) adj_returns = _adjust_returns(returns, risk_free) alpha_series ...
{ "api_call_count": 7, "dependencies_summary": { "classes_count": 0, "constants_count": 2, "functions_count": 4, "imports_count": 2, "variables_count": 11 }, "function_calls_found": 2, "function_name": "alpha_beta_aligned", "independence_code_length": 209, "matched_apis": [ "np", ...
bbfamily/abu
alpha_aligned(returns, factor_returns, risk_free, period, annualization, _beta)
function
Code snippets that use function: snippet 1: float Beta. """ b = beta_aligned(returns, factor_returns, risk_free) a = alpha_aligned(returns, factor_returns, risk_free, period, annualization, _beta=b) return a, b def alpha(returns, factor_returns, risk_free=0.0, period=DAI...
Calculates annualized alpha. If they are pd.Series, expects returns and factor_returns have already been aligned on their labels. If np.ndarray, these arguments should have the same shape. Parameters ---------- returns : pd.Series or np.ndarray Daily returns of the strategy, noncumula...
import numpy as np from .utils import nanmean, nanstd, nanmin DAILY = 'daily' ANNUALIZATION_FACTORS = {DAILY: APPROX_BDAYS_PER_YEAR, WEEKLY: WEEKS_PER_YEAR, MONTHLY: MONTHS_PER_YEAR, YEARLY: 1} _beta = beta_aligned(returns, factor_returns, risk_free) adj_returns = _adjust_returns(returns, risk_free) alpha_series ...
{ "api_call_count": 9, "dependencies_summary": { "classes_count": 0, "constants_count": 2, "functions_count": 3, "imports_count": 2, "variables_count": 9 }, "function_calls_found": 2, "function_name": "alpha_aligned", "independence_code_length": 162, "matched_apis": [ "np", "pd...
bbfamily/abu
beta_aligned(returns, factor_returns, risk_free)
function
Code snippets that use function: snippet 1: Alpha. float Beta. """ b = beta_aligned(returns, factor_returns, risk_free) a = alpha_aligned(returns, factor_returns, risk_free, period, annualization, _beta=b) return a, b snippet 2: Beta. """ if len(returns) < 2 or...
Calculates beta. If they are pd.Series, expects returns and factor_returns have already been aligned on their labels. If np.ndarray, these arguments should have the same shape. Parameters ---------- returns : pd.Series or np.ndarray Daily returns of the strategy, noncumulative. ...
import numpy as np cov = np.cov(joint, ddof=0) returns = returns[~np.isnan(returns)] joint = joint[:, ~np.isnan(joint).any(axis=0)] def _adjust_returns(returns, adjustment_factor): """ Returns the returns series adjusted by adjustment_factor. Optimizes for the case of adjustment_factor being 0 by return...
{ "api_call_count": 13, "dependencies_summary": { "classes_count": 0, "constants_count": 0, "functions_count": 1, "imports_count": 1, "variables_count": 3 }, "function_calls_found": 3, "function_name": "beta_aligned", "independence_code_length": 61, "matched_apis": [ "np", "pd"...
bbfamily/abu
hash(obj, hash_name, coerce_mmap)
function
Code snippets that use function: snippet 1: """ if 'numpy' in sys.modules: hasher = NumpyHasher(hash_name=hash_name, coerce_mmap=coerce_mmap) else: hasher = Hasher(hash_name=hash_name) return hasher.hash(obj) snippet 2: # but we keep it in a try as it's faster. self._sequence = s...
Quick calculation of a hash to identify uniquely Python objects containing numpy arrays. Parameters ----------- hash_name: 'md5' or 'sha1' Hashing algorithm used. sha1 is supposedly safer, but md5 is faster. coerce_mmap: boolean Make no diffe...
import sys obj = (klass, ('HASHED', obj.descr)) hasher = Hasher(hash_name=hash_name) class NumpyHasher(Hasher): """ Special case the hasher for when numpy is loaded. """ def __init__(self, hash_name='md5', coerce_mmap=False): """ Parameters ---------- hash_nam...
{ "api_call_count": 3, "dependencies_summary": { "classes_count": 2, "constants_count": 0, "functions_count": 0, "imports_count": 1, "variables_count": 2 }, "function_calls_found": 7, "function_name": "hash", "independence_code_length": 147, "matched_apis": [ "np", "numpy" ],...
bbfamily/abu
__init__(hash_name, coerce_mmap)
class_method
Code snippets that use function: snippet 1: class BaseHQCrawlBrower(BaseXQCrawlBrower): def _crawl_imp(self, *args, **kwargs): pass def __init__(self, url): super(BaseHQCrawlBrower, self).__init__(BASE_XQ_HQ_URL) self._base_url = self._base_url + url class NavHQCrawlBrower(BaseHQCrawl...
Parameters ---------- hash_name: string The hash algorithm to be used coerce_mmap: boolean Make no difference between np.memmap and np.ndarray objects.
import numpy as np class Hasher(Pickler): """ A subclass of pickler, to do cryptographic hashing, rather than pickling. """ def __init__(self, hash_name='md5'): self.stream = io.BytesIO() protocol = pickle.DEFAULT_PROTOCOL if PY3_OR_LATER else pickle.HIGHEST_PROTOCOL Pickle...
{ "api_call_count": 8, "dependencies_summary": { "classes_count": 1, "constants_count": 0, "functions_count": 0, "imports_count": 1, "variables_count": 0 }, "function_calls_found": 23, "function_name": "__init__", "independence_code_length": 95, "matched_apis": [ "np", "numpy" ...
bbfamily/abu
save(obj)
class_method
Code snippets that use function: snippet 1: # type(None) or type(module) do not pickle obj = _MyHash(func_name, inst) else: cls = obj.__self__.__class__ obj = _MyHash(func_name, inst, cls) Pickler.save(self, obj) def memoize(self, obj): # ...
Subclass the save method, to hash ndarray subclass, rather than pickling them. Off course, this is a total abuse of the Pickler class.
obj = (klass, ('HASHED', obj.descr)) klass = obj.__class__ obj_c_contiguous = obj.flatten() class Hasher(Pickler): """ A subclass of pickler, to do cryptographic hashing, rather than pickling. """ def __init__(self, hash_name='md5'): self.stream = io.BytesIO() protocol = pickle.D...
{ "api_call_count": 5, "dependencies_summary": { "classes_count": 1, "constants_count": 0, "functions_count": 0, "imports_count": 0, "variables_count": 3 }, "function_calls_found": 5, "function_name": "save", "independence_code_length": 105, "matched_apis": [ "np" ], "source_fi...
bbfamily/abu
pformat(obj, indent, depth)
function
Code snippets that use function: snippet 1: import numpy as np print_options = np.get_printoptions() np.set_printoptions(precision=6, threshold=64, edgeitems=1) else: print_options = None out = pprint.pformat(obj, depth=depth, indent=indent) if print_options: np.set_printopti...
No docstring found
import pprint import numpy as np import sys out = pprint.pformat(obj, depth=depth, indent=indent) print_options = None def pformat(obj, indent=0, depth=3): if 'numpy' in sys.modules: import numpy as np print_options = np.get_printoptions() np.set_printoptions(precision=6, threshold=64, ...
{ "api_call_count": 5, "dependencies_summary": { "classes_count": 0, "constants_count": 0, "functions_count": 0, "imports_count": 3, "variables_count": 2 }, "function_calls_found": 3, "function_name": "pformat", "independence_code_length": 21, "matched_apis": [ "np", "numpy" ...
bbfamily/abu
__init__(func, cachedir, ignore, mmap_mode, compress, verbose, timestamp)
class_method
Code snippets that use function: snippet 1: class BaseHQCrawlBrower(BaseXQCrawlBrower): def _crawl_imp(self, *args, **kwargs): pass def __init__(self, url): super(BaseHQCrawlBrower, self).__init__(BASE_XQ_HQ_URL) self._base_url = self._base_url + url class NavHQCrawlBrower(BaseHQCrawl...
Parameters ---------- func: callable The function to decorate cachedir: string The path of the base directory to use as a data store ignore: list or None List of variable names to ignore. mmap_mode: {None, 'r+', ...
import inspect import time import functools import warnings import re import pydoc from .disk import mkdirp, rm_subdirs from .logger import Logger, format_time, pformat verbose = self._verbose timestamp = time.time() doc = func.__doc__ func = func.func ignore = [] mmap_mode = self.mmap_mode cachedir = sel...
{ "api_call_count": 3, "dependencies_summary": { "classes_count": 0, "constants_count": 0, "functions_count": 0, "imports_count": 8, "variables_count": 7 }, "function_calls_found": 23, "function_name": "__init__", "independence_code_length": 82, "matched_apis": [ "mkdirp", "num...
bbfamily/abu
__init__(cachedir, mmap_mode, compress, verbose)
class_method
Code snippets that use function: snippet 1: class BaseHQCrawlBrower(BaseXQCrawlBrower): def _crawl_imp(self, *args, **kwargs): pass def __init__(self, url): super(BaseHQCrawlBrower, self).__init__(BASE_XQ_HQ_URL) self._base_url = self._base_url + url class NavHQCrawlBrower(BaseHQCrawl...
Parameters ---------- cachedir: string or None The path of the base directory to use as a data store or None. If None is given, no caching is done and the Memory object is completely transparent. mmap_mode: {None, 'r+', 'r', 'w+', 'c'},...
import time import warnings from .disk import mkdirp, rm_subdirs from .logger import Logger, format_time, pformat import os verbose = self._verbose mmap_mode = self.mmap_mode cachedir = self.cachedir[:-7] if self.cachedir is not None else None def __init__(self, cachedir, mmap_mode=None, compress=False, verbose...
{ "api_call_count": 3, "dependencies_summary": { "classes_count": 0, "constants_count": 0, "functions_count": 0, "imports_count": 5, "variables_count": 3 }, "function_calls_found": 23, "function_name": "__init__", "independence_code_length": 49, "matched_apis": [ "mkdirp", "num...
bbfamily/abu
dump(value, filename, compress, protocol, cache_size)
function
Code snippets that use function: snippet 1: # Initialise the hash obj self._hash = hashlib.new(hash_name) def hash(self, obj, return_digest=True): try: self.dump(obj) except pickle.PicklingError as e: e.args += ('PicklingError while hashing %r: %r' % (obj, e),) ...
Persist an arbitrary Python object into one file. Parameters ----------- value: any Python object The object to store to disk. filename: str or pathlib.Path The path of the file in which it is to be stored. The compression method corresponding to one of the supported filename ex...
from .numpy_pickle_utils import _COMPRESSORS from ._compat import _basestring, PY3_OR_LATER from ._compat import _basestring, PY3_OR_LATER import warnings import sys from pathlib import Path from .numpy_pickle_utils import _read_fileobject, _write_fileobject compress_level = 3 filename = str(filename) compress...
{ "api_call_count": 5, "dependencies_summary": { "classes_count": 1, "constants_count": 0, "functions_count": 0, "imports_count": 7, "variables_count": 7 }, "function_calls_found": 9, "function_name": "dump", "independence_code_length": 178, "matched_apis": [ "_COMPRESSORS", "_...
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
4