Функция InternalRateOfReturn из библиотеки System.Math работает неверно ( это известный баг delphi ). Как её реализовать самому?

Рейтинг: 0Ответов: 0Опубликовано: 11.07.2023

В excel есть функция ВСД это аналог функции питона irr из библиотеки numpy_financial

Привожу код питона ( потому что он выдаёт верный результат )

import numpy_financial as nf
cashFlows = [ -2000000 ]
for ii in range( 0, 23 ):
  cashFlows.append( 92187.5 )
cashFlows.append( 102187.5 ) # cashFlows = [ -2000000, 92187.5 ( 23 раза ), 102187.5 ]
print( nf.irr( cashFlows ) ) # 0.008581066391343706 ( это верно и совпадает с excel )

Пытаюсь то же самое реализовать на delphi

unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Math;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  aa: single;
  IRate: Extended;
  CashFlow: array of Double;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  aa := 5;
  aa := power( 25, 0.5 );

  SetLength( CashFlow, 25 );
  CashFlow[0] := -2000000;
  CashFlow[1] := 92187.5;
  CashFlow[2] := 92187.5;
  CashFlow[3] := 92187.5;
  CashFlow[4] := 92187.5;
  CashFlow[5] := 92187.5;
  CashFlow[6] := 92187.5;
  CashFlow[7] := 92187.5;
  CashFlow[8] := 92187.5;
  CashFlow[9] := 92187.5;
  CashFlow[10] := 92187.5;
  CashFlow[12] := 92187.5;
  CashFlow[13] := 92187.5;
  CashFlow[14] := 92187.5;
  CashFlow[15] := 92187.5;
  CashFlow[16] := 92187.5;
  CashFlow[17] := 92187.5;
  CashFlow[18] := 92187.5;
  CashFlow[19] := 92187.5;
  CashFlow[20] := 92187.5;
  CashFlow[21] := 92187.5;
  CashFlow[22] := 92187.5;
  CashFlow[23] := 92187.5;
  CashFlow[24] := 102187.5;

  IRate:= InternalRateOfReturn( 0, CashFlow);
  { IRate равно 0,00506580404381233 и это неправильно }


  aa := aa + 1;

end;

end.

Самому её реализовать сложно, требуется хорошо и глубоко знать математику. Кто уже с таким сталкивался и может помочь ?

Находил в интернете сообщения, что в делфи эта функция работает неверно

I have found that the InternalRateOfReturn function in the math.pas
library does not work and that it was reported as a bug some months ago.

Ответы

Ответов пока нет.