• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python numpy.npv函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中numpy.npv函数的典型用法代码示例。如果您正苦于以下问题:Python npv函数的具体用法?Python npv怎么用?Python npv使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了npv函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: choose_tech

def choose_tech(VE,D,j,N,energy,prices_lamp,tt,interes):

    method=strategy(VE[j,2])
    #returns the strategy to use over the different profiles
    #(1)rational, (2) social, (3) conservative


    #Rational method
    if method==1:   #180 hours of consume in average per month
        cost=np.zeros((3,139)) #Payments over time of the different techs
        cost_present=np.zeros(3) #Total present cost
        
        #Analysis of energy consume
        for i in range(139):
            if VE[j,3]==1:
                cost[0,i]=(-40*180/100)*energy[i+tt]*0.8
                cost[1,i]=(-15*180/100)*energy[i+tt]*0.8
                cost[2,i]=(-9*180/100)*energy[i+tt]*0.8
            elif VE[j,3]==2:
                cost[0,i]=(-40*180/100)*energy[i+tt]*1.2
                cost[1,i]=(-15*180/100)*energy[i+tt]*1.2
                cost[2,i]=(-9*180/100)*energy[i+tt]*1.2
        
        #LED lamp cost
        cost[2,0]=cost[2,0]-prices_lamp[2,tt]
    
        #Fluorescent lamp cost (1:36:139)
        for i in range(0,138,36):
            cost[1,i]=cost[1,i]-prices_lamp[1,tt+i]
    
        #Incandescent lamp cost (i=1:4:139)
        for i in range(0,138,4):
            cost[0,i]=cost[0,i]-prices_lamp[0,tt+i]
            
        #Cost in present value
        cost_present[0]=-np.npv(interes,cost[0,:])
        cost_present[1]=-np.npv(interes,cost[1,:])
        cost_present[2]=-np.npv(interes,cost[2,:])
    
        #Selection of the best npv performance
        tech=cost_present.argmin()
        tech=tech+1
    
    #Conservative method
    if method==3:
        tech=VE[j,0]


    #Social method
    if method==2:
        S_t=np.zeros(3) #Counter of technologies in vicinity
        D_N=D.neighbors(j) #Returns the list of neighbors
        D_N_len=len(D_N) #Dimension of neighbors list
            
        for k in range(D_N_len): #Iteration of evaluation
            S_t[VE[D_N[k],0]-1]=S_t[VE[D_N[k],0]-1]+1
                
        tech=S_t.argmax()+1
        
    return(tech)
开发者ID:pauloyuncha,项目名称:diffusion_model_car_fuel,代码行数:60,代码来源:choose_tech.py


示例2: outputRow

 def outputRow():
     #NOTE: The fields of the db row, such a loan_id, are no longer available when this is called.
     discountRate = principalDiscountRates[finalStatus]
     numeratorNARdiscount = prev_balance_end * discountRate
     cashflowLen = len(cashflow)
     while cashflow[cashflowLen-1]==0: cashflowLen -= 1
     cashflow.resize(max(cashflowLen, receivedMonthIndex+1))
     npv = np.npv(monthlyDiscountRate-1, cashflow)
     if printCashflow: print(cashflow)
     if finalStatus != 'Charged Off':
         cashflow[receivedMonthIndex] += prev_balance_end * (1-discountRate) / prev_investment
     if printCashflow: print(cashflow)
     npvForecast = np.npv(monthlyDiscountRate-1, cashflow)
     irrForecast = (1+np.irr(cashflow))**12 - 1
     finalStatusIsComplete = finalStatus in ["Charged Off", "Default", "Fully Paid"]
     output.append((
             prev_loan_id,
             finalStatus,
             prev_mob,
             missedPayment,
             firstMissed,
             dueWhenFirstMissed,
             receivedAfterMissed,
             riskFreeRate,
             npv,
             npvForecast,
             firstMissedOrLastObserved,
             (numeratorNAR-numeratorNARdiscount)/prev_investment,
             denominatorNAR/prev_investment,
             finalStatusIsComplete,
             irrForecast,
             #cashflow
         ))        
开发者ID:Erin-Boehmer,项目名称:p2p-loan-capstone,代码行数:33,代码来源:processHistory.py


示例3: net_present_value_aggregate_for_portfolio

    def net_present_value_aggregate_for_portfolio(self):
        """ Gets the portfolio's aggregate net present value.

        Returns: The portfolio's aggregate net present value.

        """
        npv = np.npv(self.discount_rate / 12, list(self.aggregate_flows_df['total_payments']))
        return float(npv)
开发者ID:ssmusoke,项目名称:MBS-Portfolio-Risk-Managament-System,代码行数:8,代码来源:cash_flows_engine.py


示例4: net_present_value_for_loan

    def net_present_value_for_loan(self, loan):
        """ Calculates a loan's net present value from its cash flows.

        Args:
            loan: The loan which is being valued.

        Returns: The net present value of the loan.

        """
        cash_flows = self.cash_flows_df[self.cash_flows_df['loan_df_pk'] == loan.name]
        npv = np.npv(self.discount_rate / 12, cash_flows['total_payments'])
        return npv
开发者ID:ssmusoke,项目名称:MBS-Portfolio-Risk-Managament-System,代码行数:12,代码来源:cash_flows_engine.py


示例5: create_company_simulation

