コード例 #1
0
def convert_schwab_pos_file(infile, file=None):
    '''Convert Positions export (.CSV) from Schwab to Fidelity format.'''
    stamp = infile.split('_')[-1]
    stamp = stamp.split('.')[0]
    with open(infile) as csv:
        acct_num = csv.readline().split()[4]
    acct_num = acct_num.replace('XXXX', os.path.basename(infile)[:4])
    outfile = 'fi' + acct_num + '_' + stamp + '.pos'

    def pos(values, outfile, acct_num=acct_num, **kwargs):
        symbol = values[0]
        description = values[1][:40]
        quantity = float(values[2])
        # values[3] == price
        # values[4] == price change $
        # values[5] == price change %
        # values[6] == market value
        # values[7] == day change $
        # values[8] == day change %
        # values[9] == Cost Basis
        # values[10] == Gain/Loss $
        # values[11] == Gain/Loss %
        # values[12] == Reinvest Dividends?
        # values[13] == Capital Gains?
        # values[14] == % Of Account
        # values[15] == Security Type
        #"SPY","S P D R S&P 500 ETF TR EXPIRES 01/22/2118","117","$204.50","-$0.48","-0.23%","$23,926.50","-$56.16","-0.23%","$17,508.94","$6,417.56","+36.65%","No","--","62.16%","ETFs & Closed End Funds",
        #"BUFBX","BUFFALO FLEXIBLE INCOME FUND","961.733","$14.32","-$0.02","-0.14%","$13,772.02","-$19.23","-0.14%","$12,600.00","$1,172.02","+9.3%","No","No","35.78%","Mutual Fund",
        #"Cash & Money Market","--","--","--","--","--","$796.11","$0.00","0%","--","--","--","--","--","2.07%","Cash and Money Market",
        #"Account Total","--","--","--","--","--","$38,494.63","-$75.39","-0.2%","$30,108.94","$7,589.58","+25.21%","--","--","--","--",
        sec_type = ''  #values[2] and 'mf'  # Mutual Funds only from TIAA-CREF
        symbol = values[3].lower()
        quantity = float(values[4])
        amount = float(values[5])

        # Other values
        acct_type = 1  # Cash account
        cusip = ''
        trade_date_quantity = settle_date_quantity = quantity
        close_price = ''  # >15.05f
        dts = os.path.basename(outfile)[2:8]
        date_str = '20{}{}'.format(dts[-2:],
                                   dts[:-2])  # Convert MMDDYY to YYYYMMDD
        factor = face_amount = clean_price = factored = ''
        option_symbol = ''
        rep1 = '000'  # Apparently C&D-specific values
        rep2 = 'J62'  # Apparently C&D-specific values

        # NOTE: Verify the need for closing_price, cusip, and description
        output = (
            '{acct_num:14} {acct_type:1d} {cusip:9} {symbol:9} '
            '{trade_date_quantity:>15.05f} {settle_date_quantity:>15.05f} '
            '{close_price:15} {description:40} {date_str:8} '
            '{factor:17} {face_amount:18} {clean_price:18} {factored:1} '
            '{sec_type:2} {option_symbol:30} {rep1:3}{rep2:3}')

        return output.format(**locals())

    return convert_csv(infile, outfile, pos, file, mode='a', headers=3)
コード例 #2
0
ファイル: AphidGui.py プロジェクト: cmhulbert/AphidGui
 def get_headers(self,file):
     '''
     given a csv file, it will return the headers
     (first row), as a list
     '''
     with open(file, 'r') as csv:
         header_string = csv.readline()
         return header_string.split(',')
