File size: 41,134 Bytes
ccefd0b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Financial Statements in the OpenBB Platform\n",
    "\n",
    "OpenBB Platform data extensions provide access to financial statements as quarterly or annual.  There are also endpoints for ratios and other common non-GAAP metrics.  Most data providers require a subscription to access all data. Refer to the website of a specific provider for details on entitlements and coverage.\n",
    "\n",
    "Financial statement functions are grouped under the `obb.equity.fundamental` module.\n",
    "\n",
    "## Endpoints\n",
    "\n",
    "The typical financial statements consist of three endpoints:\n",
    "\n",
    "- Balance Sheet: `obb.equity.fundamental.balance()`\n",
    "- Income Statement: `obb.equity.fundamental.income()`\n",
    "- Cash Flow Statement: `obb.equity.fundamental.cash()`\n",
    "\n",
    "The main parameters are:\n",
    "\n",
    "- `symbol`: The company's symbol.\n",
    "- `period`: 'annual' or 'quarter'. Default is 'annual'.\n",
    "- `limit`: Limit the number of results returned, from the latest. Default is 5. For perspective, 150 will go back to 1985. The amount of historical records varies by provider.\n",
    "\n",
    "### Field Names\n",
    "\n",
    "Some considerations to keep in mind when working with financial statements data are:\n",
    "\n",
    "- Every data provider has their own way of parsing and organizing the three financial statements.\n",
    "- Items within each statement will vary by source and by the type of company reporting.\n",
    "- Names of line items will vary by source.\n",
    "- \"Date\" values may differ because they are from the period starting/ending or date of reporting.\n",
    "\n",
    "This example highlights how different providers will have different labels for compnay facts.\n",
    "\n",
    "\n",
    "**Note**: API Keys are required for FMP, Intrinio, and Polygon."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "from openbb import obb"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>yfinance</th>\n",
       "      <th>fmp</th>\n",
       "      <th>intrinio</th>\n",
       "      <th>polygon</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>5.535600e+10</td>\n",
       "      <td>5.535600e+10</td>\n",
       "      <td>5.535600e+10</td>\n",
       "      <td>5.535600e+10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>5.333500e+10</td>\n",
       "      <td>5.333500e+10</td>\n",
       "      <td>5.333500e+10</td>\n",
       "      <td>5.333500e+10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>5.381100e+10</td>\n",
       "      <td>5.381100e+10</td>\n",
       "      <td>5.381100e+10</td>\n",
       "      <td>5.381100e+10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       yfinance           fmp      intrinio       polygon\n",
       "0  5.535600e+10  5.535600e+10  5.535600e+10  5.535600e+10\n",
       "1  5.333500e+10  5.333500e+10  5.333500e+10  5.333500e+10\n",
       "2  5.381100e+10  5.381100e+10  5.381100e+10  5.381100e+10"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.DataFrame()\n",
    "\n",
    "df[\"yfinance\"] = (\n",
    "    obb.equity.fundamental.balance(\n",
    "        \"TGT\", provider=\"yfinance\"\n",
    "    )  # There is no limit for yFinance, historical data is limited.\n",
    "    .to_df()\n",
    "    .get(\"total_assets\")\n",
    "    .head(3)\n",
    ")\n",
    "\n",
    "df[\"fmp\"] = (\n",
    "    obb.equity.fundamental.balance(\"TGT\", provider=\"fmp\", limit=3)\n",
    "    .to_df()\n",
    "    .get(\"total_assets\")\n",
    ")\n",
    "\n",
    "df[\"intrinio\"] = (\n",
    "    obb.equity.fundamental.balance(\"TGT\", provider=\"intrinio\", limit=3)\n",
    "    .to_df()\n",
    "    .get(\"total_assets\")\n",
    ")\n",
    "\n",
    "df[\"polygon\"] = (\n",
    "    obb.equity.fundamental.balance(\"TGT\", provider=\"polygon\", limit=3)\n",
    "    .to_df()\n",
    "    .get(\"total_assets\")\n",
    ")\n",
    "\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Weighted Average Shares Outstanding\n",
    "\n",
    "This key metric will be found under the income statement.  It might also be called, 'basic', and the numbers do not include authorized but unissued shares.  A declining count over time is a sign that the company is returning capital to shareholders in the form of buy backs.  Under ideal circumstances, it is more capital-efficient, for both company and shareholders, because distributions are double-taxed.  The company pays income tax on paid dividends, and the beneficiary pays income tax again on receipt.\n",
    "\n",
    "A company will disclose how many shares are outstanding at the end of the period  as a weighted average over the reporting period - three months.\n",
    "\n",
    "Let's take a look at Target.  To make the numbers easier to read, we'll divide the entire column by one million."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    462.5\n",
       "Name: weighted_average_basic_shares_outstanding, dtype: float64"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "149    1169.248\n",
       "Name: weighted_average_basic_shares_outstanding, dtype: float64"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "data = obb.equity.fundamental.income(\n",
    "    \"TGT\", provider=\"fmp\", limit=150, period=\"quarter\"\n",
    ").to_df()\n",
    "\n",
    "shares = data[\"weighted_average_basic_shares_outstanding\"] / 1000000\n",
    "\n",
    "display(shares.head(1))\n",
    "\n",
    "display(shares.tail(1))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Thirty-seven years later, the share count is approaching a two-thirds reduction.  12.2% over the past five years.  In four reporting periods, 1.3 million shares have been taken out of the float."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.3362834285714287"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "-65.75199999999995"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display(shares.pct_change(20).iloc[-1])\n",
    "\n",
    "display(shares.iloc[-4] - shares.iloc[-1])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "With an average closing price of $143.37, that represents approximately $190M in buy backs."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "190.75"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "price = obb.equity.price.historical(\n",
    "    \"TGT\", start_date=\"2022-10-01\", provider=\"fmp\"\n",
    ").to_df()\n",
    "\n",
    "round((price[\"close\"].mean() * 1300000) / 1000000, 2)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Dividends Paid\n",
    "\n",
    "Dividends paid is in the cash flow statement.  We can calculate the amount-per-share with the reported data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "136    0.040339\n",
       "137    0.023793\n",
       "138    0.020690\n",
       "139    0.022969\n",
       "Name: div_per_share, dtype: float64"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "dividends = obb.equity.fundamental.cash(\n",
    "    \"TGT\", provider=\"fmp\", limit=150, period=\"quarter\"\n",
    ").to_df()[[\"payment_of_dividends\"]]\n",
    "\n",
    "dividends[\"shares\"] = data[[\"weighted_average_basic_shares_outstanding\"]]\n",
    "dividends[\"div_per_share\"] = abs(\n",
    "    dividends[\"payment_of_dividends\"] / dividends[\"shares\"]\n",
    ")\n",
    "\n",
    "dividends[\"div_per_share\"].tail(4)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This can be compared against the real amounts paid to common share holders, as announced.  Note that the dates above represent the report date, and that dividends paid are attributed to the quarter they were paid in.  The value from \"2023-01-28\" equates to the fourth quarter of 2022."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>amount</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ex_dividend_date</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2023-08-15</th>\n",
       "      <td>1.10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-05-16</th>\n",
       "      <td>1.08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-02-14</th>\n",
       "      <td>1.08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-11-15</th>\n",
       "      <td>1.08</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  amount\n",
       "ex_dividend_date        \n",
       "2023-08-15          1.10\n",
       "2023-05-16          1.08\n",
       "2023-02-14          1.08\n",
       "2022-11-15          1.08"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = obb.equity.fundamental.dividends(\"TGT\", provider=\"fmp\").to_df()[\n",
    "    [\"ex_dividend_date\", \"amount\"]\n",
    "]\n",
    "data.ex_dividend_date = data.ex_dividend_date.astype(str)\n",
    "data.set_index(\"ex_dividend_date\").loc[\"2023-08-15\":\"2022-11-15\"]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The numbers check out, and the $2B paid to investors over four quarters is more than ten times the $190M returned through share buy backs.\n",
    "\n",
    "### Financial Attributes\n",
    "\n",
    "The `openbb-intrinio` data extension has an endpoint for extracting a single fact from financial statements.  There is a helper function for looking up the correct `tag`.\n",
    "\n",
    "**Note:** Intrinio does not offer a free API level with access to data.\n",
    "\n",
    "#### Search Financial Attributes\n",
    "\n",
    "Search attributes by keyword."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>name</th>\n",
       "      <th>tag</th>\n",
       "      <th>statement_code</th>\n",
       "      <th>statement_type</th>\n",
       "      <th>type</th>\n",
       "      <th>unit</th>\n",
       "      <th>parent_name</th>\n",
       "      <th>sequence</th>\n",
       "      <th>factor</th>\n",
       "      <th>transaction</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>tag_BgkbWy</td>\n",
       "      <td>Market Capitalization</td>\n",
       "      <td>marketcap</td>\n",
       "      <td>calculations</td>\n",
       "      <td>industrial</td>\n",
       "      <td>valuation</td>\n",
       "      <td>usd</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>tag_kylOqz</td>\n",
       "      <td>Market Capitalization</td>\n",
       "      <td>marketcap</td>\n",
       "      <td>calculations</td>\n",
       "      <td>financial</td>\n",
       "      <td>valuation</td>\n",
       "      <td>usd</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>tag_XLRlqy</td>\n",
       "      <td>Market Sector</td>\n",
       "      <td>market_sector</td>\n",
       "      <td>current</td>\n",
       "      <td>NaN</td>\n",
       "      <td>security</td>\n",
       "      <td>string</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>tag_2gBA8y</td>\n",
       "      <td>Market Category</td>\n",
       "      <td>market_category</td>\n",
       "      <td>current</td>\n",
       "      <td>NaN</td>\n",
       "      <td>security</td>\n",
       "      <td>string</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>tag_DzonXe</td>\n",
       "      <td>Marketing Expense</td>\n",
       "      <td>marketingexpense</td>\n",
       "      <td>income_statement</td>\n",
       "      <td>industrial</td>\n",
       "      <td>income_statement_metric</td>\n",
       "      <td>usd</td>\n",
       "      <td>totaloperatingexpenses</td>\n",
       "      <td>9.0</td>\n",
       "      <td>+</td>\n",
       "      <td>debit</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>95</th>\n",
       "      <td>tag_nzJAmX</td>\n",
       "      <td>Total Long-Term Debt</td>\n",
       "      <td>ltdebtandcapleases</td>\n",
       "      <td>calculations</td>\n",
       "      <td>financial</td>\n",
       "      <td>metric</td>\n",
       "      <td>usd</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>96</th>\n",
       "      <td>tag_9XaL5g</td>\n",
       "      <td>Other Net Changes in Cash</td>\n",
       "      <td>othernetchangesincash</td>\n",
       "      <td>cash_flow_statement</td>\n",
       "      <td>industrial</td>\n",
       "      <td>cash_flow_statement_metric</td>\n",
       "      <td>usd</td>\n",
       "      <td>netchangeincash</td>\n",
       "      <td>33.0</td>\n",
       "      <td>+</td>\n",
       "      <td>debit</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>97</th>\n",
       "      <td>tag_5X7p6z</td>\n",
       "      <td>Other Net Changes in Cash</td>\n",
       "      <td>othernetchangesincash</td>\n",
       "      <td>cash_flow_statement</td>\n",
       "      <td>financial</td>\n",
       "      <td>cash_flow_statement_metric</td>\n",
       "      <td>usd</td>\n",
       "      <td>netchangeincash</td>\n",
       "      <td>37.0</td>\n",
       "      <td>+</td>\n",
       "      <td>debit</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>98</th>\n",
       "      <td>tag_qzEwng</td>\n",
       "      <td>Changes in Operating Assets and Liabilities, net</td>\n",
       "      <td>increasedecreaseinoperatingcapital</td>\n",
       "      <td>cash_flow_statement</td>\n",
       "      <td>financial</td>\n",
       "      <td>cash_flow_statement_metric</td>\n",
       "      <td>usd</td>\n",
       "      <td>netcashfromcontinuingoperatingactivities</td>\n",
       "      <td>8.0</td>\n",
       "      <td>+</td>\n",
       "      <td>debit</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>tag_pgVB2g</td>\n",
       "      <td>Changes in Operating Assets and Liabilities, net</td>\n",
       "      <td>increasedecreaseinoperatingcapital</td>\n",
       "      <td>cash_flow_statement</td>\n",
       "      <td>industrial</td>\n",
       "      <td>cash_flow_statement_metric</td>\n",
       "      <td>usd</td>\n",
       "      <td>netcashfromcontinuingoperatingactivities</td>\n",
       "      <td>7.0</td>\n",
       "      <td>+</td>\n",
       "      <td>debit</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>100 rows × 11 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            id                                              name  \\\n",
       "0   tag_BgkbWy                             Market Capitalization   \n",
       "1   tag_kylOqz                             Market Capitalization   \n",
       "2   tag_XLRlqy                                     Market Sector   \n",
       "3   tag_2gBA8y                                   Market Category   \n",
       "4   tag_DzonXe                                 Marketing Expense   \n",
       "..         ...                                               ...   \n",
       "95  tag_nzJAmX                              Total Long-Term Debt   \n",
       "96  tag_9XaL5g                         Other Net Changes in Cash   \n",
       "97  tag_5X7p6z                         Other Net Changes in Cash   \n",
       "98  tag_qzEwng  Changes in Operating Assets and Liabilities, net   \n",
       "99  tag_pgVB2g  Changes in Operating Assets and Liabilities, net   \n",
       "\n",
       "                                   tag       statement_code statement_type  \\\n",
       "0                            marketcap         calculations     industrial   \n",
       "1                            marketcap         calculations      financial   \n",
       "2                        market_sector              current            NaN   \n",
       "3                      market_category              current            NaN   \n",
       "4                     marketingexpense     income_statement     industrial   \n",
       "..                                 ...                  ...            ...   \n",
       "95                  ltdebtandcapleases         calculations      financial   \n",
       "96               othernetchangesincash  cash_flow_statement     industrial   \n",
       "97               othernetchangesincash  cash_flow_statement      financial   \n",
       "98  increasedecreaseinoperatingcapital  cash_flow_statement      financial   \n",
       "99  increasedecreaseinoperatingcapital  cash_flow_statement     industrial   \n",
       "\n",
       "                          type    unit  \\\n",
       "0                    valuation     usd   \n",
       "1                    valuation     usd   \n",
       "2                     security  string   \n",
       "3                     security  string   \n",
       "4      income_statement_metric     usd   \n",
       "..                         ...     ...   \n",
       "95                      metric     usd   \n",
       "96  cash_flow_statement_metric     usd   \n",
       "97  cash_flow_statement_metric     usd   \n",
       "98  cash_flow_statement_metric     usd   \n",
       "99  cash_flow_statement_metric     usd   \n",
       "\n",
       "                                 parent_name  sequence factor transaction  \n",
       "0                                        NaN       NaN    NaN         NaN  \n",
       "1                                        NaN       NaN    NaN         NaN  \n",
       "2                                        NaN       NaN    NaN         NaN  \n",
       "3                                        NaN       NaN    NaN         NaN  \n",
       "4                     totaloperatingexpenses       9.0      +       debit  \n",
       "..                                       ...       ...    ...         ...  \n",
       "95                                       NaN       NaN    NaN         NaN  \n",
       "96                           netchangeincash      33.0      +       debit  \n",
       "97                           netchangeincash      37.0      +       debit  \n",
       "98  netcashfromcontinuingoperatingactivities       8.0      +       debit  \n",
       "99  netcashfromcontinuingoperatingactivities       7.0      +       debit  \n",
       "\n",
       "[100 rows x 11 columns]"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(obb.equity.fundamental.search_attributes(\"marketcap\", provider=\"intrinio\").to_df())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The `tag` is what we need, in this case it is what we searched for."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>symbol</th>\n",
       "      <th>tag</th>\n",
       "      <th>value</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2023-09-30</th>\n",
       "      <td>TGT</td>\n",
       "      <td>marketcap</td>\n",
       "      <td>4.951153e+10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-31</th>\n",
       "      <td>TGT</td>\n",
       "      <td>marketcap</td>\n",
       "      <td>6.443403e+10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-03-31</th>\n",
       "      <td>TGT</td>\n",
       "      <td>marketcap</td>\n",
       "      <td>8.082004e+10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-30</th>\n",
       "      <td>TGT</td>\n",
       "      <td>marketcap</td>\n",
       "      <td>6.814283e+10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-08-22</th>\n",
       "      <td>TGT</td>\n",
       "      <td>marketcap</td>\n",
       "      <td>7.387608e+10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           symbol        tag         value\n",
       "date                                      \n",
       "2023-09-30    TGT  marketcap  4.951153e+10\n",
       "2023-12-31    TGT  marketcap  6.443403e+10\n",
       "2024-03-31    TGT  marketcap  8.082004e+10\n",
       "2024-06-30    TGT  marketcap  6.814283e+10\n",
       "2024-08-22    TGT  marketcap  7.387608e+10"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "marketcap = obb.equity.fundamental.historical_attributes(\n",
    "    symbol=\"TGT\", tag=\"marketcap\", frequency=\"quarterly\", provider=\"intrinio\"\n",
    ").to_df()\n",
    "\n",
    "marketcap.tail(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Doing some quick math, and ignoring the most recent value, we can see that the market cap of Target was down nearly a quarter over the last four reporting periods."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "-0.243767327909974"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "marketcap.index = marketcap.index.astype(str)\n",
    "(\n",
    "    (marketcap.loc[\"2023-09-30\"].value - marketcap.loc[\"2022-12-31\"].value)\n",
    "    / marketcap.loc[\"2022-12-31\"].value\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Historial market cap is also available as a daily metric from FMP. We can resample it as quarterly to approximate the same results."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>market_cap</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>date</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2022-03-31</th>\n",
       "      <td>98470080000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-06-30</th>\n",
       "      <td>65177644999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-09-30</th>\n",
       "      <td>68303916999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2022-12-31</th>\n",
       "      <td>68603112000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-03-31</th>\n",
       "      <td>76338867000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-06-30</th>\n",
       "      <td>60885040000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-09-30</th>\n",
       "      <td>51039112000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-31</th>\n",
       "      <td>65755313999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-03-31</th>\n",
       "      <td>81906462000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-06-30</th>\n",
       "      <td>68424088000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2024-09-30</th>\n",
       "      <td>73653125000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             market_cap\n",
       "date                   \n",
       "2022-03-31  98470080000\n",
       "2022-06-30  65177644999\n",
       "2022-09-30  68303916999\n",
       "2022-12-31  68603112000\n",
       "2023-03-31  76338867000\n",
       "2023-06-30  60885040000\n",
       "2023-09-30  51039112000\n",
       "2023-12-31  65755313999\n",
       "2024-03-31  81906462000\n",
       "2024-06-30  68424088000\n",
       "2024-09-30  73653125000"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "market_cap   -0.256023\n",
       "dtype: float64"
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = obb.equity.historical_market_cap(\n",
    "    \"TGT\", start_date=\"2022-01-01\", provider=\"fmp\"\n",
    ").to_df()\n",
    "\n",
    "resampled = df.copy()\n",
    "resampled.index = pd.to_datetime(resampled.index)\n",
    "resampled = resampled[[\"market_cap\"]]\n",
    "resampled = resampled.resample(\"QE\").last()\n",
    "resampled.index = resampled.index.astype(str)\n",
    "display(resampled)\n",
    "(\n",
    "    (resampled.loc[\"2023-09-30\"] - resampled.loc[\"2022-12-31\"])\n",
    "    / resampled.loc[\"2022-12-31\"]\n",
    ")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Ratios and Other Metrics\n",
    "\n",
    "Other valuation functions are derivatives of the financial statements, but the data provider does the math.  Values are typically ratios between line items, on a per-share basis, or as a percent growth.\n",
    "\n",
    "This data set is where you can find EPS, FCF, P/B, EBIT, quick ratio, etc.\n",
    "\n",
    "### Quick Ratio\n",
    "\n",
    "Target's quick ratio could be one reason why its share price is losing traction against the market.  Its ability to pay current obligations is not optimistically reflected in a 0.27 score, approximately 50% below the historical median."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Current Quick Ratio: 0.8998'"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/plain": [
       "'Median Quick Ratio: 0.6047'"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "ratios = obb.equity.fundamental.ratios(\"TGT\", limit=50, provider=\"fmp\").to_df()\n",
    "\n",
    "display(f\"Current Quick Ratio: {round(ratios['quick_ratio'].iloc[-1], 4)}\")\n",
    "display(f\"Median Quick Ratio: {round(ratios['quick_ratio'].median(), 4)}\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Free Cash Flow Yield\n",
    "\n",
    "The `metrics` endpoint, with the `openbb-fmp` data extension, has a field for free cash flow yield.  It is calculated by taking the free cash flow per share divided by the current share price.  We could arrive at this answer by writing some code, but these types of endpoints do the work so we don't have to.  This is part of the value-add that API data distributors provide, they allow you to get straight to work with data.\n",
    "\n",
    "We'll use this endpoint to extract the data, and compare with some of Target's competition over the last ten years."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th>calendar_year</th>\n",
       "      <th>2023</th>\n",
       "      <th>2022</th>\n",
       "      <th>2021</th>\n",
       "      <th>2020</th>\n",
       "      <th>2019</th>\n",
       "      <th>2018</th>\n",
       "      <th>2017</th>\n",
       "      <th>2016</th>\n",
       "      <th>2015</th>\n",
       "      <th>2014</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>COST</th>\n",
       "      <td>0.027922</td>\n",
       "      <td>0.014860</td>\n",
       "      <td>0.026582</td>\n",
       "      <td>0.039351</td>\n",
       "      <td>0.025906</td>\n",
       "      <td>0.027438</td>\n",
       "      <td>0.060884</td>\n",
       "      <td>0.008941</td>\n",
       "      <td>0.030741</td>\n",
       "      <td>0.037483</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>BJ</th>\n",
       "      <td>0.029338</td>\n",
       "      <td>0.044709</td>\n",
       "      <td>0.067213</td>\n",
       "      <td>0.113551</td>\n",
       "      <td>0.056631</td>\n",
       "      <td>0.091107</td>\n",
       "      <td>0.026186</td>\n",
       "      <td>0.065871</td>\n",
       "      <td>0.016947</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DLTR</th>\n",
       "      <td>0.018948</td>\n",
       "      <td>0.010756</td>\n",
       "      <td>0.013957</td>\n",
       "      <td>0.075627</td>\n",
       "      <td>0.040338</td>\n",
       "      <td>0.041252</td>\n",
       "      <td>0.034069</td>\n",
       "      <td>0.063465</td>\n",
       "      <td>0.016602</td>\n",
       "      <td>0.041047</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DG</th>\n",
       "      <td>0.023149</td>\n",
       "      <td>0.008256</td>\n",
       "      <td>0.037507</td>\n",
       "      <td>0.058973</td>\n",
       "      <td>0.036922</td>\n",
       "      <td>0.046197</td>\n",
       "      <td>0.042609</td>\n",
       "      <td>0.050776</td>\n",
       "      <td>0.039524</td>\n",
       "      <td>0.046052</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>WMT</th>\n",
       "      <td>0.030577</td>\n",
       "      <td>0.028374</td>\n",
       "      <td>0.065467</td>\n",
       "      <td>0.044595</td>\n",
       "      <td>0.062030</td>\n",
       "      <td>0.057280</td>\n",
       "      <td>0.101023</td>\n",
       "      <td>0.073506</td>\n",
       "      <td>0.059705</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>BIG</th>\n",
       "      <td>-1.856996</td>\n",
       "      <td>-0.624151</td>\n",
       "      <td>0.025262</td>\n",
       "      <td>0.115757</td>\n",
       "      <td>0.069464</td>\n",
       "      <td>-0.111853</td>\n",
       "      <td>0.037219</td>\n",
       "      <td>0.100721</td>\n",
       "      <td>0.110443</td>\n",
       "      <td>0.089253</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>0.061077</td>\n",
       "      <td>0.050473</td>\n",
       "      <td>0.270980</td>\n",
       "      <td>0.039111</td>\n",
       "      <td>0.091301</td>\n",
       "      <td>0.101426</td>\n",
       "      <td>0.155761</td>\n",
       "      <td>0.098993</td>\n",
       "      <td>0.065634</td>\n",
       "      <td>0.072322</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>KSS</th>\n",
       "      <td>0.203512</td>\n",
       "      <td>-0.143961</td>\n",
       "      <td>0.189677</td>\n",
       "      <td>0.147968</td>\n",
       "      <td>0.119492</td>\n",
       "      <td>0.139799</td>\n",
       "      <td>0.096137</td>\n",
       "      <td>0.198790</td>\n",
       "      <td>0.081652</td>\n",
       "      <td>0.110697</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>TJX</th>\n",
       "      <td>0.027513</td>\n",
       "      <td>0.023498</td>\n",
       "      <td>0.051975</td>\n",
       "      <td>0.039865</td>\n",
       "      <td>0.049788</td>\n",
       "      <td>0.039930</td>\n",
       "      <td>0.053697</td>\n",
       "      <td>0.043328</td>\n",
       "      <td>0.046442</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "calendar_year      2023      2022      2021      2020      2019      2018  \\\n",
       "COST           0.027922  0.014860  0.026582  0.039351  0.025906  0.027438   \n",
       "BJ             0.029338  0.044709  0.067213  0.113551  0.056631  0.091107   \n",
       "DLTR           0.018948  0.010756  0.013957  0.075627  0.040338  0.041252   \n",
       "DG             0.023149  0.008256  0.037507  0.058973  0.036922  0.046197   \n",
       "WMT            0.030577  0.028374  0.065467  0.044595  0.062030  0.057280   \n",
       "BIG           -1.856996 -0.624151  0.025262  0.115757  0.069464 -0.111853   \n",
       "M              0.061077  0.050473  0.270980  0.039111  0.091301  0.101426   \n",
       "KSS            0.203512 -0.143961  0.189677  0.147968  0.119492  0.139799   \n",
       "TJX            0.027513  0.023498  0.051975  0.039865  0.049788  0.039930   \n",
       "\n",
       "calendar_year      2017      2016      2015      2014  \n",
       "COST           0.060884  0.008941  0.030741  0.037483  \n",
       "BJ             0.026186  0.065871  0.016947       NaN  \n",
       "DLTR           0.034069  0.063465  0.016602  0.041047  \n",
       "DG             0.042609  0.050776  0.039524  0.046052  \n",
       "WMT            0.101023  0.073506  0.059705       NaN  \n",
       "BIG            0.037219  0.100721  0.110443  0.089253  \n",
       "M              0.155761  0.098993  0.065634  0.072322  \n",
       "KSS            0.096137  0.198790  0.081652  0.110697  \n",
       "TJX            0.053697  0.043328  0.046442       NaN  "
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# List of other retail chains\n",
    "tickers = [\"COST\", \"BJ\", \"DLTR\", \"DG\", \"WMT\", \"BIG\", \"M\", \"KSS\", \"TJX\"]\n",
    "\n",
    "# Create a column for each.\n",
    "fcf_yield = pd.DataFrame()\n",
    "for ticker in tickers:\n",
    "    fcf_yield[ticker] = (\n",
    "        obb.equity.fundamental.metrics(\n",
    "            ticker, provider=\"fmp\", period=\"annual\", limit=10\n",
    "        )\n",
    "        .to_df()\n",
    "        .reset_index()\n",
    "        .set_index(\"calendar_year\")\n",
    "        .sort_index(ascending=False)[\"free_cash_flow_yield\"]\n",
    "    )\n",
    "fcf_yield.transpose()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "There are more usage examples on our [website](https://docs.openbb.co/platform/user_guides)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "obb-sdk4",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}