def create_company_simulation(simulation_id, stock_id):
    getcontext().prec = 4
    mu = 0.02
    sigma = 0.1
    simulation = Simulation.objects.get(pk=simulation_id)
    stock = Stock.objects.get(pk=stock_id)
    ticker = Ticker.objects.get(simulation=simulation)
    company = TickerCompany(ticker=ticker, stock=stock, symbol=stock.symbol, name="Company %s" % stock.symbol)
    company.save()
    rounds = ticker.nb_rounds + 1
    brownian_motion = geometric_brownian(rounds, mu, sigma, ticker.initial_value, rounds/(ticker.nb_days*rounds), stock_id)
    i = 0
    simulation_dividends = []
    simulation_net_income = []
    for sim_round in range(0, rounds):
        round_dividend = 0
        round_net_income = 0
        for sim_day in range(1, ticker.nb_days+1):
            # We have each round/day and the corresponding dividend
            daily_dividend = brownian_motion[i]
            daily_net_income = brownian_motion[i] / float(ticker.dividend_payoff_rate) * 100 * stock.quantity
            c = CompanyFinancial(company=company, daily_dividend=Decimal(daily_dividend), daily_net_income=Decimal(daily_net_income),
                                 sim_round=sim_round, sim_day=sim_day, sim_date=sim_round*100+sim_day)
            c.save()
            round_dividend += daily_dividend
            round_net_income += daily_net_income
            i += 1
        simulation_dividends.append(round_dividend)
        simulation_net_income.append(round_net_income)

    # Share price estimation
    G = simulation_dividends[-1]/simulation_dividends[-2]-1
    R = 0.15
    g = R
    drift = 0
    simulation_stock_price = []
    previous_company_income = None
    for sim_round in range(0, rounds):
        stock_price = np.npv(0.15, simulation_dividends[sim_round:rounds]) + (simulation_dividends[-1]*(1+g)/(R-G))/np.power(1+R, rounds-sim_round)
        simulation_stock_price.append(stock_price)
        if previous_company_income:
            drift = simulation_net_income[sim_round] / float(previous_company_income.net_income) - 1
            previous_company_income.drift = Decimal(drift)
            previous_company_income.save()
        company_share = CompanyShare(company=company, share_value=Decimal(stock_price), dividends=Decimal(simulation_dividends[sim_round]),
                                     net_income=Decimal(simulation_net_income[sim_round]), drift=Decimal(drift), sim_round=sim_round)
        company_share.save()
        previous_company_income = company_share
        if sim_round == 0:
            stock.price = Decimal(stock_price)
            stock.save()
    return company.id
开发者ID:HEG-Arc,项目名称:marmix,代码行数:52,代码来源:tasks.py


示例6: metrics

def metrics(price, percentDown, closingCosts,repairCosts,rate,term,fedTaxRate,stTaxRate,capitalGains,propTaxRate,insPremiumYr, HOA,hoaIncRate, repairsYr, vacancyPc, propMgmtMo, rent, rentIncRate,appreciationRate, inflation,bldgValPct,sellYear):
    
    years = linspace(0, term, term+1)
    cashflowND = [0]*len(years)
    
    for year in years:
        y = int(year)
        if y <= sellYear:
            payment, downPayment, cashToClose, cashToOperate = loanCalcs(price, percentDown, closingCosts, repairCosts, rate, term)
            equity, mortBal, appVal, interestYr = equityCalcs(y, price, downPayment, payment, rate, appreciationRate)
            capex                               = capexF(y, sellYear, repairsYr, cashToOperate, appVal, price)
            revenue, vacancy                    = revenueF(rent, rentIncRate, vacancyPc, y)
            opexTotal, opexLessDS, deductibles  = opexF(payment, propTaxRate, insPremiumYr, HOA, hoaIncRate, propMgmtMo, price, y, interestYr, vacancy)
            NOI                                 = NOIF(revenue, opexLessDS)
            if y is 1:
                NOI1=NOI
            deductions                          = deductionsF(deductibles, price, bldgValPct)
            taxes                               = taxesF(price, appVal, revenue, deductions, capex, fedTaxRate, stTaxRate, capitalGains, y, sellYear)
            cashflowND[y]                       = cashflowATF(revenue, opexTotal, taxes, capex, equity, y, sellYear)

    capRateYr1 = price/NOI1
    NFV = sum(cashflowND)
    PV10 = npv(.1,cashflowND)
    ROR  = irr(cashflowND)
    cashPayout = payoutCalc(cashflowND, cashToOperate)
    cashOnCashYr1 = cashToOperate/cashflowND[1]
    moCashflowYr1 = cashflowND[1]/12.
    
    metricsDict = {
                   "NFV"             : NFV,
                   "PV10"            : PV10,
                   "ROR"             : ROR, 
                   "capRateYr1"      : capRateYr1,
                   "cashPayout"      : cashPayout,
                   "cashOnCashYr1"   : cashOnCashYr1,
                   "moCashflowYr1"   : moCashflowYr1,
                   "cashToClose"     : cashToClose,
                   "cashToOperate"   : cashToOperate,
                   }
    
#     print "NFV    = $%s" %"{:,}".format(int(NFV))
#     print "PV10   = $%s" %"{:,}".format(int(PV10))
#     print "IRR    = %s" %round(ROR*100,2) + '%'
#     print "Cash payout occurs in year %s" %cashPayout
#     print "Cash on cash return in year 1 = %s" %int(cashOnCashYr1)+'%'
#     print "Monthly cashflow in year 1 = $%s" % int(moCashflowYr1)
    
    #return NFV, PV10, ROR, capRateYr1, cashPayout, cashOnCashYr1, moCashflowYr1, cashToClose, cashToOperate
    return metricsDict
开发者ID:tsh356,项目名称:ubtane_flask_app,代码行数:49,代码来源:realestate.py


示例7: mirr

