模拟纳指stock的小例子

一个模拟纳指stock的小例子:

#include <stdio.h>
#include <stdlib.h>#define MAX_YEAR          100 
#define ONE_YEAR_DAYS     240#define BEGIN_YUAN        10000
#define ONE_ADD_YUAN     4000
#define ONE_ADD_DAY      20
#define GOLD_FLOW_TIMES  3
#define GOLD_ADD_TIMES   1#define GOLD_POS          0.618// 2000 年开始
int arrBgn[100] = {0};int main(int argc, char* argv[])
{arrBgn[0] = 4000;arrBgn[1] = 3000;arrBgn[2] = 2000;arrBgn[3] = 1000;arrBgn[4] = 2000;arrBgn[5] = 2100;arrBgn[6] = 2300;arrBgn[7] = 2500;arrBgn[8] = 2400;arrBgn[9] = 1400;arrBgn[10] = 2200;arrBgn[11] = 2600;arrBgn[12] = 2600;arrBgn[13] = 3100;arrBgn[14] = 4100;arrBgn[15] = 4500;arrBgn[16] = 4300;arrBgn[17] = 5300;arrBgn[18] = 7400;arrBgn[19] = 6600;arrBgn[20] = 9100;arrBgn[21] = 9100;int iOwnYuan = BEGIN_YUAN;float iTotalYuan = BEGIN_YUAN;int iYearNum = MAX_YEAR;int iOneAddYuan = ONE_ADD_YUAN;int iOndAddDayNum = ONE_ADD_DAY;if (2 == argc){iYearNum = atoi(argv[1]);}else if (3 == argc){iYearNum = atoi(argv[1]);iOneAddYuan = atoi(argv[2]);}else if (4 == argc){iYearNum = atoi(argv[1]);iOneAddYuan = atoi(argv[2]);iOndAddDayNum = atoi(argv[3]);}printf("-----------------------------stock------------------------------------\n");printf("stock.exe 1 1000 5                                         -----------\n");printf("iBeginYuan:%d             \n", BEGIN_YUAN);printf("iYearNum:%d\n", iYearNum);printf("iOneAddYuan:%d              ", iOneAddYuan);printf("iOndAddDayNum:%d\n", iOndAddDayNum);printf("------------------------------------------------------------------------\n");// 算法1//for (int i = 0; i < iYearNum; i++)//{//	//	if (0 != arrBgn[i+1])//	{//		float iAdd = arrBgn[i+1] - arrBgn[i];//		float fFlow = (iAdd *100 / ONE_YEAR_DAYS)/arrBgn[i];////		for (int j = 0; j < ONE_YEAR_DAYS; j++)//		{//			if (0 == j % iOndAddDayNum)//			{//				for (int k = 0; k < iOndAddDayNum; k++)//				{//					iTotalYuan = iTotalYuan + iTotalYuan *fFlow / 100;//				}////				iTotalYuan += iOneAddYuan;//				iOwnYuan += iOneAddYuan;//			}//		}////		iTotalYuan = iTotalYuan * 99 /100;////		printf("year:%d; iTotalYuan:%d, iOwnYuan:%d, rate:%d!\n\n", i+1, iTotalYuan, iOwnYuan, (iTotalYuan-iOwnYuan)*100/iOwnYuan);//	////	}//}// 算法2for (int i = 0; i < iYearNum; i++){if (0 != arrBgn[i + 1]){float iAdd = arrBgn[i + 1] - arrBgn[i];float fFlow = (iAdd * 100 / ONE_YEAR_DAYS) / arrBgn[i];int iGoldDay = ONE_YEAR_DAYS * GOLD_POS;float iGoldAdd = iAdd / GOLD_POS;float fGoldFlow = (iGoldAdd * 1000 / iGoldDay) / arrBgn[i];int nGoldtime = 0;float iGoldAdd2 = arrBgn[i + 1] - (iGoldAdd + arrBgn[i]);float fGoldFlow2 = (iGoldAdd2 * 1000 / (ONE_YEAR_DAYS- iGoldDay)) / arrBgn[i];int nGoldtime2 = 0;int iPreOwnYuan = iOwnYuan;for (int j = 0; j < iGoldDay; j++){if (0 == j % iOndAddDayNum){for (int k = 0; k < iOndAddDayNum; k++){iTotalYuan = iTotalYuan + iTotalYuan *fGoldFlow / 1000;}if (fGoldFlow < 0){iTotalYuan += iOneAddYuan * GOLD_FLOW_TIMES;iOwnYuan += iOneAddYuan * GOLD_FLOW_TIMES;}else{iTotalYuan += iOneAddYuan * GOLD_ADD_TIMES;iOwnYuan += iOneAddYuan * GOLD_ADD_TIMES;}	nGoldtime++;}}printf("yearPos:%d: iTotalYuan:%0.f, iOwnYuan:%d, rate:%0.1f,flow1:%.1f, flow2:%.1f, add:%d!\n", i + 1, iTotalYuan, iOwnYuan, (iTotalYuan - iOwnYuan) * 100 / iOwnYuan, fGoldFlow, fGoldFlow2, iOwnYuan - iPreOwnYuan);iPreOwnYuan = iOwnYuan;for (int j = iGoldDay; j < ONE_YEAR_DAYS; j++){if (0 == j % iOndAddDayNum){for (int k = 0; k < iOndAddDayNum; k++){iTotalYuan = iTotalYuan + iTotalYuan *fGoldFlow2 / 1000;}if (fGoldFlow < 0){iTotalYuan += iOneAddYuan * GOLD_FLOW_TIMES;iOwnYuan += iOneAddYuan * GOLD_FLOW_TIMES;}else{iTotalYuan += iOneAddYuan * GOLD_ADD_TIMES;iOwnYuan += iOneAddYuan * GOLD_ADD_TIMES;}}nGoldtime2++;}iTotalYuan = iTotalYuan * 99 / 100;printf("year:%d: iTotalYuan:%0.0f, iOwnYuan:%d, rate:%0.1f, add:%d, bgn:%d, end:%d,\n\n", i + 1, iTotalYuan, iOwnYuan, (iTotalYuan - iOwnYuan) * 100 / iOwnYuan, iOwnYuan - iPreOwnYuan, arrBgn[i], arrBgn[i + 1]);}}// 算法3//for (int i = 0; i < iYearNum; i++)//{////	if (0 != arrBgn[i + 1])//	{//		float iAdd = arrBgn[i + 1] - arrBgn[i];//		float fFlow = (iAdd * 100 / ONE_YEAR_DAYS) / arrBgn[i];////		int iGoldDay = ONE_YEAR_DAYS * GOLD_POS;//		float iGoldAdd = iAdd / GOLD_POS;//		float fGoldFlow = (iGoldAdd * 1000 / iGoldDay) / arrBgn[i];//		int nGoldtime = 0;////		float iGoldAdd2 = arrBgn[i + 1] - (iGoldAdd + arrBgn[i]);//		float fGoldFlow2 = (iGoldAdd2 * 1000 / (ONE_YEAR_DAYS - iGoldDay)) / arrBgn[i];//		int nGoldtime2 = 0;//////		int nFlowAddYuan = iOneAddYuan;//		bool bFlowAddYuan = false;//////		for (int j = 0; j < iGoldDay; j++)//		{//			if (0 == j % iOndAddDayNum)//			{//				for (int k = 0; k < iOndAddDayNum; k++)//				{//					iTotalYuan = iTotalYuan + iTotalYuan *fGoldFlow / 1000;//				}////				if (fGoldFlow < 0)//				{//					iTotalYuan += nFlowAddYuan;//					iOwnYuan += nFlowAddYuan;//					bFlowAddYuan = true;//				}//				else//				{//					iTotalYuan += iOneAddYuan * GOLD_ADD_TIMES;//					iOwnYuan += iOneAddYuan * GOLD_ADD_TIMES;//					bFlowAddYuan = false;//				}//				nGoldtime++;////				if (bFlowAddYuan)//				{//					if (nFlowAddYuan <= 2000)//					{//						nFlowAddYuan = 2000;//					}//					else if (nFlowAddYuan <= 3000)//					{//						nFlowAddYuan = 3000;//					}//					else if (nFlowAddYuan <= 5000)//					{//						nFlowAddYuan = 5000;//					}//					else//					{//						nFlowAddYuan = iOneAddYuan;//					}						//				}//				else//				{//					nFlowAddYuan = iOneAddYuan;//				}////			}//		}////		printf("yearPos:%d; iTotalYuan:%0.f, iOwnYuan:%d, rate:%0.1f,flow1:%.1f, flow2:%.1f!\n", i + 1, iTotalYuan, iOwnYuan, (iTotalYuan - iOwnYuan) * 100 / iOwnYuan, fGoldFlow, fGoldFlow2);////		for (int j = iGoldDay; j < ONE_YEAR_DAYS; j++)//		{//			if (0 == j % iOndAddDayNum)//			{//				for (int k = 0; k < iOndAddDayNum; k++)//				{//					iTotalYuan = iTotalYuan + iTotalYuan *fGoldFlow2 / 1000;//				}////				if (fGoldFlow < 0)//				{//					iTotalYuan += nFlowAddYuan;//					iOwnYuan += nFlowAddYuan;//					bFlowAddYuan = true;//				}//				else//				{//					iTotalYuan += iOneAddYuan * GOLD_ADD_TIMES;//					iOwnYuan += iOneAddYuan * GOLD_ADD_TIMES;//					bFlowAddYuan = false;//				}////			}//			nGoldtime2++;////			if (bFlowAddYuan)//			{//				if (nFlowAddYuan <= 2000)//				{//					nFlowAddYuan = 2000;//				}//				else if (nFlowAddYuan <= 3000)//				{//					nFlowAddYuan = 3000;//				}//				else if (nFlowAddYuan <= 5000)//				{//					nFlowAddYuan = 5000;//				}//				else//				{//					nFlowAddYuan = iOneAddYuan;//				}//			}//			else//			{//				nFlowAddYuan = iOneAddYuan;//			}//		}////		iTotalYuan = iTotalYuan * 99 / 100;////		printf("year:%d; iTotalYuan:%0.0f, iOwnYuan:%d, rate:%0.1f!\n\n", i + 1, iTotalYuan, iOwnYuan, (iTotalYuan - iOwnYuan) * 100 / iOwnYuan);//////	}//}getchar();
return 0;
}

运行结果如下:

-----------------------------stock------------------------------------
stock.exe 1 1000 5                                         -----------
iBeginYuan:10000
iYearNum:100
iOneAddYuan:4000              iOndAddDayNum:20
------------------------------------------------------------------------
yearPos:1: iTotalYuan:86340, iOwnYuan:106000, rate:-18.5,flow1:-2.7, flow2:1.7, add:96000!
year:1: iTotalYuan:147768, iOwnYuan:154000, rate:-4.0, add:48000, bgn:4000, end:3000,yearPos:2: iTotalYuan:157785, iOwnYuan:250000, rate:-36.9,flow1:-3.6, flow2:2.2, add:96000!
year:2: iTotalYuan:237703, iOwnYuan:298000, rate:-20.2, add:48000, bgn:3000, end:2000,yearPos:3: iTotalYuan:166375, iOwnYuan:394000, rate:-57.8,flow1:-5.5, flow2:3.4, add:96000!
year:3: iTotalYuan:268097, iOwnYuan:442000, rate:-39.3, add:48000, bgn:2000, end:1000,yearPos:4: iTotalYuan:1604507, iOwnYuan:474000, rate:238.5,flow1:10.9, flow2:-6.7, add:32000!
year:4: iTotalYuan:939397, iOwnYuan:490000, rate:91.7, add:16000, bgn:1000, end:2000,yearPos:5: iTotalYuan:1058497, iOwnYuan:522000, rate:102.8,flow1:0.5, flow2:-0.3, add:32000!
year:5: iTotalYuan:1035802, iOwnYuan:538000, rate:92.5, add:16000, bgn:2000, end:2100,yearPos:6: iTotalYuan:1257928, iOwnYuan:570000, rate:120.7,flow1:1.0, flow2:-0.6, add:32000!
year:6: iTotalYuan:1198725, iOwnYuan:586000, rate:104.6, add:16000, bgn:2100, end:2300,yearPos:7: iTotalYuan:1429801, iOwnYuan:618000, rate:131.4,flow1:1.0, flow2:-0.6, add:32000!
year:7: iTotalYuan:1366413, iOwnYuan:634000, rate:115.5, add:16000, bgn:2300, end:2500,yearPos:8: iTotalYuan:1367174, iOwnYuan:730000, rate:87.3,flow1:-0.4, flow2:0.3, add:96000!
year:8: iTotalYuan:1430819, iOwnYuan:778000, rate:83.9, add:48000, bgn:2500, end:2400,yearPos:9: iTotalYuan:760419, iOwnYuan:874000, rate:-13.0,flow1:-4.6, flow2:2.8, add:96000!
year:9: iTotalYuan:993269, iOwnYuan:922000, rate:7.7, add:48000, bgn:2400, end:1400,yearPos:10: iTotalYuan:2742086, iOwnYuan:954000, rate:187.4,flow1:6.2, flow2:-3.8, add:32000!
year:10: iTotalYuan:2009748, iOwnYuan:970000, rate:107.2, add:16000, bgn:1400, end:2200,yearPos:11: iTotalYuan:2798365, iOwnYuan:1002000, rate:179.3,flow1:2.0, flow2:-1.2, add:32000!
year:11: iTotalYuan:2527575, iOwnYuan:1018000, rate:148.3, add:16000, bgn:2200, end:2600,yearPos:12: iTotalYuan:2559575, iOwnYuan:1050000, rate:143.8,flow1:0.0, flow2:0.0, add:32000!
year:12: iTotalYuan:2549820, iOwnYuan:1066000, rate:139.2, add:16000, bgn:2600, end:2600,yearPos:13: iTotalYuan:3605498, iOwnYuan:1098000, rate:228.4,flow1:2.1, flow2:-1.3, add:32000!
year:13: iTotalYuan:3233944, iOwnYuan:1114000, rate:190.3, add:16000, bgn:2600, end:3100,yearPos:14: iTotalYuan:5721794, iOwnYuan:1146000, rate:399.3,flow1:3.5, flow2:-2.2, add:32000!
year:14: iTotalYuan:4776810, iOwnYuan:1162000, rate:311.1, add:16000, bgn:3100, end:4100,yearPos:15: iTotalYuan:5699752, iOwnYuan:1194000, rate:377.4,flow1:1.1, flow2:-0.7, add:32000!
year:15: iTotalYuan:5369920, iOwnYuan:1210000, rate:343.8, add:16000, bgn:4100, end:4500,yearPos:16: iTotalYuan:5060957, iOwnYuan:1306000, rate:287.5,flow1:-0.5, flow2:0.3, add:96000!
year:16: iTotalYuan:5179411, iOwnYuan:1354000, rate:282.5, add:48000, bgn:4500, end:4300,yearPos:17: iTotalYuan:7814111, iOwnYuan:1386000, rate:463.8,flow1:2.5, flow2:-1.6, add:32000!
year:17: iTotalYuan:6841427, iOwnYuan:1402000, rate:388.0, add:16000, bgn:4300, end:5300,yearPos:18: iTotalYuan:13706282, iOwnYuan:1434000, rate:855.8,flow1:4.3, flow2:-2.7, add:32000!
year:18: iTotalYuan:10977905, iOwnYuan:1450000, rate:657.1, add:16000, bgn:5300, end:7400,yearPos:19: iTotalYuan:9173795, iOwnYuan:1546000, rate:493.4,flow1:-1.2, flow2:0.7, add:96000!
year:19: iTotalYuan:9673800, iOwnYuan:1594000, rate:506.9, add:48000, bgn:7400, end:6600,yearPos:20: iTotalYuan:18783782, iOwnYuan:1626000, rate:1055.2,flow1:4.1, flow2:-2.5, add:32000!
year:20: iTotalYuan:15181152, iOwnYuan:1642000, rate:824.6, add:16000, bgn:6600, end:9100,yearPos:21: iTotalYuan:15213152, iOwnYuan:1674000, rate:808.8,flow1:0.0, flow2:0.0, add:32000!
year:21: iTotalYuan:15076860, iOwnYuan:1690000, rate:792.1, add:16000, bgn:9100, end:9100,

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/462179.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

