見出し画像

負債

トレステ内にある実績データと計算だけで表示するインジケータです
外部のCSVデータなどは使用しないのでメンテ不要です
計算で求める部分が四季報や決算短信等の数字とは若干違うので
ざっくりで良い人向けです
財務のインジケータが近いのでそれを改造します

良い企業を探すには当然売上げや利益を増やしているので売上・利益部分を
見ると思いますが、負債からも探れないかと思い作ってみました
より売上や利益を伸ばすには、設備投資や人材確保等で一時的に負債が増える事もあるかもしれない、ただ単に資金繰りが悪くて負債が増えているのかもしれない、業績好調で負債を減らしているかもしれない等
今まで負債に注目して企業を探った事がなかったので取り敢えず見てみない事にはわかりませんw
良い企業が売上げ伸ばす屈伸のような前段階で見つけられるのか、潰れそうな企業を失速前にいち早く気付けるのか、探ってみたい(・∀・)

使用するトレステにある実績データ

・総資産 = CR_Total_Asset
・株主資本 = CR_Net_Asset
・自己資産比率% = CR_Capital_Ratio
・債務資産比率% = CR_DEBT_EQUITY_Ratio(有利子負債比率D/Eレシオ)
・営業キャッシュフロー = CR_OPCF

計算で求めるもの

有利子負債比率(D/Eレシオ)= 有利子負債(他人資本)÷ 自己資本なので
・有利子負債残高(百万) = 債務資産比率 ÷ 100 × 純資産 ÷ 1000000
 で有利子負債残高を求め、それを使って以下を求める
・有利子負債依存度% = 有利子負債残高 ÷ 総資産 × 100
・債務償還年数 = 有利子負債残高 ÷ 営業キャッシュフロー
※ 自己資本比率と債務資産比率は
  %としての数字がデータに入っているので計算時注意が必要
※ 広い意味で純資産、自己資本、株主資本は同義

プログラム

using tsdata.marketdata;
using elsystem;
inputs:
	int MonthsReported( 12 ) [DisplayName = "期間", ToolTip = "Enter the number of months in the reporting period for which data is desired.  Fundamental data usually covers a 3, 6 or 12 month period."],
	int ConsolidationLevel( 1 ) [DisplayName = "連結/単独", ToolTip = "Enter 1 if consolidated data is desired; enter any other value for non-consolidated data."],
	int AccountingStandard( 0 ) [DisplayName = "会計基準", ToolTip =  "Enter 1 for Japanese accounting standard; enter 2 for Securities and Exchange Commission (SEC) accounting standard; enter 3 for International Financial Reporting Standards (IFRS) accounting standard; enter 0 to use IFRS, SEC, or Japanese accounting standards, in that order, depending on which is available."];
variables:
	FundamentalQuotesProvider FQP( null ),
	intrabarpersist bool OkayToPlotTotalAssets( false ),		//総資産
	intrabarpersist bool OkayToPlotNetAssets( false ),			//株主資本
	intrabarpersist bool OkayToPlotRatio( false ),				//自己資産比率
	intrabarpersist bool OkayToPlotDERatio( false ),			//債務資産比率
	intrabarpersist bool OkayToPlotOpCF( false ),				//営業CF
	intrabarpersist string ConsLevel( "Consolidated" ),
	intrabarpersist string AcctStdInputString( "" ),
	double CRTotalAssets( 0 ),									//総資産
	double CRNetAssets( 0 ),									//株主資本
	double CRCapitalRatio( 0 ),									//自己資産比率
	double CRDERatio( 0 ),										//債務資産比率
	double CROpCF( 0 );											//営業CF;
constants:
	string MonthsReportedKey( "MonthsReported" ),				//期間
	string ConsolidatedKey( "ConsolidationLevel" ),				//連結/単独
	string AccountingKey( "AccountingStandard" ),				//会計基準
	string TotalAssetsFieldName( "CR_Total_Asset" ),			//総資産
	string NetAssetsFieldName( "CR_Net_Asset" ),				//株主資本
	string RatioFieldName( "CR_Capital_Ratio" ),				//自己資産比率
	string DERatioFieldName( "CR_DEBT_EQUITY_Ratio" ),			//債務資産比率
	string OpCFFieldName( "CR_OpCF" ),							//営業CF
	string ConsolidatedValue( "Consolidated" ),					//連結
	string NonConsolidatedValue( "NonConsolidated" ),			//単独
	string IFRSString( "IFRS" ),
	string SECString( "SEC" ),
	string JSTDString( "JSTD" );
	
method void CreateFundamentalQuotesProvider()
begin
	FQP = new FundamentalQuotesProvider();
	FQP.Symbol = Symbol;
	FQP.Fields += TotalAssetsFieldName;							//総資産
	FQP.Fields += NetAssetsFieldName;							//株主資本
	FQP.Fields += RatioFieldName;								//自己資産比率
	FQP.Fields += DERatioFieldName;								//債務資産比率
	FQP.Fields += OpCFFieldName;								//営業CF
	FQP.Realtime = false;
	FQP.TimeZone = tsdata.common.TimeZone.local;
	FQP.LoadProvider();
	Value99 = FQP.Count; { force provider to load }
