Hack Your Flow: Understanding Flow Cycles, with Steven Kotler

Before, we believed Flow was binary, like a light switch. You were either in the zone or you were out of the zone. As it turns out, based on research from Herb Benson, Flow is  actually a four part cycle.

  • Struggle
    • This is a loading phase. You are loading, then overloading the brain with information. For a baseball player this is learning to swing a bat at a ball. For a writer planning a new book. This is when you’re doing interviews. This is when you’re reading, it’s when you’re diagramming structure and things like that. It’s very unpleasant as a general rule. So even though flow may be the most desirable and pleasant state on earth, the actual flow cycle itself starts with a very unpleasant state known as struggle.
  • Release
    • This literally means you want to take your mind off the problem. So what happens in flow is we are trading conscious processing which is slow, has very limited RAM for subconscious processing which his extremely fast and is very energy efficient and has pretty much endless RAM. So to do that you have to stop thinking about what you were trying to think about. You take your mind off the problem, you go for long walks, gardening works very well, etc.
  • Flow
    • Heightened awareness. Full engagement in the present moment. Loss of sense of time, loss of sense of ego. Peak experience.
  • Recovery
    • This is really, really, really critical. So you go from this amazing high of flow to a very deep low that shows up in recovery. A lot of this is that all those feel good neurochemicals have drained out of your system.

So…

If you really want to hack flow you need to learn how to struggle better and you need to learn how to recover better. And one of the most important things in recovery is you have to – you need some emotional fortitude, some grit. You have to basically hold on to your emotions, not get stressed out at the fact that you know longer feel like Superman. And the main reason – well two reasons for this is one, if you get too stressed out and feeling low you’re going to start producing cortisol. A little bit is fine, too much of it blocks the accelerated learning that comes with flow. So you will actually get the short term benefit of the flow state itself but you won’t get the long term benefit, the accelerated learning that you get in flow. The other problem is if you have to move from recovery back into struggle and you’re bummed out at no longer being in flow during the recovery phase, it’s very hard to get up for the difficult fight of struggle that follows.

The Purpose of Purposelessness

 

The following excerpt is from Bernard De Koven’s The Well-Played Game.

The Purpose of Purposelessness

We are adults. We lead purposeful lives. We maintain our adulthood through our display of purposefulness. Not through playing with purpose but rather through displaying purpose.

We strive to become important–to do important things with other important adults. When our lives lack purpose there seems to be no reason for our continuing to live. When our purposes have been frustrated, when we are not able to accomplish what we have set forth as our goals, we scream in righteous indignation, in pain.

We seek purpose so strongly that when our purposes are finally, ultimately fufilled–when we even come close enough to see that satisfaction is inevitable–we create, as swiftly as we can, other purposes.

Thus we ask ourselves what is the purpose of this purposeless activity. To what other, nobler end is this well-played game? Do we grow as a result? Do we become better at something else than the game? Do we earn status? Money? Wisdom?

It seems, when we think about it, that for all our striving for purpose, we spend a great deal of time and energy doing and pursuing things without purpose.

There you are, caught in a moment of idleness, walking backward down the street. There you are, looking in store windows, not because you’re interested in buying anything but because you want to be looking in store windows. There you are, kicking stones off the sidewalk. There you are telling jokes. There you are, just playing.

Why? What purpose does it serve? Why is this purposelessness so valuable to you? Why does it feel so good?

You’re being playful. You like being playful. It feels good. As a matter of fact, you’re very playful.

You play whenever you get the chance. You doodle. You listen to music. You twiddle your thumbs. You do nothing. You dream. You play with ideas. You toy with things. You turn everything else off, even the sense of purpose, and you just merely play.

It’s as though you have a switch, somewhere, that lets you shut off the very force that gives you meaning, and you just play, without purpose, without meaning anything.

But why do you turn that switch?

If you could, you would play forever. Why do you turn the switch again? Why do you stop playing?

There are so many purposes, real purposes to attend to, survival, personal survival, survival of your family, of your home, of your country, your world; achieving excellence, achieving the ultimate victory, achieving wisdom, truth, enlightenment, a raise in pay.

In this book we’ve been creating yet other purposes. Our play community is purposeful, intentional. All that we do together is for the sake of something else. We want to play well together. We want to achieve excellence in something that ultimately doesn’t even matter. And yet, when we reach that high together, we discover that we can have no other purpose left to except to stay there forever.

Why? Why do we make it our purpose to be without purpose? Why do we create games that give us purpose only so we can, by playing them well together, be released from all purpose?

It is a balancing act. It is a dialog–a play between. On the one hand there is silliness, on the other seriousness. On this side confusion, on this clarity. Here delight. Here, despair. It is neither work nor play, purpose nor purposelessness that satisfies us. It is the dance between.

The game offers us a purpose. It says: Win. And we study the game, we learn the rules and regulations, the strategies that will help us win. Given the purpose, we seek the means.

Play offers us purposelessness. It says: Play! We can’t even play for the purpose of enjoyment. We can’t even play to have fun. We can have fun, we can enjoy ourselves while we are playing, but that is payoff, it isn’t purpose. Purpose interferes with play. When we play for any purpose, when we detect purpose in someone else’s play or in our own, we lose balance, we become distortions. When we play for praise, for grades, for trades, we find ourselves not really playing.

Odd, isn’t it? Paradoxical. Apparently without solution. Is play the completion of game, or is the game completion of play? Uncomfortable, this consideration. What else can one do at such a time, facing such a profound problem?

Bitcoin, Ethereum, and Litecoin

This year may be remembered as the year of Cryptocurrencies. While Cryptocurrencies have been around for some time, I would argue it was in 2017 when they reached a ‘tipping point’, becoming something more than a niche, alternative investment.

Where’s the proof? Year to date, Bitcoin has increased 370%, Ethereum has increased 2940%, and Litecoin increased 1650%. Comparatively, the S&P 500 has increased 10%. Produce returns +30X the benchmark and Investors take notice.

So how might you invest in Cryptocurrencies? I recommend using Coinbase and its sister exchange GDAX.

On both sites, you may purchase Bitcoin, Ethereum, and Litecoin. Coinbase charges a brokers fee, though locks in the price at the moment of transaction. Using limit orders on GDAX, you can avoid the brokers fee, though you will be subject to the changing market price as the order is filled throughout the day. For individual investors, both Coinbase and GDAX limit the amount you may purchase within a given a week, which could be seen as a drawback.

Curious to learn more, check the videos below.

Ideas are like Acorns

Excerpt from David J. Schwartz’s The Magic Power of Thinking Big.

‘Each year an oak tree produces enough acorns to populate a good-sized forest. Yet, from these bushels of seeds perhaps only one or two acorns will become a tree. The squirrels destroy most of them and the hard ground beneath the tree doesn’t give the few remaining seeds much chance for a start.

So it is with ideas. Very few bear fruit. Ideas are highly perishable. If we’re not on guard, the squirrels (negative-thinking-people) will destroy most of them. Ideas require special handling from the time they are born until they’re transformed into practical ways for doing things better. Use these three ways to harness and develop your ideas.

  1. Don’t let ideas escape. Write them down. Every day lots of good ideas are born only to die quickly because they are not nailed to paper. Memory is a weak slave when it comes to preserving and nurturing brand new ideas. Carry a notebook or some small cards with you. When you get an idea, write it down. A friend who travels a lot keeps a clipboard beside him so that he can write down an idea the instant it occurs to him. People with fertile, creative minds know a good idea may sprout any time, any place. Don’t let your ideas escape; else, you destroy the fruits of your thinking. Fence them in.
  2. Next, review your ideas. File these ideas in an active file. The file can be an elaborate cabinet, or it can be a desk drawer. A shoe box will do. Build a file and then examine your storehouse of ideas regularly. As you go over your ideas, some may, for very good reasons, have no value at all. Get rid of them. But so long as the idea has any promise, keep it.
  3. Cultivate and fertilize your idea. Now make your idea grow. Think about it. Tie the idea to related ideas. Read anything you can find which is in any way akin to your idea. Investigate all angles. Then, when the time is ripe, put it to work for yourself, your job, your future.

Finite vs. Infinite Games

In game theory, there are two types of games, finite and infinite.

Finite Games Infinite Games
Players Known Known and Unknown
Rules Fixed Changeable
Objective Agreed upon Perpetuate the Game
Example Baseball Cold War

