Get the "Applied Data Science Edge"!

The ViralML School

Fundamental Market Analysis with Python - Find Your Own Answers On What Is Going on in the Financial Markets

Web Work

Python Web Work - Prototyping Guide for Maker

Use HTML5 Templates, Serve Dynamic Content, Build Machine Learning Web Apps, Grow Audiences & Conquer the World!

Hot off the Press!

The Little Book of Fundamental Market Indicators

My New Book: "The Little Book of Fundamental Analysis: Hands-On Market Analysis with Python" is Out!

Do You Know How Often The Markets Go Up? Hands-On Market Analysis with Python

Introduction

Lets get back to the basics of market analysis and quantify how many times the markets go up, down and for how much. Its not always intuitive, and whether you are a trader or not, you need to know this. Casino math: https://gaming.unlv.edu/casinomath.html MORE: Blog or code: http://www.viralml.com/video-content.html?fm=yt&v=4kigop8_XXE Signup for my newsletter and more: http://www.viralml.com Connect on Twitter: https://twitter.com/amunategui My books on Amazon: The Little Book of Fundamental Indicators: Hands-On Market Analysis with Python: Find Your Market Bearings with Python, Jupyter Notebooks, and Freely Available Data: https://amzn.to/2DERG3d Monetizing Machine Learning: Quickly Turn Python ML Ideas into Web Applications on the Serverless Cloud: https://amzn.to/2PV3GCV Grow Your Web Brand, Visibility & Traffic Organically: 5 Years of amunategui.github.Io and the Lessons I Learned from Growing My Online Community from the Ground Up: Fringe Tactics - Finding Motivation in Unusual Places: Alternative Ways of Coaxing Motivation Using Raw Inspiration, Fear, and In-Your-Face Logic https://amzn.to/2DYWQas Create Income Streams with Online Classes: Design Classes That Generate Long-Term Revenue: https://amzn.to/2VToEHK Defense Against The Dark Digital Attacks: How to Protect Your Identity and Workflow in 2019: https://amzn.to/2Jw1AYS Transcript Hello Youtube friends, If you had to trade blindfolded? Would you know what to do? Well, if you look at any chart of a big market index, what do you see? Lets get back to the basics, quantify how many time the markets go up, down and for how much. Its not always intuitive, and whether you are a trader or not, you need to know this. Welcome to the ViralML show and another hands-on, market analysis with Python. My name is Manuel Amunategui and this talk will be filed under finance. please subscribe to the channel and to the newsletter. Pause Imagine that Invited you on a journey through time and I asked you to place a trade, long or short on this chart, the caveat being you will be blindfolded, so what would you do? if you had no clue about anything, going long would be the safe strategy. But what about this harder question, what is the percentage or ratio that the markets go up? Yes, not so easy. By simply looking at this S&P500 chart, Id say 2/3s of the time. I can practically hear the statisticians and seasoned traders calling me an idiot and dead wrong. 2/3s would be like 66% percent of the time - boy am I off!!! Lets quantify how many times the S&P 500 had up-days versus down-days and for how much. This is a critical market foundation we all need to have. Its basic probabilities, it the basis of our financial markets, the financial system, the edge market----makers and casion have over regular traders and why thinking in the long term is a safer bet. As always, I like to plug my book at the end of the show - if you like this raw, no-nonsense look at the markets through fundamental indicators, this book is for you. I published it recently on Amazon. put my first and last name in the Amazon search bar you will find it there. In it, I cover my favorite market indicators, like the S&P500, the CPI, the Case-Shiller index, the VIX, unemployment and a whole lot more. dont forget to give this video some thumbs up! CATEGORY:Finance HASCODE:ViralML-How-Often-Do-Markets-Go-Up.html



If you liked it, please share it:

Code

ViralML-How-Often-Do-Markets-Go-Up
In [218]:
from IPython.display import Image
Image(filename='viralml-book.png')
Out[218]:

Fundamental and Technical Indicators - Hands-On Market Analysis

Get the book "The Little Book of Fundamental Market Indicators":

https://amzn.to/2DERG3d

More at:

https://www.viralml.com/

So, How Often Does the Market Go Up?

Download the S&P500 index (^GSPC):

https://finance.yahoo.com/quote/%5EGSPC/

Download the Russell 2000 (^RUT) - The Russell 2000 index is an index measuring the performance of approximately 2,000 smallest-cap American companies in the Russell 3000:

