見出し画像

業績推移アプリ

業績推移のアプリです、表示内容は株探とほぼ同じですw
トレステ内でサッと見れたり、実績データが年々徐々に溜まってくのでその分少し良いかなぁと思っています

アプリ1本目という事もあって分からない事が多く、
インジケータの数倍理解と制御が大変でした(´д`;)
公式のアプリのソースも3本しかなくどれも長いのであまり参考にならず
あちこちに沼や谷や闇があったり、ヘルプのリンクが違うとか
しかも2つも肝心な知りたいところだけ!イライラさせてくれるw
特にシンボルリンク、ファイルのロードの挙動と制御、
データグリッドビューと行と列の記述と理解が大変でした

まだよく分かってない部分も多々あるので効率的ではない記述もあるかもしれませんがこれからアプリ作ってみたい人の参考になれば幸いです
アプリが作れると色々なデータを組み合わせてオリジナルなものが作れるので是非チャレンジを!苦労した分出来た時にはちょっと感動しますw

注意事項

・インジケータ作成ではなくアプリ作成です
・プログラム内にも注記してありますが
 検証する時にイニシャライズイベントの設定を忘れないで下さい
 忘れると真っ黒なフォームだけが現れますw
・2017年現在の過去のファンダ実績データは6年分あるみたいですので
 デフォルト表示7年にしました、
 年数経過に伴い1年に1回数字を増やすか毎回数字を変えてください
・現状通期の実績のみです、四半期は未処理で今後の予定(未定です)
・連結/単独の入力項目いちいち入力するの面倒くさいと思ったので
 内部で判断するようにしました
・銘柄コードはブランクでEnter押すと銘柄検索窓が開きます
・表示年数は1-99年以外はエラーにしてあります
・万が一アプリがクラッシュしたりした場合はアプリをアクティブにして
 表示(V)再ロード(E)
 又はCtrl + Rでアプリ再ロードになります
・トレステまでクラッシュしてしまった場合、
 私の場合は全ていいえでエラー状態を保存しないようにして終了させ
 PCを再起動か、裏で動いてるテレステ系のプロセスを全て終了させて
 トレステ再起動のどちらかをさせています
(この銘柄のこういう処理をしたら毎回クラッシュするとかいう事が
 もしあったら教えてください)

プログラム

{ -------------------------------------------------- }
	//宣言処理
{ -------------------------------------------------- }	//クラス宣言
using elsystem;																//tsdataクラスによって使用される基本クラスと、その他一般的なelsystemクラス
using platform;																//主要プラットフォームおよび設定で使用されるクラス
using elsystem.io;															//入力/出力システム例外の処理に使用される基本クラス
using tsdata.marketdata;													//価格クオート、市場レベル、ファンダメンタル値などの市場データへのアクセスに使用されるクラス
using elsystem.collections;													//各種のコレクションオブジェクトの作成に使用される基本クラス
using tsdata.common;														//他のtsdata名前空間によって使用されるクラス
using elsystem.windows.forms;												//フォームのコントロールおよびコンテナーの作成に使用されるクラス
using elsystem.drawing;														//フォームコントロールやドローイングオブジェクトの色およびフォント特性を記述するために使用されるクラス
{ -------------------------------------------------- }	//変数宣言(単数は0:省略可は省略、複数は1から連番)
variables:
	Form MainForm( null ),													//フォーム			Formクラス
	Panel Panel0( null ),													//パネル			Panelクラス
	Label Label1( null ), Label Label2( null ),								//ラベル			Labelクラス
	Label Label3( null ), Label Label4( null ),
	TextBox TextBox1( null ), TextBox TextBox2( null ),						//テキストボックス	TextBoxクラス
	RadioButton RdBtn1( null ), RadioButton RdBtn2( null ),					//ラジオボタン		RadioButtonクラス
	DataGridView DGV0( null ),												//表				DataGridViewクラス
	SymbolLinking SLink( null ),											//シンボルリンク		SymbolLinkingクラス 
	SymbolContext SLContext ( null ),										//シンボルリンク		SymbolContextクラス
	SymbolLookupDialog symbolLookup( null ),								//銘柄検索		CommonDialogクラス
	SymbolAttributesProvider SAP( null ),									//コンポーネント		SymbolAttributesProviderクラス 
	FundamentalQuotesProvider FQP( null ),									//コンポーネント		FundamentalQuotesProviderクラス
	Dictionary DataDict( null ),											//辞書			Dictionaryクラス (コレクション) キー/値のペアのコレクション
	int PeriodsAgo( 0 ),													//遡り			: 0=最新 大きい程過去
	int MonthsReported( 12 ),												//期間			: 3, 6, 12(数字の期間で纏められてる、3:四半期、6:半期、12:通期)(1、3四半期は同じ3)
	int ConsolidationLevel( 1 ),											//連結/単独		: 1=連結 1≠単独
	int AccountingStandard( 0 ),											//会計基準		: 1= JSTD 2=SEC 3=IFRS
	string ConsLevel( "Consolidated" ),										//連結/単独
	string AcctStdInputString( "" ),										//会計基準
	intrabarpersist bool OkSAP( false ),									//SAP銘柄コード確認用
	intrabarpersist bool OkFQP( false ),									//FQP銘柄コード確認用
	intrabarpersist bool OkYear( true ),									//年数確認用
	intrabarpersist bool CodeOnce( true ),									//銘柄変更毎1回用
	intrabarpersist string KpCode( "" ),									//銘柄変更確認用
	intrabarpersist string KpYear( "" ),									//年数変更確認用
	double FundFieldValue( 0 ),												//値
	DateTime Happyo( null ), 												//決算発表日
	int PeriodsAgoPlus( 0 ),												//前期比用
	int RowCount( 0 );														//行数
{ -------------------------------------------------- }	//定数宣言
constants:
	string MonthsReportedKey( "MonthsReported" ),							//期間
	string ConsolidatedKey( "ConsolidationLevel" ),							//連結/単独
	string AccountingKey( "AccountingStandard" ),							//会計基準
	string SALESActualFieldName( "CR_SALES" ),								//実売上
	string OPActualFieldName( "CR_Op" ),									//実営利
	string RPActualFieldName( "CR_RP" ),									//実経常
	string NPActualFieldName( "CR_NP" ),									//実純利
	string EPSActualFieldName( "CR_EPS" ),									//1株益
	string DPSActualFieldName( "CR_DPS" ),									//1株配
	string SALESForecastFieldName( "CE_SALES" ),							//予売上
	string OPForecastFieldName( "CE_Op" ),									//予営利
	string RPForecastFieldName( "CE_RP" ),									//予経常
	string NPForecastFieldName( "CE_NP" ),									//予純利
	string EPSForecastFieldName( "CE_EPS" ),								//予1株益
	string DPSForecastFieldName( "CE_DPS" ),								//予1株配
	string ConsolidatedValue( "Consolidated" ),								//連結
	string NonConsolidatedValue( "NonConsolidated" ),						//単独
	string KeyTermType( "TermType" ),										//期間タイプ
	string KeyFullTerm( "FullTerm" ),										//本決算
	string KeyAccounting( "AccountingStandard" ),							//会計基準
	string KeyConsolidated( "ConsolidationLevel" ),							//連単
	string ValuesAdder( "_Values" ),										//値
	string IFRSString( "IFRS" ),											//会計基準(IFRS)
	string SECString( "SEC" ),												//会計基準(SEC)
	string JSTDString( "JSTD" );											//会計基準(JSTD)
{ -------------------------------------------------- }
	//初期処理	※ 検証する時に、プロパティでイニシャライズイベントに設定
{ -------------------------------------------------- }
method void AnalysisTechnique_Initialized( elsystem.Object sender, elsystem.InitializedEventArgs args )
begin
//各種パーツ初期設定・表示
	MainForm_Column();														//メインフォーム
	SymbolLink_Column();													//シンボルリンク
	DGV_Column();															//表
	Header_Column();														//列見出し
	Label_Column();															//ラベル(文字、数値)	※ パネルの前にしないとパネルの下にラベルが隠れる
	Textbox_Column();														//テキストボックス		※ パネルの前にしないとパネルの下にテキストが隠れる
	RadioButton_Column();													//ラジオボタン			※ パネルの前にしないとパネルの下にラジオボタンが隠れる
	Panel_Column();															//パネル				※ 表のあとパネルにしないとパネルの下に表が隠れる
	MainForm.Show();														//メインフォームを表示
end;{ method AnalysisTechnique_Initialized }
{ -------------------------------------------------- }
	//各種パーツ初期設定
{ -------------------------------------------------- }	//メインフォーム初期設定
method void MainForm_Column()
begin
	MainForm = Form.Create();												//フォームの新規インスタンスを初期化
	MainForm.Dock = DockStyle.Fill;											//フォームのコントロールがドッキングされる位置および方法を指定
	MainForm.MinimumSize = Size.Create(670, 160); 							//フォームの最小サイズ(ピクセル単位)を取得または設定
	MainForm.MaximumSize = Size.Create(670, 640);							//フォームの最大サイズ(ピクセル単位)を取得または設定
	MainForm.AutoSize = true;												//フォームのサイズ変更
end; { Form_Column }
{ -------------------------------------------------- }	//シンボルリンク初期設定
method void SymbolLink_Column()
begin
	SLink = SymbolLinking.Create();
	SLContext = SymbolContext.Create();
	SLink.GetContext += GetContext_SymbolLink;								//シンボルリンクアイコン選択した時
	SLink.SetContext += SetContext_SymbolLink;								//シンボルリンク銘柄変更した時
end; { SymbolLink_Column }
{ -------------------------------------------------- }	//表初期設定
method void DGV_Column()
begin
	DGV0 = DataGridView.Create();											//DataGridViewクラス、DGV0の新規インスタンスを初期化
	MainForm.AddControl( DGV0 );											//コントロールをMainFormに追加
	DGV0.Dock = DockStyle.fill;												//DGV0のコントロールがドッキングされる位置および方法を指定
	DGV0.AllowUserToAddRows = false;										//ユーザーがグリッド行を追加できる場合はtrue/false
	DGV0.BackColor = color.Black;											//ウィンドウ背景色
	DGV0.DefaultCellStyle.BackColor = color.Black;							//セル背景色
	DGV0.DefaultCellStyle.ForeColor = color.OliveDrab;						//文字色
	DGV0.GridColor = color.DimGray;											//グリッド色
	DGV0.ReadOnly = true;													//ユーザーが列のセルを編集できる場合はfalse/true
	DGV0.ColumnHeadersDefaultCellStyle.Alignment							//ヘッダーのデフォルトの整列スタイルを取得または設定( Left:0 Center:1 Right:2 )
	 = DataGridViewContentAlignment.MiddleCenter;
	DGV0.DefaultCellStyle.Format = "###,###,###,###,##0";					//フォーマットカンマ付き数字スタイルにしたいがやり方が分からない!
	DGV0.DefaultCellStyle.Alignment = ContentAlignment.MiddleRight;			//整列スタイルを取得または設定( Left:0 Center:1 Right:2 )
end; { DGV_Column }
{ -------------------------------------------------- }	//列見出し初期設定
method void Header_Column()
begin
	DGV0.RowHeadersVisible = false;											//列のヘッダーが表示される場合true/false
	DGV0.RowHeadersWidth = 20;												//列のヘッダーの幅
	DGV0.ColumnHeadersHeight = 32;											//列のヘッダーの高さ
	DGV0.ColumnHeadersHeightSizeMode = 0;									//列のヘッダーの高さ調整( 0:可 1:不可 2:AutoSize )
	DGV0.Columns.Add( "No" );												//列見出し0
	DGV0.Columns.Add( "売 上" );											//列見出し1
	DGV0.Columns.Add( "営 利" );												//列見出し2
	DGV0.Columns.Add( "経 常" );												//列見出し3
	DGV0.Columns.Add( "純 利" );												//列見出し4
	DGV0.Columns.Add( "1株益" );												//列見出し5
	DGV0.Columns.Add( "1株配" );												//列見出し6
	DGV0.Columns.Add( "利益率%" );											//列見出し7
	DGV0.Columns.Add( "営業利益前期比" );									//列見出し8
	DGV0.Columns.Add( "営業利益前期比%" );									//列見出し9
	DGV0.Columns.Add( "決算日" );											//列見出し10
	DGV0.Columns[0].Width = 20;												//列の幅(ピクセル単位)を取得または設定
	DGV0.Columns[0].DefaultCellStyle.Alignment								//テキストのデフォルトの整列スタイルを取得または設定
	 = DataGridViewContentAlignment.MiddleCenter;							//DataGridViewContentAlignment列挙参照
	DGV0.Columns[1].Width = 70;
	DGV0.Columns[2].Width = 70;
	DGV0.Columns[3].Width = 70;
	DGV0.Columns[4].Width = 70;
	DGV0.Columns[5].Width = 45;
	DGV0.Columns[6].Width = 45;
	DGV0.Columns[7].Width = 50;
	DGV0.Columns[8].Width = 70;
	DGV0.Columns[9].Width = 70;
	DGV0.Columns[10].Width = 70;
	DGV0.Columns[5].DefaultCellStyle.Format = "###,###,###,###,##0.0";		//フォーマットカンマ付き数字スタイルにしたいがやり方が分からない!ヘルプウンコ!
	DGV0.Columns[6].DefaultCellStyle.Format = "###,###,###,###,##0.0";
	DGV0.Columns[7].DefaultCellStyle.Format = "###,##0.0%";					//フォーマット%スタイルにしたいがやり方が分からない!ヘルプウンコ!
	DGV0.Columns[9].DefaultCellStyle.Format = "###,##0.0%";	
end; { Header_Column }
{ -------------------------------------------------- }	//パネル初期設定
method void Panel_Column()
begin
	Panel0 = Panel.Create( 0, 30 );											//パネルの新規インスタンスを初期化(幅、高さ)
	Panel0.Dock = DockStyle.top;											//パネルのコントロールがドッキングされる位置および方法を指定
	Panel0.BackColor = color.Gainsboro;										//背景色
	MainForm.AddControl( Panel0 );											//コントロールをMainFormに追加
end; { Panel_Column }
{ -------------------------------------------------- }	//ラベル初期設定
method void Label_Column()
begin
//ラベル1(銘柄コード(テキスト))
	Label1 = Label.create( "銘柄コード", 60, 15 );								//ラベル(テキスト、幅、高さ)
	Label1.Location( 25, 8 );												//左上基準位置( X,Y )
	Label1.BackColor = color.Gainsboro;										//背景色
	MainForm.AddControl( Label1 ); 											//コントロールをMainFormに追加
//ラベル2(銘柄名)
	Label2 = Label.Create( "", 300, 15 );									//ラベル(枠のみ、コード入力で銘柄名表示)
	Label2.Location( 135, 8 );												//左上基準位置( X,Y )
	Label2.BackColor = color.Gainsboro;										//背景色
	MainForm.AddControl( Label2 ); 											//コントロールをMainFormに追加	
//ラベル3(年(テキスト))
	Label3 = Label.Create( "年", 15, 15 );									//ラベル(テキスト、幅、高さ)
	Label3.Location( 630, 8 );												//左上基準位置( X,Y )
	Label3.BackColor = color.Gainsboro;										//背景色
	MainForm.AddControl( Label3 ); 											//コントロールをMainFormに追加
//ラベル4(連結単独)
	Label4 = Label.Create( "", 15, 15 );									//ラベル(枠のみ、コード入力で銘柄名表示)
	Label4.Location( 5, 8 );												//左上基準位置( X,Y )
	Label4.BackColor = color.Gainsboro;										//背景色
	MainForm.AddControl( Label4 ); 											//コントロールをMainFormに追加	
end; { Label_Column }
{ -------------------------------------------------- }	//テキストボックス初期設定
method void TextBox_Column()
begin
//テキストボックス1(銘柄コード入力用)
	TextBox1 = Textbox.create( "", 40, 20 );								//テキストボックス(テキスト、幅、高さ)
	TextBox1.Location( 90, 5 );												//左上基準位置( X,Y )
	MainForm.AddControl( TextBox1 ); 										//コントロールをMainFormに追加
	TextBox1.KeyUp += TextBox_KeyUp;										//テキストボックスに入力した時
//テキストボックス2(表字年数入力用)
	TextBox2 = Textbox.create( "7", 20, 20 );								//テキストボックス(テキスト、幅、高さ)
	TextBox2.Location( 610, 5 );											//左上基準位置( X,Y )
	MainForm.AddControl( TextBox2 ); 										//コントロールをMainFormに追加
	TextBox2.KeyUp += TextBox_KeyUp;										//テキストボックスに入力した時
end; { TextBox_Column }
{ -------------------------------------------------- }	//ラジオボタン初期設定
method void RadioButton_Column()
begin
//ラジオボタン1(通期)
	RdBtn1 = RadioButton.create( " 通 期", 60, 20 );						//ラジオボタン(テキスト、幅、高さ)
	RdBtn1.Location( 460, 5 );												//左上基準位置( X,Y )
	RdBtn1.BackColor = color.Gainsboro;										//背景色
	RdBtn1.Checked = true;													//ラジオボタン(初期値ON true)
	MainForm.AddControl( RdBtn1 ); 											//コントロールをMainFormに追加
	RdBtn1.Click += RdBtn1_Click;											//ラジオボタン1をクリックした時
//ラジオボタン2(四半期)
	RdBtn2 = RadioButton.create( " 四半期", 65, 20 );						//ラジオボタン(テキスト、幅、高さ)
	RdBtn2.Location( 530, 5 );												//左上基準位置( X,Y )
	RdBtn2.BackColor = color.Gainsboro;										//背景色
	RdBtn2.Checked = false;													//ラジオボタン(初期値OFF false)
	MainForm.AddControl( RdBtn2 ); 											//コントロールをMainFormに追加
	RdBtn2.Click += RdBtn2_Click;											//ラジオボタン2をクリックした時
end; { RadioButton_Column }
{ -------------------------------------------------- }
	//イベント発生処理
{ -------------------------------------------------- }	//シンボルリンクアイコン選択した時
method void GetContext_SymbolLink( elsystem.Object sender, SymbolLinkingEventArgs args )
begin
	args.Recalculate = false;												//アプリ再計算true/false
	TextBox1.Text = args.Symbol.Substring(0,4);
	if TextBox1.text.Length >= 4 and OkYear = true then CheckCode();		//銘柄コードチェック
end; { SetContext_SymbolLink }
{ -------------------------------------------------- }	//シンボルリンク銘柄変更した時
method void SetContext_SymbolLink( elsystem.Object sender, SymbolLinkingEventArgs args )
begin
	args.Recalculate = false;												//アプリ再計算true/false
	TextBox1.Text = args.Symbol.Substring(0,4);
	if TextBox1.text.Length >= 4 and OkYear = true then CheckCode();		//銘柄コードチェック
end; { SetContext_SymbolLink }
{ -------------------------------------------------- }	//テキストボックスに入力した時
method void TextBox_KeyUp( elsystem.Object sender, elsystem.windows.forms.KeyEventArgs args )
begin
	if args.KeyCode.ToString() = "Return" then begin						//予約語ReturnじゃなくEnterキー、args.KeyCode = Keys.Returnでも可
//表示年数チェック
		if TextBox2.text <= "0"
		or TextBox2.text > "99"
		or TextBox2.text = ""
		or TextBox2.text.Length >= 3 then OkYear = false else OkYear = true;//年数確認用
		if OkYear = false then Label2.Text = "表示年数が正しくありません";		//銘柄名
//銘柄コード長0の時、銘柄検索													//銘柄コードAlt+(B)に初期設定したいがフィールド名が分からない!
		if OkYear = true and TextBox1.text.Length = 0 then begin
			SymbolLookup = SymbolLookupDialog.Create();
			SymbolLookup.StatusChanged += SymbolLookupStatus_DialogChanged;
			SymbolLookup.Show();
		end;
//年数エラーなし、銘柄コード長4以上の時、銘柄コードチェック
		if OkYear = true and TextBox1.text.Length >= 4 then CheckCode();
	end;
end; { TextBox_KeyUp }
{ -------------------------------------------------- }	//ラジオボタン1をクリックした時
method void RdBtn1_Click( elsystem.Object sender, elsystem.EventArgs args ) 
begin
	Clearprintlog();	print( "通期をクリック!期間MonthsReportedに12をセット" );
	MonthsReported = 12;													//期間に12をセット
end; { RdBtn1_Click }
{ -------------------------------------------------- }	//ラジオボタン2をクリックした時
method void RdBtn2_Click( elsystem.Object sender, elsystem.EventArgs args ) 
begin
	Clearprintlog();	print( "四半期をクリック、四半期処理はまだ未処理!" );
end; { RdBtn2_Click }
{ -------------------------------------------------- }	//銘柄検索OKした時
method void SymbolLookupStatus_DialogChanged( Object sender, DialogStatusChangedEventArgs args )
begin
	if symbolLookup.Status = DialogResult.OK then TextBox1.Text = symbolLookup.Symbol.Substring(0,4);
	if TextBox1.text.Length >= 4 and OkYear = true then CheckCode();		//銘柄コードチェック
end; { SymbolLookupStatus_DialogChanged }
{ -------------------------------------------------- }	//SAP変更した時
method void SAP_Updated( Object sender, SymbolAttributesUpdatedEventArgs args )
begin
	switch ( SAP.State ) begin
		case 3:{ failed }
				OkSAP = false;												//銘柄コード確認NG
				Label2.Text = "銘柄コードが正しくありません";						//銘柄名	
		case 2:{ loaded }
				OkSAP = true;
				Label2.Text = SAP.Description.ToString();					//銘柄名
				CreateFQP();												//FQP初期設定
		case 1:{ loading }
				OkSAP = false;
				Label2.Text = "銘柄データloading もう一度Enterを押して下さい";		//銘柄名	
		case 0:{ Unloaded }
				OkSAP = false;
	end;
end; { SAPFQP_StateChanged }
{ -------------------------------------------------- }	//FQP変更した時
method void FQP_Updated( Object sender, FundamentalQuoteUpdatedEventArgs args )
begin
	switch ( FQP.State ) begin
		case 3:{ failed }
				OkFQP = false;												//銘柄コード確認NG
				Label2.Text = "銘柄データがありません";							//銘柄名	
		case 2:{ loaded }
				OkFQP = true;
				PeriodsAgo = int.Parse( KpYear );										//遡り数
				RowCount = 0;												//行数
				for PeriodsAgo = PeriodsAgo - 1 downto 0 begin				//最新まで逆読み
					FQPDataSet();											//ファンダメンタルデータセット・実績表示
					RowCount = RowCount + 1;								//DGV行数+1
				end;
				DGV0.Sort( DGV0.Columns[0], 1 );							//列のソートモードを取得または設定(0:昇順 1:降順)
				FQPDataSet2();												//ファンダメンタルデータセット・予想表示
		case 1:{ loading }
				OkFQP = false;
		case 0:{ Unloaded }
				OkFQP = false;
	end;
end; { SAPFQP_StateChanged }
{ -------------------------------------------------- }
	//その他サブルーチン処理
{ -------------------------------------------------- }	//銘柄コードチェック、銘柄名セット(ラベル2)
method void CheckCode()
begin
//銘柄、表示年数変更時クリア
	if TextBox1.text = "" or TextBox1.text <> KpCode
	or TextBox2.text = "" or TextBox2.text <> KpYear then begin
		Label2.Text = "";													//銘柄名クリア
		DGV0.Rows.clear();													//行クリア
		DataDict = new Dictionary();										//辞書初期化
		OkSAP = false;														//SAP銘柄コード確認用
		OkFQP = false;														//FQP銘柄コード確認用
		KpCode = TextBox1.text;												//銘柄変更確認用
		KpYear = TextBox2.text;												//年数変更確認用
		CodeOnce = true;													//銘柄変更毎1回用
	end;
	CreateSAP();															//SAP初期設定
	if OkSAP = false then Label2.Text = "銘柄コードが正しくありません";				//銘柄名
end;{ CheckCode method }
{ -------------------------------------------------- }	//SymbolAttributesProvider初期設定
method void CreateSAP()
begin
	SAP = SymbolAttributesProvider.Create();								//プロバイダーオブジェクトを作成
	SAP.Symbol = TextBox1.text;												//シンボル
	if OkSAP = false then SAP.Updated += SAP_Updated;						//変更イベント時(銘柄確認まだの時のみ)
	SAP.Load = true;														//プロバイダー接続
end; { CreateSAP }
{ -------------------------------------------------- }	//FundamentalQuotesProvider初期設定
method void CreateFQP()
begin
	FQP = FundamentalQuotesProvider.Create();								//プロバイダーオブジェクトを作成
	FQP.Symbol = TextBox1.text;												//シンボル
	FQP.Fields += SALESActualFieldName;										//実売上
	FQP.Fields += OPActualFieldName;										//実営利
	FQP.Fields += RPActualFieldName;										//実経常
	FQP.Fields += NPActualFieldName;										//実純利
	FQP.Fields += EPSActualFieldName;										//1株益
	FQP.Fields += DPSActualFieldName;										//1株配
	FQP.Fields += SALESForecastFieldName;									//予売上
	FQP.Fields += OPForecastFieldName;										//予営利
	FQP.Fields += RPForecastFieldName;										//予経常	
	FQP.Fields += NPForecastFieldName;										//予純利	
	FQP.Fields += EPSForecastFieldName;										//予1株益
	FQP.Fields += DPSForecastFieldName;										//予1株配
	if OkFQP = false then FQP.Updated += FQP_Updated;						//変更イベント時(銘柄確認まだの時のみ)
	FQP.Load = true;														//プロバイダー接続
end; { CreateFQP }
{ -------------------------------------------------- }
	//ファンダメンタルデータセット処理
{ -------------------------------------------------- }	//データ存在チェック、セット
method bool GetQuoteAsOfDate( string FieldName, DateTime tempdt, int PeriodsAgo, out double QuoteVal )
variables:  
	int Counter,
	bool QuoteFound, bool SetVariable,
	DateTime VectDateTime,
	Vector QuoteDateTimeVector, Vector QuoteValuesVector;
begin
	if FieldName = "" or tempdt = null or DataDict = null or PeriodsAgo < 0 then return false;
	QuoteDateTimeVector = DataDict[FieldName] astype Vector;
	QuoteValuesVector = DataDict[FieldName + ValuesAdder] astype Vector;
	QuoteFound = false;
	Happyo = DateTime.Create( 1900, 1, 1 );
	for Counter = QuoteDateTimeVector.Count - 1 downto 0 begin
		SetVariable = false;
		VectDateTime = QuoteDateTimeVector[Counter] astype DateTime;
		if tempdt >= VectDateTime then begin	{ 現在日時以下ならデータセット }
			SetVariable = true;
		end else begin
			break;								{ for downto 終了 return へ }
		end;	
		if SetVariable then begin
			if Counter + PeriodsAgo <= QuoteDateTimeVector.Count - 1 then begin	
				QuoteVal = QuoteValuesVector[Counter + PeriodsAgo] astype double;	//値
				Happyo = QuoteDateTimeVector[Counter + PeriodsAgo] astype DateTime;	//決算発表日
				QuoteFound = true;
			end;
		end;
	end;
	return QuoteFound;	{ メソッドの実行を終了し、メソッドの呼び出し元に制御を返す、リターンキーワードQuoteFoundはbool型なのでtrue/falseどちらかを返す }
end;{ GetQuoteAsOfDate }
{ -------------------------------------------------- }	//Vectorクラスデータ要素のコレクションを作成
method void LoadFundDataVectorsWithFilters( string ifundField )
variables:  
	int Counter, 
	Vector dateVect, Vector valuesVect,
	FundamentalQuote fq,
	string fqAcctStd, string LastAcctStd,
	bool LoadThisQuote, bool ReplaceLastValue, bool NumMonthsOkay, bool ConsLevelOkay,
	DateTime LastDateTime;
begin
	if DataDict = null then DataDict = new Dictionary();
	dateVect = new Vector();
	valuesVect = new Vector();
	DataDict.Add( ifundField, dateVect astype Vector );
	DataDict.Add( ifundField + ValuesAdder, valuesVect astype Vector );
	fq = FQP[ifundField];
	LastDateTime = DateTime.Create( 1900, 1, 1 );
	for Counter = 0 to fq.Count - 1 begin
		LoadThisQuote = false;
		ReplaceLastValue = false;
		fqAcctStd = fq.ExtendedProperties[Counter][AccountingKey].StringValue;
		NumMonthsOkay = fq.ExtendedProperties[Counter][MonthsReportedKey].IntegerValue = MonthsReported;
		ConsLevelOkay = fq.ExtendedProperties[Counter][ConsolidatedKey].StringValue = ConsLevel;
		if NumMonthsOkay and ConsLevelOkay and ( AccountingStandard = 0 or fqAcctStd = AcctStdInputString ) then begin	
			if fq.PostDate[Counter] <> LastDateTime then begin { new date }
				LoadThisQuote = true;
			end else begin { same date as last quote loaded }
				switch ( fqAcctStd ) begin
					case IFRSString:ReplaceLastValue = true;
					case SECString:	if LastAcctStd <> IFRSString then ReplaceLastValue = true;
					case JSTDString:if LastAcctStd <> IFRSString and LastAcctStd <> SECString then ReplaceLastValue = true;
				end;
			end;
		end;
		if LoadThisQuote then begin
			dateVect.push_back( fq.PostDate[Counter] astype DateTime );		//コレクションの最後に新規要素(日付)を追加
			valuesVect.push_back( fq.DoubleValue[Counter] astype double );	//コレクションの最後に新規要素(値)を追加
			LastAcctStd = fqAcctStd;
			LastDateTime = fq.PostDate[Counter];
		end else if ReplaceLastValue then begin
			valuesVect[Counter-1] = fq.DoubleValue[Counter] astype double;
			LastAcctStd = fqAcctStd;
		end;
	end;
end;{ LoadFundDataVectorsWithFilters method }
{ -------------------------------------------------- }	//連結/単独・会計基準セット
method string GetConsLevel()
variables:
	int Counter,
	FundamentalQuote FQ,
	DateTime tempdt,																			//現在日時
	DateTime LastDateTime,																		//直近本決算日
	DateTime FQDateTime,																		//発表日
	string ConsLevel;
begin
	FQ = FQP[SALESActualFieldName];																//売上実績データで確認
	tempdt = LastCalcDateTime;																	//現在日時
	LastDateTime = DateTime.Create( 1900, 1, 1 );												//直近本決算日セット1900/01/01
	ConsLevel = "Consolidated";																	//連単初期設定:連結
	for counter = FQ.Count - 1 downto 0 begin													//カウント分繰り返し古いデータから逆順に確認
		FQDateTime = FQ.PostDate[counter];														//発表日セット
		//FullTerm判断
		if FQ.ExtendedProperties[counter][KeyTermType].StringValue = KeyFullTerm then begin		//FullTerm 本決算判断
			if tempdt >= FQDateTime and FQDateTime >= LastDateTime then	begin					//現在日時以下、直近本決算日以上の時
				LastDateTime = FQDateTime;														//直近本決算日セット
			end;
			//FullTerm1件しかない場合の判断(FullTerm2件で連単両方ある場合は初期設定の連結で判断)
			if FQ.Count = 1 then begin
				AcctStdInputString = FQ.ExtendedProperties[counter][KeyAccounting].ToString();	//会計基準
				ConsLevel = FQ.ExtendedProperties[counter][KeyConsolidated].ToString();			//連単
			end;
		//FullTerm以外判断
		end else if tempdt >= FQDateTime and FQDateTime >= LastDateTime then begin				//FullTerm本決算以外 現在日時以下、直近本決算日以上の時
			AcctStdInputString = FQ.ExtendedProperties[counter][KeyAccounting].ToString();		//会計基準
			ConsLevel = FQ.ExtendedProperties[counter][KeyConsolidated].ToString();				//連単
		end;
	end;{ for downto }
	if ConsLevel = ConsolidatedValue then begin 
		Label4.Text = "連";
		Label4.ForeColor = color.Red;
	end else begin 
		Label4.Text = "単";
		Label4.ForeColor = color.Blue;
	end;
	return ConsLevel;
end;{ GetConsol method }
{ -------------------------------------------------- }	//ファンダメンタルデータセット・実績表示
method void FQPDataSet()
begin
//行追加、設定
	DGV0.Rows.Add( PeriodsAgo );											//行追加、遡りNoセット
	DGV0.Rows[RowCount].Height = 18;										//行の高さ (ピクセル単位) を取得または設定
	DGV0.Rows[RowCount].Resizable = 2;										//行のサイズ変更を取得または設定( 0:未設定 1:true 2:False )
//連結/単独・会計基準セット
	if CodeOnce then ConsLevel = GetConsLevel();
//実売上( Value1 )
	if FQP.HasQuoteData( SALESActualFieldName ) and ( FQP[SALESActualFieldName].Type = DataType.doubleval	//指定名を持つクオートに値が含まれる場合は真
	or FQP[SALESActualFieldName].Type = DataType.integerval ) then begin
		Condition1 = true;
		if CodeOnce then if FQP[SALESActualFieldName].ExtendedProperties[0].Contains( MonthsReportedKey ) then LoadFundDataVectorsWithFilters( SALESActualFieldName );	//指定名を持つクオートがプロバイダーに存在する場合は真
	end;
	if Condition1 then begin
		if GetQuoteAsOfDate( SALESActualFieldName, BarDateTime, PeriodsAgo, FundFieldValue ) then Value1 = FundFieldValue;
		DGV0.Rows[RowCount].Cells[1].Value = ( Value1 );
	end;
//実営利( Value2 )
	if FQP.HasQuoteData( OPActualFieldName ) and ( FQP[OPActualFieldName].Type = DataType.doubleval
	or FQP[OPActualFieldName].Type = DataType.integerval ) then begin
		Condition2 = true;
		if CodeOnce then if FQP[OPActualFieldName].ExtendedProperties[0].Contains( MonthsReportedKey ) then	LoadFundDataVectorsWithFilters( OPActualFieldName );
	end;
	if Condition2 then begin
		if GetQuoteAsOfDate( OPActualFieldName, BarDateTime, PeriodsAgo, FundFieldValue ) then Value2 = FundFieldValue;
		DGV0.Rows[RowCount].Cells[2].Value = ( Value2 );
	end;
//実経常( Value3 )
	if FQP.HasQuoteData( RPActualFieldName ) and ( FQP[RPActualFieldName].Type = DataType.doubleval
	or FQP[RPActualFieldName].Type = DataType.integerval ) then begin
		Condition3 = true;
		if CodeOnce then if FQP[RPActualFieldName].ExtendedProperties[0].Contains( MonthsReportedKey ) then LoadFundDataVectorsWithFilters( RPActualFieldName );
	end;
	if Condition3 then begin
		if GetQuoteAsOfDate( RPActualFieldName, BarDateTime, PeriodsAgo, FundFieldValue ) then Value3 = FundFieldValue;
		DGV0.Rows[RowCount].Cells[3].Value = ( Value3 );
	end;
//実純利( Value4 )
	if FQP.HasQuoteData( NPActualFieldName ) and ( FQP[NPActualFieldName].Type = DataType.doubleval
	or FQP[NPActualFieldName].Type = DataType.integerval ) then begin
		Condition4 = true;
		if CodeOnce then if FQP[NPActualFieldName].ExtendedProperties[0].Contains( MonthsReportedKey ) then LoadFundDataVectorsWithFilters( NPActualFieldName );
	end;
	if Condition4 then begin
		if GetQuoteAsOfDate( NPActualFieldName, BarDateTime, PeriodsAgo, FundFieldValue ) then Value4 = FundFieldValue;
		DGV0.Rows[RowCount].Cells[4].Value = ( Value4 );
	end;
//1株益( Value5 )
	if FQP.HasQuoteData( EPSActualFieldName ) and ( FQP[EPSActualFieldName].Type = DataType.doubleval
	or FQP[EPSActualFieldName].Type = DataType.integerval ) then begin
		Condition5 = true;
		if CodeOnce then if FQP[EPSActualFieldName].ExtendedProperties[0].Contains( MonthsReportedKey ) then LoadFundDataVectorsWithFilters( EPSActualFieldName );
	end;
	if Condition5 then begin
		if GetQuoteAsOfDate( EPSActualFieldName, BarDateTime, PeriodsAgo, FundFieldValue ) then Value5 = FundFieldValue;
		DGV0.Rows[RowCount].Cells[5].Value = ( Value5 );
	end;
//1株配( Value6 )
	if FQP.HasQuoteData( DPSActualFieldName ) and ( FQP[DPSActualFieldName].Type = DataType.doubleval
	or FQP[DPSActualFieldName].Type = DataType.integerval ) then begin
		Condition6 = true;
		if CodeOnce then if FQP[DPSActualFieldName].ExtendedProperties[0].Contains( MonthsReportedKey ) then LoadFundDataVectorsWithFilters( DPSActualFieldName );
	end;
	if Condition6 then begin
		if GetQuoteAsOfDate( DPSActualFieldName, BarDateTime, PeriodsAgo, FundFieldValue ) then Value6 = FundFieldValue;
		DGV0.Rows[RowCount].Cells[6].Value = ( Value6 );
	end;
//利益率%( Value7 )
	if Value1 <> 0 then Value7 = ( Value2 / Value1 * 100 );
	DGV0.Rows[RowCount].Cells[7].Value = ( Value7 );
//決算発表日
	DGV0.Rows[RowCount].Cells[10].Value = ( Happyo.ToString() );
	if Happyo.tostring() = ( "1900/01/01" ) then DGV0.Rows[RowCount].Cells[10].ForeColor = color.Black;//背景同色
//前期比	( Value8 )
	PeriodsAgoPlus = PeriodsAgo + 1;
	if GetQuoteAsOfDate( OPActualFieldName, BarDateTime, PeriodsAgoPlus, FundFieldValue ) then begin
		if Condition2 then Value8 = Value2 - FundFieldValue;
	end;
	DGV0.Rows[RowCount].Cells[8].Value = ( Value8 );
//前期比%( Value9 )
	if Value8 <> 0 then Value9 = ( ( Value2 - FundFieldValue ) / FundFieldValue * 100 );
	DGV0.Rows[RowCount].Cells[9].Value = ( Value9 );
//銘柄変更毎1回用
	CodeOnce = false;
//色変更
	ColorSet();
end;{ FQPDataSet method }
{ -------------------------------------------------- }	//ファンダメンタルデータセット2・予想表示
method void FQPDataSet2()
begin
//行追加、設定
	DGV0.Rows.Add( "予" );	DGV0.Rows[RowCount].Height = 18;	DGV0.Rows[RowCount].Resizable = 2;	PeriodsAgo = 0;
//予売上( Value1 )
	if FQP.HasQuoteData( SALESForecastFieldName ) and ( FQP[SALESForecastFieldName].Type = DataType.doubleval
	or FQP[SALESForecastFieldName].Type = DataType.integerval ) then begin
		Condition1 = true;
		if FQP[SALESForecastFieldName].ExtendedProperties[0].Contains( MonthsReportedKey ) then LoadFundDataVectorsWithFilters( SALESForecastFieldName );
	end;
	if Condition1 then begin
		if GetQuoteAsOfDate( SALESForecastFieldName, BarDateTime, PeriodsAgo, FundFieldValue ) then Value1 = FundFieldValue;
		DGV0.Rows[RowCount].Cells[1].Value = ( Value1 );
	end;
//予営利( Value2 )
	if FQP.HasQuoteData( OPForecastFieldName ) and ( FQP[OPForecastFieldName].Type = DataType.doubleval
	or FQP[OPForecastFieldName].Type = DataType.integerval ) then begin
		Condition2 = true;
		if FQP[OPForecastFieldName].ExtendedProperties[0].Contains( MonthsReportedKey ) then	LoadFundDataVectorsWithFilters( OPForecastFieldName );
	end;
	if Condition2 then begin
		if GetQuoteAsOfDate( OPForecastFieldName, BarDateTime, PeriodsAgo, FundFieldValue ) then Value2 = FundFieldValue;
		DGV0.Rows[RowCount].Cells[2].Value = ( Value2 );
	end;
//予経常( Value3 )
	if FQP.HasQuoteData( RPForecastFieldName ) and ( FQP[RPForecastFieldName].Type = DataType.doubleval
	or FQP[RPForecastFieldName].Type = DataType.integerval ) then begin
		Condition3 = true;
		if FQP[RPForecastFieldName].ExtendedProperties[0].Contains( MonthsReportedKey ) then LoadFundDataVectorsWithFilters( RPForecastFieldName );
	end;
	if Condition3 then begin
		if GetQuoteAsOfDate( RPForecastFieldName, BarDateTime, PeriodsAgo, FundFieldValue ) then Value3 = FundFieldValue;
		DGV0.Rows[RowCount].Cells[3].Value = ( Value3 );
	end;
//予純利( Value4 )
	if FQP.HasQuoteData( NPForecastFieldName ) and ( FQP[NPForecastFieldName].Type = DataType.doubleval
	or FQP[NPForecastFieldName].Type = DataType.integerval ) then begin
		Condition4 = true;
		if FQP[NPForecastFieldName].ExtendedProperties[0].Contains( MonthsReportedKey ) then LoadFundDataVectorsWithFilters( NPForecastFieldName );
	end;
	if Condition4 then begin
		if GetQuoteAsOfDate( NPForecastFieldName, BarDateTime, PeriodsAgo, FundFieldValue ) then Value4 = FundFieldValue;
		DGV0.Rows[RowCount].Cells[4].Value = ( Value4 );
	end;
//予1株益( Value5 )
	if FQP.HasQuoteData( EPSForecastFieldName ) and ( FQP[EPSForecastFieldName].Type = DataType.doubleval
	or FQP[EPSForecastFieldName].Type = DataType.integerval ) then begin
		Condition5 = true;
		if FQP[EPSForecastFieldName].ExtendedProperties[0].Contains( MonthsReportedKey ) then LoadFundDataVectorsWithFilters( EPSForecastFieldName );
	end;
	if Condition5 then begin
		if GetQuoteAsOfDate( EPSForecastFieldName, BarDateTime, PeriodsAgo, FundFieldValue ) then Value5 = FundFieldValue;
		DGV0.Rows[RowCount].Cells[5].Value = ( Value5 );
	end;
//予1株配( Value6 )
	if FQP.HasQuoteData( DPSForecastFieldName ) and ( FQP[DPSForecastFieldName].Type = DataType.doubleval
	or FQP[DPSForecastFieldName].Type = DataType.integerval ) then begin
		Condition6 = true;
		if FQP[DPSForecastFieldName].ExtendedProperties[0].Contains( MonthsReportedKey ) then LoadFundDataVectorsWithFilters( DPSForecastFieldName );
	end;
	if Condition6 then begin
		if GetQuoteAsOfDate( DPSForecastFieldName, BarDateTime, PeriodsAgo, FundFieldValue ) then Value6 = FundFieldValue;
		DGV0.Rows[RowCount].Cells[6].Value = ( Value6 );
	end;
//予利益率%( Value7 )
	if Value1 <> 0 then Value7 = ( Value2 / Value1 * 100 );
	DGV0.Rows[RowCount].Cells[7].Value = ( Value7 );
//前期比	( Value8 )
	if GetQuoteAsOfDate( OPActualFieldName, BarDateTime, PeriodsAgo, FundFieldValue ) then begin
		if Condition2 then Value8 = Value2 - FundFieldValue;
	end;
	DGV0.Rows[RowCount].Cells[8].Value = ( Value8 );
//前期比%( Value9 )
	if Value8 <> 0 then Value9 = ( ( Value2 - FundFieldValue ) / FundFieldValue * 100 );
	DGV0.Rows[RowCount].Cells[9].Value = ( Value9 );
//色変更
	ColorSet();
end;{ FQPDataSet2 method }
{ -------------------------------------------------- }	//色変更
method void ColorSet()
begin
//マイナスは青表示、フォーマットのやり方が分からない為ゼロは背景色で隠すw
	if Value1 < 0 then DGV0.Rows[RowCount].Cells[1].ForeColor = color.DodgerBlue else
	 if Value1 = 0 then DGV0.Rows[RowCount].Cells[1].ForeColor = color.Black;
	if Value2 < 0 then DGV0.Rows[RowCount].Cells[2].ForeColor = color.DodgerBlue else
	 if Value2 = 0 then DGV0.Rows[RowCount].Cells[2].ForeColor = color.Black;
	if Value3 < 0 then DGV0.Rows[RowCount].Cells[3].ForeColor = color.DodgerBlue else
	 if Value3 = 0 then DGV0.Rows[RowCount].Cells[3].ForeColor = color.Black;
	if Value4 < 0 then DGV0.Rows[RowCount].Cells[4].ForeColor = color.DodgerBlue else
	 if Value4 = 0 then DGV0.Rows[RowCount].Cells[4].ForeColor = color.Black;
	if Value5 < 0 then DGV0.Rows[RowCount].Cells[5].ForeColor = color.DodgerBlue else
	 if Value5 = 0 then DGV0.Rows[RowCount].Cells[5].ForeColor = color.Black;
	if Value6 < 0 then DGV0.Rows[RowCount].Cells[6].ForeColor = color.DodgerBlue else
	 if Value6 = 0 then DGV0.Rows[RowCount].Cells[6].ForeColor = color.Black;
	if Value7 < 0 then DGV0.Rows[RowCount].Cells[7].ForeColor = color.DodgerBlue else
	 if Value7 = 0 then DGV0.Rows[RowCount].Cells[7].ForeColor = color.Black;
	if Value8 < 0 then DGV0.Rows[RowCount].Cells[8].ForeColor = color.DodgerBlue else
	 if Value8 = 0 then DGV0.Rows[RowCount].Cells[8].ForeColor = color.Black;
	if Value9 < 0 then DGV0.Rows[RowCount].Cells[9].ForeColor = color.DodgerBlue else
	 if Value9 = 0 then DGV0.Rows[RowCount].Cells[9].ForeColor = color.Black;
end;{ ColorSet method }
{ -------------------------------------------------- }

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