⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fundparser.pl

📁 基于UNIX平台的金融数据分析程序
💻 PL
字号:
#!C:\Perl\bin\perluse Data::Dumper;my $fund_list;my $fund_name;my $stock;my $file = "d:/perl/fundlist";open(READ,$file) or die "cannot read $file\n";while(<READ>) {	my $data = $_;	chomp($data);	#-----------------------------------	# the data is separated by "===="	#-----------------------------------	if ($data =~ /=/) {			print "Next data block...\n";		next;	}	#----------------------------------	# the information of date and summary of 000001	# Data is: 2007-10-12 2007-10-11 5903.26	#----------------------------------	elsif ($data =~ /^(\d{4}-\d{2}-\d{2})\s*(\d{4}-\d{2}-\d{2})\s*(\d*.*\d*)/) {		$today = $1;		$yesterday = $2;		$total_stock = $3;	}	elsif ($data =~ /^\d+\s*\d+.*\%/) {		my @fund = split/\s/,$data;		#print Dumper(\@fund);		my $number = $fund[1];		my $name = $fund[2];		my $fund_today_value = $fund[3];		my $fund_yesterday_value = $fund[5];		my $fund_increase = $fund[8];		my $fund_place = $fund[0];				$stock->{$today} = $total_stock;		$fund_name->{$number} = $name;		$fund_list->{$number}->{$today}->{'value'} = $fund_today_value;		$fund_list->{$number}->{$today}->{'increase'} = $fund_increase;		$fund_list->{$number}->{$yesterday}->{'value'} = $fund_yesterday_value;	}}#print Dumper($stock);#print Dumper($fund_name);#print Dumper($fund_list);#exit;&summary_increase($fund_list);sub summary_increase {	my $fund = shift;	my $result;		foreach my $fund_id (keys %$fund) {		my ($max, $min, $increase);		my $counter=0;		print $fund_name->{$fund_id}." is calculated...\n";				my $data_of_fund = $fund->{$fund_id};		#print Dumper($data_of_fund);		foreach my $curr_data (sort{$a<=>$b} keys %$data_of_fund) {			my $curr_value = $data_of_fund->{$curr_data}->{'value'};			if ($counter == 0) {				$max = $curr_value;				$min = $curr_value;			}			else {				if ($curr_value > $max) { $max = $curr_value };				if ($curr_value < $min) { $min = $curr_value };			}			$increase += $data_of_fund->{$curr_data}->{'increase'};						#print "$curr_data\t$curr_value\t".$data_of_fund->{$curr_data}->{'increase'}."\n";			$counter +=1;		}		my $avg_value = ($max - $min);		#my $avg_value = ($max - $min)/$counter;		#if (length($avg_value) >= 8) {		#	$avg_value =~ /^(.{7})(\d)/;		#	$avg_value = $1 + "0.00000".$2;		#}		my $avg_increase = $increase/$counter;		if (length($avg_increase) >= 6) {			$avg_increase =~ /^(.{5})(\d)/;			$avg_increase = $1 + "0.000".$2;		}				if (exists $result->{$avg_increase}) {			my $ref = $result->{$avg_increase};			#print Dumper($ref);			my $id;			foreach my $max_id (sort{$a<=>$b} keys %$ref) {				$id = $max_id;			};			my $curr_id = $id +1;			$ref->{$curr_id}->{'value'} 	= $avg_value;			$ref->{$curr_id}->{'name'} 	= $fund_name->{$fund_id};			$ref->{$curr_id}->{'id'} 		= $fund_id;			$ref->{$curr_id}->{'increase'} 		= $avg_increase;			#print Dumper($ref);exit;		}		else {			$result->{$avg_increase}->{'1'}->{'value'} 	= $avg_value;			$result->{$avg_increase}->{'1'}->{'name'} 	= $fund_name->{$fund_id};			$result->{$avg_increase}->{'1'}->{'id'} 		= $fund_id;			$result->{$avg_increase}->{'1'}->{'increase'} 		= $avg_increase;			#print Dumper($result);		}		#exit;	}	open(WRITE,">fund_result.csv") or die "Can't write fund_result.csv\n";	my $serial_id=1;	print WRITE "名次,基金ID,基金名字,平均增值,增值比率\n";	foreach my $increase_value (sort{$a<=>$b} keys %$result) {		my $curr_ref = $result->{$increase_value};		foreach my $s_id (keys %$curr_ref) {			print WRITE "$serial_id,".$curr_ref->{$s_id}->{'id'}.",".$curr_ref->{$s_id}->{'name'}.",".$curr_ref->{$s_id}->{'value'}.",".$curr_ref->{$s_id}->{'increase'}."\n";		}		$serial_id += 1;	}	print "Finished to write fund_result.csv, Please have a look!\n";}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -