Submitting predictions using python
The main choices are
- Use MicroWriter to send predictions for a specific stream and forecast horizon (read on).
- Use MicroCrawler instead, which will drive an algorithm to many streams (instructions)
- Use StreamSkater, which is a special case of MicroCrawler that makes it easy to use the timemachines functionality (instructions).
The first option is suitable if you intend to run a program on a schedule, say using cron.
Option 1. Use MicroWriter
The MicroWriter.submit() method to get the job done. This is illustratd by callable_flea.py
from microprediction import MicroWriter from microprediction.live.xraytickers import get_xray_stock_names from microprediction.live.xrayportfolios import XRAY_PORTFOLIO_NAMES from microconventions import MicroConventions NAMES = get_xray_stock_names() + XRAY_PORTFOLIO_NAMES mw = MicroWriter(write_key='YOUR WRITE KEY HERE') for name in NAMES: lagged_values = mw.get_lagged_values(name=name) padded = [-1, 0, 1 ] + list(lagged_values) + list(lagged_values[:5]) + list(lagged_values[:15]) devo = np.std(padded) values = sorted( [ devo*mw.norminv(p) + 0.001 * np.random.randn() for p in mw.percentiles()] ) nudged = StatsConventions.nudged(values) for delay in mw.DELAYS: mw.submit(name=name, values=values, delay=delay) time.sleep(1) # <-- Out of consideration for the system
This might be run once an hour, or once a day say. Naturally you’ll want to replace the dubious model above with your own statistical ingenuity.
Option 1a: MicroWriter copula submission
There is a rather specialized option that can make submission to so-called copula streams easier. For explanation, seepredict-using-python-copulas.
Option 2: Use MicroCrawler.run()
As noted there is an alternative to scheduled predictions. You can use a single long running process as follows:
- Subclass MicroCrawler
- Instantiate with your WRITE_KEY
- Call the run() method
This will create an algorithm that slowly explores the stream universe. In the first step you can override the default prediction and navigation logic. See predict-using-python-microcrawler.
Option 2a: Use a specialized version of MicroCrawler
See in particular:
You can also hunt in the repository.
Reminder: write keys
You can use a colab notebook to burn a new WRITE_KEY.