When you pit a finite player vs. a finite player, the system is stable.

When you pit an infinite player vs. an infinite player, the system is stable.

In an infinite game, there are no winners and losers. Because there are no winners or losers, the only thing a player can do is drop out, when he or she no longer has resources or the will to play.

Problems arise when you pit a finite player vs. an infinite player. The finite player gets caught in quagmire.

This happens in business all the time.

The game of business is an infinite game. The concept of business has lasted longer than every single business that exists right now.

The funny thing about business is the number of companies that are playing finite games. They are playing to win, to be the best, to beat the quarter, or the year. And they are always frustrated by that company that has an amazing vision. Over the long term, the infinite player will always win…

This is what happened to the United States in Vietnam.

Learn more by listening to the Simon Sinek video below….

Python Tutorial – Getting Started

Contact: andrewshamlet@gmail.com // @andrewshamlet

Getting Started

Congratulations, and welcome to Stock Technical Analysis in Python!

You have taken your first step towards making smarter, more disciplined trading decisions.

Before diving in, let’s make sure you have everything you may need.

Anaconda 4.4.0

We recommend downloading Anaconda 4.4.0, with Python 2.7.

– http://www.continuum.io/downloads

Pandas, Numpy, and MatPlotLib

Anaconda comes pre-loaded with the three modules you will use throughout the course.

– http://www.pandas.pydata.org/

– http://www.numpy.org/

– http://www.matplotlib.org/

Quantopian

You will backtest your strategy using the Quantopian platform.-

– http://www.quantopian.com/

StockCharts, Investopedia, and Google Finance

StockCharts, Investopedia, and Google Finance are great resources for financial knowledge.

– http://www.stockcharts.com

– http://www.investopedia.com/

– http://www.google.com/finance

Stack Overflow

Stack Overflow is a great resource for coding questions.-

– http://www.stackoverflow.com/

You are now ready to dive in!

Python Tutorial – Future Returns

Download the accompanying IPython Notebook for this Tutorial from Github. 

Last Tutorial, we outlined steps for calculating the Stochastic Oscillator.

In this Tutorial, we walk through calculating 5-day, 10-day, and 20-day future returns, from historical data.

Caculating 5-day, 10-day, and 20-day future returns will allow us to identify relationships between current technical indicators and future returns.

Let’s use Python to compute the 5-day, 10-day, and 20-day future returns.

1.) Import modules.

import pandas as pd
import numpy as np
from pandas_datareader import data as web
import matplotlib.pyplot as plt
%matplotlib inline

2.) Define function for querying daily close.

def get_stock(stock,start,end):
 return web.DataReader(stock,'google',start,end)['Close']

3.) Define function for calculating the 5-day future return.

def fiveday(close): 
 fiveday = ((close.shift(-5) - close) / close) * 100
 return fiveday

4.) Define function for calculating 10-day future return.

def tenday(close): 
 tenday = ((close.shift(-10) - close) / close) * 100
 return tenday

5.) Define function for calculating 20-day future return.

def twentyday(close): 
 twentyday = ((close.shift(-20) - close) / close) * 100
 return twentyday

6.) Query daily close.

df = pd.DataFrame(get_stock('FB', '1/1/2016', '12/31/2016'))

7.) Run daily close through fiveday, tenday, and twentday functions. Save series to new columns in dataframe.

df['5 day'] = fiveday(df['Close'])
df['10 day'] = tenday(df['Close'])
df['20 day'] = twentyday(df['Close'])
df = df.dropna()
df.tail()

8.) Plot average 5-day, 10-day, and 20-day future returns.

df2 = df[['5 day', '10 day', '20 day']].mean()
df2.plot(kind='bar')

There you have it! We calculated 5-day, 10-day, and 20-day future returns. Here’s the full code:

import pandas as pd
import numpy as np
from pandas_datareader import data as web
import matplotlib.pyplot as plt
%matplotlib inline

def get_stock(stock,start,end):
 return web.DataReader(stock,'google',start,end)['Close']

def fiveday(close): 
 fiveday = ((close.shift(-5) - close) / close) * 100
 return fiveday

def tenday(close): 
 tenday = ((close.shift(-10) - close) / close) * 100
 return tenday

