forked from core-plot/core-plot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPFinancialData.m
More file actions
34 lines (27 loc) · 1.37 KB
/
Copy pathAPFinancialData.m
File metadata and controls
34 lines (27 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#import "APFinancialData.h"
#import "NSDateFormatterExtensions.h"
@implementation NSDictionary(APFinancialData)
+(CPTDictionary)dictionaryWithCSVLine:(NSString *)csvLine
{
CPTStringArray csvChunks = [csvLine componentsSeparatedByString:@","];
CPTMutableDictionary csvDict = [NSMutableDictionary dictionaryWithCapacity:7];
// Date,Open,High,Low,Close,Volume,Adj Close
// 2009-06-08,143.82,144.23,139.43,143.85,33255400,143.85
NSDate *theDate = [[NSDateFormatter csvDateFormatter] dateFromString:csvChunks[0]];
csvDict[@"date"] = theDate;
NSDecimalNumber *theOpen = [NSDecimalNumber decimalNumberWithString:csvChunks[1]];
csvDict[@"open"] = theOpen;
NSDecimalNumber *theHigh = [NSDecimalNumber decimalNumberWithString:csvChunks[2]];
csvDict[@"high"] = theHigh;
NSDecimalNumber *theLow = [NSDecimalNumber decimalNumberWithString:csvChunks[3]];
csvDict[@"low"] = theLow;
NSDecimalNumber *theClose = [NSDecimalNumber decimalNumberWithString:csvChunks[4]];
csvDict[@"close"] = theClose;
NSDecimalNumber *theVolume = [NSDecimalNumber decimalNumberWithString:csvChunks[5]];
csvDict[@"volume"] = theVolume;
NSDecimalNumber *theAdjClose = [NSDecimalNumber decimalNumberWithString:csvChunks[6]];
csvDict[@"adjClose"] = theAdjClose;
//non-mutable autoreleased dict
return [NSDictionary dictionaryWithDictionary:csvDict];
}
@end