工行纸黄金收益及收益率计算工具

工行纸黄金不同于股票交易账户, 它直接和银行账户绑定.在进行多次不同重量的买入和卖出后, 统计一段时间的收益和收益率变得比较困难.

下面的这个程序可以对工行的导出纯文本进行自动分析得到收益值和收益率, 并可以对时间有序的多数据文本文件进行统计操作.

[Environment: GCC-4.4.3.]

#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ctype.h> /* isdigit */

#define GOLDCALC_VERSION "0.0.3 for ICBC paper gold."
#define GOLDCALC_DATE    "2011-12-28"

//#define DTEST
#ifdef DTEST
	#define dprint(x...) printf(x)
#else
	#define dprint(x...) 
#endif

#define MAX_FILE_NUMBER 10
#define MAX_PATH_LENGTH 150

enum {
	UNKOWN = 0,
	BUY,
	SELL,
};

struct one_trade_node {
	char date[11];
#if 0	
	char time[9];
	char no[10];
#endif
	int  type;
	float  price;
	float  weight;
	float  subsum;
	int  line;
	struct one_trade_node *next;
};		

static double current_price, current_weight, current_sum;

static inline int _validline(char *line)
{
	int i = 0x1 & (isdigit(line[0]) && isdigit(line[1]) && isdigit(line[2]) && isdigit(line[3]));
	return ((i) && (line[4] == '-') && (line[7] == '-'));
}

static double _katof(const char *str)
{
	char p[50];
	bzero(p, sizeof(p));
	char *q = p;
	while ( *str != '\0') {
		if (*str != ',')
			*q = *str, q++;
		str++;	
	}
	return (atof(p));	
}

static inline int _date_order_check(const char *new, const char *old)
{
	int i, ret=1;
	for (i=0; i<10; i++) {
		if (new[i]- old[i] != 0) {
			ret = ((new[i] - old[i] > 0) ? 1 : 0);
			break;
		}	
	}
	return (ret);	
}

static double _get_cost_sum(struct one_trade_node *head)
{
	struct one_trade_node *p = head->next;
	
	if (p->type != BUY) {
		dprint("This data file is probable incomplete, normal one should start with a BUY.\n");
	}	

	double cost, cash;
	int i = 0;
	cost = cash = 0;
	while(p) {
	
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值