def csv2fund(filename):
    reader=csv.reader(open(filename,'rU'), delimiter=',')
    reader.next()
    symbols=[]
    dates=[]
    for row in reader:
        if not(row[0] in symbols):
            if not(row[0]=="cash" or row[0] == ''):
                symbols.append(row[0])
        if not(dp.parse(row[3]) in dates):
            dates.append(dp.parse(row[3]))
    print symbols
    reader=csv.reader(open(filename,'rU'), delimiter=',')
    reader.next()
    if not("_CASH" in symbols):
        symbols.append("_CASH")
    vals=numpy.zeros([len(dates),len(symbols)])
    share_table=pandas.DataFrame(index=dates, columns=symbols, data=vals)
    share_table["_CASH"]=0
    # share_table["_CASH"].ix[0]=start_val
    commissions=0

    for row in reader:
        date=dp.parse(row[3])
        order_type=row[2]
        sym = row[0]
        if order_type != 'Deposit Cash':
            price = float(row[5])
            shares=float(row[4])
            commission=float(row[7])

        if order_type=="Deposit Cash":
            cash = float(row[6])
            share_table["_CASH"].ix[date]=share_table.ix[date]["_CASH"]+ cash
        if order_type=="Buy":
            share_table.ix[date][sym]+=shares
            commissions=commissions+float(commission)
            share_table["_CASH"].ix[date]=share_table.ix[date]["_CASH"]-float(price)*float(shares)-float(commission)
        if order_type=="Sell":
            share_table[sym].ix[date]+=-1*shares
            commissions=commissions+float(commission)
            share_table["_CASH"].ix[date]=share_table.ix[date]["_CASH"]+float(price)*float(shares)-float(commission)
        if order_type=="Sell Short":
            share_table[sym].ix[date]+=-1*shares
            commissions=commissions+float(commission)
            share_table["_CASH"].ix[date]=share_table.ix[date]["_CASH"]+float(price)*float(shares)-float(commission)
        if order_type=="Buy to Cover":
            share_table.ix[date][sym]+=shares
            commissions=commissions+float(commission)
            share_table["_CASH"].ix[date] = share_table.ix[date]["_CASH"]-float(price)*float(shares)-float(commission)
    share_table = share_table.cumsum()
    time_index = sorted(share_table.index)
    column_index = sorted(share_table.columns)
    share_table = share_table.reindex(index=time_index, columns=column_index)
    i_start_cash = share_table["_CASH"].ix[0]
    print i_start_cash
    return [share_table, commissions, i_start_cash]

# def ofx2fund(filename, start_val):
#     """
#     @summary converts a ofx file to a fund with the given starting value
#     @param filename: ofx file to open and convert
#     @param start_val: starting value for the portfolio
#     @return fund : time series containing fund value over time
#     @return leverage : time series containing fund value over time
#     @return slippage : value of slippage over the ofx time
#     @return commissions : value of slippage over the ofx time
#     """
#     try:
#         from ofxparse import OfxParser
#     except:
#         print "ofxparse is required to use ofx2fund"
#         exit()
#     ofx = OfxParser.parse(file(filename))
#     symbols=[]
#     dates=[]
#     for order in ofx.account.statement.transactions:
#         sym=order.security.split(":")[1]
#         if not(sym in symbols):
#             symbols.append(sym)
#         date=order.tradeDate
#         if not(date in dates):
#             dates.append(date)
#     dates.sort()
#     vals=numpy.zeros([len(dates),len(symbols)+1])
#     symbols.append("_CASH")
#     share_table=pandas.DataFrame(index=dates, columns=symbols, data=vals)
#     share_table.ix[0]["_CASH"]=start_val
#     for order in ofx.account.statement.transactions:
#         sym=order.security.split(":")[1]
#         share_table.ix[order.tradeDate][sym]=order.units
#         share_table.ix[order.tradeDate]["_CASH"]=share_table.ix[order.tradeDate]["_CASH"]-float(order.unit_price)*float(order.units)
#     share_table=share_table.cumsum()
#     slippage=0
#     commissions=0
#     return [share_table, slippage, commissions]
@summary converts a csv file to a fund with the given starting value
dataset/ETHPy150Open QuantSoftware/QuantSoftwareToolkit/QSTK/qstktools/csv2fund.py/csv2fund