Last active
December 21, 2018 02:47
-
-
Save externvoid/3ef9ba5b5269fc4ecd8e to your computer and use it in GitHub Desktop.
Swiftで日足描画用のCSVファイルを開く ref: https://qiita.com/externvoid@github/items/a2e5bb079b5d208a8bc7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Darwin | |
var result: [[String]] = [] | |
let path = "./TEST_Stock.csv" | |
//let path = "./stest.csv" | |
//NSString.stringWithContentsOfFileを呼ぶと、ambigousとか言うので... | |
do { | |
var data = try String(contentsOfFile: path, | |
encoding: NSUTF8StringEncoding) | |
data.enumerateLines { (line, stop) -> () in | |
result.append(line.componentsSeparatedByString(",")) | |
} | |
} catch let e as NSError {print(e.localizedDescription)} | |
//print(result) | |
// taking last 10 elements | |
let limit = 10 | |
let r: Range<Int> = 0..<result.count-limit | |
result.removeRange(r) | |
for (idx, e) in result.enumerate() { | |
print("\(idx) : \(e)") | |
} | |
var ar: [[Double]] = [] | |
func minmax(result: [[String]], inout ar: [[Double]]) -> (Double, Double) { | |
// taking partial part, #1 to #4 of Array -> ArraySlice | |
let result0 = result.map( {Array($0[1...4])} ) | |
ar = result0.map({$0.map({atof($0)})}) | |
//var max: Double = -1.0, min: Double = Double.infinity//1.0e38 | |
var max: Double = -Double.infinity, min: Double = -max | |
for e in ar { | |
// giita:// tag:swift map reduce | |
max = e.reduce(max, combine: {$0>$1 ? $0 : $1}) | |
min = e.reduce(min, combine: {$0<$1 ? $0 : $1}) | |
} | |
return (min, max) | |
} | |
let tap = minmax(result, ar: &ar) | |
print(tap) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let dateFormatter = DateFormatter() | |
dateFormatter.locale = Locale(identifier: "en_US") | |
dateFormatter.timeZone = TimeZone(abbreviation: "UTC") | |
dateFormatter.dateFormat = "yyyy/MM/dd HH:mm:ss Z" | |
print(dateFormatter.string(from:Date())) | |
dateFormatter.timeZone = TimeZone(abbreviation: "JST") | |
print(dateFormatter.string(from:Date())) | |
dateFormatter.locale = Locale(identifier: "ja_JP") | |
dateFormatter.dateStyle = .medium | |
dateFormatter.timeStyle = .full | |
print(dateFormatter.string(from:Date())) | |
/* print(TimeZone.abbreviationDictionary) */ | |
/* 2018/12/21 02:03:31 +0000 */ | |
/* 2018/12/21 11:03:31 +0900 */ | |
/* 2018/12/21 11時03分31秒 日本標準時 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MDATE | OPEN | HIGH | LOW | CLOSE | VOLUME | |
---|---|---|---|---|---|---|
1987/8/1 | 24755 | 24755 | 24755 | 24755 | 0 | |
1987/8/3 | 24483 | 24483 | 24483 | 24483 | 0 | |
1987/8/4 | 24172 | 24172 | 24172 | 24172 | 0 | |
1987/8/5 | 24297 | 24297 | 24297 | 24297 | 0 | |
1987/8/6 | 24658 | 24658 | 24658 | 24658 | 0 | |
1987/8/7 | 24800 | 24800 | 24800 | 24800 | 0 | |
1987/8/10 | 25119 | 25119 | 25119 | 25119 | 0 | |
1987/8/11 | 25282 | 25282 | 25282 | 25282 | 0 | |
1987/8/12 | 25560 | 25560 | 25560 | 25560 | 0 | |
1987/8/13 | 25575 | 25575 | 25575 | 25575 | 0 | |
1987/8/14 | 25494 | 25494 | 25494 | 25494 | 0 | |
1987/8/17 | 25378 | 25378 | 25378 | 25378 | 0 | |
1987/8/18 | 25344 | 25344 | 25344 | 25344 | 0 | |
1987/8/19 | 25231 | 25231 | 25231 | 25231 | 0 | |
1987/8/20 | 25396 | 25396 | 25396 | 25396 | 0 | |
1987/8/21 | 25559 | 25559 | 25559 | 25559 | 0 | |
1987/8/22 | 25764 | 25764 | 25764 | 25764 | 0 | |
1987/8/24 | 25754 | 25754 | 25754 | 25754 | 0 | |
1987/8/25 | 25643 | 25643 | 25643 | 25643 | 0 | |
1987/8/26 | 25875 | 25875 | 25875 | 25875 | 0 | |
1987/8/27 | 25968 | 25968 | 25968 | 25968 | 0 | |
1987/8/28 | 25974 | 25974 | 25974 | 25974 | 0 | |
1987/8/29 | 26048 | 26048 | 26048 | 26048 | 0 | |
1987/8/31 | 26029 | 26029 | 26029 | 26029 | 0 | |
1987/9/1 | 26118 | 26118 | 26118 | 26118 | 0 | |
1987/9/2 | 25946 | 25946 | 25946 | 25946 | 0 | |
1987/9/3 | 25649 | 25649 | 25649 | 25649 | 0 | |
1987/9/4 | 25744 | 25744 | 25744 | 25744 | 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment