In a previous project, we draw a trending stock price random walk chart. Candlestick chart is a more common way of representing stock price chart. Modify the code for the previous project to draw stock price random walk with Candlestick Chart.
Author Archives: J & J Coding Adventure
Stock Price Random Walk with Candlestick Chart
In a previous project, we draw a stock price random walk chart. Candlestick chart is a more common way of representing stock price chart. Modify the code for the previous to draw stock price random walk with Candlestick Chart.
Striped Square Spiral
In a previous project, you coded a square spiral inside squares. Make minor changes to make it a striped spiral as shown here.
Stock Price Random Walk with Positive Mean
In this project, you simulated stock price random walk with mean equal to 0%. What if we increase the mean of Gaussian distribution very slightly to 0.5% and also increase the standard deviation to 5%. You may see something similar to a trending stock prices of successful companies.
Stock Price Random Walk (Source Code)
In a previous project, we simulated a random walk on a 2-D plane. For this project, simulate stock price change with random walk. Start with an initial stock price. At next day, the price change by random percentage with Gaussian (Normal) distribution (random.gauss() function) with mean 0% and standard deviation of 2%. Try to simulate multiple times and see if they look similar to some of stock price charts you have seen before.
Source Code:
import turtle
import random
screen = turtle.Screen()
screen.title('Stock Price Random Walk - PythonTurtle.Academy')
screen.setup(1000,1000)
screen.setworldcoordinates(0,0,1000,1000)
turtle.speed(0)
turtle.hideturtle()
price=500
turtle.up()
turtle.goto(0,price)
turtle.down()
for i in range(1,1000):
price *= (1+random.gauss(0,0.02))
turtle.goto(i,price)
Striped Pentagon Spirals
In a previous project, we draw a pentagon spiral inside pentagons. Based on the solution, draw a striped pentagon spirals as shown with Python and Turtle. The modification to the code should be very small.
Hindu Temple (All-Sided) Fractal with Python Turtle
Draw all-sided hindu temple fractal. Refer to this Hindu Temple project.
Hex Star Fractal using Python and Turtle
Hex Star with Python and Turtle
Draw a hex star as shown with Python and Turtle. Practice using loop to draw this shape.
Dodecagon Spiral (Source Code)
In other related projects, we draw a pentagon spiral and a square spiral. Now draw a dodecagon spiral with 12 sides. Also make the grayscale of dodecagons gradually grow lighter as it gets smaller.
Source Code:
import turtle
import math
screen = turtle.Screen()
screen.title('Dodecagon Spiral - PythonTurtle.Academy')
screen.setup(1000,1000)
screen.setworldcoordinates(-1000,-1000,1000,1000)
turtle.speed(0)
turtle.hideturtle()
def draw_spiral(x,y,r,direction):
if r < 10: return
d = direction
r2 = r*math.cos(math.radians(360/24))/math.cos(math.radians(360/24-alpha))
dist = r*math.sin(math.radians(360/24))-r2*math.sin(math.radians(360/24-alpha))
turtle.up()
px = x + r*math.cos(math.radians(d))
py = y + r*math.sin(math.radians(d))
turtle.goto(px,py)
turtle.color((1-r/900,1-r/900,1-r/900))
turtle.down()
d += 360/12
for _ in range(12):
px = x + r*math.cos(math.radians(d))
py = y + r*math.sin(math.radians(d))
turtle.goto(px,py)
d += 360/12
draw_spiral(x,y,r2,direction+alpha)
alpha = 3
draw_spiral(0,0,900,90)