marketsim.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:machine-learning-for-trading 作者: arjun-joshua 项目源码 文件源码
def compute_portvals(orders_file = "./orders/orders2.csv", \
                     start_val = 1000000, leverLimit = True):
    # this is the function the autograder will call to test your code
    order = pd.read_csv(orders_file, index_col = 'Date', parse_dates = True, 
                          na_values=['nan'])

    """Create dataframe prices with symbol/dates/prices relevant to the order"""
    start_date = order.index[0]
    end_date = order.index[-1]
    dates = pd.date_range(start_date, end_date)
    symbols = list( order.ix[:,0].unique() ) #ndarray to list of symbols in order
    prices = get_data(symbols, dates)

    """Create dataframe of cash and deposits in stocks, indexed by date"""
    cashStocks = get_cash_stocks(order, prices, symbols, start_val, leverLimit)
    posVals = get_position_values(cashStocks, prices, symbols)
    portVals = posVals.sum(axis = 1)

    return portVals
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号