搜索
人大经济论坛 附件下载

附件下载

所在主题:
文件名:  myFundValue.xml.txt
资料下载链接地址: https://bbs.pinggu.org/a-2016444.html
附件大小:
54.68 KB   举报本内容
1、测试数据源:长盛电子信息主题灵活配置混合(000063),2013-05-10~2016-04-15全部历史净值数据。数据净值曲线:


2、写了三种方式做比较,Level1是参考了一些资料做的模版;Level2在前者基础上做了循环点的修改,将净值中所有下降沿的顶点和终点成对筛选出来,存为一个集合。经运行测试,Level1和Level2两者消耗时间相当;Level3将净值中所有下降沿的顶点值和终点值筛选出来,分别存为集合。当最大回撤出现在数据靠后位置时,减少了搜寻最低点的次数,此时Level3有一定优势。

3、主要代码如下:class ValueSample
{
private static ArrayList<Double> valueCollection = new ArrayList<>();// 净值集合
private static ArrayList<Double> maxCollection = new ArrayList<>();// 下降趋势顶部索引集合
private static ArrayList<Double> minCollection = new ArrayList<>();// 上升趋势底部索引集合
private static ArrayList<Integer> IndexCollection = new ArrayList<>();// 趋势点索引集合

public static void main(String[] args)
{
//.....此处省略导入净值到valueCollection的过程。

// 最大回撤,Level1

long start = System.nanoTime();
System.out.println("L1最大回撤=" + getMaxDrawdownLevel1());
long end = System.nanoTime();
System.out.println("L1用时:" + (end - start));

Thread.sleep(3000);//暂停3s

// 最大回撤,Level2
start = System.nanoTime();
indexInitialize();
System.out.println("L2最大回撤=" + getMaxDrawdownLevel2());
end = System.nanoTime();
System.out.println("L2用时:" + (end - start));

Thread.sleep(3000);

// 最大回撤,Level3
start = System.nanoTime();
valueInitialize();
System.out.println("L3最大回撤=" + getMaxDrawdownLevel3());
end = System.nanoTime();
System.out.println("L3用时:" + (end - start));
}

private static double getMaxDrawdownLevel1()// 最大回撤L1
{
double diff = 0;
double max = valueCollection.get(0);
for (int temp = 1; temp < valueCollection.size(); temp++)
{
if (valueCollection.get(temp) - max < diff)
diff = valueCollection.get(temp) - max;
if (valueCollection.get(temp) > max)
max = valueCollection.get(temp);
}
System.out.println("最大回撤率max=" + (diff / max) * 100);
return diff;
}

private static double getMaxDrawdownLevel2()// 最大回撤L2
{
double diff = 0;
double max = valueCollection.get(IndexCollection.get(0));
for (int baseIndex = 1; baseIndex < IndexCollection.size(); baseIndex++)
{
if (valueCollection.get(IndexCollection.get(baseIndex)) - max < diff)
diff = valueCollection.get(IndexCollection.get(baseIndex)) - max;
if (valueCollection.get(IndexCollection.get(baseIndex)) > max)
max = valueCollection.get(IndexCollection.get(baseIndex));
}
System.out.println("最大回撤率max=" + (diff / max) * 100);
return diff;
}

private static double getMaxDrawdownLevel3()// 最大回撤L3
{
double max = maxCollection.get(0);
int maxIndex = 0;
for (int baseIndex = 1; baseIndex < maxCollection.size(); baseIndex++)
if (max < maxCollection.get(baseIndex))
{
max = maxCollection.get(baseIndex);
maxIndex = baseIndex;
}
double min = minCollection.get(maxIndex + 1);
for (int baseIndex = maxIndex + 2; baseIndex < minCollection.size(); baseIndex++)
if (min > minCollection.get(baseIndex))
min = minCollection.get(baseIndex);
System.out.println("最大回撤率max=" + (min / max - 1) * 100);
return min - max;
}

private static void valueInitialize()// 初始化趋势点值集合
{
for (int baseIndex = 0; baseIndex < valueCollection.size() - 1; baseIndex++)
if (valueCollection.get(baseIndex) > valueCollection.get(baseIndex + 1))
{
maxCollection.add(valueCollection.get(baseIndex));// 加入下降趋势顶部值
for (; baseIndex + 1 < valueCollection.size(); baseIndex++)
if (valueCollection.get(baseIndex) < valueCollection.get(baseIndex + 1))
{
minCollection.add(valueCollection.get(baseIndex));// 加入上升趋势底部值
break;
}
}
}

private static void indexInitialize()// 初始化趋势点索引集合
{
for (int baseIndex = 0; baseIndex < valueCollection.size() - 1; baseIndex++)
if (valueCollection.get(baseIndex) > valueCollection.get(baseIndex + 1))
{
IndexCollection.add(baseIndex);// 加入下降趋势顶部索引
for (; baseIndex + 1 < valueCollection.size(); baseIndex++)
if (valueCollection.get(baseIndex) < valueCollection.get(baseIndex + 1))
{
IndexCollection.add(baseIndex);// 成对加入上升趋势底部索引
break;
}
}
}
}

4、测试时间(单位,毫微秒):


5、数据源xml,使用Navicat导出的MySQL数据表。(因不能上传xml文件,加了txt的后缀)




    熟悉论坛请点击新手指南
下载说明
1、论坛支持迅雷和网际快车等p2p多线程软件下载,请在上面选择下载通道单击右健下载即可。
2、论坛会定期自动批量更新下载地址,所以请不要浪费时间盗链论坛资源,盗链地址会很快失效。
3、本站为非盈利性质的学术交流网站,鼓励和保护原创作品,拒绝未经版权人许可的上传行为。本站如接到版权人发出的合格侵权通知,将积极的采取必要措施;同时,本站也将在技术手段和能力范围内,履行版权保护的注意义务。
(如有侵权,欢迎举报)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

GMT+8, 2025-12-26 04:37