def mirr(values, finance_rate, reinvest_rate):
    """
    Modified internal rate of return.

    Parameters
    ----------
    values : array_like
        Cash flows (must contain at least one positive and one negative value)
        or nan is returned.
    finance_rate : scalar
        Interest rate paid on the cash flows
    reinvest_rate : scalar
        Interest rate received on the cash flows upon reinvestment

    Returns
    -------
    out : float
        Modified internal rate of return

    """

    values = np.asarray(values)
    initial = values[0]
    values = values[1:]
    n = values.size
    pos = values * (values>0)
    neg = values * (values<0) 
    if not (pos.size > 0 and neg.size > 0):
        return np.nan

    numer = np.abs(np.npv(reinvest_rate, pos))
    denom = np.abs(np.npv(finance_rate, neg))
    if initial>0:
        return ((initial + numer) / denom)**(1.0/n)*(1+reinvest_rate) - 1
    else:
        return ((numer / (-initial + denom)))**(1.0/n)*(1+reinvest_rate) - 1
开发者ID:radovankavicky,项目名称:econpy,代码行数:36,代码来源:finance.py


示例8: eq_subvention

def eq_subvention(montant, duree, taux):
    """ Calcule l' "équivalent subvention" par rapport à un taux 0%
    pour chacune des différentes combinaisons d'hypothèses possibles"""
    # RAZ des résultats
    equivalent_subvention = np.zeros((len(montant), len(duree), len(taux)))
    part_subventionee = np.zeros((len(montant), len(duree), len(taux)))
    # Calcule de l' "équivalent subvention"
    for i in range(len(montant)):
        for j in range(len(duree)):
            # Périodicité des remboursements
            per = np.arange(duree[j]) + 1
            for k in range(len(taux)):
                # Calcule l'échancier des intérêts perçus
                echeancier_interets = -np.ipmt(taux[k], per, duree[j], montant[i])
                # Calcule et enregistre l' "équivalent subvention" comparé
                # à un taux 0 pour le jeu d'hypothèses considéré, les flux
                # d'intérêt étant actualisés à 4%
                equivalent_subvention[i, j, k] = np.npv(0.04, echeancier_interets)
                # ou alternativemen, sans actualiser:
                # equivalent_subvention[i,j,k]=np.sum(echeancier_interets)
                part_subventionee[i, j, k] = (equivalent_subvention[i, j, k] / montant[i]) * 100
    return equivalent_subvention, part_subventionee
开发者ID:milinc,项目名称:ptre,代码行数:22,代码来源:abaque.py


示例9: calc_npv

def calc_npv(r, ubi, inputs, n):
    x = np.zeros((ubi['Years Post Transfer'], n))
    y = np.zeros((ubi['Years Post Transfer'], n))
    
    # iterate through years of benefits
    for j in range(1, ubi['Years Post Transfer'] + 1):
        # sum benefits during program
        if(j < r):
            x[j - 1] += ubi['Expected baseline per capita consumption (nominal USD)']* \
                np.power((1.0 + inputs['UBI']['Expected annual consumption increase (without the UBI program)']), float(j))* \
                inputs['UBI']['Work participation adjustment'] + \
                ubi['Annual quantity of transfer money used for immediate consumtion (pre-discounting)']
        # benefits after program
        else:
            x[j - 1] += ubi['Expected baseline per capita consumption (nominal USD)']* \
                np.power((1.0 + inputs['UBI']['Expected annual consumption increase (without the UBI program)']), float(j))
        
        # investments calculations
        for k in range(n):
            if(j < r + inputs['UBI']['Duration of investment benefits (in years) - UBI'][k]):
                x[j - 1][k] += ubi['Annual return for each year of transfer investments (pre-discounting)'][k]* \
                    np.min([j, inputs['UBI']['Duration of investment benefits (in years) - UBI'][k], \
                    r, (inputs['UBI']['Duration of investment benefits (in years) - UBI'][k] + r - j)])
            
                if(j > r):
                    x[j - 1][k] += ubi['Value eventually returned from one years investment (pre-discounting)'][k]
                    
        # log transform and subtact baseline
        y[j - 1] = np.log(x[j - 1])
        y[j - 1] -= np.log(ubi['Expected baseline per capita consumption (nominal USD)']* \
            np.power((1.0 + inputs['UBI']['Expected annual consumption increase (without the UBI program)']), float(j)))
    
    # npv on yearly data
    z = np.zeros(n)
    for i in range(n):
        z[i] = np.npv(inputs['Shared']['Discount rate'][i], y[:, i])
    return z
开发者ID:danwahl,项目名称:stochastic-ea,代码行数:37,代码来源:gw_test.py


示例10: print

import numpy as np

cashflows = [-45.45, 50]
npv = np.npv(0.1, cashflows)
print(round(50 / (1 + 0.1), 2))
print(round(npv, 2))
开发者ID:AndSemenoff,项目名称:andsemenoff.github.io,代码行数:6,代码来源:numpy_npv.py


