def run(): if (CheckVar1.get() == 0 and CheckVar2.get() == 0 and CheckVar3.get() == 0 and CheckVar4.get() == 0): s_1 = '您还没选择任何组合策略' else: s1 = "认购" if CheckVar1.get() == 1 else "" s2 = "认沽" if CheckVar2.get() == 1 else "" s3 = "买入" if CheckVar3.get() == 1 else "" s4 = "卖出" if CheckVar4.get() == 1 else "" s_1 = "第一个合约:%s %s %s %s 合约" % (s1, s2, s3, s4) lb2.config(text=s_1) exe_price1 = float(inp1.get()) cost_price1 = float(inp2.get()) if (CheckVar5.get() == 0 and CheckVar6.get() == 0 and CheckVar7.get() == 0 and CheckVar8.get() == 0): s_2 = '您还没选择任何组合策略' else: s5 = "认购" if CheckVar5.get() == 1 else "" s6 = "认沽" if CheckVar6.get() == 1 else "" s7 = "买入" if CheckVar7.get() == 1 else "" s8 = "卖出" if CheckVar8.get() == 1 else "" s_2 = "第二个合约:%s %s %s %s 合约" % (s5, s6, s7, s8) lb3.config(text=s_2) exe_price2 = float(inp3.get()) cost_price2 = float(inp4.get()) #运行画图函数 is_call1 = CheckVar1.get() if CheckVar1.get() == 1 else 0 is_long1 = CheckVar3.get() if CheckVar3.get() == 1 else 0 is_call2 = CheckVar5.get() if CheckVar5.get() == 1 else 0 is_long2 = CheckVar7.get() if CheckVar7.get() == 1 else 0 rev = Revenue() print(exe_price1, cost_price1, is_call1, is_long1, exe_price2, cost_price2, is_call2, is_long2) rev.calculate(exe_price1, cost_price1, is_call1, is_long1, exe_price2, cost_price2, is_call2, is_long2)
def serialize(cls, ref): operationList = [] revenueList = [] balanceList = [] for operation in ref.operation: operationList.append(Operation.serialize(operation)) for revenue in ref.revenue: revenueList.append(Revenue.serialize(revenue)) for balance in ref.balance: balanceList.append(Balance.serialize(balance)) # TODO: use constants for the names of all JSon fields #return json.dumps(attributes) return { #"id": ref.id, "name": ref.name, "type": ref.type, "bank": ref.bank, "operations": ref.operation, "balance": ref.balance, "revenue": ref.revenue "name": ref.name, "type": ref.type, "bank": ref.bank, "operations": operationList, "revenue": revenueList, "balance": balanceList }
def check_area_ytp(pickle_name): data = load(pickle_name) n_years = 15 house_cost = data.loc[0].value appreciation = 3.0 n_months = n_years * 12 dates = pd.date_range(data.loc[0].date, periods=n_months, freq="M") rent = Revenue("rent", "monthly payment", 0.011 * house_cost) # costs utilities = Cost("utilities", "hvac", 150) insurance = Cost("insurance", "full coverage", 100) property_tax = Cost("insurance", "full coverage", (house_cost * 0.019) / 12) mortgage = Mortgage(house_cost, 25000, dates, 3.0) # revenue revenues = [rent] costs = [utilities, insurance, property_tax] house = House(revenues, costs, mortgage, dates, appreciation) # house.summary() house.graph_net_profit() portfolio = Portfolio([house]) ytp = portfolio.get_years_to_positive(house) print("years till positive", ytp) exit(0) return ytp
def addRevenue(self, newRevenue): self.revenue.append(Revenue.unserialize(newRevenue)) self.revenue = sorted(self.revenue, reverse=True)
import matplotlib.pyplot as plt import seaborn as sns from revenue import Revenue revenue = Revenue().clean() are_old = revenue["Age"] > 60 plt.hist(revenue[are_old]["Age"], bins=50) plt.show()
import numpy as np import matplotlib.pyplot as plt import seaborn as sns from revenue import Revenue revenue = Revenue().clean() revenue.info() revenue.describe() for c in revenue.columns: if revenue[c].dtype == np.dtype("O"): print(c, revenue[c].unique()) plt.figure() sns.pairplot(revenue) plt.tight_layout() plt.savefig("pairplot.png")
#PURPOSE: answer question 1 from revenue import Revenue revenue = Revenue().clean() UNIT = 1e6 #euros print(revenue.groupby("Model")["Price"].sum().sort_values(ascending=False)/UNIT)
#PURPOSE: answer question 3 from revenue import Revenue import matplotlib.pyplot as plt import seaborn as sns revenue = Revenue().clean() median_all = revenue.groupby(["Sex", "is_weekend"]).median()[["Age", "Incomes"]] is_clio = revenue["Model"] == "Clio" is_yellow = revenue["Color"] == "yellow" yellow_clio = revenue[is_clio & is_yellow] yellow_clio = yellow_clio.drop(["Model", "Color", "Price"], axis=1) median_yellow_clio = yellow_clio.groupby(["Sex", "is_weekend"]).median() # age and incomes comparison = median_all.merge(median_yellow_clio, left_index=True, right_index=True, suffixes=["_all", "_yc"]) comparison["age_diff"] = comparison["Age_yc"] - comparison["Age_all"] comparison["incomes_diff"] = comparison["Incomes_yc"] - comparison["Incomes_all"] comparison = comparison.drop(["Age_all", "Incomes_all", "Age_yc", "Incomes_yc"], axis=1) # sex and is_weekend