[PYTHON] Investment quest: Make a system trade with pyhton (2)

System trading in python: Draw Bollinger Bands

What is Bollinger Bands?

Bollinger Bands are often described in the graph below. From monex Securities HP. https://info.monex.co.jp/technical-analysis/indicators/003.html

003_p_01.jpg

I often see pictures on the website of a securities company, but I have a question here. why? 25 moving averages (25SMA), why ± 1, 2σ? There may be an optimum value for odd values ​​such as 5SMA, 7SMA, 0.9σ, 1.4σ, and so on. Since this is the world of DX, it is easy to calculate with the power of your home computer. I came up with the idea last night to try to find the optimum values ​​for this σ and SMA. I don't know if it will work just by thinking about it ... To do that, you first need to draw a Bollinger band.

Draw Bollinger Bands

To draw the Bollinger Bands, use rolling to find the standard deviation, just as you would draw a moving average. df["5day_std"]=df["end_price"].rolling(5).std().round(1) Simply add or subtract this standard deviation from the mean. If + 1σ, df["5day_bol_+1"]=df["5day_ave"]+df["5day_std"] is.

#Find the standard deviation
df["5day_std"]=df["end_price"].rolling(5).std().round(1)
#Find the Bollinger Bands (± 1σ)
df["5day_bol_+1"]=df["5day_ave"]+df["5day_std"]
df["5day_bol_-1"]=df["5day_ave"]-df["5day_std"]

Now, let's draw a graph for the second half of FY2008. image.png

I will take a closer look. This is the situation in December 2008. There are places where it is rising and places where it is reversing following the trend.

image.png

This graph is ± 1σ, but since it is a computer, you can calculate as much as you like. For example, ± 0.8σ or ± 1.1σ. image.png

I would like to find the optimum value by the number of days and bandwidth of this moving average (SMA).

The first simple strategy is

Make a short-term game. The number of days on the moving average is several days. Search for the optimal solution for bandwidth and number of days to invert or trend in Bollinger Bands.

Let's think about this.

Next, I will create features and objective variables for that purpose.

That is the next "Investment quest: Make a system trade with pyhton (3)" (let's think about the script from now on).

Recommended Posts

Investment quest: Make a system trade with pyhton (2)
Investment quest: Make a system trade with pyhton (1)
Make a recommender system with python
Is this a system trade?
Make a fortune with Python
Make a fire with kdeplot
Acoustic signal processing starting with Python-Let's make a stereophonic system
Let's make a GUI with python.
Make a sound with Jupyter notebook
Let's make a breakout with wxPython
Make a filter with a django template
Let's make a graph with python! !!
Let's make a supercomputer with xCAT
Make a model iterator with PySide
Make a nice graph with plotly
System trading starting with Python3: long-term investment
Let's make a shiritori game with Python
"System trade starting with Python3" reading memo
Make a rare gacha simulator with Flask
Make a Notebook Pipeline with Kedro + Papermill
Make a partially zoomed figure with matplotlib
Make a drawing quiz with kivy + PyTorch
Let's make a voice slowly with Python
Create a star system with Blender 2.80 script
Make a cascade classifier with google colaboratory
Let's make a simple language with PLY 1
Make a logic circuit with a perceptron (multilayer perceptron)
Make a Yes No Popup with Kivy
Make a wash-drying timer with a Raspberry Pi
Make a GIF animation with folder monitoring
Let's make a web framework with Python! (1)
Let's make a tic-tac-toe AI with Pylearn 2
Make a desktop app with Python with Electron
Let's make a Twitter Bot with Python!
Let's make a web framework with Python! (2)
How to make a dialogue system dedicated to beginners
A memorandum to make WebDAV only with nginx
Make a Twitter trend bot with heroku + Python
[Python] Make a game with Pyxel-Use an editor-
Make a monitoring device with an infrared sensor
Make a simple pixel art generator with Flask
How to make a dictionary with a hierarchical structure.
I want to make a game with Python
Build a cheap summarization system with AWS components
Try to make a "cryptanalysis" cipher with Python
[Python] Make a simple maze game with Pyxel
Let's replace UWSC with Python (5) Let's make a Robot
Try to make a dihedral group with Python
[Chat De Tornado] Make a chat using WebSocket with Tornado
Make holiday data into a data frame with pandas
Make a LINE WORKS bot with Amazon Lex
(Memorandum) Make a 3D scatter plot with matplodlib
System trading starting with Python 3: Investment and risk
Make a morphological analysis bot loosely with LINE + Flask
Try to make a command standby tool with python
[Practice] Make a Watson app with Python! # 2 [Translation function]
[Practice] Make a Watson app with Python! # 1 [Language discrimination]
Make a simple Slackbot with interactive button in python
[Let's play with Python] Make a household account book
How to make a shooting game with toio (Part 1)
Let's make a simple game with Python 3 and iPhone