示例11: sum

		energySaleChange = sum(energySaleDRyear) - sum(energySaleArray)
		peakDemandRed = PeakDemandCharge - PeakDemandChargeDR
		# Calculating the Purchase Cost, Operation and Maint. Cost and Total Cost
		outData["AnnualOpCost"] = [- AnnDROM for x in lifeYears[0:]]
		LifetimeOperationCost = (sum(outData["AnnualOpCost"]))
		outData["LifetimeOperationCost"] = abs(LifetimeOperationCost)
		outData["lifePurchaseCosts"] = [-1.0 * DrTechCost] + [0 for x in lifeYears[1:]]
		outData["TotalCost"] = abs(outData["LifetimeOperationCost"] + DrTechCost)
		# Outputs of the Program Lifetime Cash Flow figure
		outData["EnergySaleChangeBenefit"] = [energySaleChange * ScalingAnnual ** x for x in range(lifeSpan)]
		outData["PeakDemandReduction"] = [peakDemandRed * ScalingAnnual ** x for x in range(lifeSpan)]
		BenefitCurve = [x+y for x,y in zip(outData["EnergySaleChangeBenefit"], outData["PeakDemandReduction"])]
		outData["TotalBenefit"] = sum(BenefitCurve)
		outData["BenefittoCostRatio"] = float(outData["TotalBenefit"] / outData["TotalCost"])
		netBenefit = [x+y+z for x,y,z in zip(outData["AnnualOpCost"],outData["lifePurchaseCosts"],BenefitCurve)]
		outData["npv"] = npv(DiscountRate, netBenefit)
		outData["cumulativeNetBenefit"] = [sum(netBenefit[0:i+1]) for i,d in enumerate(netBenefit)]
		outData["SimplePaybackPeriod"] = DrTechCost / (outData["TotalBenefit"] / lifeSpan)
		# Stdout/stderr.
		outData["stdout"] = "Success"
		outData["stderr"] = ""
		# Write the output.
		with open(pJoin(modelDir,"allOutputData.json"),"w") as outFile:
			json.dump(outData, outFile, indent=4)
		# Update the runTime in the input file.
		endTime = datetime.datetime.now()
		inputDict["runTime"] = str(datetime.timedelta(seconds=int((endTime - startTime).total_seconds())))
		with open(pJoin(modelDir,"allInputData.json"),"w") as inFile:
			json.dump(inputDict, inFile, indent=4)
	except:
		# If input range wasn't valid delete output, write error to disk.
开发者ID:Zargontapel,项目名称:omf,代码行数:31,代码来源:demandResponse.py


示例12: value_can_afford

 def value_can_afford(monthly_payment):
     # this is a 10 year average freddie mac interest rate
     ten_year_average_interest = .055
     return np.npv(ten_year_average_interest/12, [monthly_payment]*30*12)
开发者ID:bobbylu,项目名称:bayarea_urbansim-1,代码行数:4,代码来源:subsidies.py


示例13: work

def work(modelDir, inputDict):
	''' Run the model in its directory.'''
	if inputDict['dispatch_type'] == 'prediction':
		return workForecast(modelDir, inputDict)

	out = {}
	try:
		with open(pJoin(modelDir, 'demand.csv'), 'w') as f:
			f.write(inputDict['demandCurve'].replace('\r', ''))
		with open(pJoin(modelDir, 'demand.csv')) as f:
			demand = [float(r[0]) for r in csv.reader(f)]
	 		assert len(demand) == 8760	
		
		with open(pJoin(modelDir, 'temp.csv'), 'w') as f:
			lines = inputDict['tempCurve'].split('\n')
			out["tempData"] = [float(x) if x != '999.0' else float(inputDict['setpoint']) for x in lines[:-1]]
			correctData = [x+'\n' if x != '999.0' else inputDict['setpoint']+'\n' for x in lines][:-1]
			f.write(''.join(correctData))
			assert len(correctData) == 8760
	except:
		raise Exception("CSV file is incorrect format. Please see valid format "
			"definition at <a target='_blank' href = 'https://github.com/dpinney/"
			"omf/wiki/Models-~-storagePeakShave#demand-file-csv-format'>\nOMF Wiki "
			"storagePeakShave - Demand File CSV Format</a>")
	
	# # created using calendar = {'1': 31, '2': 28, ..., '12': 31}
	# m = [calendar[key]*24 for key in calendar]
	# monthHours = [(sum(m[:i]), sum(m[:i+1])) for i, _ in enumerate(m)]
	monthHours = [(0, 744), (744, 1416), (1416, 2160), (2160, 2880), 
					(2880, 3624), (3624, 4344), (4344, 5088), (5088, 5832), 
					(5832, 6552), (6552, 7296), (7296, 8016), (8016, 8760)]

	P_lower, P_upper, E_UL = pyVbat(modelDir, inputDict)
	P_lower, P_upper, E_UL = list(P_lower), list(P_upper), list(E_UL)

	out["minPowerSeries"] = [-1*x for x in P_lower]
	out["maxPowerSeries"] = P_upper
	out["minEnergySeries"] = [-1*x for x in E_UL]
	out["maxEnergySeries"] = E_UL
	
	VBpower, out["VBenergy"] = pulpFunc(inputDict, demand, P_lower, P_upper, E_UL, monthHours)
	out["VBpower"] = VBpower
	out["dispatch_number"] = [len([p for p in VBpower[s:f] if p != 0]) for (s, f) in monthHours]

	peakDemand = [max(demand[s:f]) for s, f in monthHours] 
	energyMonthly = [sum(demand[s:f]) for s, f in monthHours]
	demandAdj = [d+p for d, p in zip(demand, out["VBpower"])]
	peakAdjustedDemand = [max(demandAdj[s:f]) for s, f in monthHours]
	energyAdjustedMonthly = [sum(demandAdj[s:f]) for s, f in monthHours]

	rms = all([x == 0 for x in P_lower]) and all([x == 0 for x in P_upper])
	out["dataCheck"] = 'VBAT returns no values for your inputs' if rms else ''
	out["demand"] = demand
	out["peakDemand"] = peakDemand
	out["energyMonthly"] = energyMonthly
	out["demandAdjusted"] = demandAdj
	out["peakAdjustedDemand"] = peakAdjustedDemand
	out["energyAdjustedMonthly"] = energyAdjustedMonthly
	
	cellCost = float(inputDict["unitDeviceCost"])*float(inputDict["number_devices"])
	eCost = float(inputDict["electricityCost"])
	dCharge = float(inputDict["demandChargeCost"])

	out["VBdispatch"] = [dal-d for dal, d in zip(demandAdj, demand)]
	out["energyCost"] = [em*eCost for em in energyMonthly]
	out["energyCostAdjusted"] = [eam*eCost for eam in energyAdjustedMonthly]
	out["demandCharge"] = [peak*dCharge for peak in peakDemand]
	out["demandChargeAdjusted"] = [pad*dCharge for pad in out["peakAdjustedDemand"]]
	out["totalCost"] = [ec+dcm for ec, dcm in zip(out["energyCost"], out["demandCharge"])]
	out["totalCostAdjusted"] = [eca+dca for eca, dca in zip(out["energyCostAdjusted"], out["demandChargeAdjusted"])]
	out["savings"] = [tot-tota for tot, tota in zip(out["totalCost"], out["totalCostAdjusted"])]

	annualEarnings = sum(out["savings"]) - float(inputDict["unitUpkeepCost"])*float(inputDict["number_devices"])
	cashFlowList = [annualEarnings] * int(inputDict["projectionLength"])
	cashFlowList.insert(0, -1*cellCost)

	out["NPV"] = npv(float(inputDict["discountRate"])/100, cashFlowList)
	out["SPP"] = cellCost / annualEarnings
	out["netCashflow"] = cashFlowList
	out["cumulativeCashflow"] = [sum(cashFlowList[:i+1]) for i, d in enumerate(cashFlowList)]

	out["stdout"] = "Success"
	return out
