コード例 #1
0
        def proceed_with_method():

            price_dict_raw = Chateau_data(self.address).get_price_data()

            #unpack the dictionaries so the dates have the correct format
            def dict_unpacker(sample_dict):
                dict_unpacked = {}
                for p_date, price in sample_dict.items():
                    formattedas_date = datetime.strptime(p_date, "%Y-%m-%d")
                    dict_unpacked[formattedas_date] = float(price)
                return dict_unpacked

            price_dict = dict_unpacker(price_dict_raw)

            x_values, y_values = [], []

            for p_date in price_dict.keys():
                if p_date > datetime(1980, 12, 31):
                    print(p_date.year)
                    y_values.append(price_dict[p_date])
                    d = Chateau_comb(self.address).vintage_distance(
                        p_date.year, '2', '8')
                    x_values.append(d)

            print(x_values)
            print(y_values)
            #Size the output
            fig = plt.figure(dpi=128, figsize=(10, 6))

            #Chart gridlines
            plt.grid(None, 'major', 'both')

            #Axis tick formats
            for tick in plt.gca().get_xticklabels():
                tick.set_fontname("Calibri")
                tick.set_fontsize(12)
                tick.set_rotation('vertical')
            for tick in plt.gca().get_yticklabels():
                tick.set_fontname("Calibri")
                tick.set_fontsize(12)

            #Axis labels and formats

            # axis 1
            color = 'tab:blue'
            plt.xlabel("Distance from average seasonality", fontsize=12)
            #plt.xticks(np.arange(x_values[11], x_values[0], 2))
            plt.ylabel("Price", color='black', fontsize=12)
            plt.scatter(x_values, y_values, color=color)
            plt.tick_params(axis='y', labelcolor=color)

            #remove borders
            plt.gca().spines['top'].set_visible(False)

            #Chart title
            plt.title("Price forecaster", fontsize=14)

            #Show chart
            plt.show()
コード例 #2
0
ファイル: weather_charts.py プロジェクト: alphadome/python
        def proceed_with_method():

            weather_dict_raw = Chateau(self.address).weather_dict(category)
            price_dict_raw = Chateau_data(self.address).get_price_data()

            weather_dict = dict_unpacker(weather_dict_raw)
            price_dict = dict_unpacker(price_dict_raw)

            correl_dict = {}

            def correl_calculator(chosen_month):
                monthly_weather_dict = all_monthly_weather_dict(
                    weather_dict, chosen_month)

                #find the average price
                px_list = []
                for px_date, price in price_dict.items():
                    if px_date > datetime(1970, 12, 31):
                        px_list.append(price)

                av = statistics.mean(px_list)
                sd = statistics.stdev(px_list)

                #add prices above average to the selected list
                selected_price_dict = {}
                y_values = []
                for px_date, price in price_dict.items():
                    if price > av + 0.5 * sd and px_date > datetime(
                            1970, 12, 31):
                        selected_price_dict[px_date] = price
                        y_values.append(price)

                #find weather data for price year
                x_values = []
                for px_date, price in selected_price_dict.items():
                    y = px_date.year
                    m = chosen_month
                    relevant_date = eomonth(y, m)
                    addition = monthly_weather_dict[relevant_date]
                    x_values.append(addition)

                #calculate best fit line
                x = x_values
                y = y_values
                z = np.polyfit(x, y, 2)
                p = np.poly1d(z)
                xp = np.linspace(min(x_values), max(x_values), 100)

                #calculate correlation coefficient
                correl_y = p(x)
                R = np.corrcoef(y, correl_y)
                cor = R.item(1)  #R is a 2x2 matrix so take the correct entry
                #print(str(chosen_month) + ": " + str(cor))
                return [cor, z.item(0), z.item(1), z.item(2)]

            for i in range(1, 13):
                correl_dict[i] = correl_calculator(i)

            return correl_dict
コード例 #3
0
        def proceed_with_method():

            price_dict = Chateau_data(self.address).get_price_data()
            weather_dict = Chateau(self.address).weather_dict(category)

            #turn weather_dict into annual rainfall
            monthly_weather_dict = {}

            def eomonth(y, m):
                year = y
                if m == 12:
                    month = 1
                else:
                    month = int(m) + 1
                given_day = datetime(year, month, 1)
                required_day = given_day - timedelta(days=1)
                return required_day

            for p_date, precip in weather_dict.items():
                formattedas_date = datetime.strptime(p_date, "%Y-%m-%d")
                y = formattedas_date.year
                m = formattedas_date.month
                needed_day = eomonth(y, m)
                if needed_day in monthly_weather_dict.keys():
                    monthly_weather_dict[needed_day] = monthly_weather_dict[
                        needed_day] + float(precip)
                else:
                    monthly_weather_dict[needed_day] = float(precip)

            monthly_weather_dict_final = {}
            for p_date, precip in monthly_weather_dict.items():
                da = p_date
                if da.month == given_month:
                    monthly_weather_dict_final[da] = precip

            # start chart
            x_values, y_values, z_values = [], [], []

            for key in price_dict.keys():
                x_date = datetime.strptime(key, '%Y-%m-%d')
                if x_date > datetime(1980, 12, 31):
                    x_values.append(key)
                    y_values.append(float(str(price_dict[key])))
                    z_date = eomonth(x_date.year, given_month)
                    z_values.append(annual_weather_dict_final[z_date])

            #Size the output
            fig = plt.figure(dpi=128, figsize=(10, 6))

            #Chart gridlines
            plt.grid(None, 'major', 'both')

            #Axis tick formats
            for tick in plt.gca().get_xticklabels():
                tick.set_fontname("Calibri")
                tick.set_fontsize(12)
                tick.set_rotation('vertical')
            for tick in plt.gca().get_yticklabels():
                tick.set_fontname("Calibri")
                tick.set_fontsize(12)

            #Axis labels and formats

            # axis 1
            color = 'tab:red'
            plt.xlabel("Date", fontsize=12)
            plt.ylabel("Price", color='black', fontsize=12)
            plt.bar(x_values, y_values, color=color)
            plt.tick_params(axis='y', labelcolor=color)

            ax2 = plt.twinx(
            )  # instantiate a second axes that shares the same x-axis

            #axis 2
            color = 'tab:blue'
            ax2.set_ylabel(
                "Precip", color='black',
                fontsize=12)  # we already handled the x-label with ax1
            ax2.plot(x_values, z_values, color=color)
            ax2.tick_params(axis='y', labelcolor=color)

            #remove borders
            plt.gca().spines['top'].set_visible(False)

            #Chart title
            plt.title("Weather/Price correlation " + str(given_month),
                      fontsize=14)

            #Show chart
            plt.show()
コード例 #4
0
        def proceed_with_method():

            weather_dict_raw = Chateau(self.address).weather_dict(category)
            price_dict_raw = Chateau_data(self.address).get_price_data()

            #unpack the dictionaries so the dates have the correct format
            def dict_unpacker(sample_dict):
                dict_unpacked = {}
                for p_date, price in sample_dict.items():
                    formattedas_date = datetime.strptime(p_date, "%Y-%m-%d")
                    dict_unpacked[formattedas_date] = float(price)
                return dict_unpacked

            weather_dict = dict_unpacker(weather_dict_raw)
            price_dict = dict_unpacker(price_dict_raw)

            def eomonth(y, m):
                """returns eomonth for a year and month"""
                year = y
                if m == 12:
                    month = 1
                else:
                    month = int(m) + 1
                given_day = datetime(year, month, 1)
                required_day = given_day - timedelta(days=1)
                return required_day

            def seasonal_weather_dict(dict_sample):
                """returns dict of average daily weather data aggregated by month"""
                monthly_weather_dict = {}
                for p_date, precip in dict_sample.items():
                    formattedas_date = p_date
                    y = formattedas_date.year
                    m = formattedas_date.month
                    needed_day = eomonth(y, m)
                    if needed_day in monthly_weather_dict.keys():
                        x = monthly_weather_dict[needed_day][0] + float(precip)
                        y = monthly_weather_dict[needed_day][1] + 1
                        monthly_weather_dict[needed_day] = [x, y]
                    else:
                        monthly_weather_dict[needed_day] = [float(precip), 1]

                monthly_weather_dict_av = {}
                for needed_day in monthly_weather_dict.keys():
                    d = monthly_weather_dict[needed_day][
                        0] / monthly_weather_dict[needed_day][1]
                    monthly_weather_dict_av[needed_day] = d
                return monthly_weather_dict_av

            def all_monthly_weather_dict(dict_sample):
                """returns dict of mean, stdev for every month"""
                monthly_weather_dict = seasonal_weather_dict(dict_sample)
                all_monthly_weather_dict = {}
                for chosen_month in range(1, 13):
                    new_list = []
                    for p_date, precip in monthly_weather_dict.items():
                        if p_date.month == int(
                                chosen_month) and p_date > datetime(
                                    1970, 12, 31):
                            new_list.append(precip)
                    av = statistics.mean(new_list)
                    sd = statistics.stdev(new_list)
                    all_monthly_weather_dict[chosen_month] = [av, sd]
                return all_monthly_weather_dict

        # monthly_weather_dict = all_monthly_weather_dict(weather_dict, chosen_month)

        #find the list of top prices
            prices, prices_dates, top_prices, lower_prices, top_prices_dates, lower_prices_dates = [], [], [], [], [], []
            for px_date, price in price_dict.items():
                if px_date > datetime(1980, 12, 31):
                    prices.append(price)
                    prices_dates.append(px_date)

            av = statistics.mean(prices)
            sd = statistics.stdev(prices)

            print("\nAverage/Stdev price is: " + str(av) + "/ " + str(sd) +
                  "\n")

            for i in range(0, len(prices) - 1):
                if prices[i] > av + 0.5 * sd:
                    top_prices.append(prices[i])
                    top_prices_dates.append(prices_dates[i])
                elif prices[i] < av - 0.5 * sd:
                    lower_prices.append(prices[i])
                    lower_prices_dates.append(prices_dates[i])

            poor_criteria_dict = {}

            for i in range(1, 13):
                poor_criteria_dict[i] = []

            weather_stats = all_monthly_weather_dict(weather_dict)
            print(weather_stats)
            specific_weather_dict = seasonal_weather_dict(weather_dict)
            #find poor price criteria
            for lower_price_date in lower_prices_dates:
                y = lower_price_date.year
                for i in range(1, 13):
                    m = i
                    weather_date = eomonth(y, m)
                    weather_stat = specific_weather_dict[weather_date]
                    av = weather_stats[i][0]
                    sd = weather_stats[i][1]

                    if weather_stat > av + 1 * sd:
                        title = "sig over av"
                        if title not in poor_criteria_dict[i]:
                            poor_criteria_dict[i].append(title)

                    elif weather_stat > av + 0.5 * sd:
                        title = "slight over av"
                        if title not in poor_criteria_dict[i]:
                            poor_criteria_dict[i].append(title)

                    elif weather_stat < av - 1 * sd:
                        title = "slight under av"
                        if title not in poor_criteria_dict[i]:
                            poor_criteria_dict[i].append(title)

                    elif weather_stat < av - 0.5 * sd:
                        title = "sig under av"
                        if title not in poor_criteria_dict[i]:
                            poor_criteria_dict[i].append(title)

            #find top price criteria

            top_criteria_dict = {}

            for i in range(1, 13):
                top_criteria_dict[i] = []

            for top_price_date in top_prices_dates:
                y = top_price_date.year
                for i in range(1, 13):
                    m = i
                    weather_date = eomonth(y, m)
                    weather_stat = specific_weather_dict[weather_date]
                    av = weather_stats[i][0]
                    sd = weather_stats[i][1]

                    if weather_stat > av + 1 * sd:
                        title = "sig over av"
                        if title not in top_criteria_dict[i]:
                            top_criteria_dict[i].append(title)

                    elif weather_stat > av + 0.5 * sd:
                        title = "slight over av"
                        if title not in top_criteria_dict[i]:
                            top_criteria_dict[i].append(title)

                    elif weather_stat < av - 1 * sd:
                        title = "sig under av"
                        if title not in top_criteria_dict[i]:
                            top_criteria_dict[i].append(title)

                    elif weather_stat < av - 0.5 * sd:
                        title = "slight under av"
                        if title not in top_criteria_dict[i]:
                            top_criteria_dict[i].append(title)

            bad_criteria_dict = {}

            for i in range(1, 13):
                bad_criteria_dict[i] = []

            for i in range(1, 13):
                y = [
                    x for x in poor_criteria_dict[i]
                    if x not in top_criteria_dict[i]
                ]
                bad_criteria_dict[i] = y

            good_criteria_dict = {}

            for i in range(1, 13):
                good_criteria_dict[i] = []

            for i in range(1, 13):
                y = [
                    x for x in top_criteria_dict[i]
                    if x not in poor_criteria_dict[i]
                ]
                good_criteria_dict[i] = y

            print(
                "\n" + str(self.address) +
                " great vintages have had these seasonal weather anomalies: " +
                str(top_criteria_dict))
            print(
                "\n" + str(self.address) +
                " standard vintages have had these seasonal weather anomalies: "
                + str(poor_criteria_dict))
            print(
                "\n" + str(self.address) +
                " we will use the following criteria as bad vintage indicators: "
                + str(bad_criteria_dict))
            print(
                "\n" + str(self.address) +
                " we will use the following criteria as good vintage indicators: "
                + str(good_criteria_dict))