android4.0.3 修改启动动画和开机声音

1. Linux 系统启动&#xff0c;出现Linux小企鹅画面(reboot)(Android 1.5及以上版本已经取消加载图片)&#xff1b;2. Android平台启动初始化&#xff0c;出现"A N D R I O D"文字字样画面&#xff1b;3. Android平台图形系统启动&#xff0c;出现含闪动的ANDROID字样…

函数式C代码

代码如下&#xff1a; #include <stdlib.h> #include <stdio.h> typedef char String[32]; typedef FILE* File;typedef struct _Employee {String name;int age;int salary;struct _Employee *next; } *Employee;typedef void (*Callback)(Employee);/* High Orde…

VMWare虚拟机NAT模式静态IP联网配置

使用静态IP&#xff0c;而不选用DHCP的主要原因是避免每次重启计算机后&#xff0c;虚拟机系统的IP发生变化&#xff0c;导致常常需要修改宿主机器远程连接虚拟机服务(例如Mysql) 环境 项目版本号VmwareVmware Workstation Pro 15UbuntuUbuntu 18.04.2 LTS关键配置 虚拟网络编辑…

ffmpeg调整缩放裁剪视频的基础知识(转)

源网址&#xff1a;ffmpeg调整缩放裁剪视频的基础知识 - yongfengnice - 博客园 1. resize and scale video 调整视频的大小和尺寸 1-1.调整视频大小(resize)是改变视频的宽度和高度。 使用-s参数实现&#xff0c;语法&#xff1a;ffmpeg -i input_file -s wxh output_fi…

