Data Sources
Base Interface
interface
DataSource
Bases: ABC
Base class for all data sources.
Source code in src/quantrl_lab/data/interface.py
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 | |
source_name
abstractmethod
property
Return the name of this data source.
supported_features
property
Return a list of supported features.
connect()
Connect to the data source.
Default implementation for sources that don't require connections. Override this method if your data source needs connection management.
disconnect()
Disconnect from the data source.
Default implementation for sources that don't require connections. Override this method if your data source needs connection management.
is_connected()
Check if the data source is currently connected.
Returns:
| Type | Description |
|---|---|
bool
|
True for sources that don't require connections (always available). |
bool
|
Override this method if your data source needs connection management. |
Source code in src/quantrl_lab/data/interface.py
list_available_instruments(instrument_type=None, market=None, **kwargs)
Return a list of available instrument symbols or identifiers that this source can provide data for.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instrument_type
|
Optional[str]
|
Optional filter by type (e.g., 'stock', 'future', 'option', 'crypto', 'forex'). |
None
|
market
|
Optional[str]
|
Optional filter by market (e.g., 'NASDAQ', 'NYSE', 'crypto_spot', 'crypto_futures'). |
None
|
**kwargs
|
Any
|
Provider-specific additional filter parameters. |
{}
|
Returns:
| Type | Description |
|---|---|
List[str]
|
A list of string identifiers for the available instruments. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
If the data source doesn't support instrument discovery. |
Source code in src/quantrl_lab/data/interface.py
supports_feature(feature_name)
__repr__()
Return a string representation of the data source.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A string representation of the data source. |
Source code in src/quantrl_lab/data/interface.py
ConnectionManaged
Bases: Protocol
Protocol for data sources that require explicit connection management.
Sources implementing this protocol need to manage persistent connections, authentication sessions, or other stateful connections.
Source code in src/quantrl_lab/data/interface.py
connect()
disconnect()
HistoricalDataCapable
Bases: Protocol
Protocol for data sources that provide historical OHLCV data.
Source code in src/quantrl_lab/data/interface.py
get_historical_ohlcv_data(symbols, start=None, end=None, timeframe='1d', **kwargs)
Get historical OHLCV data.
Source code in src/quantrl_lab/data/interface.py
NewsDataCapable
Bases: Protocol
Protocol for data sources that provide news data.
Source code in src/quantrl_lab/data/interface.py
get_news_data(symbols, start, end=None, **kwargs)
Get news for specified symbols and time range.
LiveDataCapable
Bases: Protocol
Protocol for data sources with real-time data capabilities.
It checks if the class has the following methods: - get_latest_quote - get_latest_trade
Source code in src/quantrl_lab/data/interface.py
get_latest_quote(symbols, **kwargs)
StreamingCapable
Bases: Protocol
Protocol for data sources with streaming capabilities.
It checks if the class has the following methods: - subscribe_to_updates - start_streaming - stop
Source code in src/quantrl_lab/data/interface.py
subscribe_to_updates(symbol, data_type='trades', **kwargs)
async
start_streaming()
async
FundamentalDataCapable
Bases: Protocol
Protocol for data sources that provide fundamental data.
It checks if the class has the following methods: - get_fundamental_data
Source code in src/quantrl_lab/data/interface.py
get_fundamental_data(symbols, metrics, **kwargs)
MacroDataCapable
Bases: Protocol
Protocol for data sources that provide macroeconomic data.
It checks if the class has the following methods: - get_macro_data
Source code in src/quantrl_lab/data/interface.py
get_macro_data(indicators, start, end)
Get macroeconomic data for specified indicators and time range.
AnalystDataCapable
Bases: Protocol
Protocol for data sources that provide analyst ratings and grades data.
This includes analyst recommendations, upgrades/downgrades, price targets, and other research-based insights from financial analysts.
It checks if the class has the following methods: - get_historical_grades - get_historical_rating
Source code in src/quantrl_lab/data/interface.py
get_historical_grades(symbol, **kwargs)
Get historical analyst grades/recommendations for a symbol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Stock symbol to fetch grades for |
required |
**kwargs
|
Any
|
Additional provider-specific parameters |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Historical analyst grades data |
Source code in src/quantrl_lab/data/interface.py
get_historical_rating(symbol, limit=100, **kwargs)
Get historical analyst ratings for a symbol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Stock symbol to fetch ratings for |
required |
limit
|
int
|
Number of records to return (default: 100) |
100
|
**kwargs
|
Any
|
Additional provider-specific parameters |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Historical analyst ratings data |
Source code in src/quantrl_lab/data/interface.py
SectorDataCapable
Bases: Protocol
Protocol for data sources that provide sector and industry performance data.
This includes historical performance metrics for market sectors and industries, enabling sector rotation and market trend analysis.
It checks if the class has the following methods: - get_historical_sector_performance - get_historical_industry_performance
Source code in src/quantrl_lab/data/interface.py
get_historical_sector_performance(sector, **kwargs)
Get historical performance data for a specific market sector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sector
|
str
|
Market sector name (e.g., "Energy", "Technology", "Healthcare") |
required |
**kwargs
|
Any
|
Additional provider-specific parameters |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Historical sector performance data |
Source code in src/quantrl_lab/data/interface.py
get_historical_industry_performance(industry, **kwargs)
Get historical performance data for a specific industry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
industry
|
str
|
Industry name (e.g., "Biotechnology", "Software", "Banks") |
required |
**kwargs
|
Any
|
Additional provider-specific parameters |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Historical industry performance data |
Source code in src/quantrl_lab/data/interface.py
CompanyProfileCapable
Bases: Protocol
Protocol for data sources that provide company profile and metadata.
This includes company information such as sector/industry classification, executive information, key financial metrics, and company details.
It checks if the class has the following method: - get_company_profile
Source code in src/quantrl_lab/data/interface.py
get_company_profile(symbol, **kwargs)
Get company profile information including sector, industry, and key metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
Union[str, List[str]]
|
Stock ticker symbol or list of symbols |
required |
**kwargs
|
Any
|
Additional provider-specific parameters |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Company profile data with metadata |
Source code in src/quantrl_lab/data/interface.py
Data Loaders
Alpaca
alpaca_loader
AlpacaDataLoader
Bases: DataSource, HistoricalDataCapable, LiveDataCapable, StreamingCapable, NewsDataCapable, ConnectionManaged
Alpaca implementation that provides market data from Alpaca APIs.
Source code in src/quantrl_lab/data/sources/alpaca_loader.py
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 | |
connect()
Connect to the historical data client of Alpaca.
Reinitializes the stock historical client with current credentials.
Raises:
| Type | Description |
|---|---|
AuthenticationError
|
If API credentials are not provided. |
Source code in src/quantrl_lab/data/sources/alpaca_loader.py
disconnect()
is_connected()
Check if the historical client is initialized and credentials are valid.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the client is initialized with valid credentials, False otherwise. |
Source code in src/quantrl_lab/data/sources/alpaca_loader.py
get_historical_ohlcv_data(symbols, start=None, end=None, timeframe='1d', **kwargs)
Get historical OHLCV data from Alpaca.
end is not compulsory and defaults to today if not provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbols
|
Union[str, List[str]]
|
Stock symbol(s) to fetch data for. |
required |
start
|
Union[str, datetime]
|
Start date for historical data. |
None
|
end
|
Union[str, datetime]
|
End date for historical data. Defaults to today. |
None
|
timeframe
|
str
|
The bar timeframe (1d, 1h, 1m, etc.). Defaults to "1d". |
'1d'
|
**kwargs
|
Any
|
Additional arguments to pass to Alpaca API. |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Raw OHLCV data. |
Source code in src/quantrl_lab/data/sources/alpaca_loader.py
get_latest_quote(symbol, **kwargs)
Get the latest quote for a symbol from Alpaca.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Stock symbol to fetch quote for. |
required |
**kwargs
|
Any
|
Additional arguments such as feed type. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Dict |
Dict
|
Output dictionary. |
Source code in src/quantrl_lab/data/sources/alpaca_loader.py
get_latest_trade(symbol, **kwargs)
Get the latest trade for a symbol from Alpaca.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Stock symbol to fetch trade for. |
required |
**kwargs
|
Any
|
Additional arguments such as feed type. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Dict |
Dict
|
Output dictionary. |
Source code in src/quantrl_lab/data/sources/alpaca_loader.py
subscribe_to_updates(symbol, data_type='trades')
async
Subscribe to real-time market data updates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
The stock symbol to subscribe to. |
required |
data_type
|
str
|
The type of data to subscribe to ('trades', 'quotes', 'bars'). Defaults to "trades". |
'trades'
|
Source code in src/quantrl_lab/data/sources/alpaca_loader.py
start_streaming()
async
Initialize, subscribe, and run the data stream.
Source code in src/quantrl_lab/data/sources/alpaca_loader.py
stop_streaming()
async
Stop the WebSocket connection and clean up resources.
Source code in src/quantrl_lab/data/sources/alpaca_loader.py
get_news_data(symbols, start, end=None, limit=50, include_content=False, verbose=False, silent_errors=False, **kwargs)
Get news for specified symbols from Alpaca News API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbols
|
Union[str, List[str]]
|
Stock symbol(s) to fetch news for. |
required |
start
|
Union[str, datetime]
|
Start date for news. |
required |
end
|
Union[str, datetime]
|
End date for news. Defaults to today. |
None
|
limit
|
int
|
Number of news items per request. Defaults to 50. |
50
|
include_content
|
bool
|
Whether to include full article content. Defaults to False. |
False
|
verbose
|
bool
|
Whether to log progress. Defaults to False. |
False
|
silent_errors
|
bool
|
Whether to suppress connection errors. Defaults to False. |
False
|
**kwargs
|
Any
|
Additional parameters. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[DataFrame, Dict]
|
pd.DataFrame: News data. |
Source code in src/quantrl_lab/data/sources/alpaca_loader.py
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 | |
async_fetch_news(session, symbol, start, end=None, limit=50, include_content=False)
async
Async fetch of Alpaca news for a single symbol.
Ports the pagination loop from get_news_data() using aiohttp instead of requests, keeping the event loop free during I/O waits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
ClientSession
|
Shared aiohttp session. |
required |
symbol
|
str
|
Stock symbol to fetch news for. |
required |
start
|
Union[str, datetime]
|
Start date for news. |
required |
end
|
Union[str, datetime]
|
End date for news. Defaults to today. |
None
|
limit
|
int
|
Number of news items per request. Defaults to 50. |
50
|
include_content
|
bool
|
Whether to include full article content. Defaults to False. |
False
|
Returns:
| Type | Description |
|---|---|
Tuple[str, DataFrame]
|
Tuple[str, pd.DataFrame]: Tuple of (symbol, DataFrame). DataFrame is empty on failure. |
Source code in src/quantrl_lab/data/sources/alpaca_loader.py
YFinance
yfinance_loader
YFinanceDataLoader
Bases: DataSource, FundamentalDataCapable, HistoricalDataCapable
Yahoo Finance implementation that provides market data and fundamental data.
Source code in src/quantrl_lab/data/sources/yfinance_loader.py
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 | |
connect()
disconnect()
is_connected()
get_fundamental_data(symbol, frequency='quarterly', **kwargs)
Get all fundamental data for a symbol including income statement, cash flow, and balance sheet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Stock symbol; only a single symbol is supported. |
required |
frequency
|
str
|
Frequency of data. Defaults to "quarterly". |
'quarterly'
|
**kwargs
|
Any
|
Additional yfinance parameters. |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: DataFrame with raw fundamental data. |
Source code in src/quantrl_lab/data/sources/yfinance_loader.py
get_historical_ohlcv_data(symbols, start=None, end=None, timeframe='1d', **kwargs)
Get historical OHLCV data for a list of symbols.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbols
|
Union[str, List[str]]
|
A single symbol or a list of symbols. |
required |
start
|
Union[str, datetime]
|
Start date or datetime. |
None
|
end
|
Union[str, datetime]
|
End date or datetime. |
None
|
timeframe
|
str
|
Bar interval. Defaults to "1d". |
'1d'
|
**kwargs
|
Any
|
Additional yfinance parameters, including 'period' (e.g., '1y', 'max'). |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Output dataframe with OHLCV data (raw). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If all elements in 'symbols' are not strings. |
TypeError
|
If 'symbols' is not a string or list of strings. |
ValueError
|
If interval is invalid. |
ValueError
|
If start or end date is invalid. |
ValueError
|
If start date is not before end date. |
ValueError
|
If 1 min interval start date is not within 30 days from today. |
Source code in src/quantrl_lab/data/sources/yfinance_loader.py
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 | |
async_fetch_ohlcv(symbol, start=None, end=None, timeframe='1d')
async
Async wrapper around yfinance OHLCV fetch for a single symbol.
Uses asyncio.to_thread() to run the blocking yfinance SDK call in a background thread, keeping the event loop free for concurrent fetches.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Stock symbol to fetch. |
required |
start
|
Union[str, datetime]
|
Start date or datetime. |
None
|
end
|
Union[str, datetime]
|
End date or datetime. |
None
|
timeframe
|
str
|
Bar interval. Defaults to "1d". |
'1d'
|
Returns:
| Type | Description |
|---|---|
Tuple[str, DataFrame]
|
Tuple[str, pd.DataFrame]: Tuple of (symbol, DataFrame). DataFrame is empty on failure. |
Source code in src/quantrl_lab/data/sources/yfinance_loader.py
Alpha Vantage
alpha_vantage_loader
AlphaVantageDataLoader
Bases: DataSource, FundamentalDataCapable, HistoricalDataCapable, MacroDataCapable, NewsDataCapable
Alpha Vantage implementation that provides various datasets.
Source code in src/quantrl_lab/data/sources/alpha_vantage_loader.py
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 | |
connect()
disconnect()
is_connected()
list_available_instruments(instrument_type=None, market=None, **kwargs)
Alpha Vantage does not provide a direct API to list all available instruments.
This method is a placeholder.
Source code in src/quantrl_lab/data/sources/alpha_vantage_loader.py
get_historical_ohlcv_data(symbols, start=None, end=None, timeframe='1d', **kwargs)
Get historical OHLCV data from Alpha Vantage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbols
|
str
|
Stock symbol to fetch data for. |
required |
start
|
Union[str, datetime]
|
Start date for filtering. If None, no start filtering is applied. Defaults to None. |
None
|
end
|
Union[str, datetime]
|
End date for filtering. If None, no end filtering is applied. Defaults to None. |
None
|
timeframe
|
str
|
Time interval - "1d" (daily), or intraday ("1min", "5min", "15min", "30min", "60min"). Defaults to "1d". |
'1d'
|
**kwargs
|
Any
|
Additional parameters. 'adjusted' (bool) enables split/dividend adjustment for daily data (premium). 'outputsize' (str) is "compact" or "full" (premium). 'month' (str, "YYYY-MM") fetches historical intraday month (premium). |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: OHLCV data, optionally filtered by date range. |
Note
outputsize='full' and historical intraday 'month' parameter require a premium API key. Rate limit: 25 requests/day, 1 request/second burst limit on the free tier.
Source code in src/quantrl_lab/data/sources/alpha_vantage_loader.py
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 | |
get_fundamental_data(symbol, metrics, **kwargs)
Get fundamental data for a single symbol by combining multiple Alpha Vantage API calls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Stock symbol to fetch data for. |
required |
metrics
|
List[Union[FundamentalMetric, str]]
|
List of FundamentalMetric enums or strings. |
required |
**kwargs
|
Any
|
Additional parameters. 'return_format' (str) is 'dict' or 'dataframe'. Defaults to 'dict'. |
{}
|
Returns:
| Type | Description |
|---|---|
Union[DataFrame, Dict]
|
Union[pd.DataFrame, Dict]: Dict with combined fundamental data. |
Source code in src/quantrl_lab/data/sources/alpha_vantage_loader.py
get_news_data(symbols, start, end=None, limit=50, **kwargs)
Fetch news data for given symbols from Alpha Vantage.
Retrieves news articles related to the specified symbols within the given date range. Supports additional parameters like 'sort' and 'topics' to customize the news data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbols
|
Union[str, List[str]]
|
Symbols to fetch news for. |
required |
start
|
Union[str, datetime]
|
Start datetime for news data. |
required |
end
|
Union[str, datetime]
|
End datetime for news. Defaults to None (current time). |
None
|
limit
|
int
|
Maximum number of news items to fetch. Defaults to 50. |
50
|
**kwargs
|
Any
|
Additional parameters for the API request, such as 'sort' or 'topics'. |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: DataFrame containing news data for the specified symbols. |
Source code in src/quantrl_lab/data/sources/alpha_vantage_loader.py
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 | |
get_macro_data(indicators, start, end, **kwargs)
Get macroeconomic data for specified indicators.
Supports both standard indicator names and advanced dictionary format where each indicator can have its own parameters, e.g.: {"real_gdp": {"interval": "quarterly"}, "treasury_yield": {"interval": "monthly", "maturity": "10year"}}
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indicators
|
Union[str, List[str], Dict[str, Dict]]
|
Indicator(s) to fetch data for. |
required |
start
|
Union[str, datetime]
|
Start date. |
required |
end
|
Union[str, datetime]
|
End date. |
required |
**kwargs
|
Any
|
Additional parameters for the API request. |
{}
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict[str, Any]: Dictionary containing macroeconomic data for the specified indicators. Each key is the indicator name, and the value is the fetched data. |
Source code in src/quantrl_lab/data/sources/alpha_vantage_loader.py
Financial Modeling Prep (FMP)
fmp_loader
FMPDataSource
Bases: DataSource, HistoricalDataCapable, AnalystDataCapable, SectorDataCapable, CompanyProfileCapable
Financial Modeling Prep data source for historical stock data and analyst insights.
Supports both end-of-day (daily) and intraday data. Intraday timeframes: 5min, 15min, 30min, 1hour, 4hour Daily timeframe: 1d
Implements the following protocols: - HistoricalDataCapable: OHLCV data (daily and intraday) - AnalystDataCapable: Analyst grades and ratings data - SectorDataCapable: Historical sector and industry performance data - CompanyProfileCapable: Company profile and metadata
Source code in src/quantrl_lab/data/sources/fmp_loader.py
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 | |
__init__(api_key=None)
Initialize FMP data source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key
|
str
|
FMP API key. If not provided, will try to read from FMP_API_KEY environment variable. |
None
|
Source code in src/quantrl_lab/data/sources/fmp_loader.py
get_historical_ohlcv_data(symbols, start=None, end=None, timeframe='1d', **kwargs)
Get historical OHLCV data from FMP (daily or intraday).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbols
|
Union[str, List[str]]
|
Stock symbol(s) to fetch data for. |
required |
start
|
Union[str, datetime]
|
Start date for historical data. |
None
|
end
|
Union[str, datetime]
|
End date for historical data. |
None
|
timeframe
|
str
|
Timeframe - "1d" for daily, or intraday: "5min", "15min", "30min", "1hour", "4hour". Defaults to "1d". |
'1d'
|
**kwargs
|
Any
|
Additional arguments including 'nonadjusted' (bool) for intraday data. |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: OHLCV data with standardized column names. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If timeframe is not supported. |
Source code in src/quantrl_lab/data/sources/fmp_loader.py
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 | |
get_historical_grades(symbol)
Get historical analyst grades for a symbol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Stock symbol to fetch data for. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Historical grades data. |
Source code in src/quantrl_lab/data/sources/fmp_loader.py
get_historical_rating(symbol, limit=100)
Get historical ratings for a symbol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
str
|
Stock symbol to fetch data for. |
required |
limit
|
int
|
Number of records to return. Defaults to 100. |
100
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Historical ratings data. |
Source code in src/quantrl_lab/data/sources/fmp_loader.py
get_historical_sector_performance(sector, start=None, end=None)
Get historical performance data for a specific market sector.
This endpoint provides historical performance metrics for market sectors, allowing analysis of sector trends and performance over time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sector
|
str
|
Market sector name (e.g., "Energy", "Technology", "Healthcare", "Financials", "Consumer Cyclical", "Industrials", "Basic Materials", "Consumer Defensive", "Real Estate", "Utilities", "Communication Services"). |
required |
start
|
str
|
Start date in 'YYYY-MM-DD' format. Defaults to API default. |
None
|
end
|
str
|
End date in 'YYYY-MM-DD' format. Defaults to API default. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Historical sector performance data with columns including date, sector, and performance metrics. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If sector is invalid or API request fails. |
Example
source = FMPDataSource() df = source.get_historical_sector_performance("Energy", start="2024-01-01", end="2024-12-31") print(df.head())
Source code in src/quantrl_lab/data/sources/fmp_loader.py
get_historical_industry_performance(industry, start=None, end=None)
Get historical performance data for a specific industry.
This endpoint provides historical performance metrics for industries, enabling long-term trend analysis and industry evolution tracking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
industry
|
str
|
Industry name (e.g., "Biotechnology", "Software", "Banks", "Oil & Gas", "Semiconductors", "Insurance", "Auto Manufacturers", "Pharmaceuticals", "Consumer Electronics", "Aerospace & Defense"). |
required |
start
|
str
|
Start date in 'YYYY-MM-DD' format. Defaults to API default. |
None
|
end
|
str
|
End date in 'YYYY-MM-DD' format. Defaults to API default. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Historical industry performance data with columns including date, industry, and performance metrics. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If industry is invalid or API request fails. |
Example
source = FMPDataSource() df = source.get_historical_industry_performance("Biotechnology", start="2024-01-01", end="2024-12-31") print(df.head())
Source code in src/quantrl_lab/data/sources/fmp_loader.py
get_company_profile(symbol)
Get company profile information including sector, industry, and key metrics.
This endpoint provides comprehensive company information including business description, sector/industry classification, executive information, and key financial metrics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbol
|
Union[str, List[str]]
|
Stock ticker symbol (e.g., "AAPL", "MSFT") or list of symbols (only first symbol will be used if list is provided). |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Company profile data with columns including symbol, companyName, sector, industry, description, ceo, website, exchange, mktCap, price, beta, volAvg, currency, ipoDate, address, fullTimeEmployees, and asset type flags. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If symbol is invalid or API request fails. |
Example
source = FMPDataSource() profile = source.get_company_profile("AAPL") print(f"Sector: {profile.iloc[0].get('sector')}") print(f"Industry: {profile.iloc[0].get('industry')}") print(f"CEO: {profile.iloc[0].get('ceo')}")
Use Cases
- Get sector/industry classification for stocks
- Screen stocks by sector or industry
- Retrieve company metadata for analysis
- Build company information datasets
Source code in src/quantrl_lab/data/sources/fmp_loader.py
async_fetch_ohlcv(session, symbol, start, end=None, timeframe='1d')
async
Async fetch of EOD OHLCV data for a single symbol.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
ClientSession
|
Shared aiohttp session. |
required |
symbol
|
str
|
Stock symbol to fetch. |
required |
start
|
Union[str, datetime]
|
Start date for historical data. |
required |
end
|
Union[str, datetime]
|
End date for historical data. |
None
|
timeframe
|
str
|
Timeframe string. Defaults to "1d". |
'1d'
|
Returns:
| Type | Description |
|---|---|
Tuple[str, DataFrame]
|
Tuple[str, pd.DataFrame]: Tuple of (symbol, df). |
Source code in src/quantrl_lab/data/sources/fmp_loader.py
async_fetch_ratings(session, symbol, limit=500)
async
Async fetch of historical analyst ratings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
ClientSession
|
Shared aiohttp session. |
required |
symbol
|
str
|
Stock symbol to fetch. |
required |
limit
|
int
|
Maximum number of records to return. Defaults to 500. |
500
|
Returns:
| Type | Description |
|---|---|
Tuple[str, DataFrame]
|
Tuple[str, pd.DataFrame]: Tuple of (symbol, df). |
Source code in src/quantrl_lab/data/sources/fmp_loader.py
async_fetch_company_profile(session, symbol)
async
Async fetch of company profile (sector, industry).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
ClientSession
|
Shared aiohttp session. |
required |
symbol
|
str
|
Stock symbol to fetch. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[str, DataFrame]
|
Tuple[str, pd.DataFrame]: Tuple of (symbol, df). |
Source code in src/quantrl_lab/data/sources/fmp_loader.py
async_fetch_sector_perf(session, sector, start, end)
async
Async fetch of historical sector performance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
ClientSession
|
Shared aiohttp session. |
required |
sector
|
str
|
Market sector name. |
required |
start
|
str
|
Start date in 'YYYY-MM-DD' format. |
required |
end
|
str
|
End date in 'YYYY-MM-DD' format. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[str, DataFrame]
|
Tuple[str, pd.DataFrame]: Tuple of (sector, df). |
Source code in src/quantrl_lab/data/sources/fmp_loader.py
async_fetch_industry_perf(session, industry, start, end)
async
Async fetch of historical industry performance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
session
|
ClientSession
|
Shared aiohttp session. |
required |
industry
|
str
|
Industry name. |
required |
start
|
str
|
Start date in 'YYYY-MM-DD' format. |
required |
end
|
str
|
End date in 'YYYY-MM-DD' format. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[str, DataFrame]
|
Tuple[str, pd.DataFrame]: Tuple of (industry, df). |
Source code in src/quantrl_lab/data/sources/fmp_loader.py
Registry
source_registry
DataSourceRegistry
Registry for managing multiple data sources with factory pattern.
Supports lazy initialization, multiple sources per type, and dynamic source discovery by capability.
Example
registry = DataSourceRegistry() registry.register_source("alpaca_backup", lambda: AlpacaDataLoader())
Use primary source
data = registry.get_historical_ohlcv_data(...)
Or get specific source
backup = registry.get_source("alpaca_backup") data = backup.get_historical_ohlcv_data(...)
Source code in src/quantrl_lab/data/source_registry.py
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 | |
primary_source
property
Get primary data source (lazy initialization).
Returns:
| Type | Description |
|---|---|
Any
|
Primary source instance |
news_source
property
Get news data source (lazy initialization).
Returns:
| Type | Description |
|---|---|
Any
|
News source instance |
__init__(sources=None, **kwargs)
Initialize with configured data sources.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sources
|
Optional[Dict[str, type]]
|
Dictionary mapping source names to data source classes |
None
|
**kwargs
|
Any
|
Individual source overrides (e.g., primary_source=YFinanceDataLoader) |
{}
|
Example
Use defaults
registry = DataSourceRegistry()
Override primary source
registry = DataSourceRegistry(primary_source=YFinanceDataLoader)
Custom sources dict
registry = DataSourceRegistry(sources={ ... "primary_source": AlpacaDataLoader, ... "backup_source": YFinanceDataLoader ... })
Source code in src/quantrl_lab/data/source_registry.py
register_source(name, factory, override=False)
Register a data source factory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Unique name for this source (e.g., "alpaca_primary", "yfinance_backup") |
required |
factory
|
Callable
|
Callable that returns a data source instance |
required |
override
|
bool
|
If True, replace existing registration |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If source already registered and override=False |
Example
registry.register_source("custom", lambda: YFinanceDataLoader()) registry.register_source("primary_source", lambda: AlpacaDataLoader(), override=True)
Source code in src/quantrl_lab/data/source_registry.py
get_source(name, **init_kwargs)
Get or create a data source instance (lazy initialization).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Source name to retrieve |
required |
**init_kwargs
|
Any
|
Initialization arguments for the source (if not yet created) |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
Data source instance |
Raises:
| Type | Description |
|---|---|
KeyError
|
If no factory registered for this name |
Example
source = registry.get_source("primary_source") data = source.get_historical_ohlcv_data(...)
Source code in src/quantrl_lab/data/source_registry.py
list_sources_by_capability(capability)
Find all registered sources supporting a capability.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
capability
|
str
|
Feature name (e.g., "historical_bars", "news", "streaming") |
required |
Returns:
| Type | Description |
|---|---|
List[str]
|
List of source names that support the capability |
Example
sources = registry.list_sources_by_capability("historical_bars") print(sources) # ["primary_source", "backup_source"]
Source code in src/quantrl_lab/data/source_registry.py
list_all_sources()
List all registered source names.
Returns:
| Type | Description |
|---|---|
List[str]
|
List of all registered source names |
get_historical_ohlcv_data(symbols, start, end=None, timeframe='1d', **kwargs)
Fetch historical OHLCV data from the primary data source.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbols
|
Union[str, List[str]]
|
Stock symbol(s) to fetch data for. |
required |
start
|
Union[str, datetime]
|
Start date for the data. |
required |
end
|
Optional[Union[str, datetime]]
|
End date for the data. Defaults to None. |
None
|
timeframe
|
str
|
Timeframe for the data. Defaults to "1d". |
'1d'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Historical OHLCV data. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If primary_source doesn't implement HistoricalDataCapable protocol. |
Source code in src/quantrl_lab/data/source_registry.py
get_news_data(symbols, start, end=None, **kwargs)
Get news data for a symbol or list of symbols.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
symbols
|
str
|
Stock symbol(s) |
required |
start
|
Union[str, datetime]
|
Start date or timestamp |
required |
end
|
Optional[Union[str, datetime]]
|
End date or timestamp. Defaults to None. |
None
|
**kwargs
|
Any
|
Additional parameters passed to the news source |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: raw news data |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If news_source doesn't implement NewsDataCapable protocol. |