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

New tokens on the KickEX exchange

JASMY: the cornerstone of safe, free and efficient business in the post-pandemic era

What is Sharding?

Rise of Blockchain and Its Global Adoption [Part 2]

AMA RECAP: BLOCKCHAIN INFINITY X RIKKEI FINANCE

Authtrail Integrates KILT Protocol DIDs Using DIDsign

Playcent AMA Summary with Decentralized Club ✔️

Matic Network Becomes Polygon, Ethereum’s Internet of Blockchains — Expands Mission and Tech Scope

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 Nuclear Option

Counting mitochondria

What does a Spacecraft Operations Engineer do? Smiti Dhami’s journey

Next-level gene editing with DARTs