Miloš Vlainić

My GitHub blog: things you might be interested, and probably not...

Freelance gigs (2018-now)

Side jobs and consulting that ran next to - and sometimes before - my full-time data roles. Below are gigs from 2018 through 2020: the largest power-market archive first, then three shorter ML contracts in trading patterns, mass spectrometry, and esports betting.


Balkan Energy / SEEEA (2018)

Power-market analyst, freelance (MATLAB)

Roughly February through November 2018, between my PhD experimental work and the Coursera re-qualification that became my 2019 education blogs. Balkan Energy / SEEEA hired me to stress-test and extend how a trader already forecast South-East European power.

The job was not “ship a product.” It was: look at the market hour by hour, separate regimes that behave differently, fit a small curve inside each regime, and say in plain language when a plant turns on, when load jumps with temperature, and when power crosses a border.

The question

Day-ahead electricity price in this region (Hungarian HUPX, Romanian price, Greek SMP) is set by a stack of producers. Cheap plant runs first. Expensive plant runs only when cheaper plant and imports cannot cover demand - the merit order.

The trader I reported to wanted, before tomorrow’s price is known:

He already had working rules. My job was to check them on data, quantify them, and extend them from Romania to the rest of the Balkans.

My role

Learning the market first

Before any script made sense, I wrote myself a primer on things every later folder assumed:

Idea What it meant here
MW vs MWh Power vs energy; market talk is hourly MW and MWh.
Base / peak / off-peak Peak = 08:00-20:00 working days; off-peak the other 12 hours and whole weekends.
Merit order Run-of-river and lignite at the cheap end; storage and gas engines at the expensive end; wind and solar push the stack down.
ATC and congestion Borders have finite available transfer capacity; if nominations exceed it, capacity is priced and the two countries’ power prices can diverge.
Scheduled vs physical flow What was nominated on paper is not always what was measured on the line.
Plant behaviour Nuclear barely moves; coal cold-starts burn days of fuel; new gas can ramp in ~15 minutes; hydro is energy-limited or river-following.

That is domain work, not a footnote. Bad features came from not knowing the rules.

The house method

The trader’s comments became the house style. In my own words:

  1. Do not pool unlike hours - one year, often one month or half-month, one hour or a tight block. Peak and off-peak products are too coarse for temperature.
  2. Years are not the same sample - new wind, cheap gas, a dry year shifts the level. We treated 2017 as a hot June, 2015 as average, 2016 as cheap gas.
  3. Fit a small curve, then stare at the residual - roughly quadratic for temperature; roughly linear for coal vs price in one regime. Target on Romanian load: error inside about ±150 MW.
  4. Match temperature to the hour - daytime hours vs Tmax, night vs Tmin; Tavg is the blunt instrument.
  5. Cluster by hand, then name the cluster - days whose fleet looks alike grouped first, then a line fitted; outliers marked and often left out.
  6. Use 2D density, not a scatter you pretend to read point by point - price on one axis, production or residual flow on the other.
  7. For borders, the x-axis is a price difference, often yesterday’s - absolute price was the wrong x-axis.
  8. Write the conclusion in a few lines - megawatts, dates, and contradictions left in on purpose.

Romania - coal and gas regimes

National totals first, then plant by plant (Rovinari 3/4/6, Turceni 4/5/7, and others).

Coal: 2015 was the clean year - weekends and holidays could drop a unit. 2016-2017 looked more planned than price-reactive (cheap gas). June 2017 was extreme: high prices, low Danube, you could see an extra unit as price rose and the river fell.

Gas: did not form clean multi-day blocks - a day could start at 3 units and end at 6. 2017 June was the readable part: about 3 units near 44 EUR, 4 near 55 EUR. Gas-versus-price slope steepened as more units were on - opposite of what I had been seeing on coal.

Hydro note (early Romania pass): storage output vs wind and Danube - strong wind or a high river could cut storage even when price looked similar; May 2015 cuts could exceed 1000 MW. Quantifying across all three years was left open.

Load vs temperature - eleven markets

The core operational deliverable: for each country, each summer month, working day vs weekend, heating season - a curve that says how many MW of load move per degree at each hour.