学习C语言的工具

书籍&#xff1a;《C Primer Plus》 编译器&#xff1a;code::blocks 编辑器: gedit转载于:https://www.cnblogs.com/owenbeta/archive/2012/03/07/2384286.html

二手房买卖砍价最新攻略 帮你花少钱买好房

漫天要价&#xff0c;就地还钱&#xff0c;意思是说&#xff1a;讲价要狠&#xff0c;心软则败。很多刚需们忍不住要出手了&#xff0c;市场上的好房源也越来越多&#xff0c;如何淘到你我中意的房源&#xff0c;同时我们又不用多花冤枉钱?精心准备热乎出炉&#xff0c;二手房…

lastal

http://last.cbrc.jp/doc/lastal.html This program finds local alignments between query sequences, and reference sequences that have been prepared using lastdb 转载于:https://www.cnblogs.com/0820LL/p/11136767.html

伽罗华有限域的FEC

FEC算法_cloudfly_cn的博客-CSDN博客_fec算法 I 基于IP的语音和视频通话业务为了实时性&#xff0c;一般都是采用UDP进行传输&#xff0c;基站无线一般配置UM模式的RLC承载&#xff0c;因此丢包是不可避免的&#xff0c;在小区信号的边沿则丢包率会更高&#xff1b;为了通话的…