コード例 #5
0
        def proceed_with_method():

            weather_dict_raw = Chateau(self.address).weather_dict(category)
            price_dict_raw = Chateau_data(self.address).get_price_data()

            #unpack the dictionaries so the dates have the correct format
            def dict_unpacker(sample_dict):
                dict_unpacked = {}
                for p_date, price in sample_dict.items():
                    formattedas_date = datetime.strptime(p_date, "%Y-%m-%d")
                    dict_unpacked[formattedas_date] = float(price)
                return dict_unpacked

            weather_dict = dict_unpacker(weather_dict_raw)
            price_dict = dict_unpacker(price_dict_raw)

            def eomonth(y, m):
                """returns eomonth for a year and month"""
                year = y
                if m == 12:
                    month = 1
                else:
                    month = int(m) + 1
                given_day = datetime(year, month, 1)
                required_day = given_day - timedelta(days=1)
                return required_day

            def seasonal_weather_dict(dict_sample):
                """returns dict of average daily weather data aggregated by month"""
                monthly_weather_dict = {}
                for p_date, precip in dict_sample.items():
                    formattedas_date = p_date
                    y = formattedas_date.year
                    m = formattedas_date.month
                    needed_day = eomonth(y, m)
                    if needed_day in monthly_weather_dict.keys():
                        x = monthly_weather_dict[needed_day][0] + float(precip)
                        y = monthly_weather_dict[needed_day][1] + 1
                        monthly_weather_dict[needed_day] = [x, y]
                    else:
                        monthly_weather_dict[needed_day] = [float(precip), 1]

                monthly_weather_dict_av = {}
                for needed_day in monthly_weather_dict.keys():
                    d = monthly_weather_dict[needed_day][
                        0] / monthly_weather_dict[needed_day][1]
                    monthly_weather_dict_av[needed_day] = d
                return monthly_weather_dict_av

            def all_monthly_weather_dict(dict_sample, chosen_month):
                """returns dict of weather data aggregated by month for all years"""
                monthly_weather_dict = seasonal_weather_dict(dict_sample)
                all_monthly_weather_dict_final = {}
                for p_date, precip in monthly_weather_dict.items():
                    if p_date.month == int(chosen_month):
                        all_monthly_weather_dict_final[p_date] = precip
                return all_monthly_weather_dict_final

            monthly_weather_dict = all_monthly_weather_dict(
                weather_dict, chosen_month)

            #find the average price
            px_list = []
            for px_date, price in price_dict.items():
                if px_date > datetime(1960, 12, 31):
                    px_list.append(price)

            av = statistics.mean(px_list)
            sd = statistics.stdev(px_list)

            print(str(av) + " is the average price for " + str(self.address))

            #add prices above average to the selected list
            selected_price_dict = {}
            y_values = []
            for px_date, price in price_dict.items():
                if price > av + 0.5 * sd and px_date > datetime(1960, 12, 31):
                    selected_price_dict[px_date] = price
                    y_values.append(price)

            #find weather data for price year
            x_values = []
            for px_date, price in selected_price_dict.items():
                y = px_date.year
                m = chosen_month
                relevant_date = eomonth(y, m)
                addition = monthly_weather_dict[relevant_date]
                x_values.append(addition)

            #calculate best fit line
            x = x_values
            y = y_values
            z = np.polyfit(x, y, 2)
            p = np.poly1d(z)
            xp = np.linspace(min(x_values), max(x_values), 100)

            #calculate correlation coefficient
            correl_y = p(x)
            #A = np.vstack([x, np.ones(len(x))]).T
            #m, c = np.linalg.lstsq(A, correl_y, rcond=None)[0]
            #print(m, c)
            R = np.corrcoef(y, correl_y)
            cor = R.item(1)  #R is a 2x2 matrix so take the correct entry
            print("\nCorrelation coefficient: " + str(cor))

            print("\nSuggested polynomial a*x^2 + bx + c has [a, b, c]: " +
                  str(z))

            #Size the output
            fig = plt.figure(dpi=128, figsize=(10, 6))

            #Chart gridlines
            plt.grid(None, 'major', 'both')

            #Axis tick formats
            for tick in plt.gca().get_xticklabels():
                tick.set_fontname("Calibri")
                tick.set_fontsize(12)
                tick.set_rotation('vertical')
            for tick in plt.gca().get_yticklabels():
                tick.set_fontname("Calibri")
                tick.set_fontsize(12)

            #Axis labels and formats

            # axis 1
            color = 'tab:blue'
            plt.xlabel(str(category) + " avg daily", fontsize=12)
            #plt.xticks(np.arange(x_values[11], x_values[0], 2))
            plt.ylabel("Price", color='black', fontsize=12)
            plt.scatter(x_values, y_values, color=color)
            plt.plot(xp, p(xp), color='red')
            plt.tick_params(axis='y', labelcolor=color)

            #remove borders
            plt.gca().spines['top'].set_visible(False)

            #Chart title
            plt.title(str(self.address) + " Weather Pattern for Month:  " +
                      str(chosen_month),
                      fontsize=14)

            #Show chart
            plt.show()
コード例 #6
0
        def proceed_with_method():

            weather_dict = Chateau(self.address).weather_dict(category)

            def eomonth(y, m):
                year = y
                if m == 12:
                    month = 1
                else:
                    month = int(m) + 1
                given_day = datetime(year, month, 1)
                required_day = given_day - timedelta(days=1)
                return required_day

            def seasonal_weather_dict(dict_sample):
                """returns dict of average daily weather data aggregated by month"""
                monthly_weather_dict = {}
                for p_date, precip in dict_sample.items():
                    formattedas_date = datetime.strptime(p_date, "%Y-%m-%d")
                    y = formattedas_date.year
                    m = formattedas_date.month
                    needed_day = eomonth(y, m)
                    if needed_day in monthly_weather_dict.keys():
                        x = monthly_weather_dict[needed_day][0] + float(precip)
                        y = monthly_weather_dict[needed_day][1] + 1
                        monthly_weather_dict[needed_day] = [x, y]
                    else:
                        monthly_weather_dict[needed_day] = [float(precip), 1]

                monthly_weather_dict_av = {}
                for needed_day in monthly_weather_dict.keys():
                    d = monthly_weather_dict[needed_day][
                        0] / monthly_weather_dict[needed_day][1]
                    monthly_weather_dict_av[needed_day] = d
                return monthly_weather_dict_av

            def all_monthly_weather_dict(dict_sample, chosen_month):
                """returns dict of weather data aggregated by month for vintage year"""
                monthly_weather_dict = seasonal_weather_dict(dict_sample)
                all_monthly_weather_dict_final = {}
                for p_date, precip in monthly_weather_dict.items():
                    if p_date.month == int(chosen_month):
                        all_monthly_weather_dict_final[p_date] = precip
                return all_monthly_weather_dict_final

            monthly_weather_dict = all_monthly_weather_dict(
                weather_dict, chosen_month)
            price_dict = Chateau_data(self.address).get_price_data()

            # start chart
            x_values, y_values = [], []

            for key in monthly_weather_dict.keys():
                x_date = key
                #datetime.strptime(key, '%Y-%m-%d')
                if x_date > datetime(1970, 12, 31):
                    try:
                        y = int(x_date.year)
                        x_date_eoy = date(y, 12, 31)
                        y_values.append(price_dict[str(x_date_eoy)])
                        x_values.append(float(str(monthly_weather_dict[key])))
                    except KeyError:
                        None
                    else:
                        None

            #Size the output
            fig = plt.figure(dpi=128, figsize=(10, 6))

            #Chart gridlines
            plt.grid(None, 'major', 'both')

            #Axis tick formats
            for tick in plt.gca().get_xticklabels():
                tick.set_fontname("Calibri")
                tick.set_fontsize(12)
                tick.set_rotation('vertical')
            for tick in plt.gca().get_yticklabels():
                tick.set_fontname("Calibri")
                tick.set_fontsize(12)

            #Axis labels and formats

            # axis 1
            color = 'tab:blue'
            plt.xlabel(str(category) + " avg daily", fontsize=12)
            #plt.xticks(np.arange(x_values[11], x_values[0], 2))
            plt.ylabel("Price", color='black', fontsize=12)
            plt.scatter(x_values, y_values, color=color)
            plt.tick_params(axis='y', labelcolor=color)

            #remove borders
            plt.gca().spines['top'].set_visible(False)

            #Chart title
            plt.title(str(self.address) + " Weather Pattern for Month:  " +
                      str(chosen_month),
                      fontsize=14)

            #Show chart
            plt.show()
コード例 #7
0
            plt.scatter(x_values, y_values, color=color)
            plt.tick_params(axis='y', labelcolor=color)

            #remove borders
            plt.gca().spines['top'].set_visible(False)

            #Chart title
            plt.title("Price forecaster", fontsize=14)

            #Show chart
            plt.show()

        proceed_with_method()


