All posts by oskin

Mind the gap

Many technical traders put a lot of stock into gaps on the chart. Gaps are formed when the market is closed and the bid/ask changes by the time it re-opens. These types of gaps occur on all manner of charts: equities, indexes, index futures, commodity futures, forex, you name it. Traders fall into three basic categories in regards to these types of gaps:

  1. They believe they matter and hold fast to them as if they are some deeply held religious belief. “The gap will always be filled” they contend.
  2. They believe they are irrelevant but acknowledge that enough other traders hold onto (1) and hence play along here and there.
  3. They believe they are stupid.

I am mostly in camp (3) but will go along for (2) now and then if the gap is large enough, or if it has just occurred, and a retrace seems likely.

Where I am in camp (1) is with commodity futures and for a very specific kind of gap, called the rollover gap. A rollover gap occurs when one futures contract ends and the price of the next futures contract is different. For example, natural gas’s June 2020 contract ended on May 27th at 1.721. The July contract was trading at 1.876 at the time. Why does this gap matter, and how is it “filled”?

Why commodity rollover gaps matter

The gap in contracts matters because it represent an arbitrage opportunity in the real world. You can buy the contract which obligates you to take physical delivery of the commodity and then you can store it for a month. You can then sell the next month’s futures contract (assuming it is higher), and if the cost of storage is below the size of the gap then you can be guaranteed a profit.

Lets return to our natural gas example. The June contract closed at 1.721 and the July contract was was trading at 1.876 at the time. You could buy the June contract, and take physical delivery of the gas. The storage fee for natural gas varies but let’s say it is 0.05 cents, which is about 2X the re-injection cost when there is ample storage. Simultaneously sell the July contract. You’ve now paid $1.721 for gas and be assured that you will be able to sell it in a month for $1.876. It will cost you $0.05 to store it for that amount of time, but is a guaranteed $0.105 profit. Who doesn’t like free money?

So what happens in the financial world because of this? The person who takes delivery of the gas and shorts the next month’s contract creates downward pricing pressure on the active contract. This downward pricing pressure is noticed in the market and FOMO kicks in. Traders pile in and the price goes down and the gap is closed, and can often times sink below the prior month’s closing price.

What happens if the front month is less expensive than the back month? First of all there is very little incentive for this to happen. The back month price generally collapses because the simple arbitrage trade described above doesn’t work. Who would take delivery of something they can’t be assured to sell at a profit? Commodity futures are monthly so it’ is also possible to do the same trade but shorting a different month further out. Storage costs rise, but it may still be profitable. There are traders that just play the spread between months so this downward pressure on future months is noticed and effectively shortens the financial gap between as yet unsettled futures contracts.

What about spot price?

Futures contracts are just that, a contract to buy or sell something at a specified time in the future. There is a price for that something right now. That price is called the spot price. On contract closing the spot price should converge to the futures price, but it doesn’t have to if some extreme situation is occurring. The reason they should converge is again arbitrage. Traders can buy or sell the futures contract if there’s a difference between spot and contract price. This financial movement pushes the contract price towards the actual spot price at the time of contract termination. But in extreme situations, lack of liquidity, market shock, extreme storage or transportation fees, this financial movement may not occur. Witness the implosion of oil prices in 2020 when storage space essentially filled up.

Can the gap be closed by the spot price movement? The short answer is yes and even if it does, it doesn’t always matter. Let’s return to our natural gas example. On May 27th the spot price was $1.78. Here’s an example where spot and futures contract price did not converge. Let’s recap, contract closed at $1.721, spot price $1.78 and front month price $1.876. In this case you don’t even have to pay a storage fee, just take delivery and immediately sell it for the spot price — quick profit, and the gap partly closed. The person who takes delivery of the gas still shorts the front month contract. But then if the spot price moves up to meet the front month price, you just sell the gas on the spot market and close out the front month contract. When this happens we say the gap was “closed from below”.

Does closing from below matter, however? Here we return to gaps on equity / index charts. Some traders think those gaps matter and because the gap will still exist on the futures chart they will think it still matters. Just the fact that enough traders think it matters can make it matter (see 2 above).

