top of page
Search
  • Writer's pictureBoris Mikhailovski

Simple code for processing BTC prices with dataframe and statistical normalization



import datetime
import matplotlib.pyplot as plt
import matplotlib.dates as dates
from pycoingecko import CoinGeckoAPI
import statistics
import pandas as nd

cg = CoinGeckoAPI()
btcprice = cg.get_price(ids='bitcoin', vs_currencies='usd')
mult = cg.get_price(ids='bitcoin,litecoin,ethereum', vs_currencies='usd')
history = cg.get_coin_market_chart_range_by_id(id='bitcoin', vs_currency='usd', from_timestamp='1604906000',
                                               to_timestamp='1605099600')

vmax = max(list(zip(*history['prices']))[1])
vmin = min(list(zip(*history['prices']))[1])
delta = vmax - vmin
# dfObj = nd.DataFrame(history['prices'], columns=['date', 'normalized'])
dfObj = nd.DataFrame.from_records(history['prices'],
                                  columns=['date', 'normalized'])

dfObj['normalized'] = dfObj['normalized'].apply(lambda x: (x - vmin) / delta)

dfObj['date'] = dfObj['date'].apply(lambda x: datetime.datetime.fromtimestamp(x / 1000).strftime("%d/%m-%H:%M"))

print(dfObj)

formatter = dates.DateFormatter('%H:%M')
dfObj.plot(style='k.', subplots=True)

plt.gcf().axes[0].xaxis.set_major_formatter(formatter)

lines = dfObj.plot.line(y='normalized', x='date')

plt.show()



12 views0 comments

Recent Posts

See All

NLP and NODE.JS PDF sample parser

One of important things of having users to upload documents is to ability verify & check that the document is of the expected type and contains appropriate information. * for python consider usage of

Holistic ProdOPS concept [work in progress]

#ProdOPS mission is to harmonize relations between product enablement processes, products value creation, and products experience. Without proper product operations, the product has a greater chance b

Comentarios


Post: Blog2_Post
bottom of page