mlecms v2.2版权

inc\tools\smarty 下的Smarty.class.php文件。找到 187行左右 我们会发现原来的 $dopud $_template->libfile($dopud);已经变成了$_headers $this->listaops($_headers);我们按照之前版本的方法将其注释掉&#xff0c;刷新&#xff0c;果然没有了。到这里还不算完&#…

如何求矩阵的逆矩阵

如何求矩阵的逆矩阵 - 叮叮当当sunny - 博客园 求逆矩阵最有效的方法是初等变换法&#xff08;虽然还有别的方法&#xff09;。如果要求方阵 AA 的逆矩阵&#xff0c;标准的做法是&#xff1a; 将矩阵 AA 与单位矩阵 II 排成一个新的矩阵 (AI)(AI)将此新矩阵 (AI)(AI) 做初等…

一篇英文文档中找出频数最多的10个单词

"""一篇英文文档中找出频数最多的10个单词collections: Counter 提供计数器工具以支持方便和快速的计数 most_common(n) 返回n个最常见元素及其计数的列表&#xff0c;从最常见到最少。 如果省略nNone&#xff0c;则 most_c…

中断共享(硬件角度)

中断共享&#xff1a; 和别人讨论的时候&#xff0c;谈到了中断共享&#xff0c;下面记录下几种不同的情况&#xff1a;1、一个IP模块中只有一个中断引脚连接到中断控制器&#xff0c;该IP模块中只有一个部件可以产生中断请求&#xff1b;2、一个IP模块中只有一个中断引脚连…

web绿色环境搭建

开篇 需要的软件及他们各自的版本apache-tomcat-6.0.32(绿色版&#xff0c;能直接下载得到)java-jdk1.6.0_25/jre6(安装后制作的绿色版&#xff0c;不能直接下载得到)MyEclipse6.5(安装后制作的绿色版&#xff0c;不能直接下载得到)MySql_5.1.3(绿色版&#xff0c;直接下载得到…

Babel+vscode实现APICloud开发中兼容ES6及以上代码

本文出自APICloud官方论坛&#xff0c; 感谢论坛版主 penghuoyan 的分享。 使用APICloud开发时&#xff0c;考虑到兼容问题一直使用ES5开发&#xff0c;时间越久感觉越落后&#xff0c;整理了一个兼容ES6的开发环境&#xff0c;供大家参考。 步骤1&#xff1a; 安装Node开发环境…

sql完整性

转至&#xff1a;http://www.cnblogs.com/2007/archive/2007/08/24/868428.html更新数据库时&#xff0c;表中不能出现不符合完整性要求的记录&#xff0c;以保证为用户提供正确、有效的数据。实现该目的最直接的方法&#xff0c;是在编写数据库应用程序时&#xff0c;对每个更…

html小知识

字符文本中字符太多 一、正确&#xff1a; <a hrefShowFile.aspx?ID<%# DataBinder.Eval(Container.DataItem, "ID") %>>查看文件</a> 二、错误&#xff1a; <a href"ShowFile.aspx?ID<%# DataBinder.Eval(Container.DataItem, ID) %…

基本数据结构:树(tree)

参考博客 &#xff08;1&#xff09;基本数据结构&#xff1a;树&#xff08;tree&#xff09; - andyidea - 博客园 &#xff08;2&#xff09;《大话数据结构》 &#xff08;3&#xff09;《啊哈&#xff01;算法》 1、树的相关定义 &#xff08;1&#xff09;树&#xff1a;…

参数估计方法简介

1.参数估计和非参数估计 前面提到随机变量的分布不是很明确时&#xff0c;我们需要先对随机变量的分布进行估计。有一种情况是我们知道变量分布的模型&#xff0c;但是具体分布的参数未知&#xff0c;我们通过确定这些未知参数就可以实现对变量的估计&#xff0c;这种方式就是参…

VMware Workstation 8下Ubuntu 13.04中安装VMware Tools出错

vm 8.0上安装ubuntu 13.04系统以后&#xff0c;需要安装一个vm tool 方便屏幕适应和文件拷贝&#xff0c;但是发现由于ubuntu 13.04 使用的内核太新了&#xff0c;而vm8.0 不能够提供这样的文件&#xff0c;导致安装失败。现在总结一下解决方法。首先下载最新版本的linux 头文件…

如何在工作组环境win 7远程管理Hyper-v server R2 SP1配置(三)

在 如何在工作组环境win 7远程管理Hyper-v server R2 SP1配置&#xff08;二&#xff09; 文中末尾&#xff0c;出现下图报错&#xff1a; 一般情况下&#xff0c;按上篇提到的hvremote.wsf 脚本配置说明文件HVRemote Documentation操作后&#xff0c;不会出现此报错&#xff0…