When does the gap occur? This is an interesting question. In the real world the gap occurs at the time of contract closing. But in the financial world different trading platforms “roll” their continuous chart over at a different times. Some even do crazy averaging between contract prices. This means different traders will see slightly different gaps. The gaps may not matter in the real world, but again, because of item 2 above, if enough people believe they matter, then it can matter.


Gaps on financial instruments have no real meaning beyond the fact that if enough traders think they matter, then they start to matter; gaps fill because price moves not because they have to. The rollover gap in commodity futures does matter because there is a real physical arbitrage trade that can be made that guarantees profit.

UGAZ is trash

I find myself repeating this often enough to (usually new) traders that I thought it helpful to just write a blog post on the topic.  Never buy UGAZ.  “But I want to go long on natural gas”, you say.  There’s plenty of smarter ways to do that, I reply.  This post explains why you should never buy UGAZ.  I will explain how I trade natural gas in a separate post.

What is UGAZ?

You might want to skip this section as it isn’t necessarily important what UGAZ is.  Scroll down to the Rollover section if you are in a hurry.

Let us begin with an explanation of what UGAZ actually is.  The easiest way to understand it is it’s an exchange traded note designed to provide 3X leveraged daily positive returns against the S&P GSCI Natural Gas index.  You can obtain the prospectus and other facts from Velocity Shares here.  Observe it is a note not a fund.  In other words, it is a bond and the bond is supposed to move in price 3X the movement of the GSCI gas index within the day.  It doesn’t have to, although this minor difference is not why UGAZ is trash.  It only matters if you are worried that UGAZ might up and totally implode one day.  The answer is yes, it can and yes you will lose everything and no there is no one to sue, no assets to sell to get pennies back — it’s a bond, not a fund.

What is important is that bond which backs UGAZ returns is maintained by holding onto two types of assets: treasury notes and natural gas futures.  The value of UGAZ can drift fairly far from 3X during times when the treasury market is broken (illiquid).  But this is not the reason why UGAZ is trash, because it doesn’t happen all that often.


Futures are highly leveraged contracts that expire on a preset schedule.  The issuers of the bond that UGAZ is a share in will hold a number of futures contracts so that the 3X returns (or losses) are achievable at no risk to them.  But what futures and how to deal with the fact that a futures contract has an end date?  The answer is UGAZ issuers hold the current month contract for the first week of a month, then “rolls” (sells the current month and buys the next month) into the next month’s contracts during the second week.  It then holds the next month contract for the remainder of current month.

The timing of this is important.  UGAZ rolls during the second week.  UNG rolls during the third week.  Futures traders stop trading the current month and more actively trade the next month during the last week.  The exact date for the roll of UGAZ is not specified because the bond issuer doesn’t have to.  But you can, from the velocity shares website see what is being held, and if you check it each day you will know when it begins and ends rolling.  The dates for UNG are generally more prescriptive and you can see those in advance here.

Stupid Trader Mistake #1: Using the wrong month.  Trading platforms tend to switch over from the current to the next month 3-4 days before contract expiration.   So when you look at /NG on Thinkorswim for example, how that price moves is not necessarily how UGAZ will move the majority of the time.  The current and next month price movements are usually, but not always correlated.

Average True Range

The real reason UGAZ is trash is because it is a 3X leveraged ETN tied to a commodity that has a wickedly high daily average true range.  Natural Gas is just a volatile commodity and the more volatility in the price the more a leverage investment product will decay.

UGAZ will decay in price on average ~0.7% per day.

Let that sink in for a moment.  The price of UGAZ decays on average 0.7% per day.  Just look:

The 5 year and 1 year charts make it clear that UGAZ suffers from significant decay.  To see why, lets work though an example.  Suppose the price of UGAZ was $100 and the price of natural gas goes up by 3% on one day.  Great, now UGAZ is worth $100 X (1 + 0.03 * 3) = $109.  But then suppose the next day it goes down by 3%, now UGAZ is worth 109 X (1 – 0.3 * 3) = $99.19.  Note that the price of natural gas is now the same as it was two days ago, but UGAZ has suddenly lost 0.81%!  That’s leveraged decay for you.  To understand how bad this is, consider the 5 year returns for UGAZ.  Go ahead and pull it up in your charting program of choice.  It dropped from $28,000 or so to $15.  Or go back just another year and it drops from $227,000 to $15 in 6 years.  That’s leveraged decay.

