def generate_periodic_assets(N):
    rp_dir = 'jupyter/data/'
    graph_dir = 'jupyter/data/_graphs/'
    freq = 2
    amp = 2
    time_start = 0
    time_stop = 1
    duty1 = 0.3
    duty2 = 0.5

    for i in range(N):
        # RP Variables
        D = random.randint(2, 5)
        d = random.randint(2, 4)

        size = 720 + (D-1)*d

        t_freq = freq + round(random.uniform(0, 1.5),4)
        t_amp = amp + round(random.uniform(0, 1.5), 4)
        t_time_start = time_start
        t_time_stop = time_stop + round(random.uniform(0, 7), 2)
        t_duty1 = duty1 + round(random.uniform(-0.15, 0.55), 3)
        t_duty2 = duty2 + round(random.uniform(-0.35, 0.35), 3)

        time = np.linspace(t_time_start, t_time_stop, size)

        signal1 = t_amp*np.sin(2*np.pi*t_freq*time)
        signal2 = t_amp*sg.square(2*np.pi*t_freq*time, duty=t_duty1)
        signal3 = t_amp*sg.sawtooth(2*np.pi*t_freq*time, width=t_duty2)

        signal1_fileName = 'periodic_graph_' + str(i*3) + '.png'
        signal2_fileName = 'periodic_graph_' + str(i*3+1) + '.png'
        signal3_fileName = 'periodic_graph_' + str(i*3+2) + '.png'

        generate_and_save_graph(range(0, size), signal1,
                                signal1_fileName, rp_dir, "periodic")
        generate_and_save_graph(range(0, size), signal2,
                                signal2_fileName, rp_dir, "periodic")
        generate_and_save_graph(range(0, size), signal3,
                                signal3_fileName, rp_dir, "periodic")

        ### Generating RP 

        dow1 = rp(D, d, signal1, 1, 17.5, 2.5)
        dow1.draw_diagram()
        create_new_file('plotpic.png', 'rp_graph_' +
                        str(i*3) + '.png', graph_dir)

        dow2 = rp(D, d, signal2, 1, 17.5, 2.5)
        dow2.draw_diagram()
        create_new_file('plotpic.png', 'rp_graph_' +
                        str(i*3+1) + '.png', graph_dir)
        dow3 = rp(D, d, signal3, 1, 17.5, 2.5)
        dow3.draw_diagram()
        create_new_file('plotpic.png', 'rp_graph_' +
                        str(i*3+2) + '.png', graph_dir)
def generate_trend_assets(N):
    rp_dir = 'jupyter/data/'
    graph_dir = 'jupyter/data/_graphs/'
    lower_bound = 0
    upper_bound = 60
    batch_number = 33
    batch_size = 22
    rate_up = 5
    exponent = 1.02
    exponent_increment = round((exponent - 1)/N*2, 10)
    print(exponent_increment)

    for i in range(N):
        t_rate_up = round(rate_up + random.uniform(-2,2), 2)
        data = generate_data_with_trend(lower_bound, upper_bound, \
                                        batch_number, batch_size, \
                                        t_rate_up, exponent)

        graph_fileName = 'trend_graph_' + str(i) + '.png'
        generate_and_save_graph(
            data[0], data[1], graph_fileName, graph_dir, "trend")

        dow=rp(4,2,data[1] , 1 , 17.5 ,3)
        dow.draw_diagram()
        create_new_file('plotpic.png', 'rp_graph_' +
                        str(i) + '.png', rp_dir)

        exponent -= exponent_increment
def generate_chaotic_assets(N):
    rp_dir = 'jupyter/data/'
    graph_dir = 'jupyter/data/_graphs/'

    for i in range(N):
        data = []
        # RP Variables
        D = random.randint(2, 5)
        d = random.randint(2, 4)

        size = 720 + (D-1)*d

        for _ in range(size):
            data.append(random.randint(0,random.randint(50,1500)))
        
        graph_fileName = 'chaos_graph_' + str(i) + '.png'

        generate_and_save_graph(range(0, size), data,
                                graph_fileName, graph_dir, "chaotic")

        dow1 = rp(D, d, data, 1, 17.5, 2.5)
        dow1.draw_diagram()
        create_new_file('plotpic.png', 'rp_graph_' +
                        str(i) + '.png', rp_dir)
        dowData.append(float(row[5]))
        dowLabels.append(pd.to_datetime(row[0]))
        if (len(dowData) >= 1100):
            break

# afont = {'family':'monospace'}

fig, ax = plt.subplots()  # Create a figure containing a single axes.
ax.xaxis.set_major_formatter(
    mdates.DateFormatter('%Y'))  # Use "2020-01-01" instead of "2020"
ax.plot(dowLabels, dowData)  # Plot data on the axes.
fig.autofmt_xdate()
ax.set_title(
    "Dow Jones Induastrial Average adjusted for infaltion\n in USD (2015-07-01 to 2020-01-01)"
)
ax.set_xlabel("Date")
ax.grid()

dow = rp(
    4,
    2,
    dowData,
    0,
    17.5,
    3,
)
dow.draw_diagram()
print(dow.r)

plt.show()
예제 #5
0
csvData=[]

plt.rcParams.update({'font.size': 16})

time = np.arange(0, 20, 0.05)
amplitude = np.round(np.sin(time), 10)
path = os.path.dirname(os.path.realpath(__file__))

with open(path + "/assets/DJI.csv") as csvfile:
    csvfile.readline()   # skip the first line of headers
    reader = csv.reader(csvfile)
    for row in reader:
        csvData.append(float(row[4]))
        if (len(csvData)>=720): break

dow = rp(1, 1, amplitude, 1, 17.5, 0)

dow.draw_diagram()
print(dow.r)

title = "Generated sine signal"
fig, ax = plt.subplots()  # Create a figure containing a single axes.

ax.plot(list(range(len(csvData))), csvData)  # Plot data on the axes.
ax.set_title(title)
ax.grid()

plt.savefig('plotgraph.png')
# round_to_tenths = [round(num, 6) for num in amplitude]
# print(round_to_tenths)