算移动平均值的方法,帮忙优化下

ledmhcc 2010-07-06 04:56:34
我比较贪心,在这个方法中把ma5,ma10,ma20,ma30放一起算了(股票里的移动平均值),整个方法觉得比较臃肿,但自己没办法优化了,所以想请高手看看有什么办法让代码更优雅些
最主要发现自己在逻辑上的暂时没法突破自己了,所以需要借鉴下别人的想法
C#

public IList MaNumPlus(IList list, DateTime startdate)
{
IList ma5 = new ArrayList();
IList ma10 = new ArrayList();
IList ma20 = new ArrayList();
IList ma30 = new ArrayList();
DateTime ma5end = startdate.AddDays(-10);
DateTime ma10end = startdate.AddDays(-20);
DateTime ma20end = startdate.AddDays(-40);
DateTime ma30end = startdate.AddDays(-60);

for (int i = 1; i <= list.Count; i++)
{
double tempma30 = 0;
double tempma20 = 0;
double tempma10 = 0;
double tempma5 = 0;
int num30 = 0;
int num20 = 0;
int num10 = 0;
int num5 = 0;

if (list.Count > 30)
{
for (int j = i - 1; j < 29 + i; j++)
{
if (j < list.Count)
{
tempma30 += ((StockInfo)list[j]).NowIndex;//NowIndex=收盘价
num30++;
if (j < 19+i)
{
tempma20 += ((StockInfo)list[j]).NowIndex;
num20++;
}
if (j < 9+i)
{
tempma10 += ((StockInfo)list[j]).NowIndex;
num10++;
}
if (j < 4+i)
{
tempma5 += ((StockInfo)list[j]).NowIndex;
num5++;
}
}
else
{
break;
}
}
if (num30 != 0)
{
((StockInfo)list[i - 1]).Ma30 = Math.Round(tempma30 / num30, 2);
}

if (((StockInfo)list[i - 1]).DayDate >= ma20end && num20 != 0)
{
((StockInfo)list[i - 1]).Ma20 = Math.Round(tempma20 / num20, 2);
}

if (((StockInfo)list[i - 1]).DayDate >= ma10end && num10 != 0)
{
((StockInfo)list[i - 1]).Ma10 = Math.Round(tempma10 / num10, 2);
}

if (((StockInfo)list[i - 1]).DayDate >= ma5end && num5 !=0)
{
((StockInfo)list[i - 1]).Ma5 = Math.Round(tempma5 / num5, 2);
}
}
else if (list.Count > 20)
{
for (int j = list.Count - 1; j >= i - 1; j--)
{
tempma30 += ((StockInfo)list[j]).NowIndex;
num30++;
}
if (num30 != 0)
{
((StockInfo)list[i - 1]).Ma30 = Math.Round(tempma30 / num30, 2);
}

for (int j = i - 1; j < 19 + i; j++)
{
if (j < list.Count)
{
tempma20 += ((StockInfo)list[j]).NowIndex;
num20++;
if (j < 9+i)
{
tempma10 += ((StockInfo)list[j]).NowIndex;
num10++;
}
if (j < 4+i)
{
tempma5 += ((StockInfo)list[j]).NowIndex;
num5++;
}
}
else
{
break;
}
}
if (num20 != 0)
{
((StockInfo)list[i - 1]).Ma20 = Math.Round(tempma20 / num20, 2);
}

if (((StockInfo)list[i - 1]).DayDate >= ma10end && num10 != 0)
{
((StockInfo)list[i - 1]).Ma10 = Math.Round(tempma10 / num10, 2);
}

if (((StockInfo)list[i - 1]).DayDate >= ma5end && num5 != 0)
{
((StockInfo)list[i - 1]).Ma5 = Math.Round(tempma5 / num5, 2);
}
}
else if (list.Count > 10)
{
for (int j = list.Count - 1; j >= i - 1; j--)
{
tempma30 += ((StockInfo)list[j]).NowIndex;
num30++;
}
if (num30 != 0)
{
((StockInfo)list[i - 1]).Ma30 = Math.Round(tempma30 / num30, 2);
((StockInfo)list[i - 1]).Ma20 = Math.Round(tempma30 / num30, 2);
}

for (int j = i - 1; j < 9 + i; j++)
{
if (j < list.Count)
{
tempma10 += ((StockInfo)list[j]).NowIndex;
num10++;
if (j < 4+i)
{
tempma5 += ((StockInfo)list[j]).NowIndex;
num5++;
}
}
else
{
break;
}
}
if (num10 != 0)
{
((StockInfo)list[i - 1]).Ma10 = Math.Round(tempma10 / num10, 2);
}

if (((StockInfo)list[i - 1]).DayDate >= ma5end && num5 != 0)
{
((StockInfo)list[i - 1]).Ma5 = Math.Round(tempma5 / num5, 2);
}
}
else if (list.Count > 5)
{
for (int j = list.Count - 1; j >= i - 1; j--)
{
tempma30 += ((StockInfo)list[j]).NowIndex;
num30++;
}
if (num30 != 0)
{
((StockInfo)list[i - 1]).Ma30 = Math.Round(tempma30 / num30, 2);
((StockInfo)list[i - 1]).Ma20 = Math.Round(tempma30 / num30, 2);
((StockInfo)list[i - 1]).Ma10 = Math.Round(tempma30 / num30, 2);
}

for (int j = i - 1; j < 4 + i; j++)
{
if (j < list.Count)
{
tempma5 += ((StockInfo)list[j]).NowIndex;
num5++;
}
else
{
break;
}
}
if (num5 != 0)
{
((StockInfo)list[i - 1]).Ma5 = Math.Round(tempma5 / num5, 2);
}
}
else
{
for (int j = list.Count - 1; j >= i - 1; j--)
{
tempma30 += ((StockInfo)list[j]).NowIndex;
num30++;
}
if (num30 != 0)
{
((StockInfo)list[i - 1]).Ma30 = Math.Round(tempma30 / num30, 2);
((StockInfo)list[i - 1]).Ma20 = Math.Round(tempma30 / num30, 2);
((StockInfo)list[i - 1]).Ma10 = Math.Round(tempma30 / num30, 2);
((StockInfo)list[i - 1]).Ma5 = Math.Round(tempma30 / num30, 2);
}
}
}

return list;
}
...全文
636 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
ledmhcc 2010-07-08
  • 打赏
  • 举报