The volatility of the underlying asset a leveraged product tracks leads to the magnitude of this decay.  A simple experiment can be used to estimate the impact of price for holding a leveraged product for one year:


This experiment just takes a mythical asset and moves the price randomly for a given ATR for a whole year.  The experiment is repeated millions of times and the expected value is then estimated.  The expected value of the underlying asset will remain unchanged over this time.  But as you can see above, the expected value of a 3X leveraged investment product tied to that asset will decay to zero.  The real ATR you can get from your charting software.  You’ll see that it varies over time as natural gas goes through periods of being more or less volatile.  But the fact that ATR is generally high for natural gas means holding onto a leveraged investment product tied to it for any length of time is risky business.

Stupid Trader Mistake #2: Holding onto a losing UGAZ position hoping it will ever return to your entry price.  You might get lucky and it will quickly return to your entry price, but the longer you are “holding the bag” the less likely it becomes.  I did this analysis over the life time of UGAZ.  If you are holding a bag for one month your chance of recovering your entry price is 75%.  This last year has been more volatile and more downward in trend for Natural Gas.  For this past year, holding onto a UGAZ bag one week leads to a 77% chance of recovery; for one month drops those odds to 50%; two months it drops to 29%!  Summary lesson: quit dreaming you’ll get your money back — you won’t.

Stupid Trader Mistake #3: “But I want to ride the trend and compound my gains”, you say.  Suppose you get lucky and do pick the right time to go long on natural gas and don’t become a mulit-day bag holder.  Yes, you will see some compound gains, but if you are that good at picking the right time to go long on gas you can choose other leveraged approaches that will magnify your gains even more and not expose you to leverage decay.

A smarter way to trade Natural Gas is to use futures.  A full size contract (/NG) moves $100 per cent per contract.  A mini contract (/QG) moves $25 per cent per contract.  Margin requirements for the full size contract is $2,000 per contract ($500 for a mini).  So let’s put that in the perspective of UGAZ.  Currently UGAZ is $16.24 (Friday May 22nd 2020 close).  One /NG contract will require you to hold $2,000 in margin or roughly the moral equivalent of 123 shares of UGAZ at current prices.  /NG (July) is priced at 1.881.  If price rises to 1.891, longing a contract would net you $100.  Ignoring decay or other errors in UGAZ’s price, we would expect UGAZ to go up by 1 + 3 X (1.891 – 1.881) / 1.881 or 1.59% for a price of 16.50.  Those 123 shares would net a gain of $31.  You can see that the leverage on futures is over three times that of UGAZ — similar to 10X instead of 3X.  Thus a simple way to switch over from UGAZ/DGAZ to futures is to take the amount of money you would use to purchase these trash ETNs and use only 1/3 of it to buy and sell the underlying futures contracts.  Put the other 2/3’s to better use.

In conclusion, UGAZ/DGAZ are trash.  Traders should steer clear.  If you want to buy UGAZ (or DGAZ) the futures are the way to go.  They require less capital.  They don’t decay.  They are what you indirectly are trading with UGAZ/DGAZ.  As for me personally, I prefer a simpler approach to trading gas (option selling) which I’ll describe in a later post.


Function pointers from lambdas

Recently I updated my compiler toolset from gcc to a clang based frontend.  In this switch, the -Wno-pmf-conversion option disappeared.   Searching the net for easy ways to recreate the functionality proved to be in vane.  So after a bit (well a lot) of hacking, I developed the following code that does the trick.  Since obtaining a C style pointer to a function and passing it arguments are useful things to have, I thought this approach would be useful for others as well.  Note that I have no idea how portable this is.  It could very well only work for my particular version of clang/LLVM.  If any C++ gurus out there can tell me that, I’d like to know.