def twentyday(close): 
 twentyday = ((close.shift(-20) - close) / close) * 100
 return twentyday

df = pd.DataFrame(get_stock('FB', '1/1/2016', '12/31/2016'))
df['5 day'] = fiveday(df['Close'])
df['10 day'] = tenday(df['Close'])
df['20 day'] = twentyday(df['Close'])
df = df.dropna()
df.tail()

Recommended Reading: Everybody Lies

Everybody Lies: Big Data, New Data, and What the Internet Can Tell Us About Who We Really Are

 

In Everybody Lies, Seth Stephens-Davidowitz illustrates that people hide their embarrassing thoughts from other people but not from the internet, which provides anonymity. Websites like Google function as a digital truth serum. Data allow us to see what people really want and really do, not what they say they want and say they do.

In other words, people can claim they’re furious, they can decry something as distasteful and yet they will still click.

 

Python Tutorial: Stochastic Oscillator

Download the accompanying IPython Notebook for this Tutorial from Github. 

Last Tutorial, we outlined steps for calculating the Mass Index.

In this Tutorial, we introduce a new technical indicator, the Stochastic Oscillator.

Developed by George C. Lane in the late 1950s, the Stochastic Oscillator is a momentum indicator that shows the location of the close relative to the high-low range over a set number of periods.

The Stochastic Oscillator is calculated as follows:

%K = (Current Close - Lowest Low)/(Highest High - Lowest Low) * 100
%D = 3-day SMA of %K

Lowest Low = lowest low for the look-back period
Highest High = highest high for the look-back period

The default setting for the Stochastic Oscillator is 14 periods, which can be days, weeks, months or an intraday timeframe. A 14-period %K would use the most recent close, the highest high over the last 14 periods and the lowest low over the last 14 periods. %D is a 3-day simple moving average of %K.

As a bound oscillator, the Stochastic Oscillator makes it easy to identify overbought and oversold levels. The oscillator ranges from zero to one hundred. No matter how fast a security advances or declines, the Stochastic Oscillator will always fluctuate within this range. Traditional settings use 80 as the overbought threshold and 20 as the oversold threshold. These levels can be adjusted to suit analytical needs and security characteristics. Readings above 80 for the 20-day Stochastic Oscillator would indicate that the underlying security was trading near the top of its 20-day high-low range. Readings below 20 occur when a security is trading at the low end of its high-low range.

Before looking at some chart examples, it is important to note that overbought readings are not necessarily bearish. Securities can become overbought and remain overbought during a strong uptrend. Closing levels that are consistently near the top of the range indicate sustained buying pressure. In a similar vein, oversold readings are not necessarily bullish. Securities can also become oversold and remain oversold during a strong downtrend. Closing levels consistently near the bottom of the range indicate sustained selling pressure. It is, therefore, important to identify the bigger trend and trade in the direction of this trend. Look for occasional oversold readings in an uptrend and ignore frequent overbought readings. Similarly, look for occasional overbought readings in a strong downtrend and ignore frequent oversold readings.

Let’s use Python to compute the Stochastic Oscillator.

1.) Import modules.

import pandas as pd
import numpy as np
from pandas_datareader import data as web
import matplotlib.pyplot as plt
%matplotlib inline

2.a.) Define function for querying daily close.

def get_stock(stock,start,end):
 return web.DataReader(stock,'google',start,end)['Close']

2.b.) Define function for querying daily high.

def get_high(stock,start,end):
 return web.DataReader(stock,'google',start,end)['High']

2.c.) Define function for querying daily low.

def get_low(stock,start,end):
 return web.DataReader(stock,'google',start,end)['Low']

3.) Define function for the Stochastic Oscillator, both %K and %D.

def STOK(close, low, high, n): 
 STOK = ((close - pd.rolling_min(low, n)) / (pd.rolling_max(high, n) - pd.rolling_min(low, n))) * 100
 return STOK

def STOD(close, low, high, n):
 STOK = ((close - pd.rolling_min(low, n)) / (pd.rolling_max(high, n) - pd.rolling_min(low, n))) * 100
 STOD = pd.rolling_mean(STOK, 3)
 return STOD

How does the Stochastic Oscillator function work?

