Running Scripts
Running PyneCore scripts from the command line
Running Scripts
The run
command is used to execute PyneCore scripts with historical OHLCV data. This page covers the details of how to use this command effectively.
Basic Usage
The basic syntax for running a script is:
pyne run SCRIPT DATA [OPTIONS]
Where:
SCRIPT
: Path to the PyneCore script (.py) fileDATA
: Path to the OHLCV data (.ohlcv) fileOPTIONS
: Additional options to customize the execution
Simple Example
# Run a script using paths within the working directory
pyne run my_strategy.py eurusd_data.ohlcv
This command will:
- Look for
my_strategy.py
in theworkdir/scripts/
directory - Look for
eurusd_data.ohlcv
in theworkdir/data/
directory - Execute the script with the provided data
- Save outputs to the
workdir/output/
directory
Command Arguments
The run
command has two required arguments:
SCRIPT
: The script file to run. If only a filename is provided, it will be searched in theworkdir/scripts/
directory.DATA
: The OHLCV data file to use. If only a filename is provided, it will be searched in theworkdir/data/
directory.
Command Options
The run
command supports several options to customize the execution:
Date Range Options
--from
,-f
: Start date (UTC) in ‘YYYY-MM-DD’ or ‘YYYY-MM-DD HH:MM:SS’ format. If not specified, it will use the first date in the data--to
,-t
: End date (UTC) in ‘YYYY-MM-DD’ or ‘YYYY-MM-DD HH:MM:SS’ format. If not specified, it will use the last date in the data.
Example:
# Run a script for a specific date range
pyne run my_strategy.py eurusd_data.ohlcv --from "2023-01-01" --to "2023-12-31"
Output Path Options
--plot
,-pp
: Path to save the plot data (CSV format). If not specified, it will be saved as<script_name>.csv
in theworkdir/output/
directory.--strat
,-sp
: Path to save the strategy statistics (CSV format). If not specified, it will be saved as<script_name>_strat.csv
in theworkdir/output/
directory.--equity
,-ep
: Path to save the equity curve (CSV format). If not specified, it will be saved as<script_name>_equity.csv
in theworkdir/output/
directory.
Example:
# Specify custom output paths
pyne run my_strategy.py eurusd_data.ohlcv --plot custom_plot.csv --strat custom_stats.csv
Symbol Information
When running a script, PyneCore needs symbol information to provide the script with details about the financial instrument being analyzed. This information is stored in a TOML file with the same name as the OHLCV file but with a .toml
extension.
For example, if your data file is eurusd_data.ohlcv
, the system will look for symbol information in eurusd_data.toml
.
The symbol information file should be located in the same directory as the OHLCV file and contain information like:
- Symbol name and description
- Exchange information
- Currency
- Session times
- Tick size and value
- etc.
More details about the symbol information can be found here.
If the symbol information file is not found, the command will display an error.
Progress Tracking
When running a script, the PyneCore CLI shows a progress bar with:
- Current date being processed
- Elapsed time
- Estimated remaining time
- Visual progress indicator
Example:
✓ Running script... [██████████████████████████████] 2023-12-31 12:30:00 / 0:01:45
Output Files
After the script execution completes, several output files are created:
Plot Data (CSV)
Contains the values plotted by the script for each bar. This includes all values passed to plot()
functions in your script.
Strategy Statistics (CSV)
If your script is a strategy, this file contains detailed statistics about the trading performance, including:
- Total profit/loss
- Win rate
- Maximum drawdown
- Sharpe ratio
- Trade details
Equity Curve (CSV)
If your script is a strategy, this file contains the equity curve data showing how the account balance changed over time.
Examples
Basic Usage
# Run a script with default options
pyne run my_strategy.py eurusd_data.ohlcv
Specifying Date Range
# Run a script for a specific month
pyne run my_strategy.py eurusd_data.ohlcv --from "2023-03-01" --to "2023-03-31"
Custom Output Paths
# Save outputs to custom locations
pyne run my_strategy.py eurusd_data.ohlcv \
--plot ./analysis/my_plot.csv \
--strat ./analysis/my_stats.csv \
--equity ./analysis/my_equity.csv
Troubleshooting
Script File Not Found
Script file 'my_strategy.py' not found!
This error occurs when the script file cannot be found. Make sure:
- The file exists in the specified location
- If you provided just a filename, check that it exists in the
workdir/scripts/
directory - The filename is spelled correctly (case sensitive)
Data File Not Found
Data file 'eurusd_data.ohlcv' not found!
This error occurs when the data file cannot be found. Make sure:
- The file exists in the specified location
- If you provided just a filename, check that it exists in the
workdir/data/
directory - The filename is spelled correctly (case sensitive)
Symbol Info File Not Found
Symbol info file 'eurusd_data.toml' not found!
This error occurs when the symbol information file cannot be found. Make sure:
- The file exists in the same directory as the OHLCV file
- The filename matches the OHLCV file (with a
.toml
extension) - If you’re using a data provider, check that you’ve downloaded the symbol information