回复
[Quote=引用 17 楼 kkun_3yue3 的回复:]
稍微改下就可以呀


var para = data.Concat(Enumerable.Repeat(-1, duration - 1))
.ToArray();

其余都不变...
[/Quote]
试过了,结果正确。有个问题使得只能看而没法把你写的方法融合进程序
.net2005上没有system.linq可以引用,暂时也不可能把程序升级到.net3.5以上
十分感谢花费了大量时间来帮忙把程序优化到十分精短的程度
kkun_3yue3 2010-07-08
  • 打赏
  • 举报
回复
客气了,主要是LINQ的特性使代码看起来短了些...
kkun_3yue3 2010-07-07
  • 打赏
  • 举报
回复
我的思路是,把求maN提取成一个方法,这样传5,10,20,30就能分别满足ma5,ma10,ma20,ma30这样的要求,
代码正在调试,第一项和最后一项的求平均值有点问题,,
ledmhcc 2010-07-07
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 kkun_3yue3 的回复:]
是不是这样的
数据数据:1,2,3,4,5,6,7,8,9
计算方法
?12->1
123->2
234->3
345->4
456->5
567->6
678->7
789->8
89?-?9
把结果再赋回去??
1和9怎么取呢??正努力理解你的业务...
[/Quote]
你这样的例子就是pma3,3天一算的平直值
789->8
678->7
567->6
456->5
345->4
234->3
123->2
?12->1.5
??1->1

數據的话, stockinfo.nowindex 为9,8,7,6,5,4,3,2,1 就是ilist里有9条数据,9个stockinfo对象
算出的结果填进 stockinfo.ma3 (现实里是只有ma5,ma10,ma20,ma30这几个属性)

kkun_3yue3 2010-07-07
  • 打赏
  • 举报
回复
稍微改下就可以呀


var para = data.Concat(Enumerable.Repeat(-1, duration - 1))
.ToArray();

其余都不变...
ledmhcc 2010-07-07
  • 打赏
  • 举报
回复
[Quote=引用 15 楼 ledmhcc 的回复:]
引用 14 楼 kkun_3yue3 的回复:
测试代码

C# code
var input = new[] { 10, 21, 32, 43, 54, 65, 76, 87, 98 };

for (int i = 0; i < input.Length; i++) {
input[i] = (int)MABy(input, i, 3);
……

不好意思,……
[/Quote]
写错了。。。应该为
[0]应该= (10+21+32)/3 [1]=(21+32+43)/3 [2]=(32+43+54)/3 ...[7]=(87+98)/2,[8]=98/1
ledmhcc 2010-07-07
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 kkun_3yue3 的回复:]
测试代码

C# code
var input = new[] { 10, 21, 32, 43, 54, 65, 76, 87, 98 };

for (int i = 0; i < input.Length; i++) {
input[i] = (int)MABy(input, i, 3);
……
[/Quote]
不好意思,忘了说了,这个项目跑在2005上
我把你的代码在2008里建了个项目测试了下,发现在对所得值的理解上可能有偏差吧
现在计算结果出来的数组为 [0]10,[1]15,[2]19,[3]25,[4]32,[5]40,[6]49,[7]58,[8]68
按正确结果来看肯定是不对的,
new[] { 10, 21, 32, 43, 54, 65, 76, 87, 98 };
我期望拿到的是这样的结果
[0]应该= (10+21+32)/3 [1]=(21+32+43)/3 [2]=(32+43+54)/3 ...[7]=(58+68)/2,[8]=98/1
kkun_3yue3 2010-07-07
  • 打赏
  • 举报
回复
测试代码
            var input = new[] { 10, 21, 32, 43, 54, 65, 76, 87, 98 };

for (int i = 0; i < input.Length; i++) {
input[i] = (int)MABy(input, i, 3);
}
return;


private static double MABy(int[] data, int start,int duration) {
//前后分别补充两个-1,
var para = Enumerable.Repeat(-1, duration - 1)
.Concat(data)
.Concat(Enumerable.Repeat(-1, duration - 1))
.ToArray();

//跳过前start个,取duration个,排除补的-1,得出平均值
/*
para = para.Skip(start).ToArray();
para = para.Take(duration).ToArray();
para = para.Where(x => x > 0).ToArray();
var re = para.Average();
return re;
*/
return para
.Skip(start)
.Take(duration)
.Where(x => x > 0)
.Average();
}

不知道对不对,楼主验收吧,不及格叉出去,
kkun_3yue3 2010-07-06
  • 打赏
  • 举报
回复
是不是这样的
数据数据:1,2,3,4,5,6,7,8,9
计算方法
?12->1
123->2
234->3
345->4
456->5
567->6
678->7
789->8
89?-?9
把结果再赋回去??
1和9怎么取呢??正努力理解你的业务...
fj4408 2010-07-06
  • 打赏
  • 举报
回复
没有看明白。
ledmhcc 2010-07-06
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 kkun_3yue3 的回复:]
仅仅把你第一个方法的思路说一下吧
[/Quote]
传进来的list是一个股票的每天的收盘价格的集合,每天一条数据
我做的就是按30,20,10,5天来算出平均的pma值,在赋值到那条数据里去
当数据行数大于30的话,就要靠循环移动来取平均值,当前数据的收盘价和去前29天的相加再/30,就是当前数据的pma30的值,循环到下一条的时候就再往前推,pma20,10,5也是这个思路
liu_shang_fei 2010-07-06
  • 打赏
  • 举报
回复
学习学习
kkun_3yue3 2010-07-06
  • 打赏
  • 举报
回复
仅仅把你第一个方法的思路说一下吧
hihitang 2010-07-06
  • 打赏
  • 举报
回复
我们的预测好像不是这么做的。。。学习了
ledmhcc 2010-07-06
  • 打赏
  • 举报
回复
移动平均线(MA)是以道·琼斯的"平均成本概念"为理论基础,采用统计学中"移动平均"的原理,将一段时期内的股票价格平均值连成曲线,用来显示股价的历史波动情况,进而反映股价指数未来发展趋势的技术分析方法。它是道氏理论的形象化表述。
移动平均线依计算周期分为短期(如5日、10日)、中期(如30日) 和长期(如60日、120日)移动平均线。
移动平均线依算法分为算术移动平均线、线型加权移动平均线、阶梯形移动平均线、平滑移动平均线等多种,最为常用的是下面介绍的算术移动平均线。
(一)、计算方法:
   MA = (C1+C2+C3+……+Cn)/n
   C为每日收盘价。
   n为计算周期。一般n定为5,10,30,60
   最常用的是五日、十日和三十日的移动平均线。
   移动平均线通常与股价线一同使用。