3.a.) To calculate %K, we find the difference between the current close and the lowest low for the look-back period, n. We then find the difference between the highest high for the look-back period, n, and the lowest low for the same look-back period. Dividing these two values and multiplying the result by 100, we arrive at %K, which we set to variable STOK.

#STOK = ((close - pd.rolling_min(low, n)) / (pd.rolling_max(high, n) - pd.rolling_min(low, n))) * 100

3.b.) Function returns STOK.

#return STOK

3.c.) To calculate %D, we first calculate %K.

#STOK = ((close - pd.rolling_min(low, n)) / (pd.rolling_max(high, n) - pd.rolling_min(low, n))) * 100

3.d.) Then we take the 3 day moving average of %K, and set the value to variable STOD.

#STOD = pd.rolling_mean(STOK, 3) 

3.e.) Function returns STOD.

#return STOD 

4.) Query daily close, high, and low for ‘FB’ during 2016.

df = pd.DataFrame(get_stock('FB', '1/1/2016', '12/31/2016'))
df['High'] = get_high('FB', '1/1/2016', '12/31/2016')
df['Low'] = get_low('FB', '1/1/2016', '12/31/2016')

5.) Run daily close, low, and high through %K and %D functions. Save series to new columns in dataframe.

df['%K'] = STOK(df['Close'], df['Low'], df['High'], 14)
df['%D'] = STOD(df['Close'], df['Low'], df['High'], 14)
df.tail()

6.) Plot daily close, %K, and %D.

df.plot(y=['Close'], figsize = (20, 5))
df.plot(y=['%K', '%D'], figsize = (20, 5))

There you have it! We created our Stochastic Oscillator indicator. Here’s the full code:

import pandas as pd
import numpy as np
from pandas_datareader import data as web
import matplotlib.pyplot as plt
%matplotlib inline

def get_stock(stock,start,end):
 return web.DataReader(stock,'google',start,end)['Close']

def get_high(stock,start,end):
 return web.DataReader(stock,'google',start,end)['High']

def get_low(stock,start,end):
 return web.DataReader(stock,'google',start,end)['Low']

def STOK(close, low, high, n): 
 STOK = ((close - pd.rolling_min(low, n)) / (pd.rolling_max(high, n) - pd.rolling_min(low, n))) * 100
 return STOK

def STOD(close, low, high, n):
 STOK = ((close - pd.rolling_min(low, n)) / (pd.rolling_max(high, n) - pd.rolling_min(low, n))) * 100
 STOD = pd.rolling_mean(STOK, 3)
 return STOD

df = pd.DataFrame(get_stock('FB', '1/1/2016', '12/31/2016'))
df['High'] = get_high('FB', '1/1/2016', '12/31/2016')
df['Low'] = get_low('FB', '1/1/2016', '12/31/2016')
df['%K'] = STOK(df['Close'], df['Low'], df['High'], 14)
df['%D'] = STOD(df['Close'], df['Low'], df['High'], 14)
df.tail()

Python Tutorial: Mass Index

Download the accompanying IPython Notebook for this Tutorial from Github. 

Python streamlines tasks requiring multiple steps in a single block of code. For this reason, it is a great tool for querying and performing analysis on data.

Last Tutorial, we outlined steps for calculating Commodity Channel Index (CCI).

In this Tutorial, we introduce a new technical indicator, the Mass Index.

Developed by Donald Dorsey, the Mass Index uses the high-low range to identify trend reversals based on range expansions. In this sense, the Mass Index is a volatility indicator that does not have a directional bias. Instead, the Mass Index identifies range bulges that can foreshadow a reversal of the current trend.

The Mass Index is calculated as follows:

Single EMA = 9-period exponential moving average (EMA) of the high-low differential 

Double EMA = 9-period EMA of the 9-period EMA of the high-low differential

EMA Ratio = Single EMA divided by Double EMA

Mass Index = 25-period sum of the EMA Ratio

First, the Single EMA provides the average for the high-low range.

Second, the Double EMA provides a second smoothing of this volatility measure.

Using a ratio of these two exponential moving averages normalizes the data series. This ratio shows when the Single EMA becomes large relative to the Double EMA.

The final step, a 25-period summation, acts like a moving average to further smooth the data series.

Overall, the Mass Index rises as the high-low range widens and falls as the high-low range narrows.