end;
method bool DataHasPostDate( FundamentalQuote fq )
variables:  int Counter, DateTime MissingDT, int NumMissingDates;
begin
	NumMissingDates = 0;	
	MissingDT = DateTime.Create( 1999, 11, 30 );
	for Counter = 0 to fq.Count - 1 begin
		if fq.PostDate[Counter] = MissingDT then
			NumMissingDates += 1;
	end;
	return NumMissingDates <> fq.Count;
end;
method string GetAcctStdString()
variables:  string AcctStdString;
begin
	switch ( AccountingStandard )
	begin
		case 1: { JSTD }
			AcctStdString = JSTDString;
		case 2: { SEC }
			AcctStdString = SECString;
		case 3: { IFRS }
			AcctStdString = IFRSString;
	end;
	return AcctStdString;
end;
method bool GetQuoteAsOfDate( FundamentalQuote fq, DateTime tempdt, out double QuoteVal )
variables:  
	int Counter,
	bool QuoteFound, 
	DateTime LastDateTime,  
	string AcctStd, 
	string LastUsedAcctStd, 
	bool SetVariable,
	DateTime fqDateTime;
begin
	if fq = NULL or tempdt = NULL then return false;
	QuoteFound = false;
	LastDateTime = DateTime.Create( 1900, 1, 1 );
	SetVariable = false;
	for Counter = fq.Count - 1 downto 0 begin
		SetVariable = false;
		AcctStd = fq.ExtendedProperties[Counter][AccountingKey].StringValue;
		
		if fq.ExtendedProperties[Counter][MonthsReportedKey].IntegerValue = MonthsReported
			and fq.ExtendedProperties[Counter][ConsolidatedKey].StringValue	= ConsLevel
			and ( AccountingStandard = 0 or AcctStd = AcctStdInputString ) then begin
			fqDateTime = fq.PostDate[Counter];
			
			if tempdt >= fqDateTime and fqDateTime >= LastDateTime then begin
				if fqDateTime <> LastDateTime then begin { new PostDate }
					SetVariable = true;
				end else if AccountingStandard = 0 then begin { use hierarchy }
					if AcctStd = IFRSString then
					begin
						SetVariable = true;
					end else if AcctStd = SECString and LastUsedAcctStd <> IFRSString then begin
						SetVariable = true;
					end else if AcctStd = JSTDString 
						and LastUsedAcctStd <> IFRSString 
						and LastUsedAcctStd <> SECString then begin
						SetVariable = true;
					end;			
				end;	
			end;
		end;	
		
		if SetVariable then begin
			QuoteVal = fq.DoubleValue[Counter];
			LastUsedAcctStd = AcctStd;
			LastDateTime = fqDateTime;
			QuoteFound = true;
		end;
	end;
	return QuoteFound;
end;{ GetQuoteAsOfDate method }
once begin
	if ConsolidationLevel = 1 then ConsLevel = ConsolidatedValue
	else ConsLevel = NonConsolidatedValue;
	AcctStdInputString = GetAcctStdString();
	CreateFundamentalQuotesProvider();
	OkayToPlotTotalAssets = FQP.HasQuoteData( TotalAssetsFieldName ) and DataHasPostDate( FQP[TotalAssetsFieldName] );
	OkayToPlotNetAssets = FQP.HasQuoteData( NetAssetsFieldName ) and DataHasPostDate( FQP[NetAssetsFieldName] );
	OkayToPlotRatio = FQP.HasQuoteData( RatioFieldName ) and DataHasPostDate( FQP[RatioFieldName] );
	OkayToPlotDERatio = FQP.HasQuoteData( DERatioFieldName ) and DataHasPostDate( FQP[DERatioFieldName] );
	OkayToPlotOpCF = FQP.HasQuoteData( OpCFFieldName ) and DataHasPostDate( FQP[OpCFFieldName] );
end;
//総資産
	if OkayToPlotTotalAssets and GetQuoteAsOfDate( FQP[TotalAssetsFieldName], BarDateTime, CRTotalAssets ) then
	Plot1( CRTotalAssets, !( "総資産" ) );
//株主資本
	if OkayToPlotNetAssets and GetQuoteAsOfDate( FQP[NetAssetsFieldName], BarDateTime, CRNetAssets ) then
	Plot2( CRNetAssets, !( "株主資本" ) );
//自資比率%
	if OkayToPlotRatio and GetQuoteAsOfDate( FQP[RatioFieldName], BarDateTime, CRCapitalRatio ) then
	Plot3( CRCapitalRatio, !( "自資比率%" ) );
//債務資産比率(D/Eレシオ)
	if OkayToPlotDERatio and GetQuoteAsOfDate( FQP[DERatioFieldName], BarDateTime, CRDERatio ) then
	Plot4( CRDERatio, !( "債務比率%" ) );
//有利子負債残高
	Plot5( CRDERatio / 100 * CRNetAssets, !( "有利子負債残高(百万)" ) );
//有利子負債依存度
	if Plot1 <> 0 then Plot6( CRDERatio * CRNetAssets / CRTotalAssets, !( "有利子負債依存度%" ) );
//債務償還年数
	if OkayToPlotOpCF and GetQuoteAsOfDate( FQP[OpCFFieldName], BarDateTime, CROpCF ) then begin
		if CROpCF <> 0 then Plot7( CRDERatio / 100 * CRNetAssets / CROpCF, !( "債務償還年数" ) );
//営業CF
		Plot8( CROpCF, !( "営業CF" ) );
	end;

サポートされると喜んでアイスを買っちゃいます!٩(๑❛ᴗ❛๑)۶