コード例 #3
0
ファイル: fidoconvert.py プロジェクト: ontoral/candd
def convert_schwab_pos_file(infile, file=None):
    '''Convert Positions export (.CSV) from Schwab to Fidelity format.'''
    stamp = infile.split('_')[-1]
    stamp = stamp.split('.')[0]
    with open(infile) as csv:
        acct_num = csv.readline().split()[4]
    acct_num = acct_num.replace('XXXX', os.path.basename(infile)[:4])
    outfile = 'fi' + acct_num + '_' + stamp + '.pos'

    def pos(values, outfile, acct_num=acct_num, **kwargs):
        symbol = values[0]
        description = values[1][:40]
        quantity = float(values[2])
        # values[3] == price
        # values[4] == price change $
        # values[5] == price change %
        # values[6] == market value
        # values[7] == day change $
        # values[8] == day change %
        # values[9] == Cost Basis
        # values[10] == Gain/Loss $
        # values[11] == Gain/Loss %
        # values[12] == Reinvest Dividends?
        # values[13] == Capital Gains?
        # values[14] == % Of Account
        # values[15] == Security Type
#"SPY","S P D R S&P 500 ETF TR EXPIRES 01/22/2118","117","$204.50","-$0.48","-0.23%","$23,926.50","-$56.16","-0.23%","$17,508.94","$6,417.56","+36.65%","No","--","62.16%","ETFs & Closed End Funds",
#"BUFBX","BUFFALO FLEXIBLE INCOME FUND","961.733","$14.32","-$0.02","-0.14%","$13,772.02","-$19.23","-0.14%","$12,600.00","$1,172.02","+9.3%","No","No","35.78%","Mutual Fund",
#"Cash & Money Market","--","--","--","--","--","$796.11","$0.00","0%","--","--","--","--","--","2.07%","Cash and Money Market",
#"Account Total","--","--","--","--","--","$38,494.63","-$75.39","-0.2%","$30,108.94","$7,589.58","+25.21%","--","--","--","--",
        sec_type = '' #values[2] and 'mf'  # Mutual Funds only from TIAA-CREF
        symbol = values[3].lower()
        quantity = float(values[4])
        amount = float(values[5])

        # Other values
        acct_type = 1  # Cash account
        cusip = ''
        trade_date_quantity = settle_date_quantity = quantity
        close_price = ''  # >15.05f
        dts = os.path.basename(outfile)[2:8]
        date_str = '20{}{}'.format(dts[-2:], dts[:-2])  # Convert MMDDYY to YYYYMMDD
        factor = face_amount = clean_price = factored = ''
        option_symbol = ''
        rep1 = '000'  # Apparently C&D-specific values
        rep2 = 'J62'  # Apparently C&D-specific values

        # NOTE: Verify the need for closing_price, cusip, and description
        output = ('{acct_num:14} {acct_type:1d} {cusip:9} {symbol:9} '
                  '{trade_date_quantity:>15.05f} {settle_date_quantity:>15.05f} '
                  '{close_price:15} {description:40} {date_str:8} '
                  '{factor:17} {face_amount:18} {clean_price:18} {factored:1} '
                  '{sec_type:2} {option_symbol:30} {rep1:3}{rep2:3}')

        return output.format(**locals())

    return convert_csv(infile, outfile, pos, file, mode='a', headers=3)
コード例 #4
0
def load_csv(filepath):
    """Read and convert a CSV file in the prettytable format."""

    csv = open(filepath, 'r')
    for i in range(2):
        csv.readline()  # skip the first two lines

    lin = csv.readline()
    f, p_0, p_1 = [], [], []
    while lin != "":
        if lin.count('+') == 5:
            pass
        else:
            dat = lin.split('|')
            f_i = float(dat[1].strip())
            p0_i = float(dat[2].strip())
            p1_i = float(dat[3].strip())
            f.append(f_i)
            p_0.append(p0_i)
            p_1.append(p1_i)
        lin = csv.readline()

    csv.close()
    return f, p_0, p_1
