GB Electricity Generation Data (Part 2)

def load_stackdata(date, period):
import requests
from io import StringIO
import pandas as pd
l1 = 'https://api.bmreports.com/BMRS/'
l2 = 'DETSYSPRICES'
l3 = '/V1?APIKey=' + APIKEY + '&'
l7 = 'ServiceType=csv'
d = date.strftime('%Y-%m-%d')
l4 = "SettlementDate=" + d
l4 += '&SettlementPeriod=' + str(period) + '&'
r = requests.get(l1+l2+l3+l4+l7 )
data = pd.read_csv(StringIO(r.text),
header=None,
skiprows=1)
data = data.iloc[:-1]
colnames = {4: 'bmunitid', 13: 'volume_orig', 12: 'price',
15: 'volume_arb_adj', 16: 'volume_accepted',
8: 'System'}
data = data[[4, 13, 12, 15, 16, 8]].rename(columns=colnames)
return data
import pandas as pd
data = load_stackdata(pd.datetime(2019,3,3), 18)
  1. Any bids or offers that generators offered that weren’t accepted would still be available at the same price.
  2. Any bids or offers that generators had transacted (including arbitrage transactions) could be reversed at that same transaction cost, unless they are flagged as system transactions.
data['volume_untransacted'] = (data.volume_arb_adj 
- data.volume_accepted)
data['volume_transacted'] = (data.volume_untransacted
- data.volume_orig)
data['volume_transacted'] *= np.where(data.System=='T',0.0,1.0)
data['volume_to_sell'] = (np.where(data.volume_untransacted>0,
data.volume_untransacted, 0)
+ np.where(data.volume_transacted>0,
data.volume_transacted, 0))
data['volume_to_buy'] = (np.where(data.volume_untransacted<0,
data.volume_untransacted, 0)
+ np.where(data.volume_transacted<0,
data.volume_transacted, 0))*-1
sells = data.rename({'volume_to_sell': 'volume'})
sells = sells[sells.volume>=0.99]
sells = sells[['bmunitid','price','volume']]
sells.sort_values('price', ascending=True, inplace=True)
sells['total_volume'] = sells.volume.cumsum()
sells = sells[sells.total_volume<250]
buys = data.rename({'volume_to_buy': 'volume'})
buys = buys[buys.volume>=0.99]
buys = buys[['bmunitid','price','volume']]
buys.sort_values('price', ascending=False, inplace=True)
buys['total_volume'] = buys.volume.cumsum()
buys = buys[buys.total_volume<250]
genunitmap = pd.Series(genunits.fueltype.values, 
index=genunits.bmunitid)
sells['fueltype'] = sells.bmunitid.map(genunitmap)
buys['fueltype'] = buys.bmunitid.map(genunitmap)
willingness to buy (back)
willingness to sell extra

--

--

--

Fascinated by what makes societies and markets work, especially in sustainable energy. http://guylipman.com. Views not necessarily reflect those of my employer.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The Blockchain Trilemma

Decentralized EVMOS Spot Market Listing on Injective Pro

What are Sidechains and Childchains?

The tokenized human — You will be assimilated

Definity Legends

Webblen and Algoracle Partner to grow the Algorand Oracle Network

Blockchain Government Market is Projected to Reach a Value of Over USD 8.9 Billion by 2027

Spheron (previously ArgoApp) V2 is here! Here are five use cases

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Guy Lipman

Guy Lipman

Fascinated by what makes societies and markets work, especially in sustainable energy. http://guylipman.com. Views not necessarily reflect those of my employer.

More from Medium

The Scientist’s Prayer

What if Ice didn’t float on water?

Gene Therapy for Interstellar Travel

The Sun and the Mighty Eight