13.08.2022 Views

advanced-algorithmic-trading

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

422

It takes the CSV file path as an input, along with the historical minutely price lags to

use as features, with the future minutely lags to use as responses. The up_down_factor and

percent_factor control the ratio of how much a stock must go up and not go down by in the

lookforward_minutes range.

For example, if up_down_factor=2.0 and percent_factor=0.01, this DataFrame will produce

a column of +1 and -1 values, where +1 indicates bars for which in the next lookforward_minutes

the returns exceed at least 2% and do not reduce by more than 1%. Hence it is searching for

instances where the stock is likely to increase twice as much as it is to decrease.

The function begins with reading the CSV file into Pandas. It sets the column names and

index. It also parses the dates:

def create_up_down_dataframe(

csv_filepath,

lookback_minutes=30,

lookforward_minutes=5,

up_down_factor=2.0,

percent_factor=0.01,

start=None, end=None

):

"""

Creates a Pandas DataFrame that imports and calculates

the percentage returns of an intraday OLHC ticker from disk.

’lookback_minutes’ of prior returns are stored to create

a feature vector, while ’lookforward_minutes’ are used to

ascertain how far in the future to predict across.

The actual prediction is to determine whether a ticker

moves up by at least ’up_down_factor’ x ’percent_factor’,

while not dropping below ’percent_factor’ in the same period.

i.e. Does the stock move up 1% in a minute and not down by 0.5%?

The DataFrame will consist of ’lookback_minutes’ columns for feature

vectors and one column for whether the stock adheres to the "up/down"

rule, which is 1 if True or 0 if False for each minute.

"""

ts = pd.read_csv(

csv_filepath,

names=[

"Timestamp", "Open", "Low", "High",

"Close", "Volume", "OpenInterest"

],

index_col="Timestamp", parse_dates=True

)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!