#for i in range(1,13):
#Chateau_comb("Chateau Margaux").annual_price_weather_chart('p', i)
Chateau_data("Chateau Margaux").print_wine_price(1960)
#Chateau_comb("Chateau Margaux").vintage_patterns(2015)
#Chateau_comb("Chateau Margaux").vintage_patterns(2010)
#Chateau_comb("Chateau Margaux").vintage_patterns(2009)
#Chateau_comb("Chateau Margaux").vintage_patterns(2005)
#Chateau_comb("Chateau Margaux").vintage_patterns(2000)
#Chateau_comb("Chateau Margaux").vintage_patterns(1996)
#Chateau_comb("Chateau Margaux").vintage_patterns(2006)
#Chateau_comb("Chateau Margaux").vintage_patterns(2007)
#Chateau_comb("Chateau Margaux").correl_analysis('v','7')
Chateau_comb("Chateau Margaux").vintage_rule_finder('v')
#Chateau_comb("Chateau Margaux").vintage_distance(2015)
#Chateau_comb("Chateau Margaux").price_forecaster()
コード例 #8
0
ファイル: weather_charts.py プロジェクト: alphadome/python
        def proceed_with_method():

            weather_dict_raw = Chateau(self.address).weather_dict(category)
            price_dict_raw = Chateau_data(self.address).get_price_data()

            weather_dict = dict_unpacker(weather_dict_raw)
            price_dict = dict_unpacker(price_dict_raw)

            monthly_weather_dict = all_monthly_weather_dict(
                weather_dict, chosen_month)

            # start chart
            x_values, y_values = [], []

            for key in monthly_weather_dict.keys():
                x_date = key
                #datetime.strptime(key, '%Y-%m-%d')
                if x_date > datetime(1970, 12, 31):
                    try:
                        y = int(x_date.year)
                        x_date_eoy = date(y, 12, 31)
                        y_values.append(price_dict[str(x_date_eoy)])
                        x_values.append(float(str(monthly_weather_dict[key])))
                    except KeyError:
                        None
                    else:
                        None

            #Size the output
            fig = plt.figure(dpi=128, figsize=(10, 6))

            #Chart gridlines
            plt.grid(None, 'major', 'both')

            #Axis tick formats
            for tick in plt.gca().get_xticklabels():
                tick.set_fontname("Calibri")
                tick.set_fontsize(12)
                tick.set_rotation('vertical')
            for tick in plt.gca().get_yticklabels():
                tick.set_fontname("Calibri")
                tick.set_fontsize(12)

            #Axis labels and formats

            # axis 1
            color = 'tab:blue'
            plt.xlabel(str(category) + " avg daily", fontsize=12)
            #plt.xticks(np.arange(x_values[11], x_values[0], 2))
            plt.ylabel("Price", color='black', fontsize=12)
            plt.scatter(x_values, y_values, color=color)
            plt.tick_params(axis='y', labelcolor=color)

            #remove borders
            plt.gca().spines['top'].set_visible(False)

            #Chart title
            plt.title(str(self.address) + " Weather Pattern for Month:  " +
                      str(chosen_month),
                      fontsize=14)

            #Show chart
            plt.show()
コード例 #9
0
        def proceed_with_method():

            price_dict_raw = Chateau_data(self.address).get_price_data()
            price_dict = dict_unpacker(price_dict_raw)

            x_values, y_values, z_values = [], [], []

            for p_date, price in price_dict.items():
                if p_date > datetime(1970, 12, 31):
                    y_values.append(price)
                    x_values.append(p_date)

            for p_date in x_values:
                vintage = p_date.year
                title = "fundamental_dates_" + str(vintage)
                values_dict = Chateau_fundamentals(
                    self.address).chateau_profile(title)
                z_values.append(values_dict[str(category)][number])

            #calculate best fit line

            x = z_values
            y = y_values
            z = np.polyfit(x, y, 2)
            p = np.poly1d(z)
            xp = np.linspace(min(x), max(x), 100)

            #calculate correlation coefficient
            correl_y = p(x)
            #A = np.vstack([x, np.ones(len(x))]).T
            #m, c = np.linalg.lstsq(A, correl_y, rcond=None)[0]
            #print(m, c)
            R = np.corrcoef(y, correl_y)
            cor = R.item(1)  #R is a 2x2 matrix so take the correct entry
            print("\nCorrelation coefficient: " + str(cor))

            print("\nSuggested polynomial a*x^2 + bx + c has [a, b, c]: " +
                  str(z))

            #Size the output
            fig = plt.figure(dpi=128, figsize=(10, 6))

            #Chart gridlines
            plt.grid(None, 'major', 'both')

            #Axis tick formats
            for tick in plt.gca().get_xticklabels():
                tick.set_fontname("Calibri")
                tick.set_fontsize(12)
                tick.set_rotation('vertical')
            for tick in plt.gca().get_yticklabels():
                tick.set_fontname("Calibri")
                tick.set_fontsize(12)

            #Axis labels and formats

            # axis 1
            color = 'tab:blue'
            plt.xlabel(str(category.title()), fontsize=12)
            #plt.xticks(np.arange(x_values[11], x_values[0], 2))
            plt.ylabel("Price", color='black', fontsize=12)
            plt.scatter(z_values, y_values, color=color)
            plt.plot(xp, p(xp), color='red')
            plt.tick_params(axis='y', labelcolor=color)

            #remove borders
            plt.gca().spines['top'].set_visible(False)

            #Chart title
            plt.title(str(self.address) + " " + str(category.title()) +
                      " Fundamentals:  ",
                      fontsize=14)

            #Show chart
            plt.show()
コード例 #10
0
ファイル: weather_charts.py プロジェクト: alphadome/python
        def proceed_with_method():
            dict_forecast_v = Chateau_comb(self.address).used_correl_analysis(
                'v', str(update))
            dict_forecast_p = Chateau_comb(self.address).used_correl_analysis(
                'p', str(update))
            weather_dict_raw_p = Chateau(self.address).weather_dict('p')
            weather_dict_p = dict_unpacker(weather_dict_raw_p)

            weather_dict_raw_v = Chateau(self.address).weather_dict('v')
            weather_dict_v = dict_unpacker(weather_dict_raw_v)

            m_weather_dict_p = seasonal_weather_dict(weather_dict_p)
            m_weather_dict_v = seasonal_weather_dict(weather_dict_v)

            price_predictions = []

            for i in dict_forecast_v.keys():
                y = vintage
                m = i
                required_date = eomonth(y, m)
                x = m_weather_dict_v[required_date]

                a = dict_forecast_v[i][1]
                b = dict_forecast_v[i][2]
                c = dict_forecast_v[i][3]

                p = a * x * x + b * x + c
                price_predictions.append(p)

            for i in dict_forecast_p.keys():
                y = vintage
                m = i
                required_date = eomonth(y, m)
                x = m_weather_dict_p[required_date]

                a = dict_forecast_p[i][1]
                b = dict_forecast_p[i][2]
                c = dict_forecast_p[i][3]

                p = a * x * x + b * x + c
                price_predictions.append(p)

            predictions_av = statistics.mean(price_predictions)

            #apply factor now based on strikes
            #calculate best fit line
            strike_dict = Chateau_comb(
                self.address).vintage_rule_finder_analysis(update)

            x_values, y_values = [], []
            for key in strike_dict.keys():
                y_values.append(strike_dict[key][0])
                x_values.append(strike_dict[key][1])

            x = x_values
            y = y_values
            z = np.polyfit(x, y, 2)
            p = np.poly1d(z)

            vintage_date = eomonth(vintage, 12)
            strikes = strike_dict[str(vintage_date)][1]

            #find the list of top prices

            price_dict_raw = Chateau_data(self.address).get_price_data()
            price_dict = dict_unpacker(price_dict_raw)

            prices, top_prices = [], []
            for px_date, price in price_dict.items():
                if px_date > datetime(1970, 12, 31):
                    prices.append(price)

            av = statistics.mean(prices)
            sd = statistics.stdev(prices)

            for i in range(0, len(prices) - 1):
                if prices[i] > av + 0.5 * sd:
                    top_prices.append(prices[i])

            top_price_mean = statistics.mean(top_prices)

            if strikes == 0:
                adj_prediction = predictions_av

            if strikes > 0:
                adj_prediction = predictions_av * p(strikes) / top_price_mean

            print('%.2f' % adj_prediction)
            return adj_prediction
