Python math and stocks: How to program the Chande Momentum Oscillator

2.0K views
December 1, 2013
by
sentdex
YouTube video player
Python math and stocks: How to program the Chande Momentum Oscillator

TL;DR

To program the Chande Momentum Oscillator in Python, load comma-separated price data with NumPy, examine each rolling time frame, total upward and downward price changes, and calculate (up sum minus down sum) divided by (up sum plus down sum), multiplied by 100. The function appends each result to a CMO array while advancing through the prices. Read on for the data-loading, loop, and calculation details.

Transcript

hello everybody welcome to the second part of our shawnee momentum oscillator tutorial video last video i was just telling you guys about the shawnee momentum oscillator showing you an example and in this video let's actually get to programming it within python this video is going to assume you have the sample data for this entire series if you don... Read More

Key Insights

  • ⌛ The Shawnee Momentum Oscillator can be implemented in Python using libraries such as numpy and time.
  • 🪡 The sample data for the Shawnee Momentum Oscillator calculation needs to be loaded and split using the newline character.
  • ⌛ The calculation of the Shawnee Momentum Oscillator involves considering up and down moves within a specified time frame.
  • 🧡 The Shawnee Momentum Oscillator values need to be verified to ensure they fall within the acceptable range of -100 to +100.
  • 👨‍💻 The Shawnee Momentum Oscillator code can be customized to calculate and analyze different aspects of price movement.
  • ❓ The tutorial suggests using matplotlib to visualize the Shawnee Momentum Oscillator results.
  • 📔 The next part of the tutorial will cover how to plot the Shawnee Momentum Oscillator using matplotlib.

Explore YouTube Video Summarizer or Get YouTube Transcript Extractor

Questions & Answers

Q: How do you program the Chande Momentum Oscillator in Python?

Import NumPy, load the price data, and define a CMO function that accepts prices and a time frame. For each time-frame window, total the upward and downward price changes, apply the CMO formula, append the result to an array, and advance to the next price.

Q: What data is needed to calculate the Chande Momentum Oscillator?

The tutorial uses sample data saved as sampledata.txt in the same directory as the script. The comma-separated data is unpacked into date, close price, high price, low price, open price, and volume variables.

Q: How is the sample price data loaded in Python?

Open sampledata.txt for reading, read it into memory, and split it by newline. Then use np.loadtxt with a comma delimiter and unpack set to true to place the columns into separate variables.

Q: What parameters does the CMO function accept?

The CMO function accepts the prices to analyze and the desired time frame. The time frame determines the rolling group of prices considered during each calculation.

Q: How are upward price movements calculated?

Begin at element one of the current price window so it can be compared with the preceding element. When the current price is greater than or equal to the previous price, add the difference between them to the up sum.

Q: How are downward price movements calculated?

When the current price is less than the previous price, subtract the current price from the previous price. Add that positive difference to the down sum, then continue through the prices in the selected window.

Q: What formula is used for the Chande Momentum Oscillator?

Subtract the down sum from the up sum, then divide by the up sum plus the down sum. Multiply the entire fraction by 100 to obtain the current CMO value.

Q: How does the code build the CMO result array?

After calculating the current CMO value for a price window, append it to the CMO array. Increment the outer-loop index by one and repeat while that index remains below the length of the prices.

Summary & Key Takeaways

  • The video guides viewers on how to import necessary libraries and load sample data for the Shawnee Momentum Oscillator calculation in Python.

  • It outlines the steps to define the time frame and compute the up and down sums based on price movements within the specified timeframe.

  • The video provides code implementation tips and demonstrates how to calculate the Shawnee Momentum Oscillator and verify its correctness.


Read in Other Languages (beta)

Share This Summary 📚

Explore More Summaries from sentdex 📚