移动平均线PMA 一、移动平均线及其意义 PMA是量的一种表现形式.比如指数的三日移动平均线,首先取得连续三日的三个指数,计算其平均值A,然后后移.去掉最先一个指数,增加新一日一个指数,再计算三个指数的平均值B.如此移动计算,得到一条三日移动平均线。同理,可得五日,六日,十日,十三日,三十日,七十日,二百日等移动平均线.移动平均线由样本数的多少决定了移动变化的急缓。样本数少,变化较急,称为快速线,因此多作为短线指标。样本数多,变化较缓,称为慢速线,在样本数适当多的时候,多作为中线或长线指标.重要的是,因为移动平均线是由一定样本的集合的连续移动计算产生,所以它的移动方向和速度代表了该集合的整体态势。这一点,正是人们所要利用的。
hihitang 2010-07-06
  • 打赏
  • 举报
回复
MS我做股票软件的时候没需要用到这个,不明白算来干嘛的!
LovingAlison 2010-07-06
  • 打赏
  • 举报
回复
不怎么懂什么意思
ledmhcc 2010-07-06
  • 打赏
  • 举报
回复
[C# code]
public IList MaNumPlus(IList list, DateTime startdate)
{
IList ma5 = new ArrayList();
IList ma10 = new ArrayList();
IList ma20 = new ArrayList();
IList ma30 = new ArrayList();
DateTime ma5end = startdate.AddDays(-10);
DateTime ma10end = startdate.AddDays(-20);
DateTime ma20end = startdate.AddDays(-40);
DateTime ma30end = startdate.AddDays(-60);

for (int i = 1; i <= list.Count; i++)
{
double tempma30 = 0;
double tempma20 = 0;
double tempma10 = 0;
double tempma5 = 0;
int num30 = 0;
int num20 = 0;
int num10 = 0;
int num5 = 0;

if (list.Count > 30)
{
for (int j = i - 1; j < 29 + i; j++)
{
if (j < list.Count)
{
tempma30 += ((StockInfo)list[j]).NowIndex;
num30++;
if (j < 19+i)
{
tempma20 += ((StockInfo)list[j]).NowIndex;
num20++;
}
if (j < 9+i)
{
tempma10 += ((StockInfo)list[j]).NowIndex;
num10++;
}
if (j < 4+i)
{
tempma5 += ((StockInfo)list[j]).NowIndex;
num5++;
}
}
else
{
break;
}
}
if (num30 != 0)
{
((StockInfo)list[i - 1]).Ma30 = Math.Round(tempma30 / num30, 2);
}

if (((StockInfo)list[i - 1]).DayDate >= ma20end && num20 != 0)
{
((StockInfo)list[i - 1]).Ma20 = Math.Round(tempma20 / num20, 2);
}

if (((StockInfo)list[i - 1]).DayDate >= ma10end && num10 != 0)
{
((StockInfo)list[i - 1]).Ma10 = Math.Round(tempma10 / num10, 2);
}

if (((StockInfo)list[i - 1]).DayDate >= ma5end && num5 !=0)
{
((StockInfo)list[i - 1]).Ma5 = Math.Round(tempma5 / num5, 2);
}
}
else if (list.Count > 20)
{
for (int j = list.Count - 1; j >= i - 1; j--)
{
tempma30 += ((StockInfo)list[j]).NowIndex;
num30++;
}
if (num30 != 0)
{
((StockInfo)list[i - 1]).Ma30 = Math.Round(tempma30 / num30, 2);
}

for (int j = i - 1; j < 19 + i; j++)
{
if (j < list.Count)
{
tempma20 += ((StockInfo)list[j]).NowIndex;
num20++;
if (j < 9+i)
{
tempma10 += ((StockInfo)list[j]).NowIndex;
num10++;
}
if (j < 4+i)
{
tempma5 += ((StockInfo)list[j]).NowIndex;
num5++;
}
}
else
{
break;
}
}
if (num20 != 0)
{
((StockInfo)list[i - 1]).Ma20 = Math.Round(tempma20 / num20, 2);
}

if (((StockInfo)list[i - 1]).DayDate >= ma10end && num10 != 0)
{
((StockInfo)list[i - 1]).Ma10 = Math.Round(tempma10 / num10, 2);
}

if (((StockInfo)list[i - 1]).DayDate >= ma5end && num5 != 0)
{
((StockInfo)list[i - 1]).Ma5 = Math.Round(tempma5 / num5, 2);
}
}
else if (list.Count > 10)
{
for (int j = list.Count - 1; j >= i - 1; j--)
{
tempma30 += ((StockInfo)list[j]).NowIndex;
num30++;
}
if (num30 != 0)
{
((StockInfo)list[i - 1]).Ma30 = Math.Round(tempma30 / num30, 2);
((StockInfo)list[i - 1]).Ma20 = Math.Round(tempma30 / num30, 2);
}

for (int j = i - 1; j < 9 + i; j++)
{
if (j < list.Count)
{
tempma10 += ((StockInfo)list[j]).NowIndex;
num10++;
if (j < 4+i)
{
tempma5 += ((StockInfo)list[j]).NowIndex;
num5++;
}
}
else
{
break;
}
}
if (num10 != 0)
{
((StockInfo)list[i - 1]).Ma10 = Math.Round(tempma10 / num10, 2);
}

if (((StockInfo)list[i - 1]).DayDate >= ma5end && num5 != 0)
{
((StockInfo)list[i - 1]).Ma5 = Math.Round(tempma5 / num5, 2);
}
}
else if (list.Count > 5)
{
for (int j = list.Count - 1; j >= i - 1; j--)
{
tempma30 += ((StockInfo)list[j]).NowIndex;
num30++;
}
if (num30 != 0)
{
((StockInfo)list[i - 1]).Ma30 = Math.Round(tempma30 / num30, 2);
((StockInfo)list[i - 1]).Ma20 = Math.Round(tempma30 / num30, 2);
((StockInfo)list[i - 1]).Ma10 = Math.Round(tempma30 / num30, 2);
}

for (int j = i - 1; j < 4 + i; j++)
{
if (j < list.Count)
{
tempma5 += ((StockInfo)list[j]).NowIndex;
num5++;
}
else
{
break;
}
}
if (num5 != 0)
{
((StockInfo)list[i - 1]).Ma5 = Math.Round(tempma5 / num5, 2);
}
}
else
{
for (int j = list.Count - 1; j >= i - 1; j--)
{
tempma30 += ((StockInfo)list[j]).NowIndex;
num30++;
}
if (num30 != 0)
{
((StockInfo)list[i - 1]).Ma30 = Math.Round(tempma30 / num30, 2);
((StockInfo)list[i - 1]).Ma20 = Math.Round(tempma30 / num30, 2);
((StockInfo)list[i - 1]).Ma10 = Math.Round(tempma30 / num30, 2);
((StockInfo)list[i - 1]).Ma5 = Math.Round(tempma30 / num30, 2);
}
}
}

return list;
}
[/code]
ledmhcc 2010-07-06
  • 打赏
  • 举报
回复
C#

public IList MaNumPlus(IList list, DateTime startdate)
{
IList ma5 = new ArrayList();
IList ma10 = new ArrayList();
IList ma20 = new ArrayList();
IList ma30 = new ArrayList();
DateTime ma5end = startdate.AddDays(-10);
DateTime ma10end = startdate.AddDays(-20);
DateTime ma20end = startdate.AddDays(-40);
DateTime ma30end = startdate.AddDays(-60);

for (int i = 1; i <= list.Count; i++)
{
double tempma30 = 0;
double tempma20 = 0;
double tempma10 = 0;
double tempma5 = 0;
int num30 = 0;
int num20 = 0;
int num10 = 0;
int num5 = 0;

if (list.Count > 30)
{
for (int j = i - 1; j < 29 + i; j++)
{
if (j < list.Count)
{
tempma30 += ((StockInfo)list[j]).NowIndex;
num30++;
if (j < 19+i)
{
tempma20 += ((StockInfo)list[j]).NowIndex;
num20++;
}
if (j < 9+i)
{
tempma10 += ((StockInfo)list[j]).NowIndex;
num10++;
}
if (j < 4+i)
{
tempma5 += ((StockInfo)list[j]).NowIndex;
num5++;
}
}
else
{
break;
}
}
if (num30 != 0)
{
((StockInfo)list[i - 1]).Ma30 = Math.Round(tempma30 / num30, 2);
}

if (((StockInfo)list[i - 1]).DayDate >= ma20end && num20 != 0)
{
((StockInfo)list[i - 1]).Ma20 = Math.Round(tempma20 / num20, 2);
}

if (((StockInfo)list[i - 1]).DayDate >= ma10end && num10 != 0)
{
((StockInfo)list[i - 1]).Ma10 = Math.Round(tempma10 / num10, 2);
}

if (((StockInfo)list[i - 1]).DayDate >= ma5end && num5 !=0)
{
((StockInfo)list[i - 1]).Ma5 = Math.Round(tempma5 / num5, 2);
}
}
else if (list.Count > 20)
{
for (int j = list.Count - 1; j >= i - 1; j--)
{
tempma30 += ((StockInfo)list[j]).NowIndex;
num30++;
}
if (num30 != 0)
{
((StockInfo)list[i - 1]).Ma30 = Math.Round(tempma30 / num30, 2);
}

for (int j = i - 1; j < 19 + i; j++)
{
if (j < list.Count)
{
tempma20 += ((StockInfo)list[j]).NowIndex;
num20++;
if (j < 9+i)
{
tempma10 += ((StockInfo)list[j]).NowIndex;
num10++;
}
if (j < 4+i)
{
tempma5 += ((StockInfo)list[j]).NowIndex;
num5++;
}
}
else
{
break;
}
}
if (num20 != 0)
{
((StockInfo)list[i - 1]).Ma20 = Math.Round(tempma20 / num20, 2);
}

if (((StockInfo)list[i - 1]).DayDate >= ma10end && num10 != 0)
{
((StockInfo)list[i - 1]).Ma10 = Math.Round(tempma10 / num10, 2);
}

if (((StockInfo)list[i - 1]).DayDate >= ma5end && num5 != 0)
{
((StockInfo)list[i - 1]).Ma5 = Math.Round(tempma5 / num5, 2);
}
}
else if (list.Count > 10)
{
for (int j = list.Count - 1; j >= i - 1; j--)
{
tempma30 += ((StockInfo)list[j]).NowIndex;
num30++;
}
if (num30 != 0)
{
((StockInfo)list[i - 1]).Ma30 = Math.Round(tempma30 / num30, 2);
((StockInfo)list[i - 1]).Ma20 = Math.Round(tempma30 / num30, 2);
}

for (int j = i - 1; j < 9 + i; j++)
{
if (j < list.Count)
{
tempma10 += ((StockInfo)list[j]).NowIndex;
num10++;
if (j < 4+i)
{
tempma5 += ((StockInfo)list[j]).NowIndex;
num5++;
}
}
else
{
break;
}
}
if (num10 != 0)
{
((StockInfo)list[i - 1]).Ma10 = Math.Round(tempma10 / num10, 2);
}

if (((StockInfo)list[i - 1]).DayDate >= ma5end && num5 != 0)
{
((StockInfo)list[i - 1]).Ma5 = Math.Round(tempma5 / num5, 2);
}
}
else if (list.Count > 5)
{
for (int j = list.Count - 1; j >= i - 1; j--)
{
tempma30 += ((StockInfo)list[j]).NowIndex;
num30++;
}
if (num30 != 0)
{
((StockInfo)list[i - 1]).Ma30 = Math.Round(tempma30 / num30, 2);
((StockInfo)list[i - 1]).Ma20 = Math.Round(tempma30 / num30, 2);
((StockInfo)list[i - 1]).Ma10 = Math.Round(tempma30 / num30, 2);
}

for (int j = i - 1; j < 4 + i; j++)
{
if (j < list.Count)
{
tempma5 += ((StockInfo)list[j]).NowIndex;
num5++;
}
else
{
break;
}
}
if (num5 != 0)
{
((StockInfo)list[i - 1]).Ma5 = Math.Round(tempma5 / num5, 2);
}
}
else
{
for (int j = list.Count - 1; j >= i - 1; j--)
{
tempma30 += ((StockInfo)list[j]).NowIndex;
num30++;
}
if (num30 != 0)
{
((StockInfo)list[i - 1]).Ma30 = Math.Round(tempma30 / num30, 2);
((StockInfo)list[i - 1]).Ma20 = Math.Round(tempma30 / num30, 2);
((StockInfo)list[i - 1]).Ma10 = Math.Round(tempma30 / num30, 2);
((StockInfo)list[i - 1]).Ma5 = Math.Round(tempma30 / num30, 2);
}
}
}

return list;
}

110,533

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