def test_prices_from_returns():
    df = get_data()
    returns_df = df.pct_change()  # keep NaN row

    # convert pseudo-price to price
    pseudo_prices = expected_returns.prices_from_returns(returns_df)
    initial_prices = df.bfill().iloc[0]
    test_prices = pseudo_prices * initial_prices

    # check equality, robust to floating point issues
    assert ((test_prices[1:] - df[1:]).fillna(0) < 1e-10).all().all()
Beispiel #2
0
def optimize_max_sharpe(returns_df, lowerbound=0, upperbound=1):
    wb = (lowerbound, upperbound)

    ema_returns_df = ema_historical_return(prices_from_returns(returns_df))
    returns_cov_df = returns_df.cov()

    EFOptimizer = EfficientFrontier(ema_returns_df,
                                    returns_cov_df,
                                    weight_bounds=wb)
    weights_dict = EFOptimizer.max_sharpe()

    return weights_dict