repo
stringlengths 7
55
| path
stringlengths 4
223
| func_name
stringlengths 1
134
| original_string
stringlengths 75
104k
| language
stringclasses 1
value | code
stringlengths 75
104k
| code_tokens
listlengths 19
28.4k
| docstring
stringlengths 1
46.9k
| docstring_tokens
listlengths 1
1.97k
| sha
stringlengths 40
40
| url
stringlengths 87
315
| partition
stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAARP/QARisk.py
|
QA_Risk.market_value
|
def market_value(self):
"""每日每个股票持仓市值表
Returns:
pd.DataFrame -- 市值表
"""
if self.account.daily_hold is not None:
if self.if_fq:
return (
self.market_data.to_qfq().pivot('close').fillna(
method='ffill'
) * self.account.daily_hold.apply(abs)
).fillna(method='ffill')
else:
return (
self.market_data.pivot('close').fillna(method='ffill') *
self.account.daily_hold.apply(abs)
).fillna(method='ffill')
else:
return None
|
python
|
def market_value(self):
"""每日每个股票持仓市值表
Returns:
pd.DataFrame -- 市值表
"""
if self.account.daily_hold is not None:
if self.if_fq:
return (
self.market_data.to_qfq().pivot('close').fillna(
method='ffill'
) * self.account.daily_hold.apply(abs)
).fillna(method='ffill')
else:
return (
self.market_data.pivot('close').fillna(method='ffill') *
self.account.daily_hold.apply(abs)
).fillna(method='ffill')
else:
return None
|
[
"def",
"market_value",
"(",
"self",
")",
":",
"if",
"self",
".",
"account",
".",
"daily_hold",
"is",
"not",
"None",
":",
"if",
"self",
".",
"if_fq",
":",
"return",
"(",
"self",
".",
"market_data",
".",
"to_qfq",
"(",
")",
".",
"pivot",
"(",
"'close'",
")",
".",
"fillna",
"(",
"method",
"=",
"'ffill'",
")",
"*",
"self",
".",
"account",
".",
"daily_hold",
".",
"apply",
"(",
"abs",
")",
")",
".",
"fillna",
"(",
"method",
"=",
"'ffill'",
")",
"else",
":",
"return",
"(",
"self",
".",
"market_data",
".",
"pivot",
"(",
"'close'",
")",
".",
"fillna",
"(",
"method",
"=",
"'ffill'",
")",
"*",
"self",
".",
"account",
".",
"daily_hold",
".",
"apply",
"(",
"abs",
")",
")",
".",
"fillna",
"(",
"method",
"=",
"'ffill'",
")",
"else",
":",
"return",
"None"
] |
每日每个股票持仓市值表
Returns:
pd.DataFrame -- 市值表
|
[
"每日每个股票持仓市值表"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAARP/QARisk.py#L212-L232
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAARP/QARisk.py
|
QA_Risk.max_dropback
|
def max_dropback(self):
"""最大回撤
"""
return round(
float(
max(
[
(self.assets.iloc[idx] - self.assets.iloc[idx::].min())
/ self.assets.iloc[idx]
for idx in range(len(self.assets))
]
)
),
2
)
|
python
|
def max_dropback(self):
"""最大回撤
"""
return round(
float(
max(
[
(self.assets.iloc[idx] - self.assets.iloc[idx::].min())
/ self.assets.iloc[idx]
for idx in range(len(self.assets))
]
)
),
2
)
|
[
"def",
"max_dropback",
"(",
"self",
")",
":",
"return",
"round",
"(",
"float",
"(",
"max",
"(",
"[",
"(",
"self",
".",
"assets",
".",
"iloc",
"[",
"idx",
"]",
"-",
"self",
".",
"assets",
".",
"iloc",
"[",
"idx",
":",
":",
"]",
".",
"min",
"(",
")",
")",
"/",
"self",
".",
"assets",
".",
"iloc",
"[",
"idx",
"]",
"for",
"idx",
"in",
"range",
"(",
"len",
"(",
"self",
".",
"assets",
")",
")",
"]",
")",
")",
",",
"2",
")"
] |
最大回撤
|
[
"最大回撤"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAARP/QARisk.py#L252-L266
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAARP/QARisk.py
|
QA_Risk.total_commission
|
def total_commission(self):
"""总手续费
"""
return float(
-abs(round(self.account.history_table.commission.sum(),
2))
)
|
python
|
def total_commission(self):
"""总手续费
"""
return float(
-abs(round(self.account.history_table.commission.sum(),
2))
)
|
[
"def",
"total_commission",
"(",
"self",
")",
":",
"return",
"float",
"(",
"-",
"abs",
"(",
"round",
"(",
"self",
".",
"account",
".",
"history_table",
".",
"commission",
".",
"sum",
"(",
")",
",",
"2",
")",
")",
")"
] |
总手续费
|
[
"总手续费"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAARP/QARisk.py#L269-L275
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAARP/QARisk.py
|
QA_Risk.total_tax
|
def total_tax(self):
"""总印花税
"""
return float(-abs(round(self.account.history_table.tax.sum(), 2)))
|
python
|
def total_tax(self):
"""总印花税
"""
return float(-abs(round(self.account.history_table.tax.sum(), 2)))
|
[
"def",
"total_tax",
"(",
"self",
")",
":",
"return",
"float",
"(",
"-",
"abs",
"(",
"round",
"(",
"self",
".",
"account",
".",
"history_table",
".",
"tax",
".",
"sum",
"(",
")",
",",
"2",
")",
")",
")"
] |
总印花税
|
[
"总印花税"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAARP/QARisk.py#L278-L283
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAARP/QARisk.py
|
QA_Risk.profit_construct
|
def profit_construct(self):
"""利润构成
Returns:
dict -- 利润构成表
"""
return {
'total_buyandsell':
round(
self.profit_money - self.total_commission - self.total_tax,
2
),
'total_tax':
self.total_tax,
'total_commission':
self.total_commission,
'total_profit':
self.profit_money
}
|
python
|
def profit_construct(self):
"""利润构成
Returns:
dict -- 利润构成表
"""
return {
'total_buyandsell':
round(
self.profit_money - self.total_commission - self.total_tax,
2
),
'total_tax':
self.total_tax,
'total_commission':
self.total_commission,
'total_profit':
self.profit_money
}
|
[
"def",
"profit_construct",
"(",
"self",
")",
":",
"return",
"{",
"'total_buyandsell'",
":",
"round",
"(",
"self",
".",
"profit_money",
"-",
"self",
".",
"total_commission",
"-",
"self",
".",
"total_tax",
",",
"2",
")",
",",
"'total_tax'",
":",
"self",
".",
"total_tax",
",",
"'total_commission'",
":",
"self",
".",
"total_commission",
",",
"'total_profit'",
":",
"self",
".",
"profit_money",
"}"
] |
利润构成
Returns:
dict -- 利润构成表
|
[
"利润构成"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAARP/QARisk.py#L286-L305
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAARP/QARisk.py
|
QA_Risk.profit_money
|
def profit_money(self):
"""盈利额
Returns:
[type] -- [description]
"""
return float(round(self.assets.iloc[-1] - self.assets.iloc[0], 2))
|
python
|
def profit_money(self):
"""盈利额
Returns:
[type] -- [description]
"""
return float(round(self.assets.iloc[-1] - self.assets.iloc[0], 2))
|
[
"def",
"profit_money",
"(",
"self",
")",
":",
"return",
"float",
"(",
"round",
"(",
"self",
".",
"assets",
".",
"iloc",
"[",
"-",
"1",
"]",
"-",
"self",
".",
"assets",
".",
"iloc",
"[",
"0",
"]",
",",
"2",
")",
")"
] |
盈利额
Returns:
[type] -- [description]
|
[
"盈利额"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAARP/QARisk.py#L308-L315
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAARP/QARisk.py
|
QA_Risk.annualize_return
|
def annualize_return(self):
"""年化收益
Returns:
[type] -- [description]
"""
return round(
float(self.calc_annualize_return(self.assets,
self.time_gap)),
2
)
|
python
|
def annualize_return(self):
"""年化收益
Returns:
[type] -- [description]
"""
return round(
float(self.calc_annualize_return(self.assets,
self.time_gap)),
2
)
|
[
"def",
"annualize_return",
"(",
"self",
")",
":",
"return",
"round",
"(",
"float",
"(",
"self",
".",
"calc_annualize_return",
"(",
"self",
".",
"assets",
",",
"self",
".",
"time_gap",
")",
")",
",",
"2",
")"
] |
年化收益
Returns:
[type] -- [description]
|
[
"年化收益"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAARP/QARisk.py#L334-L345
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAARP/QARisk.py
|
QA_Risk.benchmark_data
|
def benchmark_data(self):
"""
基准组合的行情数据(一般是组合,可以调整)
"""
return self.fetch[self.benchmark_type](
self.benchmark_code,
self.account.start_date,
self.account.end_date
)
|
python
|
def benchmark_data(self):
"""
基准组合的行情数据(一般是组合,可以调整)
"""
return self.fetch[self.benchmark_type](
self.benchmark_code,
self.account.start_date,
self.account.end_date
)
|
[
"def",
"benchmark_data",
"(",
"self",
")",
":",
"return",
"self",
".",
"fetch",
"[",
"self",
".",
"benchmark_type",
"]",
"(",
"self",
".",
"benchmark_code",
",",
"self",
".",
"account",
".",
"start_date",
",",
"self",
".",
"account",
".",
"end_date",
")"
] |
基准组合的行情数据(一般是组合,可以调整)
|
[
"基准组合的行情数据",
"(",
"一般是组合",
"可以调整",
")"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAARP/QARisk.py#L396-L404
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAARP/QARisk.py
|
QA_Risk.benchmark_assets
|
def benchmark_assets(self):
"""
基准组合的账户资产队列
"""
return (
self.benchmark_data.close /
float(self.benchmark_data.close.iloc[0])
* float(self.assets[0])
)
|
python
|
def benchmark_assets(self):
"""
基准组合的账户资产队列
"""
return (
self.benchmark_data.close /
float(self.benchmark_data.close.iloc[0])
* float(self.assets[0])
)
|
[
"def",
"benchmark_assets",
"(",
"self",
")",
":",
"return",
"(",
"self",
".",
"benchmark_data",
".",
"close",
"/",
"float",
"(",
"self",
".",
"benchmark_data",
".",
"close",
".",
"iloc",
"[",
"0",
"]",
")",
"*",
"float",
"(",
"self",
".",
"assets",
"[",
"0",
"]",
")",
")"
] |
基准组合的账户资产队列
|
[
"基准组合的账户资产队列"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAARP/QARisk.py#L407-L415
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAARP/QARisk.py
|
QA_Risk.benchmark_annualize_return
|
def benchmark_annualize_return(self):
"""基准组合的年化收益
Returns:
[type] -- [description]
"""
return round(
float(
self.calc_annualize_return(
self.benchmark_assets,
self.time_gap
)
),
2
)
|
python
|
def benchmark_annualize_return(self):
"""基准组合的年化收益
Returns:
[type] -- [description]
"""
return round(
float(
self.calc_annualize_return(
self.benchmark_assets,
self.time_gap
)
),
2
)
|
[
"def",
"benchmark_annualize_return",
"(",
"self",
")",
":",
"return",
"round",
"(",
"float",
"(",
"self",
".",
"calc_annualize_return",
"(",
"self",
".",
"benchmark_assets",
",",
"self",
".",
"time_gap",
")",
")",
",",
"2",
")"
] |
基准组合的年化收益
Returns:
[type] -- [description]
|
[
"基准组合的年化收益"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAARP/QARisk.py#L425-L440
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAARP/QARisk.py
|
QA_Risk.beta
|
def beta(self):
"""
beta比率 组合的系统性风险
"""
try:
res = round(
float(
self.calc_beta(
self.profit_pct.dropna(),
self.benchmark_profitpct.dropna()
)
),
2
)
except:
print('贝塔计算错误。。')
res = 0
return res
|
python
|
def beta(self):
"""
beta比率 组合的系统性风险
"""
try:
res = round(
float(
self.calc_beta(
self.profit_pct.dropna(),
self.benchmark_profitpct.dropna()
)
),
2
)
except:
print('贝塔计算错误。。')
res = 0
return res
|
[
"def",
"beta",
"(",
"self",
")",
":",
"try",
":",
"res",
"=",
"round",
"(",
"float",
"(",
"self",
".",
"calc_beta",
"(",
"self",
".",
"profit_pct",
".",
"dropna",
"(",
")",
",",
"self",
".",
"benchmark_profitpct",
".",
"dropna",
"(",
")",
")",
")",
",",
"2",
")",
"except",
":",
"print",
"(",
"'贝塔计算错误。。')",
"",
"res",
"=",
"0",
"return",
"res"
] |
beta比率 组合的系统性风险
|
[
"beta比率",
"组合的系统性风险"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAARP/QARisk.py#L450-L468
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAARP/QARisk.py
|
QA_Risk.alpha
|
def alpha(self):
"""
alpha比率 与市场基准收益无关的超额收益率
"""
return round(
float(
self.calc_alpha(
self.annualize_return,
self.benchmark_annualize_return,
self.beta,
0.05
)
),
2
)
|
python
|
def alpha(self):
"""
alpha比率 与市场基准收益无关的超额收益率
"""
return round(
float(
self.calc_alpha(
self.annualize_return,
self.benchmark_annualize_return,
self.beta,
0.05
)
),
2
)
|
[
"def",
"alpha",
"(",
"self",
")",
":",
"return",
"round",
"(",
"float",
"(",
"self",
".",
"calc_alpha",
"(",
"self",
".",
"annualize_return",
",",
"self",
".",
"benchmark_annualize_return",
",",
"self",
".",
"beta",
",",
"0.05",
")",
")",
",",
"2",
")"
] |
alpha比率 与市场基准收益无关的超额收益率
|
[
"alpha比率",
"与市场基准收益无关的超额收益率"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAARP/QARisk.py#L471-L485
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAARP/QARisk.py
|
QA_Risk.sharpe
|
def sharpe(self):
"""
夏普比率
"""
return round(
float(
self.calc_sharpe(self.annualize_return,
self.volatility,
0.05)
),
2
)
|
python
|
def sharpe(self):
"""
夏普比率
"""
return round(
float(
self.calc_sharpe(self.annualize_return,
self.volatility,
0.05)
),
2
)
|
[
"def",
"sharpe",
"(",
"self",
")",
":",
"return",
"round",
"(",
"float",
"(",
"self",
".",
"calc_sharpe",
"(",
"self",
".",
"annualize_return",
",",
"self",
".",
"volatility",
",",
"0.05",
")",
")",
",",
"2",
")"
] |
夏普比率
|
[
"夏普比率"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAARP/QARisk.py#L488-L500
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAARP/QARisk.py
|
QA_Risk.plot_assets_curve
|
def plot_assets_curve(self, length=14, height=12):
"""
资金曲线叠加图
@Roy T.Burns 2018/05/29 修改百分比显示错误
"""
plt.style.use('ggplot')
plt.figure(figsize=(length, height))
plt.subplot(211)
plt.title('BASIC INFO', fontsize=12)
plt.axis([0, length, 0, 0.6])
plt.axis('off')
i = 0
for item in ['account_cookie', 'portfolio_cookie', 'user_cookie']:
plt.text(
i,
0.5,
'{} : {}'.format(item,
self.message[item]),
fontsize=10,
rotation=0,
wrap=True
)
i += (length / 2.8)
i = 0
for item in ['benchmark_code', 'time_gap', 'max_dropback']:
plt.text(
i,
0.4,
'{} : {}'.format(item,
self.message[item]),
fontsize=10,
ha='left',
rotation=0,
wrap=True
)
i += (length / 2.8)
i = 0
for item in ['annualize_return', 'bm_annualizereturn', 'profit']:
plt.text(
i,
0.3,
'{} : {} %'.format(item,
self.message.get(item,
0) * 100),
fontsize=10,
ha='left',
rotation=0,
wrap=True
)
i += length / 2.8
i = 0
for item in ['init_cash', 'last_assets', 'volatility']:
plt.text(
i,
0.2,
'{} : {} '.format(item,
self.message[item]),
fontsize=10,
ha='left',
rotation=0,
wrap=True
)
i += length / 2.8
i = 0
for item in ['alpha', 'beta', 'sharpe']:
plt.text(
i,
0.1,
'{} : {}'.format(item,
self.message[item]),
ha='left',
fontsize=10,
rotation=0,
wrap=True
)
i += length / 2.8
plt.subplot(212)
self.assets.plot()
self.benchmark_assets.xs(self.benchmark_code, level=1).plot()
asset_p = mpatches.Patch(
color='red',
label='{}'.format(self.account.account_cookie)
)
asset_b = mpatches.Patch(
label='benchmark {}'.format(self.benchmark_code)
)
plt.legend(handles=[asset_p, asset_b], loc=0)
plt.title('ASSET AND BENCKMARK')
return plt
|
python
|
def plot_assets_curve(self, length=14, height=12):
"""
资金曲线叠加图
@Roy T.Burns 2018/05/29 修改百分比显示错误
"""
plt.style.use('ggplot')
plt.figure(figsize=(length, height))
plt.subplot(211)
plt.title('BASIC INFO', fontsize=12)
plt.axis([0, length, 0, 0.6])
plt.axis('off')
i = 0
for item in ['account_cookie', 'portfolio_cookie', 'user_cookie']:
plt.text(
i,
0.5,
'{} : {}'.format(item,
self.message[item]),
fontsize=10,
rotation=0,
wrap=True
)
i += (length / 2.8)
i = 0
for item in ['benchmark_code', 'time_gap', 'max_dropback']:
plt.text(
i,
0.4,
'{} : {}'.format(item,
self.message[item]),
fontsize=10,
ha='left',
rotation=0,
wrap=True
)
i += (length / 2.8)
i = 0
for item in ['annualize_return', 'bm_annualizereturn', 'profit']:
plt.text(
i,
0.3,
'{} : {} %'.format(item,
self.message.get(item,
0) * 100),
fontsize=10,
ha='left',
rotation=0,
wrap=True
)
i += length / 2.8
i = 0
for item in ['init_cash', 'last_assets', 'volatility']:
plt.text(
i,
0.2,
'{} : {} '.format(item,
self.message[item]),
fontsize=10,
ha='left',
rotation=0,
wrap=True
)
i += length / 2.8
i = 0
for item in ['alpha', 'beta', 'sharpe']:
plt.text(
i,
0.1,
'{} : {}'.format(item,
self.message[item]),
ha='left',
fontsize=10,
rotation=0,
wrap=True
)
i += length / 2.8
plt.subplot(212)
self.assets.plot()
self.benchmark_assets.xs(self.benchmark_code, level=1).plot()
asset_p = mpatches.Patch(
color='red',
label='{}'.format(self.account.account_cookie)
)
asset_b = mpatches.Patch(
label='benchmark {}'.format(self.benchmark_code)
)
plt.legend(handles=[asset_p, asset_b], loc=0)
plt.title('ASSET AND BENCKMARK')
return plt
|
[
"def",
"plot_assets_curve",
"(",
"self",
",",
"length",
"=",
"14",
",",
"height",
"=",
"12",
")",
":",
"plt",
".",
"style",
".",
"use",
"(",
"'ggplot'",
")",
"plt",
".",
"figure",
"(",
"figsize",
"=",
"(",
"length",
",",
"height",
")",
")",
"plt",
".",
"subplot",
"(",
"211",
")",
"plt",
".",
"title",
"(",
"'BASIC INFO'",
",",
"fontsize",
"=",
"12",
")",
"plt",
".",
"axis",
"(",
"[",
"0",
",",
"length",
",",
"0",
",",
"0.6",
"]",
")",
"plt",
".",
"axis",
"(",
"'off'",
")",
"i",
"=",
"0",
"for",
"item",
"in",
"[",
"'account_cookie'",
",",
"'portfolio_cookie'",
",",
"'user_cookie'",
"]",
":",
"plt",
".",
"text",
"(",
"i",
",",
"0.5",
",",
"'{} : {}'",
".",
"format",
"(",
"item",
",",
"self",
".",
"message",
"[",
"item",
"]",
")",
",",
"fontsize",
"=",
"10",
",",
"rotation",
"=",
"0",
",",
"wrap",
"=",
"True",
")",
"i",
"+=",
"(",
"length",
"/",
"2.8",
")",
"i",
"=",
"0",
"for",
"item",
"in",
"[",
"'benchmark_code'",
",",
"'time_gap'",
",",
"'max_dropback'",
"]",
":",
"plt",
".",
"text",
"(",
"i",
",",
"0.4",
",",
"'{} : {}'",
".",
"format",
"(",
"item",
",",
"self",
".",
"message",
"[",
"item",
"]",
")",
",",
"fontsize",
"=",
"10",
",",
"ha",
"=",
"'left'",
",",
"rotation",
"=",
"0",
",",
"wrap",
"=",
"True",
")",
"i",
"+=",
"(",
"length",
"/",
"2.8",
")",
"i",
"=",
"0",
"for",
"item",
"in",
"[",
"'annualize_return'",
",",
"'bm_annualizereturn'",
",",
"'profit'",
"]",
":",
"plt",
".",
"text",
"(",
"i",
",",
"0.3",
",",
"'{} : {} %'",
".",
"format",
"(",
"item",
",",
"self",
".",
"message",
".",
"get",
"(",
"item",
",",
"0",
")",
"*",
"100",
")",
",",
"fontsize",
"=",
"10",
",",
"ha",
"=",
"'left'",
",",
"rotation",
"=",
"0",
",",
"wrap",
"=",
"True",
")",
"i",
"+=",
"length",
"/",
"2.8",
"i",
"=",
"0",
"for",
"item",
"in",
"[",
"'init_cash'",
",",
"'last_assets'",
",",
"'volatility'",
"]",
":",
"plt",
".",
"text",
"(",
"i",
",",
"0.2",
",",
"'{} : {} '",
".",
"format",
"(",
"item",
",",
"self",
".",
"message",
"[",
"item",
"]",
")",
",",
"fontsize",
"=",
"10",
",",
"ha",
"=",
"'left'",
",",
"rotation",
"=",
"0",
",",
"wrap",
"=",
"True",
")",
"i",
"+=",
"length",
"/",
"2.8",
"i",
"=",
"0",
"for",
"item",
"in",
"[",
"'alpha'",
",",
"'beta'",
",",
"'sharpe'",
"]",
":",
"plt",
".",
"text",
"(",
"i",
",",
"0.1",
",",
"'{} : {}'",
".",
"format",
"(",
"item",
",",
"self",
".",
"message",
"[",
"item",
"]",
")",
",",
"ha",
"=",
"'left'",
",",
"fontsize",
"=",
"10",
",",
"rotation",
"=",
"0",
",",
"wrap",
"=",
"True",
")",
"i",
"+=",
"length",
"/",
"2.8",
"plt",
".",
"subplot",
"(",
"212",
")",
"self",
".",
"assets",
".",
"plot",
"(",
")",
"self",
".",
"benchmark_assets",
".",
"xs",
"(",
"self",
".",
"benchmark_code",
",",
"level",
"=",
"1",
")",
".",
"plot",
"(",
")",
"asset_p",
"=",
"mpatches",
".",
"Patch",
"(",
"color",
"=",
"'red'",
",",
"label",
"=",
"'{}'",
".",
"format",
"(",
"self",
".",
"account",
".",
"account_cookie",
")",
")",
"asset_b",
"=",
"mpatches",
".",
"Patch",
"(",
"label",
"=",
"'benchmark {}'",
".",
"format",
"(",
"self",
".",
"benchmark_code",
")",
")",
"plt",
".",
"legend",
"(",
"handles",
"=",
"[",
"asset_p",
",",
"asset_b",
"]",
",",
"loc",
"=",
"0",
")",
"plt",
".",
"title",
"(",
"'ASSET AND BENCKMARK'",
")",
"return",
"plt"
] |
资金曲线叠加图
@Roy T.Burns 2018/05/29 修改百分比显示错误
|
[
"资金曲线叠加图"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAARP/QARisk.py#L643-L733
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAARP/QARisk.py
|
QA_Risk.plot_signal
|
def plot_signal(self, start=None, end=None):
"""
使用热力图画出买卖信号
"""
start = self.account.start_date if start is None else start
end = self.account.end_date if end is None else end
_, ax = plt.subplots(figsize=(20, 18))
sns.heatmap(
self.account.trade.reset_index().drop(
'account_cookie',
axis=1
).set_index('datetime').loc[start:end],
cmap="YlGnBu",
linewidths=0.05,
ax=ax
)
ax.set_title(
'SIGNAL TABLE --ACCOUNT: {}'.format(self.account.account_cookie)
)
ax.set_xlabel('Code')
ax.set_ylabel('DATETIME')
return plt
|
python
|
def plot_signal(self, start=None, end=None):
"""
使用热力图画出买卖信号
"""
start = self.account.start_date if start is None else start
end = self.account.end_date if end is None else end
_, ax = plt.subplots(figsize=(20, 18))
sns.heatmap(
self.account.trade.reset_index().drop(
'account_cookie',
axis=1
).set_index('datetime').loc[start:end],
cmap="YlGnBu",
linewidths=0.05,
ax=ax
)
ax.set_title(
'SIGNAL TABLE --ACCOUNT: {}'.format(self.account.account_cookie)
)
ax.set_xlabel('Code')
ax.set_ylabel('DATETIME')
return plt
|
[
"def",
"plot_signal",
"(",
"self",
",",
"start",
"=",
"None",
",",
"end",
"=",
"None",
")",
":",
"start",
"=",
"self",
".",
"account",
".",
"start_date",
"if",
"start",
"is",
"None",
"else",
"start",
"end",
"=",
"self",
".",
"account",
".",
"end_date",
"if",
"end",
"is",
"None",
"else",
"end",
"_",
",",
"ax",
"=",
"plt",
".",
"subplots",
"(",
"figsize",
"=",
"(",
"20",
",",
"18",
")",
")",
"sns",
".",
"heatmap",
"(",
"self",
".",
"account",
".",
"trade",
".",
"reset_index",
"(",
")",
".",
"drop",
"(",
"'account_cookie'",
",",
"axis",
"=",
"1",
")",
".",
"set_index",
"(",
"'datetime'",
")",
".",
"loc",
"[",
"start",
":",
"end",
"]",
",",
"cmap",
"=",
"\"YlGnBu\"",
",",
"linewidths",
"=",
"0.05",
",",
"ax",
"=",
"ax",
")",
"ax",
".",
"set_title",
"(",
"'SIGNAL TABLE --ACCOUNT: {}'",
".",
"format",
"(",
"self",
".",
"account",
".",
"account_cookie",
")",
")",
"ax",
".",
"set_xlabel",
"(",
"'Code'",
")",
"ax",
".",
"set_ylabel",
"(",
"'DATETIME'",
")",
"return",
"plt"
] |
使用热力图画出买卖信号
|
[
"使用热力图画出买卖信号"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAARP/QARisk.py#L775-L796
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAARP/QARisk.py
|
QA_Performance.pnl_lifo
|
def pnl_lifo(self):
"""
使用后进先出法配对成交记录
"""
X = dict(
zip(
self.target.code,
[LifoQueue() for i in range(len(self.target.code))]
)
)
pair_table = []
for _, data in self.target.history_table_min.iterrows():
while True:
if X[data.code].qsize() == 0:
X[data.code].put((data.datetime, data.amount, data.price))
break
else:
l = X[data.code].get()
if (l[1] * data.amount) < 0:
# 原有多仓/ 平仓 或者原有空仓/平仓
if abs(l[1]) > abs(data.amount):
temp = (l[0], l[1] + data.amount, l[2])
X[data.code].put_nowait(temp)
if data.amount < 0:
pair_table.append(
[
data.code,
data.datetime,
l[0],
abs(data.amount),
data.price,
l[2]
]
)
break
else:
pair_table.append(
[
data.code,
l[0],
data.datetime,
abs(data.amount),
l[2],
data.price
]
)
break
elif abs(l[1]) < abs(data.amount):
data.amount = data.amount + l[1]
if data.amount < 0:
pair_table.append(
[
data.code,
data.datetime,
l[0],
l[1],
data.price,
l[2]
]
)
else:
pair_table.append(
[
data.code,
l[0],
data.datetime,
l[1],
l[2],
data.price
]
)
else:
if data.amount < 0:
pair_table.append(
[
data.code,
data.datetime,
l[0],
abs(data.amount),
data.price,
l[2]
]
)
break
else:
pair_table.append(
[
data.code,
l[0],
data.datetime,
abs(data.amount),
l[2],
data.price
]
)
break
else:
X[data.code].put_nowait(l)
X[data.code].put_nowait(
(data.datetime,
data.amount,
data.price)
)
break
pair_title = [
'code',
'sell_date',
'buy_date',
'amount',
'sell_price',
'buy_price'
]
pnl = pd.DataFrame(pair_table, columns=pair_title).set_index('code')
pnl = pnl.assign(
unit=pnl.code.apply(lambda x: self.market_preset.get_unit(x)),
pnl_ratio=(pnl.sell_price / pnl.buy_price) - 1,
sell_date=pd.to_datetime(pnl.sell_date),
buy_date=pd.to_datetime(pnl.buy_date)
)
pnl = pnl.assign(
pnl_money=(pnl.sell_price - pnl.buy_price) * pnl.amount * pnl.unit,
hold_gap=abs(pnl.sell_date - pnl.buy_date),
if_buyopen=(pnl.sell_date -
pnl.buy_date) > datetime.timedelta(days=0)
)
pnl = pnl.assign(
openprice=pnl.if_buyopen.apply(
lambda pnl: 1 if pnl else 0) * pnl.buy_price + pnl.if_buyopen.apply(lambda pnl: 0 if pnl else 1) * pnl.sell_price,
opendate=pnl.if_buyopen.apply(
lambda pnl: 1 if pnl else 0) * pnl.buy_date.map(str) + pnl.if_buyopen.apply(lambda pnl: 0 if pnl else 1) * pnl.sell_date.map(str),
closeprice=pnl.if_buyopen.apply(
lambda pnl: 0 if pnl else 1) * pnl.buy_price + pnl.if_buyopen.apply(lambda pnl: 1 if pnl else 0) * pnl.sell_price,
closedate=pnl.if_buyopen.apply(
lambda pnl: 0 if pnl else 1) * pnl.buy_date.map(str) + pnl.if_buyopen.apply(lambda pnl: 1 if pnl else 0) * pnl.sell_date.map(str))
return pnl.set_index('code')
|
python
|
def pnl_lifo(self):
"""
使用后进先出法配对成交记录
"""
X = dict(
zip(
self.target.code,
[LifoQueue() for i in range(len(self.target.code))]
)
)
pair_table = []
for _, data in self.target.history_table_min.iterrows():
while True:
if X[data.code].qsize() == 0:
X[data.code].put((data.datetime, data.amount, data.price))
break
else:
l = X[data.code].get()
if (l[1] * data.amount) < 0:
# 原有多仓/ 平仓 或者原有空仓/平仓
if abs(l[1]) > abs(data.amount):
temp = (l[0], l[1] + data.amount, l[2])
X[data.code].put_nowait(temp)
if data.amount < 0:
pair_table.append(
[
data.code,
data.datetime,
l[0],
abs(data.amount),
data.price,
l[2]
]
)
break
else:
pair_table.append(
[
data.code,
l[0],
data.datetime,
abs(data.amount),
l[2],
data.price
]
)
break
elif abs(l[1]) < abs(data.amount):
data.amount = data.amount + l[1]
if data.amount < 0:
pair_table.append(
[
data.code,
data.datetime,
l[0],
l[1],
data.price,
l[2]
]
)
else:
pair_table.append(
[
data.code,
l[0],
data.datetime,
l[1],
l[2],
data.price
]
)
else:
if data.amount < 0:
pair_table.append(
[
data.code,
data.datetime,
l[0],
abs(data.amount),
data.price,
l[2]
]
)
break
else:
pair_table.append(
[
data.code,
l[0],
data.datetime,
abs(data.amount),
l[2],
data.price
]
)
break
else:
X[data.code].put_nowait(l)
X[data.code].put_nowait(
(data.datetime,
data.amount,
data.price)
)
break
pair_title = [
'code',
'sell_date',
'buy_date',
'amount',
'sell_price',
'buy_price'
]
pnl = pd.DataFrame(pair_table, columns=pair_title).set_index('code')
pnl = pnl.assign(
unit=pnl.code.apply(lambda x: self.market_preset.get_unit(x)),
pnl_ratio=(pnl.sell_price / pnl.buy_price) - 1,
sell_date=pd.to_datetime(pnl.sell_date),
buy_date=pd.to_datetime(pnl.buy_date)
)
pnl = pnl.assign(
pnl_money=(pnl.sell_price - pnl.buy_price) * pnl.amount * pnl.unit,
hold_gap=abs(pnl.sell_date - pnl.buy_date),
if_buyopen=(pnl.sell_date -
pnl.buy_date) > datetime.timedelta(days=0)
)
pnl = pnl.assign(
openprice=pnl.if_buyopen.apply(
lambda pnl: 1 if pnl else 0) * pnl.buy_price + pnl.if_buyopen.apply(lambda pnl: 0 if pnl else 1) * pnl.sell_price,
opendate=pnl.if_buyopen.apply(
lambda pnl: 1 if pnl else 0) * pnl.buy_date.map(str) + pnl.if_buyopen.apply(lambda pnl: 0 if pnl else 1) * pnl.sell_date.map(str),
closeprice=pnl.if_buyopen.apply(
lambda pnl: 0 if pnl else 1) * pnl.buy_price + pnl.if_buyopen.apply(lambda pnl: 1 if pnl else 0) * pnl.sell_price,
closedate=pnl.if_buyopen.apply(
lambda pnl: 0 if pnl else 1) * pnl.buy_date.map(str) + pnl.if_buyopen.apply(lambda pnl: 1 if pnl else 0) * pnl.sell_date.map(str))
return pnl.set_index('code')
|
[
"def",
"pnl_lifo",
"(",
"self",
")",
":",
"X",
"=",
"dict",
"(",
"zip",
"(",
"self",
".",
"target",
".",
"code",
",",
"[",
"LifoQueue",
"(",
")",
"for",
"i",
"in",
"range",
"(",
"len",
"(",
"self",
".",
"target",
".",
"code",
")",
")",
"]",
")",
")",
"pair_table",
"=",
"[",
"]",
"for",
"_",
",",
"data",
"in",
"self",
".",
"target",
".",
"history_table_min",
".",
"iterrows",
"(",
")",
":",
"while",
"True",
":",
"if",
"X",
"[",
"data",
".",
"code",
"]",
".",
"qsize",
"(",
")",
"==",
"0",
":",
"X",
"[",
"data",
".",
"code",
"]",
".",
"put",
"(",
"(",
"data",
".",
"datetime",
",",
"data",
".",
"amount",
",",
"data",
".",
"price",
")",
")",
"break",
"else",
":",
"l",
"=",
"X",
"[",
"data",
".",
"code",
"]",
".",
"get",
"(",
")",
"if",
"(",
"l",
"[",
"1",
"]",
"*",
"data",
".",
"amount",
")",
"<",
"0",
":",
"# 原有多仓/ 平仓 或者原有空仓/平仓",
"if",
"abs",
"(",
"l",
"[",
"1",
"]",
")",
">",
"abs",
"(",
"data",
".",
"amount",
")",
":",
"temp",
"=",
"(",
"l",
"[",
"0",
"]",
",",
"l",
"[",
"1",
"]",
"+",
"data",
".",
"amount",
",",
"l",
"[",
"2",
"]",
")",
"X",
"[",
"data",
".",
"code",
"]",
".",
"put_nowait",
"(",
"temp",
")",
"if",
"data",
".",
"amount",
"<",
"0",
":",
"pair_table",
".",
"append",
"(",
"[",
"data",
".",
"code",
",",
"data",
".",
"datetime",
",",
"l",
"[",
"0",
"]",
",",
"abs",
"(",
"data",
".",
"amount",
")",
",",
"data",
".",
"price",
",",
"l",
"[",
"2",
"]",
"]",
")",
"break",
"else",
":",
"pair_table",
".",
"append",
"(",
"[",
"data",
".",
"code",
",",
"l",
"[",
"0",
"]",
",",
"data",
".",
"datetime",
",",
"abs",
"(",
"data",
".",
"amount",
")",
",",
"l",
"[",
"2",
"]",
",",
"data",
".",
"price",
"]",
")",
"break",
"elif",
"abs",
"(",
"l",
"[",
"1",
"]",
")",
"<",
"abs",
"(",
"data",
".",
"amount",
")",
":",
"data",
".",
"amount",
"=",
"data",
".",
"amount",
"+",
"l",
"[",
"1",
"]",
"if",
"data",
".",
"amount",
"<",
"0",
":",
"pair_table",
".",
"append",
"(",
"[",
"data",
".",
"code",
",",
"data",
".",
"datetime",
",",
"l",
"[",
"0",
"]",
",",
"l",
"[",
"1",
"]",
",",
"data",
".",
"price",
",",
"l",
"[",
"2",
"]",
"]",
")",
"else",
":",
"pair_table",
".",
"append",
"(",
"[",
"data",
".",
"code",
",",
"l",
"[",
"0",
"]",
",",
"data",
".",
"datetime",
",",
"l",
"[",
"1",
"]",
",",
"l",
"[",
"2",
"]",
",",
"data",
".",
"price",
"]",
")",
"else",
":",
"if",
"data",
".",
"amount",
"<",
"0",
":",
"pair_table",
".",
"append",
"(",
"[",
"data",
".",
"code",
",",
"data",
".",
"datetime",
",",
"l",
"[",
"0",
"]",
",",
"abs",
"(",
"data",
".",
"amount",
")",
",",
"data",
".",
"price",
",",
"l",
"[",
"2",
"]",
"]",
")",
"break",
"else",
":",
"pair_table",
".",
"append",
"(",
"[",
"data",
".",
"code",
",",
"l",
"[",
"0",
"]",
",",
"data",
".",
"datetime",
",",
"abs",
"(",
"data",
".",
"amount",
")",
",",
"l",
"[",
"2",
"]",
",",
"data",
".",
"price",
"]",
")",
"break",
"else",
":",
"X",
"[",
"data",
".",
"code",
"]",
".",
"put_nowait",
"(",
"l",
")",
"X",
"[",
"data",
".",
"code",
"]",
".",
"put_nowait",
"(",
"(",
"data",
".",
"datetime",
",",
"data",
".",
"amount",
",",
"data",
".",
"price",
")",
")",
"break",
"pair_title",
"=",
"[",
"'code'",
",",
"'sell_date'",
",",
"'buy_date'",
",",
"'amount'",
",",
"'sell_price'",
",",
"'buy_price'",
"]",
"pnl",
"=",
"pd",
".",
"DataFrame",
"(",
"pair_table",
",",
"columns",
"=",
"pair_title",
")",
".",
"set_index",
"(",
"'code'",
")",
"pnl",
"=",
"pnl",
".",
"assign",
"(",
"unit",
"=",
"pnl",
".",
"code",
".",
"apply",
"(",
"lambda",
"x",
":",
"self",
".",
"market_preset",
".",
"get_unit",
"(",
"x",
")",
")",
",",
"pnl_ratio",
"=",
"(",
"pnl",
".",
"sell_price",
"/",
"pnl",
".",
"buy_price",
")",
"-",
"1",
",",
"sell_date",
"=",
"pd",
".",
"to_datetime",
"(",
"pnl",
".",
"sell_date",
")",
",",
"buy_date",
"=",
"pd",
".",
"to_datetime",
"(",
"pnl",
".",
"buy_date",
")",
")",
"pnl",
"=",
"pnl",
".",
"assign",
"(",
"pnl_money",
"=",
"(",
"pnl",
".",
"sell_price",
"-",
"pnl",
".",
"buy_price",
")",
"*",
"pnl",
".",
"amount",
"*",
"pnl",
".",
"unit",
",",
"hold_gap",
"=",
"abs",
"(",
"pnl",
".",
"sell_date",
"-",
"pnl",
".",
"buy_date",
")",
",",
"if_buyopen",
"=",
"(",
"pnl",
".",
"sell_date",
"-",
"pnl",
".",
"buy_date",
")",
">",
"datetime",
".",
"timedelta",
"(",
"days",
"=",
"0",
")",
")",
"pnl",
"=",
"pnl",
".",
"assign",
"(",
"openprice",
"=",
"pnl",
".",
"if_buyopen",
".",
"apply",
"(",
"lambda",
"pnl",
":",
"1",
"if",
"pnl",
"else",
"0",
")",
"*",
"pnl",
".",
"buy_price",
"+",
"pnl",
".",
"if_buyopen",
".",
"apply",
"(",
"lambda",
"pnl",
":",
"0",
"if",
"pnl",
"else",
"1",
")",
"*",
"pnl",
".",
"sell_price",
",",
"opendate",
"=",
"pnl",
".",
"if_buyopen",
".",
"apply",
"(",
"lambda",
"pnl",
":",
"1",
"if",
"pnl",
"else",
"0",
")",
"*",
"pnl",
".",
"buy_date",
".",
"map",
"(",
"str",
")",
"+",
"pnl",
".",
"if_buyopen",
".",
"apply",
"(",
"lambda",
"pnl",
":",
"0",
"if",
"pnl",
"else",
"1",
")",
"*",
"pnl",
".",
"sell_date",
".",
"map",
"(",
"str",
")",
",",
"closeprice",
"=",
"pnl",
".",
"if_buyopen",
".",
"apply",
"(",
"lambda",
"pnl",
":",
"0",
"if",
"pnl",
"else",
"1",
")",
"*",
"pnl",
".",
"buy_price",
"+",
"pnl",
".",
"if_buyopen",
".",
"apply",
"(",
"lambda",
"pnl",
":",
"1",
"if",
"pnl",
"else",
"0",
")",
"*",
"pnl",
".",
"sell_price",
",",
"closedate",
"=",
"pnl",
".",
"if_buyopen",
".",
"apply",
"(",
"lambda",
"pnl",
":",
"0",
"if",
"pnl",
"else",
"1",
")",
"*",
"pnl",
".",
"buy_date",
".",
"map",
"(",
"str",
")",
"+",
"pnl",
".",
"if_buyopen",
".",
"apply",
"(",
"lambda",
"pnl",
":",
"1",
"if",
"pnl",
"else",
"0",
")",
"*",
"pnl",
".",
"sell_date",
".",
"map",
"(",
"str",
")",
")",
"return",
"pnl",
".",
"set_index",
"(",
"'code'",
")"
] |
使用后进先出法配对成交记录
|
[
"使用后进先出法配对成交记录"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAARP/QARisk.py#L1015-L1155
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAARP/QARisk.py
|
QA_Performance.plot_pnlratio
|
def plot_pnlratio(self):
"""
画出pnl比率散点图
"""
plt.scatter(x=self.pnl.sell_date.apply(str), y=self.pnl.pnl_ratio)
plt.gcf().autofmt_xdate()
return plt
|
python
|
def plot_pnlratio(self):
"""
画出pnl比率散点图
"""
plt.scatter(x=self.pnl.sell_date.apply(str), y=self.pnl.pnl_ratio)
plt.gcf().autofmt_xdate()
return plt
|
[
"def",
"plot_pnlratio",
"(",
"self",
")",
":",
"plt",
".",
"scatter",
"(",
"x",
"=",
"self",
".",
"pnl",
".",
"sell_date",
".",
"apply",
"(",
"str",
")",
",",
"y",
"=",
"self",
".",
"pnl",
".",
"pnl_ratio",
")",
"plt",
".",
"gcf",
"(",
")",
".",
"autofmt_xdate",
"(",
")",
"return",
"plt"
] |
画出pnl比率散点图
|
[
"画出pnl比率散点图"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAARP/QARisk.py#L1313-L1320
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAARP/QARisk.py
|
QA_Performance.plot_pnlmoney
|
def plot_pnlmoney(self):
"""
画出pnl盈亏额散点图
"""
plt.scatter(x=self.pnl.sell_date.apply(str), y=self.pnl.pnl_money)
plt.gcf().autofmt_xdate()
return plt
|
python
|
def plot_pnlmoney(self):
"""
画出pnl盈亏额散点图
"""
plt.scatter(x=self.pnl.sell_date.apply(str), y=self.pnl.pnl_money)
plt.gcf().autofmt_xdate()
return plt
|
[
"def",
"plot_pnlmoney",
"(",
"self",
")",
":",
"plt",
".",
"scatter",
"(",
"x",
"=",
"self",
".",
"pnl",
".",
"sell_date",
".",
"apply",
"(",
"str",
")",
",",
"y",
"=",
"self",
".",
"pnl",
".",
"pnl_money",
")",
"plt",
".",
"gcf",
"(",
")",
".",
"autofmt_xdate",
"(",
")",
"return",
"plt"
] |
画出pnl盈亏额散点图
|
[
"画出pnl盈亏额散点图"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAARP/QARisk.py#L1322-L1328
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAARP/QARisk.py
|
QA_Performance.win_rate
|
def win_rate(self):
"""胜率
胜率
盈利次数/总次数
"""
data = self.pnl
try:
return round(len(data.query('pnl_money>0')) / len(data), 2)
except ZeroDivisionError:
return 0
|
python
|
def win_rate(self):
"""胜率
胜率
盈利次数/总次数
"""
data = self.pnl
try:
return round(len(data.query('pnl_money>0')) / len(data), 2)
except ZeroDivisionError:
return 0
|
[
"def",
"win_rate",
"(",
"self",
")",
":",
"data",
"=",
"self",
".",
"pnl",
"try",
":",
"return",
"round",
"(",
"len",
"(",
"data",
".",
"query",
"(",
"'pnl_money>0'",
")",
")",
"/",
"len",
"(",
"data",
")",
",",
"2",
")",
"except",
"ZeroDivisionError",
":",
"return",
"0"
] |
胜率
胜率
盈利次数/总次数
|
[
"胜率"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAARP/QARisk.py#L1346-L1356
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QASetting/crontab.py
|
CronTabItem.next_time
|
def next_time(self, asc=False):
"""Get the local time of the next schedule time this job will run.
:param bool asc: Format the result with ``time.asctime()``
:returns: The epoch time or string representation of the epoch time that
the job should be run next
"""
_time = time.localtime(time.time() + self.next())
if asc:
return time.asctime(_time)
return time.mktime(_time)
|
python
|
def next_time(self, asc=False):
"""Get the local time of the next schedule time this job will run.
:param bool asc: Format the result with ``time.asctime()``
:returns: The epoch time or string representation of the epoch time that
the job should be run next
"""
_time = time.localtime(time.time() + self.next())
if asc:
return time.asctime(_time)
return time.mktime(_time)
|
[
"def",
"next_time",
"(",
"self",
",",
"asc",
"=",
"False",
")",
":",
"_time",
"=",
"time",
".",
"localtime",
"(",
"time",
".",
"time",
"(",
")",
"+",
"self",
".",
"next",
"(",
")",
")",
"if",
"asc",
":",
"return",
"time",
".",
"asctime",
"(",
"_time",
")",
"return",
"time",
".",
"mktime",
"(",
"_time",
")"
] |
Get the local time of the next schedule time this job will run.
:param bool asc: Format the result with ``time.asctime()``
:returns: The epoch time or string representation of the epoch time that
the job should be run next
|
[
"Get",
"the",
"local",
"time",
"of",
"the",
"next",
"schedule",
"time",
"this",
"job",
"will",
"run",
".",
":",
"param",
"bool",
"asc",
":",
"Format",
"the",
"result",
"with",
"time",
".",
"asctime",
"()",
":",
"returns",
":",
"The",
"epoch",
"time",
"or",
"string",
"representation",
"of",
"the",
"epoch",
"time",
"that",
"the",
"job",
"should",
"be",
"run",
"next"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QASetting/crontab.py#L51-L62
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAFetch/__init__.py
|
QA_fetch_get_future_transaction_realtime
|
def QA_fetch_get_future_transaction_realtime(package, code):
"""
期货实时tick
"""
Engine = use(package)
if package in ['tdx', 'pytdx']:
return Engine.QA_fetch_get_future_transaction_realtime(code)
else:
return 'Unsupport packages'
|
python
|
def QA_fetch_get_future_transaction_realtime(package, code):
"""
期货实时tick
"""
Engine = use(package)
if package in ['tdx', 'pytdx']:
return Engine.QA_fetch_get_future_transaction_realtime(code)
else:
return 'Unsupport packages'
|
[
"def",
"QA_fetch_get_future_transaction_realtime",
"(",
"package",
",",
"code",
")",
":",
"Engine",
"=",
"use",
"(",
"package",
")",
"if",
"package",
"in",
"[",
"'tdx'",
",",
"'pytdx'",
"]",
":",
"return",
"Engine",
".",
"QA_fetch_get_future_transaction_realtime",
"(",
"code",
")",
"else",
":",
"return",
"'Unsupport packages'"
] |
期货实时tick
|
[
"期货实时tick"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAFetch/__init__.py#L272-L280
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/indicators.py
|
QA_indicator_MA
|
def QA_indicator_MA(DataFrame,*args,**kwargs):
"""MA
Arguments:
DataFrame {[type]} -- [description]
Returns:
[type] -- [description]
"""
CLOSE = DataFrame['close']
return pd.DataFrame({'MA{}'.format(N): MA(CLOSE, N) for N in list(args)})
|
python
|
def QA_indicator_MA(DataFrame,*args,**kwargs):
"""MA
Arguments:
DataFrame {[type]} -- [description]
Returns:
[type] -- [description]
"""
CLOSE = DataFrame['close']
return pd.DataFrame({'MA{}'.format(N): MA(CLOSE, N) for N in list(args)})
|
[
"def",
"QA_indicator_MA",
"(",
"DataFrame",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"CLOSE",
"=",
"DataFrame",
"[",
"'close'",
"]",
"return",
"pd",
".",
"DataFrame",
"(",
"{",
"'MA{}'",
".",
"format",
"(",
"N",
")",
":",
"MA",
"(",
"CLOSE",
",",
"N",
")",
"for",
"N",
"in",
"list",
"(",
"args",
")",
"}",
")"
] |
MA
Arguments:
DataFrame {[type]} -- [description]
Returns:
[type] -- [description]
|
[
"MA",
"Arguments",
":",
"DataFrame",
"{",
"[",
"type",
"]",
"}",
"--",
"[",
"description",
"]",
"Returns",
":",
"[",
"type",
"]",
"--",
"[",
"description",
"]"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/indicators.py#L58-L69
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/indicators.py
|
QA_indicator_MACD
|
def QA_indicator_MACD(DataFrame, short=12, long=26, mid=9):
"""
MACD CALC
"""
CLOSE = DataFrame['close']
DIF = EMA(CLOSE, short)-EMA(CLOSE, long)
DEA = EMA(DIF, mid)
MACD = (DIF-DEA)*2
return pd.DataFrame({'DIF': DIF, 'DEA': DEA, 'MACD': MACD})
|
python
|
def QA_indicator_MACD(DataFrame, short=12, long=26, mid=9):
"""
MACD CALC
"""
CLOSE = DataFrame['close']
DIF = EMA(CLOSE, short)-EMA(CLOSE, long)
DEA = EMA(DIF, mid)
MACD = (DIF-DEA)*2
return pd.DataFrame({'DIF': DIF, 'DEA': DEA, 'MACD': MACD})
|
[
"def",
"QA_indicator_MACD",
"(",
"DataFrame",
",",
"short",
"=",
"12",
",",
"long",
"=",
"26",
",",
"mid",
"=",
"9",
")",
":",
"CLOSE",
"=",
"DataFrame",
"[",
"'close'",
"]",
"DIF",
"=",
"EMA",
"(",
"CLOSE",
",",
"short",
")",
"-",
"EMA",
"(",
"CLOSE",
",",
"long",
")",
"DEA",
"=",
"EMA",
"(",
"DIF",
",",
"mid",
")",
"MACD",
"=",
"(",
"DIF",
"-",
"DEA",
")",
"*",
"2",
"return",
"pd",
".",
"DataFrame",
"(",
"{",
"'DIF'",
":",
"DIF",
",",
"'DEA'",
":",
"DEA",
",",
"'MACD'",
":",
"MACD",
"}",
")"
] |
MACD CALC
|
[
"MACD",
"CALC"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/indicators.py#L82-L92
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/indicators.py
|
QA_indicator_DMI
|
def QA_indicator_DMI(DataFrame, M1=14, M2=6):
"""
趋向指标 DMI
"""
HIGH = DataFrame.high
LOW = DataFrame.low
CLOSE = DataFrame.close
OPEN = DataFrame.open
TR = SUM(MAX(MAX(HIGH-LOW, ABS(HIGH-REF(CLOSE, 1))),
ABS(LOW-REF(CLOSE, 1))), M1)
HD = HIGH-REF(HIGH, 1)
LD = REF(LOW, 1)-LOW
DMP = SUM(IFAND(HD>0,HD>LD,HD,0), M1)
DMM = SUM(IFAND(LD>0,LD>HD,LD,0), M1)
DI1 = DMP*100/TR
DI2 = DMM*100/TR
ADX = MA(ABS(DI2-DI1)/(DI1+DI2)*100, M2)
ADXR = (ADX+REF(ADX, M2))/2
return pd.DataFrame({
'DI1': DI1, 'DI2': DI2,
'ADX': ADX, 'ADXR': ADXR
})
|
python
|
def QA_indicator_DMI(DataFrame, M1=14, M2=6):
"""
趋向指标 DMI
"""
HIGH = DataFrame.high
LOW = DataFrame.low
CLOSE = DataFrame.close
OPEN = DataFrame.open
TR = SUM(MAX(MAX(HIGH-LOW, ABS(HIGH-REF(CLOSE, 1))),
ABS(LOW-REF(CLOSE, 1))), M1)
HD = HIGH-REF(HIGH, 1)
LD = REF(LOW, 1)-LOW
DMP = SUM(IFAND(HD>0,HD>LD,HD,0), M1)
DMM = SUM(IFAND(LD>0,LD>HD,LD,0), M1)
DI1 = DMP*100/TR
DI2 = DMM*100/TR
ADX = MA(ABS(DI2-DI1)/(DI1+DI2)*100, M2)
ADXR = (ADX+REF(ADX, M2))/2
return pd.DataFrame({
'DI1': DI1, 'DI2': DI2,
'ADX': ADX, 'ADXR': ADXR
})
|
[
"def",
"QA_indicator_DMI",
"(",
"DataFrame",
",",
"M1",
"=",
"14",
",",
"M2",
"=",
"6",
")",
":",
"HIGH",
"=",
"DataFrame",
".",
"high",
"LOW",
"=",
"DataFrame",
".",
"low",
"CLOSE",
"=",
"DataFrame",
".",
"close",
"OPEN",
"=",
"DataFrame",
".",
"open",
"TR",
"=",
"SUM",
"(",
"MAX",
"(",
"MAX",
"(",
"HIGH",
"-",
"LOW",
",",
"ABS",
"(",
"HIGH",
"-",
"REF",
"(",
"CLOSE",
",",
"1",
")",
")",
")",
",",
"ABS",
"(",
"LOW",
"-",
"REF",
"(",
"CLOSE",
",",
"1",
")",
")",
")",
",",
"M1",
")",
"HD",
"=",
"HIGH",
"-",
"REF",
"(",
"HIGH",
",",
"1",
")",
"LD",
"=",
"REF",
"(",
"LOW",
",",
"1",
")",
"-",
"LOW",
"DMP",
"=",
"SUM",
"(",
"IFAND",
"(",
"HD",
">",
"0",
",",
"HD",
">",
"LD",
",",
"HD",
",",
"0",
")",
",",
"M1",
")",
"DMM",
"=",
"SUM",
"(",
"IFAND",
"(",
"LD",
">",
"0",
",",
"LD",
">",
"HD",
",",
"LD",
",",
"0",
")",
",",
"M1",
")",
"DI1",
"=",
"DMP",
"*",
"100",
"/",
"TR",
"DI2",
"=",
"DMM",
"*",
"100",
"/",
"TR",
"ADX",
"=",
"MA",
"(",
"ABS",
"(",
"DI2",
"-",
"DI1",
")",
"/",
"(",
"DI1",
"+",
"DI2",
")",
"*",
"100",
",",
"M2",
")",
"ADXR",
"=",
"(",
"ADX",
"+",
"REF",
"(",
"ADX",
",",
"M2",
")",
")",
"/",
"2",
"return",
"pd",
".",
"DataFrame",
"(",
"{",
"'DI1'",
":",
"DI1",
",",
"'DI2'",
":",
"DI2",
",",
"'ADX'",
":",
"ADX",
",",
"'ADXR'",
":",
"ADXR",
"}",
")"
] |
趋向指标 DMI
|
[
"趋向指标",
"DMI"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/indicators.py#L95-L118
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/indicators.py
|
QA_indicator_PBX
|
def QA_indicator_PBX(DataFrame, N1=3, N2=5, N3=8, N4=13, N5=18, N6=24):
'瀑布线'
C = DataFrame['close']
PBX1 = (EMA(C, N1) + EMA(C, 2 * N1) + EMA(C, 4 * N1)) / 3
PBX2 = (EMA(C, N2) + EMA(C, 2 * N2) + EMA(C, 4 * N2)) / 3
PBX3 = (EMA(C, N3) + EMA(C, 2 * N3) + EMA(C, 4 * N3)) / 3
PBX4 = (EMA(C, N4) + EMA(C, 2 * N4) + EMA(C, 4 * N4)) / 3
PBX5 = (EMA(C, N5) + EMA(C, 2 * N5) + EMA(C, 4 * N5)) / 3
PBX6 = (EMA(C, N6) + EMA(C, 2 * N6) + EMA(C, 4 * N6)) / 3
DICT = {'PBX1': PBX1, 'PBX2': PBX2, 'PBX3': PBX3,
'PBX4': PBX4, 'PBX5': PBX5, 'PBX6': PBX6}
return pd.DataFrame(DICT)
|
python
|
def QA_indicator_PBX(DataFrame, N1=3, N2=5, N3=8, N4=13, N5=18, N6=24):
'瀑布线'
C = DataFrame['close']
PBX1 = (EMA(C, N1) + EMA(C, 2 * N1) + EMA(C, 4 * N1)) / 3
PBX2 = (EMA(C, N2) + EMA(C, 2 * N2) + EMA(C, 4 * N2)) / 3
PBX3 = (EMA(C, N3) + EMA(C, 2 * N3) + EMA(C, 4 * N3)) / 3
PBX4 = (EMA(C, N4) + EMA(C, 2 * N4) + EMA(C, 4 * N4)) / 3
PBX5 = (EMA(C, N5) + EMA(C, 2 * N5) + EMA(C, 4 * N5)) / 3
PBX6 = (EMA(C, N6) + EMA(C, 2 * N6) + EMA(C, 4 * N6)) / 3
DICT = {'PBX1': PBX1, 'PBX2': PBX2, 'PBX3': PBX3,
'PBX4': PBX4, 'PBX5': PBX5, 'PBX6': PBX6}
return pd.DataFrame(DICT)
|
[
"def",
"QA_indicator_PBX",
"(",
"DataFrame",
",",
"N1",
"=",
"3",
",",
"N2",
"=",
"5",
",",
"N3",
"=",
"8",
",",
"N4",
"=",
"13",
",",
"N5",
"=",
"18",
",",
"N6",
"=",
"24",
")",
":",
"C",
"=",
"DataFrame",
"[",
"'close'",
"]",
"PBX1",
"=",
"(",
"EMA",
"(",
"C",
",",
"N1",
")",
"+",
"EMA",
"(",
"C",
",",
"2",
"*",
"N1",
")",
"+",
"EMA",
"(",
"C",
",",
"4",
"*",
"N1",
")",
")",
"/",
"3",
"PBX2",
"=",
"(",
"EMA",
"(",
"C",
",",
"N2",
")",
"+",
"EMA",
"(",
"C",
",",
"2",
"*",
"N2",
")",
"+",
"EMA",
"(",
"C",
",",
"4",
"*",
"N2",
")",
")",
"/",
"3",
"PBX3",
"=",
"(",
"EMA",
"(",
"C",
",",
"N3",
")",
"+",
"EMA",
"(",
"C",
",",
"2",
"*",
"N3",
")",
"+",
"EMA",
"(",
"C",
",",
"4",
"*",
"N3",
")",
")",
"/",
"3",
"PBX4",
"=",
"(",
"EMA",
"(",
"C",
",",
"N4",
")",
"+",
"EMA",
"(",
"C",
",",
"2",
"*",
"N4",
")",
"+",
"EMA",
"(",
"C",
",",
"4",
"*",
"N4",
")",
")",
"/",
"3",
"PBX5",
"=",
"(",
"EMA",
"(",
"C",
",",
"N5",
")",
"+",
"EMA",
"(",
"C",
",",
"2",
"*",
"N5",
")",
"+",
"EMA",
"(",
"C",
",",
"4",
"*",
"N5",
")",
")",
"/",
"3",
"PBX6",
"=",
"(",
"EMA",
"(",
"C",
",",
"N6",
")",
"+",
"EMA",
"(",
"C",
",",
"2",
"*",
"N6",
")",
"+",
"EMA",
"(",
"C",
",",
"4",
"*",
"N6",
")",
")",
"/",
"3",
"DICT",
"=",
"{",
"'PBX1'",
":",
"PBX1",
",",
"'PBX2'",
":",
"PBX2",
",",
"'PBX3'",
":",
"PBX3",
",",
"'PBX4'",
":",
"PBX4",
",",
"'PBX5'",
":",
"PBX5",
",",
"'PBX6'",
":",
"PBX6",
"}",
"return",
"pd",
".",
"DataFrame",
"(",
"DICT",
")"
] |
瀑布线
|
[
"瀑布线"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/indicators.py#L121-L133
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/indicators.py
|
QA_indicator_DMA
|
def QA_indicator_DMA(DataFrame, M1=10, M2=50, M3=10):
"""
平均线差 DMA
"""
CLOSE = DataFrame.close
DDD = MA(CLOSE, M1) - MA(CLOSE, M2)
AMA = MA(DDD, M3)
return pd.DataFrame({
'DDD': DDD, 'AMA': AMA
})
|
python
|
def QA_indicator_DMA(DataFrame, M1=10, M2=50, M3=10):
"""
平均线差 DMA
"""
CLOSE = DataFrame.close
DDD = MA(CLOSE, M1) - MA(CLOSE, M2)
AMA = MA(DDD, M3)
return pd.DataFrame({
'DDD': DDD, 'AMA': AMA
})
|
[
"def",
"QA_indicator_DMA",
"(",
"DataFrame",
",",
"M1",
"=",
"10",
",",
"M2",
"=",
"50",
",",
"M3",
"=",
"10",
")",
":",
"CLOSE",
"=",
"DataFrame",
".",
"close",
"DDD",
"=",
"MA",
"(",
"CLOSE",
",",
"M1",
")",
"-",
"MA",
"(",
"CLOSE",
",",
"M2",
")",
"AMA",
"=",
"MA",
"(",
"DDD",
",",
"M3",
")",
"return",
"pd",
".",
"DataFrame",
"(",
"{",
"'DDD'",
":",
"DDD",
",",
"'AMA'",
":",
"AMA",
"}",
")"
] |
平均线差 DMA
|
[
"平均线差",
"DMA"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/indicators.py#L136-L145
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/indicators.py
|
QA_indicator_MTM
|
def QA_indicator_MTM(DataFrame, N=12, M=6):
'动量线'
C = DataFrame.close
mtm = C - REF(C, N)
MTMMA = MA(mtm, M)
DICT = {'MTM': mtm, 'MTMMA': MTMMA}
return pd.DataFrame(DICT)
|
python
|
def QA_indicator_MTM(DataFrame, N=12, M=6):
'动量线'
C = DataFrame.close
mtm = C - REF(C, N)
MTMMA = MA(mtm, M)
DICT = {'MTM': mtm, 'MTMMA': MTMMA}
return pd.DataFrame(DICT)
|
[
"def",
"QA_indicator_MTM",
"(",
"DataFrame",
",",
"N",
"=",
"12",
",",
"M",
"=",
"6",
")",
":",
"C",
"=",
"DataFrame",
".",
"close",
"mtm",
"=",
"C",
"-",
"REF",
"(",
"C",
",",
"N",
")",
"MTMMA",
"=",
"MA",
"(",
"mtm",
",",
"M",
")",
"DICT",
"=",
"{",
"'MTM'",
":",
"mtm",
",",
"'MTMMA'",
":",
"MTMMA",
"}",
"return",
"pd",
".",
"DataFrame",
"(",
"DICT",
")"
] |
动量线
|
[
"动量线"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/indicators.py#L148-L155
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/indicators.py
|
QA_indicator_EXPMA
|
def QA_indicator_EXPMA(DataFrame, P1=5, P2=10, P3=20, P4=60):
""" 指数平均线 EXPMA"""
CLOSE = DataFrame.close
MA1 = EMA(CLOSE, P1)
MA2 = EMA(CLOSE, P2)
MA3 = EMA(CLOSE, P3)
MA4 = EMA(CLOSE, P4)
return pd.DataFrame({
'MA1': MA1, 'MA2': MA2, 'MA3': MA3, 'MA4': MA4
})
|
python
|
def QA_indicator_EXPMA(DataFrame, P1=5, P2=10, P3=20, P4=60):
""" 指数平均线 EXPMA"""
CLOSE = DataFrame.close
MA1 = EMA(CLOSE, P1)
MA2 = EMA(CLOSE, P2)
MA3 = EMA(CLOSE, P3)
MA4 = EMA(CLOSE, P4)
return pd.DataFrame({
'MA1': MA1, 'MA2': MA2, 'MA3': MA3, 'MA4': MA4
})
|
[
"def",
"QA_indicator_EXPMA",
"(",
"DataFrame",
",",
"P1",
"=",
"5",
",",
"P2",
"=",
"10",
",",
"P3",
"=",
"20",
",",
"P4",
"=",
"60",
")",
":",
"CLOSE",
"=",
"DataFrame",
".",
"close",
"MA1",
"=",
"EMA",
"(",
"CLOSE",
",",
"P1",
")",
"MA2",
"=",
"EMA",
"(",
"CLOSE",
",",
"P2",
")",
"MA3",
"=",
"EMA",
"(",
"CLOSE",
",",
"P3",
")",
"MA4",
"=",
"EMA",
"(",
"CLOSE",
",",
"P4",
")",
"return",
"pd",
".",
"DataFrame",
"(",
"{",
"'MA1'",
":",
"MA1",
",",
"'MA2'",
":",
"MA2",
",",
"'MA3'",
":",
"MA3",
",",
"'MA4'",
":",
"MA4",
"}",
")"
] |
指数平均线 EXPMA
|
[
"指数平均线",
"EXPMA"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/indicators.py#L158-L167
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/indicators.py
|
QA_indicator_CHO
|
def QA_indicator_CHO(DataFrame, N1=10, N2=20, M=6):
"""
佳庆指标 CHO
"""
HIGH = DataFrame.high
LOW = DataFrame.low
CLOSE = DataFrame.close
VOL = DataFrame.volume
MID = SUM(VOL*(2*CLOSE-HIGH-LOW)/(HIGH+LOW), 0)
CHO = MA(MID, N1)-MA(MID, N2)
MACHO = MA(CHO, M)
return pd.DataFrame({
'CHO': CHO, 'MACHO': MACHO
})
|
python
|
def QA_indicator_CHO(DataFrame, N1=10, N2=20, M=6):
"""
佳庆指标 CHO
"""
HIGH = DataFrame.high
LOW = DataFrame.low
CLOSE = DataFrame.close
VOL = DataFrame.volume
MID = SUM(VOL*(2*CLOSE-HIGH-LOW)/(HIGH+LOW), 0)
CHO = MA(MID, N1)-MA(MID, N2)
MACHO = MA(CHO, M)
return pd.DataFrame({
'CHO': CHO, 'MACHO': MACHO
})
|
[
"def",
"QA_indicator_CHO",
"(",
"DataFrame",
",",
"N1",
"=",
"10",
",",
"N2",
"=",
"20",
",",
"M",
"=",
"6",
")",
":",
"HIGH",
"=",
"DataFrame",
".",
"high",
"LOW",
"=",
"DataFrame",
".",
"low",
"CLOSE",
"=",
"DataFrame",
".",
"close",
"VOL",
"=",
"DataFrame",
".",
"volume",
"MID",
"=",
"SUM",
"(",
"VOL",
"*",
"(",
"2",
"*",
"CLOSE",
"-",
"HIGH",
"-",
"LOW",
")",
"/",
"(",
"HIGH",
"+",
"LOW",
")",
",",
"0",
")",
"CHO",
"=",
"MA",
"(",
"MID",
",",
"N1",
")",
"-",
"MA",
"(",
"MID",
",",
"N2",
")",
"MACHO",
"=",
"MA",
"(",
"CHO",
",",
"M",
")",
"return",
"pd",
".",
"DataFrame",
"(",
"{",
"'CHO'",
":",
"CHO",
",",
"'MACHO'",
":",
"MACHO",
"}",
")"
] |
佳庆指标 CHO
|
[
"佳庆指标",
"CHO"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/indicators.py#L170-L183
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/indicators.py
|
QA_indicator_BIAS
|
def QA_indicator_BIAS(DataFrame, N1, N2, N3):
'乖离率'
CLOSE = DataFrame['close']
BIAS1 = (CLOSE - MA(CLOSE, N1)) / MA(CLOSE, N1) * 100
BIAS2 = (CLOSE - MA(CLOSE, N2)) / MA(CLOSE, N2) * 100
BIAS3 = (CLOSE - MA(CLOSE, N3)) / MA(CLOSE, N3) * 100
DICT = {'BIAS1': BIAS1, 'BIAS2': BIAS2, 'BIAS3': BIAS3}
return pd.DataFrame(DICT)
|
python
|
def QA_indicator_BIAS(DataFrame, N1, N2, N3):
'乖离率'
CLOSE = DataFrame['close']
BIAS1 = (CLOSE - MA(CLOSE, N1)) / MA(CLOSE, N1) * 100
BIAS2 = (CLOSE - MA(CLOSE, N2)) / MA(CLOSE, N2) * 100
BIAS3 = (CLOSE - MA(CLOSE, N3)) / MA(CLOSE, N3) * 100
DICT = {'BIAS1': BIAS1, 'BIAS2': BIAS2, 'BIAS3': BIAS3}
return pd.DataFrame(DICT)
|
[
"def",
"QA_indicator_BIAS",
"(",
"DataFrame",
",",
"N1",
",",
"N2",
",",
"N3",
")",
":",
"CLOSE",
"=",
"DataFrame",
"[",
"'close'",
"]",
"BIAS1",
"=",
"(",
"CLOSE",
"-",
"MA",
"(",
"CLOSE",
",",
"N1",
")",
")",
"/",
"MA",
"(",
"CLOSE",
",",
"N1",
")",
"*",
"100",
"BIAS2",
"=",
"(",
"CLOSE",
"-",
"MA",
"(",
"CLOSE",
",",
"N2",
")",
")",
"/",
"MA",
"(",
"CLOSE",
",",
"N2",
")",
"*",
"100",
"BIAS3",
"=",
"(",
"CLOSE",
"-",
"MA",
"(",
"CLOSE",
",",
"N3",
")",
")",
"/",
"MA",
"(",
"CLOSE",
",",
"N3",
")",
"*",
"100",
"DICT",
"=",
"{",
"'BIAS1'",
":",
"BIAS1",
",",
"'BIAS2'",
":",
"BIAS2",
",",
"'BIAS3'",
":",
"BIAS3",
"}",
"return",
"pd",
".",
"DataFrame",
"(",
"DICT",
")"
] |
乖离率
|
[
"乖离率"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/indicators.py#L216-L224
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/indicators.py
|
QA_indicator_ROC
|
def QA_indicator_ROC(DataFrame, N=12, M=6):
'变动率指标'
C = DataFrame['close']
roc = 100 * (C - REF(C, N)) / REF(C, N)
ROCMA = MA(roc, M)
DICT = {'ROC': roc, 'ROCMA': ROCMA}
return pd.DataFrame(DICT)
|
python
|
def QA_indicator_ROC(DataFrame, N=12, M=6):
'变动率指标'
C = DataFrame['close']
roc = 100 * (C - REF(C, N)) / REF(C, N)
ROCMA = MA(roc, M)
DICT = {'ROC': roc, 'ROCMA': ROCMA}
return pd.DataFrame(DICT)
|
[
"def",
"QA_indicator_ROC",
"(",
"DataFrame",
",",
"N",
"=",
"12",
",",
"M",
"=",
"6",
")",
":",
"C",
"=",
"DataFrame",
"[",
"'close'",
"]",
"roc",
"=",
"100",
"*",
"(",
"C",
"-",
"REF",
"(",
"C",
",",
"N",
")",
")",
"/",
"REF",
"(",
"C",
",",
"N",
")",
"ROCMA",
"=",
"MA",
"(",
"roc",
",",
"M",
")",
"DICT",
"=",
"{",
"'ROC'",
":",
"roc",
",",
"'ROCMA'",
":",
"ROCMA",
"}",
"return",
"pd",
".",
"DataFrame",
"(",
"DICT",
")"
] |
变动率指标
|
[
"变动率指标"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/indicators.py#L227-L234
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/indicators.py
|
QA_indicator_CCI
|
def QA_indicator_CCI(DataFrame, N=14):
"""
TYP:=(HIGH+LOW+CLOSE)/3;
CCI:(TYP-MA(TYP,N))/(0.015*AVEDEV(TYP,N));
"""
typ = (DataFrame['high'] + DataFrame['low'] + DataFrame['close']) / 3
cci = ((typ - MA(typ, N)) / (0.015 * AVEDEV(typ, N)))
a = 100
b = -100
return pd.DataFrame({
'CCI': cci, 'a': a, 'b': b
})
|
python
|
def QA_indicator_CCI(DataFrame, N=14):
"""
TYP:=(HIGH+LOW+CLOSE)/3;
CCI:(TYP-MA(TYP,N))/(0.015*AVEDEV(TYP,N));
"""
typ = (DataFrame['high'] + DataFrame['low'] + DataFrame['close']) / 3
cci = ((typ - MA(typ, N)) / (0.015 * AVEDEV(typ, N)))
a = 100
b = -100
return pd.DataFrame({
'CCI': cci, 'a': a, 'b': b
})
|
[
"def",
"QA_indicator_CCI",
"(",
"DataFrame",
",",
"N",
"=",
"14",
")",
":",
"typ",
"=",
"(",
"DataFrame",
"[",
"'high'",
"]",
"+",
"DataFrame",
"[",
"'low'",
"]",
"+",
"DataFrame",
"[",
"'close'",
"]",
")",
"/",
"3",
"cci",
"=",
"(",
"(",
"typ",
"-",
"MA",
"(",
"typ",
",",
"N",
")",
")",
"/",
"(",
"0.015",
"*",
"AVEDEV",
"(",
"typ",
",",
"N",
")",
")",
")",
"a",
"=",
"100",
"b",
"=",
"-",
"100",
"return",
"pd",
".",
"DataFrame",
"(",
"{",
"'CCI'",
":",
"cci",
",",
"'a'",
":",
"a",
",",
"'b'",
":",
"b",
"}",
")"
] |
TYP:=(HIGH+LOW+CLOSE)/3;
CCI:(TYP-MA(TYP,N))/(0.015*AVEDEV(TYP,N));
|
[
"TYP",
":",
"=",
"(",
"HIGH",
"+",
"LOW",
"+",
"CLOSE",
")",
"/",
"3",
";",
"CCI",
":",
"(",
"TYP",
"-",
"MA",
"(",
"TYP",
"N",
"))",
"/",
"(",
"0",
".",
"015",
"*",
"AVEDEV",
"(",
"TYP",
"N",
"))",
";"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/indicators.py#L237-L249
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/indicators.py
|
QA_indicator_WR
|
def QA_indicator_WR(DataFrame, N, N1):
'威廉指标'
HIGH = DataFrame['high']
LOW = DataFrame['low']
CLOSE = DataFrame['close']
WR1 = 100 * (HHV(HIGH, N) - CLOSE) / (HHV(HIGH, N) - LLV(LOW, N))
WR2 = 100 * (HHV(HIGH, N1) - CLOSE) / (HHV(HIGH, N1) - LLV(LOW, N1))
DICT = {'WR1': WR1, 'WR2': WR2}
return pd.DataFrame(DICT)
|
python
|
def QA_indicator_WR(DataFrame, N, N1):
'威廉指标'
HIGH = DataFrame['high']
LOW = DataFrame['low']
CLOSE = DataFrame['close']
WR1 = 100 * (HHV(HIGH, N) - CLOSE) / (HHV(HIGH, N) - LLV(LOW, N))
WR2 = 100 * (HHV(HIGH, N1) - CLOSE) / (HHV(HIGH, N1) - LLV(LOW, N1))
DICT = {'WR1': WR1, 'WR2': WR2}
return pd.DataFrame(DICT)
|
[
"def",
"QA_indicator_WR",
"(",
"DataFrame",
",",
"N",
",",
"N1",
")",
":",
"HIGH",
"=",
"DataFrame",
"[",
"'high'",
"]",
"LOW",
"=",
"DataFrame",
"[",
"'low'",
"]",
"CLOSE",
"=",
"DataFrame",
"[",
"'close'",
"]",
"WR1",
"=",
"100",
"*",
"(",
"HHV",
"(",
"HIGH",
",",
"N",
")",
"-",
"CLOSE",
")",
"/",
"(",
"HHV",
"(",
"HIGH",
",",
"N",
")",
"-",
"LLV",
"(",
"LOW",
",",
"N",
")",
")",
"WR2",
"=",
"100",
"*",
"(",
"HHV",
"(",
"HIGH",
",",
"N1",
")",
"-",
"CLOSE",
")",
"/",
"(",
"HHV",
"(",
"HIGH",
",",
"N1",
")",
"-",
"LLV",
"(",
"LOW",
",",
"N1",
")",
")",
"DICT",
"=",
"{",
"'WR1'",
":",
"WR1",
",",
"'WR2'",
":",
"WR2",
"}",
"return",
"pd",
".",
"DataFrame",
"(",
"DICT",
")"
] |
威廉指标
|
[
"威廉指标"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/indicators.py#L252-L261
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/indicators.py
|
QA_indicator_OSC
|
def QA_indicator_OSC(DataFrame, N=20, M=6):
"""变动速率线
震荡量指标OSC,也叫变动速率线。属于超买超卖类指标,是从移动平均线原理派生出来的一种分析指标。
它反应当日收盘价与一段时间内平均收盘价的差离值,从而测出股价的震荡幅度。
按照移动平均线原理,根据OSC的值可推断价格的趋势,如果远离平均线,就很可能向平均线回归。
"""
C = DataFrame['close']
OS = (C - MA(C, N)) * 100
MAOSC = EMA(OS, M)
DICT = {'OSC': OS, 'MAOSC': MAOSC}
return pd.DataFrame(DICT)
|
python
|
def QA_indicator_OSC(DataFrame, N=20, M=6):
"""变动速率线
震荡量指标OSC,也叫变动速率线。属于超买超卖类指标,是从移动平均线原理派生出来的一种分析指标。
它反应当日收盘价与一段时间内平均收盘价的差离值,从而测出股价的震荡幅度。
按照移动平均线原理,根据OSC的值可推断价格的趋势,如果远离平均线,就很可能向平均线回归。
"""
C = DataFrame['close']
OS = (C - MA(C, N)) * 100
MAOSC = EMA(OS, M)
DICT = {'OSC': OS, 'MAOSC': MAOSC}
return pd.DataFrame(DICT)
|
[
"def",
"QA_indicator_OSC",
"(",
"DataFrame",
",",
"N",
"=",
"20",
",",
"M",
"=",
"6",
")",
":",
"C",
"=",
"DataFrame",
"[",
"'close'",
"]",
"OS",
"=",
"(",
"C",
"-",
"MA",
"(",
"C",
",",
"N",
")",
")",
"*",
"100",
"MAOSC",
"=",
"EMA",
"(",
"OS",
",",
"M",
")",
"DICT",
"=",
"{",
"'OSC'",
":",
"OS",
",",
"'MAOSC'",
":",
"MAOSC",
"}",
"return",
"pd",
".",
"DataFrame",
"(",
"DICT",
")"
] |
变动速率线
震荡量指标OSC,也叫变动速率线。属于超买超卖类指标,是从移动平均线原理派生出来的一种分析指标。
它反应当日收盘价与一段时间内平均收盘价的差离值,从而测出股价的震荡幅度。
按照移动平均线原理,根据OSC的值可推断价格的趋势,如果远离平均线,就很可能向平均线回归。
|
[
"变动速率线"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/indicators.py#L264-L278
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/indicators.py
|
QA_indicator_RSI
|
def QA_indicator_RSI(DataFrame, N1=12, N2=26, N3=9):
'相对强弱指标RSI1:SMA(MAX(CLOSE-LC,0),N1,1)/SMA(ABS(CLOSE-LC),N1,1)*100;'
CLOSE = DataFrame['close']
LC = REF(CLOSE, 1)
RSI1 = SMA(MAX(CLOSE - LC, 0), N1) / SMA(ABS(CLOSE - LC), N1) * 100
RSI2 = SMA(MAX(CLOSE - LC, 0), N2) / SMA(ABS(CLOSE - LC), N2) * 100
RSI3 = SMA(MAX(CLOSE - LC, 0), N3) / SMA(ABS(CLOSE - LC), N3) * 100
DICT = {'RSI1': RSI1, 'RSI2': RSI2, 'RSI3': RSI3}
return pd.DataFrame(DICT)
|
python
|
def QA_indicator_RSI(DataFrame, N1=12, N2=26, N3=9):
'相对强弱指标RSI1:SMA(MAX(CLOSE-LC,0),N1,1)/SMA(ABS(CLOSE-LC),N1,1)*100;'
CLOSE = DataFrame['close']
LC = REF(CLOSE, 1)
RSI1 = SMA(MAX(CLOSE - LC, 0), N1) / SMA(ABS(CLOSE - LC), N1) * 100
RSI2 = SMA(MAX(CLOSE - LC, 0), N2) / SMA(ABS(CLOSE - LC), N2) * 100
RSI3 = SMA(MAX(CLOSE - LC, 0), N3) / SMA(ABS(CLOSE - LC), N3) * 100
DICT = {'RSI1': RSI1, 'RSI2': RSI2, 'RSI3': RSI3}
return pd.DataFrame(DICT)
|
[
"def",
"QA_indicator_RSI",
"(",
"DataFrame",
",",
"N1",
"=",
"12",
",",
"N2",
"=",
"26",
",",
"N3",
"=",
"9",
")",
":",
"CLOSE",
"=",
"DataFrame",
"[",
"'close'",
"]",
"LC",
"=",
"REF",
"(",
"CLOSE",
",",
"1",
")",
"RSI1",
"=",
"SMA",
"(",
"MAX",
"(",
"CLOSE",
"-",
"LC",
",",
"0",
")",
",",
"N1",
")",
"/",
"SMA",
"(",
"ABS",
"(",
"CLOSE",
"-",
"LC",
")",
",",
"N1",
")",
"*",
"100",
"RSI2",
"=",
"SMA",
"(",
"MAX",
"(",
"CLOSE",
"-",
"LC",
",",
"0",
")",
",",
"N2",
")",
"/",
"SMA",
"(",
"ABS",
"(",
"CLOSE",
"-",
"LC",
")",
",",
"N2",
")",
"*",
"100",
"RSI3",
"=",
"SMA",
"(",
"MAX",
"(",
"CLOSE",
"-",
"LC",
",",
"0",
")",
",",
"N3",
")",
"/",
"SMA",
"(",
"ABS",
"(",
"CLOSE",
"-",
"LC",
")",
",",
"N3",
")",
"*",
"100",
"DICT",
"=",
"{",
"'RSI1'",
":",
"RSI1",
",",
"'RSI2'",
":",
"RSI2",
",",
"'RSI3'",
":",
"RSI3",
"}",
"return",
"pd",
".",
"DataFrame",
"(",
"DICT",
")"
] |
相对强弱指标RSI1:SMA(MAX(CLOSE-LC,0),N1,1)/SMA(ABS(CLOSE-LC),N1,1)*100;
|
[
"相对强弱指标RSI1",
":",
"SMA",
"(",
"MAX",
"(",
"CLOSE",
"-",
"LC",
"0",
")",
"N1",
"1",
")",
"/",
"SMA",
"(",
"ABS",
"(",
"CLOSE",
"-",
"LC",
")",
"N1",
"1",
")",
"*",
"100",
";"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/indicators.py#L281-L290
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/indicators.py
|
QA_indicator_ADTM
|
def QA_indicator_ADTM(DataFrame, N=23, M=8):
'动态买卖气指标'
HIGH = DataFrame.high
LOW = DataFrame.low
OPEN = DataFrame.open
DTM = IF(OPEN > REF(OPEN, 1), MAX((HIGH - OPEN), (OPEN - REF(OPEN, 1))), 0)
DBM = IF(OPEN < REF(OPEN, 1), MAX((OPEN - LOW), (OPEN - REF(OPEN, 1))), 0)
STM = SUM(DTM, N)
SBM = SUM(DBM, N)
ADTM1 = IF(STM > SBM, (STM - SBM) / STM,
IF(STM != SBM, (STM - SBM) / SBM, 0))
MAADTM = MA(ADTM1, M)
DICT = {'ADTM': ADTM1, 'MAADTM': MAADTM}
return pd.DataFrame(DICT)
|
python
|
def QA_indicator_ADTM(DataFrame, N=23, M=8):
'动态买卖气指标'
HIGH = DataFrame.high
LOW = DataFrame.low
OPEN = DataFrame.open
DTM = IF(OPEN > REF(OPEN, 1), MAX((HIGH - OPEN), (OPEN - REF(OPEN, 1))), 0)
DBM = IF(OPEN < REF(OPEN, 1), MAX((OPEN - LOW), (OPEN - REF(OPEN, 1))), 0)
STM = SUM(DTM, N)
SBM = SUM(DBM, N)
ADTM1 = IF(STM > SBM, (STM - SBM) / STM,
IF(STM != SBM, (STM - SBM) / SBM, 0))
MAADTM = MA(ADTM1, M)
DICT = {'ADTM': ADTM1, 'MAADTM': MAADTM}
return pd.DataFrame(DICT)
|
[
"def",
"QA_indicator_ADTM",
"(",
"DataFrame",
",",
"N",
"=",
"23",
",",
"M",
"=",
"8",
")",
":",
"HIGH",
"=",
"DataFrame",
".",
"high",
"LOW",
"=",
"DataFrame",
".",
"low",
"OPEN",
"=",
"DataFrame",
".",
"open",
"DTM",
"=",
"IF",
"(",
"OPEN",
">",
"REF",
"(",
"OPEN",
",",
"1",
")",
",",
"MAX",
"(",
"(",
"HIGH",
"-",
"OPEN",
")",
",",
"(",
"OPEN",
"-",
"REF",
"(",
"OPEN",
",",
"1",
")",
")",
")",
",",
"0",
")",
"DBM",
"=",
"IF",
"(",
"OPEN",
"<",
"REF",
"(",
"OPEN",
",",
"1",
")",
",",
"MAX",
"(",
"(",
"OPEN",
"-",
"LOW",
")",
",",
"(",
"OPEN",
"-",
"REF",
"(",
"OPEN",
",",
"1",
")",
")",
")",
",",
"0",
")",
"STM",
"=",
"SUM",
"(",
"DTM",
",",
"N",
")",
"SBM",
"=",
"SUM",
"(",
"DBM",
",",
"N",
")",
"ADTM1",
"=",
"IF",
"(",
"STM",
">",
"SBM",
",",
"(",
"STM",
"-",
"SBM",
")",
"/",
"STM",
",",
"IF",
"(",
"STM",
"!=",
"SBM",
",",
"(",
"STM",
"-",
"SBM",
")",
"/",
"SBM",
",",
"0",
")",
")",
"MAADTM",
"=",
"MA",
"(",
"ADTM1",
",",
"M",
")",
"DICT",
"=",
"{",
"'ADTM'",
":",
"ADTM1",
",",
"'MAADTM'",
":",
"MAADTM",
"}",
"return",
"pd",
".",
"DataFrame",
"(",
"DICT",
")"
] |
动态买卖气指标
|
[
"动态买卖气指标"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/indicators.py#L293-L307
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/indicators.py
|
QA_indicator_ASI
|
def QA_indicator_ASI(DataFrame, M1=26, M2=10):
"""
LC=REF(CLOSE,1);
AA=ABS(HIGH-LC);
BB=ABS(LOW-LC);
CC=ABS(HIGH-REF(LOW,1));
DD=ABS(LC-REF(OPEN,1));
R=IF(AA>BB AND AA>CC,AA+BB/2+DD/4,IF(BB>CC AND BB>AA,BB+AA/2+DD/4,CC+DD/4));
X=(CLOSE-LC+(CLOSE-OPEN)/2+LC-REF(OPEN,1));
SI=16*X/R*MAX(AA,BB);
ASI:SUM(SI,M1);
ASIT:MA(ASI,M2);
"""
CLOSE = DataFrame['close']
HIGH = DataFrame['high']
LOW = DataFrame['low']
OPEN = DataFrame['open']
LC = REF(CLOSE, 1)
AA = ABS(HIGH - LC)
BB = ABS(LOW-LC)
CC = ABS(HIGH - REF(LOW, 1))
DD = ABS(LC - REF(OPEN, 1))
R = IFAND(AA > BB, AA > CC, AA+BB/2+DD/4,
IFAND(BB > CC, BB > AA, BB+AA/2+DD/4, CC+DD/4))
X = (CLOSE - LC + (CLOSE - OPEN) / 2 + LC - REF(OPEN, 1))
SI = 16*X/R*MAX(AA, BB)
ASI = SUM(SI, M1)
ASIT = MA(ASI, M2)
return pd.DataFrame({
'ASI': ASI, 'ASIT': ASIT
})
|
python
|
def QA_indicator_ASI(DataFrame, M1=26, M2=10):
"""
LC=REF(CLOSE,1);
AA=ABS(HIGH-LC);
BB=ABS(LOW-LC);
CC=ABS(HIGH-REF(LOW,1));
DD=ABS(LC-REF(OPEN,1));
R=IF(AA>BB AND AA>CC,AA+BB/2+DD/4,IF(BB>CC AND BB>AA,BB+AA/2+DD/4,CC+DD/4));
X=(CLOSE-LC+(CLOSE-OPEN)/2+LC-REF(OPEN,1));
SI=16*X/R*MAX(AA,BB);
ASI:SUM(SI,M1);
ASIT:MA(ASI,M2);
"""
CLOSE = DataFrame['close']
HIGH = DataFrame['high']
LOW = DataFrame['low']
OPEN = DataFrame['open']
LC = REF(CLOSE, 1)
AA = ABS(HIGH - LC)
BB = ABS(LOW-LC)
CC = ABS(HIGH - REF(LOW, 1))
DD = ABS(LC - REF(OPEN, 1))
R = IFAND(AA > BB, AA > CC, AA+BB/2+DD/4,
IFAND(BB > CC, BB > AA, BB+AA/2+DD/4, CC+DD/4))
X = (CLOSE - LC + (CLOSE - OPEN) / 2 + LC - REF(OPEN, 1))
SI = 16*X/R*MAX(AA, BB)
ASI = SUM(SI, M1)
ASIT = MA(ASI, M2)
return pd.DataFrame({
'ASI': ASI, 'ASIT': ASIT
})
|
[
"def",
"QA_indicator_ASI",
"(",
"DataFrame",
",",
"M1",
"=",
"26",
",",
"M2",
"=",
"10",
")",
":",
"CLOSE",
"=",
"DataFrame",
"[",
"'close'",
"]",
"HIGH",
"=",
"DataFrame",
"[",
"'high'",
"]",
"LOW",
"=",
"DataFrame",
"[",
"'low'",
"]",
"OPEN",
"=",
"DataFrame",
"[",
"'open'",
"]",
"LC",
"=",
"REF",
"(",
"CLOSE",
",",
"1",
")",
"AA",
"=",
"ABS",
"(",
"HIGH",
"-",
"LC",
")",
"BB",
"=",
"ABS",
"(",
"LOW",
"-",
"LC",
")",
"CC",
"=",
"ABS",
"(",
"HIGH",
"-",
"REF",
"(",
"LOW",
",",
"1",
")",
")",
"DD",
"=",
"ABS",
"(",
"LC",
"-",
"REF",
"(",
"OPEN",
",",
"1",
")",
")",
"R",
"=",
"IFAND",
"(",
"AA",
">",
"BB",
",",
"AA",
">",
"CC",
",",
"AA",
"+",
"BB",
"/",
"2",
"+",
"DD",
"/",
"4",
",",
"IFAND",
"(",
"BB",
">",
"CC",
",",
"BB",
">",
"AA",
",",
"BB",
"+",
"AA",
"/",
"2",
"+",
"DD",
"/",
"4",
",",
"CC",
"+",
"DD",
"/",
"4",
")",
")",
"X",
"=",
"(",
"CLOSE",
"-",
"LC",
"+",
"(",
"CLOSE",
"-",
"OPEN",
")",
"/",
"2",
"+",
"LC",
"-",
"REF",
"(",
"OPEN",
",",
"1",
")",
")",
"SI",
"=",
"16",
"*",
"X",
"/",
"R",
"*",
"MAX",
"(",
"AA",
",",
"BB",
")",
"ASI",
"=",
"SUM",
"(",
"SI",
",",
"M1",
")",
"ASIT",
"=",
"MA",
"(",
"ASI",
",",
"M2",
")",
"return",
"pd",
".",
"DataFrame",
"(",
"{",
"'ASI'",
":",
"ASI",
",",
"'ASIT'",
":",
"ASIT",
"}",
")"
] |
LC=REF(CLOSE,1);
AA=ABS(HIGH-LC);
BB=ABS(LOW-LC);
CC=ABS(HIGH-REF(LOW,1));
DD=ABS(LC-REF(OPEN,1));
R=IF(AA>BB AND AA>CC,AA+BB/2+DD/4,IF(BB>CC AND BB>AA,BB+AA/2+DD/4,CC+DD/4));
X=(CLOSE-LC+(CLOSE-OPEN)/2+LC-REF(OPEN,1));
SI=16*X/R*MAX(AA,BB);
ASI:SUM(SI,M1);
ASIT:MA(ASI,M2);
|
[
"LC",
"=",
"REF",
"(",
"CLOSE",
"1",
")",
";",
"AA",
"=",
"ABS",
"(",
"HIGH",
"-",
"LC",
")",
";",
"BB",
"=",
"ABS",
"(",
"LOW",
"-",
"LC",
")",
";",
"CC",
"=",
"ABS",
"(",
"HIGH",
"-",
"REF",
"(",
"LOW",
"1",
"))",
";",
"DD",
"=",
"ABS",
"(",
"LC",
"-",
"REF",
"(",
"OPEN",
"1",
"))",
";",
"R",
"=",
"IF",
"(",
"AA",
">",
"BB",
"AND",
"AA",
">",
"CC",
"AA",
"+",
"BB",
"/",
"2",
"+",
"DD",
"/",
"4",
"IF",
"(",
"BB",
">",
"CC",
"AND",
"BB",
">",
"AA",
"BB",
"+",
"AA",
"/",
"2",
"+",
"DD",
"/",
"4",
"CC",
"+",
"DD",
"/",
"4",
"))",
";",
"X",
"=",
"(",
"CLOSE",
"-",
"LC",
"+",
"(",
"CLOSE",
"-",
"OPEN",
")",
"/",
"2",
"+",
"LC",
"-",
"REF",
"(",
"OPEN",
"1",
"))",
";",
"SI",
"=",
"16",
"*",
"X",
"/",
"R",
"*",
"MAX",
"(",
"AA",
"BB",
")",
";",
"ASI",
":",
"SUM",
"(",
"SI",
"M1",
")",
";",
"ASIT",
":",
"MA",
"(",
"ASI",
"M2",
")",
";"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/indicators.py#L388-L419
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/indicators.py
|
QA_indicator_OBV
|
def QA_indicator_OBV(DataFrame):
"""能量潮"""
VOL = DataFrame.volume
CLOSE = DataFrame.close
return pd.DataFrame({
'OBV': np.cumsum(IF(CLOSE > REF(CLOSE, 1), VOL, IF(CLOSE < REF(CLOSE, 1), -VOL, 0)))/10000
})
|
python
|
def QA_indicator_OBV(DataFrame):
"""能量潮"""
VOL = DataFrame.volume
CLOSE = DataFrame.close
return pd.DataFrame({
'OBV': np.cumsum(IF(CLOSE > REF(CLOSE, 1), VOL, IF(CLOSE < REF(CLOSE, 1), -VOL, 0)))/10000
})
|
[
"def",
"QA_indicator_OBV",
"(",
"DataFrame",
")",
":",
"VOL",
"=",
"DataFrame",
".",
"volume",
"CLOSE",
"=",
"DataFrame",
".",
"close",
"return",
"pd",
".",
"DataFrame",
"(",
"{",
"'OBV'",
":",
"np",
".",
"cumsum",
"(",
"IF",
"(",
"CLOSE",
">",
"REF",
"(",
"CLOSE",
",",
"1",
")",
",",
"VOL",
",",
"IF",
"(",
"CLOSE",
"<",
"REF",
"(",
"CLOSE",
",",
"1",
")",
",",
"-",
"VOL",
",",
"0",
")",
")",
")",
"/",
"10000",
"}",
")"
] |
能量潮
|
[
"能量潮"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/indicators.py#L429-L435
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/indicators.py
|
QA_indicator_BOLL
|
def QA_indicator_BOLL(DataFrame, N=20, P=2):
'布林线'
C = DataFrame['close']
boll = MA(C, N)
UB = boll + P * STD(C, N)
LB = boll - P * STD(C, N)
DICT = {'BOLL': boll, 'UB': UB, 'LB': LB}
return pd.DataFrame(DICT)
|
python
|
def QA_indicator_BOLL(DataFrame, N=20, P=2):
'布林线'
C = DataFrame['close']
boll = MA(C, N)
UB = boll + P * STD(C, N)
LB = boll - P * STD(C, N)
DICT = {'BOLL': boll, 'UB': UB, 'LB': LB}
return pd.DataFrame(DICT)
|
[
"def",
"QA_indicator_BOLL",
"(",
"DataFrame",
",",
"N",
"=",
"20",
",",
"P",
"=",
"2",
")",
":",
"C",
"=",
"DataFrame",
"[",
"'close'",
"]",
"boll",
"=",
"MA",
"(",
"C",
",",
"N",
")",
"UB",
"=",
"boll",
"+",
"P",
"*",
"STD",
"(",
"C",
",",
"N",
")",
"LB",
"=",
"boll",
"-",
"P",
"*",
"STD",
"(",
"C",
",",
"N",
")",
"DICT",
"=",
"{",
"'BOLL'",
":",
"boll",
",",
"'UB'",
":",
"UB",
",",
"'LB'",
":",
"LB",
"}",
"return",
"pd",
".",
"DataFrame",
"(",
"DICT",
")"
] |
布林线
|
[
"布林线"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/indicators.py#L456-L464
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/indicators.py
|
QA_indicator_MIKE
|
def QA_indicator_MIKE(DataFrame, N=12):
"""
MIKE指标
指标说明
MIKE是另外一种形式的路径指标。
买卖原则
1 WEAK-S,MEDIUM-S,STRONG-S三条线代表初级、中级、强力支撑。
2 WEAK-R,MEDIUM-R,STRONG-R三条线代表初级、中级、强力压力。
"""
HIGH = DataFrame.high
LOW = DataFrame.low
CLOSE = DataFrame.close
TYP = (HIGH+LOW+CLOSE)/3
LL = LLV(LOW, N)
HH = HHV(HIGH, N)
WR = TYP+(TYP-LL)
MR = TYP+(HH-LL)
SR = 2*HH-LL
WS = TYP-(HH-TYP)
MS = TYP-(HH-LL)
SS = 2*LL-HH
return pd.DataFrame({
'WR': WR, 'MR': MR, 'SR': SR,
'WS': WS, 'MS': MS, 'SS': SS
})
|
python
|
def QA_indicator_MIKE(DataFrame, N=12):
"""
MIKE指标
指标说明
MIKE是另外一种形式的路径指标。
买卖原则
1 WEAK-S,MEDIUM-S,STRONG-S三条线代表初级、中级、强力支撑。
2 WEAK-R,MEDIUM-R,STRONG-R三条线代表初级、中级、强力压力。
"""
HIGH = DataFrame.high
LOW = DataFrame.low
CLOSE = DataFrame.close
TYP = (HIGH+LOW+CLOSE)/3
LL = LLV(LOW, N)
HH = HHV(HIGH, N)
WR = TYP+(TYP-LL)
MR = TYP+(HH-LL)
SR = 2*HH-LL
WS = TYP-(HH-TYP)
MS = TYP-(HH-LL)
SS = 2*LL-HH
return pd.DataFrame({
'WR': WR, 'MR': MR, 'SR': SR,
'WS': WS, 'MS': MS, 'SS': SS
})
|
[
"def",
"QA_indicator_MIKE",
"(",
"DataFrame",
",",
"N",
"=",
"12",
")",
":",
"HIGH",
"=",
"DataFrame",
".",
"high",
"LOW",
"=",
"DataFrame",
".",
"low",
"CLOSE",
"=",
"DataFrame",
".",
"close",
"TYP",
"=",
"(",
"HIGH",
"+",
"LOW",
"+",
"CLOSE",
")",
"/",
"3",
"LL",
"=",
"LLV",
"(",
"LOW",
",",
"N",
")",
"HH",
"=",
"HHV",
"(",
"HIGH",
",",
"N",
")",
"WR",
"=",
"TYP",
"+",
"(",
"TYP",
"-",
"LL",
")",
"MR",
"=",
"TYP",
"+",
"(",
"HH",
"-",
"LL",
")",
"SR",
"=",
"2",
"*",
"HH",
"-",
"LL",
"WS",
"=",
"TYP",
"-",
"(",
"HH",
"-",
"TYP",
")",
"MS",
"=",
"TYP",
"-",
"(",
"HH",
"-",
"LL",
")",
"SS",
"=",
"2",
"*",
"LL",
"-",
"HH",
"return",
"pd",
".",
"DataFrame",
"(",
"{",
"'WR'",
":",
"WR",
",",
"'MR'",
":",
"MR",
",",
"'SR'",
":",
"SR",
",",
"'WS'",
":",
"WS",
",",
"'MS'",
":",
"MS",
",",
"'SS'",
":",
"SS",
"}",
")"
] |
MIKE指标
指标说明
MIKE是另外一种形式的路径指标。
买卖原则
1 WEAK-S,MEDIUM-S,STRONG-S三条线代表初级、中级、强力支撑。
2 WEAK-R,MEDIUM-R,STRONG-R三条线代表初级、中级、强力压力。
|
[
"MIKE指标",
"指标说明",
"MIKE是另外一种形式的路径指标。",
"买卖原则",
"1",
"WEAK",
"-",
"S,MEDIUM",
"-",
"S,STRONG",
"-",
"S三条线代表初级、中级、强力支撑。",
"2",
"WEAK",
"-",
"R,MEDIUM",
"-",
"R,STRONG",
"-",
"R三条线代表初级、中级、强力压力。"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/indicators.py#L467-L493
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/indicators.py
|
QA_indicator_BBI
|
def QA_indicator_BBI(DataFrame, N1=3, N2=6, N3=12, N4=24):
'多空指标'
C = DataFrame['close']
bbi = (MA(C, N1) + MA(C, N2) + MA(C, N3) + MA(C, N4)) / 4
DICT = {'BBI': bbi}
return pd.DataFrame(DICT)
|
python
|
def QA_indicator_BBI(DataFrame, N1=3, N2=6, N3=12, N4=24):
'多空指标'
C = DataFrame['close']
bbi = (MA(C, N1) + MA(C, N2) + MA(C, N3) + MA(C, N4)) / 4
DICT = {'BBI': bbi}
return pd.DataFrame(DICT)
|
[
"def",
"QA_indicator_BBI",
"(",
"DataFrame",
",",
"N1",
"=",
"3",
",",
"N2",
"=",
"6",
",",
"N3",
"=",
"12",
",",
"N4",
"=",
"24",
")",
":",
"C",
"=",
"DataFrame",
"[",
"'close'",
"]",
"bbi",
"=",
"(",
"MA",
"(",
"C",
",",
"N1",
")",
"+",
"MA",
"(",
"C",
",",
"N2",
")",
"+",
"MA",
"(",
"C",
",",
"N3",
")",
"+",
"MA",
"(",
"C",
",",
"N4",
")",
")",
"/",
"4",
"DICT",
"=",
"{",
"'BBI'",
":",
"bbi",
"}",
"return",
"pd",
".",
"DataFrame",
"(",
"DICT",
")"
] |
多空指标
|
[
"多空指标"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/indicators.py#L496-L502
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/indicators.py
|
QA_indicator_MFI
|
def QA_indicator_MFI(DataFrame, N=14):
"""
资金指标
TYP := (HIGH + LOW + CLOSE)/3;
V1:=SUM(IF(TYP>REF(TYP,1),TYP*VOL,0),N)/SUM(IF(TYP<REF(TYP,1),TYP*VOL,0),N);
MFI:100-(100/(1+V1));
赋值: (最高价 + 最低价 + 收盘价)/3
V1赋值:如果TYP>1日前的TYP,返回TYP*成交量(手),否则返回0的N日累和/如果TYP<1日前的TYP,返回TYP*成交量(手),否则返回0的N日累和
输出资金流量指标:100-(100/(1+V1))
"""
C = DataFrame['close']
H = DataFrame['high']
L = DataFrame['low']
VOL = DataFrame['volume']
TYP = (C + H + L) / 3
V1 = SUM(IF(TYP > REF(TYP, 1), TYP * VOL, 0), N) / \
SUM(IF(TYP < REF(TYP, 1), TYP * VOL, 0), N)
mfi = 100 - (100 / (1 + V1))
DICT = {'MFI': mfi}
return pd.DataFrame(DICT)
|
python
|
def QA_indicator_MFI(DataFrame, N=14):
"""
资金指标
TYP := (HIGH + LOW + CLOSE)/3;
V1:=SUM(IF(TYP>REF(TYP,1),TYP*VOL,0),N)/SUM(IF(TYP<REF(TYP,1),TYP*VOL,0),N);
MFI:100-(100/(1+V1));
赋值: (最高价 + 最低价 + 收盘价)/3
V1赋值:如果TYP>1日前的TYP,返回TYP*成交量(手),否则返回0的N日累和/如果TYP<1日前的TYP,返回TYP*成交量(手),否则返回0的N日累和
输出资金流量指标:100-(100/(1+V1))
"""
C = DataFrame['close']
H = DataFrame['high']
L = DataFrame['low']
VOL = DataFrame['volume']
TYP = (C + H + L) / 3
V1 = SUM(IF(TYP > REF(TYP, 1), TYP * VOL, 0), N) / \
SUM(IF(TYP < REF(TYP, 1), TYP * VOL, 0), N)
mfi = 100 - (100 / (1 + V1))
DICT = {'MFI': mfi}
return pd.DataFrame(DICT)
|
[
"def",
"QA_indicator_MFI",
"(",
"DataFrame",
",",
"N",
"=",
"14",
")",
":",
"C",
"=",
"DataFrame",
"[",
"'close'",
"]",
"H",
"=",
"DataFrame",
"[",
"'high'",
"]",
"L",
"=",
"DataFrame",
"[",
"'low'",
"]",
"VOL",
"=",
"DataFrame",
"[",
"'volume'",
"]",
"TYP",
"=",
"(",
"C",
"+",
"H",
"+",
"L",
")",
"/",
"3",
"V1",
"=",
"SUM",
"(",
"IF",
"(",
"TYP",
">",
"REF",
"(",
"TYP",
",",
"1",
")",
",",
"TYP",
"*",
"VOL",
",",
"0",
")",
",",
"N",
")",
"/",
"SUM",
"(",
"IF",
"(",
"TYP",
"<",
"REF",
"(",
"TYP",
",",
"1",
")",
",",
"TYP",
"*",
"VOL",
",",
"0",
")",
",",
"N",
")",
"mfi",
"=",
"100",
"-",
"(",
"100",
"/",
"(",
"1",
"+",
"V1",
")",
")",
"DICT",
"=",
"{",
"'MFI'",
":",
"mfi",
"}",
"return",
"pd",
".",
"DataFrame",
"(",
"DICT",
")"
] |
资金指标
TYP := (HIGH + LOW + CLOSE)/3;
V1:=SUM(IF(TYP>REF(TYP,1),TYP*VOL,0),N)/SUM(IF(TYP<REF(TYP,1),TYP*VOL,0),N);
MFI:100-(100/(1+V1));
赋值: (最高价 + 最低价 + 收盘价)/3
V1赋值:如果TYP>1日前的TYP,返回TYP*成交量(手),否则返回0的N日累和/如果TYP<1日前的TYP,返回TYP*成交量(手),否则返回0的N日累和
输出资金流量指标:100-(100/(1+V1))
|
[
"资金指标",
"TYP",
":",
"=",
"(",
"HIGH",
"+",
"LOW",
"+",
"CLOSE",
")",
"/",
"3",
";",
"V1",
":",
"=",
"SUM",
"(",
"IF",
"(",
"TYP",
">",
"REF",
"(",
"TYP",
"1",
")",
"TYP",
"*",
"VOL",
"0",
")",
"N",
")",
"/",
"SUM",
"(",
"IF",
"(",
"TYP<REF",
"(",
"TYP",
"1",
")",
"TYP",
"*",
"VOL",
"0",
")",
"N",
")",
";",
"MFI",
":",
"100",
"-",
"(",
"100",
"/",
"(",
"1",
"+",
"V1",
"))",
";",
"赋值",
":",
"(",
"最高价",
"+",
"最低价",
"+",
"收盘价",
")",
"/",
"3",
"V1赋值",
":",
"如果TYP",
">",
"1日前的TYP",
"返回TYP",
"*",
"成交量",
"(",
"手",
")",
"否则返回0的N日累和",
"/",
"如果TYP<1日前的TYP",
"返回TYP",
"*",
"成交量",
"(",
"手",
")",
"否则返回0的N日累和",
"输出资金流量指标",
":",
"100",
"-",
"(",
"100",
"/",
"(",
"1",
"+",
"V1",
"))"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/indicators.py#L505-L525
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/indicators.py
|
QA_indicator_ATR
|
def QA_indicator_ATR(DataFrame, N=14):
"""
输出TR:(最高价-最低价)和昨收-最高价的绝对值的较大值和昨收-最低价的绝对值的较大值
输出真实波幅:TR的N日简单移动平均
算法:今日振幅、今日最高与昨收差价、今日最低与昨收差价中的最大值,为真实波幅,求真实波幅的N日移动平均
参数:N 天数,一般取14
"""
C = DataFrame['close']
H = DataFrame['high']
L = DataFrame['low']
TR = MAX(MAX((H - L), ABS(REF(C, 1) - H)), ABS(REF(C, 1) - L))
atr = MA(TR, N)
return pd.DataFrame({'TR': TR, 'ATR': atr})
|
python
|
def QA_indicator_ATR(DataFrame, N=14):
"""
输出TR:(最高价-最低价)和昨收-最高价的绝对值的较大值和昨收-最低价的绝对值的较大值
输出真实波幅:TR的N日简单移动平均
算法:今日振幅、今日最高与昨收差价、今日最低与昨收差价中的最大值,为真实波幅,求真实波幅的N日移动平均
参数:N 天数,一般取14
"""
C = DataFrame['close']
H = DataFrame['high']
L = DataFrame['low']
TR = MAX(MAX((H - L), ABS(REF(C, 1) - H)), ABS(REF(C, 1) - L))
atr = MA(TR, N)
return pd.DataFrame({'TR': TR, 'ATR': atr})
|
[
"def",
"QA_indicator_ATR",
"(",
"DataFrame",
",",
"N",
"=",
"14",
")",
":",
"C",
"=",
"DataFrame",
"[",
"'close'",
"]",
"H",
"=",
"DataFrame",
"[",
"'high'",
"]",
"L",
"=",
"DataFrame",
"[",
"'low'",
"]",
"TR",
"=",
"MAX",
"(",
"MAX",
"(",
"(",
"H",
"-",
"L",
")",
",",
"ABS",
"(",
"REF",
"(",
"C",
",",
"1",
")",
"-",
"H",
")",
")",
",",
"ABS",
"(",
"REF",
"(",
"C",
",",
"1",
")",
"-",
"L",
")",
")",
"atr",
"=",
"MA",
"(",
"TR",
",",
"N",
")",
"return",
"pd",
".",
"DataFrame",
"(",
"{",
"'TR'",
":",
"TR",
",",
"'ATR'",
":",
"atr",
"}",
")"
] |
输出TR:(最高价-最低价)和昨收-最高价的绝对值的较大值和昨收-最低价的绝对值的较大值
输出真实波幅:TR的N日简单移动平均
算法:今日振幅、今日最高与昨收差价、今日最低与昨收差价中的最大值,为真实波幅,求真实波幅的N日移动平均
参数:N 天数,一般取14
|
[
"输出TR",
":",
"(",
"最高价",
"-",
"最低价",
")",
"和昨收",
"-",
"最高价的绝对值的较大值和昨收",
"-",
"最低价的绝对值的较大值",
"输出真实波幅",
":",
"TR的N日简单移动平均",
"算法:今日振幅、今日最高与昨收差价、今日最低与昨收差价中的最大值,为真实波幅,求真实波幅的N日移动平均"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/indicators.py#L528-L542
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/indicators.py
|
QA_indicator_SKDJ
|
def QA_indicator_SKDJ(DataFrame, N=9, M=3):
"""
1.指标>80 时,回档机率大;指标<20 时,反弹机率大;
2.K在20左右向上交叉D时,视为买进信号参考;
3.K在80左右向下交叉D时,视为卖出信号参考;
4.SKDJ波动于50左右的任何讯号,其作用不大。
"""
CLOSE = DataFrame['close']
LOWV = LLV(DataFrame['low'], N)
HIGHV = HHV(DataFrame['high'], N)
RSV = EMA((CLOSE - LOWV) / (HIGHV - LOWV) * 100, M)
K = EMA(RSV, M)
D = MA(K, M)
DICT = {'RSV': RSV, 'SKDJ_K': K, 'SKDJ_D': D}
return pd.DataFrame(DICT)
|
python
|
def QA_indicator_SKDJ(DataFrame, N=9, M=3):
"""
1.指标>80 时,回档机率大;指标<20 时,反弹机率大;
2.K在20左右向上交叉D时,视为买进信号参考;
3.K在80左右向下交叉D时,视为卖出信号参考;
4.SKDJ波动于50左右的任何讯号,其作用不大。
"""
CLOSE = DataFrame['close']
LOWV = LLV(DataFrame['low'], N)
HIGHV = HHV(DataFrame['high'], N)
RSV = EMA((CLOSE - LOWV) / (HIGHV - LOWV) * 100, M)
K = EMA(RSV, M)
D = MA(K, M)
DICT = {'RSV': RSV, 'SKDJ_K': K, 'SKDJ_D': D}
return pd.DataFrame(DICT)
|
[
"def",
"QA_indicator_SKDJ",
"(",
"DataFrame",
",",
"N",
"=",
"9",
",",
"M",
"=",
"3",
")",
":",
"CLOSE",
"=",
"DataFrame",
"[",
"'close'",
"]",
"LOWV",
"=",
"LLV",
"(",
"DataFrame",
"[",
"'low'",
"]",
",",
"N",
")",
"HIGHV",
"=",
"HHV",
"(",
"DataFrame",
"[",
"'high'",
"]",
",",
"N",
")",
"RSV",
"=",
"EMA",
"(",
"(",
"CLOSE",
"-",
"LOWV",
")",
"/",
"(",
"HIGHV",
"-",
"LOWV",
")",
"*",
"100",
",",
"M",
")",
"K",
"=",
"EMA",
"(",
"RSV",
",",
"M",
")",
"D",
"=",
"MA",
"(",
"K",
",",
"M",
")",
"DICT",
"=",
"{",
"'RSV'",
":",
"RSV",
",",
"'SKDJ_K'",
":",
"K",
",",
"'SKDJ_D'",
":",
"D",
"}",
"return",
"pd",
".",
"DataFrame",
"(",
"DICT",
")"
] |
1.指标>80 时,回档机率大;指标<20 时,反弹机率大;
2.K在20左右向上交叉D时,视为买进信号参考;
3.K在80左右向下交叉D时,视为卖出信号参考;
4.SKDJ波动于50左右的任何讯号,其作用不大。
|
[
"1",
".",
"指标",
">",
"80",
"时,回档机率大;指标<20",
"时,反弹机率大;",
"2",
".",
"K在20左右向上交叉D时,视为买进信号参考;",
"3",
".",
"K在80左右向下交叉D时,视为卖出信号参考;",
"4",
".",
"SKDJ波动于50左右的任何讯号,其作用不大。"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/indicators.py#L545-L561
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/indicators.py
|
QA_indicator_DDI
|
def QA_indicator_DDI(DataFrame, N=13, N1=26, M=1, M1=5):
"""
'方向标准离差指数'
分析DDI柱状线,由红变绿(正变负),卖出信号参考;由绿变红,买入信号参考。
"""
H = DataFrame['high']
L = DataFrame['low']
DMZ = IF((H + L) > (REF(H, 1) + REF(L, 1)),
MAX(ABS(H - REF(H, 1)), ABS(L - REF(L, 1))), 0)
DMF = IF((H + L) < (REF(H, 1) + REF(L, 1)),
MAX(ABS(H - REF(H, 1)), ABS(L - REF(L, 1))), 0)
DIZ = SUM(DMZ, N) / (SUM(DMZ, N) + SUM(DMF, N))
DIF = SUM(DMF, N) / (SUM(DMF, N) + SUM(DMZ, N))
ddi = DIZ - DIF
ADDI = SMA(ddi, N1, M)
AD = MA(ADDI, M1)
DICT = {'DDI': ddi, 'ADDI': ADDI, 'AD': AD}
return pd.DataFrame(DICT)
|
python
|
def QA_indicator_DDI(DataFrame, N=13, N1=26, M=1, M1=5):
"""
'方向标准离差指数'
分析DDI柱状线,由红变绿(正变负),卖出信号参考;由绿变红,买入信号参考。
"""
H = DataFrame['high']
L = DataFrame['low']
DMZ = IF((H + L) > (REF(H, 1) + REF(L, 1)),
MAX(ABS(H - REF(H, 1)), ABS(L - REF(L, 1))), 0)
DMF = IF((H + L) < (REF(H, 1) + REF(L, 1)),
MAX(ABS(H - REF(H, 1)), ABS(L - REF(L, 1))), 0)
DIZ = SUM(DMZ, N) / (SUM(DMZ, N) + SUM(DMF, N))
DIF = SUM(DMF, N) / (SUM(DMF, N) + SUM(DMZ, N))
ddi = DIZ - DIF
ADDI = SMA(ddi, N1, M)
AD = MA(ADDI, M1)
DICT = {'DDI': ddi, 'ADDI': ADDI, 'AD': AD}
return pd.DataFrame(DICT)
|
[
"def",
"QA_indicator_DDI",
"(",
"DataFrame",
",",
"N",
"=",
"13",
",",
"N1",
"=",
"26",
",",
"M",
"=",
"1",
",",
"M1",
"=",
"5",
")",
":",
"H",
"=",
"DataFrame",
"[",
"'high'",
"]",
"L",
"=",
"DataFrame",
"[",
"'low'",
"]",
"DMZ",
"=",
"IF",
"(",
"(",
"H",
"+",
"L",
")",
">",
"(",
"REF",
"(",
"H",
",",
"1",
")",
"+",
"REF",
"(",
"L",
",",
"1",
")",
")",
",",
"MAX",
"(",
"ABS",
"(",
"H",
"-",
"REF",
"(",
"H",
",",
"1",
")",
")",
",",
"ABS",
"(",
"L",
"-",
"REF",
"(",
"L",
",",
"1",
")",
")",
")",
",",
"0",
")",
"DMF",
"=",
"IF",
"(",
"(",
"H",
"+",
"L",
")",
"<",
"(",
"REF",
"(",
"H",
",",
"1",
")",
"+",
"REF",
"(",
"L",
",",
"1",
")",
")",
",",
"MAX",
"(",
"ABS",
"(",
"H",
"-",
"REF",
"(",
"H",
",",
"1",
")",
")",
",",
"ABS",
"(",
"L",
"-",
"REF",
"(",
"L",
",",
"1",
")",
")",
")",
",",
"0",
")",
"DIZ",
"=",
"SUM",
"(",
"DMZ",
",",
"N",
")",
"/",
"(",
"SUM",
"(",
"DMZ",
",",
"N",
")",
"+",
"SUM",
"(",
"DMF",
",",
"N",
")",
")",
"DIF",
"=",
"SUM",
"(",
"DMF",
",",
"N",
")",
"/",
"(",
"SUM",
"(",
"DMF",
",",
"N",
")",
"+",
"SUM",
"(",
"DMZ",
",",
"N",
")",
")",
"ddi",
"=",
"DIZ",
"-",
"DIF",
"ADDI",
"=",
"SMA",
"(",
"ddi",
",",
"N1",
",",
"M",
")",
"AD",
"=",
"MA",
"(",
"ADDI",
",",
"M1",
")",
"DICT",
"=",
"{",
"'DDI'",
":",
"ddi",
",",
"'ADDI'",
":",
"ADDI",
",",
"'AD'",
":",
"AD",
"}",
"return",
"pd",
".",
"DataFrame",
"(",
"DICT",
")"
] |
'方向标准离差指数'
分析DDI柱状线,由红变绿(正变负),卖出信号参考;由绿变红,买入信号参考。
|
[
"方向标准离差指数",
"分析DDI柱状线,由红变绿",
"(",
"正变负",
")",
",卖出信号参考;由绿变红,买入信号参考。"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/indicators.py#L564-L583
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/indicators.py
|
QA_indicator_shadow
|
def QA_indicator_shadow(DataFrame):
"""
上下影线指标
"""
return {
'LOW': lower_shadow(DataFrame), 'UP': upper_shadow(DataFrame),
'BODY': body(DataFrame), 'BODY_ABS': body_abs(DataFrame), 'PRICE_PCG': price_pcg(DataFrame)
}
|
python
|
def QA_indicator_shadow(DataFrame):
"""
上下影线指标
"""
return {
'LOW': lower_shadow(DataFrame), 'UP': upper_shadow(DataFrame),
'BODY': body(DataFrame), 'BODY_ABS': body_abs(DataFrame), 'PRICE_PCG': price_pcg(DataFrame)
}
|
[
"def",
"QA_indicator_shadow",
"(",
"DataFrame",
")",
":",
"return",
"{",
"'LOW'",
":",
"lower_shadow",
"(",
"DataFrame",
")",
",",
"'UP'",
":",
"upper_shadow",
"(",
"DataFrame",
")",
",",
"'BODY'",
":",
"body",
"(",
"DataFrame",
")",
",",
"'BODY_ABS'",
":",
"body_abs",
"(",
"DataFrame",
")",
",",
"'PRICE_PCG'",
":",
"price_pcg",
"(",
"DataFrame",
")",
"}"
] |
上下影线指标
|
[
"上下影线指标"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/indicators.py#L586-L593
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/hurst.py
|
RSanalysis.run
|
def run(self, series, exponent=None):
'''
:type series: List
:type exponent: int
:rtype: float
'''
try:
return self.calculateHurst(series, exponent)
except Exception as e:
print(" Error: %s" % e)
|
python
|
def run(self, series, exponent=None):
'''
:type series: List
:type exponent: int
:rtype: float
'''
try:
return self.calculateHurst(series, exponent)
except Exception as e:
print(" Error: %s" % e)
|
[
"def",
"run",
"(",
"self",
",",
"series",
",",
"exponent",
"=",
"None",
")",
":",
"try",
":",
"return",
"self",
".",
"calculateHurst",
"(",
"series",
",",
"exponent",
")",
"except",
"Exception",
"as",
"e",
":",
"print",
"(",
"\" Error: %s\"",
"%",
"e",
")"
] |
:type series: List
:type exponent: int
:rtype: float
|
[
":",
"type",
"series",
":",
"List",
":",
"type",
"exponent",
":",
"int",
":",
"rtype",
":",
"float"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/hurst.py#L15-L24
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/hurst.py
|
RSanalysis.bestExponent
|
def bestExponent(self, seriesLenght):
'''
:type seriesLenght: int
:rtype: int
'''
i = 0
cont = True
while(cont):
if(int(seriesLenght/int(math.pow(2, i))) <= 1):
cont = False
else:
i += 1
return int(i-1)
|
python
|
def bestExponent(self, seriesLenght):
'''
:type seriesLenght: int
:rtype: int
'''
i = 0
cont = True
while(cont):
if(int(seriesLenght/int(math.pow(2, i))) <= 1):
cont = False
else:
i += 1
return int(i-1)
|
[
"def",
"bestExponent",
"(",
"self",
",",
"seriesLenght",
")",
":",
"i",
"=",
"0",
"cont",
"=",
"True",
"while",
"(",
"cont",
")",
":",
"if",
"(",
"int",
"(",
"seriesLenght",
"/",
"int",
"(",
"math",
".",
"pow",
"(",
"2",
",",
"i",
")",
")",
")",
"<=",
"1",
")",
":",
"cont",
"=",
"False",
"else",
":",
"i",
"+=",
"1",
"return",
"int",
"(",
"i",
"-",
"1",
")"
] |
:type seriesLenght: int
:rtype: int
|
[
":",
"type",
"seriesLenght",
":",
"int",
":",
"rtype",
":",
"int"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/hurst.py#L26-L38
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/hurst.py
|
RSanalysis.mean
|
def mean(self, series, start, limit):
'''
:type start: int
:type limit: int
:rtype: float
'''
return float(np.mean(series[start:limit]))
|
python
|
def mean(self, series, start, limit):
'''
:type start: int
:type limit: int
:rtype: float
'''
return float(np.mean(series[start:limit]))
|
[
"def",
"mean",
"(",
"self",
",",
"series",
",",
"start",
",",
"limit",
")",
":",
"return",
"float",
"(",
"np",
".",
"mean",
"(",
"series",
"[",
"start",
":",
"limit",
"]",
")",
")"
] |
:type start: int
:type limit: int
:rtype: float
|
[
":",
"type",
"start",
":",
"int",
":",
"type",
"limit",
":",
"int",
":",
"rtype",
":",
"float"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/hurst.py#L40-L46
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/hurst.py
|
RSanalysis.deviation
|
def deviation(self, series, start, limit, mean):
'''
:type start: int
:type limit: int
:type mean: int
:rtype: list()
'''
d = []
for x in range(start, limit):
d.append(float(series[x] - mean))
return d
|
python
|
def deviation(self, series, start, limit, mean):
'''
:type start: int
:type limit: int
:type mean: int
:rtype: list()
'''
d = []
for x in range(start, limit):
d.append(float(series[x] - mean))
return d
|
[
"def",
"deviation",
"(",
"self",
",",
"series",
",",
"start",
",",
"limit",
",",
"mean",
")",
":",
"d",
"=",
"[",
"]",
"for",
"x",
"in",
"range",
"(",
"start",
",",
"limit",
")",
":",
"d",
".",
"append",
"(",
"float",
"(",
"series",
"[",
"x",
"]",
"-",
"mean",
")",
")",
"return",
"d"
] |
:type start: int
:type limit: int
:type mean: int
:rtype: list()
|
[
":",
"type",
"start",
":",
"int",
":",
"type",
"limit",
":",
"int",
":",
"type",
"mean",
":",
"int",
":",
"rtype",
":",
"list",
"()"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/hurst.py#L55-L65
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/hurst.py
|
RSanalysis.standartDeviation
|
def standartDeviation(self, series, start, limit):
'''
:type start: int
:type limit: int
:rtype: float
'''
return float(np.std(series[start:limit]))
|
python
|
def standartDeviation(self, series, start, limit):
'''
:type start: int
:type limit: int
:rtype: float
'''
return float(np.std(series[start:limit]))
|
[
"def",
"standartDeviation",
"(",
"self",
",",
"series",
",",
"start",
",",
"limit",
")",
":",
"return",
"float",
"(",
"np",
".",
"std",
"(",
"series",
"[",
"start",
":",
"limit",
"]",
")",
")"
] |
:type start: int
:type limit: int
:rtype: float
|
[
":",
"type",
"start",
":",
"int",
":",
"type",
"limit",
":",
"int",
":",
"rtype",
":",
"float"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/hurst.py#L67-L73
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAIndicator/hurst.py
|
RSanalysis.calculateHurst
|
def calculateHurst(self, series, exponent=None):
'''
:type series: List
:type exponent: int
:rtype: float
'''
rescaledRange = list()
sizeRange = list()
rescaledRangeMean = list()
if(exponent is None):
exponent = self.bestExponent(len(series))
for i in range(0, exponent):
partsNumber = int(math.pow(2, i))
size = int(len(series)/partsNumber)
sizeRange.append(size)
rescaledRange.append(0)
rescaledRangeMean.append(0)
for x in range(0, partsNumber):
start = int(size*(x))
limit = int(size*(x+1))
deviationAcumulative = self.sumDeviation(self.deviation(
series, start, limit, self.mean(series, start, limit)))
deviationsDifference = float(
max(deviationAcumulative) - min(deviationAcumulative))
standartDeviation = self.standartDeviation(
series, start, limit)
if(deviationsDifference != 0 and standartDeviation != 0):
rescaledRange[i] += (deviationsDifference /
standartDeviation)
y = 0
for x in rescaledRange:
rescaledRangeMean[y] = x/int(math.pow(2, y))
y = y+1
# log calculation
rescaledRangeLog = list()
sizeRangeLog = list()
for i in range(0, exponent):
rescaledRangeLog.append(math.log(rescaledRangeMean[i], 10))
sizeRangeLog.append(math.log(sizeRange[i], 10))
slope, intercept = np.polyfit(sizeRangeLog, rescaledRangeLog, 1)
ablineValues = [slope * i + intercept for i in sizeRangeLog]
plt.plot(sizeRangeLog, rescaledRangeLog, '--')
plt.plot(sizeRangeLog, ablineValues, 'b')
plt.title(slope)
# graphic dimension settings
limitUp = 0
if(max(sizeRangeLog) > max(rescaledRangeLog)):
limitUp = max(sizeRangeLog)
else:
limitUp = max(rescaledRangeLog)
limitDown = 0
if(min(sizeRangeLog) > min(rescaledRangeLog)):
limitDown = min(rescaledRangeLog)
else:
limitDown = min(sizeRangeLog)
plt.gca().set_xlim(limitDown, limitUp)
plt.gca().set_ylim(limitDown, limitUp)
print("Hurst exponent: " + str(slope))
plt.show()
return slope
|
python
|
def calculateHurst(self, series, exponent=None):
'''
:type series: List
:type exponent: int
:rtype: float
'''
rescaledRange = list()
sizeRange = list()
rescaledRangeMean = list()
if(exponent is None):
exponent = self.bestExponent(len(series))
for i in range(0, exponent):
partsNumber = int(math.pow(2, i))
size = int(len(series)/partsNumber)
sizeRange.append(size)
rescaledRange.append(0)
rescaledRangeMean.append(0)
for x in range(0, partsNumber):
start = int(size*(x))
limit = int(size*(x+1))
deviationAcumulative = self.sumDeviation(self.deviation(
series, start, limit, self.mean(series, start, limit)))
deviationsDifference = float(
max(deviationAcumulative) - min(deviationAcumulative))
standartDeviation = self.standartDeviation(
series, start, limit)
if(deviationsDifference != 0 and standartDeviation != 0):
rescaledRange[i] += (deviationsDifference /
standartDeviation)
y = 0
for x in rescaledRange:
rescaledRangeMean[y] = x/int(math.pow(2, y))
y = y+1
# log calculation
rescaledRangeLog = list()
sizeRangeLog = list()
for i in range(0, exponent):
rescaledRangeLog.append(math.log(rescaledRangeMean[i], 10))
sizeRangeLog.append(math.log(sizeRange[i], 10))
slope, intercept = np.polyfit(sizeRangeLog, rescaledRangeLog, 1)
ablineValues = [slope * i + intercept for i in sizeRangeLog]
plt.plot(sizeRangeLog, rescaledRangeLog, '--')
plt.plot(sizeRangeLog, ablineValues, 'b')
plt.title(slope)
# graphic dimension settings
limitUp = 0
if(max(sizeRangeLog) > max(rescaledRangeLog)):
limitUp = max(sizeRangeLog)
else:
limitUp = max(rescaledRangeLog)
limitDown = 0
if(min(sizeRangeLog) > min(rescaledRangeLog)):
limitDown = min(rescaledRangeLog)
else:
limitDown = min(sizeRangeLog)
plt.gca().set_xlim(limitDown, limitUp)
plt.gca().set_ylim(limitDown, limitUp)
print("Hurst exponent: " + str(slope))
plt.show()
return slope
|
[
"def",
"calculateHurst",
"(",
"self",
",",
"series",
",",
"exponent",
"=",
"None",
")",
":",
"rescaledRange",
"=",
"list",
"(",
")",
"sizeRange",
"=",
"list",
"(",
")",
"rescaledRangeMean",
"=",
"list",
"(",
")",
"if",
"(",
"exponent",
"is",
"None",
")",
":",
"exponent",
"=",
"self",
".",
"bestExponent",
"(",
"len",
"(",
"series",
")",
")",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"exponent",
")",
":",
"partsNumber",
"=",
"int",
"(",
"math",
".",
"pow",
"(",
"2",
",",
"i",
")",
")",
"size",
"=",
"int",
"(",
"len",
"(",
"series",
")",
"/",
"partsNumber",
")",
"sizeRange",
".",
"append",
"(",
"size",
")",
"rescaledRange",
".",
"append",
"(",
"0",
")",
"rescaledRangeMean",
".",
"append",
"(",
"0",
")",
"for",
"x",
"in",
"range",
"(",
"0",
",",
"partsNumber",
")",
":",
"start",
"=",
"int",
"(",
"size",
"*",
"(",
"x",
")",
")",
"limit",
"=",
"int",
"(",
"size",
"*",
"(",
"x",
"+",
"1",
")",
")",
"deviationAcumulative",
"=",
"self",
".",
"sumDeviation",
"(",
"self",
".",
"deviation",
"(",
"series",
",",
"start",
",",
"limit",
",",
"self",
".",
"mean",
"(",
"series",
",",
"start",
",",
"limit",
")",
")",
")",
"deviationsDifference",
"=",
"float",
"(",
"max",
"(",
"deviationAcumulative",
")",
"-",
"min",
"(",
"deviationAcumulative",
")",
")",
"standartDeviation",
"=",
"self",
".",
"standartDeviation",
"(",
"series",
",",
"start",
",",
"limit",
")",
"if",
"(",
"deviationsDifference",
"!=",
"0",
"and",
"standartDeviation",
"!=",
"0",
")",
":",
"rescaledRange",
"[",
"i",
"]",
"+=",
"(",
"deviationsDifference",
"/",
"standartDeviation",
")",
"y",
"=",
"0",
"for",
"x",
"in",
"rescaledRange",
":",
"rescaledRangeMean",
"[",
"y",
"]",
"=",
"x",
"/",
"int",
"(",
"math",
".",
"pow",
"(",
"2",
",",
"y",
")",
")",
"y",
"=",
"y",
"+",
"1",
"# log calculation",
"rescaledRangeLog",
"=",
"list",
"(",
")",
"sizeRangeLog",
"=",
"list",
"(",
")",
"for",
"i",
"in",
"range",
"(",
"0",
",",
"exponent",
")",
":",
"rescaledRangeLog",
".",
"append",
"(",
"math",
".",
"log",
"(",
"rescaledRangeMean",
"[",
"i",
"]",
",",
"10",
")",
")",
"sizeRangeLog",
".",
"append",
"(",
"math",
".",
"log",
"(",
"sizeRange",
"[",
"i",
"]",
",",
"10",
")",
")",
"slope",
",",
"intercept",
"=",
"np",
".",
"polyfit",
"(",
"sizeRangeLog",
",",
"rescaledRangeLog",
",",
"1",
")",
"ablineValues",
"=",
"[",
"slope",
"*",
"i",
"+",
"intercept",
"for",
"i",
"in",
"sizeRangeLog",
"]",
"plt",
".",
"plot",
"(",
"sizeRangeLog",
",",
"rescaledRangeLog",
",",
"'--'",
")",
"plt",
".",
"plot",
"(",
"sizeRangeLog",
",",
"ablineValues",
",",
"'b'",
")",
"plt",
".",
"title",
"(",
"slope",
")",
"# graphic dimension settings",
"limitUp",
"=",
"0",
"if",
"(",
"max",
"(",
"sizeRangeLog",
")",
">",
"max",
"(",
"rescaledRangeLog",
")",
")",
":",
"limitUp",
"=",
"max",
"(",
"sizeRangeLog",
")",
"else",
":",
"limitUp",
"=",
"max",
"(",
"rescaledRangeLog",
")",
"limitDown",
"=",
"0",
"if",
"(",
"min",
"(",
"sizeRangeLog",
")",
">",
"min",
"(",
"rescaledRangeLog",
")",
")",
":",
"limitDown",
"=",
"min",
"(",
"rescaledRangeLog",
")",
"else",
":",
"limitDown",
"=",
"min",
"(",
"sizeRangeLog",
")",
"plt",
".",
"gca",
"(",
")",
".",
"set_xlim",
"(",
"limitDown",
",",
"limitUp",
")",
"plt",
".",
"gca",
"(",
")",
".",
"set_ylim",
"(",
"limitDown",
",",
"limitUp",
")",
"print",
"(",
"\"Hurst exponent: \"",
"+",
"str",
"(",
"slope",
")",
")",
"plt",
".",
"show",
"(",
")",
"return",
"slope"
] |
:type series: List
:type exponent: int
:rtype: float
|
[
":",
"type",
"series",
":",
"List",
":",
"type",
"exponent",
":",
"int",
":",
"rtype",
":",
"float"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAIndicator/hurst.py#L75-L146
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAUtil/QAMail.py
|
QA_util_send_mail
|
def QA_util_send_mail(msg, title, from_user, from_password, to_addr, smtp):
"""邮件发送
Arguments:
msg {[type]} -- [description]
title {[type]} -- [description]
from_user {[type]} -- [description]
from_password {[type]} -- [description]
to_addr {[type]} -- [description]
smtp {[type]} -- [description]
"""
msg = MIMEText(msg, 'plain', 'utf-8')
msg['Subject'] = Header(title, 'utf-8').encode()
server = smtplib.SMTP(smtp, 25) # SMTP协议默认端口是25
server.set_debuglevel(1)
server.login(from_user, from_password)
server.sendmail(from_user, [to_addr], msg.as_string())
|
python
|
def QA_util_send_mail(msg, title, from_user, from_password, to_addr, smtp):
"""邮件发送
Arguments:
msg {[type]} -- [description]
title {[type]} -- [description]
from_user {[type]} -- [description]
from_password {[type]} -- [description]
to_addr {[type]} -- [description]
smtp {[type]} -- [description]
"""
msg = MIMEText(msg, 'plain', 'utf-8')
msg['Subject'] = Header(title, 'utf-8').encode()
server = smtplib.SMTP(smtp, 25) # SMTP协议默认端口是25
server.set_debuglevel(1)
server.login(from_user, from_password)
server.sendmail(from_user, [to_addr], msg.as_string())
|
[
"def",
"QA_util_send_mail",
"(",
"msg",
",",
"title",
",",
"from_user",
",",
"from_password",
",",
"to_addr",
",",
"smtp",
")",
":",
"msg",
"=",
"MIMEText",
"(",
"msg",
",",
"'plain'",
",",
"'utf-8'",
")",
"msg",
"[",
"'Subject'",
"]",
"=",
"Header",
"(",
"title",
",",
"'utf-8'",
")",
".",
"encode",
"(",
")",
"server",
"=",
"smtplib",
".",
"SMTP",
"(",
"smtp",
",",
"25",
")",
"# SMTP协议默认端口是25",
"server",
".",
"set_debuglevel",
"(",
"1",
")",
"server",
".",
"login",
"(",
"from_user",
",",
"from_password",
")",
"server",
".",
"sendmail",
"(",
"from_user",
",",
"[",
"to_addr",
"]",
",",
"msg",
".",
"as_string",
"(",
")",
")"
] |
邮件发送
Arguments:
msg {[type]} -- [description]
title {[type]} -- [description]
from_user {[type]} -- [description]
from_password {[type]} -- [description]
to_addr {[type]} -- [description]
smtp {[type]} -- [description]
|
[
"邮件发送",
"Arguments",
":",
"msg",
"{",
"[",
"type",
"]",
"}",
"--",
"[",
"description",
"]",
"title",
"{",
"[",
"type",
"]",
"}",
"--",
"[",
"description",
"]",
"from_user",
"{",
"[",
"type",
"]",
"}",
"--",
"[",
"description",
"]",
"from_password",
"{",
"[",
"type",
"]",
"}",
"--",
"[",
"description",
"]",
"to_addr",
"{",
"[",
"type",
"]",
"}",
"--",
"[",
"description",
"]",
"smtp",
"{",
"[",
"type",
"]",
"}",
"--",
"[",
"description",
"]"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAUtil/QAMail.py#L32-L50
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAFetch/QAEastMoney.py
|
QA_fetch_get_stock_analysis
|
def QA_fetch_get_stock_analysis(code):
"""
'zyfw', 主营范围 'jyps'#经营评述 'zygcfx' 主营构成分析
date 主营构成 主营收入(元) 收入比例cbbl 主营成本(元) 成本比例 主营利润(元) 利润比例 毛利率(%)
行业 /产品/ 区域 hq cp qy
"""
market = 'sh' if _select_market_code(code) == 1 else 'sz'
null = 'none'
data = eval(requests.get(BusinessAnalysis_url.format(
market, code), headers=headers_em).text)
zyfw = pd.DataFrame(data.get('zyfw', None))
jyps = pd.DataFrame(data.get('jyps', None))
zygcfx = data.get('zygcfx', [])
temp = []
for item in zygcfx:
try:
data_ = pd.concat([pd.DataFrame(item['hy']).assign(date=item['rq']).assign(classify='hy'),
pd.DataFrame(item['cp']).assign(
date=item['rq']).assign(classify='cp'),
pd.DataFrame(item['qy']).assign(date=item['rq']).assign(classify='qy')])
temp.append(data_)
except:
pass
try:
res_zyfcfx = pd.concat(temp).set_index(
['date', 'classify'], drop=False)
except:
res_zyfcfx = None
return zyfw, jyps, res_zyfcfx
|
python
|
def QA_fetch_get_stock_analysis(code):
"""
'zyfw', 主营范围 'jyps'#经营评述 'zygcfx' 主营构成分析
date 主营构成 主营收入(元) 收入比例cbbl 主营成本(元) 成本比例 主营利润(元) 利润比例 毛利率(%)
行业 /产品/ 区域 hq cp qy
"""
market = 'sh' if _select_market_code(code) == 1 else 'sz'
null = 'none'
data = eval(requests.get(BusinessAnalysis_url.format(
market, code), headers=headers_em).text)
zyfw = pd.DataFrame(data.get('zyfw', None))
jyps = pd.DataFrame(data.get('jyps', None))
zygcfx = data.get('zygcfx', [])
temp = []
for item in zygcfx:
try:
data_ = pd.concat([pd.DataFrame(item['hy']).assign(date=item['rq']).assign(classify='hy'),
pd.DataFrame(item['cp']).assign(
date=item['rq']).assign(classify='cp'),
pd.DataFrame(item['qy']).assign(date=item['rq']).assign(classify='qy')])
temp.append(data_)
except:
pass
try:
res_zyfcfx = pd.concat(temp).set_index(
['date', 'classify'], drop=False)
except:
res_zyfcfx = None
return zyfw, jyps, res_zyfcfx
|
[
"def",
"QA_fetch_get_stock_analysis",
"(",
"code",
")",
":",
"market",
"=",
"'sh'",
"if",
"_select_market_code",
"(",
"code",
")",
"==",
"1",
"else",
"'sz'",
"null",
"=",
"'none'",
"data",
"=",
"eval",
"(",
"requests",
".",
"get",
"(",
"BusinessAnalysis_url",
".",
"format",
"(",
"market",
",",
"code",
")",
",",
"headers",
"=",
"headers_em",
")",
".",
"text",
")",
"zyfw",
"=",
"pd",
".",
"DataFrame",
"(",
"data",
".",
"get",
"(",
"'zyfw'",
",",
"None",
")",
")",
"jyps",
"=",
"pd",
".",
"DataFrame",
"(",
"data",
".",
"get",
"(",
"'jyps'",
",",
"None",
")",
")",
"zygcfx",
"=",
"data",
".",
"get",
"(",
"'zygcfx'",
",",
"[",
"]",
")",
"temp",
"=",
"[",
"]",
"for",
"item",
"in",
"zygcfx",
":",
"try",
":",
"data_",
"=",
"pd",
".",
"concat",
"(",
"[",
"pd",
".",
"DataFrame",
"(",
"item",
"[",
"'hy'",
"]",
")",
".",
"assign",
"(",
"date",
"=",
"item",
"[",
"'rq'",
"]",
")",
".",
"assign",
"(",
"classify",
"=",
"'hy'",
")",
",",
"pd",
".",
"DataFrame",
"(",
"item",
"[",
"'cp'",
"]",
")",
".",
"assign",
"(",
"date",
"=",
"item",
"[",
"'rq'",
"]",
")",
".",
"assign",
"(",
"classify",
"=",
"'cp'",
")",
",",
"pd",
".",
"DataFrame",
"(",
"item",
"[",
"'qy'",
"]",
")",
".",
"assign",
"(",
"date",
"=",
"item",
"[",
"'rq'",
"]",
")",
".",
"assign",
"(",
"classify",
"=",
"'qy'",
")",
"]",
")",
"temp",
".",
"append",
"(",
"data_",
")",
"except",
":",
"pass",
"try",
":",
"res_zyfcfx",
"=",
"pd",
".",
"concat",
"(",
"temp",
")",
".",
"set_index",
"(",
"[",
"'date'",
",",
"'classify'",
"]",
",",
"drop",
"=",
"False",
")",
"except",
":",
"res_zyfcfx",
"=",
"None",
"return",
"zyfw",
",",
"jyps",
",",
"res_zyfcfx"
] |
'zyfw', 主营范围 'jyps'#经营评述 'zygcfx' 主营构成分析
date 主营构成 主营收入(元) 收入比例cbbl 主营成本(元) 成本比例 主营利润(元) 利润比例 毛利率(%)
行业 /产品/ 区域 hq cp qy
|
[
"zyfw",
"主营范围",
"jyps",
"#经营评述",
"zygcfx",
"主营构成分析"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAFetch/QAEastMoney.py#L35-L66
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAMarket/QATTSBroker.py
|
QA_TTSBroker.send_order
|
def send_order(self, code, price, amount, towards, order_model, market=None):
"""下单
Arguments:
code {[type]} -- [description]
price {[type]} -- [description]
amount {[type]} -- [description]
towards {[type]} -- [description]
order_model {[type]} -- [description]
market:市场,SZ 深交所,SH 上交所
Returns:
[type] -- [description]
"""
towards = 0 if towards == ORDER_DIRECTION.BUY else 1
if order_model == ORDER_MODEL.MARKET:
order_model = 4
elif order_model == ORDER_MODEL.LIMIT:
order_model = 0
if market is None:
market = QAFetch.base.get_stock_market(code)
if not isinstance(market, str):
raise Exception('%s不正确,请检查code和market参数' % market)
market = market.lower()
if market not in ['sh', 'sz']:
raise Exception('%s不支持,请检查code和market参数' % market)
return self.data_to_df(self.call("send_order", {
'client_id': self.client_id,
'category': towards,
'price_type': order_model,
'gddm': self.gddm_sh if market == 'sh' else self.gddm_sz,
'zqdm': code,
'price': price,
'quantity': amount
}))
|
python
|
def send_order(self, code, price, amount, towards, order_model, market=None):
"""下单
Arguments:
code {[type]} -- [description]
price {[type]} -- [description]
amount {[type]} -- [description]
towards {[type]} -- [description]
order_model {[type]} -- [description]
market:市场,SZ 深交所,SH 上交所
Returns:
[type] -- [description]
"""
towards = 0 if towards == ORDER_DIRECTION.BUY else 1
if order_model == ORDER_MODEL.MARKET:
order_model = 4
elif order_model == ORDER_MODEL.LIMIT:
order_model = 0
if market is None:
market = QAFetch.base.get_stock_market(code)
if not isinstance(market, str):
raise Exception('%s不正确,请检查code和market参数' % market)
market = market.lower()
if market not in ['sh', 'sz']:
raise Exception('%s不支持,请检查code和market参数' % market)
return self.data_to_df(self.call("send_order", {
'client_id': self.client_id,
'category': towards,
'price_type': order_model,
'gddm': self.gddm_sh if market == 'sh' else self.gddm_sz,
'zqdm': code,
'price': price,
'quantity': amount
}))
|
[
"def",
"send_order",
"(",
"self",
",",
"code",
",",
"price",
",",
"amount",
",",
"towards",
",",
"order_model",
",",
"market",
"=",
"None",
")",
":",
"towards",
"=",
"0",
"if",
"towards",
"==",
"ORDER_DIRECTION",
".",
"BUY",
"else",
"1",
"if",
"order_model",
"==",
"ORDER_MODEL",
".",
"MARKET",
":",
"order_model",
"=",
"4",
"elif",
"order_model",
"==",
"ORDER_MODEL",
".",
"LIMIT",
":",
"order_model",
"=",
"0",
"if",
"market",
"is",
"None",
":",
"market",
"=",
"QAFetch",
".",
"base",
".",
"get_stock_market",
"(",
"code",
")",
"if",
"not",
"isinstance",
"(",
"market",
",",
"str",
")",
":",
"raise",
"Exception",
"(",
"'%s不正确,请检查code和market参数' % market)",
"",
"",
"",
"market",
"=",
"market",
".",
"lower",
"(",
")",
"if",
"market",
"not",
"in",
"[",
"'sh'",
",",
"'sz'",
"]",
":",
"raise",
"Exception",
"(",
"'%s不支持,请检查code和market参数' % market)",
"",
"",
"",
"return",
"self",
".",
"data_to_df",
"(",
"self",
".",
"call",
"(",
"\"send_order\"",
",",
"{",
"'client_id'",
":",
"self",
".",
"client_id",
",",
"'category'",
":",
"towards",
",",
"'price_type'",
":",
"order_model",
",",
"'gddm'",
":",
"self",
".",
"gddm_sh",
"if",
"market",
"==",
"'sh'",
"else",
"self",
".",
"gddm_sz",
",",
"'zqdm'",
":",
"code",
",",
"'price'",
":",
"price",
",",
"'quantity'",
":",
"amount",
"}",
")",
")"
] |
下单
Arguments:
code {[type]} -- [description]
price {[type]} -- [description]
amount {[type]} -- [description]
towards {[type]} -- [description]
order_model {[type]} -- [description]
market:市场,SZ 深交所,SH 上交所
Returns:
[type] -- [description]
|
[
"下单"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAMarket/QATTSBroker.py#L255-L292
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAUtil/QADateTools.py
|
QA_util_getBetweenMonth
|
def QA_util_getBetweenMonth(from_date, to_date):
"""
#返回所有月份,以及每月的起始日期、结束日期,字典格式
"""
date_list = {}
begin_date = datetime.datetime.strptime(from_date, "%Y-%m-%d")
end_date = datetime.datetime.strptime(to_date, "%Y-%m-%d")
while begin_date <= end_date:
date_str = begin_date.strftime("%Y-%m")
date_list[date_str] = ['%d-%d-01' % (begin_date.year, begin_date.month),
'%d-%d-%d' % (begin_date.year, begin_date.month,
calendar.monthrange(begin_date.year, begin_date.month)[1])]
begin_date = QA_util_get_1st_of_next_month(begin_date)
return(date_list)
|
python
|
def QA_util_getBetweenMonth(from_date, to_date):
"""
#返回所有月份,以及每月的起始日期、结束日期,字典格式
"""
date_list = {}
begin_date = datetime.datetime.strptime(from_date, "%Y-%m-%d")
end_date = datetime.datetime.strptime(to_date, "%Y-%m-%d")
while begin_date <= end_date:
date_str = begin_date.strftime("%Y-%m")
date_list[date_str] = ['%d-%d-01' % (begin_date.year, begin_date.month),
'%d-%d-%d' % (begin_date.year, begin_date.month,
calendar.monthrange(begin_date.year, begin_date.month)[1])]
begin_date = QA_util_get_1st_of_next_month(begin_date)
return(date_list)
|
[
"def",
"QA_util_getBetweenMonth",
"(",
"from_date",
",",
"to_date",
")",
":",
"date_list",
"=",
"{",
"}",
"begin_date",
"=",
"datetime",
".",
"datetime",
".",
"strptime",
"(",
"from_date",
",",
"\"%Y-%m-%d\"",
")",
"end_date",
"=",
"datetime",
".",
"datetime",
".",
"strptime",
"(",
"to_date",
",",
"\"%Y-%m-%d\"",
")",
"while",
"begin_date",
"<=",
"end_date",
":",
"date_str",
"=",
"begin_date",
".",
"strftime",
"(",
"\"%Y-%m\"",
")",
"date_list",
"[",
"date_str",
"]",
"=",
"[",
"'%d-%d-01'",
"%",
"(",
"begin_date",
".",
"year",
",",
"begin_date",
".",
"month",
")",
",",
"'%d-%d-%d'",
"%",
"(",
"begin_date",
".",
"year",
",",
"begin_date",
".",
"month",
",",
"calendar",
".",
"monthrange",
"(",
"begin_date",
".",
"year",
",",
"begin_date",
".",
"month",
")",
"[",
"1",
"]",
")",
"]",
"begin_date",
"=",
"QA_util_get_1st_of_next_month",
"(",
"begin_date",
")",
"return",
"(",
"date_list",
")"
] |
#返回所有月份,以及每月的起始日期、结束日期,字典格式
|
[
"#返回所有月份,以及每月的起始日期、结束日期,字典格式"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAUtil/QADateTools.py#L6-L19
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAUtil/QADateTools.py
|
QA_util_add_months
|
def QA_util_add_months(dt, months):
"""
#返回dt隔months个月后的日期,months相当于步长
"""
dt = datetime.datetime.strptime(
dt, "%Y-%m-%d") + relativedelta(months=months)
return(dt)
|
python
|
def QA_util_add_months(dt, months):
"""
#返回dt隔months个月后的日期,months相当于步长
"""
dt = datetime.datetime.strptime(
dt, "%Y-%m-%d") + relativedelta(months=months)
return(dt)
|
[
"def",
"QA_util_add_months",
"(",
"dt",
",",
"months",
")",
":",
"dt",
"=",
"datetime",
".",
"datetime",
".",
"strptime",
"(",
"dt",
",",
"\"%Y-%m-%d\"",
")",
"+",
"relativedelta",
"(",
"months",
"=",
"months",
")",
"return",
"(",
"dt",
")"
] |
#返回dt隔months个月后的日期,months相当于步长
|
[
"#返回dt隔months个月后的日期,months相当于步长"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAUtil/QADateTools.py#L22-L28
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAUtil/QADateTools.py
|
QA_util_get_1st_of_next_month
|
def QA_util_get_1st_of_next_month(dt):
"""
获取下个月第一天的日期
:return: 返回日期
"""
year = dt.year
month = dt.month
if month == 12:
month = 1
year += 1
else:
month += 1
res = datetime.datetime(year, month, 1)
return res
|
python
|
def QA_util_get_1st_of_next_month(dt):
"""
获取下个月第一天的日期
:return: 返回日期
"""
year = dt.year
month = dt.month
if month == 12:
month = 1
year += 1
else:
month += 1
res = datetime.datetime(year, month, 1)
return res
|
[
"def",
"QA_util_get_1st_of_next_month",
"(",
"dt",
")",
":",
"year",
"=",
"dt",
".",
"year",
"month",
"=",
"dt",
".",
"month",
"if",
"month",
"==",
"12",
":",
"month",
"=",
"1",
"year",
"+=",
"1",
"else",
":",
"month",
"+=",
"1",
"res",
"=",
"datetime",
".",
"datetime",
"(",
"year",
",",
"month",
",",
"1",
")",
"return",
"res"
] |
获取下个月第一天的日期
:return: 返回日期
|
[
"获取下个月第一天的日期",
":",
"return",
":",
"返回日期"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAUtil/QADateTools.py#L31-L44
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAUtil/QADateTools.py
|
QA_util_getBetweenQuarter
|
def QA_util_getBetweenQuarter(begin_date, end_date):
"""
#加上每季度的起始日期、结束日期
"""
quarter_list = {}
month_list = QA_util_getBetweenMonth(begin_date, end_date)
for value in month_list:
tempvalue = value.split("-")
year = tempvalue[0]
if tempvalue[1] in ['01', '02', '03']:
quarter_list[year + "Q1"] = ['%s-01-01' % year, '%s-03-31' % year]
elif tempvalue[1] in ['04', '05', '06']:
quarter_list[year + "Q2"] = ['%s-04-01' % year, '%s-06-30' % year]
elif tempvalue[1] in ['07', '08', '09']:
quarter_list[year + "Q3"] = ['%s-07-31' % year, '%s-09-30' % year]
elif tempvalue[1] in ['10', '11', '12']:
quarter_list[year + "Q4"] = ['%s-10-01' % year, '%s-12-31' % year]
return(quarter_list)
|
python
|
def QA_util_getBetweenQuarter(begin_date, end_date):
"""
#加上每季度的起始日期、结束日期
"""
quarter_list = {}
month_list = QA_util_getBetweenMonth(begin_date, end_date)
for value in month_list:
tempvalue = value.split("-")
year = tempvalue[0]
if tempvalue[1] in ['01', '02', '03']:
quarter_list[year + "Q1"] = ['%s-01-01' % year, '%s-03-31' % year]
elif tempvalue[1] in ['04', '05', '06']:
quarter_list[year + "Q2"] = ['%s-04-01' % year, '%s-06-30' % year]
elif tempvalue[1] in ['07', '08', '09']:
quarter_list[year + "Q3"] = ['%s-07-31' % year, '%s-09-30' % year]
elif tempvalue[1] in ['10', '11', '12']:
quarter_list[year + "Q4"] = ['%s-10-01' % year, '%s-12-31' % year]
return(quarter_list)
|
[
"def",
"QA_util_getBetweenQuarter",
"(",
"begin_date",
",",
"end_date",
")",
":",
"quarter_list",
"=",
"{",
"}",
"month_list",
"=",
"QA_util_getBetweenMonth",
"(",
"begin_date",
",",
"end_date",
")",
"for",
"value",
"in",
"month_list",
":",
"tempvalue",
"=",
"value",
".",
"split",
"(",
"\"-\"",
")",
"year",
"=",
"tempvalue",
"[",
"0",
"]",
"if",
"tempvalue",
"[",
"1",
"]",
"in",
"[",
"'01'",
",",
"'02'",
",",
"'03'",
"]",
":",
"quarter_list",
"[",
"year",
"+",
"\"Q1\"",
"]",
"=",
"[",
"'%s-01-01'",
"%",
"year",
",",
"'%s-03-31'",
"%",
"year",
"]",
"elif",
"tempvalue",
"[",
"1",
"]",
"in",
"[",
"'04'",
",",
"'05'",
",",
"'06'",
"]",
":",
"quarter_list",
"[",
"year",
"+",
"\"Q2\"",
"]",
"=",
"[",
"'%s-04-01'",
"%",
"year",
",",
"'%s-06-30'",
"%",
"year",
"]",
"elif",
"tempvalue",
"[",
"1",
"]",
"in",
"[",
"'07'",
",",
"'08'",
",",
"'09'",
"]",
":",
"quarter_list",
"[",
"year",
"+",
"\"Q3\"",
"]",
"=",
"[",
"'%s-07-31'",
"%",
"year",
",",
"'%s-09-30'",
"%",
"year",
"]",
"elif",
"tempvalue",
"[",
"1",
"]",
"in",
"[",
"'10'",
",",
"'11'",
",",
"'12'",
"]",
":",
"quarter_list",
"[",
"year",
"+",
"\"Q4\"",
"]",
"=",
"[",
"'%s-10-01'",
"%",
"year",
",",
"'%s-12-31'",
"%",
"year",
"]",
"return",
"(",
"quarter_list",
")"
] |
#加上每季度的起始日期、结束日期
|
[
"#加上每季度的起始日期、结束日期"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAUtil/QADateTools.py#L47-L64
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QASU/save_account.py
|
save_account
|
def save_account(message, collection=DATABASE.account):
"""save account
Arguments:
message {[type]} -- [description]
Keyword Arguments:
collection {[type]} -- [description] (default: {DATABASE})
"""
try:
collection.create_index(
[("account_cookie", ASCENDING), ("user_cookie", ASCENDING), ("portfolio_cookie", ASCENDING)], unique=True)
except:
pass
collection.update(
{'account_cookie': message['account_cookie'], 'portfolio_cookie':
message['portfolio_cookie'], 'user_cookie': message['user_cookie']},
{'$set': message},
upsert=True
)
|
python
|
def save_account(message, collection=DATABASE.account):
"""save account
Arguments:
message {[type]} -- [description]
Keyword Arguments:
collection {[type]} -- [description] (default: {DATABASE})
"""
try:
collection.create_index(
[("account_cookie", ASCENDING), ("user_cookie", ASCENDING), ("portfolio_cookie", ASCENDING)], unique=True)
except:
pass
collection.update(
{'account_cookie': message['account_cookie'], 'portfolio_cookie':
message['portfolio_cookie'], 'user_cookie': message['user_cookie']},
{'$set': message},
upsert=True
)
|
[
"def",
"save_account",
"(",
"message",
",",
"collection",
"=",
"DATABASE",
".",
"account",
")",
":",
"try",
":",
"collection",
".",
"create_index",
"(",
"[",
"(",
"\"account_cookie\"",
",",
"ASCENDING",
")",
",",
"(",
"\"user_cookie\"",
",",
"ASCENDING",
")",
",",
"(",
"\"portfolio_cookie\"",
",",
"ASCENDING",
")",
"]",
",",
"unique",
"=",
"True",
")",
"except",
":",
"pass",
"collection",
".",
"update",
"(",
"{",
"'account_cookie'",
":",
"message",
"[",
"'account_cookie'",
"]",
",",
"'portfolio_cookie'",
":",
"message",
"[",
"'portfolio_cookie'",
"]",
",",
"'user_cookie'",
":",
"message",
"[",
"'user_cookie'",
"]",
"}",
",",
"{",
"'$set'",
":",
"message",
"}",
",",
"upsert",
"=",
"True",
")"
] |
save account
Arguments:
message {[type]} -- [description]
Keyword Arguments:
collection {[type]} -- [description] (default: {DATABASE})
|
[
"save",
"account"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QASU/save_account.py#L32-L51
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QASU/save_financialfiles.py
|
QA_SU_save_financial_files
|
def QA_SU_save_financial_files():
"""本地存储financialdata
"""
download_financialzip()
coll = DATABASE.financial
coll.create_index(
[("code", ASCENDING), ("report_date", ASCENDING)], unique=True)
for item in os.listdir(download_path):
if item[0:4] != 'gpcw':
print(
"file ", item, " is not start with gpcw , seems not a financial file , ignore!")
continue
date = int(item.split('.')[0][-8:])
print('QUANTAXIS NOW SAVING {}'.format(date))
if coll.find({'report_date': date}).count() < 3600:
print(coll.find({'report_date': date}).count())
data = QA_util_to_json_from_pandas(parse_filelist([item]).reset_index(
).drop_duplicates(subset=['code', 'report_date']).sort_index())
# data["crawl_date"] = str(datetime.date.today())
try:
coll.insert_many(data, ordered=False)
except Exception as e:
if isinstance(e, MemoryError):
coll.insert_many(data, ordered=True)
elif isinstance(e, pymongo.bulk.BulkWriteError):
pass
else:
print('ALL READY IN DATABASE')
print('SUCCESSFULLY SAVE/UPDATE FINANCIAL DATA')
|
python
|
def QA_SU_save_financial_files():
"""本地存储financialdata
"""
download_financialzip()
coll = DATABASE.financial
coll.create_index(
[("code", ASCENDING), ("report_date", ASCENDING)], unique=True)
for item in os.listdir(download_path):
if item[0:4] != 'gpcw':
print(
"file ", item, " is not start with gpcw , seems not a financial file , ignore!")
continue
date = int(item.split('.')[0][-8:])
print('QUANTAXIS NOW SAVING {}'.format(date))
if coll.find({'report_date': date}).count() < 3600:
print(coll.find({'report_date': date}).count())
data = QA_util_to_json_from_pandas(parse_filelist([item]).reset_index(
).drop_duplicates(subset=['code', 'report_date']).sort_index())
# data["crawl_date"] = str(datetime.date.today())
try:
coll.insert_many(data, ordered=False)
except Exception as e:
if isinstance(e, MemoryError):
coll.insert_many(data, ordered=True)
elif isinstance(e, pymongo.bulk.BulkWriteError):
pass
else:
print('ALL READY IN DATABASE')
print('SUCCESSFULLY SAVE/UPDATE FINANCIAL DATA')
|
[
"def",
"QA_SU_save_financial_files",
"(",
")",
":",
"download_financialzip",
"(",
")",
"coll",
"=",
"DATABASE",
".",
"financial",
"coll",
".",
"create_index",
"(",
"[",
"(",
"\"code\"",
",",
"ASCENDING",
")",
",",
"(",
"\"report_date\"",
",",
"ASCENDING",
")",
"]",
",",
"unique",
"=",
"True",
")",
"for",
"item",
"in",
"os",
".",
"listdir",
"(",
"download_path",
")",
":",
"if",
"item",
"[",
"0",
":",
"4",
"]",
"!=",
"'gpcw'",
":",
"print",
"(",
"\"file \"",
",",
"item",
",",
"\" is not start with gpcw , seems not a financial file , ignore!\"",
")",
"continue",
"date",
"=",
"int",
"(",
"item",
".",
"split",
"(",
"'.'",
")",
"[",
"0",
"]",
"[",
"-",
"8",
":",
"]",
")",
"print",
"(",
"'QUANTAXIS NOW SAVING {}'",
".",
"format",
"(",
"date",
")",
")",
"if",
"coll",
".",
"find",
"(",
"{",
"'report_date'",
":",
"date",
"}",
")",
".",
"count",
"(",
")",
"<",
"3600",
":",
"print",
"(",
"coll",
".",
"find",
"(",
"{",
"'report_date'",
":",
"date",
"}",
")",
".",
"count",
"(",
")",
")",
"data",
"=",
"QA_util_to_json_from_pandas",
"(",
"parse_filelist",
"(",
"[",
"item",
"]",
")",
".",
"reset_index",
"(",
")",
".",
"drop_duplicates",
"(",
"subset",
"=",
"[",
"'code'",
",",
"'report_date'",
"]",
")",
".",
"sort_index",
"(",
")",
")",
"# data[\"crawl_date\"] = str(datetime.date.today())",
"try",
":",
"coll",
".",
"insert_many",
"(",
"data",
",",
"ordered",
"=",
"False",
")",
"except",
"Exception",
"as",
"e",
":",
"if",
"isinstance",
"(",
"e",
",",
"MemoryError",
")",
":",
"coll",
".",
"insert_many",
"(",
"data",
",",
"ordered",
"=",
"True",
")",
"elif",
"isinstance",
"(",
"e",
",",
"pymongo",
".",
"bulk",
".",
"BulkWriteError",
")",
":",
"pass",
"else",
":",
"print",
"(",
"'ALL READY IN DATABASE'",
")",
"print",
"(",
"'SUCCESSFULLY SAVE/UPDATE FINANCIAL DATA'",
")"
] |
本地存储financialdata
|
[
"本地存储financialdata"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QASU/save_financialfiles.py#L39-L71
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAUtil/QALogs.py
|
QA_util_log_info
|
def QA_util_log_info(
logs,
ui_log=None,
ui_progress=None,
ui_progress_int_value=None,
):
"""
QUANTAXIS Log Module
@yutiansut
QA_util_log_x is under [QAStandard#0.0.2@602-x] Protocol
"""
logging.warning(logs)
# 给GUI使用,更新当前任务到日志和进度
if ui_log is not None:
if isinstance(logs, str):
ui_log.emit(logs)
if isinstance(logs, list):
for iStr in logs:
ui_log.emit(iStr)
if ui_progress is not None and ui_progress_int_value is not None:
ui_progress.emit(ui_progress_int_value)
|
python
|
def QA_util_log_info(
logs,
ui_log=None,
ui_progress=None,
ui_progress_int_value=None,
):
"""
QUANTAXIS Log Module
@yutiansut
QA_util_log_x is under [QAStandard#0.0.2@602-x] Protocol
"""
logging.warning(logs)
# 给GUI使用,更新当前任务到日志和进度
if ui_log is not None:
if isinstance(logs, str):
ui_log.emit(logs)
if isinstance(logs, list):
for iStr in logs:
ui_log.emit(iStr)
if ui_progress is not None and ui_progress_int_value is not None:
ui_progress.emit(ui_progress_int_value)
|
[
"def",
"QA_util_log_info",
"(",
"logs",
",",
"ui_log",
"=",
"None",
",",
"ui_progress",
"=",
"None",
",",
"ui_progress_int_value",
"=",
"None",
",",
")",
":",
"logging",
".",
"warning",
"(",
"logs",
")",
"# 给GUI使用,更新当前任务到日志和进度",
"if",
"ui_log",
"is",
"not",
"None",
":",
"if",
"isinstance",
"(",
"logs",
",",
"str",
")",
":",
"ui_log",
".",
"emit",
"(",
"logs",
")",
"if",
"isinstance",
"(",
"logs",
",",
"list",
")",
":",
"for",
"iStr",
"in",
"logs",
":",
"ui_log",
".",
"emit",
"(",
"iStr",
")",
"if",
"ui_progress",
"is",
"not",
"None",
"and",
"ui_progress_int_value",
"is",
"not",
"None",
":",
"ui_progress",
".",
"emit",
"(",
"ui_progress_int_value",
")"
] |
QUANTAXIS Log Module
@yutiansut
QA_util_log_x is under [QAStandard#0.0.2@602-x] Protocol
|
[
"QUANTAXIS",
"Log",
"Module",
"@yutiansut"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAUtil/QALogs.py#L86-L109
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QASU/save_tdx_file.py
|
QA_save_tdx_to_mongo
|
def QA_save_tdx_to_mongo(file_dir, client=DATABASE):
"""save file
Arguments:
file_dir {str:direction} -- 文件的地址
Keyword Arguments:
client {Mongodb:Connection} -- Mongo Connection (default: {DATABASE})
"""
reader = TdxMinBarReader()
__coll = client.stock_min_five
for a, v, files in os.walk(file_dir):
for file in files:
if (str(file)[0:2] == 'sh' and int(str(file)[2]) == 6) or \
(str(file)[0:2] == 'sz' and int(str(file)[2]) == 0) or \
(str(file)[0:2] == 'sz' and int(str(file)[2]) == 3):
QA_util_log_info('Now_saving ' + str(file)
[2:8] + '\'s 5 min tick')
fname = file_dir + os.sep + file
df = reader.get_df(fname)
df['code'] = str(file)[2:8]
df['market'] = str(file)[0:2]
df['datetime'] = [str(x) for x in list(df.index)]
df['date'] = [str(x)[0:10] for x in list(df.index)]
df['time_stamp'] = df['datetime'].apply(
lambda x: QA_util_time_stamp(x))
df['date_stamp'] = df['date'].apply(
lambda x: QA_util_date_stamp(x))
data_json = json.loads(df.to_json(orient='records'))
__coll.insert_many(data_json)
|
python
|
def QA_save_tdx_to_mongo(file_dir, client=DATABASE):
"""save file
Arguments:
file_dir {str:direction} -- 文件的地址
Keyword Arguments:
client {Mongodb:Connection} -- Mongo Connection (default: {DATABASE})
"""
reader = TdxMinBarReader()
__coll = client.stock_min_five
for a, v, files in os.walk(file_dir):
for file in files:
if (str(file)[0:2] == 'sh' and int(str(file)[2]) == 6) or \
(str(file)[0:2] == 'sz' and int(str(file)[2]) == 0) or \
(str(file)[0:2] == 'sz' and int(str(file)[2]) == 3):
QA_util_log_info('Now_saving ' + str(file)
[2:8] + '\'s 5 min tick')
fname = file_dir + os.sep + file
df = reader.get_df(fname)
df['code'] = str(file)[2:8]
df['market'] = str(file)[0:2]
df['datetime'] = [str(x) for x in list(df.index)]
df['date'] = [str(x)[0:10] for x in list(df.index)]
df['time_stamp'] = df['datetime'].apply(
lambda x: QA_util_time_stamp(x))
df['date_stamp'] = df['date'].apply(
lambda x: QA_util_date_stamp(x))
data_json = json.loads(df.to_json(orient='records'))
__coll.insert_many(data_json)
|
[
"def",
"QA_save_tdx_to_mongo",
"(",
"file_dir",
",",
"client",
"=",
"DATABASE",
")",
":",
"reader",
"=",
"TdxMinBarReader",
"(",
")",
"__coll",
"=",
"client",
".",
"stock_min_five",
"for",
"a",
",",
"v",
",",
"files",
"in",
"os",
".",
"walk",
"(",
"file_dir",
")",
":",
"for",
"file",
"in",
"files",
":",
"if",
"(",
"str",
"(",
"file",
")",
"[",
"0",
":",
"2",
"]",
"==",
"'sh'",
"and",
"int",
"(",
"str",
"(",
"file",
")",
"[",
"2",
"]",
")",
"==",
"6",
")",
"or",
"(",
"str",
"(",
"file",
")",
"[",
"0",
":",
"2",
"]",
"==",
"'sz'",
"and",
"int",
"(",
"str",
"(",
"file",
")",
"[",
"2",
"]",
")",
"==",
"0",
")",
"or",
"(",
"str",
"(",
"file",
")",
"[",
"0",
":",
"2",
"]",
"==",
"'sz'",
"and",
"int",
"(",
"str",
"(",
"file",
")",
"[",
"2",
"]",
")",
"==",
"3",
")",
":",
"QA_util_log_info",
"(",
"'Now_saving '",
"+",
"str",
"(",
"file",
")",
"[",
"2",
":",
"8",
"]",
"+",
"'\\'s 5 min tick'",
")",
"fname",
"=",
"file_dir",
"+",
"os",
".",
"sep",
"+",
"file",
"df",
"=",
"reader",
".",
"get_df",
"(",
"fname",
")",
"df",
"[",
"'code'",
"]",
"=",
"str",
"(",
"file",
")",
"[",
"2",
":",
"8",
"]",
"df",
"[",
"'market'",
"]",
"=",
"str",
"(",
"file",
")",
"[",
"0",
":",
"2",
"]",
"df",
"[",
"'datetime'",
"]",
"=",
"[",
"str",
"(",
"x",
")",
"for",
"x",
"in",
"list",
"(",
"df",
".",
"index",
")",
"]",
"df",
"[",
"'date'",
"]",
"=",
"[",
"str",
"(",
"x",
")",
"[",
"0",
":",
"10",
"]",
"for",
"x",
"in",
"list",
"(",
"df",
".",
"index",
")",
"]",
"df",
"[",
"'time_stamp'",
"]",
"=",
"df",
"[",
"'datetime'",
"]",
".",
"apply",
"(",
"lambda",
"x",
":",
"QA_util_time_stamp",
"(",
"x",
")",
")",
"df",
"[",
"'date_stamp'",
"]",
"=",
"df",
"[",
"'date'",
"]",
".",
"apply",
"(",
"lambda",
"x",
":",
"QA_util_date_stamp",
"(",
"x",
")",
")",
"data_json",
"=",
"json",
".",
"loads",
"(",
"df",
".",
"to_json",
"(",
"orient",
"=",
"'records'",
")",
")",
"__coll",
".",
"insert_many",
"(",
"data_json",
")"
] |
save file
Arguments:
file_dir {str:direction} -- 文件的地址
Keyword Arguments:
client {Mongodb:Connection} -- Mongo Connection (default: {DATABASE})
|
[
"save",
"file",
"Arguments",
":",
"file_dir",
"{",
"str",
":",
"direction",
"}",
"--",
"文件的地址",
"Keyword",
"Arguments",
":",
"client",
"{",
"Mongodb",
":",
"Connection",
"}",
"--",
"Mongo",
"Connection",
"(",
"default",
":",
"{",
"DATABASE",
"}",
")"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QASU/save_tdx_file.py#L35-L68
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAUtil/QASetting.py
|
exclude_from_stock_ip_list
|
def exclude_from_stock_ip_list(exclude_ip_list):
""" 从stock_ip_list删除列表exclude_ip_list中的ip
从stock_ip_list删除列表future_ip_list中的ip
:param exclude_ip_list: 需要删除的ip_list
:return: None
"""
for exc in exclude_ip_list:
if exc in stock_ip_list:
stock_ip_list.remove(exc)
# 扩展市场
for exc in exclude_ip_list:
if exc in future_ip_list:
future_ip_list.remove(exc)
|
python
|
def exclude_from_stock_ip_list(exclude_ip_list):
""" 从stock_ip_list删除列表exclude_ip_list中的ip
从stock_ip_list删除列表future_ip_list中的ip
:param exclude_ip_list: 需要删除的ip_list
:return: None
"""
for exc in exclude_ip_list:
if exc in stock_ip_list:
stock_ip_list.remove(exc)
# 扩展市场
for exc in exclude_ip_list:
if exc in future_ip_list:
future_ip_list.remove(exc)
|
[
"def",
"exclude_from_stock_ip_list",
"(",
"exclude_ip_list",
")",
":",
"for",
"exc",
"in",
"exclude_ip_list",
":",
"if",
"exc",
"in",
"stock_ip_list",
":",
"stock_ip_list",
".",
"remove",
"(",
"exc",
")",
"# 扩展市场",
"for",
"exc",
"in",
"exclude_ip_list",
":",
"if",
"exc",
"in",
"future_ip_list",
":",
"future_ip_list",
".",
"remove",
"(",
"exc",
")"
] |
从stock_ip_list删除列表exclude_ip_list中的ip
从stock_ip_list删除列表future_ip_list中的ip
:param exclude_ip_list: 需要删除的ip_list
:return: None
|
[
"从stock_ip_list删除列表exclude_ip_list中的ip",
"从stock_ip_list删除列表future_ip_list中的ip"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAUtil/QASetting.py#L209-L223
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAUtil/QASetting.py
|
QA_Setting.get_config
|
def get_config(
self,
section='MONGODB',
option='uri',
default_value=DEFAULT_DB_URI
):
"""[summary]
Keyword Arguments:
section {str} -- [description] (default: {'MONGODB'})
option {str} -- [description] (default: {'uri'})
default_value {[type]} -- [description] (default: {DEFAULT_DB_URI})
Returns:
[type] -- [description]
"""
res = self.client.quantaxis.usersetting.find_one({'section': section})
if res:
return res.get(option, default_value)
else:
self.set_config(section, option, default_value)
return default_value
|
python
|
def get_config(
self,
section='MONGODB',
option='uri',
default_value=DEFAULT_DB_URI
):
"""[summary]
Keyword Arguments:
section {str} -- [description] (default: {'MONGODB'})
option {str} -- [description] (default: {'uri'})
default_value {[type]} -- [description] (default: {DEFAULT_DB_URI})
Returns:
[type] -- [description]
"""
res = self.client.quantaxis.usersetting.find_one({'section': section})
if res:
return res.get(option, default_value)
else:
self.set_config(section, option, default_value)
return default_value
|
[
"def",
"get_config",
"(",
"self",
",",
"section",
"=",
"'MONGODB'",
",",
"option",
"=",
"'uri'",
",",
"default_value",
"=",
"DEFAULT_DB_URI",
")",
":",
"res",
"=",
"self",
".",
"client",
".",
"quantaxis",
".",
"usersetting",
".",
"find_one",
"(",
"{",
"'section'",
":",
"section",
"}",
")",
"if",
"res",
":",
"return",
"res",
".",
"get",
"(",
"option",
",",
"default_value",
")",
"else",
":",
"self",
".",
"set_config",
"(",
"section",
",",
"option",
",",
"default_value",
")",
"return",
"default_value"
] |
[summary]
Keyword Arguments:
section {str} -- [description] (default: {'MONGODB'})
option {str} -- [description] (default: {'uri'})
default_value {[type]} -- [description] (default: {DEFAULT_DB_URI})
Returns:
[type] -- [description]
|
[
"[",
"summary",
"]"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAUtil/QASetting.py#L78-L101
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAUtil/QASetting.py
|
QA_Setting.set_config
|
def set_config(
self,
section='MONGODB',
option='uri',
default_value=DEFAULT_DB_URI
):
"""[summary]
Keyword Arguments:
section {str} -- [description] (default: {'MONGODB'})
option {str} -- [description] (default: {'uri'})
default_value {[type]} -- [description] (default: {DEFAULT_DB_URI})
Returns:
[type] -- [description]
"""
t = {'section': section, option: default_value}
self.client.quantaxis.usersetting.update(
{'section': section}, {'$set':t}, upsert=True)
|
python
|
def set_config(
self,
section='MONGODB',
option='uri',
default_value=DEFAULT_DB_URI
):
"""[summary]
Keyword Arguments:
section {str} -- [description] (default: {'MONGODB'})
option {str} -- [description] (default: {'uri'})
default_value {[type]} -- [description] (default: {DEFAULT_DB_URI})
Returns:
[type] -- [description]
"""
t = {'section': section, option: default_value}
self.client.quantaxis.usersetting.update(
{'section': section}, {'$set':t}, upsert=True)
|
[
"def",
"set_config",
"(",
"self",
",",
"section",
"=",
"'MONGODB'",
",",
"option",
"=",
"'uri'",
",",
"default_value",
"=",
"DEFAULT_DB_URI",
")",
":",
"t",
"=",
"{",
"'section'",
":",
"section",
",",
"option",
":",
"default_value",
"}",
"self",
".",
"client",
".",
"quantaxis",
".",
"usersetting",
".",
"update",
"(",
"{",
"'section'",
":",
"section",
"}",
",",
"{",
"'$set'",
":",
"t",
"}",
",",
"upsert",
"=",
"True",
")"
] |
[summary]
Keyword Arguments:
section {str} -- [description] (default: {'MONGODB'})
option {str} -- [description] (default: {'uri'})
default_value {[type]} -- [description] (default: {DEFAULT_DB_URI})
Returns:
[type] -- [description]
|
[
"[",
"summary",
"]"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAUtil/QASetting.py#L103-L121
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAUtil/QASetting.py
|
QA_Setting.get_or_set_section
|
def get_or_set_section(
self,
config,
section,
option,
DEFAULT_VALUE,
method='get'
):
"""[summary]
Arguments:
config {[type]} -- [description]
section {[type]} -- [description]
option {[type]} -- [description]
DEFAULT_VALUE {[type]} -- [description]
Keyword Arguments:
method {str} -- [description] (default: {'get'})
Returns:
[type] -- [description]
"""
try:
if isinstance(DEFAULT_VALUE, str):
val = DEFAULT_VALUE
else:
val = json.dumps(DEFAULT_VALUE)
if method == 'get':
return self.get_config(section, option)
else:
self.set_config(section, option, val)
return val
except:
self.set_config(section, option, val)
return val
|
python
|
def get_or_set_section(
self,
config,
section,
option,
DEFAULT_VALUE,
method='get'
):
"""[summary]
Arguments:
config {[type]} -- [description]
section {[type]} -- [description]
option {[type]} -- [description]
DEFAULT_VALUE {[type]} -- [description]
Keyword Arguments:
method {str} -- [description] (default: {'get'})
Returns:
[type] -- [description]
"""
try:
if isinstance(DEFAULT_VALUE, str):
val = DEFAULT_VALUE
else:
val = json.dumps(DEFAULT_VALUE)
if method == 'get':
return self.get_config(section, option)
else:
self.set_config(section, option, val)
return val
except:
self.set_config(section, option, val)
return val
|
[
"def",
"get_or_set_section",
"(",
"self",
",",
"config",
",",
"section",
",",
"option",
",",
"DEFAULT_VALUE",
",",
"method",
"=",
"'get'",
")",
":",
"try",
":",
"if",
"isinstance",
"(",
"DEFAULT_VALUE",
",",
"str",
")",
":",
"val",
"=",
"DEFAULT_VALUE",
"else",
":",
"val",
"=",
"json",
".",
"dumps",
"(",
"DEFAULT_VALUE",
")",
"if",
"method",
"==",
"'get'",
":",
"return",
"self",
".",
"get_config",
"(",
"section",
",",
"option",
")",
"else",
":",
"self",
".",
"set_config",
"(",
"section",
",",
"option",
",",
"val",
")",
"return",
"val",
"except",
":",
"self",
".",
"set_config",
"(",
"section",
",",
"option",
",",
"val",
")",
"return",
"val"
] |
[summary]
Arguments:
config {[type]} -- [description]
section {[type]} -- [description]
option {[type]} -- [description]
DEFAULT_VALUE {[type]} -- [description]
Keyword Arguments:
method {str} -- [description] (default: {'get'})
Returns:
[type] -- [description]
|
[
"[",
"summary",
"]"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAUtil/QASetting.py#L147-L183
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAUtil/QADate.py
|
QA_util_date_str2int
|
def QA_util_date_str2int(date):
"""
日期字符串 '2011-09-11' 变换成 整数 20110911
日期字符串 '2018-12-01' 变换成 整数 20181201
:param date: str日期字符串
:return: 类型int
"""
# return int(str(date)[0:4] + str(date)[5:7] + str(date)[8:10])
if isinstance(date, str):
return int(str().join(date.split('-')))
elif isinstance(date, int):
return date
|
python
|
def QA_util_date_str2int(date):
"""
日期字符串 '2011-09-11' 变换成 整数 20110911
日期字符串 '2018-12-01' 变换成 整数 20181201
:param date: str日期字符串
:return: 类型int
"""
# return int(str(date)[0:4] + str(date)[5:7] + str(date)[8:10])
if isinstance(date, str):
return int(str().join(date.split('-')))
elif isinstance(date, int):
return date
|
[
"def",
"QA_util_date_str2int",
"(",
"date",
")",
":",
"# return int(str(date)[0:4] + str(date)[5:7] + str(date)[8:10])",
"if",
"isinstance",
"(",
"date",
",",
"str",
")",
":",
"return",
"int",
"(",
"str",
"(",
")",
".",
"join",
"(",
"date",
".",
"split",
"(",
"'-'",
")",
")",
")",
"elif",
"isinstance",
"(",
"date",
",",
"int",
")",
":",
"return",
"date"
] |
日期字符串 '2011-09-11' 变换成 整数 20110911
日期字符串 '2018-12-01' 变换成 整数 20181201
:param date: str日期字符串
:return: 类型int
|
[
"日期字符串",
"2011",
"-",
"09",
"-",
"11",
"变换成",
"整数",
"20110911",
"日期字符串",
"2018",
"-",
"12",
"-",
"01",
"变换成",
"整数",
"20181201",
":",
"param",
"date",
":",
"str日期字符串",
":",
"return",
":",
"类型int"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAUtil/QADate.py#L60-L71
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAUtil/QADate.py
|
QA_util_date_int2str
|
def QA_util_date_int2str(int_date):
"""
类型datetime.datatime
:param date: int 8位整数
:return: 类型str
"""
date = str(int_date)
if len(date) == 8:
return str(date[0:4] + '-' + date[4:6] + '-' + date[6:8])
elif len(date) == 10:
return date
|
python
|
def QA_util_date_int2str(int_date):
"""
类型datetime.datatime
:param date: int 8位整数
:return: 类型str
"""
date = str(int_date)
if len(date) == 8:
return str(date[0:4] + '-' + date[4:6] + '-' + date[6:8])
elif len(date) == 10:
return date
|
[
"def",
"QA_util_date_int2str",
"(",
"int_date",
")",
":",
"date",
"=",
"str",
"(",
"int_date",
")",
"if",
"len",
"(",
"date",
")",
"==",
"8",
":",
"return",
"str",
"(",
"date",
"[",
"0",
":",
"4",
"]",
"+",
"'-'",
"+",
"date",
"[",
"4",
":",
"6",
"]",
"+",
"'-'",
"+",
"date",
"[",
"6",
":",
"8",
"]",
")",
"elif",
"len",
"(",
"date",
")",
"==",
"10",
":",
"return",
"date"
] |
类型datetime.datatime
:param date: int 8位整数
:return: 类型str
|
[
"类型datetime",
".",
"datatime",
":",
"param",
"date",
":",
"int",
"8位整数",
":",
"return",
":",
"类型str"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAUtil/QADate.py#L74-L84
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAUtil/QADate.py
|
QA_util_to_datetime
|
def QA_util_to_datetime(time):
"""
字符串 '2018-01-01' 转变成 datatime 类型
:param time: 字符串str -- 格式必须是 2018-01-01 ,长度10
:return: 类型datetime.datatime
"""
if len(str(time)) == 10:
_time = '{} 00:00:00'.format(time)
elif len(str(time)) == 19:
_time = str(time)
else:
QA_util_log_info('WRONG DATETIME FORMAT {}'.format(time))
return datetime.datetime.strptime(_time, '%Y-%m-%d %H:%M:%S')
|
python
|
def QA_util_to_datetime(time):
"""
字符串 '2018-01-01' 转变成 datatime 类型
:param time: 字符串str -- 格式必须是 2018-01-01 ,长度10
:return: 类型datetime.datatime
"""
if len(str(time)) == 10:
_time = '{} 00:00:00'.format(time)
elif len(str(time)) == 19:
_time = str(time)
else:
QA_util_log_info('WRONG DATETIME FORMAT {}'.format(time))
return datetime.datetime.strptime(_time, '%Y-%m-%d %H:%M:%S')
|
[
"def",
"QA_util_to_datetime",
"(",
"time",
")",
":",
"if",
"len",
"(",
"str",
"(",
"time",
")",
")",
"==",
"10",
":",
"_time",
"=",
"'{} 00:00:00'",
".",
"format",
"(",
"time",
")",
"elif",
"len",
"(",
"str",
"(",
"time",
")",
")",
"==",
"19",
":",
"_time",
"=",
"str",
"(",
"time",
")",
"else",
":",
"QA_util_log_info",
"(",
"'WRONG DATETIME FORMAT {}'",
".",
"format",
"(",
"time",
")",
")",
"return",
"datetime",
".",
"datetime",
".",
"strptime",
"(",
"_time",
",",
"'%Y-%m-%d %H:%M:%S'",
")"
] |
字符串 '2018-01-01' 转变成 datatime 类型
:param time: 字符串str -- 格式必须是 2018-01-01 ,长度10
:return: 类型datetime.datatime
|
[
"字符串",
"2018",
"-",
"01",
"-",
"01",
"转变成",
"datatime",
"类型",
":",
"param",
"time",
":",
"字符串str",
"--",
"格式必须是",
"2018",
"-",
"01",
"-",
"01",
",长度10",
":",
"return",
":",
"类型datetime",
".",
"datatime"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAUtil/QADate.py#L87-L99
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAUtil/QADate.py
|
QA_util_datetime_to_strdate
|
def QA_util_datetime_to_strdate(dt):
"""
:param dt: pythone datetime.datetime
:return: 1999-02-01 string type
"""
strdate = "%04d-%02d-%02d" % (dt.year, dt.month, dt.day)
return strdate
|
python
|
def QA_util_datetime_to_strdate(dt):
"""
:param dt: pythone datetime.datetime
:return: 1999-02-01 string type
"""
strdate = "%04d-%02d-%02d" % (dt.year, dt.month, dt.day)
return strdate
|
[
"def",
"QA_util_datetime_to_strdate",
"(",
"dt",
")",
":",
"strdate",
"=",
"\"%04d-%02d-%02d\"",
"%",
"(",
"dt",
".",
"year",
",",
"dt",
".",
"month",
",",
"dt",
".",
"day",
")",
"return",
"strdate"
] |
:param dt: pythone datetime.datetime
:return: 1999-02-01 string type
|
[
":",
"param",
"dt",
":",
"pythone",
"datetime",
".",
"datetime",
":",
"return",
":",
"1999",
"-",
"02",
"-",
"01",
"string",
"type"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAUtil/QADate.py#L102-L108
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAUtil/QADate.py
|
QA_util_datetime_to_strdatetime
|
def QA_util_datetime_to_strdatetime(dt):
"""
:param dt: pythone datetime.datetime
:return: 1999-02-01 09:30:91 string type
"""
strdatetime = "%04d-%02d-%02d %02d:%02d:%02d" % (
dt.year,
dt.month,
dt.day,
dt.hour,
dt.minute,
dt.second
)
return strdatetime
|
python
|
def QA_util_datetime_to_strdatetime(dt):
"""
:param dt: pythone datetime.datetime
:return: 1999-02-01 09:30:91 string type
"""
strdatetime = "%04d-%02d-%02d %02d:%02d:%02d" % (
dt.year,
dt.month,
dt.day,
dt.hour,
dt.minute,
dt.second
)
return strdatetime
|
[
"def",
"QA_util_datetime_to_strdatetime",
"(",
"dt",
")",
":",
"strdatetime",
"=",
"\"%04d-%02d-%02d %02d:%02d:%02d\"",
"%",
"(",
"dt",
".",
"year",
",",
"dt",
".",
"month",
",",
"dt",
".",
"day",
",",
"dt",
".",
"hour",
",",
"dt",
".",
"minute",
",",
"dt",
".",
"second",
")",
"return",
"strdatetime"
] |
:param dt: pythone datetime.datetime
:return: 1999-02-01 09:30:91 string type
|
[
":",
"param",
"dt",
":",
"pythone",
"datetime",
".",
"datetime",
":",
"return",
":",
"1999",
"-",
"02",
"-",
"01",
"09",
":",
"30",
":",
"91",
"string",
"type"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAUtil/QADate.py#L111-L124
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAUtil/QADate.py
|
QA_util_date_stamp
|
def QA_util_date_stamp(date):
"""
字符串 '2018-01-01' 转变成 float 类型时间 类似 time.time() 返回的类型
:param date: 字符串str -- 格式必须是 2018-01-01 ,长度10
:return: 类型float
"""
datestr = str(date)[0:10]
date = time.mktime(time.strptime(datestr, '%Y-%m-%d'))
return date
|
python
|
def QA_util_date_stamp(date):
"""
字符串 '2018-01-01' 转变成 float 类型时间 类似 time.time() 返回的类型
:param date: 字符串str -- 格式必须是 2018-01-01 ,长度10
:return: 类型float
"""
datestr = str(date)[0:10]
date = time.mktime(time.strptime(datestr, '%Y-%m-%d'))
return date
|
[
"def",
"QA_util_date_stamp",
"(",
"date",
")",
":",
"datestr",
"=",
"str",
"(",
"date",
")",
"[",
"0",
":",
"10",
"]",
"date",
"=",
"time",
".",
"mktime",
"(",
"time",
".",
"strptime",
"(",
"datestr",
",",
"'%Y-%m-%d'",
")",
")",
"return",
"date"
] |
字符串 '2018-01-01' 转变成 float 类型时间 类似 time.time() 返回的类型
:param date: 字符串str -- 格式必须是 2018-01-01 ,长度10
:return: 类型float
|
[
"字符串",
"2018",
"-",
"01",
"-",
"01",
"转变成",
"float",
"类型时间",
"类似",
"time",
".",
"time",
"()",
"返回的类型",
":",
"param",
"date",
":",
"字符串str",
"--",
"格式必须是",
"2018",
"-",
"01",
"-",
"01",
",长度10",
":",
"return",
":",
"类型float"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAUtil/QADate.py#L127-L135
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAUtil/QADate.py
|
QA_util_time_stamp
|
def QA_util_time_stamp(time_):
"""
字符串 '2018-01-01 00:00:00' 转变成 float 类型时间 类似 time.time() 返回的类型
:param time_: 字符串str -- 数据格式 最好是%Y-%m-%d %H:%M:%S 中间要有空格
:return: 类型float
"""
if len(str(time_)) == 10:
# yyyy-mm-dd格式
return time.mktime(time.strptime(time_, '%Y-%m-%d'))
elif len(str(time_)) == 16:
# yyyy-mm-dd hh:mm格式
return time.mktime(time.strptime(time_, '%Y-%m-%d %H:%M'))
else:
timestr = str(time_)[0:19]
return time.mktime(time.strptime(timestr, '%Y-%m-%d %H:%M:%S'))
|
python
|
def QA_util_time_stamp(time_):
"""
字符串 '2018-01-01 00:00:00' 转变成 float 类型时间 类似 time.time() 返回的类型
:param time_: 字符串str -- 数据格式 最好是%Y-%m-%d %H:%M:%S 中间要有空格
:return: 类型float
"""
if len(str(time_)) == 10:
# yyyy-mm-dd格式
return time.mktime(time.strptime(time_, '%Y-%m-%d'))
elif len(str(time_)) == 16:
# yyyy-mm-dd hh:mm格式
return time.mktime(time.strptime(time_, '%Y-%m-%d %H:%M'))
else:
timestr = str(time_)[0:19]
return time.mktime(time.strptime(timestr, '%Y-%m-%d %H:%M:%S'))
|
[
"def",
"QA_util_time_stamp",
"(",
"time_",
")",
":",
"if",
"len",
"(",
"str",
"(",
"time_",
")",
")",
"==",
"10",
":",
"# yyyy-mm-dd格式",
"return",
"time",
".",
"mktime",
"(",
"time",
".",
"strptime",
"(",
"time_",
",",
"'%Y-%m-%d'",
")",
")",
"elif",
"len",
"(",
"str",
"(",
"time_",
")",
")",
"==",
"16",
":",
"# yyyy-mm-dd hh:mm格式",
"return",
"time",
".",
"mktime",
"(",
"time",
".",
"strptime",
"(",
"time_",
",",
"'%Y-%m-%d %H:%M'",
")",
")",
"else",
":",
"timestr",
"=",
"str",
"(",
"time_",
")",
"[",
"0",
":",
"19",
"]",
"return",
"time",
".",
"mktime",
"(",
"time",
".",
"strptime",
"(",
"timestr",
",",
"'%Y-%m-%d %H:%M:%S'",
")",
")"
] |
字符串 '2018-01-01 00:00:00' 转变成 float 类型时间 类似 time.time() 返回的类型
:param time_: 字符串str -- 数据格式 最好是%Y-%m-%d %H:%M:%S 中间要有空格
:return: 类型float
|
[
"字符串",
"2018",
"-",
"01",
"-",
"01",
"00",
":",
"00",
":",
"00",
"转变成",
"float",
"类型时间",
"类似",
"time",
".",
"time",
"()",
"返回的类型",
":",
"param",
"time_",
":",
"字符串str",
"--",
"数据格式",
"最好是%Y",
"-",
"%m",
"-",
"%d",
"%H",
":",
"%M",
":",
"%S",
"中间要有空格",
":",
"return",
":",
"类型float"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAUtil/QADate.py#L138-L152
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAUtil/QADate.py
|
QA_util_stamp2datetime
|
def QA_util_stamp2datetime(timestamp):
"""
datestamp转datetime
pandas转出来的timestamp是13位整数 要/1000
It’s common for this to be restricted to years from 1970 through 2038.
从1970年开始的纳秒到当前的计数 转变成 float 类型时间 类似 time.time() 返回的类型
:param timestamp: long类型
:return: 类型float
"""
try:
return datetime.datetime.fromtimestamp(timestamp)
except Exception as e:
# it won't work ??
try:
return datetime.datetime.fromtimestamp(timestamp / 1000)
except:
try:
return datetime.datetime.fromtimestamp(timestamp / 1000000)
except:
return datetime.datetime.fromtimestamp(timestamp / 1000000000)
|
python
|
def QA_util_stamp2datetime(timestamp):
"""
datestamp转datetime
pandas转出来的timestamp是13位整数 要/1000
It’s common for this to be restricted to years from 1970 through 2038.
从1970年开始的纳秒到当前的计数 转变成 float 类型时间 类似 time.time() 返回的类型
:param timestamp: long类型
:return: 类型float
"""
try:
return datetime.datetime.fromtimestamp(timestamp)
except Exception as e:
# it won't work ??
try:
return datetime.datetime.fromtimestamp(timestamp / 1000)
except:
try:
return datetime.datetime.fromtimestamp(timestamp / 1000000)
except:
return datetime.datetime.fromtimestamp(timestamp / 1000000000)
|
[
"def",
"QA_util_stamp2datetime",
"(",
"timestamp",
")",
":",
"try",
":",
"return",
"datetime",
".",
"datetime",
".",
"fromtimestamp",
"(",
"timestamp",
")",
"except",
"Exception",
"as",
"e",
":",
"# it won't work ??",
"try",
":",
"return",
"datetime",
".",
"datetime",
".",
"fromtimestamp",
"(",
"timestamp",
"/",
"1000",
")",
"except",
":",
"try",
":",
"return",
"datetime",
".",
"datetime",
".",
"fromtimestamp",
"(",
"timestamp",
"/",
"1000000",
")",
"except",
":",
"return",
"datetime",
".",
"datetime",
".",
"fromtimestamp",
"(",
"timestamp",
"/",
"1000000000",
")"
] |
datestamp转datetime
pandas转出来的timestamp是13位整数 要/1000
It’s common for this to be restricted to years from 1970 through 2038.
从1970年开始的纳秒到当前的计数 转变成 float 类型时间 类似 time.time() 返回的类型
:param timestamp: long类型
:return: 类型float
|
[
"datestamp转datetime",
"pandas转出来的timestamp是13位整数",
"要",
"/",
"1000",
"It’s",
"common",
"for",
"this",
"to",
"be",
"restricted",
"to",
"years",
"from",
"1970",
"through",
"2038",
".",
"从1970年开始的纳秒到当前的计数",
"转变成",
"float",
"类型时间",
"类似",
"time",
".",
"time",
"()",
"返回的类型",
":",
"param",
"timestamp",
":",
"long类型",
":",
"return",
":",
"类型float"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAUtil/QADate.py#L173-L192
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAUtil/QADate.py
|
QA_util_realtime
|
def QA_util_realtime(strtime, client):
"""
查询数据库中的数据
:param strtime: strtime str字符串 -- 1999-12-11 这种格式
:param client: client pymongo.MongoClient类型 -- mongodb 数据库 从 QA_util_sql_mongo_setting 中 QA_util_sql_mongo_setting 获取
:return: Dictionary -- {'time_real': 时间,'id': id}
"""
time_stamp = QA_util_date_stamp(strtime)
coll = client.quantaxis.trade_date
temp_str = coll.find_one({'date_stamp': {"$gte": time_stamp}})
time_real = temp_str['date']
time_id = temp_str['num']
return {'time_real': time_real, 'id': time_id}
|
python
|
def QA_util_realtime(strtime, client):
"""
查询数据库中的数据
:param strtime: strtime str字符串 -- 1999-12-11 这种格式
:param client: client pymongo.MongoClient类型 -- mongodb 数据库 从 QA_util_sql_mongo_setting 中 QA_util_sql_mongo_setting 获取
:return: Dictionary -- {'time_real': 时间,'id': id}
"""
time_stamp = QA_util_date_stamp(strtime)
coll = client.quantaxis.trade_date
temp_str = coll.find_one({'date_stamp': {"$gte": time_stamp}})
time_real = temp_str['date']
time_id = temp_str['num']
return {'time_real': time_real, 'id': time_id}
|
[
"def",
"QA_util_realtime",
"(",
"strtime",
",",
"client",
")",
":",
"time_stamp",
"=",
"QA_util_date_stamp",
"(",
"strtime",
")",
"coll",
"=",
"client",
".",
"quantaxis",
".",
"trade_date",
"temp_str",
"=",
"coll",
".",
"find_one",
"(",
"{",
"'date_stamp'",
":",
"{",
"\"$gte\"",
":",
"time_stamp",
"}",
"}",
")",
"time_real",
"=",
"temp_str",
"[",
"'date'",
"]",
"time_id",
"=",
"temp_str",
"[",
"'num'",
"]",
"return",
"{",
"'time_real'",
":",
"time_real",
",",
"'id'",
":",
"time_id",
"}"
] |
查询数据库中的数据
:param strtime: strtime str字符串 -- 1999-12-11 这种格式
:param client: client pymongo.MongoClient类型 -- mongodb 数据库 从 QA_util_sql_mongo_setting 中 QA_util_sql_mongo_setting 获取
:return: Dictionary -- {'time_real': 时间,'id': id}
|
[
"查询数据库中的数据",
":",
"param",
"strtime",
":",
"strtime",
"str字符串",
"--",
"1999",
"-",
"12",
"-",
"11",
"这种格式",
":",
"param",
"client",
":",
"client",
"pymongo",
".",
"MongoClient类型",
"--",
"mongodb",
"数据库",
"从",
"QA_util_sql_mongo_setting",
"中",
"QA_util_sql_mongo_setting",
"获取",
":",
"return",
":",
"Dictionary",
"--",
"{",
"time_real",
":",
"时间",
"id",
":",
"id",
"}"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAUtil/QADate.py#L219-L231
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAUtil/QADate.py
|
QA_util_id2date
|
def QA_util_id2date(idx, client):
"""
从数据库中查询 通达信时间
:param idx: 字符串 -- 数据库index
:param client: pymongo.MongoClient类型 -- mongodb 数据库 从 QA_util_sql_mongo_setting 中 QA_util_sql_mongo_setting 获取
:return: Str -- 通达信数据库时间
"""
coll = client.quantaxis.trade_date
temp_str = coll.find_one({'num': idx})
return temp_str['date']
|
python
|
def QA_util_id2date(idx, client):
"""
从数据库中查询 通达信时间
:param idx: 字符串 -- 数据库index
:param client: pymongo.MongoClient类型 -- mongodb 数据库 从 QA_util_sql_mongo_setting 中 QA_util_sql_mongo_setting 获取
:return: Str -- 通达信数据库时间
"""
coll = client.quantaxis.trade_date
temp_str = coll.find_one({'num': idx})
return temp_str['date']
|
[
"def",
"QA_util_id2date",
"(",
"idx",
",",
"client",
")",
":",
"coll",
"=",
"client",
".",
"quantaxis",
".",
"trade_date",
"temp_str",
"=",
"coll",
".",
"find_one",
"(",
"{",
"'num'",
":",
"idx",
"}",
")",
"return",
"temp_str",
"[",
"'date'",
"]"
] |
从数据库中查询 通达信时间
:param idx: 字符串 -- 数据库index
:param client: pymongo.MongoClient类型 -- mongodb 数据库 从 QA_util_sql_mongo_setting 中 QA_util_sql_mongo_setting 获取
:return: Str -- 通达信数据库时间
|
[
"从数据库中查询",
"通达信时间",
":",
"param",
"idx",
":",
"字符串",
"--",
"数据库index",
":",
"param",
"client",
":",
"pymongo",
".",
"MongoClient类型",
"--",
"mongodb",
"数据库",
"从",
"QA_util_sql_mongo_setting",
"中",
"QA_util_sql_mongo_setting",
"获取",
":",
"return",
":",
"Str",
"--",
"通达信数据库时间"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAUtil/QADate.py#L234-L243
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAUtil/QADate.py
|
QA_util_is_trade
|
def QA_util_is_trade(date, code, client):
"""
判断是否是交易日
从数据库中查询
:param date: str类型 -- 1999-12-11 这种格式 10位字符串
:param code: str类型 -- 股票代码 例如 603658 , 6位字符串
:param client: pymongo.MongoClient类型 -- mongodb 数据库 从 QA_util_sql_mongo_setting 中 QA_util_sql_mongo_setting 获取
:return: Boolean -- 是否是交易时间
"""
coll = client.quantaxis.stock_day
date = str(date)[0:10]
is_trade = coll.find_one({'code': code, 'date': date})
try:
len(is_trade)
return True
except:
return False
|
python
|
def QA_util_is_trade(date, code, client):
"""
判断是否是交易日
从数据库中查询
:param date: str类型 -- 1999-12-11 这种格式 10位字符串
:param code: str类型 -- 股票代码 例如 603658 , 6位字符串
:param client: pymongo.MongoClient类型 -- mongodb 数据库 从 QA_util_sql_mongo_setting 中 QA_util_sql_mongo_setting 获取
:return: Boolean -- 是否是交易时间
"""
coll = client.quantaxis.stock_day
date = str(date)[0:10]
is_trade = coll.find_one({'code': code, 'date': date})
try:
len(is_trade)
return True
except:
return False
|
[
"def",
"QA_util_is_trade",
"(",
"date",
",",
"code",
",",
"client",
")",
":",
"coll",
"=",
"client",
".",
"quantaxis",
".",
"stock_day",
"date",
"=",
"str",
"(",
"date",
")",
"[",
"0",
":",
"10",
"]",
"is_trade",
"=",
"coll",
".",
"find_one",
"(",
"{",
"'code'",
":",
"code",
",",
"'date'",
":",
"date",
"}",
")",
"try",
":",
"len",
"(",
"is_trade",
")",
"return",
"True",
"except",
":",
"return",
"False"
] |
判断是否是交易日
从数据库中查询
:param date: str类型 -- 1999-12-11 这种格式 10位字符串
:param code: str类型 -- 股票代码 例如 603658 , 6位字符串
:param client: pymongo.MongoClient类型 -- mongodb 数据库 从 QA_util_sql_mongo_setting 中 QA_util_sql_mongo_setting 获取
:return: Boolean -- 是否是交易时间
|
[
"判断是否是交易日",
"从数据库中查询",
":",
"param",
"date",
":",
"str类型",
"--",
"1999",
"-",
"12",
"-",
"11",
"这种格式",
"10位字符串",
":",
"param",
"code",
":",
"str类型",
"--",
"股票代码",
"例如",
"603658",
",",
"6位字符串",
":",
"param",
"client",
":",
"pymongo",
".",
"MongoClient类型",
"--",
"mongodb",
"数据库",
"从",
"QA_util_sql_mongo_setting",
"中",
"QA_util_sql_mongo_setting",
"获取",
":",
"return",
":",
"Boolean",
"--",
"是否是交易时间"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAUtil/QADate.py#L246-L262
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAUtil/QADate.py
|
QA_util_select_hours
|
def QA_util_select_hours(time=None, gt=None, lt=None, gte=None, lte=None):
'quantaxis的时间选择函数,约定时间的范围,比如早上9点到11点'
if time is None:
__realtime = datetime.datetime.now()
else:
__realtime = time
fun_list = []
if gt != None:
fun_list.append('>')
if lt != None:
fun_list.append('<')
if gte != None:
fun_list.append('>=')
if lte != None:
fun_list.append('<=')
assert len(fun_list) > 0
true_list = []
try:
for item in fun_list:
if item == '>':
if __realtime.strftime('%H') > gt:
true_list.append(0)
else:
true_list.append(1)
elif item == '<':
if __realtime.strftime('%H') < lt:
true_list.append(0)
else:
true_list.append(1)
elif item == '>=':
if __realtime.strftime('%H') >= gte:
true_list.append(0)
else:
true_list.append(1)
elif item == '<=':
if __realtime.strftime('%H') <= lte:
true_list.append(0)
else:
true_list.append(1)
except:
return Exception
if sum(true_list) > 0:
return False
else:
return True
|
python
|
def QA_util_select_hours(time=None, gt=None, lt=None, gte=None, lte=None):
'quantaxis的时间选择函数,约定时间的范围,比如早上9点到11点'
if time is None:
__realtime = datetime.datetime.now()
else:
__realtime = time
fun_list = []
if gt != None:
fun_list.append('>')
if lt != None:
fun_list.append('<')
if gte != None:
fun_list.append('>=')
if lte != None:
fun_list.append('<=')
assert len(fun_list) > 0
true_list = []
try:
for item in fun_list:
if item == '>':
if __realtime.strftime('%H') > gt:
true_list.append(0)
else:
true_list.append(1)
elif item == '<':
if __realtime.strftime('%H') < lt:
true_list.append(0)
else:
true_list.append(1)
elif item == '>=':
if __realtime.strftime('%H') >= gte:
true_list.append(0)
else:
true_list.append(1)
elif item == '<=':
if __realtime.strftime('%H') <= lte:
true_list.append(0)
else:
true_list.append(1)
except:
return Exception
if sum(true_list) > 0:
return False
else:
return True
|
[
"def",
"QA_util_select_hours",
"(",
"time",
"=",
"None",
",",
"gt",
"=",
"None",
",",
"lt",
"=",
"None",
",",
"gte",
"=",
"None",
",",
"lte",
"=",
"None",
")",
":",
"if",
"time",
"is",
"None",
":",
"__realtime",
"=",
"datetime",
".",
"datetime",
".",
"now",
"(",
")",
"else",
":",
"__realtime",
"=",
"time",
"fun_list",
"=",
"[",
"]",
"if",
"gt",
"!=",
"None",
":",
"fun_list",
".",
"append",
"(",
"'>'",
")",
"if",
"lt",
"!=",
"None",
":",
"fun_list",
".",
"append",
"(",
"'<'",
")",
"if",
"gte",
"!=",
"None",
":",
"fun_list",
".",
"append",
"(",
"'>='",
")",
"if",
"lte",
"!=",
"None",
":",
"fun_list",
".",
"append",
"(",
"'<='",
")",
"assert",
"len",
"(",
"fun_list",
")",
">",
"0",
"true_list",
"=",
"[",
"]",
"try",
":",
"for",
"item",
"in",
"fun_list",
":",
"if",
"item",
"==",
"'>'",
":",
"if",
"__realtime",
".",
"strftime",
"(",
"'%H'",
")",
">",
"gt",
":",
"true_list",
".",
"append",
"(",
"0",
")",
"else",
":",
"true_list",
".",
"append",
"(",
"1",
")",
"elif",
"item",
"==",
"'<'",
":",
"if",
"__realtime",
".",
"strftime",
"(",
"'%H'",
")",
"<",
"lt",
":",
"true_list",
".",
"append",
"(",
"0",
")",
"else",
":",
"true_list",
".",
"append",
"(",
"1",
")",
"elif",
"item",
"==",
"'>='",
":",
"if",
"__realtime",
".",
"strftime",
"(",
"'%H'",
")",
">=",
"gte",
":",
"true_list",
".",
"append",
"(",
"0",
")",
"else",
":",
"true_list",
".",
"append",
"(",
"1",
")",
"elif",
"item",
"==",
"'<='",
":",
"if",
"__realtime",
".",
"strftime",
"(",
"'%H'",
")",
"<=",
"lte",
":",
"true_list",
".",
"append",
"(",
"0",
")",
"else",
":",
"true_list",
".",
"append",
"(",
"1",
")",
"except",
":",
"return",
"Exception",
"if",
"sum",
"(",
"true_list",
")",
">",
"0",
":",
"return",
"False",
"else",
":",
"return",
"True"
] |
quantaxis的时间选择函数,约定时间的范围,比如早上9点到11点
|
[
"quantaxis的时间选择函数",
"约定时间的范围",
"比如早上9点到11点"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAUtil/QADate.py#L284-L331
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAUtil/QADate.py
|
QA_util_calc_time
|
def QA_util_calc_time(func, *args, **kwargs):
"""
'耗时长度的装饰器'
:param func:
:param args:
:param kwargs:
:return:
"""
_time = datetime.datetime.now()
func(*args, **kwargs)
print(datetime.datetime.now() - _time)
|
python
|
def QA_util_calc_time(func, *args, **kwargs):
"""
'耗时长度的装饰器'
:param func:
:param args:
:param kwargs:
:return:
"""
_time = datetime.datetime.now()
func(*args, **kwargs)
print(datetime.datetime.now() - _time)
|
[
"def",
"QA_util_calc_time",
"(",
"func",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"_time",
"=",
"datetime",
".",
"datetime",
".",
"now",
"(",
")",
"func",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"print",
"(",
"datetime",
".",
"datetime",
".",
"now",
"(",
")",
"-",
"_time",
")"
] |
'耗时长度的装饰器'
:param func:
:param args:
:param kwargs:
:return:
|
[
"耗时长度的装饰器",
":",
"param",
"func",
":",
":",
"param",
"args",
":",
":",
"param",
"kwargs",
":",
":",
"return",
":"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAUtil/QADate.py#L407-L417
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAData/QADataStruct.py
|
QA_DataStruct_Stock_day.high_limit
|
def high_limit(self):
'涨停价'
return self.groupby(level=1).close.apply(lambda x: round((x.shift(1) + 0.0002)*1.1, 2)).sort_index()
|
python
|
def high_limit(self):
'涨停价'
return self.groupby(level=1).close.apply(lambda x: round((x.shift(1) + 0.0002)*1.1, 2)).sort_index()
|
[
"def",
"high_limit",
"(",
"self",
")",
":",
"return",
"self",
".",
"groupby",
"(",
"level",
"=",
"1",
")",
".",
"close",
".",
"apply",
"(",
"lambda",
"x",
":",
"round",
"(",
"(",
"x",
".",
"shift",
"(",
"1",
")",
"+",
"0.0002",
")",
"*",
"1.1",
",",
"2",
")",
")",
".",
"sort_index",
"(",
")"
] |
涨停价
|
[
"涨停价"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAData/QADataStruct.py#L121-L123
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAData/QADataStruct.py
|
QA_DataStruct_Stock_day.next_day_low_limit
|
def next_day_low_limit(self):
"明日跌停价"
return self.groupby(level=1).close.apply(lambda x: round((x + 0.0002)*0.9, 2)).sort_index()
|
python
|
def next_day_low_limit(self):
"明日跌停价"
return self.groupby(level=1).close.apply(lambda x: round((x + 0.0002)*0.9, 2)).sort_index()
|
[
"def",
"next_day_low_limit",
"(",
"self",
")",
":",
"return",
"self",
".",
"groupby",
"(",
"level",
"=",
"1",
")",
".",
"close",
".",
"apply",
"(",
"lambda",
"x",
":",
"round",
"(",
"(",
"x",
"+",
"0.0002",
")",
"*",
"0.9",
",",
"2",
")",
")",
".",
"sort_index",
"(",
")"
] |
明日跌停价
|
[
"明日跌停价"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAData/QADataStruct.py#L133-L135
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAData/QADataStruct.py
|
QA_DataStruct_Stock_transaction.get_medium_order
|
def get_medium_order(self, lower=200000, higher=1000000):
"""return medium
Keyword Arguments:
lower {[type]} -- [description] (default: {200000})
higher {[type]} -- [description] (default: {1000000})
Returns:
[type] -- [description]
"""
return self.data.query('amount>={}'.format(lower)).query('amount<={}'.format(higher))
|
python
|
def get_medium_order(self, lower=200000, higher=1000000):
"""return medium
Keyword Arguments:
lower {[type]} -- [description] (default: {200000})
higher {[type]} -- [description] (default: {1000000})
Returns:
[type] -- [description]
"""
return self.data.query('amount>={}'.format(lower)).query('amount<={}'.format(higher))
|
[
"def",
"get_medium_order",
"(",
"self",
",",
"lower",
"=",
"200000",
",",
"higher",
"=",
"1000000",
")",
":",
"return",
"self",
".",
"data",
".",
"query",
"(",
"'amount>={}'",
".",
"format",
"(",
"lower",
")",
")",
".",
"query",
"(",
"'amount<={}'",
".",
"format",
"(",
"higher",
")",
")"
] |
return medium
Keyword Arguments:
lower {[type]} -- [description] (default: {200000})
higher {[type]} -- [description] (default: {1000000})
Returns:
[type] -- [description]
|
[
"return",
"medium"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAData/QADataStruct.py#L767-L778
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAAnalysis/QAAnalysis_dataframe.py
|
shadow_calc
|
def shadow_calc(data):
"""计算上下影线
Arguments:
data {DataStruct.slice} -- 输入的是一个行情切片
Returns:
up_shadow {float} -- 上影线
down_shdow {float} -- 下影线
entity {float} -- 实体部分
date {str} -- 时间
code {str} -- 代码
"""
up_shadow = abs(data.high - (max(data.open, data.close)))
down_shadow = abs(data.low - (min(data.open, data.close)))
entity = abs(data.open - data.close)
towards = True if data.open < data.close else False
print('=' * 15)
print('up_shadow : {}'.format(up_shadow))
print('down_shadow : {}'.format(down_shadow))
print('entity: {}'.format(entity))
print('towards : {}'.format(towards))
return up_shadow, down_shadow, entity, data.date, data.code
|
python
|
def shadow_calc(data):
"""计算上下影线
Arguments:
data {DataStruct.slice} -- 输入的是一个行情切片
Returns:
up_shadow {float} -- 上影线
down_shdow {float} -- 下影线
entity {float} -- 实体部分
date {str} -- 时间
code {str} -- 代码
"""
up_shadow = abs(data.high - (max(data.open, data.close)))
down_shadow = abs(data.low - (min(data.open, data.close)))
entity = abs(data.open - data.close)
towards = True if data.open < data.close else False
print('=' * 15)
print('up_shadow : {}'.format(up_shadow))
print('down_shadow : {}'.format(down_shadow))
print('entity: {}'.format(entity))
print('towards : {}'.format(towards))
return up_shadow, down_shadow, entity, data.date, data.code
|
[
"def",
"shadow_calc",
"(",
"data",
")",
":",
"up_shadow",
"=",
"abs",
"(",
"data",
".",
"high",
"-",
"(",
"max",
"(",
"data",
".",
"open",
",",
"data",
".",
"close",
")",
")",
")",
"down_shadow",
"=",
"abs",
"(",
"data",
".",
"low",
"-",
"(",
"min",
"(",
"data",
".",
"open",
",",
"data",
".",
"close",
")",
")",
")",
"entity",
"=",
"abs",
"(",
"data",
".",
"open",
"-",
"data",
".",
"close",
")",
"towards",
"=",
"True",
"if",
"data",
".",
"open",
"<",
"data",
".",
"close",
"else",
"False",
"print",
"(",
"'='",
"*",
"15",
")",
"print",
"(",
"'up_shadow : {}'",
".",
"format",
"(",
"up_shadow",
")",
")",
"print",
"(",
"'down_shadow : {}'",
".",
"format",
"(",
"down_shadow",
")",
")",
"print",
"(",
"'entity: {}'",
".",
"format",
"(",
"entity",
")",
")",
"print",
"(",
"'towards : {}'",
".",
"format",
"(",
"towards",
")",
")",
"return",
"up_shadow",
",",
"down_shadow",
",",
"entity",
",",
"data",
".",
"date",
",",
"data",
".",
"code"
] |
计算上下影线
Arguments:
data {DataStruct.slice} -- 输入的是一个行情切片
Returns:
up_shadow {float} -- 上影线
down_shdow {float} -- 下影线
entity {float} -- 实体部分
date {str} -- 时间
code {str} -- 代码
|
[
"计算上下影线"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAAnalysis/QAAnalysis_dataframe.py#L202-L225
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAMarket/QASimulatedBroker.py
|
QA_SimulatedBroker.query_data
|
def query_data(self, code, start, end, frequence, market_type=None):
"""
标准格式是numpy
"""
try:
return self.fetcher[(market_type, frequence)](
code, start, end, frequence=frequence)
except:
pass
|
python
|
def query_data(self, code, start, end, frequence, market_type=None):
"""
标准格式是numpy
"""
try:
return self.fetcher[(market_type, frequence)](
code, start, end, frequence=frequence)
except:
pass
|
[
"def",
"query_data",
"(",
"self",
",",
"code",
",",
"start",
",",
"end",
",",
"frequence",
",",
"market_type",
"=",
"None",
")",
":",
"try",
":",
"return",
"self",
".",
"fetcher",
"[",
"(",
"market_type",
",",
"frequence",
")",
"]",
"(",
"code",
",",
"start",
",",
"end",
",",
"frequence",
"=",
"frequence",
")",
"except",
":",
"pass"
] |
标准格式是numpy
|
[
"标准格式是numpy"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAMarket/QASimulatedBroker.py#L76-L84
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QASU/save_gm.py
|
QA_SU_save_stock_min
|
def QA_SU_save_stock_min(client=DATABASE, ui_log=None, ui_progress=None):
"""
掘金实现方式
save current day's stock_min data
"""
# 导入掘金模块且进行登录
try:
from gm.api import set_token
from gm.api import history
# 请自行将掘金量化的 TOKEN 替换掉 GMTOKEN
set_token("9c5601171e97994686b47b5cbfe7b2fc8bb25b09")
except:
raise ModuleNotFoundError
# 股票代码格式化
code_list = list(
map(
lambda x: "SHSE." + x if x[0] == "6" else "SZSE." + x,
QA_fetch_get_stock_list().code.unique().tolist(),
))
coll = client.stock_min
coll.create_index([
("code", pymongo.ASCENDING),
("time_stamp", pymongo.ASCENDING),
("date_stamp", pymongo.ASCENDING),
])
err = []
def __transform_gm_to_qa(df, type_):
"""
将掘金数据转换为 qa 格式
"""
if df is None or len(df) == 0:
raise ValueError("没有掘金数据")
df = df.rename(columns={
"eob": "datetime",
"volume": "vol",
"symbol": "code"
}).drop(["bob", "frequency", "position", "pre_close"], axis=1)
df["code"] = df["code"].map(str).str.slice(5, )
df["datetime"] = pd.to_datetime(df["datetime"].map(str).str.slice(
0, 19))
df["date"] = df.datetime.map(str).str.slice(0, 10)
df = df.set_index("datetime", drop=False)
df["date_stamp"] = df["date"].apply(lambda x: QA_util_date_stamp(x))
df["time_stamp"] = (
df["datetime"].map(str).apply(lambda x: QA_util_time_stamp(x)))
df["type"] = type_
return df[[
"open",
"close",
"high",
"low",
"vol",
"amount",
"datetime",
"code",
"date",
"date_stamp",
"time_stamp",
"type",
]]
def __saving_work(code, coll):
QA_util_log_info(
"##JOB03 Now Saving STOCK_MIN ==== {}".format(code), ui_log=ui_log)
try:
for type_ in ["1min", "5min", "15min", "30min", "60min"]:
col_filter = {"code": str(code)[5:], "type": type_}
ref_ = coll.find(col_filter)
end_time = str(now_time())[0:19]
if coll.count_documents(col_filter) > 0:
start_time = ref_[coll.count_documents(
col_filter) - 1]["datetime"]
print(start_time)
QA_util_log_info(
"##JOB03.{} Now Saving {} from {} to {} == {}".format(
["1min",
"5min",
"15min",
"30min",
"60min"
].index(type_),
str(code)[5:],
start_time,
end_time,
type_,
),
ui_log=ui_log,
)
if start_time != end_time:
df = history(
symbol=code,
start_time=start_time,
end_time=end_time,
frequency=MIN_SEC[type_],
df=True
)
__data = __transform_gm_to_qa(df, type_)
if len(__data) > 1:
# print(QA_util_to_json_from_pandas(__data)[1::])
# print(__data)
coll.insert_many(
QA_util_to_json_from_pandas(__data)[1::])
else:
start_time = "2015-01-01 09:30:00"
QA_util_log_info(
"##JOB03.{} Now Saving {} from {} to {} == {}".format(
["1min",
"5min",
"15min",
"30min",
"60min"
].index(type_),
str(code)[5:],
start_time,
end_time,
type_,
),
ui_log=ui_log,
)
if start_time != end_time:
df = history(
symbol=code,
start_time=start_time,
end_time=end_time,
frequency=MIN_SEC[type_],
df=True
)
__data = __transform_gm_to_qa(df, type_)
if len(__data) > 1:
# print(__data)
coll.insert_many(
QA_util_to_json_from_pandas(__data)[1::])
# print(QA_util_to_json_from_pandas(__data)[1::])
except Exception as e:
QA_util_log_info(e, ui_log=ui_log)
err.append(code)
QA_util_log_info(err, ui_log=ui_log)
executor = ThreadPoolExecutor(max_workers=2)
res = {
executor.submit(__saving_work, code_list[i_], coll)
for i_ in range(len(code_list))
}
count = 0
for i_ in concurrent.futures.as_completed(res):
QA_util_log_info(
'The {} of Total {}'.format(count,
len(code_list)),
ui_log=ui_log
)
strProgress = "DOWNLOAD PROGRESS {} ".format(
str(float(count / len(code_list) * 100))[0:4] + "%")
intProgress = int(count / len(code_list) * 10000.0)
QA_util_log_info(
strProgress,
ui_log,
ui_progress=ui_progress,
ui_progress_int_value=intProgress
)
count = count + 1
if len(err) < 1:
QA_util_log_info("SUCCESS", ui_log=ui_log)
else:
QA_util_log_info(" ERROR CODE \n ", ui_log=ui_log)
QA_util_log_info(err, ui_log=ui_log)
|
python
|
def QA_SU_save_stock_min(client=DATABASE, ui_log=None, ui_progress=None):
"""
掘金实现方式
save current day's stock_min data
"""
# 导入掘金模块且进行登录
try:
from gm.api import set_token
from gm.api import history
# 请自行将掘金量化的 TOKEN 替换掉 GMTOKEN
set_token("9c5601171e97994686b47b5cbfe7b2fc8bb25b09")
except:
raise ModuleNotFoundError
# 股票代码格式化
code_list = list(
map(
lambda x: "SHSE." + x if x[0] == "6" else "SZSE." + x,
QA_fetch_get_stock_list().code.unique().tolist(),
))
coll = client.stock_min
coll.create_index([
("code", pymongo.ASCENDING),
("time_stamp", pymongo.ASCENDING),
("date_stamp", pymongo.ASCENDING),
])
err = []
def __transform_gm_to_qa(df, type_):
"""
将掘金数据转换为 qa 格式
"""
if df is None or len(df) == 0:
raise ValueError("没有掘金数据")
df = df.rename(columns={
"eob": "datetime",
"volume": "vol",
"symbol": "code"
}).drop(["bob", "frequency", "position", "pre_close"], axis=1)
df["code"] = df["code"].map(str).str.slice(5, )
df["datetime"] = pd.to_datetime(df["datetime"].map(str).str.slice(
0, 19))
df["date"] = df.datetime.map(str).str.slice(0, 10)
df = df.set_index("datetime", drop=False)
df["date_stamp"] = df["date"].apply(lambda x: QA_util_date_stamp(x))
df["time_stamp"] = (
df["datetime"].map(str).apply(lambda x: QA_util_time_stamp(x)))
df["type"] = type_
return df[[
"open",
"close",
"high",
"low",
"vol",
"amount",
"datetime",
"code",
"date",
"date_stamp",
"time_stamp",
"type",
]]
def __saving_work(code, coll):
QA_util_log_info(
"##JOB03 Now Saving STOCK_MIN ==== {}".format(code), ui_log=ui_log)
try:
for type_ in ["1min", "5min", "15min", "30min", "60min"]:
col_filter = {"code": str(code)[5:], "type": type_}
ref_ = coll.find(col_filter)
end_time = str(now_time())[0:19]
if coll.count_documents(col_filter) > 0:
start_time = ref_[coll.count_documents(
col_filter) - 1]["datetime"]
print(start_time)
QA_util_log_info(
"##JOB03.{} Now Saving {} from {} to {} == {}".format(
["1min",
"5min",
"15min",
"30min",
"60min"
].index(type_),
str(code)[5:],
start_time,
end_time,
type_,
),
ui_log=ui_log,
)
if start_time != end_time:
df = history(
symbol=code,
start_time=start_time,
end_time=end_time,
frequency=MIN_SEC[type_],
df=True
)
__data = __transform_gm_to_qa(df, type_)
if len(__data) > 1:
# print(QA_util_to_json_from_pandas(__data)[1::])
# print(__data)
coll.insert_many(
QA_util_to_json_from_pandas(__data)[1::])
else:
start_time = "2015-01-01 09:30:00"
QA_util_log_info(
"##JOB03.{} Now Saving {} from {} to {} == {}".format(
["1min",
"5min",
"15min",
"30min",
"60min"
].index(type_),
str(code)[5:],
start_time,
end_time,
type_,
),
ui_log=ui_log,
)
if start_time != end_time:
df = history(
symbol=code,
start_time=start_time,
end_time=end_time,
frequency=MIN_SEC[type_],
df=True
)
__data = __transform_gm_to_qa(df, type_)
if len(__data) > 1:
# print(__data)
coll.insert_many(
QA_util_to_json_from_pandas(__data)[1::])
# print(QA_util_to_json_from_pandas(__data)[1::])
except Exception as e:
QA_util_log_info(e, ui_log=ui_log)
err.append(code)
QA_util_log_info(err, ui_log=ui_log)
executor = ThreadPoolExecutor(max_workers=2)
res = {
executor.submit(__saving_work, code_list[i_], coll)
for i_ in range(len(code_list))
}
count = 0
for i_ in concurrent.futures.as_completed(res):
QA_util_log_info(
'The {} of Total {}'.format(count,
len(code_list)),
ui_log=ui_log
)
strProgress = "DOWNLOAD PROGRESS {} ".format(
str(float(count / len(code_list) * 100))[0:4] + "%")
intProgress = int(count / len(code_list) * 10000.0)
QA_util_log_info(
strProgress,
ui_log,
ui_progress=ui_progress,
ui_progress_int_value=intProgress
)
count = count + 1
if len(err) < 1:
QA_util_log_info("SUCCESS", ui_log=ui_log)
else:
QA_util_log_info(" ERROR CODE \n ", ui_log=ui_log)
QA_util_log_info(err, ui_log=ui_log)
|
[
"def",
"QA_SU_save_stock_min",
"(",
"client",
"=",
"DATABASE",
",",
"ui_log",
"=",
"None",
",",
"ui_progress",
"=",
"None",
")",
":",
"# 导入掘金模块且进行登录",
"try",
":",
"from",
"gm",
".",
"api",
"import",
"set_token",
"from",
"gm",
".",
"api",
"import",
"history",
"# 请自行将掘金量化的 TOKEN 替换掉 GMTOKEN",
"set_token",
"(",
"\"9c5601171e97994686b47b5cbfe7b2fc8bb25b09\"",
")",
"except",
":",
"raise",
"ModuleNotFoundError",
"# 股票代码格式化",
"code_list",
"=",
"list",
"(",
"map",
"(",
"lambda",
"x",
":",
"\"SHSE.\"",
"+",
"x",
"if",
"x",
"[",
"0",
"]",
"==",
"\"6\"",
"else",
"\"SZSE.\"",
"+",
"x",
",",
"QA_fetch_get_stock_list",
"(",
")",
".",
"code",
".",
"unique",
"(",
")",
".",
"tolist",
"(",
")",
",",
")",
")",
"coll",
"=",
"client",
".",
"stock_min",
"coll",
".",
"create_index",
"(",
"[",
"(",
"\"code\"",
",",
"pymongo",
".",
"ASCENDING",
")",
",",
"(",
"\"time_stamp\"",
",",
"pymongo",
".",
"ASCENDING",
")",
",",
"(",
"\"date_stamp\"",
",",
"pymongo",
".",
"ASCENDING",
")",
",",
"]",
")",
"err",
"=",
"[",
"]",
"def",
"__transform_gm_to_qa",
"(",
"df",
",",
"type_",
")",
":",
"\"\"\"\n 将掘金数据转换为 qa 格式\n \"\"\"",
"if",
"df",
"is",
"None",
"or",
"len",
"(",
"df",
")",
"==",
"0",
":",
"raise",
"ValueError",
"(",
"\"没有掘金数据\")",
"",
"df",
"=",
"df",
".",
"rename",
"(",
"columns",
"=",
"{",
"\"eob\"",
":",
"\"datetime\"",
",",
"\"volume\"",
":",
"\"vol\"",
",",
"\"symbol\"",
":",
"\"code\"",
"}",
")",
".",
"drop",
"(",
"[",
"\"bob\"",
",",
"\"frequency\"",
",",
"\"position\"",
",",
"\"pre_close\"",
"]",
",",
"axis",
"=",
"1",
")",
"df",
"[",
"\"code\"",
"]",
"=",
"df",
"[",
"\"code\"",
"]",
".",
"map",
"(",
"str",
")",
".",
"str",
".",
"slice",
"(",
"5",
",",
")",
"df",
"[",
"\"datetime\"",
"]",
"=",
"pd",
".",
"to_datetime",
"(",
"df",
"[",
"\"datetime\"",
"]",
".",
"map",
"(",
"str",
")",
".",
"str",
".",
"slice",
"(",
"0",
",",
"19",
")",
")",
"df",
"[",
"\"date\"",
"]",
"=",
"df",
".",
"datetime",
".",
"map",
"(",
"str",
")",
".",
"str",
".",
"slice",
"(",
"0",
",",
"10",
")",
"df",
"=",
"df",
".",
"set_index",
"(",
"\"datetime\"",
",",
"drop",
"=",
"False",
")",
"df",
"[",
"\"date_stamp\"",
"]",
"=",
"df",
"[",
"\"date\"",
"]",
".",
"apply",
"(",
"lambda",
"x",
":",
"QA_util_date_stamp",
"(",
"x",
")",
")",
"df",
"[",
"\"time_stamp\"",
"]",
"=",
"(",
"df",
"[",
"\"datetime\"",
"]",
".",
"map",
"(",
"str",
")",
".",
"apply",
"(",
"lambda",
"x",
":",
"QA_util_time_stamp",
"(",
"x",
")",
")",
")",
"df",
"[",
"\"type\"",
"]",
"=",
"type_",
"return",
"df",
"[",
"[",
"\"open\"",
",",
"\"close\"",
",",
"\"high\"",
",",
"\"low\"",
",",
"\"vol\"",
",",
"\"amount\"",
",",
"\"datetime\"",
",",
"\"code\"",
",",
"\"date\"",
",",
"\"date_stamp\"",
",",
"\"time_stamp\"",
",",
"\"type\"",
",",
"]",
"]",
"def",
"__saving_work",
"(",
"code",
",",
"coll",
")",
":",
"QA_util_log_info",
"(",
"\"##JOB03 Now Saving STOCK_MIN ==== {}\"",
".",
"format",
"(",
"code",
")",
",",
"ui_log",
"=",
"ui_log",
")",
"try",
":",
"for",
"type_",
"in",
"[",
"\"1min\"",
",",
"\"5min\"",
",",
"\"15min\"",
",",
"\"30min\"",
",",
"\"60min\"",
"]",
":",
"col_filter",
"=",
"{",
"\"code\"",
":",
"str",
"(",
"code",
")",
"[",
"5",
":",
"]",
",",
"\"type\"",
":",
"type_",
"}",
"ref_",
"=",
"coll",
".",
"find",
"(",
"col_filter",
")",
"end_time",
"=",
"str",
"(",
"now_time",
"(",
")",
")",
"[",
"0",
":",
"19",
"]",
"if",
"coll",
".",
"count_documents",
"(",
"col_filter",
")",
">",
"0",
":",
"start_time",
"=",
"ref_",
"[",
"coll",
".",
"count_documents",
"(",
"col_filter",
")",
"-",
"1",
"]",
"[",
"\"datetime\"",
"]",
"print",
"(",
"start_time",
")",
"QA_util_log_info",
"(",
"\"##JOB03.{} Now Saving {} from {} to {} == {}\"",
".",
"format",
"(",
"[",
"\"1min\"",
",",
"\"5min\"",
",",
"\"15min\"",
",",
"\"30min\"",
",",
"\"60min\"",
"]",
".",
"index",
"(",
"type_",
")",
",",
"str",
"(",
"code",
")",
"[",
"5",
":",
"]",
",",
"start_time",
",",
"end_time",
",",
"type_",
",",
")",
",",
"ui_log",
"=",
"ui_log",
",",
")",
"if",
"start_time",
"!=",
"end_time",
":",
"df",
"=",
"history",
"(",
"symbol",
"=",
"code",
",",
"start_time",
"=",
"start_time",
",",
"end_time",
"=",
"end_time",
",",
"frequency",
"=",
"MIN_SEC",
"[",
"type_",
"]",
",",
"df",
"=",
"True",
")",
"__data",
"=",
"__transform_gm_to_qa",
"(",
"df",
",",
"type_",
")",
"if",
"len",
"(",
"__data",
")",
">",
"1",
":",
"# print(QA_util_to_json_from_pandas(__data)[1::])",
"# print(__data)",
"coll",
".",
"insert_many",
"(",
"QA_util_to_json_from_pandas",
"(",
"__data",
")",
"[",
"1",
":",
":",
"]",
")",
"else",
":",
"start_time",
"=",
"\"2015-01-01 09:30:00\"",
"QA_util_log_info",
"(",
"\"##JOB03.{} Now Saving {} from {} to {} == {}\"",
".",
"format",
"(",
"[",
"\"1min\"",
",",
"\"5min\"",
",",
"\"15min\"",
",",
"\"30min\"",
",",
"\"60min\"",
"]",
".",
"index",
"(",
"type_",
")",
",",
"str",
"(",
"code",
")",
"[",
"5",
":",
"]",
",",
"start_time",
",",
"end_time",
",",
"type_",
",",
")",
",",
"ui_log",
"=",
"ui_log",
",",
")",
"if",
"start_time",
"!=",
"end_time",
":",
"df",
"=",
"history",
"(",
"symbol",
"=",
"code",
",",
"start_time",
"=",
"start_time",
",",
"end_time",
"=",
"end_time",
",",
"frequency",
"=",
"MIN_SEC",
"[",
"type_",
"]",
",",
"df",
"=",
"True",
")",
"__data",
"=",
"__transform_gm_to_qa",
"(",
"df",
",",
"type_",
")",
"if",
"len",
"(",
"__data",
")",
">",
"1",
":",
"# print(__data)",
"coll",
".",
"insert_many",
"(",
"QA_util_to_json_from_pandas",
"(",
"__data",
")",
"[",
"1",
":",
":",
"]",
")",
"# print(QA_util_to_json_from_pandas(__data)[1::])",
"except",
"Exception",
"as",
"e",
":",
"QA_util_log_info",
"(",
"e",
",",
"ui_log",
"=",
"ui_log",
")",
"err",
".",
"append",
"(",
"code",
")",
"QA_util_log_info",
"(",
"err",
",",
"ui_log",
"=",
"ui_log",
")",
"executor",
"=",
"ThreadPoolExecutor",
"(",
"max_workers",
"=",
"2",
")",
"res",
"=",
"{",
"executor",
".",
"submit",
"(",
"__saving_work",
",",
"code_list",
"[",
"i_",
"]",
",",
"coll",
")",
"for",
"i_",
"in",
"range",
"(",
"len",
"(",
"code_list",
")",
")",
"}",
"count",
"=",
"0",
"for",
"i_",
"in",
"concurrent",
".",
"futures",
".",
"as_completed",
"(",
"res",
")",
":",
"QA_util_log_info",
"(",
"'The {} of Total {}'",
".",
"format",
"(",
"count",
",",
"len",
"(",
"code_list",
")",
")",
",",
"ui_log",
"=",
"ui_log",
")",
"strProgress",
"=",
"\"DOWNLOAD PROGRESS {} \"",
".",
"format",
"(",
"str",
"(",
"float",
"(",
"count",
"/",
"len",
"(",
"code_list",
")",
"*",
"100",
")",
")",
"[",
"0",
":",
"4",
"]",
"+",
"\"%\"",
")",
"intProgress",
"=",
"int",
"(",
"count",
"/",
"len",
"(",
"code_list",
")",
"*",
"10000.0",
")",
"QA_util_log_info",
"(",
"strProgress",
",",
"ui_log",
",",
"ui_progress",
"=",
"ui_progress",
",",
"ui_progress_int_value",
"=",
"intProgress",
")",
"count",
"=",
"count",
"+",
"1",
"if",
"len",
"(",
"err",
")",
"<",
"1",
":",
"QA_util_log_info",
"(",
"\"SUCCESS\"",
",",
"ui_log",
"=",
"ui_log",
")",
"else",
":",
"QA_util_log_info",
"(",
"\" ERROR CODE \\n \"",
",",
"ui_log",
"=",
"ui_log",
")",
"QA_util_log_info",
"(",
"err",
",",
"ui_log",
"=",
"ui_log",
")"
] |
掘金实现方式
save current day's stock_min data
|
[
"掘金实现方式",
"save",
"current",
"day",
"s",
"stock_min",
"data"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QASU/save_gm.py#L36-L206
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAData/base_datastruct.py
|
_quotation_base.datetime
|
def datetime(self):
'分钟线结构返回datetime 日线结构返回date'
index = self.data.index.remove_unused_levels()
return pd.to_datetime(index.levels[0])
|
python
|
def datetime(self):
'分钟线结构返回datetime 日线结构返回date'
index = self.data.index.remove_unused_levels()
return pd.to_datetime(index.levels[0])
|
[
"def",
"datetime",
"(",
"self",
")",
":",
"index",
"=",
"self",
".",
"data",
".",
"index",
".",
"remove_unused_levels",
"(",
")",
"return",
"pd",
".",
"to_datetime",
"(",
"index",
".",
"levels",
"[",
"0",
"]",
")"
] |
分钟线结构返回datetime 日线结构返回date
|
[
"分钟线结构返回datetime",
"日线结构返回date"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAData/base_datastruct.py#L391-L394
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAData/base_datastruct.py
|
_quotation_base.price_diff
|
def price_diff(self):
'返回DataStruct.price的一阶差分'
res = self.price.groupby(level=1).apply(lambda x: x.diff(1))
res.name = 'price_diff'
return res
|
python
|
def price_diff(self):
'返回DataStruct.price的一阶差分'
res = self.price.groupby(level=1).apply(lambda x: x.diff(1))
res.name = 'price_diff'
return res
|
[
"def",
"price_diff",
"(",
"self",
")",
":",
"res",
"=",
"self",
".",
"price",
".",
"groupby",
"(",
"level",
"=",
"1",
")",
".",
"apply",
"(",
"lambda",
"x",
":",
"x",
".",
"diff",
"(",
"1",
")",
")",
"res",
".",
"name",
"=",
"'price_diff'",
"return",
"res"
] |
返回DataStruct.price的一阶差分
|
[
"返回DataStruct",
".",
"price的一阶差分"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAData/base_datastruct.py#L447-L451
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAData/base_datastruct.py
|
_quotation_base.pvariance
|
def pvariance(self):
'返回DataStruct.price的方差 variance'
res = self.price.groupby(level=1
).apply(lambda x: statistics.pvariance(x))
res.name = 'pvariance'
return res
|
python
|
def pvariance(self):
'返回DataStruct.price的方差 variance'
res = self.price.groupby(level=1
).apply(lambda x: statistics.pvariance(x))
res.name = 'pvariance'
return res
|
[
"def",
"pvariance",
"(",
"self",
")",
":",
"res",
"=",
"self",
".",
"price",
".",
"groupby",
"(",
"level",
"=",
"1",
")",
".",
"apply",
"(",
"lambda",
"x",
":",
"statistics",
".",
"pvariance",
"(",
"x",
")",
")",
"res",
".",
"name",
"=",
"'pvariance'",
"return",
"res"
] |
返回DataStruct.price的方差 variance
|
[
"返回DataStruct",
".",
"price的方差",
"variance"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAData/base_datastruct.py#L457-L462
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAData/base_datastruct.py
|
_quotation_base.bar_pct_change
|
def bar_pct_change(self):
'返回bar的涨跌幅'
res = (self.close - self.open) / self.open
res.name = 'bar_pct_change'
return res
|
python
|
def bar_pct_change(self):
'返回bar的涨跌幅'
res = (self.close - self.open) / self.open
res.name = 'bar_pct_change'
return res
|
[
"def",
"bar_pct_change",
"(",
"self",
")",
":",
"res",
"=",
"(",
"self",
".",
"close",
"-",
"self",
".",
"open",
")",
"/",
"self",
".",
"open",
"res",
".",
"name",
"=",
"'bar_pct_change'",
"return",
"res"
] |
返回bar的涨跌幅
|
[
"返回bar的涨跌幅"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAData/base_datastruct.py#L478-L482
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAData/base_datastruct.py
|
_quotation_base.bar_amplitude
|
def bar_amplitude(self):
"返回bar振幅"
res = (self.high - self.low) / self.low
res.name = 'bar_amplitude'
return res
|
python
|
def bar_amplitude(self):
"返回bar振幅"
res = (self.high - self.low) / self.low
res.name = 'bar_amplitude'
return res
|
[
"def",
"bar_amplitude",
"(",
"self",
")",
":",
"res",
"=",
"(",
"self",
".",
"high",
"-",
"self",
".",
"low",
")",
"/",
"self",
".",
"low",
"res",
".",
"name",
"=",
"'bar_amplitude'",
"return",
"res"
] |
返回bar振幅
|
[
"返回bar振幅"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAData/base_datastruct.py#L486-L490
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAData/base_datastruct.py
|
_quotation_base.mean_harmonic
|
def mean_harmonic(self):
'返回DataStruct.price的调和平均数'
res = self.price.groupby(level=1
).apply(lambda x: statistics.harmonic_mean(x))
res.name = 'mean_harmonic'
return res
|
python
|
def mean_harmonic(self):
'返回DataStruct.price的调和平均数'
res = self.price.groupby(level=1
).apply(lambda x: statistics.harmonic_mean(x))
res.name = 'mean_harmonic'
return res
|
[
"def",
"mean_harmonic",
"(",
"self",
")",
":",
"res",
"=",
"self",
".",
"price",
".",
"groupby",
"(",
"level",
"=",
"1",
")",
".",
"apply",
"(",
"lambda",
"x",
":",
"statistics",
".",
"harmonic_mean",
"(",
"x",
")",
")",
"res",
".",
"name",
"=",
"'mean_harmonic'",
"return",
"res"
] |
返回DataStruct.price的调和平均数
|
[
"返回DataStruct",
".",
"price的调和平均数"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAData/base_datastruct.py#L513-L518
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAData/base_datastruct.py
|
_quotation_base.amplitude
|
def amplitude(self):
'返回DataStruct.price的百分比变化'
res = self.price.groupby(
level=1
).apply(lambda x: (x.max() - x.min()) / x.min())
res.name = 'amplitude'
return res
|
python
|
def amplitude(self):
'返回DataStruct.price的百分比变化'
res = self.price.groupby(
level=1
).apply(lambda x: (x.max() - x.min()) / x.min())
res.name = 'amplitude'
return res
|
[
"def",
"amplitude",
"(",
"self",
")",
":",
"res",
"=",
"self",
".",
"price",
".",
"groupby",
"(",
"level",
"=",
"1",
")",
".",
"apply",
"(",
"lambda",
"x",
":",
"(",
"x",
".",
"max",
"(",
")",
"-",
"x",
".",
"min",
"(",
")",
")",
"/",
"x",
".",
"min",
"(",
")",
")",
"res",
".",
"name",
"=",
"'amplitude'",
"return",
"res"
] |
返回DataStruct.price的百分比变化
|
[
"返回DataStruct",
".",
"price的百分比变化"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAData/base_datastruct.py#L536-L542
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAData/base_datastruct.py
|
_quotation_base.close_pct_change
|
def close_pct_change(self):
'返回DataStruct.close的百分比变化'
res = self.close.groupby(level=1).apply(lambda x: x.pct_change())
res.name = 'close_pct_change'
return res
|
python
|
def close_pct_change(self):
'返回DataStruct.close的百分比变化'
res = self.close.groupby(level=1).apply(lambda x: x.pct_change())
res.name = 'close_pct_change'
return res
|
[
"def",
"close_pct_change",
"(",
"self",
")",
":",
"res",
"=",
"self",
".",
"close",
".",
"groupby",
"(",
"level",
"=",
"1",
")",
".",
"apply",
"(",
"lambda",
"x",
":",
"x",
".",
"pct_change",
"(",
")",
")",
"res",
".",
"name",
"=",
"'close_pct_change'",
"return",
"res"
] |
返回DataStruct.close的百分比变化
|
[
"返回DataStruct",
".",
"close的百分比变化"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAData/base_datastruct.py#L575-L579
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAData/base_datastruct.py
|
_quotation_base.normalized
|
def normalized(self):
'归一化'
res = self.groupby('code').apply(lambda x: x / x.iloc[0])
return res
|
python
|
def normalized(self):
'归一化'
res = self.groupby('code').apply(lambda x: x / x.iloc[0])
return res
|
[
"def",
"normalized",
"(",
"self",
")",
":",
"res",
"=",
"self",
".",
"groupby",
"(",
"'code'",
")",
".",
"apply",
"(",
"lambda",
"x",
":",
"x",
"/",
"x",
".",
"iloc",
"[",
"0",
"]",
")",
"return",
"res"
] |
归一化
|
[
"归一化"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAData/base_datastruct.py#L593-L596
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAData/base_datastruct.py
|
_quotation_base.security_gen
|
def security_gen(self):
'返回一个基于代码的迭代器'
for item in self.index.levels[1]:
yield self.new(
self.data.xs(item,
level=1,
drop_level=False),
dtype=self.type,
if_fq=self.if_fq
)
|
python
|
def security_gen(self):
'返回一个基于代码的迭代器'
for item in self.index.levels[1]:
yield self.new(
self.data.xs(item,
level=1,
drop_level=False),
dtype=self.type,
if_fq=self.if_fq
)
|
[
"def",
"security_gen",
"(",
"self",
")",
":",
"for",
"item",
"in",
"self",
".",
"index",
".",
"levels",
"[",
"1",
"]",
":",
"yield",
"self",
".",
"new",
"(",
"self",
".",
"data",
".",
"xs",
"(",
"item",
",",
"level",
"=",
"1",
",",
"drop_level",
"=",
"False",
")",
",",
"dtype",
"=",
"self",
".",
"type",
",",
"if_fq",
"=",
"self",
".",
"if_fq",
")"
] |
返回一个基于代码的迭代器
|
[
"返回一个基于代码的迭代器"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAData/base_datastruct.py#L618-L627
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAData/base_datastruct.py
|
_quotation_base.get_dict
|
def get_dict(self, time, code):
'''
'give the time,code tuple and turn the dict'
:param time:
:param code:
:return: 字典dict 类型
'''
try:
return self.dicts[(QA_util_to_datetime(time), str(code))]
except Exception as e:
raise e
|
python
|
def get_dict(self, time, code):
'''
'give the time,code tuple and turn the dict'
:param time:
:param code:
:return: 字典dict 类型
'''
try:
return self.dicts[(QA_util_to_datetime(time), str(code))]
except Exception as e:
raise e
|
[
"def",
"get_dict",
"(",
"self",
",",
"time",
",",
"code",
")",
":",
"try",
":",
"return",
"self",
".",
"dicts",
"[",
"(",
"QA_util_to_datetime",
"(",
"time",
")",
",",
"str",
"(",
"code",
")",
")",
"]",
"except",
"Exception",
"as",
"e",
":",
"raise",
"e"
] |
'give the time,code tuple and turn the dict'
:param time:
:param code:
:return: 字典dict 类型
|
[
"give",
"the",
"time",
"code",
"tuple",
"and",
"turn",
"the",
"dict",
":",
"param",
"time",
":",
":",
"param",
"code",
":",
":",
"return",
":",
"字典dict",
"类型"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAData/base_datastruct.py#L662-L672
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAData/base_datastruct.py
|
_quotation_base.kline_echarts
|
def kline_echarts(self, code=None):
def kline_formater(param):
return param.name + ':' + vars(param)
"""plot the market_data"""
if code is None:
path_name = '.' + os.sep + 'QA_' + self.type + \
'_codepackage_' + self.if_fq + '.html'
kline = Kline(
'CodePackage_' + self.if_fq + '_' + self.type,
width=1360,
height=700,
page_title='QUANTAXIS'
)
bar = Bar()
data_splits = self.splits()
for ds in data_splits:
data = []
axis = []
if ds.type[-3:] == 'day':
datetime = np.array(ds.date.map(str))
else:
datetime = np.array(ds.datetime.map(str))
ohlc = np.array(
ds.data.loc[:,
['open',
'close',
'low',
'high']]
)
kline.add(
ds.code[0],
datetime,
ohlc,
mark_point=["max",
"min"],
is_datazoom_show=True,
datazoom_orient='horizontal'
)
return kline
else:
data = []
axis = []
ds = self.select_code(code)
data = []
#axis = []
if self.type[-3:] == 'day':
datetime = np.array(ds.date.map(str))
else:
datetime = np.array(ds.datetime.map(str))
ohlc = np.array(ds.data.loc[:, ['open', 'close', 'low', 'high']])
vol = np.array(ds.volume)
kline = Kline(
'{}__{}__{}'.format(code,
self.if_fq,
self.type),
width=1360,
height=700,
page_title='QUANTAXIS'
)
bar = Bar()
kline.add(self.code, datetime, ohlc,
mark_point=["max", "min"],
# is_label_show=True,
is_datazoom_show=True,
is_xaxis_show=False,
# is_toolbox_show=True,
tooltip_formatter='{b}:{c}', # kline_formater,
# is_more_utils=True,
datazoom_orient='horizontal')
bar.add(
self.code,
datetime,
vol,
is_datazoom_show=True,
datazoom_xaxis_index=[0,
1]
)
grid = Grid(width=1360, height=700, page_title='QUANTAXIS')
grid.add(bar, grid_top="80%")
grid.add(kline, grid_bottom="30%")
return grid
|
python
|
def kline_echarts(self, code=None):
def kline_formater(param):
return param.name + ':' + vars(param)
"""plot the market_data"""
if code is None:
path_name = '.' + os.sep + 'QA_' + self.type + \
'_codepackage_' + self.if_fq + '.html'
kline = Kline(
'CodePackage_' + self.if_fq + '_' + self.type,
width=1360,
height=700,
page_title='QUANTAXIS'
)
bar = Bar()
data_splits = self.splits()
for ds in data_splits:
data = []
axis = []
if ds.type[-3:] == 'day':
datetime = np.array(ds.date.map(str))
else:
datetime = np.array(ds.datetime.map(str))
ohlc = np.array(
ds.data.loc[:,
['open',
'close',
'low',
'high']]
)
kline.add(
ds.code[0],
datetime,
ohlc,
mark_point=["max",
"min"],
is_datazoom_show=True,
datazoom_orient='horizontal'
)
return kline
else:
data = []
axis = []
ds = self.select_code(code)
data = []
#axis = []
if self.type[-3:] == 'day':
datetime = np.array(ds.date.map(str))
else:
datetime = np.array(ds.datetime.map(str))
ohlc = np.array(ds.data.loc[:, ['open', 'close', 'low', 'high']])
vol = np.array(ds.volume)
kline = Kline(
'{}__{}__{}'.format(code,
self.if_fq,
self.type),
width=1360,
height=700,
page_title='QUANTAXIS'
)
bar = Bar()
kline.add(self.code, datetime, ohlc,
mark_point=["max", "min"],
# is_label_show=True,
is_datazoom_show=True,
is_xaxis_show=False,
# is_toolbox_show=True,
tooltip_formatter='{b}:{c}', # kline_formater,
# is_more_utils=True,
datazoom_orient='horizontal')
bar.add(
self.code,
datetime,
vol,
is_datazoom_show=True,
datazoom_xaxis_index=[0,
1]
)
grid = Grid(width=1360, height=700, page_title='QUANTAXIS')
grid.add(bar, grid_top="80%")
grid.add(kline, grid_bottom="30%")
return grid
|
[
"def",
"kline_echarts",
"(",
"self",
",",
"code",
"=",
"None",
")",
":",
"def",
"kline_formater",
"(",
"param",
")",
":",
"return",
"param",
".",
"name",
"+",
"':'",
"+",
"vars",
"(",
"param",
")",
"if",
"code",
"is",
"None",
":",
"path_name",
"=",
"'.'",
"+",
"os",
".",
"sep",
"+",
"'QA_'",
"+",
"self",
".",
"type",
"+",
"'_codepackage_'",
"+",
"self",
".",
"if_fq",
"+",
"'.html'",
"kline",
"=",
"Kline",
"(",
"'CodePackage_'",
"+",
"self",
".",
"if_fq",
"+",
"'_'",
"+",
"self",
".",
"type",
",",
"width",
"=",
"1360",
",",
"height",
"=",
"700",
",",
"page_title",
"=",
"'QUANTAXIS'",
")",
"bar",
"=",
"Bar",
"(",
")",
"data_splits",
"=",
"self",
".",
"splits",
"(",
")",
"for",
"ds",
"in",
"data_splits",
":",
"data",
"=",
"[",
"]",
"axis",
"=",
"[",
"]",
"if",
"ds",
".",
"type",
"[",
"-",
"3",
":",
"]",
"==",
"'day'",
":",
"datetime",
"=",
"np",
".",
"array",
"(",
"ds",
".",
"date",
".",
"map",
"(",
"str",
")",
")",
"else",
":",
"datetime",
"=",
"np",
".",
"array",
"(",
"ds",
".",
"datetime",
".",
"map",
"(",
"str",
")",
")",
"ohlc",
"=",
"np",
".",
"array",
"(",
"ds",
".",
"data",
".",
"loc",
"[",
":",
",",
"[",
"'open'",
",",
"'close'",
",",
"'low'",
",",
"'high'",
"]",
"]",
")",
"kline",
".",
"add",
"(",
"ds",
".",
"code",
"[",
"0",
"]",
",",
"datetime",
",",
"ohlc",
",",
"mark_point",
"=",
"[",
"\"max\"",
",",
"\"min\"",
"]",
",",
"is_datazoom_show",
"=",
"True",
",",
"datazoom_orient",
"=",
"'horizontal'",
")",
"return",
"kline",
"else",
":",
"data",
"=",
"[",
"]",
"axis",
"=",
"[",
"]",
"ds",
"=",
"self",
".",
"select_code",
"(",
"code",
")",
"data",
"=",
"[",
"]",
"#axis = []",
"if",
"self",
".",
"type",
"[",
"-",
"3",
":",
"]",
"==",
"'day'",
":",
"datetime",
"=",
"np",
".",
"array",
"(",
"ds",
".",
"date",
".",
"map",
"(",
"str",
")",
")",
"else",
":",
"datetime",
"=",
"np",
".",
"array",
"(",
"ds",
".",
"datetime",
".",
"map",
"(",
"str",
")",
")",
"ohlc",
"=",
"np",
".",
"array",
"(",
"ds",
".",
"data",
".",
"loc",
"[",
":",
",",
"[",
"'open'",
",",
"'close'",
",",
"'low'",
",",
"'high'",
"]",
"]",
")",
"vol",
"=",
"np",
".",
"array",
"(",
"ds",
".",
"volume",
")",
"kline",
"=",
"Kline",
"(",
"'{}__{}__{}'",
".",
"format",
"(",
"code",
",",
"self",
".",
"if_fq",
",",
"self",
".",
"type",
")",
",",
"width",
"=",
"1360",
",",
"height",
"=",
"700",
",",
"page_title",
"=",
"'QUANTAXIS'",
")",
"bar",
"=",
"Bar",
"(",
")",
"kline",
".",
"add",
"(",
"self",
".",
"code",
",",
"datetime",
",",
"ohlc",
",",
"mark_point",
"=",
"[",
"\"max\"",
",",
"\"min\"",
"]",
",",
"# is_label_show=True,",
"is_datazoom_show",
"=",
"True",
",",
"is_xaxis_show",
"=",
"False",
",",
"# is_toolbox_show=True,",
"tooltip_formatter",
"=",
"'{b}:{c}'",
",",
"# kline_formater,",
"# is_more_utils=True,",
"datazoom_orient",
"=",
"'horizontal'",
")",
"bar",
".",
"add",
"(",
"self",
".",
"code",
",",
"datetime",
",",
"vol",
",",
"is_datazoom_show",
"=",
"True",
",",
"datazoom_xaxis_index",
"=",
"[",
"0",
",",
"1",
"]",
")",
"grid",
"=",
"Grid",
"(",
"width",
"=",
"1360",
",",
"height",
"=",
"700",
",",
"page_title",
"=",
"'QUANTAXIS'",
")",
"grid",
".",
"add",
"(",
"bar",
",",
"grid_top",
"=",
"\"80%\"",
")",
"grid",
".",
"add",
"(",
"kline",
",",
"grid_bottom",
"=",
"\"30%\"",
")",
"return",
"grid"
] |
plot the market_data
|
[
"plot",
"the",
"market_data"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAData/base_datastruct.py#L680-L769
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAData/base_datastruct.py
|
_quotation_base.query
|
def query(self, context):
"""
查询data
"""
try:
return self.data.query(context)
except pd.core.computation.ops.UndefinedVariableError:
print('QA CANNOT QUERY THIS {}'.format(context))
pass
|
python
|
def query(self, context):
"""
查询data
"""
try:
return self.data.query(context)
except pd.core.computation.ops.UndefinedVariableError:
print('QA CANNOT QUERY THIS {}'.format(context))
pass
|
[
"def",
"query",
"(",
"self",
",",
"context",
")",
":",
"try",
":",
"return",
"self",
".",
"data",
".",
"query",
"(",
"context",
")",
"except",
"pd",
".",
"core",
".",
"computation",
".",
"ops",
".",
"UndefinedVariableError",
":",
"print",
"(",
"'QA CANNOT QUERY THIS {}'",
".",
"format",
"(",
"context",
")",
")",
"pass"
] |
查询data
|
[
"查询data"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAData/base_datastruct.py#L791-L800
|
train
|
QUANTAXIS/QUANTAXIS
|
QUANTAXIS/QAData/base_datastruct.py
|
_quotation_base.groupby
|
def groupby(
self,
by=None,
axis=0,
level=None,
as_index=True,
sort=False,
group_keys=False,
squeeze=False,
**kwargs
):
"""仿dataframe的groupby写法,但控制了by的code和datetime
Keyword Arguments:
by {[type]} -- [description] (default: {None})
axis {int} -- [description] (default: {0})
level {[type]} -- [description] (default: {None})
as_index {bool} -- [description] (default: {True})
sort {bool} -- [description] (default: {True})
group_keys {bool} -- [description] (default: {True})
squeeze {bool} -- [description] (default: {False})
observed {bool} -- [description] (default: {False})
Returns:
[type] -- [description]
"""
if by == self.index.names[1]:
by = None
level = 1
elif by == self.index.names[0]:
by = None
level = 0
return self.data.groupby(
by=by,
axis=axis,
level=level,
as_index=as_index,
sort=sort,
group_keys=group_keys,
squeeze=squeeze
)
|
python
|
def groupby(
self,
by=None,
axis=0,
level=None,
as_index=True,
sort=False,
group_keys=False,
squeeze=False,
**kwargs
):
"""仿dataframe的groupby写法,但控制了by的code和datetime
Keyword Arguments:
by {[type]} -- [description] (default: {None})
axis {int} -- [description] (default: {0})
level {[type]} -- [description] (default: {None})
as_index {bool} -- [description] (default: {True})
sort {bool} -- [description] (default: {True})
group_keys {bool} -- [description] (default: {True})
squeeze {bool} -- [description] (default: {False})
observed {bool} -- [description] (default: {False})
Returns:
[type] -- [description]
"""
if by == self.index.names[1]:
by = None
level = 1
elif by == self.index.names[0]:
by = None
level = 0
return self.data.groupby(
by=by,
axis=axis,
level=level,
as_index=as_index,
sort=sort,
group_keys=group_keys,
squeeze=squeeze
)
|
[
"def",
"groupby",
"(",
"self",
",",
"by",
"=",
"None",
",",
"axis",
"=",
"0",
",",
"level",
"=",
"None",
",",
"as_index",
"=",
"True",
",",
"sort",
"=",
"False",
",",
"group_keys",
"=",
"False",
",",
"squeeze",
"=",
"False",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"by",
"==",
"self",
".",
"index",
".",
"names",
"[",
"1",
"]",
":",
"by",
"=",
"None",
"level",
"=",
"1",
"elif",
"by",
"==",
"self",
".",
"index",
".",
"names",
"[",
"0",
"]",
":",
"by",
"=",
"None",
"level",
"=",
"0",
"return",
"self",
".",
"data",
".",
"groupby",
"(",
"by",
"=",
"by",
",",
"axis",
"=",
"axis",
",",
"level",
"=",
"level",
",",
"as_index",
"=",
"as_index",
",",
"sort",
"=",
"sort",
",",
"group_keys",
"=",
"group_keys",
",",
"squeeze",
"=",
"squeeze",
")"
] |
仿dataframe的groupby写法,但控制了by的code和datetime
Keyword Arguments:
by {[type]} -- [description] (default: {None})
axis {int} -- [description] (default: {0})
level {[type]} -- [description] (default: {None})
as_index {bool} -- [description] (default: {True})
sort {bool} -- [description] (default: {True})
group_keys {bool} -- [description] (default: {True})
squeeze {bool} -- [description] (default: {False})
observed {bool} -- [description] (default: {False})
Returns:
[type] -- [description]
|
[
"仿dataframe的groupby写法",
"但控制了by的code和datetime"
] |
bb1fe424e4108b62a1f712b81a05cf829297a5c0
|
https://github.com/QUANTAXIS/QUANTAXIS/blob/bb1fe424e4108b62a1f712b81a05cf829297a5c0/QUANTAXIS/QAData/base_datastruct.py#L802-L843
|
train
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.