https://finance.yahoo.com/quote/%5ERUT/history?p=^RUT

In [180]:
%matplotlib inline
import matplotlib
import matplotlib.pyplot as plt
import io, base64, os, json, re 
import pandas as pd
import numpy as np
import datetime
import warnings
warnings.filterwarnings('ignore')

Load Historical Data

In [182]:
sp500_df = pd.read_csv('^GSPC.csv')
sp500_df['Date'] = pd.to_datetime(sp500_df['Date'])
sp500_df = sp500_df[['Date', 'Adj Close']]
sp500_df.columns = ['Date', 'SP500_close']
sp500_df.tail()
Out[182]:
Date SP500_close
17463 2019-05-30 2788.860107
17464 2019-05-31 2752.060059
17465 2019-06-03 2744.449951
17466 2019-06-04 2803.270020
17467 2019-06-05 2826.149902
In [183]:
sp500_df.head()
Out[183]:
Date SP500_close
0 1950-01-03 16.66
1 1950-01-04 16.85
2 1950-01-05 16.93
3 1950-01-06 16.98
4 1950-01-09 17.08
In [184]:
rus2000_df = pd.read_csv('^RUT.csv')
rus2000_df['Date'] = pd.to_datetime(rus2000_df['Date'])
rus2000_df = rus2000_df[['Date', 'Adj Close']]
rus2000_df.columns = ['Date', 'RUS2000_close']
rus2000_df.tail()
Out[184]:
Date RUS2000_close
7993 2019-05-30 1485.530029
7994 2019-05-31 1465.489990
7995 2019-06-03 1469.979980
7996 2019-06-04 1508.560059
7997 2019-06-05 1506.790039
In [185]:
rus2000_df.head()
Out[185]:
Date RUS2000_close
0 1987-09-10 168.970001
1 1987-09-11 170.539993
2 1987-09-14 170.429993
3 1987-09-15 169.199997
4 1987-09-16 168.919998

Simple Visualization using the Adjusted Close

In [186]:
fig, ax = plt.subplots(figsize=(16, 8))
plt.plot(sp500_df['Date'], sp500_df['SP500_close'], color='blue')
plt.title('S&P 500')
plt.grid()
plt.show()
In [187]:
fig, ax = plt.subplots(figsize=(16, 8))
plt.plot(rus2000_df['Date'], rus2000_df['RUS2000_close'], color='blue')
plt.title('Russell 2000')
plt.grid()

Let's count up days

In [189]:
 
sp500_df['Previous_Close'] = sp500_df['SP500_close'].shift(1) 
sp500_df.head()
Out[189]:
Date SP500_close Previous_Close
0 1950-01-03 16.66 NaN
1 1950-01-04 16.85 16.66
2 1950-01-05 16.93 16.85
3 1950-01-06 16.98 16.93
4 1950-01-09 17.08 16.98
In [190]:
# drop NAs
sp500_df = sp500_df.dropna(axis=0)
sp500_df.head()
Out[190]:
Date SP500_close Previous_Close
1 1950-01-04 16.850000 16.66
2 1950-01-05 16.930000 16.85
3 1950-01-06 16.980000 16.93
4 1950-01-09 17.080000 16.98
5 1950-01-10 17.030001 17.08
In [191]:
sp500_df['Price_Diff'] = sp500_df['SP500_close'] - sp500_df['Previous_Close']
sp500_df['Is_Up_Day'] = np.where(sp500_df['SP500_close'] > sp500_df['Previous_Close'], 1, 0)
sp500_df.head()
Out[191]:
Date SP500_close Previous_Close Price_Diff Is_Up_Day
1 1950-01-04 16.850000 16.66 0.190000 1
2 1950-01-05 16.930000 16.85 0.080000 1
3 1950-01-06 16.980000 16.93 0.050000 1
4 1950-01-09 17.080000 16.98 0.100000 1
5 1950-01-10 17.030001 17.08 -0.049999 0
In [192]:
print('Up days:', np.sum(sp500_df['Is_Up_Day']), 'out of:', len(sp500_df))
Up days: 9253 out of: 17467
In [64]:
print(np.sum(sp500_df['Is_Up_Day']==1) / len(sp500_df))
0.5297417988206332
In [65]:
print(np.sum(sp500_df['Is_Up_Day']==0) / len(sp500_df))
0.4702582011793668

Track up versus down dollar moves