コード例 #11
0
ファイル: weather_charts.py プロジェクト: alphadome/python
        def proceed_with_method():
            criteria_dict_p = Chateau_comb(
                self.address).chateau_profile('vintage_rule_finder_p')
            criteria_dict_v = Chateau_comb(
                self.address).chateau_profile('vintage_rule_finder_v')

            weather_dict_raw_p = Chateau(self.address).weather_dict('p')
            weather_dict_raw_v = Chateau(self.address).weather_dict('v')

            price_dict_raw = Chateau_data(self.address).get_price_data()

            weather_dict_p = dict_unpacker(weather_dict_raw_p)
            weather_dict_v = dict_unpacker(weather_dict_raw_v)

            seasonal_weather_dict_p = seasonal_weather_dict(weather_dict_p)
            seasonal_weather_dict_v = seasonal_weather_dict(weather_dict_v)

            price_dict = dict_unpacker(price_dict_raw)

            strike_dict = {}
            for px_date, price in price_dict.items():
                if px_date > datetime(1970, 12, 31):
                    y = px_date.year
                    strike = 0

                    #exceptions in p
                    for i in range(1, 10):
                        m = i
                        required_day = eomonth(y, m)
                        data = seasonal_weather_dict_p[required_day]
                        av = criteria_dict_p[str(i)][1]
                        sd = criteria_dict_p[str(i)][2]
                        for t in range(0, len(criteria_dict_p[str(i)][0]) - 1):
                            if criteria_dict_p[str(i)][0][t] == 'sig over av':
                                if data > av + 2 * sd:
                                    strike = strike + 1

                            if criteria_dict_p[str(
                                    i)][0][t] == 'slight over av':
                                if data > av + 1 * sd and data < av + 2 * sd:
                                    strike = strike + 1

                            if criteria_dict_p[str(i)][0][t] == 'sig under av':
                                if data < av - 2 * sd:
                                    strike = strike + 1

                            if criteria_dict_p[str(
                                    i)][0][t] == 'slight under av':
                                if data < av - 1 * sd and data > av - 2 * sd:
                                    strike = strike + 1

                    #exceptions in v
                    for i in range(1, 13):
                        m = i
                        required_day = eomonth(y, m)
                        data = seasonal_weather_dict_v[required_day]
                        av = criteria_dict_v[str(i)][1]
                        sd = criteria_dict_v[str(i)][2]
                        for t in range(0, len(criteria_dict_v[str(i)][0]) - 1):
                            if criteria_dict_v[str(i)][0][t] == 'sig over av':
                                if data > av + 2 * sd:
                                    strike = strike + 1

                            if criteria_dict_v[str(
                                    i)][0][t] == 'slight over av':
                                if data > av + 1 * sd and data < av + 2 * sd:
                                    strike = strike + 1

                            if criteria_dict_v[str(i)][0][t] == 'sig under av':
                                if data < av - 2 * sd:
                                    strike = strike + 1

                            if criteria_dict_v[str(
                                    i)][0][t] == 'slight under av':
                                if data < av - 1 * sd and data > av - 2 * sd:
                                    strike = strike + 1

                    strike_dict[eomonth(px_date.year, 12)] = [price, strike]

            #calculate best fit line
            x_values, y_values = [], []
            for key in strike_dict.keys():
                y_values.append(strike_dict[key][0])
                x_values.append(strike_dict[key][1])

            x = x_values
            y = y_values
            z = np.polyfit(x, y, 2)
            p = np.poly1d(z)
            xp = np.linspace(min(x_values), max(x_values), 100)

            #calculate correlation coefficient
            correl_y = p(x)
            #A = np.vstack([x, np.ones(len(x))]).T
            #m, c = np.linalg.lstsq(A, correl_y, rcond=None)[0]
            #print(m, c)
            R = np.corrcoef(y, correl_y)
            cor = R.item(1)  #R is a 2x2 matrix so take the correct entry
            print("\nCorrelation coefficient: " + str(cor))

            print("\nSuggested polynomial a*x^2 + bx + c has [a, b, c]: " +
                  str(z))

            #Size the output
            fig = plt.figure(dpi=128, figsize=(10, 6))

            #Chart gridlines
            plt.grid(None, 'major', 'both')

            #Axis tick formats
            for tick in plt.gca().get_xticklabels():
                tick.set_fontname("Calibri")
                tick.set_fontsize(12)
                tick.set_rotation('vertical')
            for tick in plt.gca().get_yticklabels():
                tick.set_fontname("Calibri")
                tick.set_fontsize(12)

            #Axis labels and formats

            # axis 1
            color = 'tab:blue'
            plt.xlabel("Strikes", fontsize=12)
            #plt.xticks(np.arange(x_values[11], x_values[0], 2))
            plt.ylabel("Price", color='black', fontsize=12)
            plt.scatter(x_values, y_values, color=color)
            plt.plot(xp, p(xp), color='red')
            plt.tick_params(axis='y', labelcolor=color)

            #remove borders
            plt.gca().spines['top'].set_visible(False)

            #Chart title
            plt.title(str(self.address) + " Strikes vs Price:  ", fontsize=14)

            #Show chart
            plt.show()
コード例 #12
0
ファイル: weather_charts.py プロジェクト: alphadome/python
        def proceed_with_method():
            criteria_dict_p = Chateau_comb(
                self.address).chateau_profile('vintage_rule_finder_p')
            criteria_dict_v = Chateau_comb(
                self.address).chateau_profile('vintage_rule_finder_v')

            weather_dict_raw_p = Chateau(self.address).weather_dict('p')
            weather_dict_raw_v = Chateau(self.address).weather_dict('v')

            price_dict_raw = Chateau_data(self.address).get_price_data()

            weather_dict_p = dict_unpacker(weather_dict_raw_p)
            weather_dict_v = dict_unpacker(weather_dict_raw_v)

            seasonal_weather_dict_p = seasonal_weather_dict(weather_dict_p)
            seasonal_weather_dict_v = seasonal_weather_dict(weather_dict_v)

            price_dict = dict_unpacker(price_dict_raw)

            strike_dict = {}
            for px_date, price in price_dict.items():
                if px_date > datetime(1970, 12, 31):
                    y = px_date.year
                    strike = 0

                    #exceptions in p
                    for i in range(1, 10):
                        m = i
                        required_day = eomonth(y, m)
                        data = seasonal_weather_dict_p[required_day]
                        av = criteria_dict_p[str(i)][1]
                        sd = criteria_dict_p[str(i)][2]
                        for t in range(0, len(criteria_dict_p[str(i)][0]) - 1):
                            if criteria_dict_p[str(i)][0][t] == 'sig over av':
                                if data > av + 2 * sd:
                                    strike = strike + 1

                            if criteria_dict_p[str(
                                    i)][0][t] == 'slight over av':
                                if data > av + 1 * sd and data < av + 2 * sd:
                                    strike = strike + 1

                            if criteria_dict_p[str(i)][0][t] == 'sig under av':
                                if data < av - 2 * sd:
                                    strike = strike + 1

                            if criteria_dict_p[str(
                                    i)][0][t] == 'slight under av':
                                if data < av - 1 * sd and data > av - 2 * sd:
                                    strike = strike + 1

                    #exceptions in v
                    for i in range(1, 13):
                        m = i
                        required_day = eomonth(y, m)
                        data = seasonal_weather_dict_v[required_day]
                        av = criteria_dict_v[str(i)][1]
                        sd = criteria_dict_v[str(i)][2]
                        for t in range(0, len(criteria_dict_v[str(i)][0]) - 1):
                            if criteria_dict_v[str(i)][0][t] == 'sig over av':
                                if data > av + 2 * sd:
                                    strike = strike + 1

                            if criteria_dict_v[str(
                                    i)][0][t] == 'slight over av':
                                if data > av + 1 * sd and data < av + 2 * sd:
                                    strike = strike + 1

                            if criteria_dict_v[str(i)][0][t] == 'sig under av':
                                if data < av - 2 * sd:
                                    strike = strike + 1

                            if criteria_dict_v[str(
                                    i)][0][t] == 'slight under av':
                                if data < av - 1 * sd and data > av - 2 * sd:
                                    strike = strike + 1

                    strike_dict[str(eomonth(int(px_date.year),
                                            12))] = [price, strike]

            return strike_dict
