搜尋此網誌

2013年3月22日 星期五

簡單的c範例,對於配股的累進

/*此範例可用於換算配息或配股後在加進原本股數,需要幾年可以攤平。*/
int main (void)
{
int tmp, year = 20;
float stock_price = 11, number = 10, Distributions = 1.0, x, y;
/*[輸入參數] ==> year:輸入幾年、stock_price:目前股價或預測未來之平均股價、
number:原始股數、Distributions:配息*/
x = number;
for (tmp = 0; tmp <= year; tmp ++) {
y = x * (Distributions / stock_price); /*現金殖利率換算*/
printf("%d year\t=>[stock price]:%f, [number]:%f, [cash]:%f\n", tmp, stock_price, x, y);
x += y;
}
return 0
}
/*stock price:每年的股價、number:每年累積的總股數、cash:每年總股數所配的總股息*/

0 year  =>[stock price]:11.000000, [number]:10.000000, [cash]:0.909091
1 year  =>[stock price]:11.000000, [number]:10.909091, [cash]:0.991736
2 year  =>[stock price]:11.000000, [number]:11.900826, [cash]:1.081893
3 year  =>[stock price]:11.000000, [number]:12.982719, [cash]:1.180247
4 year  =>[stock price]:11.000000, [number]:14.162967, [cash]:1.287542
5 year  =>[stock price]:11.000000, [number]:15.450509, [cash]:1.404592
6 year  =>[stock price]:11.000000, [number]:16.855101, [cash]:1.532282
7 year  =>[stock price]:11.000000, [number]:18.387383, [cash]:1.671580
8 year  =>[stock price]:11.000000, [number]:20.058962, [cash]:1.823542
9 year  =>[stock price]:11.000000, [number]:21.882504, [cash]:1.989318
10 year =>[stock price]:11.000000, [number]:23.871822, [cash]:2.170166
11 year =>[stock price]:11.000000, [number]:26.041988, [cash]:2.367454
12 year =>[stock price]:11.000000, [number]:28.409443, [cash]:2.582677
13 year =>[stock price]:11.000000, [number]:30.992119, [cash]:2.817465
14 year =>[stock price]:11.000000, [number]:33.809586, [cash]:3.073599
15 year =>[stock price]:11.000000, [number]:36.883183, [cash]:3.353017
16 year =>[stock price]:11.000000, [number]:40.236198, [cash]:3.657836
17 year =>[stock price]:11.000000, [number]:43.894035, [cash]:3.990367
18 year =>[stock price]:11.000000, [number]:47.884403, [cash]:4.353127
19 year =>[stock price]:11.000000, [number]:52.237530, [cash]:4.748867
20 year =>[stock price]:11.000000, [number]:56.986397, [cash]:5.180582

沒有留言:

張貼留言