上文获得了每天的基金净值数据,并且保存在数据库中,接下来就要把数据展示出来才行。
先写个简单的界面:
接下来让这么难看的界面变得让人可以接受,并且可以清楚看出所需的数据。对界面进行简单的调整,修改:
<%@ page language="java"
import="java.sql.*,java.io.*,database.*,java.text.*,java.math.*,java.util.*"%>
<%@
page contentType="text/html;charset=gb2312"%>
<jsp:useBean
id="database" class="database.Database"
/>
<html>
<head>
<!--[if IE]>
<link
rel="stylesheet" type="text/css" href="style.css" media="screen"
/>
<![endif]-->
<!--[if !IE]><!-->
<link
rel="stylesheet" type="text/css" href="style.css" media="screen"
/>
<!--<![endif]-->
<script type="text/javascript"
language="javascript"
src="./3pp/dataTables-1.6/media/js/jquery.js"></script>
<script
type="text/javascript" charset="utf-8">
$(document).ready(function()
{
$('tr:nth-child(odd)').addClass('odd-row');
$('tr:nth-child(even)').addClass('even-row');
$('td').addClass('even-column');
});
$(document).ready(function()
{
$('.detail').click(function(){
document.getElementById("detail").src =
"detail.jsp?id="+this.id;
$('#detail').fadeIn("fast");
$('#detaildiv').fadeIn("slow");
});
$('#detailclose').click(function(){
$('#detail').fadeOut("fast");
$('#detaildiv').fadeOut("slow");
});
});
</script>
</head>
<body>
<div
class="title">Summary</div>
<div id="A">
<div
class="sub-title" id="titlea">non-Monetary Fund</div>
<table
id="a-info">
<tr>
<td>ID</td>
<td>Name</td>
<td>Cost</td>
<td>Actual</td>
<td>TotalCost</td>
<td>TotalValue</td>
<td>Changed</td>
<td>Trend</td>
</tr>
<%
//Forgive
me,my God.I pull all the java code in the jsp
page
database.connect();
DecimalFormat df = new
DecimalFormat("0.0000");
DecimalFormat df1 = new
DecimalFormat("0.0");
String query = "select Number from Number where Type
=1";
ResultSet rs =
database.getResults(query);
if(!rs.first()){
//bome!bome!
return;
}
rs.beforeFirst();
String
id,name,color;
float
total,actual,changed,value,yesturday,per,year;
ResultSet
rstmp;
while(rs.next()){
id =rs.getString(1);
query = "select
Name,Value,Total from Average where Number = '"+id+"'";
rstmp =
database.getResults(query);
if(rstmp.first()){
name =
rstmp.getString(1);
value = rstmp.getFloat(2);
total =
rstmp.getFloat(3);
}else{
name = "";
value =
1;
total = 0;
}
rstmp.close();
query = "select
Value from Data where Number = '"+id+"' order by Date DESC";
rstmp =
database.getResults(query);
if(rstmp.first()){
actual =
rstmp.getFloat(1);
}else{
actual = 0;
}
rstmp.close();
changed = (actual-value)/value*total;
yesturday =
actual/value*total;
if(changed >=0){
color = "red";
}else{
color = "green";
}
%>
<tr>
<td><%=id%></td>
<td><%=name%></td>
<td><%=Float.parseFloat(df.format(value))%></td>
<td><%=Float.parseFloat(df.format(actual))%></td>
<td><%=Float.parseFloat(df1.format(total))%></td>
<td><%=Float.parseFloat(df1.format(yesturday))%></td>
<td class="important"
style="color:<%=color%>"><%=Float.parseFloat(df1.format(changed))%></td>
<td><a class="detail" id="<%=id%>">Click
me</a></td>
</tr>
<%
}
rs.close();
%>
</table>
</div>
<div id="B">
<div id="titleb">Monetary
Fund</div>
<table
id="b-info">
<tr>
<td>ID</td>
<td>Name</td>
<td>Total</td>
<td>Per10k</td>
<td>Year</td>
<td>Trend</td>
</tr>
<%
query
= "select Number from Number where Type =2";
rs =
database.getResults(query);
if(!rs.first()){
//bome!bome!
return;
}
rs.beforeFirst();
while(rs.next()){
id =rs.getString(1);
query = "select Name,Value,Total from
Average where Number = '"+id+"'";
rstmp =
database.getResults(query);
if(rstmp.first()){
name =
rstmp.getString(1);
value = rstmp.getFloat(2);
total =
rstmp.getFloat(3);
}else{
name = "";
value =
1;
total = 0;
}
rstmp.close();
query = "select
Value,Year from Data where Number = '"+id+"' order by Date DESC";
rstmp =
database.getResults(query);
if(rstmp.first()){
per =
rstmp.getFloat(1);
year = rstmp.getFloat(2);
}else{
per = 0;
year = 0;
}
rstmp.close();
if(year
>=4){
color = "red";
}else{
color =
"green";
}
%>
<tr>
<td><%=id%></td>
<td><%=name%></td>
<td><%=Float.parseFloat(df1.format(total))%></td>
<td><%=Float.parseFloat(df.format(per))%></td>
<td
class="important"
style="color:<%=color%>"><%=Float.parseFloat(df.format(year))%>%</td>
<td><a class="detail" id="<%=id%>">Click
me</a></td>
</tr>
<%
}
rs.close();
%>
</table>
</div>
<%
query = "select Number from Number where Type = 1";
rs =
database.getResults(query);
if(!rs.first()){
//bome!bome!bome!
}
rs.beforeFirst();
float
sum = 0;
while(rs.next()){
query = "select Total from Average where
Number = '"+rs.getString(1)+"'";
rstmp =
database.getResults(query);
if(rstmp.first()){
sum +=
rstmp.getFloat(1);
}
rstmp.close();
}
rs.close();
query =
"select Number from Number where Type = 2";
rs =
database.getResults(query);
if(!rs.first()){
//bome!bome!bome!
}
rs.beforeFirst();
float
sum1 = 0;
while(rs.next()){
query = "select Total from Average where
Number = '"+rs.getString(1)+"'";
rstmp =
database.getResults(query);
if(rstmp.first()){
sum1 +=
rstmp.getFloat(1);
}
rstmp.close();
}
rs.close();
//write
data into Data.xml
String path=request.getRealPath(".");
path =
path.substring(0,path.length()-1)+ "tmp/Data.xml";
StringBuilder strXML=new
StringBuilder("<graph caption='Distribution' decimalPrecision='1'
showPercentageValues='0' showNames='1' showValues='1' showPercentageInLabel='0'
pieYScale='45' pieBorderAlpha='100' pieRadius='100' animation='0'
shadowXShift='4' shadowYShift='4' shadowAlpha='40' pieFillAlpha='95'
pieBorderColor='FFFFFF' bgColor='87CEFA' baseFont='Times'
baseFontSize='13'>");
String tmp1 = "<set value='"+(new
BigDecimal(sum).round(new MathContext(3)).floatValue())+"' name='not-Monetary'
color='8BBA00' />";
String tmp2 = "<set value='"+(new
BigDecimal(sum1).round(new MathContext(3)).floatValue())+"' name='Monetary'
color='F6BD0F'/>";
strXML.append(tmp1);
strXML.append(tmp2);
strXML.append("</graph>");
String
xml=new String(strXML);
FileWriter fw=new
FileWriter(path);
fw.write(xml,0,xml.length());
fw.close();
%>
<div id='container'>
<jsp:include
page="3pp/FusionChartsFree/FusionChartsHTMLRenderer.jsp" flush="true">
<jsp:param name="chartSWF" value="3pp/FusionChartsFree/FCF_Pie2D.swf"
/>
<jsp:param name="strURL" value="tmp/Data.xml" />
<jsp:param name="strXML" value="" />
<jsp:param
name="chartId" value="chart" />
<jsp:param name="chartWidth"
value="400" />
<jsp:param name="chartHeight" value="350" />
<jsp:param name="debugMode" value="false" />
</jsp:include>
</div>
<div id="detaildiv">
<div
id="detailclose">close</div>
<iframe id="detail" name="detail"
src="" width="100%" height="100%"
frameborder="0">
</iframe>
</div>
</body>
</html>
通俗易通的显示当前的数据。然而,这样的数据还是不够直观,只能看到当前的净值以及盈亏程度,但是对于后续的分析,投资操作没有太大帮助。因此,我们还需要最直观的,同时也是最重要的趋势图:
<%@ page language="java"
import="java.sql.*,java.io.*,database.*,java.util.*"%>
<%@ page
contentType="text/html;charset=gb2312"%>
<jsp:useBean id="database"
class="database.Database" />
<html>
<body>
<%
String
id=request.getParameter("id");
database.connect();
String tmp
="<categories>";
float max =0;
float min =0;
ResultSet rs =
database.getResults("select Type from Number where Number =
'"+id+"'");
if(!rs.first()){
//bome!bome!bome!
}
int type =
rs.getInt(1);
rs.close();
if(type == 1){
float average = 0;
rs = database.getResults("select Value from Average where Number =
'"+id+"'");
if(rs.first()){
average = rs.getFloat(1);
}
rs.close();
rs = database.getResults("select Value,Date from Data
where Number = '"+id+"' order by Date");
ResultSet rsm =
database.getResults("select min(Value),max(Value) from Data where Number =
'"+id+"' order by Date");
rsm.first();
min =
rsm.getFloat(1)-0.005f;
max = rsm.getFloat(2)+0.005f;
rsm.close();
if(!rs.first()){
//bome!bome!bome!
}
rs.beforeFirst();
String valuetmp="";
String
avgtmp="";
while(rs.next()){
tmp += "<category
name='"+rs.getString(2)+"' />";
valuetmp += "<set
value='"+rs.getString(1)+"' />";
avgtmp += "<set
value='"+average+"' />";
}
tmp = tmp+
"</categories><dataset seriesname='Actual' color='0099FF' showValue='0'
alpha='100' showAnchors='1' anchorAlpha='80' lineThickness='2'>"+valuetmp+
"</dataset><dataset seriesname='Cost' color='FF8000' showValue='0'
alpha='80' showAnchors='0'>"+avgtmp+" </dataset>";
rs.close();
}else{
rs = database.getResults("select Year,Date from
Data where Number = '"+id+"' order by Date");
ResultSet rsm =
database.getResults("select min(Year),max(Year) from Data where Number =
'"+id+"' order by Date");
rsm.first();
min =
rsm.getFloat(1)-0.1f;
max = rsm.getFloat(2)+0.1f;
rsm.close();
if(!rs.first()){
//bome!bome!bome!
}
rs.beforeFirst();
String valuetmp="";
while(rs.next()){
tmp += "<category name='"+rs.getString(2)+"'
/>";
valuetmp += "<set value='"+rs.getString(1)+"'
/>";
}
tmp = tmp+ "</categories><dataset
seriesname='Actual' color='0099FF' showValue='0' alpha='100' showAnchors='1'
anchorAlpha='80' lineThickness='2'>"+valuetmp+ "</dataset>";
rs.close();
}
//write data into xml
String path=request.getRealPath(".");
path =
path.substring(0,path.length()-1)+
"tmp/DataDetail"+id+".xml";
//StringBuilder strXML=new
StringBuilder("<graph caption='Top 10 Test Suites' yaxisname='BugNumber'
xaxisname='TestSuites' showAlternateVGridColor='1' alternateVGridAlpha='10'
alternateVGridColor='AFD8F8' numDivLines='4' decimalPrecision='0'
canvasBorderThickness='1' canvasBorderColor='114B78' baseFontColor='114B78'
hoverCapBorderColor='114B78' hoverCapBgColor='E7EFF6' bgColor='87CEFA'
baseFont='Times' baseFontSize='13'>");
StringBuilder strXML=new
StringBuilder("<graph caption='trend' xAxisName='date' yAxisName='value '
hovercapbg='FFECAA' hovercapborder='F47E00' formatNumberScale='0'
decimalPrecision='3' showvalues='0' animation='1' numdivlines='3'
numVdivlines='0' yaxisminvalue='"+min+"' yaxismaxvalue='"+max+"'
lineThickness='3'
rotateNames='1'>");
strXML.append(tmp);
strXML.append("</graph>");
String
xml=new String(strXML);
FileWriter fw=new
FileWriter(path);
fw.write(xml,0,xml.length());
fw.close();
String aa = "tmp/DataDetail"+id+".xml";
%>
<div id="container"
style="width: 760px; height: 450px; margin: 0 auto">
<jsp:include
page="3pp/FusionChartsFree/FusionChartsHTMLRenderer.jsp" flush="true">
<jsp:param name="chartSWF" value="3pp/FusionChartsFree/FCF_MSLine.swf"
/>
<jsp:param name="strURL" value="<%=aa%>" />
<jsp:param name="strXML" value="" />
<jsp:param
name="chartId" value="myFirst" />
<jsp:param name="chartWidth"
value="750" />
<jsp:param name="chartHeight" value="450" />
<jsp:param name="debugMode" value="false" />
</jsp:include>
</div>
</body>
</html>
这样一眼就能看到该基金的净值曲线,同时给出成本的基准线,可以快速读出基金走势。
到此为止,该工具就基本完成了。只要将数据采集的脚本放进定时计划中,每天定时执行就可以了。
如果宏观经济,高等数学和解析几何好的话,还可以针对当前经济形势,曲线斜率等等进行进一步的分析。大师计算赌博概率赚大钱,我们这种数学不好的,只要计算基金走势赚小钱