1 #include<iostream>
2 #include<fstream.h>
3 using namespace std;
4
5 void month(){
6
7 // histogram set up
8 char hname[16]={0};
9 TH1D* mhis[12];
10 for (int ii=0;ii<12;ii++){
11 sprintf(hname,"h-%02d",ii+1);
12 mhis[ii]=new TH1D(hname,hname,16,-20,20);
13 mhis[ii]->GetXaxis()->SetTitle("return [\%]");
14 }
15
16
17
18 // read data
19 char line[256]={0};
20 int yy,mm;
21 double rtn; //return
22 ifstream ifs("nikkei225_monthly_return.txt");
23 while(ifs.getline(line,256)){
24 stringstream st;
25 st << line;
26 st >> yy >> mm >> rtn;
27 mhis[mm-1]-> Fill(rtn);
28 }
29 ifs.close();
30
31
32
33 // plot histogram
34 TCanvas *c1=new TCanvas("c1","c1",0,0,1200,900);
35 c1->Divide(4,3);
36 //gStyle->SetOptStat("nerM");
37 for(int ii=0;ii<12;ii++){
38 c1->cd(ii+1);
39 c1->cd(ii+1)->SetGrid();
40 mhis[ii]->Draw();
41 //mhis[ii]->Fit("gaus");
42 }
43
44
45
46 // get histogram parameters
47 double rmean[12]={0};
48 double rerr[12]={0};
49 double month[12]={0};
50 double merr[12]={0};
51 for(int ii=0;ii<12;ii++){
52 rmean[ii]=mhis[ii]->GetMean();
53 rerr[ii]=mhis[ii]->GetMeanError();
54 month[ii]=ii+1;
55 merr[ii]=0.5;
56 }
57
58
59
60 // Graph set up
61 TGraphErrors *gr = new TGraphErrors(12,month,rmean,merr,rerr);
62 //gr->SetMarkerStyle(3);
63 gr->SetTitle("month .VS. stock return");
64 gr->GetXaxis()->SetTitle("month");
65 gr->GetYaxis()->SetTitle("return[\%]");
66
67
68 // plot Graph
69 TCanvas *c2=new TCanvas("c2","c2",0,0,450,450);
70 c2->cd(1);
71 c2->cd(1)->SetGrid();
72 gr->GetXaxis()->SetLimits(0.5,12.5);
73 gr->Draw("ap");
74
75
76
77 }
78
Author:Kapok