-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCaculate.php
More file actions
77 lines (63 loc) · 1.63 KB
/
Caculate.php
File metadata and controls
77 lines (63 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
namespace Stock\Caculate;
class Caculate
{
protected $stockInfo;
protected $commissionList;
public function __construct(array $StockInfo)
{
$this -> stockInfo = $StockInfo;
}
public function commission(array $StockInfo)
{
$totalBuy = 0;
$totalSell = 0;
for($idx = 10; $idx < 20; $idx += 2)
{
$totalBuy += $StockInfo[$idx];
}
for($idx = 20; $idx < 30; $idx += 2)
{
$totalSell += $StockInfo[$idx];
}
$commission = ($totalBuy - $totalSell) / 100;
return number_format($commission, 2);
}
public function commissionList()
{
$stockList = $this -> stockInfo;
$list = array();
foreach ($stockList as $value)
{
$list[$value[0]] = $this -> Commission($value);
}
asort($list);
return $this -> commissionList = $list;
}
public function getAvg($historyData)
{
$result = array();
$result['stockCode'] = $historyData[0];
$count = count($historyData[1]);
$raise = 1.0;
$price = 0.0;
foreach ($historyData[1] as $value)
{
$raise *= (1 + (float)$value[4] / 100);
$price += (float)$value[2];
}
$weekRaise = 1.0;
$weekPrice = 0.0;
for($day = 0; $day < 6; $day++)
{
$value = $historyData[1][$day];
$weekRaise *= (1 + (float)$value[4] / 100);
$weekPrice += (float)$value[2];
}
$result['raise'] = number_format($raise, 2) - 1;
$result['avgPrice'] = number_format($price / $count, 2);
$result['weekRaise'] = number_format($weekRaise, 2) - 1;
$result['weekPrice'] = number_format($weekPrice / 6, 2);
return $result;
}
}