开发者ID:dpinney,项目名称:omf,代码行数:83,代码来源:f_vbatDispatch.py


示例14: workForecast


#.........这里部分代码省略.........
	dailyPl = [P_lower[i:i+24] for i in range(0, len(P_lower), 24)]
	dailyPu = [P_upper[i:i+24] for i in range(0, len(P_upper), 24)]
	dailyEu = [E_UL[i:i+24] for i in range(0, len(E_UL), 24)]
	
	vbp, vbe = [], []
	dispatched_d = [False]*365
	# Decide what days to dispatch
	zipped = zip(dailyLoadPredictions, df['month'][-8760:], dailyPl, dailyPu, dailyEu)
	for i, (load, m, pl, pu, eu) in enumerate(zipped):
		peak = max(load)
		if fc.shouldDispatchPS(peak, m, df, float(ind['confidence'])/100):
			dispatched_d[i] = True
			p, e = fc.pulp24hrVbat(ind, load, pl, pu, eu)
			vbp.extend(p)
			vbe.extend(e)
		else:
			vbp.extend([0]*24)
			vbe.extend([0]*24)

	### TESTING FOR ACCURACY ###
	assert len(dailyPl) == 365
	assert all([len(i) == 24 for i in dailyPl])

	VB_power, VB_energy = vbp, vbe

	# -------------------- MODEL ACCURACY ANALYSIS -------------------------- #

	o['predictedLoad'] = list(clf.predict(X_test))
	o['trainAccuracy'] = round(clf.score(X_train, y_train) * 100, 2)
	o['testAccuracy'] = round(clf.score(X_test, y_test) * 100, 2)

	# PRECISION AND RECALL
	maxDays = []
	for month in range(1, 13):
		test = df[df['month'] == month]
		maxDays.append(test.loc[test['load'].idxmax()]['dayOfYear'])
	
	shouldHaveDispatched = [False]*365
	for day in maxDays:
		shouldHaveDispatched[day] = True

	truePositive = len([b for b in [i and j for (i, j) in zip(dispatched_d, shouldHaveDispatched)] if b])
	falsePositive = len([b for b in [i and (not j) for (i, j) in zip(dispatched_d, shouldHaveDispatched)] if b])
	falseNegative = len([b for b in [(not i) and j for (i, j) in zip(dispatched_d, shouldHaveDispatched)] if b])
	o['confidence'] = ind['confidence']
	o['precision'] = round(truePositive / float(truePositive + falsePositive) * 100, 2)
	o['recall'] = round(truePositive / float(truePositive + falseNegative) * 100, 2)
	o['number_of_dispatches'] = len([i for i in dispatched_d if i])
	o['MAE'] = round(sum([abs(l-m)/m*100 for l, m in zip(predictions, list(y_test))])/8760., 2)

	# ---------------------- FINANCIAL ANALYSIS ----------------------------- #

	o['VBpower'], o['VBenergy'] = list(VB_power), list(VB_energy)

	# Calculate monthHours
	year = df[-8760:].copy()
	year.reset_index(inplace=True)
	year['hour'] = list(year.index)
	start = list(year.groupby('month').first()['hour'])
	finish = list(year.groupby('month').last()['hour'])
	monthHours = [(s, f+1) for (s, f) in zip(start, finish)]

	demand = list(y_test)
	peakDemand = [max(demand[s:f]) for s, f in monthHours] 
	energyMonthly = [sum(demand[s:f]) for s, f in monthHours]
	demandAdj = [d+p for d, p in zip(demand, o['VBpower'])]
	peakAdjustedDemand = [max(demandAdj[s:f]) for s, f in monthHours]
	energyAdjustedMonthly = [sum(demandAdj[s:f]) for s, f in monthHours]

	o['demand'] = demand
	o['peakDemand'] = peakDemand
	o['energyMonthly'] = energyMonthly
	o['demandAdjusted'] = demandAdj
	o['peakAdjustedDemand'] = peakAdjustedDemand
	o['energyAdjustedMonthly'] = energyAdjustedMonthly
	
	cellCost = float(ind['unitDeviceCost'])*float(ind['number_devices'])
	eCost = float(ind['electricityCost'])
	dCharge = float(ind['demandChargeCost'])

	o['VBdispatch'] = [dal-d for dal, d in zip(demandAdj, demand)]
	o['energyCost'] = [em*eCost for em in energyMonthly]
	o['energyCostAdjusted'] = [eam*eCost for eam in energyAdjustedMonthly]
	o['demandCharge'] = [peak*dCharge for peak in peakDemand]
	o['demandChargeAdjusted'] = [pad*dCharge for pad in o['peakAdjustedDemand']]
	o['totalCost'] = [ec+dcm for ec, dcm in zip(o['energyCost'], o['demandCharge'])]
	o['totalCostAdjusted'] = [eca+dca for eca, dca in zip(o['energyCostAdjusted'], o['demandChargeAdjusted'])]
	o['savings'] = [tot-tota for tot, tota in zip(o['totalCost'], o['totalCostAdjusted'])]

	annualEarnings = sum(o['savings']) - float(ind['unitUpkeepCost'])*float(ind['number_devices'])
	cashFlowList = [annualEarnings] * int(ind['projectionLength'])
	cashFlowList.insert(0, -1*cellCost)

	o['NPV'] = np.npv(float(ind['discountRate'])/100, cashFlowList)
	o['SPP'] = cellCost / annualEarnings
	o['netCashflow'] = cashFlowList
	o['cumulativeCashflow'] = [sum(cashFlowList[:i+1]) for i, d in enumerate(cashFlowList)]
	
	o['stdout'] = 'Success'
	return o
开发者ID:dpinney,项目名称:omf,代码行数:101,代码来源:f_vbatDispatch.py


示例15: taxEquityFlip


#.........这里部分代码省略.........
            for i in range(1, len(SPERevenueTE) + 1):
                SPEMgmtFeeTE.append(-managementFee *
                                    math.pow((1 + .01), (i - 1)))
                EBITDATE.append(float(SPERevenueTE[
                                i - 1]) + float(OMTE[i - 1]) + float(insuranceTE[i - 1]) + float(SPEMgmtFeeTE[i - 1]))
                if (i <= 6):
                    cashFromSPEToBlockerTE.append(float(EBITDATE[i - 1]) * .01)
                else:
                    cashFromSPEToBlockerTE.append(0)
                    EBITDATEREDUCED.append(EBITDATE[i - 1])

            # Output Tax Equity Flip [I]
            # TEI Calcs [Y21]
            cashRevenueTE = -totalCost * (1 - 0.53)
            buyoutAmountTE = 0
            for i in range(1, len(EBITDATEREDUCED) + 1):
                buyoutAmountTE = buyoutAmountTE + \
                    EBITDATEREDUCED[i - 1] / (math.pow(1 + 0.12, i))
            buyoutAmountTE = buyoutAmountTE * 0.05
            cashFromBlockerTE = - (buyoutAmountTE) + 0.0725 * cashRevenueTE

            # Output Tax Equity Flip [K] [L]
            for i in range(1, len(allYearGenerationMWh) + 1):
                if (i == 6):
                    netCoopPaymentsTaxEquity.append(financeCostCashTaxEquity + cashToSPEOForPPATE[
                                                    i - 1] + cashFromSPEToBlockerTE[i - 1] + OMInsuranceETCTE[i - 1] + cashFromBlockerTE)
                else:
                    netCoopPaymentsTaxEquity.append(financeCostCashTaxEquity + cashFromSPEToBlockerTE[
                                                    i - 1] + cashToSPEOForPPATE[i - 1] + OMInsuranceETCTE[i - 1])
                costToCustomerTaxEquity.append(
                    netCoopPaymentsTaxEquity[i - 1] - distAdderTaxEquity[i - 1])

            # Output Tax Equity Flip [L37]
            NPVLoanTaxEquity = npv(
                float(inputDict.get("discRate", 0)) / 100, [0, 0] + costToCustomerTaxEquity)

            # Output - Tax Equity [F42]
            Rate_Levelized_TaxEquity = - \
                NPVLoanTaxEquity / NPVallYearGenerationMWh

            # TEI Calcs - Achieved Return [AW 21]
            #[AK]
            MACRDepreciation = []
            MACRDepreciation.append(-0.99 * 0.2 *
                                    (totalCost - totalCost * 0.5 * 0.9822 * 0.3))
            MACRDepreciation.append(-0.99 * 0.32 *
                                    (totalCost - totalCost * 0.5 * 0.9822 * 0.3))
            MACRDepreciation.append(-0.99 * 0.192 *
                                    (totalCost - totalCost * 0.5 * 0.9822 * 0.3))
            MACRDepreciation.append(-0.99 * 0.1152 *
                                    (totalCost - totalCost * 0.5 * 0.9822 * 0.3))
            MACRDepreciation.append(-0.99 * 0.1152 *
                                    (totalCost - totalCost * 0.5 * 0.9822 * 0.3))
            MACRDepreciation.append(-0.99 * 0.0576 *
                                    (totalCost - totalCost * 0.5 * 0.9822 * 0.3))
            #[AI] [AL]	[AN]
            cashRevenueTEI = []  # [AI]
            slDepreciation = []  # [AL]
            totalDistributions = []  # [AN]
            cashRevenueTEI.append(-totalCost * 0.53)
            for i in range(1, 7):
                cashRevenueTEI.append(EBITDATE[i - 1] * 0.99)
                slDepreciation.append(totalCost / 25)
                totalDistributions.append(-cashRevenueTEI[i])
            #[AJ]
            ITC = totalCost * 0.9822 * 0.3 * 0.99
开发者ID:geomf,项目名称:omf-fork,代码行数:67,代码来源:solarSunda.py


示例16: heavyProcessing

