1
+ import pandas as pd
2
+ import random
3
+ from datetime import date , timedelta
4
+ from mplfinance .plotting import plot
5
+ from mplfinance ._styles import make_marketcolors
6
+
7
+ dict_data = []
8
+ start_date = date (2019 , 1 , 1 )
9
+ end_date = date (2020 , 1 , 1 )
10
+ delta = timedelta (days = 1 )
11
+ start = 20
12
+ end = 30
13
+ while start_date <= end_date :
14
+ openval = random .randint (start , end )
15
+ closeval = random .randint (start , end )
16
+ high = random .randint (max (openval , closeval ), end )
17
+ low = random .randint (start , min (openval , closeval ))
18
+ change = random .randint (- 5 , 5 )
19
+ volume = random .randint (10000 , 20000 )
20
+ dict_data .append ({
21
+ "Open" : openval ,
22
+ "Close" : closeval ,
23
+ "High" : high ,
24
+ "Low" : low ,
25
+ "Date" : start_date ,
26
+ "Volume" : volume
27
+ })
28
+ start += change
29
+ end += change
30
+ start_date += delta
31
+
32
+ df = pd .DataFrame (dict_data )
33
+ df .index = pd .to_datetime (df ['Date' ])
34
+
35
+ # custom_colors = []
36
+ # for i in range(len(df)):
37
+ # if i % 3 == 0:
38
+ # custom_colors.append(make_marketcolors(up='#29c9ff', down='#f3b5ff', edge='#29c9ff', wick='#29c9ff', ohlc='#32a852', volume='#a89132'))
39
+ # elif i%5 == 0:
40
+ # custom_colors.append("#000000")
41
+ # else:
42
+ # custom_colors.append(None)
43
+
44
+ # plot(df, type='candle', style='yahoo', colors=custom_colors, volume=True)
45
+ plot (df , type = 'candle' , style = 'yahoo' , volume = True )
0 commit comments