Пример #1
0
def return_sr(weights, data):
    """
    Telle me what the 
    
    In this simplified version we assume all assets have the same volatility and mean returns
    
    This means we only need to use the correlation matrix instead of the covariance
    And a dull vector of returns
    
    You can change this if required.... 
    """
    
    sigma=correlation_matrix(data)
    
    default_SR=1.0
    mus=np.array([(sigma.diagonal()[idx]**.5)*default_SR/16.0 for idx in range(len(data.columns))], ndmin=2).transpose()
    
    return -neg_SR(weights, sigma,mus)
Пример #2
0
if __name__=="__main__":
    
    ## Get the data
    
    """
    This is a trivial example, 3 possible assets, portfolio of 2
    
    """
    
    filename="assetprices.csv"
    data=pd_readcsv(filename)
    asset_names=data.columns
    
    assets_to_add=2
    
    cmat=correlation_matrix(data)
    
    instrument_index=instrument_index_list(data.shape[1])
    first_index=find_most_diversifying_asset(cmat)
    instrument_index.add(first_index)
    print "Started with %s" % asset_names[first_index] 
    
    while len(instrument_index.in_portfolio)<assets_to_add:
        current_portfolio=instrument_index.in_portfolio
        candidates=instrument_index.not_in_portfolio
        new_addition=find_best_addition(data, candidates, current_portfolio)
        print "Adding %s" % asset_names[new_addition]
        
        instrument_index.add(new_addition)
    
    print "Selected portfolio:"