# 金融 / 金融工程 / 策略验证 / 中间函数 ## `portfolioBackTesting_adjustVolByBonusShare(tp_gp, end_t)` 声明:function 返回分红送股处理,若有分红送股,则对'数量'(持仓数量)进行调整 | 参数 | 类型 | 说明 | | ------- | ----------- | ------------------------------ | | `tp_gp` | table_array | 数据表类型,EndT之前的持仓明细 | | `end_t` | datetime | 日期型时间,截止日 | 返回:table_array ### 示例 范例01:调用 PortfolioBackTesting_AdjustVolByBonusShare ```tsl tpGP := array( ("代码":"SH600143", "名称":"金发科技", "数量":288760.00), ("代码":"SH600601", "名称":"方正科技", "数量":1334310.00), ("代码":"SH600839", "名称":"四川长虹", "数量":1368608.00)); return PortfolioBackTesting_AdjustVolByBonusShare(tpGP, inttodate(20070702)); ``` ## `portfolioBackTesting_benchmarkReturn(index_id, t)` 声明:function 返回策略验证-基准收益率,返回基准收益率和组合收益率 | 参数 | 类型 | 说明 | | ---------- | ----------- | --------------------------- | | `index_id` | string | 字符串,指数代码,Benchmark | | `t` | table_array | 数据表类型,组合日收益率 | 返回:table_array ### 示例 范例01:调用 PortfolioBackTesting_BenchmarkReturn ```tsl t := array(('截止日':41213, '净值收益率(%)':0.012), ('截止日':41214, '净值收益率(%)':0.018), ('截止日':41215, '净值收益率(%)':0.022)); PortfolioBackTesting_BenchmarkReturn('SH000300', t); RETURN T; ``` ## `portfolioBackTesting_buySellDefaultRatio(stock_id, end_t, buy_ratio, sell_ratio, buy_other_fee, sell_other_fee)` 声明:function 返回策略验证-缺省买卖费率和费用,判断数据BuyRatio,SellRatio BuyOtherFee ,SellOtherFee为nil则按照证券代码类型分别赋值 | 参数 | 类型 | 说明 | | ---------------- | -------- | ------------------ | | `stock_id` | string | 字符串,证券代码 | | `end_t` | datetime | 日期型时间,截止日 | | `buy_ratio` | float | 实数,开仓费率(%) | | `sell_ratio` | float | 实数,平仓费率(%) | | `buy_other_fee` | float | 实数,开仓其他费用 | | `sell_other_fee` | float | 实数,平仓其他费用 | 返回:table_array ### 示例 范例01:调用 PortfolioBackTesting_BuySellDefaultRatio ```tsl BuyRatio := 0.3; SellRatio := NIL; BuyOtherFee := NIL; PortfolioBackTesting_BuySellDefaultRatio( 'SH000300', inttodate(20121029), BuyRatio, SellRatio, BuyOtherFee, SellOtherFee); return array(BuyRatio, SellRatio, BuyOtherFee); ``` ## `portfolioBackTesting_calBenchmarkReturn(b_minfo, bm_arr, t)` 声明:function 返回累计收益率计算 | 参数 | 类型 | 说明 | | --------- | ----------- | -------------------------- | | `b_minfo` | array | 一维数组,基准详情 | | `bm_arr` | table_array | 数据表类型,基准收益率序列 | | `t` | table_array | 数据表类型,组合收益率序列 | 返回:table_array ### 示例 范例01:单个市场指数作为基准:沪深300作为基准 ```tsl // 单个市场指数作为基准:沪深300作为基准 BMinfo := array( "复合收益率计算方法":0, "基准类型":0, "基准代码":"沪深300" ); BMArr := array( ("截止日":44930.0, "基准收益率(%)":0.129851617552233), ("截止日":44931.0, "基准收益率(%)":1.9427566417088), ("截止日":44932.0, "基准收益率(%)":0.310201774529736), ("截止日":44935.0, "基准收益率(%)":0.809638289821103), ("截止日":44936.0, "基准收益率(%)":0.10849664186435), ("截止日":44937.0, "基准收益率(%)":-0.185260702515608), ("截止日":44938.0, "基准收益率(%)":0.19546732171066), ("截止日":44939.0, "基准收益率(%)":1.40641711283184), ("截止日":44942.0, "基准收益率(%)":1.56065815408548), ("截止日":44943.0, "基准收益率(%)":-0.017450609711639), ("截止日":44944.0, "基准收益率(%)":-0.167452125476234), ("截止日":44945.0, "基准收益率(%)":0.622068882263999), ("截止日":44946.0, "基准收益率(%)":0.614026773819506) ); t := array( ("截止日":44930.0, "净值收益率(%)":-0.332793457), ("截止日":44931.0, "净值收益率(%)":-0.263773111664858), ("截止日":44932.0, "净值收益率(%)":0.0354019916831471), ("截止日":44935.0, "净值收益率(%)":0.277866916531731), ("截止日":44936.0, "净值收益率(%)":0.351341637362642), ("截止日":44937.0, "净值收益率(%)":-0.857619853637283), ("截止日":44938.0, "净值收益率(%)":-0.829772904725061), ("截止日":44939.0, "净值收益率(%)":-1.37385104622509), ("截止日":44942.0, "净值收益率(%)":-0.698157299507218), ("截止日":44943.0, "净值收益率(%)":-1.30100783081455), ("截止日":44944.0, "净值收益率(%)":0.328379438447828), ("截止日":44945.0, "净值收益率(%)":0.204243778249732), ("截止日":44946.0, "净值收益率(%)":-0.398048534322399) ); return PortfolioBackTesting_CalBenchmarkReturn(BMinfo, BMArr, t); ``` 范例02:多个市场市场指数加权作为基准 ```tsl // 多个市场市场指数加权作为基准 // array(("代码":"SH000012","比例(%)":35),("代码":"SH000300","比例(%)":65)) BMinfo := array( "复合收益率计算方法":0, // 累计收益率计算方式0-累成,1-累加 "基准类型":1, "基准代码":"复合基准" ); BMArr := array( ("截止日":43801.0, "基准收益率(%)":0.123171172283601), ("截止日":43802.0, "基准收益率(%)":0.25829833514229), ("截止日":43803.0, "基准收益率(%)":-0.020653085113629), ("截止日":43804.0, "基准收益率(%)":0.505178796361568), ("截止日":43805.0, "基准收益率(%)":0.388033089336361), ("截止日":43808.0, "基准收益率(%)":-0.105537214736128), ("截止日":43809.0, "基准收益率(%)":0.0888504434722582), ("截止日":43810.0, "基准收益率(%)":0.0416111626986788) ); t := array( ("截止日":43801.0, "净值收益率(%)":-0.0021054), ("截止日":43802.0, "净值收益率(%)":0.0144003031839832), ("截止日":43803.0, "净值收益率(%)":0.0105986969326069), ("截止日":43804.0, "净值收益率(%)":0.0173960172514344), ("截止日":43805.0, "净值收益率(%)":0.0361854192300629), ("截止日":43808.0, "净值收益率(%)":0.0275789036279854), ("截止日":43809.0, "净值收益率(%)":0.0241748353018918), ("截止日":43810.0, "净值收益率(%)":0.00659154340575376) ); return PortfolioBackTesting_CalBenchmarkReturn(BMinfo, BMArr, t); ``` ## `portfolioBackTesting_initInvestmentRatio(end_t, tm)` 声明:function 返回策略验证-初始化资产配置 | 参数 | 类型 | 说明 | | ------- | -------- | ------------------ | | `end_t` | datetime | 日期型时间,截止日 | | `tm` | float | 实数,初始资金 | 返回:table_array ### 示例 范例01:调用 PortfolioBackTesting_InitInvestmentRatio ```tsl return PortfolioBackTesting_InitInvestmentRatio(inttodate(20121029), 100000); // 对资产配资初始化 ``` ## `portfolioBackTesting_transactionPrice(stock_id, end_t, price_type)` 声明:function 返回策略验证-成交价,确定StockId代码的成交价 | 参数 | 类型 | 说明 | | ------------ | -------- | ----------------------------------------- | | `stock_id` | string | 字符串,证券代码 | | `end_t` | datetime | 日期型时间,截止日 | | `price_type` | integer | 整数,用户自定义,成交价类别,含义如下表: | 返回:float ### 示例 范例01:结果:7.46 ```tsl return PortfolioBackTesting_TransactionPrice('SH600000', inttodate(20121029), 1); // 输出:7.46 ``` ## `portfolioBackTesting_transactionVol(mod_type, p_2, v_blbd, v_vol_before_round)` 声明:function 返回策略验证-成交量 | 参数 | 类型 | 说明 | | -------------------- | ------- | -------------------------------------------------------------------- | | `mod_type` | integer | 整数,成交量取整模式,0表示不取整,1表示100整数倍,2表示小数点后两位 | | `p_2` | float | 实数,目标比例(%) | | `v_blbd` | float | 实数,比例变动(%) | | `v_vol_before_round` | float | 实数,取整前数量 | 返回:float ### 示例 范例01:调用 PortfolioBackTesting_TransactionVol ```tsl return PortfolioBackTesting_TransactionVol(1, 0.3, 0.2, 20030); // 输出:20000 ```