コード例 #5
0
def getOffsetsAndSensitivity(boardNo):
    i=1
    fileName=boardNo+'.csv'
    csv=open(fileName, 'r')
    hdr = csv.readline()
    hdr = hdr.strip().split(',')
    d = defaultdict(list)
    for line in csv:
        row = line.strip().split(',')
        for i in range(len(hdr)):
            key = str(hdr[i])
            value = str(row[i])
            d[key].append(value)
            
    csv.close()    
    return d
コード例 #6
0
ファイル: CSV.py プロジェクト: calebhailey/sqlitemaker
 def _get_row_by_line_num(self, line_num):
     csv = codecs.open(self.file.name, self.file.mode, self.file.encoding)
     count = 0
     while True:
         line = csv.readline()
         count += 1
         if count == line_num + 1:
             break
     delimiter = '%s%s%s' % (self.dialect.quotechar, self.dialect.delimiter, self.dialect.quotechar)
     line = line.lstrip(self.dialect.quotechar).rstrip(self.dialect.quotechar)
     line = line.split(delimiter)
     line_dict = {}
     for field in self.data.fieldnames:
         index = self.data.fieldnames.index(field)
         line_dict[field] = line[index]
     return line_dict
コード例 #7
0
    def getOffsetsAndSensitivity(self):
        # i=1
        fileName = self.O3boardNo + '.csv'
        csv = open(fileName, 'r')
        hdr = csv.readline()
        hdr = hdr.strip().split(',')
        self.gasOffsetsAndSensitivity = defaultdict(list)
        lines = csv.readlines()
        for line in lines:
            row = line.strip().split(',')
            for i in range(1, len(hdr)):
                key = str(hdr[i])
                value = str(row[i])
                self.gasOffsetsAndSensitivity[key].append(value)

        csv.close()
        return self.gasOffsetsAndSensitivity
コード例 #8
0
def read_csv2(path):
    csv = open(path, 'r')
    data = []
    keys = []
    # collect keys from 1st line and init data
    for i in csv.readline().rstrip().split(','):
        keys.append(i)
    # fill data with values
    for i in csv.readlines():
        obj = {}
        for key, val in zip(keys, i.rstrip().split(',')):
            if re.match(r'\d*\.?\d+', val):
                obj[key] = float(val)
            else:
                obj[key] = val
        data.append(obj)

    return data
コード例 #9
0
        ax.imshow(img)
        for (x1,y1,x2,y2) in orig_coords:
            rect = Rectangle((x1,y1),x2-x1, y2-y1, edgecolor='r', fill=False)
            ax.add_patch(rect)
    plt.show()

def test_crop_results(img, orig_coords, region, percent):
    print(orig_coords)
    cropped_img, cropped_coords = crop(img, orig_coords, region, percent)
    print(cropped_coords)
    show_img_with_fractions(img, orig_coords, cropped_img=cropped_img, cropped_coords=cropped_coords)

from PIL import Image

csv = open(CSV_SAVE_PATH + '\\new_validation_' + extension[1:] + '.csv', 'r')
img_path, x1, y1, x2, y2, _ = csv.readline().split(',')
orig_coords = np.array([[int(x1), int(y1), int(x2), int(y2)]])
while True:
    new_img_path, x1, y1, x2, y2, _ = csv.readline().split(',')
    if new_img_path != img_path:
        break
    orig_coords = np.append(orig_coords, [[int(x1), int(y1), int(x2), int(y2)]], axis=0)

if __name__ == '__main__':
    TL = 1
    ML = 2
    BR = 3
    TM = 4
    MM = 5
    BM = 6
    TR = 7
コード例 #10
0
ファイル: dbint.py プロジェクト: ManushGupta/the-mean-manager
import os
import csv
import fileinput

dirs = os.listdir(os.getcwd()+'/csv')

for f in dirs:
	csv=open(f,'r')
	print csv.readline()
コード例 #11
0
def readdata(fname):
    print(f"readdata: reading from File: {fname}")
    csv = open(fname, mode="r")
    csv.readline()
    return csv