Create for loop to calculate irr

I am currently trying to calculate the IRR for a set number of NNV values.
I have created a formula for calculating the NNV, which is:
syms n
NNV=round(-ko+symsum(tot_profit./((1+r)^n),n,1,30))
-Where r is the rate
-n goes between 1 and 30
-tot_profit is a matrix of 20 different profits
I was thinking about creating a for loop that can go through all the different values and find the IRR (which is the rate at which NNV=0), but i don't know how to set this up. Does anyone know of a good way to solve this?

回答 (1 件)

Torsten
Torsten 2023 年 4 月 28 日
編集済み: Torsten 2023 年 4 月 28 日

0 投票

syms r n N
symsum(1/(1+r)^n,n,1,N)
ans = 
ko = 100;
tot_profit = 7;
n = 30;
fun = @(r) -ko + tot_profit* ((r+1)^n-1)/(r*(r+1)^n);
r = fzero(fun,[0.01 0.2])
r = 0.0566

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

製品

タグ

質問済み:

2023 年 4 月 28 日

編集済み:

2023 年 4 月 28 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by