You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.5 KiB
53 lines
1.5 KiB
''' |
|
''' |
|
import csv |
|
import datetime |
|
|
|
class Series: |
|
|
|
def __init__(self): |
|
self.data = [] |
|
|
|
def load_from_finam_csv(self, filepath): |
|
with open(filepath) as fp: |
|
self.ticker_ = None |
|
reader = csv.reader(fp, delimiter=',') |
|
next(reader) |
|
for row in reader: |
|
try: |
|
self.ticker_ = row[0] |
|
open_ = float(row[4]) |
|
high = float(row[5]) |
|
low = float(row[6]) |
|
close = float(row[7]) |
|
volume = int(row[8]) |
|
date = row[2] |
|
time = row[3] |
|
dt = datetime.datetime.strptime(date + "_" + time, "%Y%m%d_%H%M%S") |
|
self.append_bar(dt, open_, high, low, close, volume) |
|
except IndexError: |
|
pass |
|
|
|
def append_bar(self, dt, open_, high, low, close, volume): |
|
self.data.append((dt, open_, high, low, close, volume)) |
|
|
|
def get_dt(self, index): |
|
return self.data[index][0] |
|
|
|
def get_open(self, index): |
|
return self.data[index][1] |
|
|
|
def get_high(self, index): |
|
return self.data[index][2] |
|
|
|
def get_low(self, index): |
|
return self.data[index][3] |
|
|
|
def get_close(self, index): |
|
return self.data[index][4] |
|
|
|
def get_volume(self, index): |
|
return self.data[index][5] |
|
|
|
def length(self): |
|
return len(self.data) |