def heavyProcessing(modelDir, inputDict):
	''' Run the model in a separate process. web.py calls this to run the model.
	This function will return fast, but results take a while to hit the file system.'''
	# Delete output file every run if it exists
	try:
		# Ready to run.
		startTime = datetime.datetime.now()
		outData = {}
		# Get variables.
		cellCapacity = float(inputDict['cellCapacity'])
		(cellCapacity, dischargeRate, chargeRate, cellQuantity, demandCharge, cellCost) = \
			[float(inputDict[x]) for x in ('cellCapacity', 'dischargeRate', 'chargeRate', 'cellQuantity', 'demandCharge', 'cellCost')]
		battEff	= float(inputDict.get("batteryEfficiency", 92)) / 100.0 * float(inputDict.get("inverterEfficiency", 92)) / 100.0 * float(inputDict.get("inverterEfficiency", 92)) / 100.0
		discountRate = float(inputDict.get('discountRate', 2.5)) / 100.0
		retailCost = float(inputDict.get('retailCost', 0.07))
		dodFactor = float(inputDict.get('dodFactor', 85)) / 100.0
		projYears = int(inputDict.get('projYears',10))
		# Put demand data in to a file for safe keeping.
		with open(pJoin(modelDir,"demand.csv"),"w") as demandFile:
			demandFile.write(inputDict['demandCurve'])
		# Start running battery simulation.
		battCapacity = cellQuantity * cellCapacity * dodFactor
		battDischarge = cellQuantity * dischargeRate
		battCharge = cellQuantity * chargeRate
		# Most of our data goes inside the dc "table"
		try:
			dc = []
			with open(pJoin(modelDir,"demand.csv")) as inFile:
				reader = csv.DictReader(inFile)
				for row in reader:
					dc.append({'datetime': parse(row['timestamp']), 'power': float(row['power'])})
				if len(dc)<8760: raise Exception
		except:
			errorMessage = "CSV file is incorrect format. Please see valid format definition at\n <a target='_blank' href = 'https://github.com/dpinney/omf/wiki/Models-~-energyStorage#demand-file-csv-format'>OMF Wiki energyStorage</a>"
			raise Exception(errorMessage)
		for row in dc:
			row['month'] = row['datetime'].month-1
			row['weekday'] = row['datetime'].weekday
		outData['startDate'] = dc[0]['datetime'].isoformat()
		ps = [battDischarge for x in range(12)]
		dcGroupByMonth = [[t['power'] for t in dc if t['datetime'].month-1==x] for x in range(12)]
		monthlyPeakDemand = [max(dcGroupByMonth[x]) for x in range(12)]
		capacityLimited = True
		while capacityLimited:
			battSoC = battCapacity # Battery state of charge; begins full.
			battDoD = [battCapacity for x in range(12)]  # Depth-of-discharge every month, depends on dodFactor.
			for row in dc:
				month = int(row['datetime'].month)-1
				powerUnderPeak  = monthlyPeakDemand[month] - row['power'] - ps[month]
				isCharging = powerUnderPeak > 0
				isDischarging = powerUnderPeak <= 0
				charge = isCharging * min(
					powerUnderPeak * battEff, # Charge rate <= new monthly peak - row['power']
					battCharge, # Charge rate <= battery maximum charging rate.
					battCapacity - battSoC) # Charge rage <= capacity remaining in battery.
				discharge = isDischarging * min(
					abs(powerUnderPeak), # Discharge rate <= new monthly peak - row['power']
					abs(battDischarge), # Discharge rate <= battery maximum charging rate.
					abs(battSoC+.001)) # Discharge rate <= capacity remaining in battery.
				# (Dis)charge battery
				battSoC += charge
				battSoC -= discharge
				# Update minimum state-of-charge for this month.
				battDoD[month] = min(battSoC,battDoD[month])
				row['netpower'] = row['power'] + charge/battEff - discharge
				row['battSoC'] = battSoC
			capacityLimited = min(battDoD) < 0
			ps = [ps[month]-(battDoD[month] < 0) for month in range(12)]
		dcThroughTheMonth = [[t for t in iter(dc) if t['datetime'].month-1<=x] for x in range(12)]
		hoursThroughTheMonth = [len(dcThroughTheMonth[month]) for month in range(12)]
		peakShaveSum = sum(ps)
		outData['SPP'] = (cellCost*cellQuantity)/(peakShaveSum*demandCharge)
		cashFlowCurve = [peakShaveSum * demandCharge for year in range(projYears)]
		cashFlowCurve[0]-= (cellCost * cellQuantity)
		outData['netCashflow'] = cashFlowCurve
		outData['cumulativeCashflow'] = [sum(cashFlowCurve[0:i+1]) for i,d in enumerate(cashFlowCurve)]
		outData['NPV'] = npv(discountRate, cashFlowCurve)
		outData['demand'] = [t['power']*1000.0 for t in dc]
		outData['demandAfterBattery'] = [t['netpower']*1000.0 for t in dc]
		outData['batterySoc'] = [t['battSoC']/battCapacity*100.0*dodFactor + (100-100*dodFactor) for t in dc]
		# Estimate number of cyles the battery went through.
		SoC = outData['batterySoc']
		outData['cycleEquivalents'] = sum([SoC[i]-SoC[i+1] for i,x in enumerate(SoC[0:-1]) if SoC[i+1] < SoC[i]]) / 100.0
		# # Output some matplotlib results as well.
		# plt.plot([t['power'] for t in dc])
		# plt.plot([t['netpower'] for t in dc])
		# plt.plot([t['battSoC'] for t in dc])
		# for month in range(12):
		#   plt.axvline(hoursThroughTheMonth[month])
		# plt.savefig(pJoin(modelDir,"plot.png"))
		# Summary of results
		outData['months'] = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]
		totMonNum = []
		monthlyDemand = []
		for x in range (0, len(dcGroupByMonth)):
			totMonNum.append(sum(dcGroupByMonth[x])/1000)
			monthlyDemand.append([outData['months'][x], totMonNum[x]])
		outData['monthlyDemand'] = totMonNum
		outData['ps'] = ps
		outData['monthlyDemandRed'] = [totMonNum - ps for totMonNum, ps in zip(totMonNum, ps)]
#.........这里部分代码省略.........
开发者ID:mannanj,项目名称:omf,代码行数:101,代码来源:energyStorage.py


示例17: work


