top of page
Search

Simple code for processing BTC prices with dataframe and statistical normalization

  • Writer: Boris Mikhailovski
    Boris Mikhailovski
  • Jun 20, 2021
  • 1 min read


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()


ree

 
 
 

Recent Posts

See All
CrewAI

I believe that CrewAI's three-tier architecture is one of its most compelling design features. Practical Benefits especially with DDD...

 
 
 
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...

 
 
 

Comments


Post: Blog2_Post

Subscribe Form

Thanks for submitting!

  • LinkedIn

©2021 by Bora Tech. Proudly created with Wix.com

bottom of page