コード例 #13
0
ファイル: weather_charts.py プロジェクト: alphadome/python
        def proceed_with_method():

            weather_dict_raw = Chateau(self.address).weather_dict(category)
            price_dict_raw = Chateau_data(self.address).get_price_data()

            weather_dict = dict_unpacker(weather_dict_raw)
            price_dict = dict_unpacker(price_dict_raw)

            # monthly_weather_dict = all_monthly_weather_dict(weather_dict, chosen_month)

            #find the list of top prices
            prices, prices_dates, top_prices, lower_prices, top_prices_dates, lower_prices_dates = [], [], [], [], [], []
            for px_date, price in price_dict.items():
                if px_date > datetime(1970, 12, 31):
                    prices.append(price)
                    prices_dates.append(px_date)

            av = statistics.mean(prices)
            sd = statistics.stdev(prices)

            print("\nAverage/Stdev price is: " + str(av) + "/ " + str(sd) +
                  "\n")

            for i in range(0, len(prices) - 1):
                if prices[i] > av + 0.5 * sd:
                    top_prices.append(prices[i])
                    top_prices_dates.append(prices_dates[i])
                elif prices[i] < av - 0 * sd:
                    lower_prices.append(prices[i])
                    lower_prices_dates.append(prices_dates[i])

            poor_criteria_dict = {}

            for i in range(1, 13):
                poor_criteria_dict[i] = []

            weather_stats = all_monthly_weather_dict_detail(weather_dict)
            print(weather_stats)
            specific_weather_dict = seasonal_weather_dict(weather_dict)
            #find poor price criteria
            for lower_price_date in lower_prices_dates:
                y = lower_price_date.year
                for i in range(1, 13):
                    m = i
                    weather_date = eomonth(y, m)
                    weather_stat = specific_weather_dict[weather_date]
                    av = weather_stats[i][0]
                    sd = weather_stats[i][1]

                    if weather_stat > av + 2 * sd:
                        title = "sig over av"
                        if title not in poor_criteria_dict[i]:
                            poor_criteria_dict[i].append(title)

                    elif weather_stat > av + 1 * sd:
                        title = "slight over av"
                        if title not in poor_criteria_dict[i]:
                            poor_criteria_dict[i].append(title)

                    elif weather_stat < av - 2 * sd:
                        title = "slight under av"
                        if title not in poor_criteria_dict[i]:
                            poor_criteria_dict[i].append(title)

                    elif weather_stat < av - 1 * sd:
                        title = "sig under av"
                        if title not in poor_criteria_dict[i]:
                            poor_criteria_dict[i].append(title)

            #find top price criteria

            top_criteria_dict = {}

            for i in range(1, 13):
                top_criteria_dict[i] = []

            for top_price_date in top_prices_dates:
                y = top_price_date.year
                for i in range(1, 13):
                    m = i
                    weather_date = eomonth(y, m)
                    weather_stat = specific_weather_dict[weather_date]
                    av = weather_stats[i][0]
                    sd = weather_stats[i][1]

                    if weather_stat > av + 2 * sd:
                        title = "sig over av"
                        if title not in top_criteria_dict[i]:
                            top_criteria_dict[i].append(title)

                    elif weather_stat > av + 1 * sd:
                        title = "slight over av"
                        if title not in top_criteria_dict[i]:
                            top_criteria_dict[i].append(title)

                    elif weather_stat < av - 2 * sd:
                        title = "sig under av"
                        if title not in top_criteria_dict[i]:
                            top_criteria_dict[i].append(title)

                    elif weather_stat < av - 1 * sd:
                        title = "slight under av"
                        if title not in top_criteria_dict[i]:
                            top_criteria_dict[i].append(title)

            bad_criteria_dict = {}

            for i in range(1, 13):
                bad_criteria_dict[i] = []

            for i in range(1, 13):
                y = [
                    x for x in poor_criteria_dict[i]
                    if x not in top_criteria_dict[i]
                ]
                av = weather_stats[i][0]
                sd = weather_stats[i][1]
                bad_criteria_dict[i] = [y, av, sd]

            good_criteria_dict = {}

            for i in range(1, 13):
                good_criteria_dict[i] = []

            for i in range(1, 13):
                y = [
                    x for x in top_criteria_dict[i]
                    if x not in poor_criteria_dict[i]
                ]
                av = weather_stats[i][0]
                sd = weather_stats[i][1]
                good_criteria_dict[i] = [y, av, sd]

            print("\n" + str(self.address) +
                  " great vintages have had these seasonal " + str(category) +
                  " weather anomalies: " + str(top_criteria_dict))
            print("\n" + str(self.address) +
                  " standard vintages have had these seasonal " +
                  str(category) + " weather anomalies: " +
                  str(poor_criteria_dict))
            print("\n" + str(self.address) +
                  " we will use the following criteria as bad " +
                  str(category) + " vintage indicators: " +
                  str(bad_criteria_dict))
            #print("\n" + str(self.address) + " we will use the following criteria as good vintage indicators: " + str(good_criteria_dict))
            return bad_criteria_dict
コード例 #14
0
ファイル: weather_charts.py プロジェクト: alphadome/python
        def proceed_with_method():

            weather_dict_raw = Chateau(self.address).weather_dict(category)
            price_dict_raw = Chateau_data(self.address).get_price_data()

            weather_dict = dict_unpacker(weather_dict_raw)
            price_dict = dict_unpacker(price_dict_raw)

            monthly_weather_dict = all_monthly_weather_dict(
                weather_dict, chosen_month)

            #find the average price
            px_list = []
            for px_date, price in price_dict.items():
                if px_date > datetime(1960, 12, 31):
                    px_list.append(price)

            av = statistics.mean(px_list)
            sd = statistics.stdev(px_list)

            print(str(av) + " is the average price for " + str(self.address))

            #add prices above average to the selected list
            selected_price_dict = {}
            y_values = []
            for px_date, price in price_dict.items():
                if price > av + 0.5 * sd and px_date > datetime(1970, 12, 31):
                    selected_price_dict[px_date] = price
                    y_values.append(price)

            #find weather data for price year
            x_values = []
            for px_date, price in selected_price_dict.items():
                y = px_date.year
                m = chosen_month
                relevant_date = eomonth(y, m)
                addition = monthly_weather_dict[relevant_date]
                x_values.append(addition)

            #calculate best fit line
            x = x_values
            y = y_values
            z = np.polyfit(x, y, 2)
            p = np.poly1d(z)
            xp = np.linspace(min(x_values), max(x_values), 100)

            #calculate correlation coefficient
            correl_y = p(x)
            #A = np.vstack([x, np.ones(len(x))]).T
            #m, c = np.linalg.lstsq(A, correl_y, rcond=None)[0]
            #print(m, c)
            R = np.corrcoef(y, correl_y)
            cor = R.item(1)  #R is a 2x2 matrix so take the correct entry
            print("\nCorrelation coefficient: " + str(cor))

            print("\nSuggested polynomial a*x^2 + bx + c has [a, b, c]: " +
                  str(z))

            #Size the output
            fig = plt.figure(dpi=128, figsize=(10, 6))

            #Chart gridlines
            plt.grid(None, 'major', 'both')

            #Axis tick formats
            for tick in plt.gca().get_xticklabels():
                tick.set_fontname("Calibri")
                tick.set_fontsize(12)
                tick.set_rotation('vertical')
            for tick in plt.gca().get_yticklabels():
                tick.set_fontname("Calibri")
                tick.set_fontsize(12)

            #Axis labels and formats

            # axis 1
            color = 'tab:blue'
            plt.xlabel(str(category) + " avg daily", fontsize=12)
            #plt.xticks(np.arange(x_values[11], x_values[0], 2))
            plt.ylabel("Price", color='black', fontsize=12)
            plt.scatter(x_values, y_values, color=color)
            plt.plot(xp, p(xp), color='red')
            plt.tick_params(axis='y', labelcolor=color)

            #remove borders
            plt.gca().spines['top'].set_visible(False)

            #Chart title
            plt.title(str(self.address) + " Weather Pattern for Month:  " +
                      str(chosen_month),
                      fontsize=14)

            #Show chart
            plt.show()
