Beispiel #1
0
def _plot_corr(s1, s2, **kwargs):
    if not kwargs.get("label"):
        kwargs["label"] = "correlation"
    d1 = series_to_dict(price_diff(s1))
    d2 = series_to_dict(price_diff(s2))
    s = []
    for a in s1:
        if a[0] not in d2:
            continue
        if d1[a[0]] * d2[a[0]] > 0:
            s.append((a[0], 100))
        else:
            s.append((a[0], 0))
    s = moving_average(s, days=28)
    plt.plot([a[0] for a in s], [a[1] for a in s], **kwargs)
Beispiel #2
0
def draw_coin(coin):
    fig = plt.figure()
    fig.show()

    if 'usd' in config.CHART_METRICS:
        _plot(coin,
              'usd_norm',
              label="{}/USD".format(coin.name),
              color="blue",
              linestyle="-")
    if coin.name != 'bitcoin':
        if 'btc' in config.CHART_METRICS:
            _plot(coin,
                  'btc_norm',
                  label="{}/BTC".format(coin.name),
                  color="blue",
                  linestyle="--")
    if 'supply' in config.CHART_METRICS:
        _plot(coin,
              'supply_norm',
              label="supply".format(coin.name),
              color="green",
              linestyle="--")
    if coin.cmc.sub:
        if 'subs' in config.CHART_METRICS:
            _plot(coin,
                  'subs_norm',
                  label="r/{} subscribers".format(coin.cmc.sub),
                  color="red",
                  linestyle="-",
                  linewidth=2)
        if 'asubs' in config.CHART_METRICS:
            _plot(coin,
                  'asubs_norm',
                  label="r/{} active users".format(coin.cmc.sub),
                  color="red",
                  linestyle=":",
                  linewidth=2)
    if coin.cmc.twt:
        if 'flw' in config.CHART_METRICS:
            _plot(coin,
                  'flw_norm',
                  label="@{} followers".format(coin.cmc.twt),
                  color="cyan",
                  linestyle="-",
                  linewidth=2)

    if coin.name != 'bitcoin':
        if 'btcusd' in config.CHART_METRICS:
            _plot(Coin('bitcoin'),
                  'usd_norm',
                  label="BTC/USD",
                  color="orange",
                  linestyle="--")

    if 'ma28' in config.CHART_METRICS:
        _plot(coin,
              'usd_norm',
              label="{}/USD MA28".format(coin.name),
              mut=lambda s: moving_average(s, days=28))
    if 'ma100' in config.CHART_METRICS:
        _plot(coin,
              'usd_norm',
              label="{}/USD MA100".format(coin.name),
              mut=lambda s: moving_average(s, days=100))

    if 'xusddiff' in config.CHART_METRICS:
        _plot(coin,
              'usd',
              label="{}/USD diff".format(coin.name),
              mut=lambda s: price_diff(s))

    if coin.name != 'bitcoin':
        if 'btcusddiff' in config.CHART_METRICS:
            _plot(Coin('bitcoin'),
                  'usd',
                  label="BTC/USD diff",
                  mut=lambda s: price_diff(s))

    if coin.name != 'bitcoin':
        if 'btcusdxusdcorr' in config.CHART_METRICS:
            _plot_corr(Coin('bitcoin').usd_norm,
                       coin.usd_norm,
                       label="{}/USD corr_btc".format(coin.name),
                       color="black",
                       linestyle="--")
        if 'btcusdxbtccorr' in config.CHART_METRICS:
            _plot_corr(Coin('bitcoin').usd_norm,
                       coin.btc_norm,
                       label="{}/BTC corr_btc".format(coin.name),
                       color="black",
                       linestyle=":")
        if 'xusdnextdaycorrbtc' in config.CHART_METRICS:
            _plot_corr(Coin('bitcoin').usd_norm,
                       series_shift(coin.usd_norm, 1),
                       label="{}/USD next day corr_btc".format(coin.name),
                       style="y:")
        if 'xusdprevdaycorrbtc' in config.CHART_METRICS:
            _plot_corr(Coin('bitcoin').usd_norm,
                       series_shift(coin.usd_norm, -1),
                       label="{}/USD prev day corr_btc".format(coin.name),
                       style="b:")

    if coin.name == 'bitcoin':
        if 'tethersupply' in config.CHART_METRICS:
            _plot(Coin('tether'),
                  "supply_norm",
                  label="Tether supply",
                  color="green",
                  linestyle=":")

        if 'ntx' in config.CHART_METRICS or 'ntxsquared' in config.CHART_METRICS:
            coin.n_transactions = [
                a for a in BlockchainCom.fetch_data("n-transactions")
                if a[0] >= config.DATE_START
            ]
            normalize(coin, "n_transactions")
            coin.n_transactions_squared = [(a[0], a[1]**2)
                                           for a in coin.n_transactions]
            normalize(coin, "n_transactions_squared")
            if 'ntx' in config.CHART_METRICS:
                _plot(coin,
                      "n_transactions_norm",
                      label="n_transactions",
                      color="violet",
                      linestyle=":")
            if 'ntxsquared' in config.CHART_METRICS:
                _plot(coin,
                      "n_transactions_squared_norm",
                      label="n_transactions_squared",
                      color="violet",
                      linestyle=":")

        if 'difficulty' in config.CHART_METRICS:
            coin.difficulty = [
                a for a in BlockchainCom.fetch_data("difficulty")
                if a[0] >= config.DATE_START
            ]
            coin.difficulty.append(BtcCom.get_next_diff())
            normalize(coin, "difficulty")
            _plot(coin,
                  "difficulty_norm",
                  label="difficulty",
                  color="brown",
                  linestyle="--")

        if 'hashrate' in config.CHART_METRICS:
            coin.hash_rate = [
                a for a in BlockchainCom.fetch_data("hash-rate")
                if a[0] >= config.DATE_START
            ]
            normalize(coin, "hash_rate")
            _plot(coin,
                  "hash_rate_norm",
                  label="hash_rate",
                  color="brown",
                  linestyle=":")

    _draw_end(fig)