Skip to content

Commit

Permalink
fix ix to iloc
Browse files Browse the repository at this point in the history
  • Loading branch information
bbfamily committed Sep 7, 2017
1 parent b5cef93 commit a6b1b50
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 32 deletions.
2 changes: 1 addition & 1 deletion abupy/FactorBuyBu/ABuBuyFactorWrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def fit_month_wrapped(*args, **kwargs):
if benchmark_today.empty:
return 0
# 要拿大盘最近一个月的走势,准备切片的start,end
end_key = int(benchmark_today.ix[0].key)
end_key = int(benchmark_today.iloc[0].key)
start_key = end_key - 20
if start_key < 0:
return 0
Expand Down
2 changes: 1 addition & 1 deletion abupy/FactorBuyBu/ABuFactorBuyDemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def fit_month(self, today):
if benchmark_today.empty:
return 0
# 要拿大盘最近一个月的走势,准备切片的start,end
end_key = int(benchmark_today.ix[0].key)
end_key = int(benchmark_today.iloc[0].key)
start_key = end_key - 20
if start_key < 0:
return False
Expand Down
2 changes: 1 addition & 1 deletion abupy/MLBu/ABuMLPd.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def btc_siblings_df(self, btc_raw):
"""

# 将所有交易日以3个为一组,切割成多个子df,即每一个子df中有3个交易日的交易数据
btc_siblings = [btc_raw.ix[sib_ind * 3:(sib_ind + 1) * 3, :]
btc_siblings = [btc_raw.iloc[sib_ind * 3:(sib_ind + 1) * 3, :]
for sib_ind in np.arange(0, int(btc_raw.shape[0] / 3))]

btc_df = pd.DataFrame()
Expand Down
12 changes: 8 additions & 4 deletions abupy/TLineBu/ABuTLExecute.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def calc_pair_speed(symbol, benchmark_symbol, resample=5, speed_key='close',
start=None, end=None, n_folds=2, show=False):
"""
参数传递一组symbol对,获取symbol对的金融时间序列数据,根据speed_key获取曲线序列数据,
分别通过calc_kl_speed计算symbol对的趋势跟随速度
分别通过calc_kl_speed计算symbol对的趋势跟随速度,相关性*敏感度=敏感度置信度
:param symbol: eg: 'AU0'
:param benchmark_symbol: eg: 'XAU'
:param resample: 计算速度数值的重采样周期默认5
Expand All @@ -226,16 +226,20 @@ def calc_pair_speed(symbol, benchmark_symbol, resample=5, speed_key='close',
:param end: 获取金融时间序列的end时间
:param n_folds: 获取金融时间序列的n_folds参数
:param show: 是否可视化symbol对的趋势走势对比
:return: 参数symbol, benchmark_symbol所对应的趋势变化敏感速度数值
:return: 参数symbol, benchmark_symbol所对应的趋势变化敏感速度数值,以及相关性*敏感度=敏感度置信度
"""
from ..TradeBu import AbuBenchmark
from ..SimilarBu import ABuCorrcoef, ECoreCorrType

benchmark = AbuBenchmark(benchmark_symbol, start=start, end=end, n_folds=n_folds)
benchmark_kl = benchmark.kl_pd
kl = ABuSymbolPd.make_kl_df(symbol, benchmark=benchmark,
data_mode=EMarketDataSplitMode.E_DATA_SPLIT_UNDO)
# 通过calc_kl_speed计算趋势跟随速度
kl_speed = calc_kl_speed(kl[speed_key], resample)
benchmark_kl_speed = calc_kl_speed(benchmark_kl[speed_key], resample)
# 两个走势的SPERM相关性
corr = ABuCorrcoef.corr_xy(kl.close, benchmark_kl.close, ECoreCorrType.E_CORE_TYPE_SPERM)

if show:
# 可视化symbol对的趋势走势对比
Expand All @@ -246,8 +250,8 @@ def calc_pair_speed(symbol, benchmark_symbol, resample=5, speed_key='close',
kl_resamp.plot(label='kl', style=['*--'])
benchmark_kl_resamp.plot(label='benchmark', style=['^--'])
plt.legend(loc='best')
# 返回参数symbol, benchmark_symbol所对应的趋势变化敏感速度数值
return kl_speed, benchmark_kl_speed
# 返回参数symbol, benchmark_symbol所对应的趋势变化敏感速度数值, 以及相关性*敏感度=敏感度置信度
return kl_speed, benchmark_kl_speed, corr


def shift_distance_how(how):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@
"source": [
"def btc_siblings_df(btc_raw):\n",
" # 将所有交易日以3个为一组,切割成多个子df,即每一个子df中有3个交易日的交易数据\n",
" btc_siblings = [btc_raw.ix[sib_ind * 3:(sib_ind + 1) * 3, :]\n",
" btc_siblings = [btc_raw.iloc[sib_ind * 3:(sib_ind + 1) * 3, :]\n",
" for sib_ind in np.arange(0, int(btc_raw.shape[0] / 3))]\n",
"\n",
" btc_df = pd.DataFrame()\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@
" sell_factors,\n",
" choice_symbols=['usTSLA'])\n",
"\n",
"order = abu_result_tuple.orders_pd.ix[0]"
"order = abu_result_tuple.orders_pd.iloc[0]"
]
},
{
Expand Down
173 changes: 152 additions & 21 deletions abupy_lecture/25-期货市场内外盘低频统计套利.ipynb

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@
" if benchmark_today.empty:\n",
" return 0\n",
" # 要拿大盘最近一个月的走势,准备切片的start,end\n",
" end_key = int(benchmark_today.ix[0].key)\n",
" end_key = int(benchmark_today.iloc[0].key)\n",
" start_key = end_key - 20\n",
" if start_key < 0:\n",
" return False\n",
Expand Down Expand Up @@ -834,7 +834,7 @@
" if benchmark_today.empty:\n",
" return 0\n",
" # 要拿大盘最近一个月的走势,准备切片的start,end\n",
" end_key = int(benchmark_today.ix[0].key)\n",
" end_key = int(benchmark_today.iloc[0].key)\n",
" start_key = end_key - 20\n",
" if start_key < 0:\n",
" return 0\n",
Expand Down

0 comments on commit a6b1b50

Please sign in to comment.