Process went from Romania April-June to all eleven markets June-August, then weekend differences from working-day curves, then September-December working days. Shared machinery: linear deviation, hour-by-hour view, exceptions named (holiday, heat wave).

The requirement stayed ±150 MW on the fit where we could measure it - a tolerance, not a filed certificate that every hour hit it.

Slovenia coal (TEŠ)

Much smaller fleet: TEŠ4, TEŠ5, TEŠ6, with Krško nuclear nearby.

Nuclear on/off did not explain the coal pattern. Fits were a bit better against Hungarian than local price; some clusters came out with negative slope against Slovenian price, which I did not trust.

The result I flagged as most useful: (coal today − coal yesterday) vs (coal yesterday − coal last night). Slope about −1 with a break: if last night’s drop is larger than the break, today’s coal falls by about that extra amount; otherwise today rises. Break about 150 MW with TEŠ6 on, about 50 MW with only a smaller unit on. Weekends were milder than in Romania.

Rovinari and Turceni - on/off diary

Day-by-day log of individual blocks with daily price at every start and stop.

My own closing verdict: price does not usually decide these switches, and the diary was hard to justify on price alone. What survived:

Greek border and HUPX

Cross-border flows into Greece vs spreads between HUPX and Greek SMP. Second pass after feedback on the first presentation.

Takeaways we wrote down and the scripts were built to test:

My own side research (not a client deliverable)

Alongside the job I tried whether Hungarian price is low-dimensional chaos you could forecast with delay embedding and support vector regression - recurrence plots, FFT, mutual-information delay, false nearest neighbours, correlation dimension; Python + scikit-learn and a few MATLAB SVR paths.

Honest outcome: did not beat the hand-fitted CT curves, and the efficient-market / chaos literature I read says evidence for exploitable low-dimensional chaos in prices is weak. It was still my first serious Python ML work - a bridge straight into the Coursera stack I blogged about in 2019.

What I actually learned

What was left open (from my own notes)


TradeButler (spring 2019)

Machine Learning consultant (Keras / TensorFlow, ~4 weeks)

TradeButler wanted a module for a live trading assistant: pattern recognition, not price forecasting. Each sample was a short multivariate window (on the order of 18 ticks) of simple moving-average curves. The label was Buy, Sell, or HOLD. The client aimed for very high recall on plotted patterns with few outright mistakes and fast inference - while positives were only on the order of 0.09-0.16% of all sliding windows on real backtest charts.

I logged about 105 hours over four weeks, mostly on Kaggle GPUs, in parallel with the Coursera AML track and Burkov’s book that became my 2019 education blogs.

What I tried

LightGBM, MLP, vanilla 1D/2D CNNs, FilterNet-style multi-scale Conv1D plus a dense branch, Ladder networks (reproduced MNIST with only 100 labels at ~98.7% locally, but poor on market data), and LSTMs. Standard pooling on such short windows tended to wash out the exact endpoint geometry that defines whether a rebound or drop “just happened.”

I implemented a multi-class Matthews correlation loss from Gorodkin (2004), validated in NumPy, ported to TensorFlow, and added asymmetric penalties for false positives - because a trading bot that fires thousands of false alarms is unusable even at high recall.

The lesson that actually mattered: data, not model size

When I carved a mock test from the augmented training distribution (roughly 10,000 negatives and 30 positives), simple MLP and LightGBM hit 100% on both classes. On the real test set the same pipeline caught 1 out of 23 true patterns at first.

That contrast meant the failure was not “we need a bigger net.” It was train/test misalignment:

EDA that changed the spec

Plotting tens of thousands of windows showed the human labeler was effectively looking at the fifth moving average, while earlier datasets fed the model other SMA channels. I flagged ~18 labels where the pattern geometry contradicted the tag, and raised whether Weak/Average/Strong/Extreme tiers might use lookahead (knowledge of what happens after the window). A causal recognizer only seeing 18 ticks cannot cleanly separate those tiers if they were defined that way.

On multi-class Peak Drop, FilterNet plus MCC loss pushed HOLD specificity from the low 70s toward ~89-93% and MCC from a few percent toward ~7-8% on that extreme imbalance - real movement, not victory.

I later reused the FilterNet idea on HUPX price series from the SEEEA gig. Same mental model, different market.

