• R/O
  • SSH
  • HTTPS

robotbrain: コミット


コミットメタ情報

リビジョン307 (tree)
日時2013-11-10 11:50:35
作者robotbrain

ログメッセージ

新日付取り込み対応

変更サマリ

差分

--- trunk/RobotTraderLibrary/src/jp/robotbrain/framework/HistoricalDataList.java (revision 306)
+++ trunk/RobotTraderLibrary/src/jp/robotbrain/framework/HistoricalDataList.java (nonexistent)
@@ -1,246 +0,0 @@
1-/**
2- * Copyright (C) 2013 RobotBrain. All Rights Reserved.
3- * このプログラムはフリーソフトウェアです。あなたはこれをフリーソフトウェア財団
4- * によって発行されたGNU劣等一般公衆利用許諾書バージョン3(LGPLv3)が定める条件の
5- * 下で再頒布または改変することができます。
6- * このプログラムは有用であることを願って頒布されますが全くの無保証です。
7- * 商業可能性の保証や特定目的への適合性は、言外に示されたものも含め全く存在しま
8- * せん。詳しくはGNU劣等一般公衆利用許諾書バージョン3(LGPLv3)をご覧ください。
9- * あなたはこのプログラムと共に、GNU劣等一般公衆利用許諾書バージョン3(LGPLv3)の
10- * コピーを一部受け取っているはずです。
11- * もし受け取っていなければ<http://www.gnu.org/licenses/>をご覧ください。
12- */
13-package jp.robotbrain.framework;
14-
15-import java.io.File;
16-import java.util.ArrayList;
17-import java.util.Collections;
18-import java.util.HashMap;
19-
20-import jp.robotbrain.common.StringComparator;
21-
22-/**
23- * ヒストリカルデータを管理するクラス
24- *
25- * @since 2.80
26- * @author Copyright (C) 2013 <a href="http://robotbrain.jp">
27- * RobotBrain.</a> All Rights Reserved.
28- */
29-public class HistoricalDataList {
30-
31- /**
32- * ヒストリカルデータのポインタ
33- *
34- * @since 2.80
35- */
36- private Pointer m_pointer;
37-
38- /**
39- * ヒストリカルデータのファイル名(取引日)のリスト
40- *
41- * @since 2.80
42- */
43- private ArrayList<String> m_tradingDateList;
44-
45- /**
46- * ヒストリカルデータのファイル名のリストのキャッシュ。生成済みのデータを保持。
47- *
48- * @since 2.80
49- */
50- private static HashMap<String,HistoricalDataList> m_cacheTable = new HashMap<String,HistoricalDataList>();
51-
52- /**
53- * HistoricalDataListを生成します。
54- *
55- * @since 2.80
56- */
57- private HistoricalDataList() {
58- }
59-
60- /**
61- * HistoricalDataListを生成します。
62- *
63- * @since 2.80
64- * @param p_historicalDataFolderPath ヒストリカルデータが入っているフォルダのパス
65- * @throws HistoricalDataException ヒストリカルデータのリストアップに失敗した場合
66- */
67- public static synchronized HistoricalDataList create(String p_historicalDataFolderPath) throws HistoricalDataException {
68- return create(p_historicalDataFolderPath, false);
69- }
70-
71- /**
72- * HistoricalDataListを生成します。
73- *
74- * @since 2.80
75- * @param p_historicalDataFolderPath ヒストリカルデータが入っているフォルダのパス
76- * @param p_reload trueの場合、キャッシュデータを使わずにファイルリストを読み直す
77- * @throws HistoricalDataException ヒストリカルデータのリストアップに失敗した場合
78- */
79- @SuppressWarnings("unchecked")
80- public static synchronized HistoricalDataList create(String p_historicalDataFolderPath, boolean p_reload) throws HistoricalDataException {
81- HistoricalDataList returnValue = null;
82- // 既に処理済のデータはキャッシュから取得して返す
83- if (!p_reload) {
84- HistoricalDataList cache = m_cacheTable.get(p_historicalDataFolderPath.toUpperCase());
85- if (cache!=null) {
86- returnValue = new HistoricalDataList();
87- returnValue.m_pointer = new Pointer();
88- returnValue.m_tradingDateList = (ArrayList<String>)cache.m_tradingDateList.clone();
89- return returnValue;
90- }
91- }
92- // 新規にファイル名をリストアップ
93- returnValue = new HistoricalDataList();
94- returnValue.m_pointer = new Pointer();
95- returnValue.m_tradingDateList = new ArrayList<String>();
96- if (p_historicalDataFolderPath==null || p_historicalDataFolderPath.equals("")) {
97- String msg = "HistoricalData Path Error: " + p_historicalDataFolderPath;
98- throw new HistoricalDataException(msg);
99- }
100- File f = new File(p_historicalDataFolderPath);
101- File[] flist = f.listFiles();
102- if (flist==null) {
103- String msg = "HistoricalData Listing Error: " + p_historicalDataFolderPath;
104- throw new HistoricalDataException(msg);
105- }
106- // ファイル名でソートする
107- for (int i=0;i<flist.length;i++) {
108- returnValue.m_tradingDateList.add(flist[i].getName());
109- }
110- Collections.sort(returnValue.m_tradingDateList, new StringComparator(false));
111- m_cacheTable.put(p_historicalDataFolderPath.toUpperCase(), returnValue);
112- return returnValue;
113- }
114-
115- /**
116- * 指定した日数分遡ったヒストリカルデータファイル名のリストを返します。
117- *
118- * @since 2.80
119- * @param p_tradingDate 基準日(yyyyMMdd形式)
120- * @param p_pastDays 基準日から何日分過去を遡るか指定します
121- * @return ヒストリカルデータファイル名のリスト
122- * @throws HistoricalDataException ヒストリカルデータが見つからなかった場合
123- */
124- public ArrayList<String> getPastList(String p_tradingDate, int p_pastDays) throws HistoricalDataException {
125- ArrayList<String> returnValue = new ArrayList<String>();
126- if (m_tradingDateList.size()<=0) return returnValue;
127- // 指定された取引日のヒストリカルデータが存在するか確認する
128- int tradingDatePoint = m_tradingDateList.indexOf(p_tradingDate);
129- if (tradingDatePoint<0) {
130- // ヒストリカルデータが見つからない場合は取引日が新日付か確認する
131- String lastDate = m_tradingDateList.get(m_tradingDateList.size()-1);
132- if (Integer.parseInt(lastDate)<Integer.parseInt(p_tradingDate)) {
133- tradingDatePoint = m_tradingDateList.size();
134- } else {
135- String msg = "NotFound HistoricalData lastDate:" + lastDate + " tradingDate:" + p_tradingDate;
136- throw new HistoricalDataException(msg);
137- }
138- }
139- // 引数の取引日を含まないファイル名リストを生成
140- // p_pastDays=3 tradingDatePoint=5 の場合
141- // 0 1 2 3 4 5 6 7 8 9 -> size=10
142- // *tradingDatePoint
143- // *loop tradingDatePoint-i=3
144- // *loop tradingDatePoint-i=2
145- // *loop tradingDatePoint-i=1
146- for (int i=p_pastDays;i>=1;i--) {
147- if (tradingDatePoint-i>=0) {
148- String pastDate = m_tradingDateList.get(tradingDatePoint-i);
149- returnValue.add(pastDate);
150- }
151- }
152- return returnValue;
153- }
154-
155- /**
156- * 1件目のヒストリカルデータに移動してファイル名を返します。
157- *
158- * @since 2.80
159- * @return ヒストリカルデータのファイル名。取得できなかった場合は空文字""を返します。
160- */
161- public String moveFirst() {
162- if (m_tradingDateList.size()<=0) return "";
163- m_pointer.moveFirst();
164- return m_tradingDateList.get(0);
165- }
166-
167- /**
168- * 最後のヒストリカルデータに移動してファイル名を返します。
169- *
170- * @since 2.80
171- * @return ヒストリカルデータのファイル名。取得できなかった場合は空文字""を返します。
172- */
173- public String moveLast() {
174- if (m_tradingDateList.size()<1) return "";
175- int lastPointer = m_tradingDateList.size() - 1;
176- m_pointer.move(lastPointer);
177- return m_tradingDateList.get(lastPointer);
178- }
179-
180- /**
181- * 次のヒストリカルデータに移動してファイル名を返します。
182- *
183- * @since 2.80
184- * @return ヒストリカルデータのファイル名。取得できなかった場合は空文字""を返します。
185- */
186- public String moveNext() {
187- if (m_tradingDateList.size()<=m_pointer.getValue()+1) return "";
188- m_pointer.moveNext();
189- return m_tradingDateList.get(m_pointer.getValue());
190- }
191-
192- /**
193- * 前のヒストリカルデータに移動してファイル名を返します。
194- *
195- * @since 2.80
196- * @return ヒストリカルデータのファイル名。取得できなかった場合は空文字""を返します。
197- */
198- public String movePrev() {
199- if (0 > m_pointer.getValue()-1) return "";
200- m_pointer.movePrev();
201- return m_tradingDateList.get(m_pointer.getValue());
202- }
203-
204- /**
205- * 指定した日数分戻ったヒストリカルデータに移動してファイル名を返します。
206- *
207- * @since 2.80
208- * @param p_prevDays 戻る日数
209- * @return ヒストリカルデータのファイル名。取得できなかった場合は空文字""を返します。
210- */
211- public String movePrev(int p_prevDays) {
212- String returnValue = "";
213- for (int i=0;i<p_prevDays;i++) {
214- returnValue = movePrev();
215- if (returnValue.equals("")) {
216- return moveFirst();
217- }
218- }
219- return returnValue;
220- }
221-
222- /**
223- * 指定した日付のヒストリカルデータに移動してファイル名を返します。
224- *
225- * @since 2.80
226- * @param p_tradingDate 移動先の日付(yyyyMMdd形式)
227- * @return ヒストリカルデータのファイル名。取得できなかった場合は空文字""を返します。
228- */
229- public String move(String p_tradingDate) {
230- int i = m_tradingDateList.indexOf(p_tradingDate);
231- if (i<0) return "";
232- m_pointer.move(i);
233- return m_tradingDateList.get(m_pointer.getValue());
234- }
235-
236- /**
237- * ヒストリカルデータの日付リストを返します。
238- *
239- * @since 2.80
240- * @return ヒストリカルデータの日付リスト
241- */
242- public ArrayList<String> getValues() {
243- return m_tradingDateList;
244- }
245-
246-}
Deleted: svn:mime-type
## -1 +0,0 ##
-text/plain
\ No newline at end of property
--- trunk/RobotTraderLibrary/src/jp/robotbrain/framework/HistoricalTradingDateList.java (nonexistent)
+++ trunk/RobotTraderLibrary/src/jp/robotbrain/framework/HistoricalTradingDateList.java (revision 307)
@@ -0,0 +1,246 @@
1+/**
2+ * Copyright (C) 2013 RobotBrain. All Rights Reserved.
3+ * このプログラムはフリーソフトウェアです。あなたはこれをフリーソフトウェア財団
4+ * によって発行されたGNU劣等一般公衆利用許諾書バージョン3(LGPLv3)が定める条件の
5+ * 下で再頒布または改変することができます。
6+ * このプログラムは有用であることを願って頒布されますが全くの無保証です。
7+ * 商業可能性の保証や特定目的への適合性は、言外に示されたものも含め全く存在しま
8+ * せん。詳しくはGNU劣等一般公衆利用許諾書バージョン3(LGPLv3)をご覧ください。
9+ * あなたはこのプログラムと共に、GNU劣等一般公衆利用許諾書バージョン3(LGPLv3)の
10+ * コピーを一部受け取っているはずです。
11+ * もし受け取っていなければ<http://www.gnu.org/licenses/>をご覧ください。
12+ */
13+package jp.robotbrain.framework;
14+
15+import java.io.File;
16+import java.util.ArrayList;
17+import java.util.Collections;
18+import java.util.HashMap;
19+
20+import jp.robotbrain.common.StringComparator;
21+
22+/**
23+ * ヒストリカルデータを管理するクラス
24+ *
25+ * @since 2.80
26+ * @author Copyright (C) 2013 <a href="http://robotbrain.jp">
27+ * RobotBrain.</a> All Rights Reserved.
28+ */
29+public class HistoricalTradingDateList {
30+
31+ /**
32+ * ヒストリカルデータのポインタ
33+ *
34+ * @since 2.80
35+ */
36+ private Pointer m_pointer;
37+
38+ /**
39+ * ヒストリカルデータのファイル名(取引日)のリスト
40+ *
41+ * @since 2.80
42+ */
43+ private ArrayList<String> m_tradingDateList;
44+
45+ /**
46+ * ヒストリカルデータのファイル名のリストのキャッシュ。生成済みのデータを保持。
47+ *
48+ * @since 2.80
49+ */
50+ private static HashMap<String,HistoricalTradingDateList> m_cacheTable = new HashMap<String,HistoricalTradingDateList>();
51+
52+ /**
53+ * HistoricalDataListを生成します。
54+ *
55+ * @since 2.80
56+ */
57+ private HistoricalTradingDateList() {
58+ }
59+
60+ /**
61+ * HistoricalDataListを生成します。
62+ *
63+ * @since 2.80
64+ * @param p_historicalDataFolderPath ヒストリカルデータが入っているフォルダのパス
65+ * @throws HistoricalDataException ヒストリカルデータのリストアップに失敗した場合
66+ */
67+ public static synchronized HistoricalTradingDateList create(String p_historicalDataFolderPath) throws HistoricalDataException {
68+ return create(p_historicalDataFolderPath, false);
69+ }
70+
71+ /**
72+ * HistoricalDataListを生成します。
73+ *
74+ * @since 2.80
75+ * @param p_historicalDataFolderPath ヒストリカルデータが入っているフォルダのパス
76+ * @param p_reload trueの場合、キャッシュデータを使わずにファイルリストを読み直す
77+ * @throws HistoricalDataException ヒストリカルデータのリストアップに失敗した場合
78+ */
79+ @SuppressWarnings("unchecked")
80+ public static synchronized HistoricalTradingDateList create(String p_historicalDataFolderPath, boolean p_reload) throws HistoricalDataException {
81+ HistoricalTradingDateList returnValue = null;
82+ // 既に処理済のデータはキャッシュから取得して返す
83+ if (!p_reload) {
84+ HistoricalTradingDateList cache = m_cacheTable.get(p_historicalDataFolderPath.toUpperCase());
85+ if (cache!=null) {
86+ returnValue = new HistoricalTradingDateList();
87+ returnValue.m_pointer = new Pointer();
88+ returnValue.m_tradingDateList = (ArrayList<String>)cache.m_tradingDateList.clone();
89+ return returnValue;
90+ }
91+ }
92+ // 新規にファイル名をリストアップ
93+ returnValue = new HistoricalTradingDateList();
94+ returnValue.m_pointer = new Pointer();
95+ returnValue.m_tradingDateList = new ArrayList<String>();
96+ if (p_historicalDataFolderPath==null || p_historicalDataFolderPath.equals("")) {
97+ String msg = "HistoricalData Path Error: " + p_historicalDataFolderPath;
98+ throw new HistoricalDataException(msg);
99+ }
100+ File f = new File(p_historicalDataFolderPath);
101+ File[] flist = f.listFiles();
102+ if (flist==null) {
103+ String msg = "HistoricalData Listing Error: " + p_historicalDataFolderPath;
104+ throw new HistoricalDataException(msg);
105+ }
106+ // ファイル名でソートする
107+ for (int i=0;i<flist.length;i++) {
108+ returnValue.m_tradingDateList.add(flist[i].getName());
109+ }
110+ Collections.sort(returnValue.m_tradingDateList, new StringComparator(false));
111+ m_cacheTable.put(p_historicalDataFolderPath.toUpperCase(), returnValue);
112+ return returnValue;
113+ }
114+
115+ /**
116+ * 指定した日数分遡ったヒストリカルデータファイル名のリストを返します。
117+ *
118+ * @since 2.80
119+ * @param p_tradingDate 基準日(yyyyMMdd形式)
120+ * @param p_pastDays 基準日から何日分過去を遡るか指定します
121+ * @return ヒストリカルデータファイル名のリスト
122+ * @throws HistoricalDataException ヒストリカルデータが見つからなかった場合
123+ */
124+ public ArrayList<String> getPastList(String p_tradingDate, int p_pastDays) throws HistoricalDataException {
125+ ArrayList<String> returnValue = new ArrayList<String>();
126+ if (m_tradingDateList.size()<=0) return returnValue;
127+ // 指定された取引日のヒストリカルデータが存在するか確認する
128+ int tradingDatePoint = m_tradingDateList.indexOf(p_tradingDate);
129+ if (tradingDatePoint<0) {
130+ // ヒストリカルデータが見つからない場合は取引日が新日付か確認する
131+ String lastDate = m_tradingDateList.get(m_tradingDateList.size()-1);
132+ if (Integer.parseInt(lastDate)<Integer.parseInt(p_tradingDate)) {
133+ tradingDatePoint = m_tradingDateList.size();
134+ } else {
135+ String msg = "NotFound HistoricalData lastDate:" + lastDate + " tradingDate:" + p_tradingDate;
136+ throw new HistoricalDataException(msg);
137+ }
138+ }
139+ // 引数の取引日を含まないファイル名リストを生成
140+ // p_pastDays=3 tradingDatePoint=5 の場合
141+ // 0 1 2 3 4 5 6 7 8 9 -> size=10
142+ // *tradingDatePoint
143+ // *loop tradingDatePoint-i=3
144+ // *loop tradingDatePoint-i=2
145+ // *loop tradingDatePoint-i=1
146+ for (int i=p_pastDays;i>=1;i--) {
147+ if (tradingDatePoint-i>=0) {
148+ String pastDate = m_tradingDateList.get(tradingDatePoint-i);
149+ returnValue.add(pastDate);
150+ }
151+ }
152+ return returnValue;
153+ }
154+
155+ /**
156+ * 1件目のヒストリカルデータに移動してファイル名を返します。
157+ *
158+ * @since 2.80
159+ * @return ヒストリカルデータのファイル名。取得できなかった場合は空文字""を返します。
160+ */
161+ public String moveFirst() {
162+ if (m_tradingDateList.size()<=0) return "";
163+ m_pointer.moveFirst();
164+ return m_tradingDateList.get(0);
165+ }
166+
167+ /**
168+ * 最後のヒストリカルデータに移動してファイル名を返します。
169+ *
170+ * @since 2.80
171+ * @return ヒストリカルデータのファイル名。取得できなかった場合は空文字""を返します。
172+ */
173+ public String moveLast() {
174+ if (m_tradingDateList.size()<1) return "";
175+ int lastPointer = m_tradingDateList.size() - 1;
176+ m_pointer.move(lastPointer);
177+ return m_tradingDateList.get(lastPointer);
178+ }
179+
180+ /**
181+ * 次のヒストリカルデータに移動してファイル名を返します。
182+ *
183+ * @since 2.80
184+ * @return ヒストリカルデータのファイル名。取得できなかった場合は空文字""を返します。
185+ */
186+ public String moveNext() {
187+ if (m_tradingDateList.size()<=m_pointer.getValue()+1) return "";
188+ m_pointer.moveNext();
189+ return m_tradingDateList.get(m_pointer.getValue());
190+ }
191+
192+ /**
193+ * 前のヒストリカルデータに移動してファイル名を返します。
194+ *
195+ * @since 2.80
196+ * @return ヒストリカルデータのファイル名。取得できなかった場合は空文字""を返します。
197+ */
198+ public String movePrev() {
199+ if (0 > m_pointer.getValue()-1) return "";
200+ m_pointer.movePrev();
201+ return m_tradingDateList.get(m_pointer.getValue());
202+ }
203+
204+ /**
205+ * 指定した日数分戻ったヒストリカルデータに移動してファイル名を返します。
206+ *
207+ * @since 2.80
208+ * @param p_prevDays 戻る日数
209+ * @return ヒストリカルデータのファイル名。取得できなかった場合は空文字""を返します。
210+ */
211+ public String movePrev(int p_prevDays) {
212+ String returnValue = "";
213+ for (int i=0;i<p_prevDays;i++) {
214+ returnValue = movePrev();
215+ if (returnValue.equals("")) {
216+ return moveFirst();
217+ }
218+ }
219+ return returnValue;
220+ }
221+
222+ /**
223+ * 指定した日付のヒストリカルデータに移動してファイル名を返します。
224+ *
225+ * @since 2.80
226+ * @param p_tradingDate 移動先の日付(yyyyMMdd形式)
227+ * @return ヒストリカルデータのファイル名。取得できなかった場合は空文字""を返します。
228+ */
229+ public String move(String p_tradingDate) {
230+ int i = m_tradingDateList.indexOf(p_tradingDate);
231+ if (i<0) return "";
232+ m_pointer.move(i);
233+ return m_tradingDateList.get(m_pointer.getValue());
234+ }
235+
236+ /**
237+ * ヒストリカルデータの日付リストを返します。
238+ *
239+ * @since 2.80
240+ * @return ヒストリカルデータの日付リスト
241+ */
242+ public ArrayList<String> getValues() {
243+ return m_tradingDateList;
244+ }
245+
246+}
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
旧リポジトリブラウザで表示