#.........这里部分代码省略.........
		# keep shrinking peak shave (ps) until every month doesn't fully expend the battery
		while True:
			SoC = battCapacity
			incorrect_shave = [False] * 12
			for row in dc:
				month = row['month']
				if not incorrect_shave[month]:
					powerUnderPeak = monthlyPeakDemand[month] - row['power'] - ps[month]
					charge = (min(powerUnderPeak, battCharge, battCapacity - SoC) if powerUnderPeak > 0
						else -1 * min(abs(powerUnderPeak), battDischarge, SoC))
					if charge == -1 * SoC:
						incorrect_shave[month] = True
					SoC += charge
					row['netpower'] = row['power'] + charge
					row['battSoC'] = SoC
			ps = [s-1 if incorrect else s for s, incorrect in zip(ps, incorrect_shave)]
			if not any(incorrect_shave):
				break
	elif dispatchStrategy == 'daily':
		start = int(inputDict.get('startPeakHour'))
		end = int(inputDict.get('endPeakHour'))
		for r in dc:
			# Discharge if hour is within peak hours otherwise charge
			charge = (-1*min(battDischarge, SoC) if start <= r['hour'] <= end 
				else min(battCharge, battCapacity - SoC))
			r['netpower'] = r['power'] + charge
			SoC += charge
			r['battSoC'] = SoC
	elif dispatchStrategy == 'customDispatch':
		try:
			with open(pJoin(modelDir,'dispatchStrategy.csv')) as f:
				reader = csv.reader(f)
				for d, r in zip(dc, reader):
					d['dispatch'] = int(r[0])
				assert all(['dispatch' in r for r in dc])  # ensure each row is filled
		except:
			if str(sys.exc_info()[0]) != "<type 'exceptions.SystemExit'>":
				raise Exception("Dispatch Strategy file is in an incorrect " 
					"format. Please see valid format definition at <a target "
					"= '_blank' href = 'https://github.com/dpinney/omf/wiki/"
					"Models-~-storagePeakShave#custom-dispatch-strategy-file-"
					"csv-format'>\nOMF Wiki storagePeakShave - Custom "
					"Dispatch Strategy File Format</a>")
		for r in dc:
			# Discharge if there is a 1 in the dispatch strategy csv, otherwise charge the battery.
			charge = (-1*min(battDischarge, SoC) if r['dispatch'] == 1 
				else min(battCharge, battCapacity-SoC))
			r['netpower'] = r['power'] + charge
			SoC += charge
			r['battSoC'] = SoC

	# ------------------------- CALCULATIONS ------------------------- #
	netByMonth = [[t['netpower'] for t in dc if t['month']==x] for x in range(12)]
	monthlyPeakNet = [max(net) for net in netByMonth]
	ps = [h-s for h, s in zip(monthlyPeakDemand, monthlyPeakNet)]
	dischargeByMonth = [[i-j for i, j in zip(k, l) if i-j < 0] for k, l in zip(netByMonth, demandByMonth)]

	# Monthly Cost Comparison Table
	out['monthlyDemand'] = [sum(lDemand)/1000 for lDemand in demandByMonth]
	out['monthlyDemandRed'] = [t-p for t, p in zip(out['monthlyDemand'], ps)]
	out['ps'] = ps
	out['benefitMonthly'] = [x*demandCharge for x in ps]
	
	# Demand Before and After Storage Graph
	out['demand'] = [t['power']*1000.0 for t in dc] # kW -> W
	out['demandAfterBattery'] = [t['netpower']*1000.0 for t in dc] # kW -> W
	out['batteryDischargekW'] = [d-b for d, b in zip(out['demand'], out['demandAfterBattery'])]
	out['batteryDischargekWMax'] = max(out['batteryDischargekW'])

	# Battery State of Charge Graph
	# Turn dc's SoC into a percentage, with dodFactor considered.
	out['batterySoc'] = SoC = [t['battSoC']/battCapacity*100*dodFactor + (100-100*dodFactor) for t in dc]
	# Estimate number of cyles the battery went through. Sums the percent of SoC.
	cycleEquivalents = sum([SoC[i]-SoC[i+1] for i, x in enumerate(SoC[:-1]) if SoC[i+1] < SoC[i]]) / 100.0
	out['cycleEquivalents'] = cycleEquivalents
	out['batteryLife'] = batteryCycleLife / cycleEquivalents

	# Cash Flow Graph
	# inserting battery efficiency only into the cashflow calculation
	# cashFlowCurve is $ in from peak shaving minus the cost to recharge the battery every day of the year
	cashFlowCurve = [sum(ps)*demandCharge for year in range(projYears)]
	cashFlowCurve.insert(0, -1 * cellCost * cellQuantity)  # insert initial investment
	# simplePayback is also affected by the cost to recharge the battery every day of the year
	out['SPP'] = (cellCost*cellQuantity)/(sum(ps)*demandCharge)
	out['netCashflow'] = cashFlowCurve
	out['cumulativeCashflow'] = [sum(cashFlowCurve[:i+1]) for i, d in enumerate(cashFlowCurve)]
	out['NPV'] = npv(discountRate, cashFlowCurve)

	battCostPerCycle = cellQuantity * cellCost / batteryCycleLife
	lcoeTotCost = cycleEquivalents*retailCost + battCostPerCycle*cycleEquivalents
	out['LCOE'] = lcoeTotCost / (cycleEquivalents*battCapacity)

	# Other
	out['startDate'] = '2011-01-01'  # dc[0]['datetime'].isoformat()
	out['stderr'] = ''
	# Seemingly unimportant. Ask permission to delete.
	out['stdout'] = 'Success' 
	out['months'] = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]

	return out
开发者ID:dpinney,项目名称:omf,代码行数:101,代码来源:nn_storagePeakShave.py


示例18: work

该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python numpy.nsum函数代码示例发布时间:2022-05-27
下一篇:
Python numpy.nper函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap