Esempio n. 1
0
def test_monte_carlo():
    skew1 = skew_normal_density(L=25, unit=unit, a=1.5)
    densities = [skew1, skew1, skew1]
    densityAll, multiplicityAll = winner_of_many(densities)
    densityAllCheck = sample_winner_of_many(densities, nSamples=5000)
    assert all(
        abs(p1 - p2) < 3e-2 for p1, p2 in zip(densityAll, densityAllCheck))
def demo():
    densities = [
        skew_normal_density(L=L, unit=unit, a=0.3 * i) for i in range(25)
    ]
    best, multiplicity = winner_of_many(densities)
    densitiesPlot([d / unit
                   for d in densities[:5]] + [best / unit, multiplicity], unit)
def demo():
    skew1 = skew_normal_density(L=25, unit=unit, a=1.5)
    densities = [skew1, skew1, skew1]
    densityAll, multiplicityAll = winner_of_many(densities)
    densityAllCheck = sample_winner_of_many(densities, nSamples=50000)
    if PLOTS:
        densitiesPlot([densityAll, densityAllCheck], unit=0.1)
def demo():
    skew1 = skew_normal_density(L=L, unit=unit, a=1.5)
    skew2 = skew_normal_density(L=L, unit=unit, a=1.5, loc=-0.5)
    skew3 = skew_normal_density(L=L, unit=unit, a=1.5, loc=-1.0)
    best, multiplicity = winner_of_many([skew1, skew2, skew3])
    densitiesPlot(
        [skew1 / unit, skew2 / unit, skew3 / unit, best / unit, multiplicity],
        unit,
        legend=['1', '2,', '3', 'best', 'multiplicity'])
Esempio n. 5
0
def test_calibration():
    skew1 = skew_normal_density(L=L, unit=unit, a=1.5)
    prices = [0.2, 0.3, 0.5]
    implied_offsets = solve_for_implied_offsets(prices=prices,
                                                density=skew1,
                                                nIter=2)
    inferred_prices = state_prices_from_offsets(skew1, implied_offsets)
    print(str(inferred_prices))
    densities = densities_from_offsets(skew1, implied_offsets)
    densityAllAgain, multiplicityAll = winner_of_many(densities)
def demo():
    skew1                   = skew_normal_density(L=L, unit = unit, a=1.5)
    prices                  = [ 0.2, 0.3, 0.5 ]
    implied_offsets         = solve_for_implied_offsets(prices = prices, density = skew1, nIter = 2)
    inferred_prices         = state_prices_from_offsets( skew1, implied_offsets )
    print(str(inferred_prices))
    densities               = densities_from_offsets( skew1, implied_offsets )
    densityAllAgain, multiplicityAll  = winner_of_many(densities)
    if PLOTS:
        densitiesPlot( [ densityAllAgain ] + densities, unit = 0.1, legend = ['guess','analytic','1','2','3'] )
Esempio n. 7
0
def test_implicit_payoffs():
    skew1 = skew_normal_density(L=L, unit=unit, a=1.5)
    skew2 = skew_normal_density(L=L, unit=unit, a=1.5, loc=-0.5)
    skew3 = skew_normal_density(L=L, unit=unit, a=1.5, loc=-1.0)
    densityAll, multiplicityAll = winner_of_many([skew1, skew2, skew3])
    payoffs = implicit_state_prices(density=skew1,
                                    densityAll=densityAll,
                                    multiplicityAll=multiplicityAll,
                                    cdf=None,
                                    cdfAll=None,
                                    offsets=None)
Esempio n. 8
0
def demo():
    skew1 = skew_normal_density(L=L, unit=unit, a=1.5)
    skew2 = skew_normal_density(L=L, unit=unit, a=1.5, loc=-0.5)
    skew3 = skew_normal_density(L=L, unit=unit, a=1.5, loc=-1.0)
    densityAll, multiplicityAll = winner_of_many([skew1, skew2, skew3])
    payoffs = implicit_state_prices(density=skew1,
                                    densityAll=densityAll,
                                    multiplicityAll=multiplicityAll,
                                    cdf=None,
                                    cdfAll=None,
                                    offsets=None)
    import matplotlib.pyplot as plt
    plt.plot(payoffs)
    plt.show()
Esempio n. 9
0
def test_minimumPdf():
    skew1 = skew_normal_density(L=L, unit=unit, a=1.5)
    skew2 = skew_normal_density(L=L, unit=unit, a=1.5, loc=-0.5)
    skew3 = skew_normal_density(L=L, unit=unit, a=1.5, loc=-1.0)
    best, multiplicity = winner_of_many([skew1, skew2, skew3])
def solve_for_implied_offsets(prices,
                              density,
                              offset_samples=None,
                              implied_offsets_guess=None,
                              nIter=3,
                              verbose=False,
                              visualize=False):
    """
    This is the main routine.

    See the paper for details, in the /doc folder
    https://github.com/microprediction/winning/blob/main/docs/Horse_Race_Problem__SIAM_updated.pdf

        offset_samples   Optionally supply a list of offsets which are used in the interpolation table  a_i -> p_i

    """

    L = implied_L(density)
    if offset_samples is None:
        offset_samples = list(range(int(-L / 2), int(L / 2)))[::-1]
    else:
        _assert_descending(offset_samples)

    if implied_offsets_guess is None:
        implied_offsets_guess = list(range(int(L / 3)))

    # First guess at densities
    densities, coefs = densities_and_coefs_from_offsets(
        density, implied_offsets_guess)
    densityAllGuess, multiplicityAllGuess = winner_of_many(densities)
    densityAll = densityAllGuess.copy()
    multiplicityAll = multiplicityAllGuess.copy()

    if verbose:
        guess_prices = [
            np.sum(
                expected_payoff(density,
                                densityAll,
                                multiplicityAll,
                                cdf=None,
                                cdfAll=None)) for density in densities
        ]

    for _ in range(nIter):
        if visualize:
            from winning.lattice_plot import densitiesPlot
            # temporary hack to check progress of optimization
            densitiesPlot([densityAll] + densities, unit=0.1)

        # Main iteration...
        implied_prices = implicit_state_prices(density=density,
                                               densityAll=densityAll,
                                               multiplicityAll=multiplicityAll,
                                               offsets=offset_samples)
        implied_offsets = np.interp(prices, implied_prices, offset_samples)
        densities = densities_from_offsets(density, implied_offsets)
        densityAll, multiplicityAll = winner_of_many(densities)

        if verbose:
            guess_prices = [
                np.sum(
                    expected_payoff(density,
                                    densityAll,
                                    multiplicityAll,
                                    cdf=None,
                                    cdfAll=None)) for density in densities
            ]
            approx_prices = [np.round(pri, 3) for pri in prices]
            approx_guesses = [np.round(pri, 3) for pri in guess_prices]

            print(zip(approx_prices, approx_guesses)[:5])

    return implied_offsets