コード例 #15
0
        def proceed_with_method():

            weather_dict_p_raw = Chateau(self.address).weather_dict('p')
            weather_dict_v_raw = Chateau(self.address).weather_dict('v')

            weather_dict_p = dict_unpacker(weather_dict_p_raw)
            weather_dict_v = dict_unpacker(weather_dict_v_raw)

            rating_dict_raw = Chateau_rating(self.address).get_rating_data()
            rating_dict = dict_unpacker(rating_dict_raw)

            seasonal_weather_dict_p = average_seasonal_weather_dict(
                weather_dict_p)
            seasonal_weather_dict_v = average_seasonal_weather_dict(
                weather_dict_v)

            price_dict_raw = Chateau_data(self.address).get_price_data()

            price_dict = dict_unpacker(price_dict_raw)

            x_values, y_values, n_values = [], [], []

            for key, rating in rating_dict.items():
                if key in rating_dict.keys() and key > datetime(
                        1970, 12, 31) and rating > 96:

                    p_values, v_values = [], []

                    for w_date, data in weather_dict_v.items():
                        if w_date < eomonth(
                                key.year, end_month - 1) and w_date > eomonth(
                                    key.year, start_month - 1):
                            v_values.append(float(data))

                    if v_values == []:
                        None
                    else:
                        av = statistics.mean(v_values)
                        x_values.append(av)
                        y_values.append(rating)
                        n_values.append(key.year)

            #calculate best fit line
            x = x_values
            y = y_values
            z = np.polyfit(x, y, 2)
            z_formatted = np.ndarray.tolist(z)
            p = np.poly1d(z)
            xp = np.linspace(min(x_values), max(x_values), 100)

            #calculate correlation coefficient
            correl_y = p(x)
            #A = np.vstack([x, np.ones(len(x))]).T
            #m, c = np.linalg.lstsq(A, correl_y, rcond=None)[0]
            #print(m, c)
            R = np.corrcoef(y, correl_y)
            cor = R.item(1)  #R is a 2x2 matrix so take the correct entry
            print("\n For month:" + str(start_month))
            print("\nCorrelation coefficient: " + str('%0.2f' % cor))

            print("\nSuggested polynomial a*x^2 + bx + c has [a, b, c]: " +
                  str('%0.2f' % z_formatted[0]) + ", " +
                  str('%0.2f' % z_formatted[1]) + ", " +
                  str('%0.2f' %
                      z_formatted[2]))  #+ str('%0.2f' % z_formatted[3]))

            #Size the output
            fig = plt.figure(dpi=128, figsize=(10, 6))

            #Chart gridlines
            plt.grid(None, 'major', 'both')

            #Axis tick formats
            for tick in plt.gca().get_xticklabels():
                tick.set_fontname("Calibri")
                tick.set_fontsize(12)
                tick.set_rotation('vertical')
            for tick in plt.gca().get_yticklabels():
                tick.set_fontname("Calibri")
                tick.set_fontsize(12)

            #Axis labels and formats

            # axis 1
            color = 'tab:blue'
            plt.xlabel("Temp", fontsize=12)
            #plt.xticks(np.arange(x_values[11], x_values[0], 2))
            plt.ylabel("Rating", color='black', fontsize=12)
            plt.scatter(x_values, y_values, color=color)
            plt.plot(xp, p(xp), color='red')
            plt.tick_params(axis='y', labelcolor=color)

            for i, txt in enumerate(n_values):
                plt.annotate(txt, (x[i], y[i]))

            #remove borders
            plt.gca().spines['top'].set_visible(False)

            #Chart title
            plt.title(str(self.address) + " Rating vs Price", fontsize=14)

            #Show chart
            plt.show()
コード例 #16
0
        def proceed_with_method():

            price_dict_raw = Chateau_data(self.address).get_price_data()
            price_dict = dict_unpacker(price_dict_raw)

            weather_dict_p_raw = Chateau(self.address).weather_dict('p')
            weather_dict_v_raw = Chateau(self.address).weather_dict('v')

            weather_dict_p = dict_unpacker(weather_dict_p_raw)
            weather_dict_v = dict_unpacker(weather_dict_v_raw)

            # start chart
            x_values, y_values, z_values = [], [], []
            p_values_train, p_values_test = [], []
            x_values_train, x_values_test = [], []
            y_values_train, y_values_test = [], []
            z_values_train, z_values_test = [], []

            for p_date, price in price_dict.items():

                vintage = p_date.year
                monthly_weather_dict_p = vintage_monthly_weather_dict(
                    weather_dict_p, vintage)
                monthly_weather_dict_v = vintage_monthly_weather_dict(
                    weather_dict_v, vintage)

                if p_date > datetime(1970, 12, 31) and p_date <= datetime(
                        2000, 12, 31):
                    p_values_train.append(price)

                    x_vector_train = []
                    y_vector_train = []
                    z_vector_train = []

                    for key in monthly_weather_dict_p.keys():
                        x_date = key
                        x_vector_train.append(key)
                        y_vector_train.append(
                            float(str(monthly_weather_dict_p[key])))
                        y_vector_train.append(monthly_weather_dict_v[x_date])

                    x_values_train.append(x_vector_train)
                    y_values_train.append(y_vector_train)
                    z_values_train.append(z_vector_train)

                if p_date > datetime(2000, 12, 31):
                    p_values_test.append(price)

                    x_vector_test = []
                    y_vector_test = []
                    z_vector_test = []

                    for key in monthly_weather_dict_p.keys():
                        x_date = key
                        x_vector_test.append(key)
                        y_vector_test.append(
                            float(str(monthly_weather_dict_p[key])))
                        z_vector_test.append(monthly_weather_dict_v[x_date])

                    x_values_test.append(x_vector_test)
                    y_values_test.append(y_vector_test)
                    y_values_test.append(z_vector_test)

            x_train = y_values_train
            x_test = y_values_test
            print(x_train)
            print(p_values_train)

            scaler = StandardScaler()
            # Don't cheat - fit only on training data
            scaler.fit(x_train)
            X_train = scaler.transform(x_train)
            # apply same transformation to test data
            X_test = scaler.transform(x_test)

            X = X_train
            y = p_values_train
            clf = MLPRegressor(solver='lbfgs',
                               alpha=1e-5,
                               hidden_layer_sizes=(5, 2),
                               random_state=1)

            clf.fit(X, y)
            MLPRegressor(activation='relu',
                         alpha=1e-05,
                         batch_size='auto',
                         beta_1=0.9,
                         beta_2=0.999,
                         early_stopping=False,
                         epsilon=1e-08,
                         hidden_layer_sizes=(5, 2),
                         learning_rate='constant',
                         learning_rate_init=0.001,
                         max_iter=200,
                         momentum=0.9,
                         n_iter_no_change=10,
                         nesterovs_momentum=True,
                         power_t=0.5,
                         random_state=1,
                         shuffle=True,
                         solver='lbfgs',
                         tol=0.0001,
                         validation_fraction=0.1,
                         verbose=False,
                         warm_start=False)

            results = clf.predict(X_test)
            print(results)
            #print(str(results).replace(' ',', ').replace(' ,',''))

            y_values_pred_raw = str(results).replace(' ',
                                                     ', ').replace(' ,', '')

            y_values_pred = ast.literal_eval(y_values_pred_raw)
            #for i in range(0,len(y_values_pred_raw)-1):
            #y_values_pred.append(float(y_values_pred_raw[i]))

            #print(y_values_pred)

            print([coef.shape for coef in clf.coefs_])

            #print(clf.predict_proba(z_values_test))

            # Create linear regression object
            ##regr = linear_model.LinearRegression()

            # Train the model using the training sets
            #regr.fit(z_values_train, y_values_train)

            # Make predictions using the testing set
            #y_values_pred = regr.predict(z_values_test)

            # The coefficients
            #print('Coefficients: \n', regr.coef_)
            # The mean squared error
            #print("Mean squared error: %.2f"
            #     % mean_squared_error(p_values_test, y_values_pred))
            #Explained variance score: 1 is perfect prediction
            #print('R2 score: %.2f' % r2_score(p_values_test, y_values_pred))
            # print('R2 score: %.2f' % r2_score(y_values_test, y_values_pred))

            #Size the output
            fig = plt.figure(dpi=128, figsize=(10, 6))

            #Chart gridlines
            plt.grid(None, 'major', 'both')

            #Axis tick formats
            for tick in plt.gca().get_xticklabels():
                tick.set_fontname("Calibri")
                tick.set_fontsize(12)
                tick.set_rotation('vertical')
            for tick in plt.gca().get_yticklabels():
                tick.set_fontname("Calibri")
                tick.set_fontsize(12)

            #Axis labels and formats

            # axis 1
            color = 'tab:blue'
            plt.xlabel("Date", fontsize=12)
            #plt.xticks(np.arange(x_values[11], x_values[0], 2))
            plt.ylabel("Price", color='black', fontsize=12)
            plt.bar(
                x_values_train + x_values_test,
                p_values_train + p_values_test,
                facecolor='none',
                edgecolor='blue',
            )
            plt.scatter(x_values_train + x_values_test,
                        y_values_pred,
                        color='red',
                        linestyle='dashed')
            plt.tick_params(axis='y', labelcolor=color)

            #ax2 = plt.twinx()  # instantiate a second axes that shares the same x-axis

            #axis 2
            #color = 'tab:red'
            #ax2.set_ylabel("Price", color='black', fontsize=12)  # we already handled the x-label with ax1
            #ax2.plot(x_values, y_values, color=color)
            #ax2.scatter(x_values, z_values, color=color, linestyle='dashed')
            #ax2.tick_params(axis='y', labelcolor=color)

            #remove borders
            plt.gca().spines['top'].set_visible(False)

            #Chart title
            plt.title(str(self.address) + " actual px vs forecast",
                      fontsize=14)

            #Show chart
            plt.show()
