Files
playbook/skills/tsl-api-reference/references/codegen/dotnet/datawarehouse/wizard.md
T

332 lines
11 KiB
Markdown

# 数据仓库 / 向导函数
## `avgOfSector(exp, mode, shares_day, list_day, s_type, sample_select, eps_criterion, except_no_trade)`
声明:function
板块平均。对指定板块按照一定标准进行选股后,对板块下每一只股票Exp表达式的指标值按mode求平均,选股标准由SampleSelect与EPSCriterion确定。其中亏损股为当前时间之前最近一期报告期每股收益(摊薄)\*12/报告期所在月份<0,停牌股为当前时间之前最近一期报告期每股收益(摊薄)\*12/报告期所在月份<EPSCriterion,与系统参数(股票,周期)相关
<!-- tags: 数据仓库 向导函数 -->
| 参数 | 类型 | 说明 |
| ----------------- | -------- | ------------------------------------------------------------ |
| `exp` | expr | 函数表达式 |
| `mode` | int | 用户自定义,平均模式 |
| `shares_day` | datetime | 日期,收益计算日 |
| `list_day` | datetime | 日期,在之前上市 |
| `s_type` | int | 用户自定义,股票类型 |
| `sample_select` | int | 用户自定义,样本股选择 |
| `eps_criterion` | float | 实数,绩差股标准。每股收益(摊薄)&lt;EPSCriterion即表示绩差股 |
| `except_no_trade` | bool | 真假,剔除停牌股 |
返回:float
### 示例
范例01:返回:12.27
```tsl
setSysParam(pn_bk(), "沪深300");
setSysParam(pn_stock(), "SH600000");
setSysParam(pn_cycle(), cy_day());
return avgOfSector(@close(), 2, 20180801T, 20180801T, 1, 0, 0, 0);
// 输出:53.354628
```
## `derivative1(f, n)`
声明:function
指标技术趋势,返回N个时间点前连续三个周期的指标Expr变化趋势,与当前系统参数(股票,日期,周期,复权)相关
<!-- tags: 数据仓库 向导函数 -->
| 参数 | 类型 | 说明 |
| ---- | ---- | --------------- |
| `f` | expr | 函数表达式,指标 |
| `n` | int | 整数,日期偏移 |
返回:float
### 示例
范例01:调用函数
```tsl
SetSysParam(pn_stock(), 'SZ000001');
SetSysParam(pn_date(), 20180801T);
return Derivative1(@close(), 0); // 指标值为收盘价
```
## `derivative2(a)`
声明:function
指标技术加速度,返回4个周期的指标Expr变化趋势,与当前系统参数(股票,日期,周期,复权)相关
<!-- tags: 数据仓库 向导函数 -->
| 参数 | 类型 | 说明 |
| ---- | ---- | ---------- |
| `a` | expr | 函数表达式 |
返回:float
### 示例
范例01:调用函数
```tsl
SetSysParam(pn_stock(), 'SZ000001');
SetSysParam(pn_date(), 20180801T);
return Derivative2(@close()); // 指标值为收盘价
```
## `growthWithLowestOfPeriod(exp, beg_date, end_date, return_type)`
声明:function
返回表达式Exp在区间BegDate到EndDate中的最小值与在EndDate的值的偏离,ReturnType决定返回偏离值(增加值)还是偏离率(增速%)
<!-- tags: 数据仓库 向导函数 返回 获取 -->
| 参数 | 类型 | 说明 |
| ------------- | -------- | -------------------- |
| `exp` | expr | 函数表达式 |
| `beg_date` | datetime | 日期,开始日 |
| `end_date` | datetime | 日期,截止日 |
| `return_type` | int | 用户自定义,返回类型 |
返回:float
### 示例
范例01:调用函数
```tsl
SetSysParam(pn_stock(), 'SZ000001');
return GrowthWithLowestOfPeriod(@close(), 20180801T, 20180903T, 0);
```
## `positionOfSector(exp, sector)`
声明:function
从大到小排名。板块Sector中成分股按个券指标EXP大小排序,返回指定股票pn_stock()的排名,该函数与系统参数(股票,日期,复权,周期)相关
<!-- tags: 数据仓库 向导函数 排序 sort EXP -->
| 参数 | 类型 | 说明 |
| -------- | ------ | ---------------- |
| `exp` | expr | 函数表达式 |
| `sector` | string | 市场和板块,板块 |
返回:float
### 示例
范例01:调用函数
```tsl
SetSysParam(pn_stock(), 'SZ000001');
SetSysParam(pn_date(), 20180801T);
return PositionOfSector(@close(), 'A股');
```
## `positionOfSectorDesc(exp, sector)`
声明:function
从小到大排名。板块Sector中按指标EXP大小排序,返回指定股票的排名,与系统参数(股票,日期,复权,周期)相关
<!-- tags: 数据仓库 向导函数 排序 sort EXP -->
| 参数 | 类型 | 说明 |
| -------- | ------ | ---------------- |
| `exp` | expr | 函数表达式 |
| `sector` | string | 市场和板块,板块 |
返回:float
### 示例
范例01:调用函数
```tsl
SetSysParam(pn_stock(), 'SZ000001');
SetSysParam(pn_date(), 20180801T);
return PositionOfSectorDesc(@close(), 'A股');
```
## `reduceWithHighestOfPeriod(exp, beg_date, end_date, return_type)`
声明:function
返回表达式Exp在区间BegDate到EndDate中的最大值与在EndDate的值的偏离,ReturnType决定返回偏离值(增加值)还是偏离率(增速%)
<!-- tags: 数据仓库 向导函数 返回 获取 -->
| 参数 | 类型 | 说明 |
| ------------- | -------- | -------------------- |
| `exp` | expr | 函数表达式 |
| `beg_date` | datetime | 日期,开始日 |
| `end_date` | datetime | 日期,截止日 |
| `return_type` | int | 用户自定义,返回类型 |
返回:float
### 示例
范例01:调用函数
```tsl
SetSysParam(pn_stock(), 'SZ000001');
return ReduceWithHighestOfPeriod(@close(), 20180801T, 20180803T, 0);
```
## `relativeStrengthOfSector(exp, sector)`
声明:function
系统当前证券在板块中的相对强弱(%)。系统当前证券pn_stock()在指定板块Sector中的指标Exp值的从大到小的排位百分比。该函数与系统参数(股票,日期,复权,周期)相关
<!-- tags: 数据仓库 向导函数 -->
| 参数 | 类型 | 说明 |
| -------- | ------ | ---------------- |
| `exp` | expr | 函数表达式 |
| `sector` | string | 市场和板块,板块 |
返回:float
### 示例
范例01:调用函数
```tsl
SetSysParam(pn_stock(), 'SH000300');
SetSysParam(pn_date(), 20180801T);
return RelativeStrengthOfSector(@stockzf3(), 'A股');
```
## `relativeStrengthOfSectorDesc(exp, sector)`
声明:function
系统当前证券在板块中的相对强弱(%)。系统当前证券pn_stock()在指定板块Sector中的指标Exp值的从小到大的排位百分比。该函数与系统参数(股票,日期,复权,周期)相关
<!-- tags: 数据仓库 向导函数 -->
| 参数 | 类型 | 说明 |
| -------- | ------ | ---------------- |
| `exp` | expr | 函数表达式 |
| `sector` | string | 市场和板块,板块 |
返回:float
### 示例
范例01:调用函数
```tsl
SetSysParam(pn_stock(), 'SZ000001');
SetSysParam(pn_date(), 20180801T);
return RelativeStrengthOfSectorDesc(@close(), 'A股');
```
## `stockTrailingAvgByEndT(end_t, ref_type, exp, is_exclude_ipo, n)`
声明:function
返回指定证券截至 `end_t` 的推移区间日均指标。
<!-- tags: 数据仓库 向导函数 证券 推移区间 日均值 成交金额 历史统计 -->
| 参数 | 类型 | 说明 |
| ---------------- | ----------- | ------------------------------------ |
| `end_t` | datetime | 截止日 |
| `ref_type` | user_define | 推移区间类型;`4` 表示过去 1 年 |
| `exp` | string | 指标表达式字符串,如 `'amount()'` |
| `is_exclude_ipo` | bool | 是否剔除上市初期区间行情 |
| `n` | int | 剔除的上市初期天数;不剔除时可传 `0` |
返回:float
依赖系统参数:`pn_stock()`
### 示例
范例01:计算万科 A 截至 2021-07-14 过去 1 年的日均成交金额
```tsl
setSysParam(pn_stock(), 'SZ000002');
end_t := 20210714T;
ref_type := 4;
exp := 'amount()';
return stockTrailingAvgByEndT(end_t, ref_type, exp, false, 0);
// 输出:2172484158.52107
```
## `stockTrailingStdByEndT(end_t, ref_type, exp, is_exclude_ipo, n)`
声明:function
返回指定证券截至 `end_t` 的推移区间指标标准差。
<!-- tags: 数据仓库 向导函数 证券 推移区间 标准差 收益率 波动 历史统计 -->
| 参数 | 类型 | 说明 |
| ---------------- | ----------- | ------------------------------------ |
| `end_t` | datetime | 截止日 |
| `ref_type` | user_define | 推移区间类型;`4` 表示过去 1 年 |
| `exp` | string | 指标表达式字符串,如 `'stockzf3()'` |
| `is_exclude_ipo` | bool | 是否剔除上市初期区间行情 |
| `n` | int | 剔除的上市初期天数;不剔除时可传 `0` |
返回:float
依赖系统参数:`pn_stock()`
### 示例
范例01:计算万科 A 截至 2021-07-14 过去 1 年的日收益率标准差
```tsl
setSysParam(pn_stock(), 'SZ000002');
end_t := 20210714T;
ref_type := 4;
exp := 'stockzf3()';
return stockTrailingStdByEndT(end_t, ref_type, exp, false, 0);
// 输出:1.687273
```
## `sumOfSector(exp, shares_day, list_day, s_type, sample_select, eps_criterion, except_no_trade)`
声明:function
对指定板块按照一定标准进行选股后,对板块下每一只股票Exp表达式的指标值求和. 选股标准由SType、SampleSelect与EPSCriterion确定。 其中亏损股为当前时间之前最近一期报告期每股收益(摊薄)\*12/报告期所在月份<0; 停牌股为当前时间之前最近一期报告期每股收益(摊薄)\*12/报告期所在月份<EPSCriterion,与系统参数(板块,周期,时间)相关
<!-- tags: 数据仓库 向导函数 -->
| 参数 | 类型 | 说明 |
| ----------------- | -------- | ------------------------------------------------------------ |
| `exp` | expr | 函数表达式 |
| `shares_day` | datetime | 日期,收益计算日 |
| `list_day` | datetime | 日期,在之前上市 |
| `s_type` | int | 用户自定义,股票类型 |
| `sample_select` | int | 用户自定义,样本股选择 |
| `eps_criterion` | float | 实数,绩差股标准。每股收益(摊薄)&lt;EPSCriterion即表示绩差股 |
| `except_no_trade` | bool | 真假,剔除停牌股 |
返回:float
### 示例
范例01:调用函数
```tsl
setsysparam(pn_bk(), "上证A股");
setsysparam(Pn_date(), 20180801T);
return SumOfSector(@close(), 20180801T, 20180801T, 1, 0, 0, 0);
```