def create_chart(self, file_path): date = datetime.now().strftime('%Y-%m-%d_%H-%M-%S') self.main_window.change_buttons_state() handler = reader.CSVReader(file_path) chart_path = "/".join(file_path.split("/")[:-1]) + f"/{date}_chart.png" chart = charts.Chart(handler.cells, chart_path).create_plot() self.main_window.change_buttons_state()
def testPlotlyfromMPL(): chart = c.Chart(2,1) chart.chartBasic(pd.Series([0,1,4,2,3,4]),(0,1), kind='line') mpl_fig = chart.fig plotly_fig = tls.mpl_to_plotly(mpl_fig) unique_url = py.plot(plotly_fig, fileopt='overwrite', auto_open=False) print(unique_url)
def histogram(self, evalperiod, fieldList): """ Produces histogram chart :param fieldList: list of fields for histograms :param evalperiod: which period you want the histogram on """ chart = ch.Chart(len(fieldList), 1, sharex=False, sharey=False, hspace=0.4, top=0.930, title="Simulation Histogram", chartfilename="Sim Histogram" + datetime.now().strftime('%a %I.%M.%S')) for i in range(0, len(fieldList)): bb = (fieldList[i].iloc[evalperiod, :] ) # ** (1 / (p / self.frequency)) - 1 chart.chartBasic(bb, (i, 0), kind='hist', title=fieldList[i].name, fontsize=9) self.fillTextBox(chart, 0.135, 0.05, single=False) chart.save() return
def simABTest(dictA, dictB): """ Show Various Sim Results for two simulation runs with one or more parameter changed on the second run. *** Charts are on the same axis *** Notes: Trials must be 1. :return: """ chart = c.Chart(3, 1, sharex=True, sharey=False, title="Sim: A/B Test", bottom=.21, top=.935) sim_A = Simulation(**dictA) sim_A.simulate() chart.chartBasic(sim_A.simresults.totalInvestorValue, (0, 1), color='cadetblue', linestyle='-') chart.chartBasic(sim_A.simresults.residualCashFlow, (1, 1), legend=True, color='cadetblue', linestyle='-') sim_B = Simulation(**dictB) sim_B.simulate() chart.chartBasic(sim_B.simresults.totalInvestorValue, (0, 1), color='brown', linestyle='-', title='Total Investor Value') chart.chartBasic(sim_B.simresults.residualCashFlow, (1, 1), title="Cash Flow Paths", legend=True, color='brown', linestyle='-') """ PRICE INPUTS """ chart.chartBasic(sim_A.process.pricePaths, (2, 1), legend=False, color='cadetblue', linestyle='-') chart.chartBasic(sim_B.process.pricePaths, (2, 1), title="Price Path", legend=False, color='brown', linestyle='-') sim_A.fillTextBox(chart, 0.135, 0.12) sim_B.fillTextBox(chart, 0.135, 0.05) plt.show()
def get_csv(): stat_name, benchmarks, procs, normalize, average, hmean = halogen.process_chart_request(request) chart = charts.Chart(stat_name=stat_name, benchmarks=benchmarks, runs=procs, normalize=normalize, average=average, hmean=hmean) return Response(chart.to_csv(), mimetype="text/plain", headers={"Content-Disposition": "attachment;filename=test.csv"})
def get_chart(): stat_name, benchmarks, procs, normalize, average, hmean = halogen.process_chart_request(request) chart = charts.Chart(stat_name=stat_name, benchmarks=benchmarks, runs=procs, normalize=normalize, average=average, hmean=hmean) response = make_response(chart.to_json()) response.content_type = 'application/json' return response
def chartNavPaths(self, **kwargs): chart = kwargs.get( 'chart', ch.Chart(2, 1, sharex=False, sharey=False, title="SimHist", top=0.930)) investmentSize = self.simresults.ramp.sum() # bogey lines a = pd.Series([ investmentSize * (1 + 0.05 / self.account.frequency)**x for x in range(0, self.process.processLife) ]) b = pd.Series([ investmentSize * (1 + 0.10 / self.account.frequency)**x for x in range(0, self.process.processLife) ]) c = pd.Series([ investmentSize * (1 + 0.15 / self.account.frequency)**x for x in range(0, self.process.processLife) ]) d = pd.Series([(1 + self.process.growthRate)**x for x in range(0, self.process.processLife)]) a.name = 'IRR=0.05' b.name = 'IRR=0.1' c.name = 'IRR=0.15' d.name = 'IRR=' + str( round(self.process.growthRate * self.account.frequency, 2)) chart.chartBasic(c, (0, 0), color='blue', legend=True) chart.chartBasic(b, (0, 0), color='blue', legend=True) chart.chartBasic(a, (0, 0), color='blue', legend=True) chart.chartBasic(d, (1, 0), color='green', legend=True) chart.chartBasic(self.simresults.totalInvestorValue, (0, 0), title=self.simresults.totalInvestorValue.name, legend=True) chart.chartBasic(self.process.pricePaths, (1, 0), title="Price Path", legend=True) chart.save() return
def chartsmain(): d = s.Data() d.getFreddieData() #d.getMSAData() ch = c.Chart(1, 2) # Schiller Plot # c.plotCaseSchiller(d.getCaseSchillerData()) # Grid of Multiples and Discounts # c.gridOfMultiplesAndDiscounts() # Grid of IRR by Vintage/Age #c.gridOfIRR(d, msa=10900, payoff_status='Defaulted') # Histogram of Home Price Appreciation versus Payoff #c.histAppreciationVsPayoff(d.getFreddieData(), msa=10900, vintage=1999, payoff_status='Paid Off') # ch = c.Chart(2,2, sharey = False, sharex = True, title="Total Appreciation") # ch.histGeneric(d.getFreddieData, a.calcTotalAppreciation, (0, 0), vintage=1999, age=4) # ch.histGeneric(d.getFreddieData, a.calcTotalAppreciation, (0, 1), vintage=1999, age=7) # ch.histGeneric(d.getFreddieData, a.calcTotalAppreciation, (1, 0), vintage=2005, age=4) # ch.histGeneric(d.getFreddieData, a.calcTotalAppreciation, (1, 1), vintage=2005, age=7) # ch.save() # ddd = c.Chart(1,1) # d = a.payoffIRR(initialInv, investorShare, apprAnnualized, life, discount) # d2 = p.monthlyPayoffTiming(d.getFreddieData(), ddd.axes, yr="all", dollar=False) # print(d2) # ch1 = c.Chart(4,1, sharey = False, title="Total Appreciation by Multiple Cuts") # ch1.setChartFileName("Test1") # ch1.histGeneric(d.getFreddieData(), a.calcTotalAppreciation, (0, 0), title='Total Appreciation\n') # ch1.histGeneric(d.getFreddieData(), a.calcTotalAppreciation, (1, 0), vintage=2006, title='Total Appreciation\n') # ch1.histGeneric(d.getFreddieData(), a.calcTotalAppreciation, (2, 0), payoff_status='Defaulted', vintage=2006, title='Total Appreciation\n') # ch1.histGeneric(d.getFreddieData(), a.calcTotalAppreciation, (3, 0), payoff_status='Defaulted', vintage=2006, msa=10900, title='Total Appreciation\n') # ch1.save() # # ch2 = c.Chart(4, 2, sharey=False, title="Annualized SOTW Returns by LTV") # ch2.setChartFileName("Test2") # ch2.histGeneric(d.getFreddieData(), a.calcAnnualizedPayoff, (0, 0), orig_oltv=(60, 100), age=(2, 10), title='Annualized Payoff\n') # ch2.histGeneric(d.getFreddieData(), a.calcAnnualizedPayoff, (1, 0), orig_oltv=(40, 60), age=(2, 10), title='Annualized Payoff\n') # ch2.histGeneric(d.getFreddieData(), a.calcAnnualizedPayoff, (2, 0), orig_oltv=(20, 40), age=(2, 10), title='Annualized Payoff\n') # ch2.histGeneric(d.getFreddieData(), a.calcAnnualizedPayoff, (3, 0), orig_oltv=(0, 20), age=(2, 10), title='Annualized Payoff\n') # ch2.histGeneric(d.getFreddieData(), a.calcAnnualizedPayoff, (0, 1), orig_oltv=(60, 100), age=(0, 10), title='Annualized Payoff\n') # ch2.histGeneric(d.getFreddieData(), a.calcAnnualizedPayoff, (1, 1), orig_oltv=(40, 60), age=(0, 10), title='Annualized Payoff\n') # ch2.histGeneric(d.getFreddieData(), a.calcAnnualizedPayoff, (2, 1), orig_oltv=(20, 40), age=(0, 10), title='Annualized Payoff\n') # ch2.histGeneric(d.getFreddieData(), a.calcAnnualizedPayoff, (3, 1), orig_oltv=(0, 20), age=(0, 10), title='Annualized Payoff\n') # ch2.save() # ch3 = c.Chart(5, 2, sharey=False, title="Annualized SOTW Returns by Age") # ch3.setChartFileName("Test3") # ch3.histGeneric(d.getFreddieData(), a.calcAnnualizedPayoff, (0, 0), age=(0, 0), title='Annualized Payoff\n', bins = (-1, 1, .02)) # ch3.histGeneric(d.getFreddieData(), a.calcAnnualizedPayoff, (1, 0), age=(1, 1), title='Annualized Payoff\n') # ch3.histGeneric(d.getFreddieData(), a.calcAnnualizedPayoff, (2, 0), age=(2, 2), title='Annualized Payoff\n') # ch3.histGeneric(d.getFreddieData(), a.calcAnnualizedPayoff, (3, 0), age=(3, 3), title='Annualized Payoff\n') # ch3.histGeneric(d.getFreddieData(), a.calcAnnualizedPayoff, (4, 0), age=(4, 4), title='Annualized Payoff\n') # ch3.histGeneric(d.getFreddieData(), a.calcAnnualizedPayoff, (0, 1), age=(5, 5), title='Annualized Payoff\n') # ch3.histGeneric(d.getFreddieData(), a.calcAnnualizedPayoff, (1, 1), age=(6, 6), title='Annualized Payoff\n') # ch3.histGeneric(d.getFreddieData(), a.calcAnnualizedPayoff, (2, 1), age=(7, 7), title='Annualized Payoff\n') # ch3.histGeneric(d.getFreddieData(), a.calcAnnualizedPayoff, (3, 1), age=(8, 8), title='Annualized Payoff\n') # ch3.histGeneric(d.getFreddieData(), a.calcAnnualizedPayoff, (4, 1), age=(9, 10), title='Annualized Payoff\n') # ch3.save() # ch4 = c.Chart(2,1, sharey=False, title="testAge") # ch4.setChartFileName("testAge") # ch4.ageGeneric(d.getFreddieData(), (0, 0), pct=True, title='Annualized Payoff\n', vintage=2006) # ch4.ageGeneric(d.getFreddieData(), (0, 0), pct=True, byyear=True, title='Default Curve\n', payoff_status='Defaulted', msa = 10900) # ch4.ageGeneric(d.getFreddieData(), (0, 0), pct=True, byyear=True, title='Default Curve\n', payoff_status='Defaulted') # ch4.ageGeneric(d.getFreddieData(), (2, 0), pct=True, byyear=True, title='Default Curve\n', payoff_status='Defaulted', vintage=2006, msa = 10900) # ch4.ageGeneric(d.getFreddieData(), (3, 0), pct=True, byyear=True, title='Default Curve\n', payoff_status='Defaulted', vintage=2006) # ch4.save() ch5 = c.Chart(2, 1, sharex=False, sharey=False) ch5.setChartFileName("test kwarg") ch5.setTitle("testPivot") ch5.pivotGeneric(d.getFreddieData(), (0, 0), age=(2, 10), rows='age', values='ret', vintage=2006, title="Returns by Age") ch5.pivotGeneric(d.getFreddieData(), (1, 0), rows='vintage', values='ret', title="Returns by Vintage") ch5.save() return
def chartAllSimResults(self, plotly=False): """ Five charts stacked up, showing all important simulated stats Use with single run :return: """ if self.process.trials > 1: print("Error: Single-trial function. Set trials=1") return chart = ch.Chart(5, 1, sharex=True, sharey=False, fontsize=8, title='SOTW Simulation Trial Results ' + str(self.account.ramp.sum() / 1e6) + "MM", plotly=plotly) chart.chartfilename = "Sim Results " + datetime.now().strftime( '%a %I.%M.%S') chart.chartBasic(self.simresults.servicingFee, (0, 0), legend=True, color=ch.SOTW_RED, linestyle='-') chart.chartBasic(self.simresults.performanceFee, (0, 0), legend=True, color=ch.SOTW_RED, linestyle='--') #chart.chartBasic(self.simresults.dividendPaths, (0, 0), legend=True, color=c.SOTW_YELLOW, linestyle='-') chart.chartBasic(self.simresults.residualCashFlow, (0, 0), legend=True, color=ch.SOTW_GREEN, linestyle='--', secondary=True) chart.chartBasic(self.simresults.totalInvestorValue, (1, 0), legend=True, color='sienna', linestyle='-') chart.chartBasic(self.simresults.totalInvestorCashFlow, (1, 0), legend=True, color=ch.SOTW_YELLOW, linestyle='--') chart.chartBasic(self.simresults.accountValue, (1, 0), legend=True, color=ch.SOTW_YELLOW, linestyle='-') chart.chartBasic(self.process.pricePaths, (2, 0), legend=True, color=ch.SOTW_BLUE, linestyle='-') chart.chartBasic(self.simresults.nav, (3, 0), legend=True, color=ch.SOTW_YELLOW, linestyle='-') chart.chartBasic(self.simresults.dfNav, (3, 0), legend=True, color='lightgray', linestyle='--') chart.chartBasic(self.simresults.equity, (3, 0), legend=True, color=ch.SOTW_BLUE, linestyle='-') #chart.chartBasic(self.simresults.lossPaths, (3, 0), legend=True, color=c.SOTW_YELLOW, linestyle='-') #chart.chartBasic(self.simresults.finalPayLossPaths, (3, 0), legend=True, color=c.SOTW_GREEN, linestyle='-') totalfee = pd.DataFrame( (self.simresults.servicingFee['Servicing Fee'] + self.simresults.performanceFee['Performance Fee']).cumsum()) totalfee.name = 'Cumulative Fee' chart.chartBasic(totalfee, (4, 0), legend=True, color=ch.SOTW_RED, linestyle='-') self.fillTextBox(chart, 0.135, 0.05) if chart.plotly: ch.plotly.plotly.plot( chart.plotlyFig, filename='make-subplots-multiple-with-titles', auto_open=False) else: chart.save()