Takeaway: Data and labels were the bottleneck, not model size. Accuracy and even ROC-AUC lie when positives are one in a thousand.


MOLEAC (summer-autumn 2019)

Data analysis consultant (Python, LC-MS)

MOLEAC is a Singapore biopharma team working on botanical post-stroke compounds. For regulatory advance they needed proof of systemic absorption: do parent compounds or metabolites show up in plasma after dosing?

They sent untargeted liquid chromatography - mass spectrometry runs from three animals at three timepoints. There was no true pre-dose baseline; the “day after first dose, 24h” scan acted as a proxy control, while later draws were shortly after administration when signal should rise.

Toolchain before statistics

I had never worked in analytical chemistry. The files were proprietary Thermo scientific .RAW archives - not camera RAW, which I embarrassingly tried first. MZmine plus vendor libraries converted runs to open mzML; then Python and Jupyter did the analysis. MS2 scans were dropped (irregular timing); MS1 positive and negative modes were kept separate.

Scan counts did not match 1-to-1 across runs, so direct subtraction was impossible. My workaround: per m/z channel, integrate signal over retention time with a cumulative sum, then compare endpoints as a ratio between timepoints. Divergence showed up mainly in a mid-run window (on the order of 1400-1800 seconds in the chromatogram).

Milestone and final report

Report 1 flagged candidate regions on the first animal. Cross-animal work moved to 2-sigma and 3-sigma cuts on those ratios so thresholds were not hand-tuned per animal.

Signed final report (October 2019):

I wrote plainly: absence of evidence is not evidence of non-absorption. The protocol needed true predose controls, higher resolution, and a targeted quant workflow - not more thresholds on the same files. Their later in-house targeted LC-MS/MS study did find quantifiable absorption markers, which is exactly what I had argued the data could not establish from this design.

Takeaway: Learn a new science fast, and deliver “no” with evidence instead of overfitting chromatographic noise to please a client.


eBlitz.gg (2020)

Machine Learning consultant, live CS:GO betting (Python, LightGBM, TrueSkill)

eBlitz wanted in-play odds for professional Counter-Strike: Global Offensive: before each round, how likely is each team to win the round and the map, and how many kills might each player get? The MVP we scoped was 2-3 markets, a focused player pool, and calibrated probabilities with volatility in mind - not raw accuracy alone.

This sits next to my longer WIN.gg esports work; here the product was the client’s own historic event API and betting use case.

Data engineering

I reverse-engineered an undocumented JSON event stream, scraped on the order of 6,000+ series, and parsed 9,815 maps and 256,772 rounds. Rosters had to be rebuilt from kills and bomb plants (no clean lineup object). 302 maps dropped for impossible per-round stats (too many kills/deaths per player in one round, bad round indexing).

I built map-level TrueSkill ratings again: pre-match map winner AUC around 0.66, conservative exposure ladder that surfaced sensible tier-one names. Round-level TrueSkill updates looked barely above random (~0.54) and were set aside for production.

Features used strict causality: shifted rolling windows (current map excluded), prior-only head-to-head, and a live pre-round state buffer. Train/validation/test splits held out whole matches, never random rounds.

Results (test set, honest)

Market What we measured
Map winner LightGBM test ROC-AUC ~0.71, accuracy ~0.64 (train AUC ~0.95 - tree capacity too high for ~9k maps)
Round winner ~0.70 ROC-AUC vs ~0.59 from “who is ahead on the scoreboard” alone; naively blending score and history models hurt (~0.64)
Player kills this round Regression RMSE ~0.87 kills; binary “any kill?” AUC ~0.54 even on a veteran-only subgroup

The product lead had said from meeting one that mid-round weapons, economy, and map positions were missing from the feed. The kill model failing for veterans was empirical confirmation - not a surprise in hindsight.

Literature on game telemetry (tree ensembles beating LSTM/CNN on structured game state) matched what we did: LightGBM on tabular lagged state, not a heavy net first.

Takeaway: Beat a dumb baseline every time, publish negative results (failed blends, weak kill AUC), and treat calibration and book risk as deliverables alongside AUC.


If something is off in any of these summaries, or you want another gig section added, please let me know.