- OmegaChartスレ ver.11
251 :名無しさん@お腹いっぱい。[]:2019/02/12(火) 21:54:56.67 ID:MyBX68rD0 - >>244
無尽蔵データの当日株価と過去株価についてもう少し詳しく調べるコンソールアプリを作成してみました。 d_dataの方が当日、k_dataの方が過去株価のようです。 OmegaChartで取得する当日株価の方が市場、0データ、銘柄の重複を含め間違いが多いような気がします。 また、過去株価でも市場と無尽蔵独自の市場コードや銘柄名などで間違いがあるようですが、市場名のフィールドに関しては1部と2部あるいは2部とマザーズの間違いがほとんどのようでした。 データインポートには過去株価の方が良さそうに思えますが、コード変更が多くなってしまうでしょう。 index.txtを更新せずに市場変更があった場合には、データダウンロードで市場チェックをしていると取りこぼしの原因になると考えられます。 信頼性に欠ける面はありますから、素直に他のデータソースを使えということになりますかね。 Edatalabを市場チェックせずに利用するのが一番早くて簡単かもしれません。 ちなみに、ヤフーがデータソースの場合は優先市場の取得で市場チェックしていないのでindex.txtにあるコードは更新されるようです。 ところで、昔のヤフー時系列は前日分までだったと記憶していたのですが今見てみたら今日のデータも追加されているのですね。 検証したコンソールアプリを次に参考として投稿しておきます。 適当に日付を変更して、Omegaのディレクトリを変更する必要があります。 新規作成したコンソールアプリのメインメソッドに貼り付けてください。 zipファイルをHttpClientでStream取得して直接読み込むため、System.IO.Commpressionの参照が必要です。
| - OmegaChartスレ ver.11
252 :名無しさん@お腹いっぱい。[]:2019/02/12(火) 21:58:37.03 ID:MyBX68rD0 - //>>251 Mujinzou.cs 1
//新規にコンソールアプリを作成、要参照追加 System.IO.Compressionの参照追加して以下をメインにコピペ //dateを適当に変更して実行 *ウンロードできなければエラーとなる DateTime date = DateTime.Parse("2019/2/12"); string[] urls = new string[] { "http://souba-data.com/d_data/" + date.ToString(@"yyyy\d/yy_MM\d/TyyMMdd") + ".zip", "http://souba-data.com/k_data/" + date.ToString(@"yyyy/yy_MM/TyyMMdd") + ".zip" }; string[] sources = new string[2] { null, null }; using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient()) { for (int i=0;i<2;i++) { using (var zipStream = client.GetStreamAsync(urls[i]).Result) { using (System.IO.Compression.ZipArchive archive = new System.IO.Compression.ZipArchive(zipStream)) { using (System.IO.StreamReader reader = new System.IO.StreamReader(archive.Entries[0].Open(), System.Text.Encoding.Default)) { sources[i] = reader.ReadToEnd(); System.IO.File.WriteAllText((i == 0 ? "t" : "k") + archive.Entries[0].Name, sources[i], Encoding.Default); } } } } } Dictionary<int, string[]> dicIndexMarket = new Dictionary<int, string[]>(); string indexfile = @"Z:\data\trade\OmegaChart\index.txt"; string[] lines = System.IO.File.ReadAllLines(indexfile, Encoding.Default); foreach (string line in lines) { string[] cols = line.Split(','); if (cols.Contains("OBS")) continue; if (int.TryParse(cols[0], out int code)) { dicIndexMarket.Add(code, new string[]{cols[1], cols[2], cols[2].Replace("T1","東証1部").Replace("T2","東証2部").Replace("J","JAQ").Replace("M","東証マ") }); } }
| - OmegaChartスレ ver.11
253 :名無しさん@お腹いっぱい。[]:2019/02/12(火) 22:05:53.80 ID:MyBX68rD0 - //>>251 Mujinzou.cs 2
SortedDictionary<int, string> dic = new SortedDictionary<int, string>(); lines = sources[0].Replace("\r", "").Split('\n'); foreach (string line in lines) { if (line.Trim() == "") continue; string[] cols = line.Split(','); int code = int.Parse(cols[1]); if (dic.ContainsKey(code)) { Console.WriteLine("当日株価データに重複して存在しています {0}", code); Console.WriteLine(" 新 :{0}", line); Console.WriteLine(" 既存:{0}", dic[code]); continue; } dic.Add(code, line); } Console.WriteLine("\r\nindex.txtのOBS以外で銘柄当日株価に銘柄コードが見当たらないもの"); foreach (int code in dicIndexMarket.Keys) { if (!dic.ContainsKey(code)) Console.WriteLine(" {0} {1} {2}", code, dicIndexMarket[code][1], dicIndexMarket[code][0]); } Console.WriteLine("\r\nindex.txtに存在しない当日株価の銘柄"); foreach (var pair in dic) { if (pair.Key > 1300 && !dicIndexMarket.ContainsKey(pair.Key)) Console.WriteLine(" {0}", pair.Value); } lines = sources[1].Replace("\r", "").Split('\n'); Dictionary<int, List<string[]>> dicPast = new Dictionary<int, List<string[]>>(); for (int i = 0; i < lines.Length; i++) { if (lines[i].Trim() == "") continue; string[] cols = lines[i].Split(','); int code = int.Parse(cols[01]); if (dicPast.ContainsKey(code)) { List<string[]> list = dicPast[code]; list.Add(cols); dicPast[code] = list; } else dicPast.Add(code, new List<string[]> { cols }); }
| - OmegaChartスレ ver.11
254 :名無しさん@お腹いっぱい。[]:2019/02/12(火) 22:08:52.25 ID:MyBX68rD0 - //>>251 Mujinzou.cs 3
Console.WriteLine("\r\nindex.txtと市場が異なる当日株価の銘柄"); foreach (var pair in dic) { string[] cols = pair.Value.Split(','); if (dicIndexMarket.ContainsKey(pair.Key) && cols[9] != dicIndexMarket[pair.Key][2]) { StringBuilder sb2 = new StringBuilder(); if (!dicPast.ContainsKey(pair.Key)) sb2.Append("該当銘柄なし"); else { foreach (string[] cols2 in dicPast[pair.Key]) { if (cols2[9] == dicIndexMarket[pair.Key][2]) { sb2.Clear(); sb2.Append("[一致]"); sb2.Append(string.Join(",", cols2)); break; } else sb2.Append(cols2[9] + ","); } } if (!sb2.ToString().Contains("[一致]")) { sb2.Remove(sb2.Length - 1, 1); sb2.Append("(一致せず)"); } Console.WriteLine(" {0} omega[{1,-2}] 当日株価:({3}){2} \t過去:{4}\t{5}", pair.Key, dicIndexMarket[pair.Key][1], cols[9], cols[2], sb2.ToString(), dicIndexMarket[pair.Key][0]); } } Console.WriteLine("\r\n過去株価に存在するが当日株価には存在しない銘柄コード"); for (int i = 0; i < lines.Length; i++) { if (lines[i].Trim() == "") continue; int code = int.Parse(lines[i].Split(',')[1]); if (!dic.ContainsKey(code)) Console.WriteLine(" {0}", lines[i]); }
| - OmegaChartスレ ver.11
255 :名無しさん@お腹いっぱい。[]:2019/02/12(火) 22:09:45.24 ID:MyBX68rD0 - //>>251 Mujinzou.cs 4
Console.WriteLine("\r\n過去株価と当日株価の内容が異なるもの"); int prevcode = 0; StringBuilder sb = new StringBuilder(); for (int i=0;i<lines.Length;i++) { if (lines[i].Trim() == "") continue; int code = int.Parse(lines[i].Split(',')[1]); if (!dic.ContainsKey(code)) continue; if (code != prevcode) { if (sb.Length > 0 && !sb.ToString().Contains("当日株価に一致")) Console.WriteLine(sb.ToString()); sb.Clear(); } //過去株価では名証が名古となっている if (lines[i].Replace(",名古",",名証") != dic[code]) { if (code != prevcode) { sb.AppendFormat(" 当日株価:{0}\r\n", dic[code]); sb.AppendFormat(" 過去株価:{0}\r\n", lines[i]); } else sb.AppendFormat(" 過去株価:{0}\r\n", lines[i]); } else if(code == prevcode) { sb.AppendFormat(" 過去株価:{0} 当日株価に一致", lines[i]); } prevcode = code; } Console.WriteLine("hit any key then quit"); Console.ReadKey();
|
|