//================================================================C // 2株式のリスク、リターン及び相関係数の計算 // Input File: M-6501.txt & M-9613 : プログラムと同じディレクトリ // Output File: P1-out.txt : プログラムと同じディレクトリ //----------------------------------------------------------------C // javac Correlation.java : classファイルの作成 // java Correlation : 実行 //----------------------------------------------------------------C // Written by Yasunori Ushiro (後 保範), 2011/11/09 // ( Waseda University, 早稲田大学 ) //================================================================C import java.io.*; import java.util.*; public class Correlation { static String code1="6501", code2="9613"; public static double marume(double x, int n, int id) { double y, nd, s; nd = n; // id=1 --> % value (y=100*x) if (id == 1) { nd = n/100; } s = 0.5; if (x < 0.0) { s = -0.5; } y = (double)( (int)(x*n + s) ) / nd; return y; } public static void main (String[] args) throws Exception { String s, std; int i, k, n, n12, NO; int input1[][] = new int[2][300]; int input2[][] = new int[2][300]; int data1[][] = new int[2][300]; int data2[][] = new int[2][300]; double ret[][] = new double[2][300]; double myu[] = new double[2]; double sigm[] = new double[2]; double r, r1; // Input File FileInputStream fi1 = new FileInputStream("M-"+code1+".txt"); InputStreamReader in1 = new InputStreamReader(fi1); BufferedReader b1 = new BufferedReader(in1); FileInputStream fi2 = new FileInputStream("M-"+code2+".txt"); InputStreamReader in2 = new InputStreamReader(fi2); BufferedReader b2 = new BufferedReader(in2); // Output File FileOutputStream fo = new FileOutputStream("P1-out.txt"); PrintWriter q = new PrintWriter(fo,true); // File-1 Read n = 0; while ( (s = b1.readLine()) != null) { StringTokenizer st1 = new StringTokenizer(s); NO = 0; while (st1.hasMoreTokens()) { std = st1.nextToken(); if(NO==1) { input1[0][n] = Integer.parseInt(std); } if(NO==4) { input1[1][n] = Integer.parseInt(std); } NO++; } n++; } // File-2 Read n = 0; while ( (s = b2.readLine()) != null) { StringTokenizer st2 = new StringTokenizer(s); NO = 0; while (st2.hasMoreTokens()) { std = st2.nextToken(); if(NO==1) { input2[0][n] = Integer.parseInt(std); } if(NO==4) { input2[1][n] = Integer.parseInt(std); } NO++; } n++; } // データを日付の昇順にし、月別リターンとリターン(平均)を計算 myu[0] = 0.0; myu[1] = 0.0; for (i=0; i