-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
data / ib - fetch futures data (#17)
* examples. provide better log messages. * enable IB to fetch futures data. * add more data to basic report. * update examples to show futures data fetching * run on all branches * update readme * try this * try one more thing * readme * remove unused data. * unused * return calendar that's specific to symbol * rename * handle various futures exchanges * log things via OOO
- Loading branch information
Weston Platter
authored
Jul 29, 2020
1 parent
ab11a60
commit 602fde5
Showing
12 changed files
with
267 additions
and
326 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from loguru import logger | ||
from ta_scanner.data import load_and_cache, IbDataFetcher | ||
|
||
ib_data_fetcher = IbDataFetcher() | ||
|
||
df = load_and_cache("/MES", ib_data_fetcher, previous_days=20, use_rth=True) | ||
df = load_and_cache("/MNQ", ib_data_fetcher, previous_days=20, use_rth=True) | ||
df = load_and_cache("/ZS", ib_data_fetcher, previous_days=30, use_rth=True) | ||
df = load_and_cache("/MGC", ib_data_fetcher, previous_days=30, use_rth=True) |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from loguru import logger | ||
from ta_scanner.data import load_and_cache, IbDataFetcher | ||
from ta_scanner.indicators import IndicatorSmaCrossover, IndicatorParams | ||
from ta_scanner.signals import Signal | ||
from ta_scanner.filters import FilterCumsum, FilterOptions, FilterNames | ||
from ta_scanner.reports import BasicReport | ||
|
||
|
||
# get SPY data | ||
ib_data_fetcher = IbDataFetcher() | ||
df = load_and_cache("/ZS", ib_data_fetcher, previous_days=30, use_rth=True) | ||
|
||
indicator_sma_cross = IndicatorSmaCrossover() | ||
|
||
# store signals in this field | ||
field_name = "moving_avg_cross" | ||
|
||
# Moving Average Crossover, 20 vs 50 | ||
indicator_params = { | ||
IndicatorParams.fast_sma: 10, | ||
IndicatorParams.slow_sma: 30, | ||
} | ||
# apply indicator to generate signals | ||
indicator_sma_cross.apply(df, field_name, indicator_params) | ||
|
||
# initialize filter | ||
sfilter = FilterCumsum() | ||
|
||
filter_options = { | ||
FilterOptions.win_points: 5, | ||
FilterOptions.loss_points: 2, | ||
FilterOptions.threshold_intervals: 20, | ||
} | ||
|
||
# generate results | ||
results = sfilter.apply(df, field_name, filter_options) | ||
|
||
# analyze results | ||
basic_report = BasicReport() | ||
pnl, count, average, median = basic_report.analyze(df, FilterNames.filter_cumsum.value) | ||
|
||
logger.info("------------------------") | ||
|
||
logger.info(f"Final PnL = {pnl}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from loguru import logger | ||
import sys | ||
|
||
from ta_scanner.data import load_and_cache, IbDataFetcher | ||
from ta_scanner.indicators import IndicatorSmaCrossover, IndicatorParams | ||
from ta_scanner.signals import Signal | ||
from ta_scanner.filters import FilterCumsum, FilterOptions, FilterNames | ||
from ta_scanner.reports import BasicReport | ||
|
||
|
||
# mute the noisy data debug statements | ||
logger.remove() | ||
logger.add(sys.stderr, level="INFO") | ||
|
||
ib_data_fetcher = IbDataFetcher() | ||
df = load_and_cache("/MNQ", ib_data_fetcher, previous_days=30, use_rth=True) | ||
|
||
indicator_sma_cross = IndicatorSmaCrossover() | ||
|
||
# store signals in this field | ||
field_name = "moving_avg_cross" | ||
|
||
|
||
def run_cross(fast_sma: int, slow_sma: int): | ||
indicator_params = { | ||
IndicatorParams.fast_sma: fast_sma, | ||
IndicatorParams.slow_sma: slow_sma, | ||
} | ||
# apply indicator to generate signals | ||
indicator_sma_cross.apply(df, field_name, indicator_params) | ||
|
||
# initialize filter | ||
sfilter = FilterCumsum() | ||
|
||
filter_options = { | ||
FilterOptions.win_points: 4, | ||
FilterOptions.loss_points: 2, | ||
FilterOptions.threshold_intervals: 20, | ||
} | ||
|
||
# generate results | ||
results = sfilter.apply(df, field_name, filter_options) | ||
|
||
# get aggregate pnl | ||
basic_report = BasicReport() | ||
pnl, count, avg, median = basic_report.analyze(df, FilterNames.filter_cumsum.value) | ||
return pnl, count, avg, median | ||
|
||
|
||
slow_sma = 100 | ||
|
||
for fast_sma in range(2, slow_sma): | ||
pnl, count, avg, median = run_cross(fast_sma, slow_sma) | ||
print(f"MA_Crx_{fast_sma}/{slow_sma}, {pnl}, {count}, {avg}, {median}") |
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.