What’s the problem?

The following bit of code used to work with gcc and the Wno-pmf-conversions flag, but is not actually standard C++ and does not compile with clang:

// does not work :(
template<typename Func> void *obtain_ptr(Func f) {
  return (void*) &Func::operator();

An error like the following occurrs:

error: cannot cast from type 'auto ((lambda at ...)() const -> void' to pointer type 'void *'

Looking around there are some tantalizing hints about how to achieve the same functionality.  Namely, this from the C++ standard:

This user-defined conversion function is only defined if the capture list of the lambda-expression is empty. It is a public, constexpr (since C++17) non-virtual, non-explicit, const noexcept (since C++14) member function of the closure object.

Unfortunately, for my requirements I needed to support lamdas that have a capture list.

Enter the hack

The following template function will splice apart a lamda into a function pointer and an argument pointer:

template<typename Func> size_t function_from_lambda(
    void (**func_ptr)(void *),
    void *arg_ptr,
    size_t max_args,
    Func f) {
    class _dummy {
       static void function_pointer(Func *local_f) { (*local_f)(); }
    } dummy;

    *func_ptr = (void (*)(void *)) &dummy.function_pointer;
    assert(max_args >= sizeof(f));
    memcpy(arg_ptr, &f, sizeof(f));
    return sizeof(f);

Here are some examples that use it:

int main() {
    void (*f)(void *);
    void *args = malloc(16);
    size_t arg_size;
    unsigned long long var = 1;
    printf("main %llx %llx\n", var, &var);

    arg_size = function_from_lambda(&f, args, 16, [=] {
        printf("Hello! %llx %llx\n", var, &var);

    printf("We're actually going to invoke it here!\n");


    auto foo = [=] {
        printf("It even works with stored lamdas! %llx %llx\n",
            var, &var);
    arg_size = function_from_lambda(&f, args, 16, foo);

    return 0;

Now your milage may vary, but so far, it’s a useful hack for me.  Note that with this trick you can also play some nasty games:

// deep dark voodoo... don't try this at home!
 unsigned long long *iptr = (unsigned long long *) args;
 iptr[0] = 2;


Namely, you can alter the arguments after the fact if you know where they are in the class struct created for the lambda.

Understanding the West: A primer for my eastern friends


I have lived my entire life in the West.  By that I mean, the western half of the United States. After marrying (twice) into eastern familes and spending a good deal of time traveling along the eastern half of the country, I’ve concluded many people just don’t get the west. I also find many people outside of the United States are genuinely confounded by Americans, and especially westerners.  Here’s my attempt at explaining the west and its people.  Before I do I feel the need to put some caveats on it.

The west is not homogenious.  If you live in Seattle or San Francisco there are aspects of being “a westerner” that are quite different from Yakima or the planes of Wyoming.  My thesis, however, is there are core threads of an ethos and outlook that is common to people of both regions.

My view is limited.  Geographically I grew up in a track home in Orange County (south of Los Angeles).  I spent nine years in the north central valley of California (“norcal”) in a college town (Davis).  Then thirteen years in the city of Seattle.  Finally for the last couple of years I live in rural Washington (Whidbey Island) but still commute to work in Seattle.  Time wise, I’m 41.  I feel like the world has changed a lot in my “concious time”, but surely someone who is 61 or 81 will have experienced a greater breadth of change.

My view is not that limited.  I’m equally at home in the grit of the city, farm country, the desert and along the ocean.  I’ve traveled all over the west and a good part of the world as well.  I feel like I have something to say on what the west is all about.

The Romantic West

With the caveats out of the way, let me address what I feel are some guiding ethos of the west.

Bear Tooth Highway, Montana

The West is vast.

The western half of the united states really is big, and compared to the east, mostly sparsely populated.  You can leave Seattle and within an hour start walking into the wilderness and see no one and experiene no man made structure or presence of any kind, for days on end.  The same is true if you head east from Reno, Pheonix or Albuquerque; west from Denver, Cody or Missoula.  This still untamed land is the heart of the west.  Few now will set off into these wilds for longer than a weekend.  Fewer still leave their cell phone behind.  But the wild land is there, ready to receive us when we are in need of some place to study our own soul.  In the east and throughout much of Europe and Asia I’ve never felt the same ability to escape; maybe I just havent been to the right places, but more often than not a cafe is at the end of the trail.  A friendly voice switches from German or Dutch to English to greet me along the way.

Puget Sound, Washington

Rugged Individualism.

This is perhaps the least well understood characheristic of the westerner and of Americans generally.  In the 1800’s, moving West was not a decision people took casually.  Moreover, it wasn’t as if you went west because things were working out for you.  While some wealthy and successful individauls went west hoping to become more wealthy and more successful, most everyone else did so precisely because their life in the east wasn’t going so well.  One can only imagine the conversation between husband and wife went something like this:

“Hey babe, we just aren’t making it here.  It’s been three years now and we are still living with your parents.  I’ve heard about this place, they call it South Dakota.  Land is free!  They say all you have to do is spread seed on the ground and it will grow strong from the sweet smelling rain and shinning sun.  The Smith’s are headed there next month and we could join them.  We have just enough saved up that we could make the journey.  I know a guy with a wagon he wants to sell.  We could take your daddy’s horse.  We’d pack everything we need to make a fresh start, a new life there.  I really think we can be successful there.”

“I hear there are indians out there?  And will I ever see my family again?”

“Sure babe, of course we’ll be back to visit.  And don’t worry about the indians.  Trust me.”

And so they went.  That’s a whole lot of gumption.  To put that in perspective, imagine if you were having trouble finding a job out of college and you decide your best choice is to sell everything you own, buy a tent, a rifle and a few hundred pounds of canned food and head to the far north of Alaska.  The federal homestead act expired in the 80’s but the state will sell you a chunk of land for less than the price of a used car.  There’s no fear that fellow humanoids will come marauding through your camp, becuase hey, you really did steal their land, but there’s some hefty size bears that will be non too plussed to see you.

Actually, that doesn’t sound half bad to me.  And there in lies my point: that spirit of being able to gather together everything you need for the rest of your life, pack it all up and head into the great unknown lives on in the west.  It is passed down from generation to generation, and while it is surely diluted over the past couple hundred years, there’s enough of it left that it still profoundly shapes the culture and politics of the west.  Most of us will never up root our physical lives in the way our ancestors did, but many of us will use that inner spirit to perform similarly challenging pursuits.  I believe there’s a reason Silicon Valley is in the west.  It takes people with gumption to quit their jobs and bet everything they have on some new online venture.  And to do it over and over again until they finally succeed.

South Dakota

Come as you are

The west is full of people not like you.  The west will make you question your prejudicious.  That girl with the full body tattoo and blue hair?  She works for Amazon running operational security.  At home with her friends she likes to bake huckleberry pies and run tough mudders.  That dude in the business suit isn’t a wall street type, he sells used cars and goes to a new-age baptist church on the weekends.  That person who you can’t quite pin what gender they are, despite the foot high rainbow mohawk, skull rings and knee high boots, ordering a triple espresso and a brownie at the coffee shop?  Amazon again. Has two pugs at home, a boyfriend of five years and a girlfriend of ten.  Don’t worry if your mind is blown, keep reading.  If you want to survive out here and be happy you have to be comfortable breaking bread with all these folks.  And you know what?  They are all pretty cool, just ask them a question.


A friend of mine once described the east coast to me thusly: “Suppose your kid sucks at baseball, so the little league coach benches him all season.  You know your kid isn’t any good, but hey, he’s your kid and you’d like to give him that experience of actually being in the game.  On the west coast you can go talk to the coach and they’d say, sure, we’ll put him/her in right field for an inning, no sweat.  On the east coast the coach would tell you to ‘Go form your own league!'”  To me that story has summed up a lot about the west.  After all it’s just a little league game.  Why not let the kid play, is it really that important?


And there in lies the west.  It is a place where you can still disappear into nowhere to find yourself, a place colonized by riffraff that has left behind a sense of adventure among us, and a place accepting of you in all of your strangeness.  Sounds awesome right?