コード例 #17
0
        def proceed_with_method():
            rating_dict_raw = Chateau_rating(self.address).get_rating_data()
            price_dict_raw = Chateau_data(self.address).get_price_data()

            rating_dict = dict_unpacker(rating_dict_raw)
            price_dict = dict_unpacker(price_dict_raw)

            x_values, y_values, n_values = [], [], []

            for key, price in price_dict.items():
                if key in rating_dict.keys() and key > datetime(1970, 12, 31):
                    y_values.append(price)
                    x_values.append(rating_dict[key])
                    n_values.append(key.year)

            #calculate best fit line
            x = x_values
            y = y_values
            z = np.polyfit(x, y, 3)
            z_formatted = np.ndarray.tolist(z)
            p = np.poly1d(z)
            xp = np.linspace(min(x_values), max(x_values), 100)

            #calculate correlation coefficient
            correl_y = p(x)
            #A = np.vstack([x, np.ones(len(x))]).T
            #m, c = np.linalg.lstsq(A, correl_y, rcond=None)[0]
            #print(m, c)
            R = np.corrcoef(y, correl_y)
            cor = R.item(1)  #R is a 2x2 matrix so take the correct entry
            print("\nCorrelation coefficient: " + str('%0.2f' % cor))

            print(
                "\nSuggested polynomial a*x^3 + bx^2 + cx + d has [a, b, c, d]: "
                + str('%0.2f' % z_formatted[0]) + ", " +
                str('%0.2f' % z_formatted[1]) + ", " +
                str('%0.2f' % z_formatted[2]) + ", " +
                str('%0.2f' % z_formatted[3]))

            #Size the output
            fig = plt.figure(dpi=128, figsize=(10, 6))

            #Chart gridlines
            plt.grid(None, 'major', 'both')

            #Axis tick formats
            for tick in plt.gca().get_xticklabels():
                tick.set_fontname("Calibri")
                tick.set_fontsize(12)
                tick.set_rotation('vertical')
            for tick in plt.gca().get_yticklabels():
                tick.set_fontname("Calibri")
                tick.set_fontsize(12)

            #Axis labels and formats

            # axis 1
            color = 'tab:blue'
            plt.xlabel("Global wine rating", fontsize=12)
            #plt.xticks(np.arange(x_values[11], x_values[0], 2))
            plt.ylabel("Price", color='black', fontsize=12)
            plt.scatter(x_values, y_values, color=color)
            plt.plot(xp, p(xp), color='red')
            plt.tick_params(axis='y', labelcolor=color)

            for i, txt in enumerate(n_values):
                plt.annotate(txt, (x[i], y[i]))

            #remove borders
            plt.gca().spines['top'].set_visible(False)

            #Chart title
            plt.title(str(self.address) + " Rating vs Price", fontsize=14)

            #Show chart
            plt.show()
コード例 #18
0
ファイル: weather_charts.py プロジェクト: alphadome/python
        def proceed_with_method():
            price_dict_raw = Chateau_data(self.address).get_price_data()
            price_dict = dict_unpacker(price_dict_raw)

            #create the chart list
            x_values, y_values, z_values = [], [], []

            for key in price_dict.keys():
                x_date = key
                if int(x_date.year) > int(beg_year):
                    x_values.append(key.year)
                    y_values.append(float(str(price_dict[key])))
                    forecast = Chateau_comb(self.address).price_forecaster(
                        x_date.year)
                    print(x_date.year)
                    z_values.append(forecast)

            print(y_values)
            print(z_values)

            #Size the output
            fig = plt.figure(dpi=128, figsize=(10, 6))

            #Chart gridlines
            plt.grid(None, 'major', 'both')

            #Axis tick formats
            for tick in plt.gca().get_xticklabels():
                tick.set_fontname("Calibri")
                tick.set_fontsize(12)
                tick.set_rotation('vertical')
            for tick in plt.gca().get_yticklabels():
                tick.set_fontname("Calibri")
                tick.set_fontsize(12)

            #Axis labels and formats

            # axis 1
            color = 'tab:blue'
            plt.xlabel("Date", fontsize=12)
            #plt.xticks(np.arange(x_values[11], x_values[0], 2))
            plt.ylabel("Price", color='black', fontsize=12)
            plt.bar(
                x_values,
                y_values,
                facecolor='none',
                edgecolor='blue',
            )
            plt.scatter(x_values, z_values, color='red', linestyle='dashed')
            plt.tick_params(axis='y', labelcolor=color)

            #ax2 = plt.twinx()  # instantiate a second axes that shares the same x-axis

            #axis 2
            #color = 'tab:red'
            #ax2.set_ylabel("Price", color='black', fontsize=12)  # we already handled the x-label with ax1
            #ax2.plot(x_values, y_values, color=color)
            #ax2.scatter(x_values, z_values, color=color, linestyle='dashed')
            #ax2.tick_params(axis='y', labelcolor=color)

            #remove borders
            plt.gca().spines['top'].set_visible(False)

            #Chart title
            plt.title(str(self.address) + " actual px vs forecast",
                      fontsize=14)

            #Show chart
            plt.show()