Donald Dorsey looked for “reversal bulges” to signal a trend reversal. According to Dorsey, a bulge occurs when the Mass Index moves above 27. This initial bulge does not complete the signal though. Dorsey waited for this bulge to reverse with a move back below 26.50. Once the reversal bulge is complete, traders should use other analysis techniques to determine the direction of the next move. Ideally, a downtrend followed by a reversal bulge would suggest a bullish trend reversal. Conversely, an uptrend followed by a reversal bulge would suggest a bearish trend reversal.

Let’s use Python to compute the Mass Index.

1.) Import modules.

import pandas as pd
import numpy as np
from pandas_datareader import data as web
import matplotlib.pyplot as plt
%matplotlib inline

2.a.) Define function for querying daily close.

def get_stock(stock,start,end):
 return web.DataReader(stock,'google',start,end)['Close']

2.b.) Define function for querying daily high.

def get_high(stock,start,end):
 return web.DataReader(stock,'google',start,end)['High']

2.c.) Define function for querying daily low.

def get_low(stock,start,end):
 return web.DataReader(stock,'google',start,end)['Low']

3.) Define function for Mass Index.

def MassIndex(high, low): 
 Range = high - low 
 EX1 = pd.ewma(Range, span = 9, min_periods = 8) 
 EX2 = pd.ewma(EX1, span = 9, min_periods = 8) 
 Mass = EX1 / EX2 
 MassIndex = pd.Series(pd.rolling_sum(Mass, 25), name = 'Mass Index') 
 return MassIndex

How does the Mass Index function work?

3.a.) Function calculates the difference between the high and the low, and sets this value to variable Range.

#Range = high - low  

3.b.) Function takes a 9 period Exponential Moving Average of the Range, and sets this value to variable EX1.

#EX1 = pd.ewma(Range, span = 9, min_periods = 8)  

3.c.) Function takes a 9 period Exponential Moving Average of the EX1, to smooth volatility, and sets this value to variable EX2.

#EX2 = pd.ewma(EX1, span = 9, min_periods = 8)  

3.d.) Function takes the ratio of EX1 to EX2, and sets this value to variable Mass.

#Mass = EX1 / EX2  

3.e.) Function calculates the 25 period rolling sum of Mass, and sets this value to variable MassIndex.

#MassIndex = pd.Series(pd.rolling_sum(Mass, 25), name = 'Mass Index')  

3.f.) Function returns MassIndex.

#return MassIndex

4.) Query daily close, high, and low for ‘FB’ during 2016.

df = pd.DataFrame(get_stock('FB', '1/1/2016', '12/31/2016'))
df['High'] = get_high('FB', '1/1/2016', '12/31/2016')
df['Low'] = get_low('FB', '1/1/2016', '12/31/2016')

5.) Run daily high and low through Mass Index function. Save series to new column in dataframe.

df['MassIndex'] = MassIndex(df['High'], df['Low'])
df.tail()

6.) Plot daily close and Mass Index.

df.plot(y=['Close'])
df.plot(y=['MassIndex'])

There you have it! We created our Mass Index indicator. Here’s the full code:

import pandas as pd
import numpy as np
from pandas_datareader import data as web
import matplotlib.pyplot as plt
%matplotlib inline

def get_stock(stock,start,end):
 return web.DataReader(stock,'google',start,end)['Close']
 
def get_high(stock,start,end):
 return web.DataReader(stock,'google',start,end)['High']
 
def get_low(stock,start,end):
 return web.DataReader(stock,'google',start,end)['Low']
 
def MassIndex(high, low): 
 Range = high - low 
 EX1 = pd.ewma(Range, span = 9, min_periods = 8) 
 EX2 = pd.ewma(EX1, span = 9, min_periods = 8) 
 Mass = EX1 / EX2 
 MassIndex = pd.Series(pd.rolling_sum(Mass, 25), name = 'Mass Index') 
 return MassIndex
 
df = pd.DataFrame(get_stock('FB', '1/1/2016', '12/31/2016'))
df['High'] = get_high('FB', '1/1/2016', '12/31/2016')
df['Low'] = get_low('FB', '1/1/2016', '12/31/2016')
df['MassIndex'] = MassIndex(df['High'], df['Low'])
df.tail()