def pdf_add(): global pdf_file, pdf_name_history, pdf_name if pdf_name_history == pdf_name.get(): pdf_file.add() pdf_file.save() else: pdf_name_history = pdf_name.get() pdf_file = pdf.PDF("pdf/" + pdf_name.get()) pdf_file.add() pdf_file.save()
import stocks from statsmodels.tsa.arima_model import ARIMA import matplotlib.pyplot as plt import pdf import pandas as pd pr = pdf.PDF("pdf/arima_input.pdf") def input_pdq(): x = tuple( input(stocks.get_only_name() + " : Enter, p d q : ").strip().split(" ")) if len(x) < 3: x = (1, 1, 1) y = [int(i) for i in x] return y def arima_man_forecast(ts, f, order=None): confirm = False if order is None: confirm = True train = ts[:int(len(ts) * f)] test = ts[int(len(ts) * f):] if order is None: order = input_pdq() model = ARIMA(train, order) model_fit = model.fit(disp=-1) plt.plot(test) plt.plot(train)
import stocks from pmdarima.arima import auto_arima import matplotlib.pyplot as plt import pdf import pandas as pd pr = pdf.PDF("pdf/auto_arima.pdf", True) def arima_auto_forecast(ts, f): train = ts[:int(len(ts) * f)] test = ts[int(len(ts) * f):] plt.plot(train) plt.plot(test) model = auto_arima(train) prd = model.predict(n_periods=len(test)) plt.plot(prd) print(prd) plt.show() while True: arima_auto_forecast(stocks.stock["Close Price"], 0.6) if not stocks.next_stock(): break pr.save()
import pandas as pd import matplotlib.pyplot as plt import cvr import stocks import pdf def frm(s): s = str(s) while len(s) < 8: s += " " return s pr = pdf.PDF("pdf/savex.pdf") coverWidth = 90 while True: c = cvr.Cover(stocks.stock["Close Price"], coverWidth) x = list() y = list() while c.move_forward(): # print(frm(c.min) + " " + frm(c.max) + " " + c.get_cover()) x.append((c.curr - c.min) / (c.max - c.min)) y.append(c.delta) plt.title(stocks.get_name().split(".")[0].split("/")[1]) plt.xlabel("(curr-min)/(max-min) | max,min in past " + str(coverWidth) + " days") plt.ylabel("curr-price_on_previous_day") plt.scatter(x, y, s=2) pr.add() plt.clf()
screen_width = win.winfo_screenwidth() win.minsize(int(screen_width / 5), int(screen_height / 3)) lb = tk.Listbox(win) files = os.listdir("stkdata/") lb.configure(justify=tk.CENTER) fill_list() lb.bind("<Double-1>", list_click) lb.pack() # -------------------------------- pdf_frame = tk.Frame(win) pdf_frame.pack() pdf_name_history = "temp.pdf" pdf_file = pdf.PDF("pdf/" + pdf_name_history) pdf_name = tk.Entry(pdf_frame) pdf_name.insert(0, pdf_name_history) pdf_name.pack(side=tk.LEFT) def pdf_add(): global pdf_file, pdf_name_history, pdf_name if pdf_name_history == pdf_name.get(): pdf_file.add() pdf_file.save() else: pdf_name_history = pdf_name.get() pdf_file = pdf.PDF("pdf/" + pdf_name.get()) pdf_file.add() pdf_file.save()
import stocks import math import numpy as np import stock_iterator import matplotlib from matplotlib import pyplot as plt from scipy.stats import norm import pdf import pandas as pd import math import mylib matplotlib.rcParams["lines.linewidth"] = 0.5 train_data_percent = 0.9 # Load the data, and make training and testing sets. pdf1 = pdf.PDF("pdf/MKV.pdf") data = pd.Series(stocks.get_by_name("TCS")) train_test_divider_index = int(train_data_percent * len(data)) train_data = data[:train_test_divider_index] test_data = data[train_test_divider_index:] train_length = len(train_data) test_length = len(test_data) plt.plot(train_data) plt.plot(test_data) # Show trend and scale on the graph trend_polyfit = np.poly1d(np.polyfit(train_data.index, train_data, 3)) trend_series = pd.Series(trend_polyfit(data.index), index=data.index) plt.plot(trend_series) plt.title("TCS")
#!/usr/bin/python import sys sys.path += ["../scripts/"] import pdf # a test for transparency groups: # form xobjects used for doing transparency groups can do savestate (q) # without ever needing to do a corresponding restorestate (Q) because # their content stream is self-contained. # # Test that this doesn't confuse the pdf reader. file = pdf.PDF() page = file.add_page(612, 100) group1 = file.create_object("/XObject", "/Form") group1.stream = """ 0.0 1.0 0.0 rg 0.0 0.0 0.0 RG 10 10 m 70 10 l 70 70 l 10 70 l 10 10 l f 10 10 m 70 10 l 70 70 l 10 70 l 10 10 l s 0.0 0.0 1.0 rg 0.0 0.0 0.0 RG 30 30 m 90 30 l 90 90 l 30 90 l 30 30 l f 30 30 m 90 30 l 90 90 l 30 90 l 30 30 l s 1.0 0 0 1.0 1000 1000 cm q 1.0 0 0 1.0 1000 1000 cm q 1.0 0 0 1.0 1000 1000 cm q 1.0 0 0 1.0 1000 1000 cm q """
def __init__(self, name): self.name = name self.btnct = 0 self.curr_slab = None self.pdf1 = pdf.PDF("pdf/transition_" + name + ".pdf")
import stocks from statsmodels.tsa.arima_model import ARIMA import matplotlib.pyplot as plt import pdf import pandas as pd pr = pdf.PDF("pdf/arima_insample.pdf") def input_pdq(): x = tuple( input(stocks.get_only_name() + " : Enter, p d q : ").strip().split(" ")) if len(x) < 3: x = (1, 1, 1) y = [int(i) for i in x] return y def arima_man_forecast(ts, f, order=None): confirm = False if order is None: confirm = True train = ts[:int(len(ts) * f)] test = ts[int(len(ts) * f):] if order is None: order = input_pdq() model = ARIMA(train, order) model_fit = model.fit(disp=-1) plt.plot(test) plt.plot(train)
str(sg)[:5]) plt.hist(dif, bins=np.arange(-70, 70, 1), density=True) plt.plot(np.arange(-70, 70, 1), norm.pdf(np.arange(-70, 70, 1), mu, sg)) pd.add() plt.clf() return mu, sg mu1, sg1 = ms(train[0:int(ntrain / 5)]) print(mu1, sg1) mu2, sg2 = ms(train[int(ntrain / 5):2 * int(ntrain / 5)]) print(mu2, sg2) mu3, sg3 = ms(train[2 * int(ntrain / 5):3 * int(ntrain / 5)]) print(mu3, sg3) mu4, sg4 = ms(train[3 * int(ntrain / 5):4 * int(ntrain / 5)]) print(mu4, sg4) mu5, sg5 = ms(train[4 * int(ntrain / 5):]) print(mu5, sg5) mu = (mu1 + mu2 + mu3 + mu4 + mu5) / 5 sg = (sg1 + sg2 + sg3 + sg4 + sg5) / 5 brt = (mu + sg * sg) / 2 drt = (sg * sg - mu) / 2 print(brt, drt) pd = pdf.PDF("pdf/ab.pdf") # f(stocks.get_by_name("TCS"), "TCS") stock_iterator.iterate(f) pd.save()