In [193]:
np.sum(sp500_df[sp500_df['Is_Up_Day']== 1]['Price_Diff'])
Out[193]:
37646.364575
In [70]:
np.sum(sp500_df[sp500_df['Is_Up_Day']== 0]['Price_Diff'])
Out[70]:
-34836.874673
In [102]:
# let's check our math
37646.364575 -  34836.874673
Out[102]:
2809.489902000001

Let's create our own simulation

Casino Mathematics

University of Nevada, Las Vegas

https://gaming.unlv.edu/casinomath.html

In [214]:
from random import randint

up_down_days = []
for x in range(0,1000000):
    up_down_days.append(1 if randint(1, 100) <= 52 else -1)
    
up_down_days[0:10]
Out[214]:
[-1, 1, 1, -1, -1, 1, -1, -1, 1, -1]
In [215]:
np.sum(up_down_days)
Out[215]:
39840
In [216]:
np.array(up_down_days).cumsum() 
Out[216]:
array([   -1,     0,     1, ..., 39838, 39839, 39840])
In [217]:
plt.plot(np.array(up_down_days).cumsum() )
Out[217]:
[<matplotlib.lines.Line2D at 0x13b47c710>]

Show Notes

(pardon typos and formatting -
these are the notes I use to make the videos)

Lets get back to the basics of market analysis and quantify how many times the markets go up, down and for how much. Its not always intuitive, and whether you are a trader or not, you need to know this. Casino math: https://gaming.unlv.edu/casinomath.html MORE: Blog or code: http://www.viralml.com/video-content.html?fm=yt&v=4kigop8_XXE Signup for my newsletter and more: http://www.viralml.com Connect on Twitter: https://twitter.com/amunategui My books on Amazon: The Little Book of Fundamental Indicators: Hands-On Market Analysis with Python: Find Your Market Bearings with Python, Jupyter Notebooks, and Freely Available Data: https://amzn.to/2DERG3d Monetizing Machine Learning: Quickly Turn Python ML Ideas into Web Applications on the Serverless Cloud: https://amzn.to/2PV3GCV Grow Your Web Brand, Visibility & Traffic Organically: 5 Years of amunategui.github.Io and the Lessons I Learned from Growing My Online Community from the Ground Up: Fringe Tactics - Finding Motivation in Unusual Places: Alternative Ways of Coaxing Motivation Using Raw Inspiration, Fear, and In-Your-Face Logic https://amzn.to/2DYWQas Create Income Streams with Online Classes: Design Classes That Generate Long-Term Revenue: https://amzn.to/2VToEHK Defense Against The Dark Digital Attacks: How to Protect Your Identity and Workflow in 2019: https://amzn.to/2Jw1AYS Transcript Hello Youtube friends, If you had to trade blindfolded? Would you know what to do? Well, if you look at any chart of a big market index, what do you see? Lets get back to the basics, quantify how many time the markets go up, down and for how much. Its not always intuitive, and whether you are a trader or not, you need to know this. Welcome to the ViralML show and another hands-on, market analysis with Python. My name is Manuel Amunategui and this talk will be filed under finance. please subscribe to the channel and to the newsletter. Pause Imagine that Invited you on a journey through time and I asked you to place a trade, long or short on this chart, the caveat being you will be blindfolded, so what would you do? if you had no clue about anything, going long would be the safe strategy. But what about this harder question, what is the percentage or ratio that the markets go up? Yes, not so easy. By simply looking at this S&P500 chart, Id say 2/3s of the time. I can practically hear the statisticians and seasoned traders calling me an idiot and dead wrong. 2/3s would be like 66% percent of the time - boy am I off!!! Lets quantify how many times the S&P 500 had up-days versus down-days and for how much. This is a critical market foundation we all need to have. Its basic probabilities, it the basis of our financial markets, the financial system, the edge market----makers and casion have over regular traders and why thinking in the long term is a safer bet. As always, I like to plug my book at the end of the show - if you like this raw, no-nonsense look at the markets through fundamental indicators, this book is for you. I published it recently on Amazon. put my first and last name in the Amazon search bar you will find it there. In it, I cover my favorite market indicators, like the S&P500, the CPI, the Case-Shiller index, the VIX, unemployment and a whole lot more. dont forget to give this video some thumbs up! CATEGORY:Finance HASCODE:ViralML-How-Often-Do-Markets-Go-Up.html